nl80211.c 235 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006
  1. /*
  2. * This is the new netlink-based wireless configuration interface.
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. */
  6. #include <linux/if.h>
  7. #include <linux/module.h>
  8. #include <linux/err.h>
  9. #include <linux/slab.h>
  10. #include <linux/list.h>
  11. #include <linux/if_ether.h>
  12. #include <linux/ieee80211.h>
  13. #include <linux/nl80211.h>
  14. #include <linux/rtnetlink.h>
  15. #include <linux/netlink.h>
  16. #include <linux/etherdevice.h>
  17. #include <net/net_namespace.h>
  18. #include <net/genetlink.h>
  19. #include <net/cfg80211.h>
  20. #include <net/sock.h>
  21. #include "core.h"
  22. #include "nl80211.h"
  23. #include "reg.h"
  24. static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
  25. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  26. struct genl_info *info,
  27. struct cfg80211_crypto_settings *settings,
  28. int cipher_limit);
  29. static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
  30. struct genl_info *info);
  31. static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
  32. struct genl_info *info);
  33. /* the netlink family */
  34. static struct genl_family nl80211_fam = {
  35. .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
  36. .name = "nl80211", /* have users key off the name instead */
  37. .hdrsize = 0, /* no private header */
  38. .version = 1, /* no particular meaning now */
  39. .maxattr = NL80211_ATTR_MAX,
  40. .netnsok = true,
  41. .pre_doit = nl80211_pre_doit,
  42. .post_doit = nl80211_post_doit,
  43. };
  44. /* internal helper: get rdev and dev */
  45. static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
  46. struct cfg80211_registered_device **rdev,
  47. struct net_device **dev)
  48. {
  49. int ifindex;
  50. if (!attrs[NL80211_ATTR_IFINDEX])
  51. return -EINVAL;
  52. ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
  53. *dev = dev_get_by_index(netns, ifindex);
  54. if (!*dev)
  55. return -ENODEV;
  56. *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
  57. if (IS_ERR(*rdev)) {
  58. dev_put(*dev);
  59. return PTR_ERR(*rdev);
  60. }
  61. return 0;
  62. }
  63. static int validate_beacon_head(const struct nlattr *attr)
  64. {
  65. const u8 *data = nla_data(attr);
  66. unsigned int len = nla_len(attr);
  67. const struct element *elem;
  68. const struct ieee80211_mgmt *mgmt = (void *)data;
  69. unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
  70. u.beacon.variable);
  71. if (len < fixedlen)
  72. goto err;
  73. if (ieee80211_hdrlen(mgmt->frame_control) !=
  74. offsetof(struct ieee80211_mgmt, u.beacon))
  75. goto err;
  76. data += fixedlen;
  77. len -= fixedlen;
  78. for_each_element(elem, data, len) {
  79. /* nothing */
  80. }
  81. if (for_each_element_completed(elem, data, len))
  82. return 0;
  83. err:
  84. return -EINVAL;
  85. }
  86. /* policy for the attributes */
  87. static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
  88. [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
  89. [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
  90. .len = 20-1 },
  91. [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
  92. [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
  93. [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
  94. [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
  95. [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
  96. [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
  97. [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
  98. [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
  99. [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
  100. [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
  101. [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
  102. [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
  103. [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
  104. [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
  105. [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
  106. .len = WLAN_MAX_KEY_LEN },
  107. [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
  108. [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
  109. [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
  110. [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  111. [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
  112. [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
  113. [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
  114. [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
  115. .len = IEEE80211_MAX_DATA_LEN },
  116. [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
  117. .len = IEEE80211_MAX_DATA_LEN },
  118. [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
  119. [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
  120. [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
  121. [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
  122. .len = NL80211_MAX_SUPP_RATES },
  123. [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
  124. [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
  125. [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
  126. [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
  127. .len = IEEE80211_MAX_MESH_ID_LEN },
  128. [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_BINARY,
  129. .len = ETH_ALEN },
  130. [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
  131. [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
  132. [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
  133. [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
  134. [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
  135. [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
  136. .len = NL80211_MAX_SUPP_RATES },
  137. [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
  138. [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
  139. [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
  140. [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
  141. [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
  142. [NL80211_ATTR_IE] = { .type = NLA_BINARY,
  143. .len = IEEE80211_MAX_DATA_LEN },
  144. [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
  145. [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
  146. [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
  147. .len = IEEE80211_MAX_SSID_LEN },
  148. [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
  149. [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
  150. [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
  151. [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
  152. [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
  153. [NL80211_ATTR_STA_FLAGS2] = {
  154. .len = sizeof(struct nl80211_sta_flag_update),
  155. },
  156. [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
  157. [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
  158. [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
  159. [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
  160. [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
  161. [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
  162. [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
  163. [NL80211_ATTR_PID] = { .type = NLA_U32 },
  164. [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
  165. [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
  166. [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
  167. [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
  168. [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
  169. [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
  170. .len = IEEE80211_MAX_DATA_LEN },
  171. [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
  172. [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
  173. [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
  174. [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
  175. [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
  176. [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
  177. [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
  178. [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
  179. [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
  180. [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
  181. [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
  182. [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
  183. [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  184. [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
  185. [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
  186. [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
  187. [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
  188. [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
  189. [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
  190. [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
  191. .len = IEEE80211_MAX_DATA_LEN },
  192. [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
  193. .len = IEEE80211_MAX_DATA_LEN },
  194. [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
  195. [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
  196. [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
  197. [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
  198. [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
  199. [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
  200. [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
  201. [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
  202. [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
  203. [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
  204. .len = IEEE80211_MAX_DATA_LEN },
  205. [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
  206. [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
  207. [NL80211_ATTR_HT_CAPABILITY_MASK] = {
  208. .len = NL80211_HT_CAPABILITY_LEN
  209. },
  210. [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
  211. [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
  212. [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
  213. [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
  214. [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
  215. [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
  216. [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
  217. [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
  218. [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
  219. [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
  220. [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
  221. [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
  222. [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
  223. [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
  224. [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
  225. .len = NL80211_VHT_CAPABILITY_LEN,
  226. },
  227. [NL80211_ATTR_MDID] = { .type = NLA_U16 },
  228. [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
  229. .len = IEEE80211_MAX_DATA_LEN },
  230. [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
  231. [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
  232. [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
  233. [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
  234. [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
  235. [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
  236. [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
  237. [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
  238. [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
  239. [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
  240. [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
  241. [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
  242. [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
  243. [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
  244. [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
  245. [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
  246. .len = IEEE80211_QOS_MAP_LEN_MAX },
  247. [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
  248. [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
  249. [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
  250. };
  251. /* policy for the key attributes */
  252. static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
  253. [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
  254. [NL80211_KEY_IDX] = { .type = NLA_U8 },
  255. [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
  256. [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  257. [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
  258. [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
  259. [NL80211_KEY_TYPE] = { .type = NLA_U32 },
  260. [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  261. };
  262. /* policy for the key default flags */
  263. static const struct nla_policy
  264. nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
  265. [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
  266. [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
  267. };
  268. /* policy for WoWLAN attributes */
  269. static const struct nla_policy
  270. nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
  271. [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
  272. [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
  273. [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
  274. [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
  275. [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
  276. [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
  277. [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
  278. [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
  279. };
  280. /* policy for GTK rekey offload attributes */
  281. static const struct nla_policy
  282. nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
  283. [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
  284. [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
  285. [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
  286. };
  287. static const struct nla_policy
  288. nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
  289. [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
  290. .len = IEEE80211_MAX_SSID_LEN },
  291. };
  292. /* policy for packet pattern attributes */
  293. static const struct nla_policy
  294. nl80211_packet_pattern_policy[MAX_NL80211_WOWLAN_PKTPAT + 1] = {
  295. [NL80211_WOWLAN_PKTPAT_MASK] = { .type = NLA_BINARY, },
  296. [NL80211_WOWLAN_PKTPAT_PATTERN] = { .type = NLA_BINARY, }
  297. };
  298. /* ifidx get helper */
  299. static int nl80211_get_ifidx(struct netlink_callback *cb)
  300. {
  301. int res;
  302. res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  303. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  304. nl80211_policy);
  305. if (res)
  306. return res;
  307. if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
  308. return -EINVAL;
  309. res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
  310. if (!res)
  311. return -EINVAL;
  312. return res;
  313. }
  314. static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
  315. struct netlink_callback *cb,
  316. struct cfg80211_registered_device **rdev,
  317. struct net_device **dev)
  318. {
  319. int ifidx = cb->args[0];
  320. int err;
  321. if (!ifidx)
  322. ifidx = nl80211_get_ifidx(cb);
  323. if (ifidx < 0)
  324. return ifidx;
  325. cb->args[0] = ifidx;
  326. rtnl_lock();
  327. *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
  328. if (!*dev) {
  329. err = -ENODEV;
  330. goto out_rtnl;
  331. }
  332. *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
  333. if (IS_ERR(*rdev)) {
  334. err = PTR_ERR(*rdev);
  335. goto out_rtnl;
  336. }
  337. return 0;
  338. out_rtnl:
  339. rtnl_unlock();
  340. return err;
  341. }
  342. static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
  343. {
  344. cfg80211_unlock_rdev(rdev);
  345. rtnl_unlock();
  346. }
  347. /* IE validation */
  348. static bool is_valid_ie_attr(const struct nlattr *attr)
  349. {
  350. const u8 *pos;
  351. int len;
  352. if (!attr)
  353. return true;
  354. pos = nla_data(attr);
  355. len = nla_len(attr);
  356. while (len) {
  357. u8 elemlen;
  358. if (len < 2)
  359. return false;
  360. len -= 2;
  361. elemlen = pos[1];
  362. if (elemlen > len)
  363. return false;
  364. len -= elemlen;
  365. pos += 2 + elemlen;
  366. }
  367. return true;
  368. }
  369. /* message building helper */
  370. static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
  371. int flags, u8 cmd)
  372. {
  373. /* since there is no private header just add the generic one */
  374. return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
  375. }
  376. static int nl80211_msg_put_channel(struct sk_buff *msg,
  377. struct ieee80211_channel *chan)
  378. {
  379. NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
  380. chan->center_freq);
  381. if (chan->flags & IEEE80211_CHAN_DISABLED)
  382. NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
  383. if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
  384. NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
  385. if (chan->flags & IEEE80211_CHAN_NO_IBSS)
  386. NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
  387. if (chan->flags & IEEE80211_CHAN_RADAR)
  388. NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
  389. if (chan->flags & IEEE80211_CHAN_NO_20MHZ)
  390. NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ);
  391. if (chan->flags & IEEE80211_CHAN_NO_10MHZ)
  392. NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ);
  393. NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
  394. DBM_TO_MBM(chan->max_power));
  395. return 0;
  396. nla_put_failure:
  397. return -ENOBUFS;
  398. }
  399. /* netlink command implementations */
  400. struct key_parse {
  401. struct key_params p;
  402. int idx;
  403. int type;
  404. bool def, defmgmt;
  405. bool def_uni, def_multi;
  406. };
  407. static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
  408. {
  409. struct nlattr *tb[NL80211_KEY_MAX + 1];
  410. int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
  411. nl80211_key_policy);
  412. if (err)
  413. return err;
  414. k->def = !!tb[NL80211_KEY_DEFAULT];
  415. k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
  416. if (k->def) {
  417. k->def_uni = true;
  418. k->def_multi = true;
  419. }
  420. if (k->defmgmt)
  421. k->def_multi = true;
  422. if (tb[NL80211_KEY_IDX])
  423. k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
  424. if (tb[NL80211_KEY_DATA]) {
  425. k->p.key = nla_data(tb[NL80211_KEY_DATA]);
  426. k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
  427. }
  428. if (tb[NL80211_KEY_SEQ]) {
  429. k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
  430. k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
  431. }
  432. if (tb[NL80211_KEY_CIPHER])
  433. k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
  434. if (tb[NL80211_KEY_TYPE]) {
  435. k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
  436. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  437. return -EINVAL;
  438. }
  439. if (tb[NL80211_KEY_DEFAULT_TYPES]) {
  440. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  441. err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  442. tb[NL80211_KEY_DEFAULT_TYPES],
  443. nl80211_key_default_policy);
  444. if (err)
  445. return err;
  446. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  447. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  448. }
  449. return 0;
  450. }
  451. static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
  452. {
  453. if (info->attrs[NL80211_ATTR_KEY_DATA]) {
  454. k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
  455. k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
  456. }
  457. if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
  458. k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
  459. k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
  460. }
  461. if (info->attrs[NL80211_ATTR_KEY_IDX])
  462. k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  463. if (info->attrs[NL80211_ATTR_KEY_CIPHER])
  464. k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
  465. k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
  466. k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
  467. if (k->def) {
  468. k->def_uni = true;
  469. k->def_multi = true;
  470. }
  471. if (k->defmgmt)
  472. k->def_multi = true;
  473. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  474. k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  475. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  476. return -EINVAL;
  477. }
  478. if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
  479. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  480. int err = nla_parse_nested(
  481. kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  482. info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
  483. nl80211_key_default_policy);
  484. if (err)
  485. return err;
  486. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  487. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  488. }
  489. return 0;
  490. }
  491. static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
  492. {
  493. int err;
  494. memset(k, 0, sizeof(*k));
  495. k->idx = -1;
  496. k->type = -1;
  497. if (info->attrs[NL80211_ATTR_KEY])
  498. err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
  499. else
  500. err = nl80211_parse_key_old(info, k);
  501. if (err)
  502. return err;
  503. if (k->def && k->defmgmt)
  504. return -EINVAL;
  505. if (k->defmgmt) {
  506. if (k->def_uni || !k->def_multi)
  507. return -EINVAL;
  508. }
  509. if (k->idx != -1) {
  510. if (k->defmgmt) {
  511. if (k->idx < 4 || k->idx > 5)
  512. return -EINVAL;
  513. } else if (k->def) {
  514. if (k->idx < 0 || k->idx > 3)
  515. return -EINVAL;
  516. } else {
  517. if (k->idx < 0 || k->idx > 5)
  518. return -EINVAL;
  519. }
  520. }
  521. return 0;
  522. }
  523. static struct cfg80211_cached_keys *
  524. nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
  525. struct nlattr *keys)
  526. {
  527. struct key_parse parse;
  528. struct nlattr *key;
  529. struct cfg80211_cached_keys *result;
  530. int rem, err, def = 0;
  531. result = kzalloc(sizeof(*result), GFP_KERNEL);
  532. if (!result)
  533. return ERR_PTR(-ENOMEM);
  534. result->def = -1;
  535. result->defmgmt = -1;
  536. nla_for_each_nested(key, keys, rem) {
  537. memset(&parse, 0, sizeof(parse));
  538. parse.idx = -1;
  539. err = nl80211_parse_key_new(key, &parse);
  540. if (err)
  541. goto error;
  542. err = -EINVAL;
  543. if (!parse.p.key)
  544. goto error;
  545. if (parse.idx < 0 || parse.idx > 4)
  546. goto error;
  547. if (parse.def) {
  548. if (def)
  549. goto error;
  550. def = 1;
  551. result->def = parse.idx;
  552. if (!parse.def_uni || !parse.def_multi)
  553. goto error;
  554. } else if (parse.defmgmt)
  555. goto error;
  556. err = cfg80211_validate_key_settings(rdev, &parse.p,
  557. parse.idx, false, NULL);
  558. if (err)
  559. goto error;
  560. result->params[parse.idx].cipher = parse.p.cipher;
  561. result->params[parse.idx].key_len = parse.p.key_len;
  562. result->params[parse.idx].key = result->data[parse.idx];
  563. memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
  564. }
  565. return result;
  566. error:
  567. kfree(result);
  568. return ERR_PTR(err);
  569. }
  570. static int nl80211_key_allowed(struct wireless_dev *wdev)
  571. {
  572. ASSERT_WDEV_LOCK(wdev);
  573. switch (wdev->iftype) {
  574. case NL80211_IFTYPE_AP:
  575. case NL80211_IFTYPE_AP_VLAN:
  576. case NL80211_IFTYPE_P2P_GO:
  577. case NL80211_IFTYPE_MESH_POINT:
  578. break;
  579. case NL80211_IFTYPE_ADHOC:
  580. if (!wdev->current_bss)
  581. return -ENOLINK;
  582. break;
  583. case NL80211_IFTYPE_STATION:
  584. case NL80211_IFTYPE_P2P_CLIENT:
  585. if (wdev->sme_state != CFG80211_SME_CONNECTED)
  586. return -ENOLINK;
  587. break;
  588. default:
  589. return -EINVAL;
  590. }
  591. return 0;
  592. }
  593. static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
  594. {
  595. struct nlattr *nl_modes = nla_nest_start(msg, attr);
  596. int i;
  597. if (!nl_modes)
  598. goto nla_put_failure;
  599. i = 0;
  600. while (ifmodes) {
  601. if (ifmodes & 1)
  602. NLA_PUT_FLAG(msg, i);
  603. ifmodes >>= 1;
  604. i++;
  605. }
  606. nla_nest_end(msg, nl_modes);
  607. return 0;
  608. nla_put_failure:
  609. return -ENOBUFS;
  610. }
  611. static int nl80211_put_iface_combinations(struct wiphy *wiphy,
  612. struct sk_buff *msg)
  613. {
  614. struct nlattr *nl_combis;
  615. int i, j;
  616. nl_combis = nla_nest_start(msg,
  617. NL80211_ATTR_INTERFACE_COMBINATIONS);
  618. if (!nl_combis)
  619. goto nla_put_failure;
  620. for (i = 0; i < wiphy->n_iface_combinations; i++) {
  621. const struct ieee80211_iface_combination *c;
  622. struct nlattr *nl_combi, *nl_limits;
  623. c = &wiphy->iface_combinations[i];
  624. nl_combi = nla_nest_start(msg, i + 1);
  625. if (!nl_combi)
  626. goto nla_put_failure;
  627. nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
  628. if (!nl_limits)
  629. goto nla_put_failure;
  630. for (j = 0; j < c->n_limits; j++) {
  631. struct nlattr *nl_limit;
  632. nl_limit = nla_nest_start(msg, j + 1);
  633. if (!nl_limit)
  634. goto nla_put_failure;
  635. NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
  636. c->limits[j].max);
  637. if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
  638. c->limits[j].types))
  639. goto nla_put_failure;
  640. nla_nest_end(msg, nl_limit);
  641. }
  642. nla_nest_end(msg, nl_limits);
  643. if (c->beacon_int_infra_match)
  644. NLA_PUT_FLAG(msg,
  645. NL80211_IFACE_COMB_STA_AP_BI_MATCH);
  646. NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
  647. c->num_different_channels);
  648. NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
  649. c->max_interfaces);
  650. nla_nest_end(msg, nl_combi);
  651. }
  652. nla_nest_end(msg, nl_combis);
  653. return 0;
  654. nla_put_failure:
  655. return -ENOBUFS;
  656. }
  657. static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
  658. struct cfg80211_registered_device *dev)
  659. {
  660. void *hdr;
  661. struct nlattr *nl_bands, *nl_band;
  662. struct nlattr *nl_freqs, *nl_freq;
  663. struct nlattr *nl_rates, *nl_rate;
  664. struct nlattr *nl_cmds;
  665. enum ieee80211_band band;
  666. struct ieee80211_channel *chan;
  667. struct ieee80211_rate *rate;
  668. int i;
  669. const struct ieee80211_txrx_stypes *mgmt_stypes =
  670. dev->wiphy.mgmt_stypes;
  671. hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
  672. if (!hdr)
  673. return -1;
  674. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
  675. NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
  676. NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
  677. cfg80211_rdev_list_generation);
  678. NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
  679. dev->wiphy.retry_short);
  680. NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
  681. dev->wiphy.retry_long);
  682. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
  683. dev->wiphy.frag_threshold);
  684. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
  685. dev->wiphy.rts_threshold);
  686. NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
  687. dev->wiphy.coverage_class);
  688. NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
  689. dev->wiphy.max_scan_ssids);
  690. NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
  691. dev->wiphy.max_sched_scan_ssids);
  692. NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
  693. dev->wiphy.max_scan_ie_len);
  694. NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
  695. dev->wiphy.max_sched_scan_ie_len);
  696. NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
  697. dev->wiphy.max_match_sets);
  698. if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
  699. NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
  700. if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
  701. NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
  702. if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
  703. NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
  704. if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
  705. NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
  706. if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
  707. NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
  708. if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
  709. NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
  710. NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
  711. sizeof(u32) * dev->wiphy.n_cipher_suites,
  712. dev->wiphy.cipher_suites);
  713. NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
  714. dev->wiphy.max_num_pmkids);
  715. if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
  716. NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
  717. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
  718. dev->wiphy.available_antennas_tx);
  719. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
  720. dev->wiphy.available_antennas_rx);
  721. if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD)
  722. NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
  723. dev->wiphy.probe_resp_offload);
  724. if ((dev->wiphy.available_antennas_tx ||
  725. dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
  726. u32 tx_ant = 0, rx_ant = 0;
  727. int res;
  728. res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
  729. if (!res) {
  730. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
  731. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
  732. }
  733. }
  734. if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
  735. dev->wiphy.interface_modes))
  736. goto nla_put_failure;
  737. nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
  738. if (!nl_bands)
  739. goto nla_put_failure;
  740. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  741. if (!dev->wiphy.bands[band])
  742. continue;
  743. nl_band = nla_nest_start(msg, band);
  744. if (!nl_band)
  745. goto nla_put_failure;
  746. /* add HT info */
  747. if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
  748. NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
  749. sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
  750. &dev->wiphy.bands[band]->ht_cap.mcs);
  751. NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
  752. dev->wiphy.bands[band]->ht_cap.cap);
  753. NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
  754. dev->wiphy.bands[band]->ht_cap.ampdu_factor);
  755. NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
  756. dev->wiphy.bands[band]->ht_cap.ampdu_density);
  757. }
  758. /* add VHT info */
  759. if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
  760. (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
  761. sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
  762. &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
  763. nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
  764. dev->wiphy.bands[band]->vht_cap.cap)))
  765. goto nla_put_failure;
  766. /* add frequencies */
  767. nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
  768. if (!nl_freqs)
  769. goto nla_put_failure;
  770. for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
  771. nl_freq = nla_nest_start(msg, i);
  772. if (!nl_freq)
  773. goto nla_put_failure;
  774. chan = &dev->wiphy.bands[band]->channels[i];
  775. if (nl80211_msg_put_channel(msg, chan))
  776. goto nla_put_failure;
  777. nla_nest_end(msg, nl_freq);
  778. }
  779. nla_nest_end(msg, nl_freqs);
  780. /* add bitrates */
  781. nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
  782. if (!nl_rates)
  783. goto nla_put_failure;
  784. for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
  785. nl_rate = nla_nest_start(msg, i);
  786. if (!nl_rate)
  787. goto nla_put_failure;
  788. rate = &dev->wiphy.bands[band]->bitrates[i];
  789. NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
  790. rate->bitrate);
  791. if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
  792. NLA_PUT_FLAG(msg,
  793. NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
  794. nla_nest_end(msg, nl_rate);
  795. }
  796. nla_nest_end(msg, nl_rates);
  797. nla_nest_end(msg, nl_band);
  798. }
  799. nla_nest_end(msg, nl_bands);
  800. nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
  801. if (!nl_cmds)
  802. goto nla_put_failure;
  803. i = 0;
  804. #define CMD(op, n) \
  805. do { \
  806. if (dev->ops->op) { \
  807. i++; \
  808. NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
  809. } \
  810. } while (0)
  811. CMD(add_virtual_intf, NEW_INTERFACE);
  812. CMD(change_virtual_intf, SET_INTERFACE);
  813. CMD(add_key, NEW_KEY);
  814. CMD(start_ap, START_AP);
  815. CMD(add_station, NEW_STATION);
  816. CMD(add_mpath, NEW_MPATH);
  817. CMD(update_mesh_config, SET_MESH_CONFIG);
  818. CMD(change_bss, SET_BSS);
  819. CMD(auth, AUTHENTICATE);
  820. CMD(assoc, ASSOCIATE);
  821. CMD(deauth, DEAUTHENTICATE);
  822. CMD(disassoc, DISASSOCIATE);
  823. CMD(join_ibss, JOIN_IBSS);
  824. CMD(join_mesh, JOIN_MESH);
  825. CMD(set_pmksa, SET_PMKSA);
  826. CMD(del_pmksa, DEL_PMKSA);
  827. CMD(flush_pmksa, FLUSH_PMKSA);
  828. if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
  829. CMD(remain_on_channel, REMAIN_ON_CHANNEL);
  830. CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
  831. CMD(mgmt_tx, FRAME);
  832. CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
  833. if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
  834. i++;
  835. NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
  836. }
  837. CMD(set_channel, SET_CHANNEL);
  838. CMD(set_wds_peer, SET_WDS_PEER);
  839. if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
  840. CMD(tdls_mgmt, TDLS_MGMT);
  841. CMD(tdls_oper, TDLS_OPER);
  842. }
  843. if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  844. CMD(sched_scan_start, START_SCHED_SCAN);
  845. CMD(probe_client, PROBE_CLIENT);
  846. CMD(set_noack_map, SET_NOACK_MAP);
  847. if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
  848. i++;
  849. NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS);
  850. }
  851. CMD(set_qos_map, SET_QOS_MAP);
  852. #ifdef CONFIG_NL80211_TESTMODE
  853. CMD(testmode_cmd, TESTMODE);
  854. #endif
  855. #undef CMD
  856. if (dev->ops->connect || dev->ops->auth) {
  857. i++;
  858. NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
  859. }
  860. if (dev->ops->disconnect || dev->ops->deauth) {
  861. i++;
  862. NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
  863. }
  864. nla_nest_end(msg, nl_cmds);
  865. if (dev->ops->remain_on_channel &&
  866. dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
  867. NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
  868. dev->wiphy.max_remain_on_channel_duration);
  869. if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)
  870. NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
  871. if (mgmt_stypes) {
  872. u16 stypes;
  873. struct nlattr *nl_ftypes, *nl_ifs;
  874. enum nl80211_iftype ift;
  875. nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
  876. if (!nl_ifs)
  877. goto nla_put_failure;
  878. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  879. nl_ftypes = nla_nest_start(msg, ift);
  880. if (!nl_ftypes)
  881. goto nla_put_failure;
  882. i = 0;
  883. stypes = mgmt_stypes[ift].tx;
  884. while (stypes) {
  885. if (stypes & 1)
  886. NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
  887. (i << 4) | IEEE80211_FTYPE_MGMT);
  888. stypes >>= 1;
  889. i++;
  890. }
  891. nla_nest_end(msg, nl_ftypes);
  892. }
  893. nla_nest_end(msg, nl_ifs);
  894. nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
  895. if (!nl_ifs)
  896. goto nla_put_failure;
  897. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  898. nl_ftypes = nla_nest_start(msg, ift);
  899. if (!nl_ftypes)
  900. goto nla_put_failure;
  901. i = 0;
  902. stypes = mgmt_stypes[ift].rx;
  903. while (stypes) {
  904. if (stypes & 1)
  905. NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
  906. (i << 4) | IEEE80211_FTYPE_MGMT);
  907. stypes >>= 1;
  908. i++;
  909. }
  910. nla_nest_end(msg, nl_ftypes);
  911. }
  912. nla_nest_end(msg, nl_ifs);
  913. }
  914. if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
  915. struct nlattr *nl_wowlan;
  916. nl_wowlan = nla_nest_start(msg,
  917. NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
  918. if (!nl_wowlan)
  919. goto nla_put_failure;
  920. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
  921. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
  922. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
  923. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
  924. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
  925. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
  926. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
  927. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
  928. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
  929. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
  930. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
  931. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
  932. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
  933. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
  934. if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
  935. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
  936. if (dev->wiphy.wowlan.n_patterns) {
  937. struct nl80211_wowlan_pattern_support pat = {
  938. .max_patterns = dev->wiphy.wowlan.n_patterns,
  939. .min_pattern_len =
  940. dev->wiphy.wowlan.pattern_min_len,
  941. .max_pattern_len =
  942. dev->wiphy.wowlan.pattern_max_len,
  943. };
  944. NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  945. sizeof(pat), &pat);
  946. }
  947. nla_nest_end(msg, nl_wowlan);
  948. }
  949. if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
  950. dev->wiphy.software_iftypes))
  951. goto nla_put_failure;
  952. if (nl80211_put_iface_combinations(&dev->wiphy, msg))
  953. goto nla_put_failure;
  954. if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
  955. NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
  956. dev->wiphy.ap_sme_capa);
  957. NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features);
  958. if (dev->wiphy.ht_capa_mod_mask)
  959. NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
  960. sizeof(*dev->wiphy.ht_capa_mod_mask),
  961. dev->wiphy.ht_capa_mod_mask);
  962. if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
  963. dev->wiphy.max_acl_mac_addrs)
  964. NLA_PUT_U32(msg, NL80211_ATTR_MAC_ACL_MAX,
  965. dev->wiphy.max_acl_mac_addrs);
  966. if (dev->wiphy.max_ap_assoc_sta &&
  967. nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
  968. dev->wiphy.max_ap_assoc_sta))
  969. goto nla_put_failure;
  970. if (dev->wiphy.n_vendor_commands) {
  971. const struct nl80211_vendor_cmd_info *info;
  972. struct nlattr *nested;
  973. nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
  974. if (!nested)
  975. goto nla_put_failure;
  976. for (i = 0; i < dev->wiphy.n_vendor_commands; i++) {
  977. info = &dev->wiphy.vendor_commands[i].info;
  978. if (nla_put(msg, i + 1, sizeof(*info), info))
  979. goto nla_put_failure;
  980. }
  981. nla_nest_end(msg, nested);
  982. }
  983. if (dev->wiphy.n_vendor_events) {
  984. const struct nl80211_vendor_cmd_info *info;
  985. struct nlattr *nested;
  986. nested = nla_nest_start(msg,
  987. NL80211_ATTR_VENDOR_EVENTS);
  988. if (!nested)
  989. goto nla_put_failure;
  990. for (i = 0; i < dev->wiphy.n_vendor_events; i++) {
  991. info = &dev->wiphy.vendor_events[i];
  992. if (nla_put(msg, i + 1, sizeof(*info), info))
  993. goto nla_put_failure;
  994. }
  995. nla_nest_end(msg, nested);
  996. }
  997. return genlmsg_end(msg, hdr);
  998. nla_put_failure:
  999. genlmsg_cancel(msg, hdr);
  1000. return -EMSGSIZE;
  1001. }
  1002. static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
  1003. {
  1004. int idx = 0;
  1005. int start = cb->args[0];
  1006. struct cfg80211_registered_device *dev;
  1007. mutex_lock(&cfg80211_mutex);
  1008. list_for_each_entry(dev, &cfg80211_rdev_list, list) {
  1009. if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
  1010. continue;
  1011. if (++idx <= start)
  1012. continue;
  1013. if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
  1014. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  1015. dev) < 0) {
  1016. idx--;
  1017. break;
  1018. }
  1019. }
  1020. mutex_unlock(&cfg80211_mutex);
  1021. cb->args[0] = idx;
  1022. return skb->len;
  1023. }
  1024. static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
  1025. {
  1026. struct sk_buff *msg;
  1027. struct cfg80211_registered_device *dev = info->user_ptr[0];
  1028. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1029. if (!msg)
  1030. return -ENOMEM;
  1031. if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
  1032. nlmsg_free(msg);
  1033. return -ENOBUFS;
  1034. }
  1035. return genlmsg_reply(msg, info);
  1036. }
  1037. static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
  1038. [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
  1039. [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
  1040. [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
  1041. [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
  1042. [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
  1043. };
  1044. static int parse_txq_params(struct nlattr *tb[],
  1045. struct ieee80211_txq_params *txq_params)
  1046. {
  1047. if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
  1048. !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
  1049. !tb[NL80211_TXQ_ATTR_AIFS])
  1050. return -EINVAL;
  1051. txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
  1052. txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
  1053. txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
  1054. txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
  1055. txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
  1056. return 0;
  1057. }
  1058. static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
  1059. {
  1060. /*
  1061. * You can only set the channel explicitly for AP, mesh
  1062. * and WDS type interfaces; all others have their channel
  1063. * managed via their respective "establish a connection"
  1064. * command (connect, join, ...)
  1065. *
  1066. * Monitors are special as they are normally slaved to
  1067. * whatever else is going on, so they behave as though
  1068. * you tried setting the wiphy channel itself.
  1069. */
  1070. return !wdev ||
  1071. wdev->iftype == NL80211_IFTYPE_AP ||
  1072. wdev->iftype == NL80211_IFTYPE_WDS ||
  1073. wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
  1074. wdev->iftype == NL80211_IFTYPE_MONITOR ||
  1075. wdev->iftype == NL80211_IFTYPE_P2P_GO;
  1076. }
  1077. static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
  1078. struct wireless_dev *wdev,
  1079. struct genl_info *info)
  1080. {
  1081. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  1082. u32 freq;
  1083. int result;
  1084. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  1085. return -EINVAL;
  1086. if (!nl80211_can_set_dev_channel(wdev))
  1087. return -EOPNOTSUPP;
  1088. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  1089. channel_type = nla_get_u32(info->attrs[
  1090. NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  1091. if (channel_type != NL80211_CHAN_NO_HT &&
  1092. channel_type != NL80211_CHAN_HT20 &&
  1093. channel_type != NL80211_CHAN_HT40PLUS &&
  1094. channel_type != NL80211_CHAN_HT40MINUS)
  1095. return -EINVAL;
  1096. }
  1097. freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  1098. mutex_lock(&rdev->devlist_mtx);
  1099. if (wdev) {
  1100. wdev_lock(wdev);
  1101. result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
  1102. wdev_unlock(wdev);
  1103. } else {
  1104. result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
  1105. }
  1106. mutex_unlock(&rdev->devlist_mtx);
  1107. return result;
  1108. }
  1109. static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
  1110. {
  1111. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1112. struct net_device *netdev = info->user_ptr[1];
  1113. return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
  1114. }
  1115. static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
  1116. {
  1117. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1118. struct net_device *dev = info->user_ptr[1];
  1119. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1120. const u8 *bssid;
  1121. if (!info->attrs[NL80211_ATTR_MAC])
  1122. return -EINVAL;
  1123. if (netif_running(dev))
  1124. return -EBUSY;
  1125. if (!rdev->ops->set_wds_peer)
  1126. return -EOPNOTSUPP;
  1127. if (wdev->iftype != NL80211_IFTYPE_WDS)
  1128. return -EOPNOTSUPP;
  1129. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1130. return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
  1131. }
  1132. static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
  1133. {
  1134. struct cfg80211_registered_device *rdev;
  1135. struct net_device *netdev = NULL;
  1136. struct wireless_dev *wdev;
  1137. int result = 0, rem_txq_params = 0;
  1138. struct nlattr *nl_txq_params;
  1139. u32 changed;
  1140. u8 retry_short = 0, retry_long = 0;
  1141. u32 frag_threshold = 0, rts_threshold = 0;
  1142. u8 coverage_class = 0;
  1143. /*
  1144. * Try to find the wiphy and netdev. Normally this
  1145. * function shouldn't need the netdev, but this is
  1146. * done for backward compatibility -- previously
  1147. * setting the channel was done per wiphy, but now
  1148. * it is per netdev. Previous userland like hostapd
  1149. * also passed a netdev to set_wiphy, so that it is
  1150. * possible to let that go to the right netdev!
  1151. */
  1152. mutex_lock(&cfg80211_mutex);
  1153. if (info->attrs[NL80211_ATTR_IFINDEX]) {
  1154. int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
  1155. netdev = dev_get_by_index(genl_info_net(info), ifindex);
  1156. if (netdev && netdev->ieee80211_ptr) {
  1157. rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
  1158. mutex_lock(&rdev->mtx);
  1159. } else
  1160. netdev = NULL;
  1161. }
  1162. if (!netdev) {
  1163. rdev = __cfg80211_rdev_from_info(info);
  1164. if (IS_ERR(rdev)) {
  1165. mutex_unlock(&cfg80211_mutex);
  1166. return PTR_ERR(rdev);
  1167. }
  1168. wdev = NULL;
  1169. netdev = NULL;
  1170. result = 0;
  1171. mutex_lock(&rdev->mtx);
  1172. } else if (netif_running(netdev) &&
  1173. nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
  1174. wdev = netdev->ieee80211_ptr;
  1175. else
  1176. wdev = NULL;
  1177. /*
  1178. * end workaround code, by now the rdev is available
  1179. * and locked, and wdev may or may not be NULL.
  1180. */
  1181. if (info->attrs[NL80211_ATTR_WIPHY_NAME])
  1182. result = cfg80211_dev_rename(
  1183. rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
  1184. mutex_unlock(&cfg80211_mutex);
  1185. if (result)
  1186. goto bad_res;
  1187. if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
  1188. struct ieee80211_txq_params txq_params;
  1189. struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
  1190. if (!rdev->ops->set_txq_params) {
  1191. result = -EOPNOTSUPP;
  1192. goto bad_res;
  1193. }
  1194. if (!netdev) {
  1195. result = -EINVAL;
  1196. goto bad_res;
  1197. }
  1198. if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  1199. netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
  1200. result = -EINVAL;
  1201. goto bad_res;
  1202. }
  1203. if (!netif_running(netdev)) {
  1204. result = -ENETDOWN;
  1205. goto bad_res;
  1206. }
  1207. nla_for_each_nested(nl_txq_params,
  1208. info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
  1209. rem_txq_params) {
  1210. nla_parse(tb, NL80211_TXQ_ATTR_MAX,
  1211. nla_data(nl_txq_params),
  1212. nla_len(nl_txq_params),
  1213. txq_params_policy);
  1214. result = parse_txq_params(tb, &txq_params);
  1215. if (result)
  1216. goto bad_res;
  1217. result = rdev->ops->set_txq_params(&rdev->wiphy,
  1218. netdev,
  1219. &txq_params);
  1220. if (result)
  1221. goto bad_res;
  1222. }
  1223. }
  1224. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  1225. result = __nl80211_set_channel(rdev, wdev, info);
  1226. if (result)
  1227. goto bad_res;
  1228. }
  1229. if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
  1230. enum nl80211_tx_power_setting type;
  1231. int idx, mbm = 0;
  1232. if (!rdev->ops->set_tx_power) {
  1233. result = -EOPNOTSUPP;
  1234. goto bad_res;
  1235. }
  1236. idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
  1237. type = nla_get_u32(info->attrs[idx]);
  1238. if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
  1239. (type != NL80211_TX_POWER_AUTOMATIC)) {
  1240. result = -EINVAL;
  1241. goto bad_res;
  1242. }
  1243. if (type != NL80211_TX_POWER_AUTOMATIC) {
  1244. idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
  1245. mbm = nla_get_u32(info->attrs[idx]);
  1246. }
  1247. result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
  1248. if (result)
  1249. goto bad_res;
  1250. }
  1251. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  1252. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
  1253. u32 tx_ant, rx_ant;
  1254. if ((!rdev->wiphy.available_antennas_tx &&
  1255. !rdev->wiphy.available_antennas_rx) ||
  1256. !rdev->ops->set_antenna) {
  1257. result = -EOPNOTSUPP;
  1258. goto bad_res;
  1259. }
  1260. tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
  1261. rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
  1262. /* reject antenna configurations which don't match the
  1263. * available antenna masks, except for the "all" mask */
  1264. if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
  1265. (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
  1266. result = -EINVAL;
  1267. goto bad_res;
  1268. }
  1269. tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
  1270. rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
  1271. result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
  1272. if (result)
  1273. goto bad_res;
  1274. }
  1275. changed = 0;
  1276. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
  1277. retry_short = nla_get_u8(
  1278. info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
  1279. if (retry_short == 0) {
  1280. result = -EINVAL;
  1281. goto bad_res;
  1282. }
  1283. changed |= WIPHY_PARAM_RETRY_SHORT;
  1284. }
  1285. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
  1286. retry_long = nla_get_u8(
  1287. info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
  1288. if (retry_long == 0) {
  1289. result = -EINVAL;
  1290. goto bad_res;
  1291. }
  1292. changed |= WIPHY_PARAM_RETRY_LONG;
  1293. }
  1294. if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
  1295. frag_threshold = nla_get_u32(
  1296. info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
  1297. if (frag_threshold < 256) {
  1298. result = -EINVAL;
  1299. goto bad_res;
  1300. }
  1301. if (frag_threshold != (u32) -1) {
  1302. /*
  1303. * Fragments (apart from the last one) are required to
  1304. * have even length. Make the fragmentation code
  1305. * simpler by stripping LSB should someone try to use
  1306. * odd threshold value.
  1307. */
  1308. frag_threshold &= ~0x1;
  1309. }
  1310. changed |= WIPHY_PARAM_FRAG_THRESHOLD;
  1311. }
  1312. if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
  1313. rts_threshold = nla_get_u32(
  1314. info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
  1315. changed |= WIPHY_PARAM_RTS_THRESHOLD;
  1316. }
  1317. if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
  1318. coverage_class = nla_get_u8(
  1319. info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
  1320. changed |= WIPHY_PARAM_COVERAGE_CLASS;
  1321. }
  1322. if (changed) {
  1323. u8 old_retry_short, old_retry_long;
  1324. u32 old_frag_threshold, old_rts_threshold;
  1325. u8 old_coverage_class;
  1326. if (!rdev->ops->set_wiphy_params) {
  1327. result = -EOPNOTSUPP;
  1328. goto bad_res;
  1329. }
  1330. old_retry_short = rdev->wiphy.retry_short;
  1331. old_retry_long = rdev->wiphy.retry_long;
  1332. old_frag_threshold = rdev->wiphy.frag_threshold;
  1333. old_rts_threshold = rdev->wiphy.rts_threshold;
  1334. old_coverage_class = rdev->wiphy.coverage_class;
  1335. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1336. rdev->wiphy.retry_short = retry_short;
  1337. if (changed & WIPHY_PARAM_RETRY_LONG)
  1338. rdev->wiphy.retry_long = retry_long;
  1339. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  1340. rdev->wiphy.frag_threshold = frag_threshold;
  1341. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  1342. rdev->wiphy.rts_threshold = rts_threshold;
  1343. if (changed & WIPHY_PARAM_COVERAGE_CLASS)
  1344. rdev->wiphy.coverage_class = coverage_class;
  1345. result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
  1346. if (result) {
  1347. rdev->wiphy.retry_short = old_retry_short;
  1348. rdev->wiphy.retry_long = old_retry_long;
  1349. rdev->wiphy.frag_threshold = old_frag_threshold;
  1350. rdev->wiphy.rts_threshold = old_rts_threshold;
  1351. rdev->wiphy.coverage_class = old_coverage_class;
  1352. }
  1353. }
  1354. bad_res:
  1355. mutex_unlock(&rdev->mtx);
  1356. if (netdev)
  1357. dev_put(netdev);
  1358. return result;
  1359. }
  1360. static int nl80211_send_chandef(struct sk_buff *msg,
  1361. struct cfg80211_chan_def *chandef)
  1362. {
  1363. WARN_ON(!cfg80211_chandef_valid(chandef));
  1364. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
  1365. chandef->chan->center_freq))
  1366. return -ENOBUFS;
  1367. switch (chandef->width) {
  1368. case NL80211_CHAN_WIDTH_20_NOHT:
  1369. case NL80211_CHAN_WIDTH_20:
  1370. case NL80211_CHAN_WIDTH_40:
  1371. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  1372. cfg80211_get_chandef_type(chandef)))
  1373. return -ENOBUFS;
  1374. break;
  1375. default:
  1376. break;
  1377. }
  1378. if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
  1379. return -ENOBUFS;
  1380. if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
  1381. return -ENOBUFS;
  1382. if (chandef->center_freq2 &&
  1383. nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
  1384. return -ENOBUFS;
  1385. return 0;
  1386. }
  1387. static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
  1388. struct cfg80211_registered_device *rdev,
  1389. struct net_device *dev)
  1390. {
  1391. void *hdr;
  1392. hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
  1393. if (!hdr)
  1394. return -1;
  1395. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  1396. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  1397. NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
  1398. NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
  1399. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dev->dev_addr);
  1400. NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
  1401. rdev->devlist_generation ^
  1402. (cfg80211_rdev_list_generation << 2));
  1403. return genlmsg_end(msg, hdr);
  1404. nla_put_failure:
  1405. genlmsg_cancel(msg, hdr);
  1406. return -EMSGSIZE;
  1407. }
  1408. static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
  1409. {
  1410. int wp_idx = 0;
  1411. int if_idx = 0;
  1412. int wp_start = cb->args[0];
  1413. int if_start = cb->args[1];
  1414. struct cfg80211_registered_device *rdev;
  1415. struct wireless_dev *wdev;
  1416. mutex_lock(&cfg80211_mutex);
  1417. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  1418. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  1419. continue;
  1420. if (wp_idx < wp_start) {
  1421. wp_idx++;
  1422. continue;
  1423. }
  1424. if_idx = 0;
  1425. mutex_lock(&rdev->devlist_mtx);
  1426. list_for_each_entry(wdev, &rdev->netdev_list, list) {
  1427. if (if_idx < if_start) {
  1428. if_idx++;
  1429. continue;
  1430. }
  1431. if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
  1432. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  1433. rdev, wdev->netdev) < 0) {
  1434. mutex_unlock(&rdev->devlist_mtx);
  1435. goto out;
  1436. }
  1437. if_idx++;
  1438. }
  1439. mutex_unlock(&rdev->devlist_mtx);
  1440. wp_idx++;
  1441. }
  1442. out:
  1443. mutex_unlock(&cfg80211_mutex);
  1444. cb->args[0] = wp_idx;
  1445. cb->args[1] = if_idx;
  1446. return skb->len;
  1447. }
  1448. static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
  1449. {
  1450. struct sk_buff *msg;
  1451. struct cfg80211_registered_device *dev = info->user_ptr[0];
  1452. struct net_device *netdev = info->user_ptr[1];
  1453. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1454. if (!msg)
  1455. return -ENOMEM;
  1456. if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
  1457. dev, netdev) < 0) {
  1458. nlmsg_free(msg);
  1459. return -ENOBUFS;
  1460. }
  1461. return genlmsg_reply(msg, info);
  1462. }
  1463. static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
  1464. [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
  1465. [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
  1466. [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
  1467. [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
  1468. [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
  1469. };
  1470. static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
  1471. {
  1472. struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
  1473. int flag;
  1474. *mntrflags = 0;
  1475. if (!nla)
  1476. return -EINVAL;
  1477. if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
  1478. nla, mntr_flags_policy))
  1479. return -EINVAL;
  1480. for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
  1481. if (flags[flag])
  1482. *mntrflags |= (1<<flag);
  1483. return 0;
  1484. }
  1485. static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
  1486. struct net_device *netdev, u8 use_4addr,
  1487. enum nl80211_iftype iftype)
  1488. {
  1489. if (!use_4addr) {
  1490. if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
  1491. return -EBUSY;
  1492. return 0;
  1493. }
  1494. switch (iftype) {
  1495. case NL80211_IFTYPE_AP_VLAN:
  1496. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
  1497. return 0;
  1498. break;
  1499. case NL80211_IFTYPE_STATION:
  1500. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
  1501. return 0;
  1502. break;
  1503. default:
  1504. break;
  1505. }
  1506. return -EOPNOTSUPP;
  1507. }
  1508. static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
  1509. {
  1510. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1511. struct vif_params params;
  1512. int err;
  1513. enum nl80211_iftype otype, ntype;
  1514. struct net_device *dev = info->user_ptr[1];
  1515. u32 _flags, *flags = NULL;
  1516. bool change = false;
  1517. memset(&params, 0, sizeof(params));
  1518. otype = ntype = dev->ieee80211_ptr->iftype;
  1519. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  1520. ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  1521. if (otype != ntype)
  1522. change = true;
  1523. if (ntype > NL80211_IFTYPE_MAX)
  1524. return -EINVAL;
  1525. }
  1526. if (info->attrs[NL80211_ATTR_MESH_ID]) {
  1527. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1528. if (ntype != NL80211_IFTYPE_MESH_POINT)
  1529. return -EINVAL;
  1530. if (netif_running(dev))
  1531. return -EBUSY;
  1532. wdev_lock(wdev);
  1533. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  1534. IEEE80211_MAX_MESH_ID_LEN);
  1535. wdev->mesh_id_up_len =
  1536. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  1537. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  1538. wdev->mesh_id_up_len);
  1539. wdev_unlock(wdev);
  1540. }
  1541. if (info->attrs[NL80211_ATTR_4ADDR]) {
  1542. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  1543. change = true;
  1544. err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
  1545. if (err)
  1546. return err;
  1547. } else {
  1548. params.use_4addr = -1;
  1549. }
  1550. if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
  1551. if (ntype != NL80211_IFTYPE_MONITOR)
  1552. return -EINVAL;
  1553. err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
  1554. &_flags);
  1555. if (err)
  1556. return err;
  1557. flags = &_flags;
  1558. change = true;
  1559. }
  1560. if (change)
  1561. err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
  1562. else
  1563. err = 0;
  1564. if (!err && params.use_4addr != -1)
  1565. dev->ieee80211_ptr->use_4addr = params.use_4addr;
  1566. return err;
  1567. }
  1568. static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
  1569. {
  1570. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1571. struct vif_params params;
  1572. struct net_device *dev;
  1573. int err;
  1574. enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
  1575. u32 flags;
  1576. memset(&params, 0, sizeof(params));
  1577. if (!info->attrs[NL80211_ATTR_IFNAME])
  1578. return -EINVAL;
  1579. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  1580. type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  1581. if (type > NL80211_IFTYPE_MAX)
  1582. return -EINVAL;
  1583. }
  1584. if (!rdev->ops->add_virtual_intf ||
  1585. !(rdev->wiphy.interface_modes & (1 << type)))
  1586. return -EOPNOTSUPP;
  1587. if (info->attrs[NL80211_ATTR_4ADDR]) {
  1588. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  1589. err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
  1590. if (err)
  1591. return err;
  1592. }
  1593. err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
  1594. info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
  1595. &flags);
  1596. dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
  1597. nla_data(info->attrs[NL80211_ATTR_IFNAME]),
  1598. type, err ? NULL : &flags, &params);
  1599. if (IS_ERR(dev))
  1600. return PTR_ERR(dev);
  1601. if (type == NL80211_IFTYPE_MESH_POINT &&
  1602. info->attrs[NL80211_ATTR_MESH_ID]) {
  1603. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1604. wdev_lock(wdev);
  1605. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  1606. IEEE80211_MAX_MESH_ID_LEN);
  1607. wdev->mesh_id_up_len =
  1608. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  1609. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  1610. wdev->mesh_id_up_len);
  1611. wdev_unlock(wdev);
  1612. }
  1613. return 0;
  1614. }
  1615. static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
  1616. {
  1617. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1618. struct net_device *dev = info->user_ptr[1];
  1619. if (!rdev->ops->del_virtual_intf)
  1620. return -EOPNOTSUPP;
  1621. return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
  1622. }
  1623. static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
  1624. {
  1625. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1626. struct net_device *dev = info->user_ptr[1];
  1627. u16 noack_map;
  1628. if (!info->attrs[NL80211_ATTR_NOACK_MAP])
  1629. return -EINVAL;
  1630. if (!rdev->ops->set_noack_map)
  1631. return -EOPNOTSUPP;
  1632. noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
  1633. return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
  1634. }
  1635. struct get_key_cookie {
  1636. struct sk_buff *msg;
  1637. int error;
  1638. int idx;
  1639. };
  1640. static void get_key_callback(void *c, struct key_params *params)
  1641. {
  1642. struct nlattr *key;
  1643. struct get_key_cookie *cookie = c;
  1644. if (params->key)
  1645. NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
  1646. params->key_len, params->key);
  1647. if (params->seq)
  1648. NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
  1649. params->seq_len, params->seq);
  1650. if (params->cipher)
  1651. NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
  1652. params->cipher);
  1653. key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
  1654. if (!key)
  1655. goto nla_put_failure;
  1656. if (params->key)
  1657. NLA_PUT(cookie->msg, NL80211_KEY_DATA,
  1658. params->key_len, params->key);
  1659. if (params->seq)
  1660. NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
  1661. params->seq_len, params->seq);
  1662. if (params->cipher)
  1663. NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
  1664. params->cipher);
  1665. NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
  1666. nla_nest_end(cookie->msg, key);
  1667. return;
  1668. nla_put_failure:
  1669. cookie->error = 1;
  1670. }
  1671. static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
  1672. {
  1673. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1674. int err;
  1675. struct net_device *dev = info->user_ptr[1];
  1676. u8 key_idx = 0;
  1677. const u8 *mac_addr = NULL;
  1678. bool pairwise;
  1679. struct get_key_cookie cookie = {
  1680. .error = 0,
  1681. };
  1682. void *hdr;
  1683. struct sk_buff *msg;
  1684. if (info->attrs[NL80211_ATTR_KEY_IDX])
  1685. key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  1686. if (key_idx > 5)
  1687. return -EINVAL;
  1688. if (info->attrs[NL80211_ATTR_MAC])
  1689. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1690. pairwise = !!mac_addr;
  1691. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  1692. u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  1693. if (kt >= NUM_NL80211_KEYTYPES)
  1694. return -EINVAL;
  1695. if (kt != NL80211_KEYTYPE_GROUP &&
  1696. kt != NL80211_KEYTYPE_PAIRWISE)
  1697. return -EINVAL;
  1698. pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
  1699. }
  1700. if (!rdev->ops->get_key)
  1701. return -EOPNOTSUPP;
  1702. if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  1703. return -ENOENT;
  1704. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1705. if (!msg)
  1706. return -ENOMEM;
  1707. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  1708. NL80211_CMD_NEW_KEY);
  1709. if (!hdr)
  1710. goto nla_put_failure;
  1711. cookie.msg = msg;
  1712. cookie.idx = key_idx;
  1713. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  1714. NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
  1715. if (mac_addr)
  1716. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
  1717. err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
  1718. mac_addr, &cookie, get_key_callback);
  1719. if (err)
  1720. goto free_msg;
  1721. if (cookie.error)
  1722. goto nla_put_failure;
  1723. genlmsg_end(msg, hdr);
  1724. return genlmsg_reply(msg, info);
  1725. nla_put_failure:
  1726. err = -ENOBUFS;
  1727. free_msg:
  1728. nlmsg_free(msg);
  1729. return err;
  1730. }
  1731. static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
  1732. {
  1733. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1734. struct key_parse key;
  1735. int err;
  1736. struct net_device *dev = info->user_ptr[1];
  1737. err = nl80211_parse_key(info, &key);
  1738. if (err)
  1739. return err;
  1740. if (key.idx < 0)
  1741. return -EINVAL;
  1742. /* only support setting default key */
  1743. if (!key.def && !key.defmgmt)
  1744. return -EINVAL;
  1745. wdev_lock(dev->ieee80211_ptr);
  1746. if (key.def) {
  1747. if (!rdev->ops->set_default_key) {
  1748. err = -EOPNOTSUPP;
  1749. goto out;
  1750. }
  1751. err = nl80211_key_allowed(dev->ieee80211_ptr);
  1752. if (err)
  1753. goto out;
  1754. err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
  1755. key.def_uni, key.def_multi);
  1756. if (err)
  1757. goto out;
  1758. #ifdef CONFIG_CFG80211_WEXT
  1759. dev->ieee80211_ptr->wext.default_key = key.idx;
  1760. #endif
  1761. } else {
  1762. if (key.def_uni || !key.def_multi) {
  1763. err = -EINVAL;
  1764. goto out;
  1765. }
  1766. if (!rdev->ops->set_default_mgmt_key) {
  1767. err = -EOPNOTSUPP;
  1768. goto out;
  1769. }
  1770. err = nl80211_key_allowed(dev->ieee80211_ptr);
  1771. if (err)
  1772. goto out;
  1773. err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
  1774. dev, key.idx);
  1775. if (err)
  1776. goto out;
  1777. #ifdef CONFIG_CFG80211_WEXT
  1778. dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
  1779. #endif
  1780. }
  1781. out:
  1782. wdev_unlock(dev->ieee80211_ptr);
  1783. return err;
  1784. }
  1785. static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
  1786. {
  1787. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1788. int err;
  1789. struct net_device *dev = info->user_ptr[1];
  1790. struct key_parse key;
  1791. const u8 *mac_addr = NULL;
  1792. err = nl80211_parse_key(info, &key);
  1793. if (err)
  1794. return err;
  1795. if (!key.p.key)
  1796. return -EINVAL;
  1797. if (info->attrs[NL80211_ATTR_MAC])
  1798. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1799. if (key.type == -1) {
  1800. if (mac_addr)
  1801. key.type = NL80211_KEYTYPE_PAIRWISE;
  1802. else
  1803. key.type = NL80211_KEYTYPE_GROUP;
  1804. }
  1805. /* for now */
  1806. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  1807. key.type != NL80211_KEYTYPE_GROUP)
  1808. return -EINVAL;
  1809. if (!rdev->ops->add_key)
  1810. return -EOPNOTSUPP;
  1811. if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
  1812. key.type == NL80211_KEYTYPE_PAIRWISE,
  1813. mac_addr))
  1814. return -EINVAL;
  1815. wdev_lock(dev->ieee80211_ptr);
  1816. err = nl80211_key_allowed(dev->ieee80211_ptr);
  1817. if (!err)
  1818. err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
  1819. key.type == NL80211_KEYTYPE_PAIRWISE,
  1820. mac_addr, &key.p);
  1821. wdev_unlock(dev->ieee80211_ptr);
  1822. return err;
  1823. }
  1824. static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
  1825. {
  1826. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1827. int err;
  1828. struct net_device *dev = info->user_ptr[1];
  1829. u8 *mac_addr = NULL;
  1830. struct key_parse key;
  1831. err = nl80211_parse_key(info, &key);
  1832. if (err)
  1833. return err;
  1834. if (info->attrs[NL80211_ATTR_MAC])
  1835. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1836. if (key.type == -1) {
  1837. if (mac_addr)
  1838. key.type = NL80211_KEYTYPE_PAIRWISE;
  1839. else
  1840. key.type = NL80211_KEYTYPE_GROUP;
  1841. }
  1842. /* for now */
  1843. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  1844. key.type != NL80211_KEYTYPE_GROUP)
  1845. return -EINVAL;
  1846. if (!rdev->ops->del_key)
  1847. return -EOPNOTSUPP;
  1848. wdev_lock(dev->ieee80211_ptr);
  1849. err = nl80211_key_allowed(dev->ieee80211_ptr);
  1850. if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
  1851. !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  1852. err = -ENOENT;
  1853. if (!err)
  1854. err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
  1855. key.type == NL80211_KEYTYPE_PAIRWISE,
  1856. mac_addr);
  1857. #ifdef CONFIG_CFG80211_WEXT
  1858. if (!err) {
  1859. if (key.idx == dev->ieee80211_ptr->wext.default_key)
  1860. dev->ieee80211_ptr->wext.default_key = -1;
  1861. else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
  1862. dev->ieee80211_ptr->wext.default_mgmt_key = -1;
  1863. }
  1864. #endif
  1865. wdev_unlock(dev->ieee80211_ptr);
  1866. return err;
  1867. }
  1868. /* This function returns an error or the number of nested attributes */
  1869. static int validate_acl_mac_addrs(struct nlattr *nl_attr)
  1870. {
  1871. struct nlattr *attr;
  1872. int n_entries = 0, tmp;
  1873. nla_for_each_nested(attr, nl_attr, tmp) {
  1874. if (nla_len(attr) != ETH_ALEN)
  1875. return -EINVAL;
  1876. n_entries++;
  1877. }
  1878. return n_entries;
  1879. }
  1880. /*
  1881. * This function parses ACL information and allocates memory for ACL data.
  1882. * On successful return, the calling function is responsible to free the
  1883. * ACL buffer returned by this function.
  1884. */
  1885. static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
  1886. struct genl_info *info)
  1887. {
  1888. enum nl80211_acl_policy acl_policy;
  1889. struct nlattr *attr;
  1890. struct cfg80211_acl_data *acl;
  1891. int i = 0, n_entries, tmp;
  1892. if (!wiphy->max_acl_mac_addrs)
  1893. return ERR_PTR(-EOPNOTSUPP);
  1894. if (!info->attrs[NL80211_ATTR_ACL_POLICY])
  1895. return ERR_PTR(-EINVAL);
  1896. acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
  1897. if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
  1898. acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
  1899. return ERR_PTR(-EINVAL);
  1900. if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
  1901. return ERR_PTR(-EINVAL);
  1902. n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
  1903. if (n_entries < 0)
  1904. return ERR_PTR(n_entries);
  1905. if (n_entries > wiphy->max_acl_mac_addrs)
  1906. return ERR_PTR(-ENOTSUPP);
  1907. acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
  1908. GFP_KERNEL);
  1909. if (!acl)
  1910. return ERR_PTR(-ENOMEM);
  1911. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
  1912. memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
  1913. i++;
  1914. }
  1915. acl->n_acl_entries = n_entries;
  1916. acl->acl_policy = acl_policy;
  1917. return acl;
  1918. }
  1919. static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
  1920. {
  1921. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1922. struct net_device *dev = info->user_ptr[1];
  1923. struct cfg80211_acl_data *acl;
  1924. int err;
  1925. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  1926. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  1927. return -EOPNOTSUPP;
  1928. if (!dev->ieee80211_ptr->beacon_interval)
  1929. return -EINVAL;
  1930. acl = parse_acl_data(&rdev->wiphy, info);
  1931. if (IS_ERR(acl))
  1932. return PTR_ERR(acl);
  1933. err = rdev->ops->set_mac_acl(&rdev->wiphy, dev, acl);
  1934. kfree(acl);
  1935. return err;
  1936. }
  1937. static int nl80211_parse_beacon(struct nlattr *attrs[],
  1938. struct cfg80211_beacon_data *bcn)
  1939. {
  1940. bool haveinfo = false;
  1941. if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
  1942. !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
  1943. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
  1944. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
  1945. return -EINVAL;
  1946. memset(bcn, 0, sizeof(*bcn));
  1947. if (attrs[NL80211_ATTR_BEACON_HEAD]) {
  1948. int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD]);
  1949. if (ret)
  1950. return ret;
  1951. bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
  1952. bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
  1953. if (!bcn->head_len)
  1954. return -EINVAL;
  1955. haveinfo = true;
  1956. }
  1957. if (attrs[NL80211_ATTR_BEACON_TAIL]) {
  1958. bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
  1959. bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
  1960. haveinfo = true;
  1961. }
  1962. if (!haveinfo)
  1963. return -EINVAL;
  1964. if (attrs[NL80211_ATTR_IE]) {
  1965. bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
  1966. bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
  1967. }
  1968. if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
  1969. bcn->proberesp_ies =
  1970. nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  1971. bcn->proberesp_ies_len =
  1972. nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  1973. }
  1974. if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
  1975. bcn->assocresp_ies =
  1976. nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  1977. bcn->assocresp_ies_len =
  1978. nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  1979. }
  1980. if (attrs[NL80211_ATTR_PROBE_RESP]) {
  1981. bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
  1982. bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
  1983. }
  1984. return 0;
  1985. }
  1986. static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
  1987. {
  1988. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1989. struct net_device *dev = info->user_ptr[1];
  1990. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1991. struct cfg80211_ap_settings params;
  1992. int err;
  1993. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  1994. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  1995. return -EOPNOTSUPP;
  1996. if (!rdev->ops->start_ap)
  1997. return -EOPNOTSUPP;
  1998. if (wdev->beacon_interval)
  1999. return -EALREADY;
  2000. memset(&params, 0, sizeof(params));
  2001. /* these are required for START_AP */
  2002. if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
  2003. !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
  2004. !info->attrs[NL80211_ATTR_BEACON_HEAD])
  2005. return -EINVAL;
  2006. err = nl80211_parse_beacon(info->attrs, &params.beacon);
  2007. if (err)
  2008. return err;
  2009. params.beacon_interval =
  2010. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  2011. params.dtim_period =
  2012. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  2013. err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
  2014. if (err)
  2015. return err;
  2016. /*
  2017. * In theory, some of these attributes should be required here
  2018. * but since they were not used when the command was originally
  2019. * added, keep them optional for old user space programs to let
  2020. * them continue to work with drivers that do not need the
  2021. * additional information -- drivers must check!
  2022. */
  2023. if (info->attrs[NL80211_ATTR_SSID]) {
  2024. params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  2025. params.ssid_len =
  2026. nla_len(info->attrs[NL80211_ATTR_SSID]);
  2027. if (params.ssid_len == 0 ||
  2028. params.ssid_len > IEEE80211_MAX_SSID_LEN)
  2029. return -EINVAL;
  2030. }
  2031. if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
  2032. params.hidden_ssid = nla_get_u32(
  2033. info->attrs[NL80211_ATTR_HIDDEN_SSID]);
  2034. if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
  2035. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
  2036. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
  2037. return -EINVAL;
  2038. }
  2039. params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  2040. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  2041. params.auth_type = nla_get_u32(
  2042. info->attrs[NL80211_ATTR_AUTH_TYPE]);
  2043. if (!nl80211_valid_auth_type(params.auth_type))
  2044. return -EINVAL;
  2045. } else
  2046. params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  2047. err = nl80211_crypto_settings(rdev, info, &params.crypto,
  2048. NL80211_MAX_NR_CIPHER_SUITES);
  2049. if (err)
  2050. return err;
  2051. if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
  2052. if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
  2053. return -EOPNOTSUPP;
  2054. params.inactivity_timeout = nla_get_u16(
  2055. info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
  2056. }
  2057. if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
  2058. params.acl = parse_acl_data(&rdev->wiphy, info);
  2059. if (IS_ERR(params.acl))
  2060. return PTR_ERR(params.acl);
  2061. }
  2062. err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
  2063. if (!err)
  2064. wdev->beacon_interval = params.beacon_interval;
  2065. kfree(params.acl);
  2066. return err;
  2067. }
  2068. static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
  2069. {
  2070. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2071. struct net_device *dev = info->user_ptr[1];
  2072. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2073. struct cfg80211_beacon_data params;
  2074. int err;
  2075. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2076. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2077. return -EOPNOTSUPP;
  2078. if (!rdev->ops->change_beacon)
  2079. return -EOPNOTSUPP;
  2080. if (!wdev->beacon_interval)
  2081. return -EINVAL;
  2082. err = nl80211_parse_beacon(info->attrs, &params);
  2083. if (err)
  2084. return err;
  2085. return rdev->ops->change_beacon(&rdev->wiphy, dev, &params);
  2086. }
  2087. static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
  2088. {
  2089. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2090. struct net_device *dev = info->user_ptr[1];
  2091. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2092. int err;
  2093. if (!rdev->ops->stop_ap)
  2094. return -EOPNOTSUPP;
  2095. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2096. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2097. return -EOPNOTSUPP;
  2098. if (!wdev->beacon_interval)
  2099. return -ENOENT;
  2100. err = rdev->ops->stop_ap(&rdev->wiphy, dev);
  2101. wdev->beacon_interval = 0;
  2102. return err;
  2103. }
  2104. static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
  2105. [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
  2106. [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
  2107. [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
  2108. [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
  2109. [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
  2110. [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
  2111. };
  2112. static int parse_station_flags(struct genl_info *info,
  2113. enum nl80211_iftype iftype,
  2114. struct station_parameters *params)
  2115. {
  2116. struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
  2117. struct nlattr *nla;
  2118. int flag;
  2119. /*
  2120. * Try parsing the new attribute first so userspace
  2121. * can specify both for older kernels.
  2122. */
  2123. nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
  2124. if (nla) {
  2125. struct nl80211_sta_flag_update *sta_flags;
  2126. sta_flags = nla_data(nla);
  2127. params->sta_flags_mask = sta_flags->mask;
  2128. params->sta_flags_set = sta_flags->set;
  2129. if ((params->sta_flags_mask |
  2130. params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
  2131. return -EINVAL;
  2132. return 0;
  2133. }
  2134. /* if present, parse the old attribute */
  2135. nla = info->attrs[NL80211_ATTR_STA_FLAGS];
  2136. if (!nla)
  2137. return 0;
  2138. if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
  2139. nla, sta_flags_policy))
  2140. return -EINVAL;
  2141. /*
  2142. * Only allow certain flags for interface types so that
  2143. * other attributes are silently ignored. Remember that
  2144. * this is backward compatibility code with old userspace
  2145. * and shouldn't be hit in other cases anyway.
  2146. */
  2147. switch (iftype) {
  2148. case NL80211_IFTYPE_AP:
  2149. case NL80211_IFTYPE_AP_VLAN:
  2150. case NL80211_IFTYPE_P2P_GO:
  2151. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  2152. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  2153. BIT(NL80211_STA_FLAG_WME) |
  2154. BIT(NL80211_STA_FLAG_MFP);
  2155. break;
  2156. case NL80211_IFTYPE_P2P_CLIENT:
  2157. case NL80211_IFTYPE_STATION:
  2158. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  2159. BIT(NL80211_STA_FLAG_TDLS_PEER);
  2160. break;
  2161. case NL80211_IFTYPE_MESH_POINT:
  2162. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  2163. BIT(NL80211_STA_FLAG_MFP) |
  2164. BIT(NL80211_STA_FLAG_AUTHORIZED);
  2165. default:
  2166. return -EINVAL;
  2167. }
  2168. for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
  2169. if (flags[flag])
  2170. params->sta_flags_set |= (1<<flag);
  2171. return 0;
  2172. }
  2173. static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
  2174. int attr)
  2175. {
  2176. struct nlattr *rate;
  2177. u32 bitrate;
  2178. u16 bitrate_compat;
  2179. rate = nla_nest_start(msg, attr);
  2180. if (!rate)
  2181. return false;
  2182. /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
  2183. bitrate = cfg80211_calculate_bitrate(info);
  2184. /* report 16-bit bitrate only if we can */
  2185. bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
  2186. if (bitrate > 0 &&
  2187. nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
  2188. return false;
  2189. if (bitrate_compat > 0 &&
  2190. nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
  2191. return false;
  2192. if (info->flags & RATE_INFO_FLAGS_MCS) {
  2193. if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
  2194. return false;
  2195. if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
  2196. nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
  2197. return false;
  2198. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  2199. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  2200. return false;
  2201. } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
  2202. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
  2203. return false;
  2204. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
  2205. return false;
  2206. if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
  2207. nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
  2208. return false;
  2209. if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
  2210. nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
  2211. return false;
  2212. if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
  2213. nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
  2214. return false;
  2215. if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
  2216. nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
  2217. return false;
  2218. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  2219. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  2220. return false;
  2221. }
  2222. nla_nest_end(msg, rate);
  2223. return true;
  2224. }
  2225. static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
  2226. int flags,
  2227. struct cfg80211_registered_device *rdev,
  2228. struct net_device *dev,
  2229. const u8 *mac_addr, struct station_info *sinfo)
  2230. {
  2231. void *hdr;
  2232. struct nlattr *sinfoattr, *bss_param;
  2233. hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
  2234. if (!hdr)
  2235. return -1;
  2236. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  2237. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
  2238. NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
  2239. sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
  2240. if (!sinfoattr)
  2241. goto nla_put_failure;
  2242. if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
  2243. NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
  2244. sinfo->connected_time);
  2245. if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
  2246. NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
  2247. sinfo->inactive_time);
  2248. if (sinfo->filled & STATION_INFO_RX_BYTES)
  2249. NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
  2250. sinfo->rx_bytes);
  2251. if (sinfo->filled & STATION_INFO_TX_BYTES)
  2252. NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
  2253. sinfo->tx_bytes);
  2254. if (sinfo->filled & STATION_INFO_LLID)
  2255. NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
  2256. sinfo->llid);
  2257. if (sinfo->filled & STATION_INFO_PLID)
  2258. NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
  2259. sinfo->plid);
  2260. if (sinfo->filled & STATION_INFO_PLINK_STATE)
  2261. NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
  2262. sinfo->plink_state);
  2263. switch (rdev->wiphy.signal_type) {
  2264. case CFG80211_SIGNAL_TYPE_MBM:
  2265. if (sinfo->filled & STATION_INFO_SIGNAL)
  2266. NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
  2267. sinfo->signal);
  2268. if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
  2269. NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
  2270. sinfo->signal_avg);
  2271. break;
  2272. default:
  2273. break;
  2274. }
  2275. if (sinfo->filled & STATION_INFO_TX_BITRATE) {
  2276. if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
  2277. NL80211_STA_INFO_TX_BITRATE))
  2278. goto nla_put_failure;
  2279. }
  2280. if (sinfo->filled & STATION_INFO_RX_BITRATE) {
  2281. if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
  2282. NL80211_STA_INFO_RX_BITRATE))
  2283. goto nla_put_failure;
  2284. }
  2285. if (sinfo->filled & STATION_INFO_RX_PACKETS)
  2286. NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
  2287. sinfo->rx_packets);
  2288. if (sinfo->filled & STATION_INFO_TX_PACKETS)
  2289. NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
  2290. sinfo->tx_packets);
  2291. if (sinfo->filled & STATION_INFO_TX_RETRIES)
  2292. NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
  2293. sinfo->tx_retries);
  2294. if (sinfo->filled & STATION_INFO_TX_FAILED)
  2295. NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
  2296. sinfo->tx_failed);
  2297. if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT)
  2298. NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS,
  2299. sinfo->beacon_loss_count);
  2300. if (sinfo->filled & STATION_INFO_BSS_PARAM) {
  2301. bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
  2302. if (!bss_param)
  2303. goto nla_put_failure;
  2304. if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
  2305. NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
  2306. if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
  2307. NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
  2308. if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
  2309. NLA_PUT_FLAG(msg,
  2310. NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
  2311. NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
  2312. sinfo->bss_param.dtim_period);
  2313. NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
  2314. sinfo->bss_param.beacon_interval);
  2315. nla_nest_end(msg, bss_param);
  2316. }
  2317. if (sinfo->filled & STATION_INFO_STA_FLAGS)
  2318. NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
  2319. sizeof(struct nl80211_sta_flag_update),
  2320. &sinfo->sta_flags);
  2321. nla_nest_end(msg, sinfoattr);
  2322. if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
  2323. NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
  2324. sinfo->assoc_req_ies);
  2325. return genlmsg_end(msg, hdr);
  2326. nla_put_failure:
  2327. genlmsg_cancel(msg, hdr);
  2328. return -EMSGSIZE;
  2329. }
  2330. static int nl80211_dump_station(struct sk_buff *skb,
  2331. struct netlink_callback *cb)
  2332. {
  2333. struct station_info sinfo;
  2334. struct cfg80211_registered_device *dev;
  2335. struct net_device *netdev;
  2336. u8 mac_addr[ETH_ALEN];
  2337. int sta_idx = cb->args[1];
  2338. int err;
  2339. err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
  2340. if (err)
  2341. return err;
  2342. if (!dev->ops->dump_station) {
  2343. err = -EOPNOTSUPP;
  2344. goto out_err;
  2345. }
  2346. while (1) {
  2347. memset(&sinfo, 0, sizeof(sinfo));
  2348. err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
  2349. mac_addr, &sinfo);
  2350. if (err == -ENOENT)
  2351. break;
  2352. if (err)
  2353. goto out_err;
  2354. if (nl80211_send_station(skb,
  2355. NETLINK_CB(cb->skb).pid,
  2356. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  2357. dev, netdev, mac_addr,
  2358. &sinfo) < 0)
  2359. goto out;
  2360. sta_idx++;
  2361. }
  2362. out:
  2363. cb->args[1] = sta_idx;
  2364. err = skb->len;
  2365. out_err:
  2366. nl80211_finish_netdev_dump(dev);
  2367. return err;
  2368. }
  2369. static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
  2370. {
  2371. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2372. struct net_device *dev = info->user_ptr[1];
  2373. struct station_info sinfo;
  2374. struct sk_buff *msg;
  2375. u8 *mac_addr = NULL;
  2376. int err;
  2377. memset(&sinfo, 0, sizeof(sinfo));
  2378. if (!info->attrs[NL80211_ATTR_MAC])
  2379. return -EINVAL;
  2380. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2381. if (!rdev->ops->get_station)
  2382. return -EOPNOTSUPP;
  2383. err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
  2384. if (err)
  2385. return err;
  2386. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2387. if (!msg)
  2388. return -ENOMEM;
  2389. if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
  2390. rdev, dev, mac_addr, &sinfo) < 0) {
  2391. nlmsg_free(msg);
  2392. return -ENOBUFS;
  2393. }
  2394. return genlmsg_reply(msg, info);
  2395. }
  2396. /*
  2397. * Get vlan interface making sure it is running and on the right wiphy.
  2398. */
  2399. static struct net_device *get_vlan(struct genl_info *info,
  2400. struct cfg80211_registered_device *rdev)
  2401. {
  2402. struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
  2403. struct net_device *v;
  2404. int ret;
  2405. if (!vlanattr)
  2406. return NULL;
  2407. v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
  2408. if (!v)
  2409. return ERR_PTR(-ENODEV);
  2410. if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
  2411. ret = -EINVAL;
  2412. goto error;
  2413. }
  2414. if (!netif_running(v)) {
  2415. ret = -ENETDOWN;
  2416. goto error;
  2417. }
  2418. return v;
  2419. error:
  2420. dev_put(v);
  2421. return ERR_PTR(ret);
  2422. }
  2423. static int nl80211_parse_sta_channel_info(struct genl_info *info,
  2424. struct station_parameters *params)
  2425. {
  2426. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
  2427. params->supported_channels =
  2428. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  2429. params->supported_channels_len =
  2430. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  2431. /*
  2432. * Need to include at least one (first channel, number of
  2433. * channels) tuple for each subband, and must have proper
  2434. * tuples for the rest of the data as well.
  2435. */
  2436. if (params->supported_channels_len < 2)
  2437. return -EINVAL;
  2438. if (params->supported_channels_len % 2)
  2439. return -EINVAL;
  2440. }
  2441. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
  2442. params->supported_oper_classes =
  2443. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  2444. params->supported_oper_classes_len =
  2445. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  2446. /*
  2447. * The value of the Length field of the Supported Operating
  2448. * Classes element is between 2 and 253.
  2449. */
  2450. if (params->supported_oper_classes_len < 2 ||
  2451. params->supported_oper_classes_len > 253)
  2452. return -EINVAL;
  2453. }
  2454. return 0;
  2455. }
  2456. static struct nla_policy
  2457. nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
  2458. [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
  2459. [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
  2460. };
  2461. static int nl80211_set_station_tdls(struct genl_info *info,
  2462. struct station_parameters *params)
  2463. {
  2464. struct nlattr *tb[NL80211_STA_WME_MAX + 1];
  2465. struct nlattr *nla;
  2466. int err;
  2467. /* Dummy STA entry gets updated once the peer capabilities are known */
  2468. if (info->attrs[NL80211_ATTR_PEER_AID])
  2469. params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  2470. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  2471. params->ht_capa =
  2472. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  2473. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  2474. params->vht_capa =
  2475. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  2476. err = nl80211_parse_sta_channel_info(info, params);
  2477. if (err)
  2478. return err;
  2479. /* parse WME attributes if present */
  2480. if (!info->attrs[NL80211_ATTR_STA_WME])
  2481. return 0;
  2482. nla = info->attrs[NL80211_ATTR_STA_WME];
  2483. err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
  2484. nl80211_sta_wme_policy);
  2485. if (err)
  2486. return err;
  2487. if (tb[NL80211_STA_WME_UAPSD_QUEUES])
  2488. params->uapsd_queues = nla_get_u8(
  2489. tb[NL80211_STA_WME_UAPSD_QUEUES]);
  2490. if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  2491. return -EINVAL;
  2492. if (tb[NL80211_STA_WME_MAX_SP])
  2493. params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
  2494. if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  2495. return -EINVAL;
  2496. params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
  2497. return 0;
  2498. }
  2499. static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
  2500. {
  2501. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2502. int err;
  2503. struct net_device *dev = info->user_ptr[1];
  2504. struct station_parameters params;
  2505. u8 *mac_addr = NULL;
  2506. memset(&params, 0, sizeof(params));
  2507. params.listen_interval = -1;
  2508. params.plink_state = -1;
  2509. if (info->attrs[NL80211_ATTR_STA_AID])
  2510. return -EINVAL;
  2511. if (!info->attrs[NL80211_ATTR_MAC])
  2512. return -EINVAL;
  2513. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2514. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
  2515. params.supported_rates =
  2516. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  2517. params.supported_rates_len =
  2518. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  2519. }
  2520. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  2521. params.capability =
  2522. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  2523. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  2524. }
  2525. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  2526. params.ext_capab =
  2527. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  2528. params.ext_capab_len =
  2529. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  2530. }
  2531. if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  2532. params.listen_interval =
  2533. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  2534. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  2535. params.ht_capa =
  2536. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  2537. if (!rdev->ops->change_station)
  2538. return -EOPNOTSUPP;
  2539. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  2540. return -EINVAL;
  2541. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
  2542. params.plink_action =
  2543. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  2544. if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
  2545. params.plink_state =
  2546. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
  2547. switch (dev->ieee80211_ptr->iftype) {
  2548. case NL80211_IFTYPE_AP:
  2549. case NL80211_IFTYPE_AP_VLAN:
  2550. case NL80211_IFTYPE_P2P_GO:
  2551. /* disallow mesh-specific things */
  2552. if (params.plink_action)
  2553. return -EINVAL;
  2554. /* TDLS can't be set, ... */
  2555. if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  2556. return -EINVAL;
  2557. /*
  2558. * ... but don't bother the driver with it. This works around
  2559. * a hostapd/wpa_supplicant issue -- it always includes the
  2560. * TLDS_PEER flag in the mask even for AP mode.
  2561. */
  2562. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  2563. /* accept only the listed bits */
  2564. if (params.sta_flags_mask &
  2565. ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  2566. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  2567. BIT(NL80211_STA_FLAG_WME) |
  2568. BIT(NL80211_STA_FLAG_MFP)))
  2569. return -EINVAL;
  2570. if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
  2571. return -EINVAL;
  2572. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
  2573. return -EINVAL;
  2574. if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
  2575. info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  2576. return -EINVAL;
  2577. /* must be last in here for error handling */
  2578. params.vlan = get_vlan(info, rdev);
  2579. if (IS_ERR(params.vlan))
  2580. return PTR_ERR(params.vlan);
  2581. break;
  2582. case NL80211_IFTYPE_P2P_CLIENT:
  2583. case NL80211_IFTYPE_STATION:
  2584. /*
  2585. * Don't allow userspace to change the TDLS_PEER flag,
  2586. * but silently ignore attempts to change it since we
  2587. * don't have state here to verify that it doesn't try
  2588. * to change the flag.
  2589. */
  2590. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  2591. /* Include parameters for TDLS peer (driver will check) */
  2592. err = nl80211_set_station_tdls(info, &params);
  2593. if (err)
  2594. return err;
  2595. /* disallow things sta doesn't support */
  2596. if (params.plink_action)
  2597. return -EINVAL;
  2598. if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  2599. BIT(NL80211_STA_FLAG_WME)))
  2600. return -EINVAL;
  2601. break;
  2602. case NL80211_IFTYPE_ADHOC:
  2603. /* disallow things sta doesn't support */
  2604. if (params.plink_action)
  2605. return -EINVAL;
  2606. if (params.ht_capa)
  2607. return -EINVAL;
  2608. if (params.listen_interval >= 0)
  2609. return -EINVAL;
  2610. if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
  2611. info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  2612. return -EINVAL;
  2613. /* reject any changes other than AUTHORIZED */
  2614. if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
  2615. return -EINVAL;
  2616. break;
  2617. case NL80211_IFTYPE_MESH_POINT:
  2618. /* disallow things mesh doesn't support */
  2619. if (params.vlan)
  2620. return -EINVAL;
  2621. if (params.ht_capa)
  2622. return -EINVAL;
  2623. if (params.listen_interval >= 0)
  2624. return -EINVAL;
  2625. if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
  2626. return -EINVAL;
  2627. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
  2628. return -EINVAL;
  2629. if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
  2630. info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  2631. return -EINVAL;
  2632. /*
  2633. * No special handling for TDLS here -- the userspace
  2634. * mesh code doesn't have this bug.
  2635. */
  2636. if (params.sta_flags_mask &
  2637. ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  2638. BIT(NL80211_STA_FLAG_MFP) |
  2639. BIT(NL80211_STA_FLAG_AUTHORIZED)))
  2640. return -EINVAL;
  2641. break;
  2642. default:
  2643. return -EOPNOTSUPP;
  2644. }
  2645. /* be aware of params.vlan when changing code here */
  2646. err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, &params);
  2647. if (params.vlan)
  2648. dev_put(params.vlan);
  2649. return err;
  2650. }
  2651. static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
  2652. {
  2653. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2654. int err;
  2655. struct net_device *dev = info->user_ptr[1];
  2656. struct station_parameters params;
  2657. u8 *mac_addr = NULL;
  2658. memset(&params, 0, sizeof(params));
  2659. if (!info->attrs[NL80211_ATTR_MAC])
  2660. return -EINVAL;
  2661. if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  2662. return -EINVAL;
  2663. if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
  2664. return -EINVAL;
  2665. if (!info->attrs[NL80211_ATTR_STA_AID] &&
  2666. !info->attrs[NL80211_ATTR_PEER_AID])
  2667. return -EINVAL;
  2668. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2669. params.supported_rates =
  2670. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  2671. params.supported_rates_len =
  2672. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  2673. params.listen_interval =
  2674. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  2675. if (info->attrs[NL80211_ATTR_PEER_AID])
  2676. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  2677. else
  2678. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
  2679. if (!params.aid || params.aid > IEEE80211_MAX_AID)
  2680. return -EINVAL;
  2681. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  2682. params.capability =
  2683. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  2684. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  2685. }
  2686. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  2687. params.ext_capab =
  2688. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  2689. params.ext_capab_len =
  2690. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  2691. }
  2692. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  2693. params.ht_capa =
  2694. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  2695. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  2696. params.vht_capa =
  2697. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  2698. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
  2699. params.plink_action =
  2700. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  2701. err = nl80211_parse_sta_channel_info(info, &params);
  2702. if (err)
  2703. return err;
  2704. if (!rdev->ops->add_station)
  2705. return -EOPNOTSUPP;
  2706. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  2707. return -EINVAL;
  2708. /* HT requires QoS, but if we don't have that just ignore HT/VHT
  2709. * as userspace might just pass through the capabilities from the IEs
  2710. * directly, rather than enforcing this restriction and returning an
  2711. * error in this case.
  2712. */
  2713. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
  2714. params.ht_capa = NULL;
  2715. switch (dev->ieee80211_ptr->iftype) {
  2716. case NL80211_IFTYPE_AP:
  2717. case NL80211_IFTYPE_AP_VLAN:
  2718. case NL80211_IFTYPE_P2P_GO:
  2719. /* parse WME attributes if sta is WME capable */
  2720. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
  2721. (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
  2722. info->attrs[NL80211_ATTR_STA_WME]) {
  2723. struct nlattr *tb[NL80211_STA_WME_MAX + 1];
  2724. struct nlattr *nla;
  2725. nla = info->attrs[NL80211_ATTR_STA_WME];
  2726. err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
  2727. nl80211_sta_wme_policy);
  2728. if (err)
  2729. return err;
  2730. if (tb[NL80211_STA_WME_UAPSD_QUEUES])
  2731. params.uapsd_queues =
  2732. nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
  2733. if (params.uapsd_queues &
  2734. ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  2735. return -EINVAL;
  2736. if (tb[NL80211_STA_WME_MAX_SP])
  2737. params.max_sp =
  2738. nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
  2739. if (params.max_sp &
  2740. ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  2741. return -EINVAL;
  2742. params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
  2743. }
  2744. /* TDLS peers cannot be added */
  2745. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  2746. info->attrs[NL80211_ATTR_PEER_AID])
  2747. return -EINVAL;
  2748. /* but don't bother the driver with it */
  2749. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  2750. /* must be last in here for error handling */
  2751. params.vlan = get_vlan(info, rdev);
  2752. if (IS_ERR(params.vlan))
  2753. return PTR_ERR(params.vlan);
  2754. break;
  2755. case NL80211_IFTYPE_MESH_POINT:
  2756. /* TDLS peers cannot be added */
  2757. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  2758. info->attrs[NL80211_ATTR_PEER_AID])
  2759. return -EINVAL;
  2760. break;
  2761. case NL80211_IFTYPE_STATION:
  2762. case NL80211_IFTYPE_P2P_CLIENT:
  2763. /* Only TDLS peers can be added */
  2764. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  2765. return -EINVAL;
  2766. /* Can only add if TDLS ... */
  2767. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2768. return -EOPNOTSUPP;
  2769. /* ... with external setup is supported */
  2770. if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
  2771. return -EOPNOTSUPP;
  2772. break;
  2773. default:
  2774. return -EOPNOTSUPP;
  2775. }
  2776. /* be aware of params.vlan when changing code here */
  2777. err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, &params);
  2778. if (params.vlan)
  2779. dev_put(params.vlan);
  2780. return err;
  2781. }
  2782. static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
  2783. {
  2784. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2785. struct net_device *dev = info->user_ptr[1];
  2786. u8 *mac_addr = NULL;
  2787. if (info->attrs[NL80211_ATTR_MAC])
  2788. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2789. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2790. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  2791. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  2792. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2793. return -EINVAL;
  2794. if (!rdev->ops->del_station)
  2795. return -EOPNOTSUPP;
  2796. return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
  2797. }
  2798. static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
  2799. int flags, struct net_device *dev,
  2800. u8 *dst, u8 *next_hop,
  2801. struct mpath_info *pinfo)
  2802. {
  2803. void *hdr;
  2804. struct nlattr *pinfoattr;
  2805. hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
  2806. if (!hdr)
  2807. return -1;
  2808. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  2809. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
  2810. NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
  2811. NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
  2812. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
  2813. if (!pinfoattr)
  2814. goto nla_put_failure;
  2815. if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
  2816. NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
  2817. pinfo->frame_qlen);
  2818. if (pinfo->filled & MPATH_INFO_SN)
  2819. NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
  2820. pinfo->sn);
  2821. if (pinfo->filled & MPATH_INFO_METRIC)
  2822. NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
  2823. pinfo->metric);
  2824. if (pinfo->filled & MPATH_INFO_EXPTIME)
  2825. NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
  2826. pinfo->exptime);
  2827. if (pinfo->filled & MPATH_INFO_FLAGS)
  2828. NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
  2829. pinfo->flags);
  2830. if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
  2831. NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
  2832. pinfo->discovery_timeout);
  2833. if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
  2834. NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
  2835. pinfo->discovery_retries);
  2836. nla_nest_end(msg, pinfoattr);
  2837. return genlmsg_end(msg, hdr);
  2838. nla_put_failure:
  2839. genlmsg_cancel(msg, hdr);
  2840. return -EMSGSIZE;
  2841. }
  2842. static int nl80211_dump_mpath(struct sk_buff *skb,
  2843. struct netlink_callback *cb)
  2844. {
  2845. struct mpath_info pinfo;
  2846. struct cfg80211_registered_device *dev;
  2847. struct net_device *netdev;
  2848. u8 dst[ETH_ALEN];
  2849. u8 next_hop[ETH_ALEN];
  2850. int path_idx = cb->args[1];
  2851. int err;
  2852. err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
  2853. if (err)
  2854. return err;
  2855. if (!dev->ops->dump_mpath) {
  2856. err = -EOPNOTSUPP;
  2857. goto out_err;
  2858. }
  2859. if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
  2860. err = -EOPNOTSUPP;
  2861. goto out_err;
  2862. }
  2863. while (1) {
  2864. err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
  2865. dst, next_hop, &pinfo);
  2866. if (err == -ENOENT)
  2867. break;
  2868. if (err)
  2869. goto out_err;
  2870. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
  2871. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  2872. netdev, dst, next_hop,
  2873. &pinfo) < 0)
  2874. goto out;
  2875. path_idx++;
  2876. }
  2877. out:
  2878. cb->args[1] = path_idx;
  2879. err = skb->len;
  2880. out_err:
  2881. nl80211_finish_netdev_dump(dev);
  2882. return err;
  2883. }
  2884. static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
  2885. {
  2886. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2887. int err;
  2888. struct net_device *dev = info->user_ptr[1];
  2889. struct mpath_info pinfo;
  2890. struct sk_buff *msg;
  2891. u8 *dst = NULL;
  2892. u8 next_hop[ETH_ALEN];
  2893. memset(&pinfo, 0, sizeof(pinfo));
  2894. if (!info->attrs[NL80211_ATTR_MAC])
  2895. return -EINVAL;
  2896. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2897. if (!rdev->ops->get_mpath)
  2898. return -EOPNOTSUPP;
  2899. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  2900. return -EOPNOTSUPP;
  2901. err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
  2902. if (err)
  2903. return err;
  2904. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2905. if (!msg)
  2906. return -ENOMEM;
  2907. if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
  2908. dev, dst, next_hop, &pinfo) < 0) {
  2909. nlmsg_free(msg);
  2910. return -ENOBUFS;
  2911. }
  2912. return genlmsg_reply(msg, info);
  2913. }
  2914. static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
  2915. {
  2916. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2917. struct net_device *dev = info->user_ptr[1];
  2918. u8 *dst = NULL;
  2919. u8 *next_hop = NULL;
  2920. if (!info->attrs[NL80211_ATTR_MAC])
  2921. return -EINVAL;
  2922. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  2923. return -EINVAL;
  2924. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2925. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  2926. if (!rdev->ops->change_mpath)
  2927. return -EOPNOTSUPP;
  2928. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  2929. return -EOPNOTSUPP;
  2930. return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
  2931. }
  2932. static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
  2933. {
  2934. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2935. struct net_device *dev = info->user_ptr[1];
  2936. u8 *dst = NULL;
  2937. u8 *next_hop = NULL;
  2938. if (!info->attrs[NL80211_ATTR_MAC])
  2939. return -EINVAL;
  2940. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  2941. return -EINVAL;
  2942. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2943. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  2944. if (!rdev->ops->add_mpath)
  2945. return -EOPNOTSUPP;
  2946. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  2947. return -EOPNOTSUPP;
  2948. return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
  2949. }
  2950. static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
  2951. {
  2952. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2953. struct net_device *dev = info->user_ptr[1];
  2954. u8 *dst = NULL;
  2955. if (info->attrs[NL80211_ATTR_MAC])
  2956. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2957. if (!rdev->ops->del_mpath)
  2958. return -EOPNOTSUPP;
  2959. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  2960. return -EOPNOTSUPP;
  2961. return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
  2962. }
  2963. static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
  2964. {
  2965. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2966. struct net_device *dev = info->user_ptr[1];
  2967. struct bss_parameters params;
  2968. memset(&params, 0, sizeof(params));
  2969. /* default to not changing parameters */
  2970. params.use_cts_prot = -1;
  2971. params.use_short_preamble = -1;
  2972. params.use_short_slot_time = -1;
  2973. params.ap_isolate = -1;
  2974. params.ht_opmode = -1;
  2975. if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
  2976. params.use_cts_prot =
  2977. nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
  2978. if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
  2979. params.use_short_preamble =
  2980. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
  2981. if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
  2982. params.use_short_slot_time =
  2983. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
  2984. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  2985. params.basic_rates =
  2986. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  2987. params.basic_rates_len =
  2988. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  2989. }
  2990. if (info->attrs[NL80211_ATTR_AP_ISOLATE])
  2991. params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
  2992. if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
  2993. params.ht_opmode =
  2994. nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
  2995. if (!rdev->ops->change_bss)
  2996. return -EOPNOTSUPP;
  2997. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2998. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2999. return -EOPNOTSUPP;
  3000. return rdev->ops->change_bss(&rdev->wiphy, dev, &params);
  3001. }
  3002. static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
  3003. [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
  3004. [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
  3005. [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
  3006. [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
  3007. [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
  3008. [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
  3009. };
  3010. static int parse_reg_rule(struct nlattr *tb[],
  3011. struct ieee80211_reg_rule *reg_rule)
  3012. {
  3013. struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
  3014. struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
  3015. if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
  3016. return -EINVAL;
  3017. if (!tb[NL80211_ATTR_FREQ_RANGE_START])
  3018. return -EINVAL;
  3019. if (!tb[NL80211_ATTR_FREQ_RANGE_END])
  3020. return -EINVAL;
  3021. if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
  3022. return -EINVAL;
  3023. if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
  3024. return -EINVAL;
  3025. reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
  3026. freq_range->start_freq_khz =
  3027. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
  3028. freq_range->end_freq_khz =
  3029. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
  3030. freq_range->max_bandwidth_khz =
  3031. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
  3032. power_rule->max_eirp =
  3033. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
  3034. if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
  3035. power_rule->max_antenna_gain =
  3036. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
  3037. return 0;
  3038. }
  3039. static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
  3040. {
  3041. int r;
  3042. char *data = NULL;
  3043. /*
  3044. * You should only get this when cfg80211 hasn't yet initialized
  3045. * completely when built-in to the kernel right between the time
  3046. * window between nl80211_init() and regulatory_init(), if that is
  3047. * even possible.
  3048. */
  3049. mutex_lock(&cfg80211_mutex);
  3050. if (unlikely(!cfg80211_regdomain)) {
  3051. mutex_unlock(&cfg80211_mutex);
  3052. return -EINPROGRESS;
  3053. }
  3054. mutex_unlock(&cfg80211_mutex);
  3055. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  3056. return -EINVAL;
  3057. data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  3058. r = regulatory_hint_user(data);
  3059. return r;
  3060. }
  3061. static int nl80211_get_mesh_config(struct sk_buff *skb,
  3062. struct genl_info *info)
  3063. {
  3064. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3065. struct net_device *dev = info->user_ptr[1];
  3066. struct wireless_dev *wdev = dev->ieee80211_ptr;
  3067. struct mesh_config cur_params;
  3068. int err = 0;
  3069. void *hdr;
  3070. struct nlattr *pinfoattr;
  3071. struct sk_buff *msg;
  3072. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  3073. return -EOPNOTSUPP;
  3074. if (!rdev->ops->get_mesh_config)
  3075. return -EOPNOTSUPP;
  3076. wdev_lock(wdev);
  3077. /* If not connected, get default parameters */
  3078. if (!wdev->mesh_id_len)
  3079. memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
  3080. else
  3081. err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
  3082. &cur_params);
  3083. wdev_unlock(wdev);
  3084. if (err)
  3085. return err;
  3086. /* Draw up a netlink message to send back */
  3087. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3088. if (!msg)
  3089. return -ENOMEM;
  3090. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  3091. NL80211_CMD_GET_MESH_CONFIG);
  3092. if (!hdr)
  3093. goto out;
  3094. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
  3095. if (!pinfoattr)
  3096. goto nla_put_failure;
  3097. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  3098. NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
  3099. cur_params.dot11MeshRetryTimeout);
  3100. NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  3101. cur_params.dot11MeshConfirmTimeout);
  3102. NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
  3103. cur_params.dot11MeshHoldingTimeout);
  3104. NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
  3105. cur_params.dot11MeshMaxPeerLinks);
  3106. NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
  3107. cur_params.dot11MeshMaxRetries);
  3108. NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
  3109. cur_params.dot11MeshTTL);
  3110. NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
  3111. cur_params.element_ttl);
  3112. NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  3113. cur_params.auto_open_plinks);
  3114. NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  3115. cur_params.dot11MeshHWMPmaxPREQretries);
  3116. NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
  3117. cur_params.path_refresh_time);
  3118. NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  3119. cur_params.min_discovery_timeout);
  3120. NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  3121. cur_params.dot11MeshHWMPactivePathTimeout);
  3122. NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  3123. cur_params.dot11MeshHWMPpreqMinInterval);
  3124. NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  3125. cur_params.dot11MeshHWMPperrMinInterval);
  3126. NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  3127. cur_params.dot11MeshHWMPnetDiameterTraversalTime);
  3128. NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
  3129. cur_params.dot11MeshHWMPRootMode);
  3130. NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  3131. cur_params.dot11MeshHWMPRannInterval);
  3132. NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  3133. cur_params.dot11MeshGateAnnouncementProtocol);
  3134. NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING,
  3135. cur_params.dot11MeshForwarding);
  3136. NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
  3137. cur_params.rssi_threshold);
  3138. nla_nest_end(msg, pinfoattr);
  3139. genlmsg_end(msg, hdr);
  3140. return genlmsg_reply(msg, info);
  3141. nla_put_failure:
  3142. genlmsg_cancel(msg, hdr);
  3143. out:
  3144. nlmsg_free(msg);
  3145. return -ENOBUFS;
  3146. }
  3147. static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
  3148. [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
  3149. [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
  3150. [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
  3151. [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
  3152. [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
  3153. [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
  3154. [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
  3155. [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
  3156. [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
  3157. [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
  3158. [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
  3159. [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
  3160. [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
  3161. [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
  3162. [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
  3163. [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
  3164. [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
  3165. [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
  3166. [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
  3167. [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32},
  3168. };
  3169. static const struct nla_policy
  3170. nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
  3171. [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
  3172. [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
  3173. [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
  3174. [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
  3175. .len = IEEE80211_MAX_DATA_LEN },
  3176. [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
  3177. };
  3178. static int nl80211_parse_mesh_config(struct genl_info *info,
  3179. struct mesh_config *cfg,
  3180. u32 *mask_out)
  3181. {
  3182. struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
  3183. u32 mask = 0;
  3184. #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
  3185. do {\
  3186. if (table[attr_num]) {\
  3187. cfg->param = nla_fn(table[attr_num]); \
  3188. mask |= (1 << (attr_num - 1)); \
  3189. } \
  3190. } while (0);\
  3191. if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
  3192. return -EINVAL;
  3193. if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
  3194. info->attrs[NL80211_ATTR_MESH_CONFIG],
  3195. nl80211_meshconf_params_policy))
  3196. return -EINVAL;
  3197. /* This makes sure that there aren't more than 32 mesh config
  3198. * parameters (otherwise our bitfield scheme would not work.) */
  3199. BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
  3200. /* Fill in the params struct */
  3201. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
  3202. mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
  3203. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
  3204. mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
  3205. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
  3206. mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
  3207. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
  3208. mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
  3209. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
  3210. mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
  3211. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
  3212. mask, NL80211_MESHCONF_TTL, nla_get_u8);
  3213. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
  3214. mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
  3215. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
  3216. mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
  3217. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
  3218. mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  3219. nla_get_u8);
  3220. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
  3221. mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
  3222. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
  3223. mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  3224. nla_get_u16);
  3225. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
  3226. mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  3227. nla_get_u32);
  3228. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
  3229. mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  3230. nla_get_u16);
  3231. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
  3232. mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  3233. nla_get_u16);
  3234. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  3235. dot11MeshHWMPnetDiameterTraversalTime,
  3236. mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  3237. nla_get_u16);
  3238. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  3239. dot11MeshHWMPRootMode, mask,
  3240. NL80211_MESHCONF_HWMP_ROOTMODE,
  3241. nla_get_u8);
  3242. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  3243. dot11MeshHWMPRannInterval, mask,
  3244. NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  3245. nla_get_u16);
  3246. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  3247. dot11MeshGateAnnouncementProtocol, mask,
  3248. NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  3249. nla_get_u8);
  3250. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
  3251. mask, NL80211_MESHCONF_FORWARDING, nla_get_u8);
  3252. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
  3253. mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32);
  3254. if (mask_out)
  3255. *mask_out = mask;
  3256. return 0;
  3257. #undef FILL_IN_MESH_PARAM_IF_SET
  3258. }
  3259. static int nl80211_parse_mesh_setup(struct genl_info *info,
  3260. struct mesh_setup *setup)
  3261. {
  3262. struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
  3263. if (!info->attrs[NL80211_ATTR_MESH_SETUP])
  3264. return -EINVAL;
  3265. if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
  3266. info->attrs[NL80211_ATTR_MESH_SETUP],
  3267. nl80211_mesh_setup_params_policy))
  3268. return -EINVAL;
  3269. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
  3270. setup->path_sel_proto =
  3271. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
  3272. IEEE80211_PATH_PROTOCOL_VENDOR :
  3273. IEEE80211_PATH_PROTOCOL_HWMP;
  3274. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
  3275. setup->path_metric =
  3276. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
  3277. IEEE80211_PATH_METRIC_VENDOR :
  3278. IEEE80211_PATH_METRIC_AIRTIME;
  3279. if (tb[NL80211_MESH_SETUP_IE]) {
  3280. struct nlattr *ieattr =
  3281. tb[NL80211_MESH_SETUP_IE];
  3282. if (!is_valid_ie_attr(ieattr))
  3283. return -EINVAL;
  3284. setup->ie = nla_data(ieattr);
  3285. setup->ie_len = nla_len(ieattr);
  3286. }
  3287. setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
  3288. setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
  3289. return 0;
  3290. }
  3291. static int nl80211_update_mesh_config(struct sk_buff *skb,
  3292. struct genl_info *info)
  3293. {
  3294. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3295. struct net_device *dev = info->user_ptr[1];
  3296. struct wireless_dev *wdev = dev->ieee80211_ptr;
  3297. struct mesh_config cfg;
  3298. u32 mask;
  3299. int err;
  3300. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  3301. return -EOPNOTSUPP;
  3302. if (!rdev->ops->update_mesh_config)
  3303. return -EOPNOTSUPP;
  3304. err = nl80211_parse_mesh_config(info, &cfg, &mask);
  3305. if (err)
  3306. return err;
  3307. wdev_lock(wdev);
  3308. if (!wdev->mesh_id_len)
  3309. err = -ENOLINK;
  3310. if (!err)
  3311. err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
  3312. mask, &cfg);
  3313. wdev_unlock(wdev);
  3314. return err;
  3315. }
  3316. static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
  3317. {
  3318. struct sk_buff *msg;
  3319. void *hdr = NULL;
  3320. struct nlattr *nl_reg_rules;
  3321. unsigned int i;
  3322. int err = -EINVAL;
  3323. mutex_lock(&cfg80211_mutex);
  3324. if (!cfg80211_regdomain)
  3325. goto out;
  3326. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3327. if (!msg) {
  3328. err = -ENOBUFS;
  3329. goto out;
  3330. }
  3331. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  3332. NL80211_CMD_GET_REG);
  3333. if (!hdr)
  3334. goto put_failure;
  3335. NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
  3336. cfg80211_regdomain->alpha2);
  3337. if (cfg80211_regdomain->dfs_region)
  3338. NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
  3339. cfg80211_regdomain->dfs_region);
  3340. nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
  3341. if (!nl_reg_rules)
  3342. goto nla_put_failure;
  3343. for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
  3344. struct nlattr *nl_reg_rule;
  3345. const struct ieee80211_reg_rule *reg_rule;
  3346. const struct ieee80211_freq_range *freq_range;
  3347. const struct ieee80211_power_rule *power_rule;
  3348. reg_rule = &cfg80211_regdomain->reg_rules[i];
  3349. freq_range = &reg_rule->freq_range;
  3350. power_rule = &reg_rule->power_rule;
  3351. nl_reg_rule = nla_nest_start(msg, i);
  3352. if (!nl_reg_rule)
  3353. goto nla_put_failure;
  3354. NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
  3355. reg_rule->flags);
  3356. NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
  3357. freq_range->start_freq_khz);
  3358. NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
  3359. freq_range->end_freq_khz);
  3360. NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
  3361. freq_range->max_bandwidth_khz);
  3362. NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
  3363. power_rule->max_antenna_gain);
  3364. NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
  3365. power_rule->max_eirp);
  3366. nla_nest_end(msg, nl_reg_rule);
  3367. }
  3368. nla_nest_end(msg, nl_reg_rules);
  3369. genlmsg_end(msg, hdr);
  3370. err = genlmsg_reply(msg, info);
  3371. goto out;
  3372. nla_put_failure:
  3373. genlmsg_cancel(msg, hdr);
  3374. put_failure:
  3375. nlmsg_free(msg);
  3376. err = -EMSGSIZE;
  3377. out:
  3378. mutex_unlock(&cfg80211_mutex);
  3379. return err;
  3380. }
  3381. static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
  3382. {
  3383. struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
  3384. struct nlattr *nl_reg_rule;
  3385. char *alpha2 = NULL;
  3386. int rem_reg_rules = 0, r = 0;
  3387. u32 num_rules = 0, rule_idx = 0, size_of_regd;
  3388. u8 dfs_region = 0;
  3389. struct ieee80211_regdomain *rd = NULL;
  3390. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  3391. return -EINVAL;
  3392. if (!info->attrs[NL80211_ATTR_REG_RULES])
  3393. return -EINVAL;
  3394. alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  3395. if (info->attrs[NL80211_ATTR_DFS_REGION])
  3396. dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
  3397. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  3398. rem_reg_rules) {
  3399. num_rules++;
  3400. if (num_rules > NL80211_MAX_SUPP_REG_RULES)
  3401. return -EINVAL;
  3402. }
  3403. mutex_lock(&cfg80211_mutex);
  3404. if (!reg_is_valid_request(alpha2)) {
  3405. r = -EINVAL;
  3406. goto bad_reg;
  3407. }
  3408. size_of_regd = sizeof(struct ieee80211_regdomain) +
  3409. (num_rules * sizeof(struct ieee80211_reg_rule));
  3410. rd = kzalloc(size_of_regd, GFP_KERNEL);
  3411. if (!rd) {
  3412. r = -ENOMEM;
  3413. goto bad_reg;
  3414. }
  3415. rd->n_reg_rules = num_rules;
  3416. rd->alpha2[0] = alpha2[0];
  3417. rd->alpha2[1] = alpha2[1];
  3418. /*
  3419. * Disable DFS master mode if the DFS region was
  3420. * not supported or known on this kernel.
  3421. */
  3422. if (reg_supported_dfs_region(dfs_region))
  3423. rd->dfs_region = dfs_region;
  3424. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  3425. rem_reg_rules) {
  3426. nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
  3427. nla_data(nl_reg_rule), nla_len(nl_reg_rule),
  3428. reg_rule_policy);
  3429. r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
  3430. if (r)
  3431. goto bad_reg;
  3432. rule_idx++;
  3433. if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
  3434. r = -EINVAL;
  3435. goto bad_reg;
  3436. }
  3437. }
  3438. BUG_ON(rule_idx != num_rules);
  3439. r = set_regdom(rd);
  3440. mutex_unlock(&cfg80211_mutex);
  3441. return r;
  3442. bad_reg:
  3443. mutex_unlock(&cfg80211_mutex);
  3444. kfree(rd);
  3445. return r;
  3446. }
  3447. static int validate_scan_freqs(struct nlattr *freqs)
  3448. {
  3449. struct nlattr *attr1, *attr2;
  3450. int n_channels = 0, tmp1, tmp2;
  3451. nla_for_each_nested(attr1, freqs, tmp1) {
  3452. n_channels++;
  3453. /*
  3454. * Some hardware has a limited channel list for
  3455. * scanning, and it is pretty much nonsensical
  3456. * to scan for a channel twice, so disallow that
  3457. * and don't require drivers to check that the
  3458. * channel list they get isn't longer than what
  3459. * they can scan, as long as they can scan all
  3460. * the channels they registered at once.
  3461. */
  3462. nla_for_each_nested(attr2, freqs, tmp2)
  3463. if (attr1 != attr2 &&
  3464. nla_get_u32(attr1) == nla_get_u32(attr2))
  3465. return 0;
  3466. }
  3467. return n_channels;
  3468. }
  3469. static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
  3470. {
  3471. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3472. struct net_device *dev = info->user_ptr[1];
  3473. struct cfg80211_scan_request *request;
  3474. struct nlattr *attr;
  3475. struct wiphy *wiphy;
  3476. int err, tmp, n_ssids = 0, n_channels, i;
  3477. size_t ie_len;
  3478. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  3479. return -EINVAL;
  3480. wiphy = &rdev->wiphy;
  3481. if (!rdev->ops->scan)
  3482. return -EOPNOTSUPP;
  3483. if (rdev->scan_req)
  3484. return -EBUSY;
  3485. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  3486. n_channels = validate_scan_freqs(
  3487. info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  3488. if (!n_channels)
  3489. return -EINVAL;
  3490. } else {
  3491. enum ieee80211_band band;
  3492. n_channels = 0;
  3493. for (band = 0; band < IEEE80211_NUM_BANDS; band++)
  3494. if (wiphy->bands[band])
  3495. n_channels += wiphy->bands[band]->n_channels;
  3496. }
  3497. if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
  3498. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
  3499. n_ssids++;
  3500. if (n_ssids > wiphy->max_scan_ssids)
  3501. return -EINVAL;
  3502. if (info->attrs[NL80211_ATTR_IE])
  3503. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  3504. else
  3505. ie_len = 0;
  3506. if (ie_len > wiphy->max_scan_ie_len)
  3507. return -EINVAL;
  3508. request = kzalloc(sizeof(*request)
  3509. + sizeof(*request->ssids) * n_ssids
  3510. + sizeof(*request->channels) * n_channels
  3511. + ie_len, GFP_KERNEL);
  3512. if (!request)
  3513. return -ENOMEM;
  3514. if (n_ssids)
  3515. request->ssids = (void *)&request->channels[n_channels];
  3516. request->n_ssids = n_ssids;
  3517. if (ie_len) {
  3518. if (request->ssids)
  3519. request->ie = (void *)(request->ssids + n_ssids);
  3520. else
  3521. request->ie = (void *)(request->channels + n_channels);
  3522. }
  3523. i = 0;
  3524. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  3525. /* user specified, bail out if channel not found */
  3526. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
  3527. struct ieee80211_channel *chan;
  3528. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  3529. if (!chan) {
  3530. err = -EINVAL;
  3531. goto out_free;
  3532. }
  3533. /* ignore disabled channels */
  3534. if (chan->flags & IEEE80211_CHAN_DISABLED)
  3535. continue;
  3536. request->channels[i] = chan;
  3537. i++;
  3538. }
  3539. } else {
  3540. enum ieee80211_band band;
  3541. /* all channels */
  3542. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  3543. int j;
  3544. if (!wiphy->bands[band])
  3545. continue;
  3546. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  3547. struct ieee80211_channel *chan;
  3548. chan = &wiphy->bands[band]->channels[j];
  3549. if (chan->flags & IEEE80211_CHAN_DISABLED)
  3550. continue;
  3551. request->channels[i] = chan;
  3552. i++;
  3553. }
  3554. }
  3555. }
  3556. if (!i) {
  3557. err = -EINVAL;
  3558. goto out_free;
  3559. }
  3560. request->n_channels = i;
  3561. i = 0;
  3562. if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
  3563. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
  3564. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  3565. err = -EINVAL;
  3566. goto out_free;
  3567. }
  3568. request->ssids[i].ssid_len = nla_len(attr);
  3569. memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
  3570. i++;
  3571. }
  3572. }
  3573. if (info->attrs[NL80211_ATTR_IE]) {
  3574. request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  3575. memcpy((void *)request->ie,
  3576. nla_data(info->attrs[NL80211_ATTR_IE]),
  3577. request->ie_len);
  3578. }
  3579. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  3580. if (wiphy->bands[i])
  3581. request->rates[i] =
  3582. (1 << wiphy->bands[i]->n_bitrates) - 1;
  3583. if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
  3584. nla_for_each_nested(attr,
  3585. info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
  3586. tmp) {
  3587. enum ieee80211_band band = nla_type(attr);
  3588. if (band < 0 || band >= IEEE80211_NUM_BANDS) {
  3589. err = -EINVAL;
  3590. goto out_free;
  3591. }
  3592. err = ieee80211_get_ratemask(wiphy->bands[band],
  3593. nla_data(attr),
  3594. nla_len(attr),
  3595. &request->rates[band]);
  3596. if (err)
  3597. goto out_free;
  3598. }
  3599. }
  3600. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  3601. if (wiphy->bands[i])
  3602. request->rates[i] =
  3603. (1 << wiphy->bands[i]->n_bitrates) - 1;
  3604. if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
  3605. nla_for_each_nested(attr,
  3606. info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
  3607. tmp) {
  3608. enum ieee80211_band band = nla_type(attr);
  3609. if (band < 0 || band >= IEEE80211_NUM_BANDS) {
  3610. err = -EINVAL;
  3611. goto out_free;
  3612. }
  3613. if (!wiphy->bands[band])
  3614. continue;
  3615. err = ieee80211_get_ratemask(wiphy->bands[band],
  3616. nla_data(attr),
  3617. nla_len(attr),
  3618. &request->rates[band]);
  3619. if (err)
  3620. goto out_free;
  3621. }
  3622. }
  3623. request->no_cck =
  3624. nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  3625. request->dev = dev;
  3626. request->wiphy = &rdev->wiphy;
  3627. request->no_cck =
  3628. nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  3629. rdev->scan_req = request;
  3630. err = rdev->ops->scan(&rdev->wiphy, dev, request);
  3631. if (!err) {
  3632. nl80211_send_scan_start(rdev, dev);
  3633. dev_hold(dev);
  3634. } else {
  3635. out_free:
  3636. rdev->scan_req = NULL;
  3637. kfree(request);
  3638. }
  3639. return err;
  3640. }
  3641. static int nl80211_start_sched_scan(struct sk_buff *skb,
  3642. struct genl_info *info)
  3643. {
  3644. struct cfg80211_sched_scan_request *request;
  3645. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3646. struct net_device *dev = info->user_ptr[1];
  3647. struct nlattr *attr;
  3648. struct wiphy *wiphy;
  3649. int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
  3650. u32 interval;
  3651. enum ieee80211_band band;
  3652. size_t ie_len;
  3653. struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
  3654. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  3655. !rdev->ops->sched_scan_start)
  3656. return -EOPNOTSUPP;
  3657. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  3658. return -EINVAL;
  3659. if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  3660. return -EINVAL;
  3661. interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
  3662. if (interval == 0)
  3663. return -EINVAL;
  3664. wiphy = &rdev->wiphy;
  3665. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  3666. n_channels = validate_scan_freqs(
  3667. info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  3668. if (!n_channels)
  3669. return -EINVAL;
  3670. } else {
  3671. n_channels = 0;
  3672. for (band = 0; band < IEEE80211_NUM_BANDS; band++)
  3673. if (wiphy->bands[band])
  3674. n_channels += wiphy->bands[band]->n_channels;
  3675. }
  3676. if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
  3677. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
  3678. tmp)
  3679. n_ssids++;
  3680. if (n_ssids > wiphy->max_sched_scan_ssids)
  3681. return -EINVAL;
  3682. if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
  3683. nla_for_each_nested(attr,
  3684. info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  3685. tmp)
  3686. n_match_sets++;
  3687. if (n_match_sets > wiphy->max_match_sets)
  3688. return -EINVAL;
  3689. if (info->attrs[NL80211_ATTR_IE])
  3690. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  3691. else
  3692. ie_len = 0;
  3693. if (ie_len > wiphy->max_sched_scan_ie_len)
  3694. return -EINVAL;
  3695. mutex_lock(&rdev->sched_scan_mtx);
  3696. if (rdev->sched_scan_req) {
  3697. err = -EINPROGRESS;
  3698. goto out;
  3699. }
  3700. request = kzalloc(sizeof(*request)
  3701. + sizeof(*request->ssids) * n_ssids
  3702. + sizeof(*request->match_sets) * n_match_sets
  3703. + sizeof(*request->channels) * n_channels
  3704. + ie_len, GFP_KERNEL);
  3705. if (!request) {
  3706. err = -ENOMEM;
  3707. goto out;
  3708. }
  3709. if (n_ssids)
  3710. request->ssids = (void *)&request->channels[n_channels];
  3711. request->n_ssids = n_ssids;
  3712. if (ie_len) {
  3713. if (request->ssids)
  3714. request->ie = (void *)(request->ssids + n_ssids);
  3715. else
  3716. request->ie = (void *)(request->channels + n_channels);
  3717. }
  3718. if (n_match_sets) {
  3719. if (request->ie)
  3720. request->match_sets = (void *)(request->ie + ie_len);
  3721. else if (request->ssids)
  3722. request->match_sets =
  3723. (void *)(request->ssids + n_ssids);
  3724. else
  3725. request->match_sets =
  3726. (void *)(request->channels + n_channels);
  3727. }
  3728. request->n_match_sets = n_match_sets;
  3729. i = 0;
  3730. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  3731. /* user specified, bail out if channel not found */
  3732. nla_for_each_nested(attr,
  3733. info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
  3734. tmp) {
  3735. struct ieee80211_channel *chan;
  3736. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  3737. if (!chan) {
  3738. err = -EINVAL;
  3739. goto out_free;
  3740. }
  3741. /* ignore disabled channels */
  3742. if (chan->flags & IEEE80211_CHAN_DISABLED)
  3743. continue;
  3744. request->channels[i] = chan;
  3745. i++;
  3746. }
  3747. } else {
  3748. /* all channels */
  3749. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  3750. int j;
  3751. if (!wiphy->bands[band])
  3752. continue;
  3753. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  3754. struct ieee80211_channel *chan;
  3755. chan = &wiphy->bands[band]->channels[j];
  3756. if (chan->flags & IEEE80211_CHAN_DISABLED)
  3757. continue;
  3758. request->channels[i] = chan;
  3759. i++;
  3760. }
  3761. }
  3762. }
  3763. if (!i) {
  3764. err = -EINVAL;
  3765. goto out_free;
  3766. }
  3767. request->n_channels = i;
  3768. i = 0;
  3769. if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
  3770. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
  3771. tmp) {
  3772. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  3773. err = -EINVAL;
  3774. goto out_free;
  3775. }
  3776. request->ssids[i].ssid_len = nla_len(attr);
  3777. memcpy(request->ssids[i].ssid, nla_data(attr),
  3778. nla_len(attr));
  3779. i++;
  3780. }
  3781. }
  3782. i = 0;
  3783. if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  3784. nla_for_each_nested(attr,
  3785. info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  3786. tmp) {
  3787. struct nlattr *ssid;
  3788. nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  3789. nla_data(attr), nla_len(attr),
  3790. nl80211_match_policy);
  3791. ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
  3792. if (ssid) {
  3793. if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
  3794. err = -EINVAL;
  3795. goto out_free;
  3796. }
  3797. memcpy(request->match_sets[i].ssid.ssid,
  3798. nla_data(ssid), nla_len(ssid));
  3799. request->match_sets[i].ssid.ssid_len =
  3800. nla_len(ssid);
  3801. }
  3802. i++;
  3803. }
  3804. }
  3805. if (info->attrs[NL80211_ATTR_IE]) {
  3806. request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  3807. memcpy((void *)request->ie,
  3808. nla_data(info->attrs[NL80211_ATTR_IE]),
  3809. request->ie_len);
  3810. }
  3811. request->dev = dev;
  3812. request->wiphy = &rdev->wiphy;
  3813. request->interval = interval;
  3814. err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
  3815. if (!err) {
  3816. rdev->sched_scan_req = request;
  3817. nl80211_send_sched_scan(rdev, dev,
  3818. NL80211_CMD_START_SCHED_SCAN);
  3819. goto out;
  3820. }
  3821. out_free:
  3822. kfree(request);
  3823. out:
  3824. mutex_unlock(&rdev->sched_scan_mtx);
  3825. return err;
  3826. }
  3827. static int nl80211_stop_sched_scan(struct sk_buff *skb,
  3828. struct genl_info *info)
  3829. {
  3830. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3831. int err;
  3832. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  3833. !rdev->ops->sched_scan_stop)
  3834. return -EOPNOTSUPP;
  3835. mutex_lock(&rdev->sched_scan_mtx);
  3836. err = __cfg80211_stop_sched_scan(rdev, false);
  3837. mutex_unlock(&rdev->sched_scan_mtx);
  3838. return err;
  3839. }
  3840. static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
  3841. u32 seq, int flags,
  3842. struct cfg80211_registered_device *rdev,
  3843. struct wireless_dev *wdev,
  3844. struct cfg80211_internal_bss *intbss)
  3845. {
  3846. struct cfg80211_bss *res = &intbss->pub;
  3847. void *hdr;
  3848. struct nlattr *bss;
  3849. ASSERT_WDEV_LOCK(wdev);
  3850. hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
  3851. NL80211_CMD_NEW_SCAN_RESULTS);
  3852. if (!hdr)
  3853. return -1;
  3854. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  3855. NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
  3856. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
  3857. bss = nla_nest_start(msg, NL80211_ATTR_BSS);
  3858. if (!bss)
  3859. goto nla_put_failure;
  3860. if (!is_zero_ether_addr(res->bssid))
  3861. NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
  3862. if (res->information_elements && res->len_information_elements)
  3863. NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
  3864. res->len_information_elements,
  3865. res->information_elements);
  3866. if (res->beacon_ies && res->len_beacon_ies &&
  3867. res->beacon_ies != res->information_elements)
  3868. NLA_PUT(msg, NL80211_BSS_BEACON_IES,
  3869. res->len_beacon_ies, res->beacon_ies);
  3870. if (res->tsf)
  3871. NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
  3872. if (res->beacon_interval)
  3873. NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
  3874. NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
  3875. NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
  3876. NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
  3877. jiffies_to_msecs(jiffies - intbss->ts));
  3878. switch (rdev->wiphy.signal_type) {
  3879. case CFG80211_SIGNAL_TYPE_MBM:
  3880. NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
  3881. break;
  3882. case CFG80211_SIGNAL_TYPE_UNSPEC:
  3883. NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
  3884. break;
  3885. default:
  3886. break;
  3887. }
  3888. switch (wdev->iftype) {
  3889. case NL80211_IFTYPE_P2P_CLIENT:
  3890. case NL80211_IFTYPE_STATION:
  3891. if (intbss == wdev->current_bss)
  3892. NLA_PUT_U32(msg, NL80211_BSS_STATUS,
  3893. NL80211_BSS_STATUS_ASSOCIATED);
  3894. break;
  3895. case NL80211_IFTYPE_ADHOC:
  3896. if (intbss == wdev->current_bss)
  3897. NLA_PUT_U32(msg, NL80211_BSS_STATUS,
  3898. NL80211_BSS_STATUS_IBSS_JOINED);
  3899. break;
  3900. default:
  3901. break;
  3902. }
  3903. nla_nest_end(msg, bss);
  3904. return genlmsg_end(msg, hdr);
  3905. nla_put_failure:
  3906. genlmsg_cancel(msg, hdr);
  3907. return -EMSGSIZE;
  3908. }
  3909. static int nl80211_dump_scan(struct sk_buff *skb,
  3910. struct netlink_callback *cb)
  3911. {
  3912. struct cfg80211_registered_device *rdev;
  3913. struct net_device *dev;
  3914. struct cfg80211_internal_bss *scan;
  3915. struct wireless_dev *wdev;
  3916. int start = cb->args[1], idx = 0;
  3917. int err;
  3918. err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
  3919. if (err)
  3920. return err;
  3921. wdev = dev->ieee80211_ptr;
  3922. wdev_lock(wdev);
  3923. spin_lock_bh(&rdev->bss_lock);
  3924. cfg80211_bss_expire(rdev);
  3925. cb->seq = rdev->bss_generation;
  3926. list_for_each_entry(scan, &rdev->bss_list, list) {
  3927. if (++idx <= start)
  3928. continue;
  3929. if (nl80211_send_bss(skb, cb,
  3930. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  3931. rdev, wdev, scan) < 0) {
  3932. idx--;
  3933. break;
  3934. }
  3935. }
  3936. spin_unlock_bh(&rdev->bss_lock);
  3937. wdev_unlock(wdev);
  3938. cb->args[1] = idx;
  3939. nl80211_finish_netdev_dump(rdev);
  3940. return skb->len;
  3941. }
  3942. static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
  3943. int flags, struct net_device *dev,
  3944. struct survey_info *survey)
  3945. {
  3946. void *hdr;
  3947. struct nlattr *infoattr;
  3948. hdr = nl80211hdr_put(msg, pid, seq, flags,
  3949. NL80211_CMD_NEW_SURVEY_RESULTS);
  3950. if (!hdr)
  3951. return -ENOMEM;
  3952. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  3953. infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
  3954. if (!infoattr)
  3955. goto nla_put_failure;
  3956. NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
  3957. survey->channel->center_freq);
  3958. if (survey->filled & SURVEY_INFO_NOISE_DBM)
  3959. NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
  3960. survey->noise);
  3961. if (survey->filled & SURVEY_INFO_IN_USE)
  3962. NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
  3963. if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
  3964. NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
  3965. survey->channel_time);
  3966. if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
  3967. NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
  3968. survey->channel_time_busy);
  3969. if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
  3970. NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
  3971. survey->channel_time_ext_busy);
  3972. if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
  3973. NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
  3974. survey->channel_time_rx);
  3975. if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
  3976. NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
  3977. survey->channel_time_tx);
  3978. nla_nest_end(msg, infoattr);
  3979. return genlmsg_end(msg, hdr);
  3980. nla_put_failure:
  3981. genlmsg_cancel(msg, hdr);
  3982. return -EMSGSIZE;
  3983. }
  3984. static int nl80211_dump_survey(struct sk_buff *skb,
  3985. struct netlink_callback *cb)
  3986. {
  3987. struct survey_info survey;
  3988. struct cfg80211_registered_device *dev;
  3989. struct net_device *netdev;
  3990. int survey_idx = cb->args[1];
  3991. int res;
  3992. res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
  3993. if (res)
  3994. return res;
  3995. if (!dev->ops->dump_survey) {
  3996. res = -EOPNOTSUPP;
  3997. goto out_err;
  3998. }
  3999. while (1) {
  4000. struct ieee80211_channel *chan;
  4001. res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
  4002. &survey);
  4003. if (res == -ENOENT)
  4004. break;
  4005. if (res)
  4006. goto out_err;
  4007. /* Survey without a channel doesn't make sense */
  4008. if (!survey.channel) {
  4009. res = -EINVAL;
  4010. goto out;
  4011. }
  4012. chan = ieee80211_get_channel(&dev->wiphy,
  4013. survey.channel->center_freq);
  4014. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
  4015. survey_idx++;
  4016. continue;
  4017. }
  4018. if (nl80211_send_survey(skb,
  4019. NETLINK_CB(cb->skb).pid,
  4020. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4021. netdev,
  4022. &survey) < 0)
  4023. goto out;
  4024. survey_idx++;
  4025. }
  4026. out:
  4027. cb->args[1] = survey_idx;
  4028. res = skb->len;
  4029. out_err:
  4030. nl80211_finish_netdev_dump(dev);
  4031. return res;
  4032. }
  4033. static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
  4034. {
  4035. return auth_type <= NL80211_AUTHTYPE_MAX;
  4036. }
  4037. static bool nl80211_valid_wpa_versions(u32 wpa_versions)
  4038. {
  4039. return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
  4040. NL80211_WPA_VERSION_2 |
  4041. /*SEC_PRODUCT_FEATURE_WLAN_SUPPORT_WAPI*/
  4042. NL80211_WAPI_VERSION_1 ));
  4043. }
  4044. static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
  4045. {
  4046. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4047. struct net_device *dev = info->user_ptr[1];
  4048. struct ieee80211_channel *chan;
  4049. const u8 *bssid, *ssid, *ie = NULL;
  4050. int err, ssid_len, ie_len = 0;
  4051. enum nl80211_auth_type auth_type;
  4052. struct key_parse key;
  4053. bool local_state_change;
  4054. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4055. return -EINVAL;
  4056. if (!info->attrs[NL80211_ATTR_MAC])
  4057. return -EINVAL;
  4058. if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
  4059. return -EINVAL;
  4060. if (!info->attrs[NL80211_ATTR_SSID])
  4061. return -EINVAL;
  4062. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  4063. return -EINVAL;
  4064. err = nl80211_parse_key(info, &key);
  4065. if (err)
  4066. return err;
  4067. if (key.idx >= 0) {
  4068. if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
  4069. return -EINVAL;
  4070. if (!key.p.key || !key.p.key_len)
  4071. return -EINVAL;
  4072. if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
  4073. key.p.key_len != WLAN_KEY_LEN_WEP40) &&
  4074. (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
  4075. key.p.key_len != WLAN_KEY_LEN_WEP104))
  4076. return -EINVAL;
  4077. if (key.idx > 4)
  4078. return -EINVAL;
  4079. } else {
  4080. key.p.key_len = 0;
  4081. key.p.key = NULL;
  4082. }
  4083. if (key.idx >= 0) {
  4084. int i;
  4085. bool ok = false;
  4086. for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
  4087. if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
  4088. ok = true;
  4089. break;
  4090. }
  4091. }
  4092. if (!ok)
  4093. return -EINVAL;
  4094. }
  4095. if (!rdev->ops->auth)
  4096. return -EOPNOTSUPP;
  4097. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4098. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4099. return -EOPNOTSUPP;
  4100. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4101. chan = ieee80211_get_channel(&rdev->wiphy,
  4102. nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
  4103. if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
  4104. return -EINVAL;
  4105. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  4106. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  4107. if (info->attrs[NL80211_ATTR_IE]) {
  4108. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  4109. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4110. }
  4111. auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  4112. if (!nl80211_valid_auth_type(auth_type))
  4113. return -EINVAL;
  4114. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  4115. /*
  4116. * Since we no longer track auth state, ignore
  4117. * requests to only change local state.
  4118. */
  4119. if (local_state_change)
  4120. return 0;
  4121. return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
  4122. ssid, ssid_len, ie, ie_len,
  4123. key.p.key, key.p.key_len, key.idx);
  4124. }
  4125. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  4126. struct genl_info *info,
  4127. struct cfg80211_crypto_settings *settings,
  4128. int cipher_limit)
  4129. {
  4130. memset(settings, 0, sizeof(*settings));
  4131. settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
  4132. if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
  4133. u16 proto;
  4134. proto = nla_get_u16(
  4135. info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
  4136. settings->control_port_ethertype = cpu_to_be16(proto);
  4137. if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  4138. proto != ETH_P_PAE)
  4139. return -EINVAL;
  4140. if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
  4141. settings->control_port_no_encrypt = true;
  4142. } else
  4143. settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
  4144. if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
  4145. void *data;
  4146. int len, i;
  4147. data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  4148. len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  4149. settings->n_ciphers_pairwise = len / sizeof(u32);
  4150. if (len % sizeof(u32))
  4151. return -EINVAL;
  4152. if (settings->n_ciphers_pairwise > cipher_limit)
  4153. return -EINVAL;
  4154. memcpy(settings->ciphers_pairwise, data, len);
  4155. for (i = 0; i < settings->n_ciphers_pairwise; i++)
  4156. if (!cfg80211_supported_cipher_suite(
  4157. &rdev->wiphy,
  4158. settings->ciphers_pairwise[i]))
  4159. return -EINVAL;
  4160. }
  4161. if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
  4162. settings->cipher_group =
  4163. nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
  4164. if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
  4165. settings->cipher_group))
  4166. return -EINVAL;
  4167. }
  4168. if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
  4169. settings->wpa_versions =
  4170. nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
  4171. if (!nl80211_valid_wpa_versions(settings->wpa_versions))
  4172. return -EINVAL;
  4173. }
  4174. if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
  4175. void *data;
  4176. int len;
  4177. data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
  4178. len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
  4179. settings->n_akm_suites = len / sizeof(u32);
  4180. if (len % sizeof(u32))
  4181. return -EINVAL;
  4182. if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
  4183. return -EINVAL;
  4184. memcpy(settings->akm_suites, data, len);
  4185. }
  4186. return 0;
  4187. }
  4188. static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
  4189. {
  4190. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4191. struct net_device *dev = info->user_ptr[1];
  4192. struct cfg80211_crypto_settings crypto;
  4193. struct ieee80211_channel *chan;
  4194. const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
  4195. int err, ssid_len, ie_len = 0;
  4196. bool use_mfp = false;
  4197. u32 flags = 0;
  4198. struct ieee80211_ht_cap *ht_capa = NULL;
  4199. struct ieee80211_ht_cap *ht_capa_mask = NULL;
  4200. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4201. return -EINVAL;
  4202. if (!info->attrs[NL80211_ATTR_MAC] ||
  4203. !info->attrs[NL80211_ATTR_SSID] ||
  4204. !info->attrs[NL80211_ATTR_WIPHY_FREQ])
  4205. return -EINVAL;
  4206. if (!rdev->ops->assoc)
  4207. return -EOPNOTSUPP;
  4208. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4209. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4210. return -EOPNOTSUPP;
  4211. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4212. chan = ieee80211_get_channel(&rdev->wiphy,
  4213. nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
  4214. if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
  4215. return -EINVAL;
  4216. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  4217. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  4218. if (info->attrs[NL80211_ATTR_IE]) {
  4219. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  4220. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4221. }
  4222. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  4223. enum nl80211_mfp mfp =
  4224. nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  4225. if (mfp == NL80211_MFP_REQUIRED)
  4226. use_mfp = true;
  4227. else if (mfp != NL80211_MFP_NO)
  4228. return -EINVAL;
  4229. }
  4230. if (info->attrs[NL80211_ATTR_PREV_BSSID])
  4231. prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
  4232. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  4233. flags |= ASSOC_REQ_DISABLE_HT;
  4234. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  4235. ht_capa_mask =
  4236. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
  4237. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  4238. if (!ht_capa_mask)
  4239. return -EINVAL;
  4240. ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  4241. }
  4242. err = nl80211_crypto_settings(rdev, info, &crypto, 1);
  4243. if (!err)
  4244. err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
  4245. ssid, ssid_len, ie, ie_len, use_mfp,
  4246. &crypto, flags, ht_capa,
  4247. ht_capa_mask);
  4248. return err;
  4249. }
  4250. static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
  4251. {
  4252. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4253. struct net_device *dev = info->user_ptr[1];
  4254. const u8 *ie = NULL, *bssid;
  4255. int ie_len = 0;
  4256. u16 reason_code;
  4257. bool local_state_change;
  4258. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4259. return -EINVAL;
  4260. if (!info->attrs[NL80211_ATTR_MAC])
  4261. return -EINVAL;
  4262. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  4263. return -EINVAL;
  4264. if (!rdev->ops->deauth)
  4265. return -EOPNOTSUPP;
  4266. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4267. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4268. return -EOPNOTSUPP;
  4269. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4270. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  4271. if (reason_code == 0) {
  4272. /* Reason Code 0 is reserved */
  4273. return -EINVAL;
  4274. }
  4275. if (info->attrs[NL80211_ATTR_IE]) {
  4276. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  4277. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4278. }
  4279. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  4280. return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
  4281. local_state_change);
  4282. }
  4283. static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
  4284. {
  4285. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4286. struct net_device *dev = info->user_ptr[1];
  4287. const u8 *ie = NULL, *bssid;
  4288. int ie_len = 0;
  4289. u16 reason_code;
  4290. bool local_state_change;
  4291. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4292. return -EINVAL;
  4293. if (!info->attrs[NL80211_ATTR_MAC])
  4294. return -EINVAL;
  4295. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  4296. return -EINVAL;
  4297. if (!rdev->ops->disassoc)
  4298. return -EOPNOTSUPP;
  4299. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4300. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4301. return -EOPNOTSUPP;
  4302. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4303. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  4304. if (reason_code == 0) {
  4305. /* Reason Code 0 is reserved */
  4306. return -EINVAL;
  4307. }
  4308. if (info->attrs[NL80211_ATTR_IE]) {
  4309. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  4310. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4311. }
  4312. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  4313. return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
  4314. local_state_change);
  4315. }
  4316. static bool
  4317. nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
  4318. int mcast_rate[IEEE80211_NUM_BANDS],
  4319. int rateval)
  4320. {
  4321. struct wiphy *wiphy = &rdev->wiphy;
  4322. bool found = false;
  4323. int band, i;
  4324. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  4325. struct ieee80211_supported_band *sband;
  4326. sband = wiphy->bands[band];
  4327. if (!sband)
  4328. continue;
  4329. for (i = 0; i < sband->n_bitrates; i++) {
  4330. if (sband->bitrates[i].bitrate == rateval) {
  4331. mcast_rate[band] = i + 1;
  4332. found = true;
  4333. break;
  4334. }
  4335. }
  4336. }
  4337. return found;
  4338. }
  4339. static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
  4340. {
  4341. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4342. struct net_device *dev = info->user_ptr[1];
  4343. struct cfg80211_ibss_params ibss;
  4344. struct wiphy *wiphy;
  4345. struct cfg80211_cached_keys *connkeys = NULL;
  4346. int err;
  4347. memset(&ibss, 0, sizeof(ibss));
  4348. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4349. return -EINVAL;
  4350. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  4351. !info->attrs[NL80211_ATTR_SSID] ||
  4352. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  4353. return -EINVAL;
  4354. ibss.beacon_interval = 100;
  4355. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
  4356. ibss.beacon_interval =
  4357. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  4358. if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
  4359. return -EINVAL;
  4360. }
  4361. if (!rdev->ops->join_ibss)
  4362. return -EOPNOTSUPP;
  4363. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  4364. return -EOPNOTSUPP;
  4365. wiphy = &rdev->wiphy;
  4366. if (info->attrs[NL80211_ATTR_MAC]) {
  4367. ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4368. if (!is_valid_ether_addr(ibss.bssid))
  4369. return -EINVAL;
  4370. }
  4371. ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  4372. ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  4373. if (info->attrs[NL80211_ATTR_IE]) {
  4374. ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  4375. ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4376. }
  4377. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  4378. enum nl80211_channel_type channel_type;
  4379. channel_type = nla_get_u32(
  4380. info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  4381. if (channel_type != NL80211_CHAN_NO_HT &&
  4382. channel_type != NL80211_CHAN_HT20 &&
  4383. channel_type != NL80211_CHAN_HT40MINUS &&
  4384. channel_type != NL80211_CHAN_HT40PLUS)
  4385. return -EINVAL;
  4386. if (channel_type != NL80211_CHAN_NO_HT &&
  4387. !(wiphy->features & NL80211_FEATURE_HT_IBSS))
  4388. return -EINVAL;
  4389. ibss.channel_type = channel_type;
  4390. } else {
  4391. ibss.channel_type = NL80211_CHAN_NO_HT;
  4392. }
  4393. ibss.channel = rdev_freq_to_chan(rdev,
  4394. nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
  4395. ibss.channel_type);
  4396. if (!ibss.channel ||
  4397. ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
  4398. ibss.channel->flags & IEEE80211_CHAN_DISABLED)
  4399. return -EINVAL;
  4400. /* Both channels should be able to initiate communication */
  4401. if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
  4402. ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
  4403. !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
  4404. ibss.channel_type))
  4405. return -EINVAL;
  4406. ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
  4407. ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  4408. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  4409. u8 *rates =
  4410. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4411. int n_rates =
  4412. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4413. struct ieee80211_supported_band *sband =
  4414. wiphy->bands[ibss.channel->band];
  4415. err = ieee80211_get_ratemask(sband, rates, n_rates,
  4416. &ibss.basic_rates);
  4417. if (err)
  4418. return err;
  4419. }
  4420. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  4421. !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
  4422. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  4423. return -EINVAL;
  4424. if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  4425. connkeys = nl80211_parse_connkeys(rdev,
  4426. info->attrs[NL80211_ATTR_KEYS]);
  4427. if (IS_ERR(connkeys))
  4428. return PTR_ERR(connkeys);
  4429. }
  4430. ibss.control_port =
  4431. nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
  4432. err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
  4433. if (err)
  4434. kfree(connkeys);
  4435. return err;
  4436. }
  4437. static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
  4438. {
  4439. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4440. struct net_device *dev = info->user_ptr[1];
  4441. if (!rdev->ops->leave_ibss)
  4442. return -EOPNOTSUPP;
  4443. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  4444. return -EOPNOTSUPP;
  4445. return cfg80211_leave_ibss(rdev, dev, false);
  4446. }
  4447. static struct sk_buff *
  4448. __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
  4449. struct wireless_dev *wdev, int approxlen,
  4450. u32 portid, u32 seq, enum nl80211_commands cmd,
  4451. enum nl80211_attrs attr,
  4452. const struct nl80211_vendor_cmd_info *info,
  4453. gfp_t gfp)
  4454. {
  4455. struct sk_buff *skb;
  4456. void *hdr;
  4457. struct nlattr *data;
  4458. skb = nlmsg_new(approxlen + 100, gfp);
  4459. if (!skb)
  4460. return NULL;
  4461. hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
  4462. if (!hdr) {
  4463. kfree_skb(skb);
  4464. return NULL;
  4465. }
  4466. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  4467. goto nla_put_failure;
  4468. if (info) {
  4469. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
  4470. info->vendor_id))
  4471. goto nla_put_failure;
  4472. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
  4473. info->subcmd))
  4474. goto nla_put_failure;
  4475. }
  4476. if (wdev) {
  4477. if (wdev->netdev &&
  4478. nla_put_u32(skb, NL80211_ATTR_IFINDEX,
  4479. wdev->netdev->ifindex))
  4480. goto nla_put_failure;
  4481. }
  4482. data = nla_nest_start(skb, attr);
  4483. ((void **)skb->cb)[0] = rdev;
  4484. ((void **)skb->cb)[1] = hdr;
  4485. ((void **)skb->cb)[2] = data;
  4486. return skb;
  4487. nla_put_failure:
  4488. kfree_skb(skb);
  4489. return NULL;
  4490. }
  4491. static struct genl_multicast_group nl80211_vendor_mcgrp = {
  4492. .name = "vendor",
  4493. };
  4494. #ifdef CONFIG_NL80211_TESTMODE
  4495. static struct genl_multicast_group nl80211_testmode_mcgrp = {
  4496. .name = "testmode",
  4497. };
  4498. static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
  4499. {
  4500. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4501. int err;
  4502. if (!info->attrs[NL80211_ATTR_TESTDATA])
  4503. return -EINVAL;
  4504. err = -EOPNOTSUPP;
  4505. if (rdev->ops->testmode_cmd) {
  4506. rdev->cur_cmd_info = info;
  4507. err = rdev->ops->testmode_cmd(&rdev->wiphy,
  4508. nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
  4509. nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
  4510. rdev->cur_cmd_info = NULL;
  4511. }
  4512. return err;
  4513. }
  4514. static int nl80211_testmode_dump(struct sk_buff *skb,
  4515. struct netlink_callback *cb)
  4516. {
  4517. struct cfg80211_registered_device *rdev;
  4518. int err;
  4519. long phy_idx;
  4520. void *data = NULL;
  4521. int data_len = 0;
  4522. if (cb->args[0]) {
  4523. /*
  4524. * 0 is a valid index, but not valid for args[0],
  4525. * so we need to offset by 1.
  4526. */
  4527. phy_idx = cb->args[0] - 1;
  4528. } else {
  4529. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  4530. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  4531. nl80211_policy);
  4532. if (err)
  4533. return err;
  4534. if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
  4535. phy_idx = nla_get_u32(
  4536. nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
  4537. } else {
  4538. struct net_device *netdev;
  4539. err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
  4540. nl80211_fam.attrbuf,
  4541. &rdev, &netdev);
  4542. if (err)
  4543. return err;
  4544. dev_put(netdev);
  4545. phy_idx = rdev->wiphy_idx;
  4546. cfg80211_unlock_rdev(rdev);
  4547. }
  4548. if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
  4549. cb->args[1] =
  4550. (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
  4551. }
  4552. if (cb->args[1]) {
  4553. data = nla_data((void *)cb->args[1]);
  4554. data_len = nla_len((void *)cb->args[1]);
  4555. }
  4556. mutex_lock(&cfg80211_mutex);
  4557. rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
  4558. if (!rdev) {
  4559. mutex_unlock(&cfg80211_mutex);
  4560. return -ENOENT;
  4561. }
  4562. cfg80211_lock_rdev(rdev);
  4563. mutex_unlock(&cfg80211_mutex);
  4564. if (!rdev->ops->testmode_dump) {
  4565. err = -EOPNOTSUPP;
  4566. goto out_err;
  4567. }
  4568. while (1) {
  4569. void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
  4570. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4571. NL80211_CMD_TESTMODE);
  4572. struct nlattr *tmdata;
  4573. if (!hdr)
  4574. break;
  4575. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) {
  4576. genlmsg_cancel(skb, hdr);
  4577. break;
  4578. }
  4579. tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
  4580. if (!tmdata) {
  4581. genlmsg_cancel(skb, hdr);
  4582. break;
  4583. }
  4584. err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
  4585. data, data_len);
  4586. nla_nest_end(skb, tmdata);
  4587. if (err == -ENOBUFS || err == -ENOENT) {
  4588. genlmsg_cancel(skb, hdr);
  4589. break;
  4590. } else if (err) {
  4591. genlmsg_cancel(skb, hdr);
  4592. goto out_err;
  4593. }
  4594. genlmsg_end(skb, hdr);
  4595. }
  4596. err = skb->len;
  4597. /* see above */
  4598. cb->args[0] = phy_idx + 1;
  4599. out_err:
  4600. cfg80211_unlock_rdev(rdev);
  4601. return err;
  4602. }
  4603. #endif
  4604. struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
  4605. struct wireless_dev *wdev,
  4606. enum nl80211_commands cmd,
  4607. enum nl80211_attrs attr,
  4608. int vendor_event_idx,
  4609. int approxlen, gfp_t gfp)
  4610. {
  4611. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  4612. const struct nl80211_vendor_cmd_info *info;
  4613. switch (cmd) {
  4614. case NL80211_CMD_TESTMODE:
  4615. if (WARN_ON(vendor_event_idx != -1))
  4616. return NULL;
  4617. info = NULL;
  4618. break;
  4619. case NL80211_CMD_VENDOR:
  4620. if (WARN_ON(vendor_event_idx < 0 ||
  4621. vendor_event_idx >= wiphy->n_vendor_events))
  4622. return NULL;
  4623. info = &wiphy->vendor_events[vendor_event_idx];
  4624. break;
  4625. default:
  4626. WARN_ON(1);
  4627. return NULL;
  4628. }
  4629. return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
  4630. cmd, attr, info, gfp);
  4631. }
  4632. EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
  4633. void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
  4634. {
  4635. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  4636. void *hdr = ((void **)skb->cb)[1];
  4637. struct nlattr *data = ((void **)skb->cb)[2];
  4638. /* clear CB data for netlink core to own from now on */
  4639. memset(skb->cb, 0, sizeof(skb->cb));
  4640. nla_nest_end(skb, data);
  4641. genlmsg_end(skb, hdr);
  4642. if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
  4643. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
  4644. nl80211_vendor_mcgrp.id, gfp);
  4645. else
  4646. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
  4647. nl80211_testmode_mcgrp.id, gfp);
  4648. }
  4649. EXPORT_SYMBOL(__cfg80211_send_event_skb);
  4650. static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
  4651. {
  4652. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4653. struct net_device *dev = info->user_ptr[1];
  4654. struct cfg80211_connect_params connect;
  4655. struct wiphy *wiphy;
  4656. struct cfg80211_cached_keys *connkeys = NULL;
  4657. int err;
  4658. memset(&connect, 0, sizeof(connect));
  4659. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4660. return -EINVAL;
  4661. if (!info->attrs[NL80211_ATTR_SSID] ||
  4662. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  4663. return -EINVAL;
  4664. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  4665. connect.auth_type =
  4666. nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  4667. if (!nl80211_valid_auth_type(connect.auth_type))
  4668. return -EINVAL;
  4669. } else
  4670. connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  4671. connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
  4672. err = nl80211_crypto_settings(rdev, info, &connect.crypto,
  4673. NL80211_MAX_NR_CIPHER_SUITES);
  4674. if (err)
  4675. return err;
  4676. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4677. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4678. return -EOPNOTSUPP;
  4679. wiphy = &rdev->wiphy;
  4680. connect.bg_scan_period = -1;
  4681. if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
  4682. (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
  4683. connect.bg_scan_period =
  4684. nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
  4685. }
  4686. if (info->attrs[NL80211_ATTR_MAC])
  4687. connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4688. else if (info->attrs[NL80211_ATTR_MAC_HINT])
  4689. connect.bssid_hint =
  4690. nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
  4691. connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  4692. connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  4693. if (info->attrs[NL80211_ATTR_IE]) {
  4694. connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  4695. connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4696. }
  4697. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  4698. connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  4699. if (connect.mfp != NL80211_MFP_REQUIRED &&
  4700. connect.mfp != NL80211_MFP_NO)
  4701. return -EINVAL;
  4702. } else {
  4703. connect.mfp = NL80211_MFP_NO;
  4704. }
  4705. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  4706. connect.channel =
  4707. ieee80211_get_channel(wiphy,
  4708. nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
  4709. if (!connect.channel ||
  4710. connect.channel->flags & IEEE80211_CHAN_DISABLED)
  4711. return -EINVAL;
  4712. } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
  4713. connect.channel_hint =
  4714. ieee80211_get_channel(wiphy,
  4715. nla_get_u32(
  4716. info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]));
  4717. if (!connect.channel_hint ||
  4718. connect.channel_hint->flags & IEEE80211_CHAN_DISABLED)
  4719. return -EINVAL;
  4720. }
  4721. if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  4722. connkeys = nl80211_parse_connkeys(rdev,
  4723. info->attrs[NL80211_ATTR_KEYS]);
  4724. if (IS_ERR(connkeys))
  4725. return PTR_ERR(connkeys);
  4726. }
  4727. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  4728. connect.flags |= ASSOC_REQ_DISABLE_HT;
  4729. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  4730. memcpy(&connect.ht_capa_mask,
  4731. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  4732. sizeof(connect.ht_capa_mask));
  4733. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  4734. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  4735. return -EINVAL;
  4736. memcpy(&connect.ht_capa,
  4737. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  4738. sizeof(connect.ht_capa));
  4739. }
  4740. err = cfg80211_connect(rdev, dev, &connect, connkeys);
  4741. if (err)
  4742. kfree(connkeys);
  4743. return err;
  4744. }
  4745. static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
  4746. {
  4747. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4748. struct net_device *dev = info->user_ptr[1];
  4749. u16 reason;
  4750. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  4751. reason = WLAN_REASON_DEAUTH_LEAVING;
  4752. else
  4753. reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  4754. if (reason == 0)
  4755. return -EINVAL;
  4756. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4757. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4758. return -EOPNOTSUPP;
  4759. return cfg80211_disconnect(rdev, dev, reason, true);
  4760. }
  4761. static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
  4762. {
  4763. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4764. struct net *net;
  4765. int err;
  4766. u32 pid;
  4767. if (!info->attrs[NL80211_ATTR_PID])
  4768. return -EINVAL;
  4769. pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
  4770. net = get_net_ns_by_pid(pid);
  4771. if (IS_ERR(net))
  4772. return PTR_ERR(net);
  4773. err = 0;
  4774. /* check if anything to do */
  4775. if (!net_eq(wiphy_net(&rdev->wiphy), net))
  4776. err = cfg80211_switch_netns(rdev, net);
  4777. put_net(net);
  4778. return err;
  4779. }
  4780. static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
  4781. {
  4782. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4783. int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
  4784. struct cfg80211_pmksa *pmksa) = NULL;
  4785. struct net_device *dev = info->user_ptr[1];
  4786. struct cfg80211_pmksa pmksa;
  4787. memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
  4788. if (!info->attrs[NL80211_ATTR_MAC])
  4789. return -EINVAL;
  4790. if (!info->attrs[NL80211_ATTR_PMKID])
  4791. return -EINVAL;
  4792. pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
  4793. pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4794. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4795. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4796. return -EOPNOTSUPP;
  4797. switch (info->genlhdr->cmd) {
  4798. case NL80211_CMD_SET_PMKSA:
  4799. rdev_ops = rdev->ops->set_pmksa;
  4800. break;
  4801. case NL80211_CMD_DEL_PMKSA:
  4802. rdev_ops = rdev->ops->del_pmksa;
  4803. break;
  4804. default:
  4805. WARN_ON(1);
  4806. break;
  4807. }
  4808. if (!rdev_ops)
  4809. return -EOPNOTSUPP;
  4810. return rdev_ops(&rdev->wiphy, dev, &pmksa);
  4811. }
  4812. static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
  4813. {
  4814. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4815. struct net_device *dev = info->user_ptr[1];
  4816. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  4817. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  4818. return -EOPNOTSUPP;
  4819. if (!rdev->ops->flush_pmksa)
  4820. return -EOPNOTSUPP;
  4821. return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
  4822. }
  4823. static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
  4824. {
  4825. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4826. struct net_device *dev = info->user_ptr[1];
  4827. u8 action_code, dialog_token;
  4828. u32 peer_capability = 0;
  4829. u16 status_code;
  4830. u8 *peer;
  4831. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  4832. !rdev->ops->tdls_mgmt)
  4833. return -EOPNOTSUPP;
  4834. if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
  4835. !info->attrs[NL80211_ATTR_STATUS_CODE] ||
  4836. !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
  4837. !info->attrs[NL80211_ATTR_IE] ||
  4838. !info->attrs[NL80211_ATTR_MAC])
  4839. return -EINVAL;
  4840. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4841. action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
  4842. status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
  4843. dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
  4844. if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
  4845. peer_capability =
  4846. nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
  4847. return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
  4848. dialog_token, status_code, peer_capability,
  4849. nla_data(info->attrs[NL80211_ATTR_IE]),
  4850. nla_len(info->attrs[NL80211_ATTR_IE]));
  4851. }
  4852. static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
  4853. {
  4854. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4855. struct net_device *dev = info->user_ptr[1];
  4856. enum nl80211_tdls_operation operation;
  4857. u8 *peer;
  4858. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  4859. !rdev->ops->tdls_oper)
  4860. return -EOPNOTSUPP;
  4861. if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
  4862. !info->attrs[NL80211_ATTR_MAC])
  4863. return -EINVAL;
  4864. operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
  4865. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4866. return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
  4867. }
  4868. static int nl80211_remain_on_channel(struct sk_buff *skb,
  4869. struct genl_info *info)
  4870. {
  4871. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4872. struct net_device *dev = info->user_ptr[1];
  4873. struct ieee80211_channel *chan;
  4874. struct sk_buff *msg;
  4875. void *hdr;
  4876. u64 cookie;
  4877. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  4878. u32 freq, duration;
  4879. int err;
  4880. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  4881. !info->attrs[NL80211_ATTR_DURATION])
  4882. return -EINVAL;
  4883. duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  4884. /*
  4885. * We should be on that channel for at least one jiffie,
  4886. * and more than 5 seconds seems excessive.
  4887. */
  4888. if (!duration || !msecs_to_jiffies(duration) ||
  4889. duration > rdev->wiphy.max_remain_on_channel_duration)
  4890. return -EINVAL;
  4891. if (!rdev->ops->remain_on_channel ||
  4892. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
  4893. return -EOPNOTSUPP;
  4894. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  4895. channel_type = nla_get_u32(
  4896. info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  4897. if (channel_type != NL80211_CHAN_NO_HT &&
  4898. channel_type != NL80211_CHAN_HT20 &&
  4899. channel_type != NL80211_CHAN_HT40PLUS &&
  4900. channel_type != NL80211_CHAN_HT40MINUS)
  4901. return -EINVAL;
  4902. }
  4903. freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  4904. chan = rdev_freq_to_chan(rdev, freq, channel_type);
  4905. if (chan == NULL)
  4906. return -EINVAL;
  4907. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4908. if (!msg)
  4909. return -ENOMEM;
  4910. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  4911. NL80211_CMD_REMAIN_ON_CHANNEL);
  4912. if (!hdr) {
  4913. err = -ENOBUFS;
  4914. goto free_msg;
  4915. }
  4916. err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
  4917. channel_type, duration, &cookie);
  4918. if (err)
  4919. goto free_msg;
  4920. NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
  4921. genlmsg_end(msg, hdr);
  4922. return genlmsg_reply(msg, info);
  4923. nla_put_failure:
  4924. err = -ENOBUFS;
  4925. free_msg:
  4926. nlmsg_free(msg);
  4927. return err;
  4928. }
  4929. static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
  4930. struct genl_info *info)
  4931. {
  4932. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4933. struct net_device *dev = info->user_ptr[1];
  4934. u64 cookie;
  4935. if (!info->attrs[NL80211_ATTR_COOKIE])
  4936. return -EINVAL;
  4937. if (!rdev->ops->cancel_remain_on_channel)
  4938. return -EOPNOTSUPP;
  4939. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  4940. return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
  4941. }
  4942. static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
  4943. u8 *rates, u8 rates_len)
  4944. {
  4945. u8 i;
  4946. u32 mask = 0;
  4947. for (i = 0; i < rates_len; i++) {
  4948. int rate = (rates[i] & 0x7f) * 5;
  4949. int ridx;
  4950. for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
  4951. struct ieee80211_rate *srate =
  4952. &sband->bitrates[ridx];
  4953. if (rate == srate->bitrate) {
  4954. mask |= 1 << ridx;
  4955. break;
  4956. }
  4957. }
  4958. if (ridx == sband->n_bitrates)
  4959. return 0; /* rate not found */
  4960. }
  4961. return mask;
  4962. }
  4963. static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
  4964. u8 *rates, u8 rates_len,
  4965. u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
  4966. {
  4967. u8 i;
  4968. memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
  4969. for (i = 0; i < rates_len; i++) {
  4970. int ridx, rbit;
  4971. ridx = rates[i] / 8;
  4972. rbit = BIT(rates[i] % 8);
  4973. /* check validity */
  4974. if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
  4975. return false;
  4976. /* check availability */
  4977. if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
  4978. mcs[ridx] |= rbit;
  4979. else
  4980. return false;
  4981. }
  4982. return true;
  4983. }
  4984. static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
  4985. [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
  4986. .len = NL80211_MAX_SUPP_RATES },
  4987. [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
  4988. .len = NL80211_MAX_SUPP_HT_RATES },
  4989. };
  4990. static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
  4991. struct genl_info *info)
  4992. {
  4993. struct nlattr *tb[NL80211_TXRATE_MAX + 1];
  4994. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4995. struct cfg80211_bitrate_mask mask;
  4996. int rem, i;
  4997. struct net_device *dev = info->user_ptr[1];
  4998. struct nlattr *tx_rates;
  4999. struct ieee80211_supported_band *sband;
  5000. if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
  5001. return -EINVAL;
  5002. if (!rdev->ops->set_bitrate_mask)
  5003. return -EOPNOTSUPP;
  5004. memset(&mask, 0, sizeof(mask));
  5005. /* Default to all rates enabled */
  5006. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  5007. sband = rdev->wiphy.bands[i];
  5008. mask.control[i].legacy =
  5009. sband ? (1 << sband->n_bitrates) - 1 : 0;
  5010. if (sband)
  5011. memcpy(mask.control[i].mcs,
  5012. sband->ht_cap.mcs.rx_mask,
  5013. sizeof(mask.control[i].mcs));
  5014. else
  5015. memset(mask.control[i].mcs, 0,
  5016. sizeof(mask.control[i].mcs));
  5017. }
  5018. /*
  5019. * The nested attribute uses enum nl80211_band as the index. This maps
  5020. * directly to the enum ieee80211_band values used in cfg80211.
  5021. */
  5022. BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
  5023. nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
  5024. {
  5025. enum ieee80211_band band = nla_type(tx_rates);
  5026. if (band < 0 || band >= IEEE80211_NUM_BANDS)
  5027. return -EINVAL;
  5028. sband = rdev->wiphy.bands[band];
  5029. if (sband == NULL)
  5030. return -EINVAL;
  5031. nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
  5032. nla_len(tx_rates), nl80211_txattr_policy);
  5033. if (tb[NL80211_TXRATE_LEGACY]) {
  5034. mask.control[band].legacy = rateset_to_mask(
  5035. sband,
  5036. nla_data(tb[NL80211_TXRATE_LEGACY]),
  5037. nla_len(tb[NL80211_TXRATE_LEGACY]));
  5038. }
  5039. if (tb[NL80211_TXRATE_MCS]) {
  5040. if (!ht_rateset_to_mask(
  5041. sband,
  5042. nla_data(tb[NL80211_TXRATE_MCS]),
  5043. nla_len(tb[NL80211_TXRATE_MCS]),
  5044. mask.control[band].mcs))
  5045. return -EINVAL;
  5046. }
  5047. if (mask.control[band].legacy == 0) {
  5048. /* don't allow empty legacy rates if HT
  5049. * is not even supported. */
  5050. if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
  5051. return -EINVAL;
  5052. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  5053. if (mask.control[band].mcs[i])
  5054. break;
  5055. /* legacy and mcs rates may not be both empty */
  5056. if (i == IEEE80211_HT_MCS_MASK_LEN)
  5057. return -EINVAL;
  5058. }
  5059. }
  5060. return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
  5061. }
  5062. static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
  5063. {
  5064. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5065. struct net_device *dev = info->user_ptr[1];
  5066. u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
  5067. if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
  5068. return -EINVAL;
  5069. if (info->attrs[NL80211_ATTR_FRAME_TYPE])
  5070. frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
  5071. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  5072. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
  5073. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
  5074. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  5075. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  5076. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  5077. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  5078. return -EOPNOTSUPP;
  5079. /* not much point in registering if we can't reply */
  5080. if (!rdev->ops->mgmt_tx)
  5081. return -EOPNOTSUPP;
  5082. return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
  5083. frame_type,
  5084. nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
  5085. nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
  5086. }
  5087. static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
  5088. {
  5089. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5090. struct net_device *dev = info->user_ptr[1];
  5091. struct ieee80211_channel *chan;
  5092. enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
  5093. bool channel_type_valid = false;
  5094. u32 freq;
  5095. int err;
  5096. void *hdr = NULL;
  5097. u64 cookie;
  5098. struct sk_buff *msg = NULL;
  5099. unsigned int wait = 0;
  5100. bool offchan, no_cck, dont_wait_for_ack;
  5101. dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
  5102. if (!info->attrs[NL80211_ATTR_FRAME] ||
  5103. !info->attrs[NL80211_ATTR_WIPHY_FREQ])
  5104. return -EINVAL;
  5105. if (!rdev->ops->mgmt_tx)
  5106. return -EOPNOTSUPP;
  5107. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  5108. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
  5109. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
  5110. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  5111. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  5112. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  5113. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  5114. return -EOPNOTSUPP;
  5115. if (info->attrs[NL80211_ATTR_DURATION]) {
  5116. if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  5117. return -EINVAL;
  5118. wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  5119. }
  5120. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  5121. channel_type = nla_get_u32(
  5122. info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  5123. if (channel_type != NL80211_CHAN_NO_HT &&
  5124. channel_type != NL80211_CHAN_HT20 &&
  5125. channel_type != NL80211_CHAN_HT40PLUS &&
  5126. channel_type != NL80211_CHAN_HT40MINUS)
  5127. return -EINVAL;
  5128. channel_type_valid = true;
  5129. }
  5130. offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
  5131. if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  5132. return -EINVAL;
  5133. no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  5134. freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  5135. chan = rdev_freq_to_chan(rdev, freq, channel_type);
  5136. if (chan == NULL)
  5137. return -EINVAL;
  5138. if (!dont_wait_for_ack) {
  5139. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5140. if (!msg)
  5141. return -ENOMEM;
  5142. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  5143. NL80211_CMD_FRAME);
  5144. if (!hdr) {
  5145. err = -ENOBUFS;
  5146. goto free_msg;
  5147. }
  5148. }
  5149. err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
  5150. channel_type_valid, wait,
  5151. nla_data(info->attrs[NL80211_ATTR_FRAME]),
  5152. nla_len(info->attrs[NL80211_ATTR_FRAME]),
  5153. no_cck, dont_wait_for_ack, &cookie);
  5154. if (err)
  5155. goto free_msg;
  5156. if (msg) {
  5157. NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
  5158. genlmsg_end(msg, hdr);
  5159. return genlmsg_reply(msg, info);
  5160. }
  5161. return 0;
  5162. nla_put_failure:
  5163. err = -ENOBUFS;
  5164. free_msg:
  5165. nlmsg_free(msg);
  5166. return err;
  5167. }
  5168. static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
  5169. {
  5170. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5171. struct net_device *dev = info->user_ptr[1];
  5172. u64 cookie;
  5173. if (!info->attrs[NL80211_ATTR_COOKIE])
  5174. return -EINVAL;
  5175. if (!rdev->ops->mgmt_tx_cancel_wait)
  5176. return -EOPNOTSUPP;
  5177. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  5178. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
  5179. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
  5180. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  5181. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  5182. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  5183. return -EOPNOTSUPP;
  5184. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  5185. return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
  5186. }
  5187. static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
  5188. {
  5189. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5190. struct wireless_dev *wdev;
  5191. struct net_device *dev = info->user_ptr[1];
  5192. u8 ps_state;
  5193. bool state;
  5194. int err;
  5195. if (!info->attrs[NL80211_ATTR_PS_STATE])
  5196. return -EINVAL;
  5197. ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
  5198. if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
  5199. return -EINVAL;
  5200. wdev = dev->ieee80211_ptr;
  5201. if (!rdev->ops->set_power_mgmt)
  5202. return -EOPNOTSUPP;
  5203. state = (ps_state == NL80211_PS_ENABLED) ? true : false;
  5204. if (state == wdev->ps)
  5205. return 0;
  5206. err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
  5207. wdev->ps_timeout);
  5208. if (!err)
  5209. wdev->ps = state;
  5210. return err;
  5211. }
  5212. static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
  5213. {
  5214. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5215. enum nl80211_ps_state ps_state;
  5216. struct wireless_dev *wdev;
  5217. struct net_device *dev = info->user_ptr[1];
  5218. struct sk_buff *msg;
  5219. void *hdr;
  5220. int err;
  5221. wdev = dev->ieee80211_ptr;
  5222. if (!rdev->ops->set_power_mgmt)
  5223. return -EOPNOTSUPP;
  5224. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5225. if (!msg)
  5226. return -ENOMEM;
  5227. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  5228. NL80211_CMD_GET_POWER_SAVE);
  5229. if (!hdr) {
  5230. err = -ENOBUFS;
  5231. goto free_msg;
  5232. }
  5233. if (wdev->ps)
  5234. ps_state = NL80211_PS_ENABLED;
  5235. else
  5236. ps_state = NL80211_PS_DISABLED;
  5237. NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
  5238. genlmsg_end(msg, hdr);
  5239. return genlmsg_reply(msg, info);
  5240. nla_put_failure:
  5241. err = -ENOBUFS;
  5242. free_msg:
  5243. nlmsg_free(msg);
  5244. return err;
  5245. }
  5246. static struct nla_policy
  5247. nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
  5248. [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
  5249. [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
  5250. [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
  5251. };
  5252. static int nl80211_set_cqm_rssi(struct genl_info *info,
  5253. s32 threshold, u32 hysteresis)
  5254. {
  5255. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5256. struct wireless_dev *wdev;
  5257. struct net_device *dev = info->user_ptr[1];
  5258. if (threshold > 0)
  5259. return -EINVAL;
  5260. wdev = dev->ieee80211_ptr;
  5261. if (!rdev->ops->set_cqm_rssi_config)
  5262. return -EOPNOTSUPP;
  5263. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  5264. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  5265. return -EOPNOTSUPP;
  5266. return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
  5267. threshold, hysteresis);
  5268. }
  5269. static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
  5270. {
  5271. struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
  5272. struct nlattr *cqm;
  5273. int err;
  5274. cqm = info->attrs[NL80211_ATTR_CQM];
  5275. if (!cqm) {
  5276. err = -EINVAL;
  5277. goto out;
  5278. }
  5279. err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
  5280. nl80211_attr_cqm_policy);
  5281. if (err)
  5282. goto out;
  5283. if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
  5284. attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
  5285. s32 threshold;
  5286. u32 hysteresis;
  5287. threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
  5288. hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
  5289. err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
  5290. } else
  5291. err = -EINVAL;
  5292. out:
  5293. return err;
  5294. }
  5295. static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
  5296. {
  5297. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5298. struct net_device *dev = info->user_ptr[1];
  5299. struct mesh_config cfg;
  5300. struct mesh_setup setup;
  5301. int err;
  5302. /* start with default */
  5303. memcpy(&cfg, &default_mesh_config, sizeof(cfg));
  5304. memcpy(&setup, &default_mesh_setup, sizeof(setup));
  5305. if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
  5306. /* and parse parameters if given */
  5307. err = nl80211_parse_mesh_config(info, &cfg, NULL);
  5308. if (err)
  5309. return err;
  5310. }
  5311. if (!info->attrs[NL80211_ATTR_MESH_ID] ||
  5312. !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
  5313. return -EINVAL;
  5314. setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
  5315. setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  5316. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  5317. !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
  5318. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  5319. return -EINVAL;
  5320. if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
  5321. /* parse additional setup parameters if given */
  5322. err = nl80211_parse_mesh_setup(info, &setup);
  5323. if (err)
  5324. return err;
  5325. }
  5326. return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
  5327. }
  5328. static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
  5329. {
  5330. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5331. struct net_device *dev = info->user_ptr[1];
  5332. return cfg80211_leave_mesh(rdev, dev);
  5333. }
  5334. static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
  5335. {
  5336. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5337. struct sk_buff *msg;
  5338. void *hdr;
  5339. if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
  5340. return -EOPNOTSUPP;
  5341. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5342. if (!msg)
  5343. return -ENOMEM;
  5344. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  5345. NL80211_CMD_GET_WOWLAN);
  5346. if (!hdr)
  5347. goto nla_put_failure;
  5348. if (rdev->wowlan) {
  5349. struct nlattr *nl_wowlan;
  5350. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  5351. if (!nl_wowlan)
  5352. goto nla_put_failure;
  5353. if (rdev->wowlan->any)
  5354. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
  5355. if (rdev->wowlan->disconnect)
  5356. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
  5357. if (rdev->wowlan->magic_pkt)
  5358. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
  5359. if (rdev->wowlan->gtk_rekey_failure)
  5360. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
  5361. if (rdev->wowlan->eap_identity_req)
  5362. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
  5363. if (rdev->wowlan->four_way_handshake)
  5364. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
  5365. if (rdev->wowlan->rfkill_release)
  5366. NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
  5367. if (rdev->wowlan->n_patterns) {
  5368. struct nlattr *nl_pats, *nl_pat;
  5369. int i, pat_len;
  5370. nl_pats = nla_nest_start(msg,
  5371. NL80211_WOWLAN_TRIG_PKT_PATTERN);
  5372. if (!nl_pats)
  5373. goto nla_put_failure;
  5374. for (i = 0; i < rdev->wowlan->n_patterns; i++) {
  5375. nl_pat = nla_nest_start(msg, i + 1);
  5376. if (!nl_pat)
  5377. goto nla_put_failure;
  5378. pat_len = rdev->wowlan->patterns[i].pattern_len;
  5379. NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
  5380. DIV_ROUND_UP(pat_len, 8),
  5381. rdev->wowlan->patterns[i].mask);
  5382. NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
  5383. pat_len,
  5384. rdev->wowlan->patterns[i].pattern);
  5385. nla_nest_end(msg, nl_pat);
  5386. }
  5387. nla_nest_end(msg, nl_pats);
  5388. }
  5389. nla_nest_end(msg, nl_wowlan);
  5390. }
  5391. genlmsg_end(msg, hdr);
  5392. return genlmsg_reply(msg, info);
  5393. nla_put_failure:
  5394. nlmsg_free(msg);
  5395. return -ENOBUFS;
  5396. }
  5397. static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
  5398. {
  5399. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5400. struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
  5401. struct cfg80211_wowlan no_triggers = {};
  5402. struct cfg80211_wowlan new_triggers = {};
  5403. struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
  5404. int err, i;
  5405. if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
  5406. return -EOPNOTSUPP;
  5407. if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
  5408. goto no_triggers;
  5409. err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
  5410. nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  5411. nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  5412. nl80211_wowlan_policy);
  5413. if (err)
  5414. return err;
  5415. if (tb[NL80211_WOWLAN_TRIG_ANY]) {
  5416. if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
  5417. return -EINVAL;
  5418. new_triggers.any = true;
  5419. }
  5420. if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
  5421. if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
  5422. return -EINVAL;
  5423. new_triggers.disconnect = true;
  5424. }
  5425. if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
  5426. if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
  5427. return -EINVAL;
  5428. new_triggers.magic_pkt = true;
  5429. }
  5430. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
  5431. return -EINVAL;
  5432. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
  5433. if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
  5434. return -EINVAL;
  5435. new_triggers.gtk_rekey_failure = true;
  5436. }
  5437. if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
  5438. if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
  5439. return -EINVAL;
  5440. new_triggers.eap_identity_req = true;
  5441. }
  5442. if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
  5443. if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
  5444. return -EINVAL;
  5445. new_triggers.four_way_handshake = true;
  5446. }
  5447. if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
  5448. if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
  5449. return -EINVAL;
  5450. new_triggers.rfkill_release = true;
  5451. }
  5452. if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
  5453. struct nlattr *pat;
  5454. int n_patterns = 0;
  5455. int rem, pat_len, mask_len;
  5456. struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
  5457. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  5458. rem)
  5459. n_patterns++;
  5460. if (n_patterns > wowlan->n_patterns)
  5461. return -EINVAL;
  5462. new_triggers.patterns = kcalloc(n_patterns,
  5463. sizeof(new_triggers.patterns[0]),
  5464. GFP_KERNEL);
  5465. if (!new_triggers.patterns)
  5466. return -ENOMEM;
  5467. new_triggers.n_patterns = n_patterns;
  5468. i = 0;
  5469. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  5470. rem) {
  5471. nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
  5472. nla_data(pat), nla_len(pat), nl80211_packet_pattern_policy);
  5473. err = -EINVAL;
  5474. if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
  5475. !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
  5476. goto error;
  5477. pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
  5478. mask_len = DIV_ROUND_UP(pat_len, 8);
  5479. if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
  5480. mask_len)
  5481. goto error;
  5482. if (pat_len > wowlan->pattern_max_len ||
  5483. pat_len < wowlan->pattern_min_len)
  5484. goto error;
  5485. new_triggers.patterns[i].mask =
  5486. kmalloc(mask_len + pat_len, GFP_KERNEL);
  5487. if (!new_triggers.patterns[i].mask) {
  5488. err = -ENOMEM;
  5489. goto error;
  5490. }
  5491. new_triggers.patterns[i].pattern =
  5492. new_triggers.patterns[i].mask + mask_len;
  5493. memcpy(new_triggers.patterns[i].mask,
  5494. nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
  5495. mask_len);
  5496. new_triggers.patterns[i].pattern_len = pat_len;
  5497. memcpy(new_triggers.patterns[i].pattern,
  5498. nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
  5499. pat_len);
  5500. i++;
  5501. }
  5502. }
  5503. if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
  5504. struct cfg80211_wowlan *ntrig;
  5505. ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
  5506. GFP_KERNEL);
  5507. if (!ntrig) {
  5508. err = -ENOMEM;
  5509. goto error;
  5510. }
  5511. cfg80211_rdev_free_wowlan(rdev);
  5512. rdev->wowlan = ntrig;
  5513. } else {
  5514. no_triggers:
  5515. cfg80211_rdev_free_wowlan(rdev);
  5516. rdev->wowlan = NULL;
  5517. }
  5518. return 0;
  5519. error:
  5520. for (i = 0; i < new_triggers.n_patterns; i++)
  5521. kfree(new_triggers.patterns[i].mask);
  5522. kfree(new_triggers.patterns);
  5523. return err;
  5524. }
  5525. static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
  5526. {
  5527. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5528. struct net_device *dev = info->user_ptr[1];
  5529. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5530. struct nlattr *tb[NUM_NL80211_REKEY_DATA];
  5531. struct cfg80211_gtk_rekey_data rekey_data;
  5532. int err;
  5533. if (!info->attrs[NL80211_ATTR_REKEY_DATA])
  5534. return -EINVAL;
  5535. err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
  5536. nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
  5537. nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
  5538. nl80211_rekey_policy);
  5539. if (err)
  5540. return err;
  5541. if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
  5542. !tb[NL80211_REKEY_DATA_KCK])
  5543. return -EINVAL;
  5544. if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
  5545. return -ERANGE;
  5546. if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
  5547. return -ERANGE;
  5548. if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
  5549. return -ERANGE;
  5550. memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
  5551. NL80211_KEK_LEN);
  5552. memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
  5553. NL80211_KCK_LEN);
  5554. memcpy(rekey_data.replay_ctr,
  5555. nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
  5556. NL80211_REPLAY_CTR_LEN);
  5557. wdev_lock(wdev);
  5558. if (!wdev->current_bss) {
  5559. err = -ENOTCONN;
  5560. goto out;
  5561. }
  5562. if (!rdev->ops->set_rekey_data) {
  5563. err = -EOPNOTSUPP;
  5564. goto out;
  5565. }
  5566. err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
  5567. out:
  5568. wdev_unlock(wdev);
  5569. return err;
  5570. }
  5571. static int nl80211_register_unexpected_frame(struct sk_buff *skb,
  5572. struct genl_info *info)
  5573. {
  5574. struct net_device *dev = info->user_ptr[1];
  5575. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5576. if (wdev->iftype != NL80211_IFTYPE_AP &&
  5577. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  5578. return -EINVAL;
  5579. if (wdev->ap_unexpected_nlpid)
  5580. return -EBUSY;
  5581. wdev->ap_unexpected_nlpid = info->snd_pid;
  5582. return 0;
  5583. }
  5584. static int nl80211_probe_client(struct sk_buff *skb,
  5585. struct genl_info *info)
  5586. {
  5587. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5588. struct net_device *dev = info->user_ptr[1];
  5589. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5590. struct sk_buff *msg;
  5591. void *hdr;
  5592. const u8 *addr;
  5593. u64 cookie;
  5594. int err;
  5595. if (wdev->iftype != NL80211_IFTYPE_AP &&
  5596. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  5597. return -EOPNOTSUPP;
  5598. if (!info->attrs[NL80211_ATTR_MAC])
  5599. return -EINVAL;
  5600. if (!rdev->ops->probe_client)
  5601. return -EOPNOTSUPP;
  5602. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5603. if (!msg)
  5604. return -ENOMEM;
  5605. hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
  5606. NL80211_CMD_PROBE_CLIENT);
  5607. if (!hdr) {
  5608. err = -ENOBUFS;
  5609. goto free_msg;
  5610. }
  5611. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  5612. err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
  5613. if (err)
  5614. goto free_msg;
  5615. NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
  5616. genlmsg_end(msg, hdr);
  5617. return genlmsg_reply(msg, info);
  5618. nla_put_failure:
  5619. err = -ENOBUFS;
  5620. free_msg:
  5621. nlmsg_free(msg);
  5622. return err;
  5623. }
  5624. static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
  5625. {
  5626. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5627. if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
  5628. return -EOPNOTSUPP;
  5629. if (rdev->ap_beacons_nlpid)
  5630. return -EBUSY;
  5631. rdev->ap_beacons_nlpid = info->snd_pid;
  5632. return 0;
  5633. }
  5634. static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
  5635. {
  5636. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5637. struct cfg80211_update_ft_ies_params ft_params;
  5638. struct net_device *dev = info->user_ptr[1];
  5639. if (!rdev->ops->update_ft_ies)
  5640. return -EOPNOTSUPP;
  5641. if (!info->attrs[NL80211_ATTR_MDID] ||
  5642. !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  5643. return -EINVAL;
  5644. memset(&ft_params, 0, sizeof(ft_params));
  5645. ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
  5646. ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  5647. ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5648. return rdev->ops->update_ft_ies(&rdev->wiphy, dev, &ft_params);
  5649. }
  5650. static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
  5651. {
  5652. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5653. struct net_device *dev = info->user_ptr[1];
  5654. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5655. int i, err;
  5656. u32 vid, subcmd;
  5657. if (!rdev->wiphy.vendor_commands)
  5658. return -EOPNOTSUPP;
  5659. if (IS_ERR(wdev)) {
  5660. err = PTR_ERR(wdev);
  5661. if (err != -EINVAL)
  5662. return err;
  5663. wdev = NULL;
  5664. } else if (wdev->wiphy != &rdev->wiphy) {
  5665. return -EINVAL;
  5666. }
  5667. if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
  5668. !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
  5669. return -EINVAL;
  5670. vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
  5671. subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
  5672. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  5673. const struct wiphy_vendor_command *vcmd;
  5674. void *data = NULL;
  5675. int len = 0;
  5676. vcmd = &rdev->wiphy.vendor_commands[i];
  5677. if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
  5678. continue;
  5679. if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
  5680. WIPHY_VENDOR_CMD_NEED_NETDEV)) {
  5681. if (!wdev)
  5682. return -EINVAL;
  5683. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
  5684. !wdev->netdev)
  5685. return -EINVAL;
  5686. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
  5687. if (wdev->netdev &&
  5688. !netif_running(wdev->netdev))
  5689. return -ENETDOWN;
  5690. }
  5691. } else {
  5692. wdev = NULL;
  5693. }
  5694. if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
  5695. data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  5696. len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  5697. }
  5698. rdev->cur_cmd_info = info;
  5699. err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
  5700. data, len);
  5701. rdev->cur_cmd_info = NULL;
  5702. return err;
  5703. }
  5704. return -EOPNOTSUPP;
  5705. }
  5706. struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
  5707. enum nl80211_commands cmd,
  5708. enum nl80211_attrs attr,
  5709. int approxlen)
  5710. {
  5711. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  5712. if (WARN_ON(!rdev->cur_cmd_info))
  5713. return NULL;
  5714. return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
  5715. 0,
  5716. 0,
  5717. cmd, attr, NULL, GFP_KERNEL);
  5718. }
  5719. EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
  5720. int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
  5721. {
  5722. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  5723. void *hdr = ((void **)skb->cb)[1];
  5724. struct nlattr *data = ((void **)skb->cb)[2];
  5725. if (WARN_ON(!rdev->cur_cmd_info)) {
  5726. kfree_skb(skb);
  5727. return -EINVAL;
  5728. }
  5729. nla_nest_end(skb, data);
  5730. genlmsg_end(skb, hdr);
  5731. return genlmsg_reply(skb, rdev->cur_cmd_info);
  5732. }
  5733. EXPORT_SYMBOL(cfg80211_vendor_cmd_reply);
  5734. static int nl80211_set_qos_map(struct sk_buff *skb,
  5735. struct genl_info *info)
  5736. {
  5737. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5738. struct cfg80211_qos_map *qos_map = NULL;
  5739. struct net_device *dev = info->user_ptr[1];
  5740. u8 *pos, len, num_des, des_len, des;
  5741. int ret;
  5742. if (!rdev->ops->set_qos_map)
  5743. return -EOPNOTSUPP;
  5744. if (info->attrs[NL80211_ATTR_QOS_MAP]) {
  5745. pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
  5746. len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
  5747. if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
  5748. len > IEEE80211_QOS_MAP_LEN_MAX)
  5749. return -EINVAL;
  5750. qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
  5751. if (!qos_map)
  5752. return -ENOMEM;
  5753. num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
  5754. if (num_des) {
  5755. des_len = num_des *
  5756. sizeof(struct cfg80211_dscp_exception);
  5757. memcpy(qos_map->dscp_exception, pos, des_len);
  5758. qos_map->num_des = num_des;
  5759. for (des = 0; des < num_des; des++) {
  5760. if (qos_map->dscp_exception[des].up > 7) {
  5761. kfree(qos_map);
  5762. return -EINVAL;
  5763. }
  5764. }
  5765. pos += des_len;
  5766. }
  5767. memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
  5768. }
  5769. wdev_lock(dev->ieee80211_ptr);
  5770. ret = nl80211_key_allowed(dev->ieee80211_ptr);
  5771. if (!ret)
  5772. ret = rdev->ops->set_qos_map(&rdev->wiphy, dev, qos_map);
  5773. wdev_unlock(dev->ieee80211_ptr);
  5774. kfree(qos_map);
  5775. return ret;
  5776. }
  5777. #define NL80211_FLAG_NEED_WIPHY 0x01
  5778. #define NL80211_FLAG_NEED_NETDEV 0x02
  5779. #define NL80211_FLAG_NEED_RTNL 0x04
  5780. #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
  5781. #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
  5782. NL80211_FLAG_CHECK_NETDEV_UP)
  5783. static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
  5784. struct genl_info *info)
  5785. {
  5786. struct cfg80211_registered_device *rdev;
  5787. struct net_device *dev;
  5788. int err;
  5789. bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
  5790. if (rtnl)
  5791. rtnl_lock();
  5792. if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
  5793. rdev = cfg80211_get_dev_from_info(info);
  5794. if (IS_ERR(rdev)) {
  5795. if (rtnl)
  5796. rtnl_unlock();
  5797. return PTR_ERR(rdev);
  5798. }
  5799. info->user_ptr[0] = rdev;
  5800. } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
  5801. err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
  5802. &rdev, &dev);
  5803. if (err) {
  5804. if (rtnl)
  5805. rtnl_unlock();
  5806. return err;
  5807. }
  5808. if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
  5809. !netif_running(dev)) {
  5810. cfg80211_unlock_rdev(rdev);
  5811. dev_put(dev);
  5812. if (rtnl)
  5813. rtnl_unlock();
  5814. return -ENETDOWN;
  5815. }
  5816. info->user_ptr[0] = rdev;
  5817. info->user_ptr[1] = dev;
  5818. }
  5819. return 0;
  5820. }
  5821. static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
  5822. struct genl_info *info)
  5823. {
  5824. if (info->user_ptr[0])
  5825. cfg80211_unlock_rdev(info->user_ptr[0]);
  5826. if (info->user_ptr[1])
  5827. dev_put(info->user_ptr[1]);
  5828. if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
  5829. rtnl_unlock();
  5830. }
  5831. static struct genl_ops nl80211_ops[] = {
  5832. {
  5833. .cmd = NL80211_CMD_GET_WIPHY,
  5834. .doit = nl80211_get_wiphy,
  5835. .dumpit = nl80211_dump_wiphy,
  5836. .policy = nl80211_policy,
  5837. /* can be retrieved by unprivileged users */
  5838. .internal_flags = NL80211_FLAG_NEED_WIPHY,
  5839. },
  5840. {
  5841. .cmd = NL80211_CMD_SET_WIPHY,
  5842. .doit = nl80211_set_wiphy,
  5843. .policy = nl80211_policy,
  5844. .flags = GENL_ADMIN_PERM,
  5845. .internal_flags = NL80211_FLAG_NEED_RTNL,
  5846. },
  5847. {
  5848. .cmd = NL80211_CMD_GET_INTERFACE,
  5849. .doit = nl80211_get_interface,
  5850. .dumpit = nl80211_dump_interface,
  5851. .policy = nl80211_policy,
  5852. /* can be retrieved by unprivileged users */
  5853. .internal_flags = NL80211_FLAG_NEED_NETDEV,
  5854. },
  5855. {
  5856. .cmd = NL80211_CMD_SET_INTERFACE,
  5857. .doit = nl80211_set_interface,
  5858. .policy = nl80211_policy,
  5859. .flags = GENL_ADMIN_PERM,
  5860. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  5861. NL80211_FLAG_NEED_RTNL,
  5862. },
  5863. {
  5864. .cmd = NL80211_CMD_NEW_INTERFACE,
  5865. .doit = nl80211_new_interface,
  5866. .policy = nl80211_policy,
  5867. .flags = GENL_ADMIN_PERM,
  5868. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  5869. NL80211_FLAG_NEED_RTNL,
  5870. },
  5871. {
  5872. .cmd = NL80211_CMD_DEL_INTERFACE,
  5873. .doit = nl80211_del_interface,
  5874. .policy = nl80211_policy,
  5875. .flags = GENL_ADMIN_PERM,
  5876. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  5877. NL80211_FLAG_NEED_RTNL,
  5878. },
  5879. {
  5880. .cmd = NL80211_CMD_GET_KEY,
  5881. .doit = nl80211_get_key,
  5882. .policy = nl80211_policy,
  5883. .flags = GENL_ADMIN_PERM,
  5884. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5885. NL80211_FLAG_NEED_RTNL,
  5886. },
  5887. {
  5888. .cmd = NL80211_CMD_SET_KEY,
  5889. .doit = nl80211_set_key,
  5890. .policy = nl80211_policy,
  5891. .flags = GENL_ADMIN_PERM,
  5892. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5893. NL80211_FLAG_NEED_RTNL,
  5894. },
  5895. {
  5896. .cmd = NL80211_CMD_NEW_KEY,
  5897. .doit = nl80211_new_key,
  5898. .policy = nl80211_policy,
  5899. .flags = GENL_ADMIN_PERM,
  5900. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5901. NL80211_FLAG_NEED_RTNL,
  5902. },
  5903. {
  5904. .cmd = NL80211_CMD_DEL_KEY,
  5905. .doit = nl80211_del_key,
  5906. .policy = nl80211_policy,
  5907. .flags = GENL_ADMIN_PERM,
  5908. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5909. NL80211_FLAG_NEED_RTNL,
  5910. },
  5911. {
  5912. .cmd = NL80211_CMD_SET_BEACON,
  5913. .policy = nl80211_policy,
  5914. .flags = GENL_ADMIN_PERM,
  5915. .doit = nl80211_set_beacon,
  5916. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5917. NL80211_FLAG_NEED_RTNL,
  5918. },
  5919. {
  5920. .cmd = NL80211_CMD_START_AP,
  5921. .policy = nl80211_policy,
  5922. .flags = GENL_ADMIN_PERM,
  5923. .doit = nl80211_start_ap,
  5924. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5925. NL80211_FLAG_NEED_RTNL,
  5926. },
  5927. {
  5928. .cmd = NL80211_CMD_STOP_AP,
  5929. .policy = nl80211_policy,
  5930. .flags = GENL_ADMIN_PERM,
  5931. .doit = nl80211_stop_ap,
  5932. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5933. NL80211_FLAG_NEED_RTNL,
  5934. },
  5935. {
  5936. .cmd = NL80211_CMD_GET_STATION,
  5937. .doit = nl80211_get_station,
  5938. .dumpit = nl80211_dump_station,
  5939. .policy = nl80211_policy,
  5940. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  5941. NL80211_FLAG_NEED_RTNL,
  5942. },
  5943. {
  5944. .cmd = NL80211_CMD_SET_STATION,
  5945. .doit = nl80211_set_station,
  5946. .policy = nl80211_policy,
  5947. .flags = GENL_ADMIN_PERM,
  5948. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5949. NL80211_FLAG_NEED_RTNL,
  5950. },
  5951. {
  5952. .cmd = NL80211_CMD_NEW_STATION,
  5953. .doit = nl80211_new_station,
  5954. .policy = nl80211_policy,
  5955. .flags = GENL_ADMIN_PERM,
  5956. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5957. NL80211_FLAG_NEED_RTNL,
  5958. },
  5959. {
  5960. .cmd = NL80211_CMD_DEL_STATION,
  5961. .doit = nl80211_del_station,
  5962. .policy = nl80211_policy,
  5963. .flags = GENL_ADMIN_PERM,
  5964. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5965. NL80211_FLAG_NEED_RTNL,
  5966. },
  5967. {
  5968. .cmd = NL80211_CMD_GET_MPATH,
  5969. .doit = nl80211_get_mpath,
  5970. .dumpit = nl80211_dump_mpath,
  5971. .policy = nl80211_policy,
  5972. .flags = GENL_ADMIN_PERM,
  5973. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5974. NL80211_FLAG_NEED_RTNL,
  5975. },
  5976. {
  5977. .cmd = NL80211_CMD_SET_MPATH,
  5978. .doit = nl80211_set_mpath,
  5979. .policy = nl80211_policy,
  5980. .flags = GENL_ADMIN_PERM,
  5981. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5982. NL80211_FLAG_NEED_RTNL,
  5983. },
  5984. {
  5985. .cmd = NL80211_CMD_NEW_MPATH,
  5986. .doit = nl80211_new_mpath,
  5987. .policy = nl80211_policy,
  5988. .flags = GENL_ADMIN_PERM,
  5989. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5990. NL80211_FLAG_NEED_RTNL,
  5991. },
  5992. {
  5993. .cmd = NL80211_CMD_DEL_MPATH,
  5994. .doit = nl80211_del_mpath,
  5995. .policy = nl80211_policy,
  5996. .flags = GENL_ADMIN_PERM,
  5997. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  5998. NL80211_FLAG_NEED_RTNL,
  5999. },
  6000. {
  6001. .cmd = NL80211_CMD_SET_BSS,
  6002. .doit = nl80211_set_bss,
  6003. .policy = nl80211_policy,
  6004. .flags = GENL_ADMIN_PERM,
  6005. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6006. NL80211_FLAG_NEED_RTNL,
  6007. },
  6008. {
  6009. .cmd = NL80211_CMD_GET_REG,
  6010. .doit = nl80211_get_reg,
  6011. .policy = nl80211_policy,
  6012. /* can be retrieved by unprivileged users */
  6013. },
  6014. {
  6015. .cmd = NL80211_CMD_SET_REG,
  6016. .doit = nl80211_set_reg,
  6017. .policy = nl80211_policy,
  6018. .flags = GENL_ADMIN_PERM,
  6019. },
  6020. {
  6021. .cmd = NL80211_CMD_REQ_SET_REG,
  6022. .doit = nl80211_req_set_reg,
  6023. .policy = nl80211_policy,
  6024. .flags = GENL_ADMIN_PERM,
  6025. },
  6026. {
  6027. .cmd = NL80211_CMD_GET_MESH_CONFIG,
  6028. .doit = nl80211_get_mesh_config,
  6029. .policy = nl80211_policy,
  6030. /* can be retrieved by unprivileged users */
  6031. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6032. NL80211_FLAG_NEED_RTNL,
  6033. },
  6034. {
  6035. .cmd = NL80211_CMD_SET_MESH_CONFIG,
  6036. .doit = nl80211_update_mesh_config,
  6037. .policy = nl80211_policy,
  6038. .flags = GENL_ADMIN_PERM,
  6039. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6040. NL80211_FLAG_NEED_RTNL,
  6041. },
  6042. {
  6043. .cmd = NL80211_CMD_TRIGGER_SCAN,
  6044. .doit = nl80211_trigger_scan,
  6045. .policy = nl80211_policy,
  6046. .flags = GENL_ADMIN_PERM,
  6047. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6048. NL80211_FLAG_NEED_RTNL,
  6049. },
  6050. {
  6051. .cmd = NL80211_CMD_GET_SCAN,
  6052. .policy = nl80211_policy,
  6053. .dumpit = nl80211_dump_scan,
  6054. },
  6055. {
  6056. .cmd = NL80211_CMD_START_SCHED_SCAN,
  6057. .doit = nl80211_start_sched_scan,
  6058. .policy = nl80211_policy,
  6059. .flags = GENL_ADMIN_PERM,
  6060. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6061. NL80211_FLAG_NEED_RTNL,
  6062. },
  6063. {
  6064. .cmd = NL80211_CMD_STOP_SCHED_SCAN,
  6065. .doit = nl80211_stop_sched_scan,
  6066. .policy = nl80211_policy,
  6067. .flags = GENL_ADMIN_PERM,
  6068. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6069. NL80211_FLAG_NEED_RTNL,
  6070. },
  6071. {
  6072. .cmd = NL80211_CMD_AUTHENTICATE,
  6073. .doit = nl80211_authenticate,
  6074. .policy = nl80211_policy,
  6075. .flags = GENL_ADMIN_PERM,
  6076. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6077. NL80211_FLAG_NEED_RTNL,
  6078. },
  6079. {
  6080. .cmd = NL80211_CMD_ASSOCIATE,
  6081. .doit = nl80211_associate,
  6082. .policy = nl80211_policy,
  6083. .flags = GENL_ADMIN_PERM,
  6084. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6085. NL80211_FLAG_NEED_RTNL,
  6086. },
  6087. {
  6088. .cmd = NL80211_CMD_DEAUTHENTICATE,
  6089. .doit = nl80211_deauthenticate,
  6090. .policy = nl80211_policy,
  6091. .flags = GENL_ADMIN_PERM,
  6092. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6093. NL80211_FLAG_NEED_RTNL,
  6094. },
  6095. {
  6096. .cmd = NL80211_CMD_DISASSOCIATE,
  6097. .doit = nl80211_disassociate,
  6098. .policy = nl80211_policy,
  6099. .flags = GENL_ADMIN_PERM,
  6100. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6101. NL80211_FLAG_NEED_RTNL,
  6102. },
  6103. {
  6104. .cmd = NL80211_CMD_JOIN_IBSS,
  6105. .doit = nl80211_join_ibss,
  6106. .policy = nl80211_policy,
  6107. .flags = GENL_ADMIN_PERM,
  6108. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6109. NL80211_FLAG_NEED_RTNL,
  6110. },
  6111. {
  6112. .cmd = NL80211_CMD_LEAVE_IBSS,
  6113. .doit = nl80211_leave_ibss,
  6114. .policy = nl80211_policy,
  6115. .flags = GENL_ADMIN_PERM,
  6116. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6117. NL80211_FLAG_NEED_RTNL,
  6118. },
  6119. #ifdef CONFIG_NL80211_TESTMODE
  6120. {
  6121. .cmd = NL80211_CMD_TESTMODE,
  6122. .doit = nl80211_testmode_do,
  6123. .dumpit = nl80211_testmode_dump,
  6124. .policy = nl80211_policy,
  6125. .flags = GENL_ADMIN_PERM,
  6126. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  6127. NL80211_FLAG_NEED_RTNL,
  6128. },
  6129. #endif
  6130. {
  6131. .cmd = NL80211_CMD_CONNECT,
  6132. .doit = nl80211_connect,
  6133. .policy = nl80211_policy,
  6134. .flags = GENL_ADMIN_PERM,
  6135. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6136. NL80211_FLAG_NEED_RTNL,
  6137. },
  6138. {
  6139. .cmd = NL80211_CMD_DISCONNECT,
  6140. .doit = nl80211_disconnect,
  6141. .policy = nl80211_policy,
  6142. .flags = GENL_ADMIN_PERM,
  6143. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6144. NL80211_FLAG_NEED_RTNL,
  6145. },
  6146. {
  6147. .cmd = NL80211_CMD_SET_WIPHY_NETNS,
  6148. .doit = nl80211_wiphy_netns,
  6149. .policy = nl80211_policy,
  6150. .flags = GENL_ADMIN_PERM,
  6151. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  6152. NL80211_FLAG_NEED_RTNL,
  6153. },
  6154. {
  6155. .cmd = NL80211_CMD_GET_SURVEY,
  6156. .policy = nl80211_policy,
  6157. .dumpit = nl80211_dump_survey,
  6158. },
  6159. {
  6160. .cmd = NL80211_CMD_SET_PMKSA,
  6161. .doit = nl80211_setdel_pmksa,
  6162. .policy = nl80211_policy,
  6163. .flags = GENL_ADMIN_PERM,
  6164. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6165. NL80211_FLAG_NEED_RTNL,
  6166. },
  6167. {
  6168. .cmd = NL80211_CMD_DEL_PMKSA,
  6169. .doit = nl80211_setdel_pmksa,
  6170. .policy = nl80211_policy,
  6171. .flags = GENL_ADMIN_PERM,
  6172. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6173. NL80211_FLAG_NEED_RTNL,
  6174. },
  6175. {
  6176. .cmd = NL80211_CMD_FLUSH_PMKSA,
  6177. .doit = nl80211_flush_pmksa,
  6178. .policy = nl80211_policy,
  6179. .flags = GENL_ADMIN_PERM,
  6180. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6181. NL80211_FLAG_NEED_RTNL,
  6182. },
  6183. {
  6184. .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
  6185. .doit = nl80211_remain_on_channel,
  6186. .policy = nl80211_policy,
  6187. .flags = GENL_ADMIN_PERM,
  6188. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6189. NL80211_FLAG_NEED_RTNL,
  6190. },
  6191. {
  6192. .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  6193. .doit = nl80211_cancel_remain_on_channel,
  6194. .policy = nl80211_policy,
  6195. .flags = GENL_ADMIN_PERM,
  6196. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6197. NL80211_FLAG_NEED_RTNL,
  6198. },
  6199. {
  6200. .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
  6201. .doit = nl80211_set_tx_bitrate_mask,
  6202. .policy = nl80211_policy,
  6203. .flags = GENL_ADMIN_PERM,
  6204. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6205. NL80211_FLAG_NEED_RTNL,
  6206. },
  6207. {
  6208. .cmd = NL80211_CMD_REGISTER_FRAME,
  6209. .doit = nl80211_register_mgmt,
  6210. .policy = nl80211_policy,
  6211. .flags = GENL_ADMIN_PERM,
  6212. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6213. NL80211_FLAG_NEED_RTNL,
  6214. },
  6215. {
  6216. .cmd = NL80211_CMD_FRAME,
  6217. .doit = nl80211_tx_mgmt,
  6218. .policy = nl80211_policy,
  6219. .flags = GENL_ADMIN_PERM,
  6220. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6221. NL80211_FLAG_NEED_RTNL,
  6222. },
  6223. {
  6224. .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
  6225. .doit = nl80211_tx_mgmt_cancel_wait,
  6226. .policy = nl80211_policy,
  6227. .flags = GENL_ADMIN_PERM,
  6228. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6229. NL80211_FLAG_NEED_RTNL,
  6230. },
  6231. {
  6232. .cmd = NL80211_CMD_SET_POWER_SAVE,
  6233. .doit = nl80211_set_power_save,
  6234. .policy = nl80211_policy,
  6235. .flags = GENL_ADMIN_PERM,
  6236. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6237. NL80211_FLAG_NEED_RTNL,
  6238. },
  6239. {
  6240. .cmd = NL80211_CMD_GET_POWER_SAVE,
  6241. .doit = nl80211_get_power_save,
  6242. .policy = nl80211_policy,
  6243. /* can be retrieved by unprivileged users */
  6244. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6245. NL80211_FLAG_NEED_RTNL,
  6246. },
  6247. {
  6248. .cmd = NL80211_CMD_SET_CQM,
  6249. .doit = nl80211_set_cqm,
  6250. .policy = nl80211_policy,
  6251. .flags = GENL_ADMIN_PERM,
  6252. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6253. NL80211_FLAG_NEED_RTNL,
  6254. },
  6255. {
  6256. .cmd = NL80211_CMD_SET_CHANNEL,
  6257. .doit = nl80211_set_channel,
  6258. .policy = nl80211_policy,
  6259. .flags = GENL_ADMIN_PERM,
  6260. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6261. NL80211_FLAG_NEED_RTNL,
  6262. },
  6263. {
  6264. .cmd = NL80211_CMD_SET_WDS_PEER,
  6265. .doit = nl80211_set_wds_peer,
  6266. .policy = nl80211_policy,
  6267. .flags = GENL_ADMIN_PERM,
  6268. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6269. NL80211_FLAG_NEED_RTNL,
  6270. },
  6271. {
  6272. .cmd = NL80211_CMD_JOIN_MESH,
  6273. .doit = nl80211_join_mesh,
  6274. .policy = nl80211_policy,
  6275. .flags = GENL_ADMIN_PERM,
  6276. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6277. NL80211_FLAG_NEED_RTNL,
  6278. },
  6279. {
  6280. .cmd = NL80211_CMD_LEAVE_MESH,
  6281. .doit = nl80211_leave_mesh,
  6282. .policy = nl80211_policy,
  6283. .flags = GENL_ADMIN_PERM,
  6284. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6285. NL80211_FLAG_NEED_RTNL,
  6286. },
  6287. {
  6288. .cmd = NL80211_CMD_GET_WOWLAN,
  6289. .doit = nl80211_get_wowlan,
  6290. .policy = nl80211_policy,
  6291. /* can be retrieved by unprivileged users */
  6292. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  6293. NL80211_FLAG_NEED_RTNL,
  6294. },
  6295. {
  6296. .cmd = NL80211_CMD_SET_WOWLAN,
  6297. .doit = nl80211_set_wowlan,
  6298. .policy = nl80211_policy,
  6299. .flags = GENL_ADMIN_PERM,
  6300. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  6301. NL80211_FLAG_NEED_RTNL,
  6302. },
  6303. {
  6304. .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
  6305. .doit = nl80211_set_rekey_data,
  6306. .policy = nl80211_policy,
  6307. .flags = GENL_ADMIN_PERM,
  6308. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6309. NL80211_FLAG_NEED_RTNL,
  6310. },
  6311. {
  6312. .cmd = NL80211_CMD_TDLS_MGMT,
  6313. .doit = nl80211_tdls_mgmt,
  6314. .policy = nl80211_policy,
  6315. .flags = GENL_ADMIN_PERM,
  6316. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6317. NL80211_FLAG_NEED_RTNL,
  6318. },
  6319. {
  6320. .cmd = NL80211_CMD_TDLS_OPER,
  6321. .doit = nl80211_tdls_oper,
  6322. .policy = nl80211_policy,
  6323. .flags = GENL_ADMIN_PERM,
  6324. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6325. NL80211_FLAG_NEED_RTNL,
  6326. },
  6327. {
  6328. .cmd = NL80211_CMD_UNEXPECTED_FRAME,
  6329. .doit = nl80211_register_unexpected_frame,
  6330. .policy = nl80211_policy,
  6331. .flags = GENL_ADMIN_PERM,
  6332. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6333. NL80211_FLAG_NEED_RTNL,
  6334. },
  6335. {
  6336. .cmd = NL80211_CMD_PROBE_CLIENT,
  6337. .doit = nl80211_probe_client,
  6338. .policy = nl80211_policy,
  6339. .flags = GENL_ADMIN_PERM,
  6340. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6341. NL80211_FLAG_NEED_RTNL,
  6342. },
  6343. {
  6344. .cmd = NL80211_CMD_REGISTER_BEACONS,
  6345. .doit = nl80211_register_beacons,
  6346. .policy = nl80211_policy,
  6347. .flags = GENL_ADMIN_PERM,
  6348. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  6349. NL80211_FLAG_NEED_RTNL,
  6350. },
  6351. {
  6352. .cmd = NL80211_CMD_SET_NOACK_MAP,
  6353. .doit = nl80211_set_noack_map,
  6354. .policy = nl80211_policy,
  6355. .flags = GENL_ADMIN_PERM,
  6356. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6357. NL80211_FLAG_NEED_RTNL,
  6358. },
  6359. {
  6360. .cmd = NL80211_CMD_SET_MAC_ACL,
  6361. .doit = nl80211_set_mac_acl,
  6362. .policy = nl80211_policy,
  6363. .flags = GENL_ADMIN_PERM,
  6364. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6365. NL80211_FLAG_NEED_RTNL,
  6366. },
  6367. {
  6368. .cmd = NL80211_CMD_UPDATE_FT_IES,
  6369. .doit = nl80211_update_ft_ies,
  6370. .policy = nl80211_policy,
  6371. .flags = GENL_ADMIN_PERM,
  6372. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6373. NL80211_FLAG_NEED_RTNL,
  6374. },
  6375. {
  6376. .cmd = NL80211_CMD_VENDOR,
  6377. .doit = nl80211_vendor_cmd,
  6378. .policy = nl80211_policy,
  6379. .flags = GENL_ADMIN_PERM,
  6380. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  6381. NL80211_FLAG_NEED_RTNL,
  6382. },
  6383. {
  6384. .cmd = NL80211_CMD_SET_QOS_MAP,
  6385. .doit = nl80211_set_qos_map,
  6386. .policy = nl80211_policy,
  6387. .flags = GENL_ADMIN_PERM,
  6388. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  6389. NL80211_FLAG_NEED_RTNL,
  6390. },
  6391. };
  6392. static struct genl_multicast_group nl80211_mlme_mcgrp = {
  6393. .name = "mlme",
  6394. };
  6395. /* multicast groups */
  6396. static struct genl_multicast_group nl80211_config_mcgrp = {
  6397. .name = "config",
  6398. };
  6399. static struct genl_multicast_group nl80211_scan_mcgrp = {
  6400. .name = "scan",
  6401. };
  6402. static struct genl_multicast_group nl80211_regulatory_mcgrp = {
  6403. .name = "regulatory",
  6404. };
  6405. /* notification functions */
  6406. void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
  6407. {
  6408. struct sk_buff *msg;
  6409. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  6410. if (!msg)
  6411. return;
  6412. if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
  6413. nlmsg_free(msg);
  6414. return;
  6415. }
  6416. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6417. nl80211_config_mcgrp.id, GFP_KERNEL);
  6418. }
  6419. static int nl80211_add_scan_req(struct sk_buff *msg,
  6420. struct cfg80211_registered_device *rdev)
  6421. {
  6422. struct cfg80211_scan_request *req = rdev->scan_req;
  6423. struct nlattr *nest;
  6424. int i;
  6425. ASSERT_RDEV_LOCK(rdev);
  6426. if (WARN_ON(!req))
  6427. return 0;
  6428. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
  6429. if (!nest)
  6430. goto nla_put_failure;
  6431. for (i = 0; i < req->n_ssids; i++)
  6432. NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
  6433. nla_nest_end(msg, nest);
  6434. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  6435. if (!nest)
  6436. goto nla_put_failure;
  6437. for (i = 0; i < req->n_channels; i++)
  6438. NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
  6439. nla_nest_end(msg, nest);
  6440. if (req->ie)
  6441. NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
  6442. return 0;
  6443. nla_put_failure:
  6444. return -ENOBUFS;
  6445. }
  6446. static int nl80211_send_scan_msg(struct sk_buff *msg,
  6447. struct cfg80211_registered_device *rdev,
  6448. struct net_device *netdev,
  6449. u32 pid, u32 seq, int flags,
  6450. u32 cmd)
  6451. {
  6452. void *hdr;
  6453. hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
  6454. if (!hdr)
  6455. return -1;
  6456. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6457. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6458. /* ignore errors and send incomplete event anyway */
  6459. nl80211_add_scan_req(msg, rdev);
  6460. return genlmsg_end(msg, hdr);
  6461. nla_put_failure:
  6462. genlmsg_cancel(msg, hdr);
  6463. return -EMSGSIZE;
  6464. }
  6465. static int
  6466. nl80211_send_sched_scan_msg(struct sk_buff *msg,
  6467. struct cfg80211_registered_device *rdev,
  6468. struct net_device *netdev,
  6469. u32 pid, u32 seq, int flags, u32 cmd)
  6470. {
  6471. void *hdr;
  6472. hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
  6473. if (!hdr)
  6474. return -1;
  6475. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6476. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6477. return genlmsg_end(msg, hdr);
  6478. nla_put_failure:
  6479. genlmsg_cancel(msg, hdr);
  6480. return -EMSGSIZE;
  6481. }
  6482. void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
  6483. struct net_device *netdev)
  6484. {
  6485. struct sk_buff *msg;
  6486. msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  6487. if (!msg)
  6488. return;
  6489. if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
  6490. NL80211_CMD_TRIGGER_SCAN) < 0) {
  6491. nlmsg_free(msg);
  6492. return;
  6493. }
  6494. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6495. nl80211_scan_mcgrp.id, GFP_KERNEL);
  6496. }
  6497. void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
  6498. struct net_device *netdev)
  6499. {
  6500. struct sk_buff *msg;
  6501. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  6502. if (!msg)
  6503. return;
  6504. if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
  6505. NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
  6506. nlmsg_free(msg);
  6507. return;
  6508. }
  6509. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6510. nl80211_scan_mcgrp.id, GFP_KERNEL);
  6511. }
  6512. void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
  6513. struct net_device *netdev)
  6514. {
  6515. struct sk_buff *msg;
  6516. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  6517. if (!msg)
  6518. return;
  6519. if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
  6520. NL80211_CMD_SCAN_ABORTED) < 0) {
  6521. nlmsg_free(msg);
  6522. return;
  6523. }
  6524. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6525. nl80211_scan_mcgrp.id, GFP_KERNEL);
  6526. }
  6527. void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
  6528. struct net_device *netdev)
  6529. {
  6530. struct sk_buff *msg;
  6531. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  6532. if (!msg)
  6533. return;
  6534. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
  6535. NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
  6536. nlmsg_free(msg);
  6537. return;
  6538. }
  6539. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6540. nl80211_scan_mcgrp.id, GFP_KERNEL);
  6541. }
  6542. void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
  6543. struct net_device *netdev, u32 cmd)
  6544. {
  6545. struct sk_buff *msg;
  6546. msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  6547. if (!msg)
  6548. return;
  6549. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
  6550. nlmsg_free(msg);
  6551. return;
  6552. }
  6553. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6554. nl80211_scan_mcgrp.id, GFP_KERNEL);
  6555. }
  6556. /*
  6557. * This can happen on global regulatory changes or device specific settings
  6558. * based on custom world regulatory domains.
  6559. */
  6560. void nl80211_send_reg_change_event(struct regulatory_request *request)
  6561. {
  6562. struct sk_buff *msg;
  6563. void *hdr;
  6564. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  6565. if (!msg)
  6566. return;
  6567. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
  6568. if (!hdr) {
  6569. nlmsg_free(msg);
  6570. return;
  6571. }
  6572. /* Userspace can always count this one always being set */
  6573. NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
  6574. if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
  6575. NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
  6576. NL80211_REGDOM_TYPE_WORLD);
  6577. else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
  6578. NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
  6579. NL80211_REGDOM_TYPE_CUSTOM_WORLD);
  6580. else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
  6581. request->intersect)
  6582. NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
  6583. NL80211_REGDOM_TYPE_INTERSECTION);
  6584. else {
  6585. NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
  6586. NL80211_REGDOM_TYPE_COUNTRY);
  6587. NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
  6588. }
  6589. if (wiphy_idx_valid(request->wiphy_idx))
  6590. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
  6591. genlmsg_end(msg, hdr);
  6592. rcu_read_lock();
  6593. genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
  6594. GFP_ATOMIC);
  6595. rcu_read_unlock();
  6596. return;
  6597. nla_put_failure:
  6598. genlmsg_cancel(msg, hdr);
  6599. nlmsg_free(msg);
  6600. }
  6601. static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
  6602. struct net_device *netdev,
  6603. const u8 *buf, size_t len,
  6604. enum nl80211_commands cmd, gfp_t gfp)
  6605. {
  6606. struct sk_buff *msg;
  6607. void *hdr;
  6608. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  6609. if (!msg)
  6610. return;
  6611. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  6612. if (!hdr) {
  6613. nlmsg_free(msg);
  6614. return;
  6615. }
  6616. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6617. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6618. NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
  6619. genlmsg_end(msg, hdr);
  6620. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6621. nl80211_mlme_mcgrp.id, gfp);
  6622. return;
  6623. nla_put_failure:
  6624. genlmsg_cancel(msg, hdr);
  6625. nlmsg_free(msg);
  6626. }
  6627. void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
  6628. struct net_device *netdev, const u8 *buf,
  6629. size_t len, gfp_t gfp)
  6630. {
  6631. nl80211_send_mlme_event(rdev, netdev, buf, len,
  6632. NL80211_CMD_AUTHENTICATE, gfp);
  6633. }
  6634. void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
  6635. struct net_device *netdev, const u8 *buf,
  6636. size_t len, gfp_t gfp)
  6637. {
  6638. nl80211_send_mlme_event(rdev, netdev, buf, len,
  6639. NL80211_CMD_ASSOCIATE, gfp);
  6640. }
  6641. void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
  6642. struct net_device *netdev, const u8 *buf,
  6643. size_t len, gfp_t gfp)
  6644. {
  6645. nl80211_send_mlme_event(rdev, netdev, buf, len,
  6646. NL80211_CMD_DEAUTHENTICATE, gfp);
  6647. }
  6648. void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
  6649. struct net_device *netdev, const u8 *buf,
  6650. size_t len, gfp_t gfp)
  6651. {
  6652. nl80211_send_mlme_event(rdev, netdev, buf, len,
  6653. NL80211_CMD_DISASSOCIATE, gfp);
  6654. }
  6655. void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
  6656. struct net_device *netdev, const u8 *buf,
  6657. size_t len, gfp_t gfp)
  6658. {
  6659. nl80211_send_mlme_event(rdev, netdev, buf, len,
  6660. NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
  6661. }
  6662. void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
  6663. struct net_device *netdev, const u8 *buf,
  6664. size_t len, gfp_t gfp)
  6665. {
  6666. nl80211_send_mlme_event(rdev, netdev, buf, len,
  6667. NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
  6668. }
  6669. static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
  6670. struct net_device *netdev, int cmd,
  6671. const u8 *addr, gfp_t gfp)
  6672. {
  6673. struct sk_buff *msg;
  6674. void *hdr;
  6675. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  6676. if (!msg)
  6677. return;
  6678. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  6679. if (!hdr) {
  6680. nlmsg_free(msg);
  6681. return;
  6682. }
  6683. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6684. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6685. NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
  6686. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  6687. genlmsg_end(msg, hdr);
  6688. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6689. nl80211_mlme_mcgrp.id, gfp);
  6690. return;
  6691. nla_put_failure:
  6692. genlmsg_cancel(msg, hdr);
  6693. nlmsg_free(msg);
  6694. }
  6695. void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
  6696. struct net_device *netdev, const u8 *addr,
  6697. gfp_t gfp)
  6698. {
  6699. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
  6700. addr, gfp);
  6701. }
  6702. void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
  6703. struct net_device *netdev, const u8 *addr,
  6704. gfp_t gfp)
  6705. {
  6706. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
  6707. addr, gfp);
  6708. }
  6709. void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
  6710. struct net_device *netdev, const u8 *bssid,
  6711. const u8 *req_ie, size_t req_ie_len,
  6712. const u8 *resp_ie, size_t resp_ie_len,
  6713. u16 status, gfp_t gfp)
  6714. {
  6715. struct sk_buff *msg;
  6716. void *hdr;
  6717. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  6718. if (!msg)
  6719. return;
  6720. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
  6721. if (!hdr) {
  6722. nlmsg_free(msg);
  6723. return;
  6724. }
  6725. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6726. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6727. if (bssid)
  6728. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
  6729. NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
  6730. if (req_ie)
  6731. NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
  6732. if (resp_ie)
  6733. NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
  6734. genlmsg_end(msg, hdr);
  6735. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6736. nl80211_mlme_mcgrp.id, gfp);
  6737. return;
  6738. nla_put_failure:
  6739. genlmsg_cancel(msg, hdr);
  6740. nlmsg_free(msg);
  6741. }
  6742. void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
  6743. struct net_device *netdev, const u8 *bssid,
  6744. const u8 *req_ie, size_t req_ie_len,
  6745. const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
  6746. {
  6747. struct sk_buff *msg;
  6748. void *hdr;
  6749. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  6750. if (!msg)
  6751. return;
  6752. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
  6753. if (!hdr) {
  6754. nlmsg_free(msg);
  6755. return;
  6756. }
  6757. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6758. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6759. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
  6760. if (req_ie)
  6761. NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
  6762. if (resp_ie)
  6763. NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
  6764. genlmsg_end(msg, hdr);
  6765. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6766. nl80211_mlme_mcgrp.id, gfp);
  6767. return;
  6768. nla_put_failure:
  6769. genlmsg_cancel(msg, hdr);
  6770. nlmsg_free(msg);
  6771. }
  6772. void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
  6773. struct net_device *netdev, u16 reason,
  6774. const u8 *ie, size_t ie_len, bool from_ap)
  6775. {
  6776. struct sk_buff *msg;
  6777. void *hdr;
  6778. msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  6779. if (!msg)
  6780. return;
  6781. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
  6782. if (!hdr) {
  6783. nlmsg_free(msg);
  6784. return;
  6785. }
  6786. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6787. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6788. if (from_ap && reason)
  6789. NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
  6790. if (from_ap)
  6791. NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
  6792. if (ie)
  6793. NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
  6794. genlmsg_end(msg, hdr);
  6795. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6796. nl80211_mlme_mcgrp.id, GFP_KERNEL);
  6797. return;
  6798. nla_put_failure:
  6799. genlmsg_cancel(msg, hdr);
  6800. nlmsg_free(msg);
  6801. }
  6802. void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
  6803. struct net_device *netdev, const u8 *bssid,
  6804. gfp_t gfp)
  6805. {
  6806. struct sk_buff *msg;
  6807. void *hdr;
  6808. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  6809. if (!msg)
  6810. return;
  6811. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
  6812. if (!hdr) {
  6813. nlmsg_free(msg);
  6814. return;
  6815. }
  6816. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6817. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6818. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
  6819. genlmsg_end(msg, hdr);
  6820. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6821. nl80211_mlme_mcgrp.id, gfp);
  6822. return;
  6823. nla_put_failure:
  6824. genlmsg_cancel(msg, hdr);
  6825. nlmsg_free(msg);
  6826. }
  6827. void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
  6828. struct net_device *netdev,
  6829. const u8 *macaddr, const u8* ie, u8 ie_len,
  6830. gfp_t gfp)
  6831. {
  6832. struct sk_buff *msg;
  6833. void *hdr;
  6834. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  6835. if (!msg)
  6836. return;
  6837. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
  6838. if (!hdr) {
  6839. nlmsg_free(msg);
  6840. return;
  6841. }
  6842. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6843. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6844. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
  6845. if (ie_len && ie)
  6846. NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
  6847. genlmsg_end(msg, hdr);
  6848. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6849. nl80211_mlme_mcgrp.id, gfp);
  6850. return;
  6851. nla_put_failure:
  6852. genlmsg_cancel(msg, hdr);
  6853. nlmsg_free(msg);
  6854. }
  6855. void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
  6856. struct net_device *netdev, const u8 *addr,
  6857. enum nl80211_key_type key_type, int key_id,
  6858. const u8 *tsc, gfp_t gfp)
  6859. {
  6860. struct sk_buff *msg;
  6861. void *hdr;
  6862. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  6863. if (!msg)
  6864. return;
  6865. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
  6866. if (!hdr) {
  6867. nlmsg_free(msg);
  6868. return;
  6869. }
  6870. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6871. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6872. if (addr)
  6873. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  6874. NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
  6875. if (key_id != -1)
  6876. NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
  6877. if (tsc)
  6878. NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
  6879. genlmsg_end(msg, hdr);
  6880. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6881. nl80211_mlme_mcgrp.id, gfp);
  6882. return;
  6883. nla_put_failure:
  6884. genlmsg_cancel(msg, hdr);
  6885. nlmsg_free(msg);
  6886. }
  6887. void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
  6888. struct ieee80211_channel *channel_before,
  6889. struct ieee80211_channel *channel_after)
  6890. {
  6891. struct sk_buff *msg;
  6892. void *hdr;
  6893. struct nlattr *nl_freq;
  6894. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  6895. if (!msg)
  6896. return;
  6897. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
  6898. if (!hdr) {
  6899. nlmsg_free(msg);
  6900. return;
  6901. }
  6902. /*
  6903. * Since we are applying the beacon hint to a wiphy we know its
  6904. * wiphy_idx is valid
  6905. */
  6906. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
  6907. /* Before */
  6908. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
  6909. if (!nl_freq)
  6910. goto nla_put_failure;
  6911. if (nl80211_msg_put_channel(msg, channel_before))
  6912. goto nla_put_failure;
  6913. nla_nest_end(msg, nl_freq);
  6914. /* After */
  6915. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
  6916. if (!nl_freq)
  6917. goto nla_put_failure;
  6918. if (nl80211_msg_put_channel(msg, channel_after))
  6919. goto nla_put_failure;
  6920. nla_nest_end(msg, nl_freq);
  6921. genlmsg_end(msg, hdr);
  6922. rcu_read_lock();
  6923. genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
  6924. GFP_ATOMIC);
  6925. rcu_read_unlock();
  6926. return;
  6927. nla_put_failure:
  6928. genlmsg_cancel(msg, hdr);
  6929. nlmsg_free(msg);
  6930. }
  6931. static void nl80211_send_remain_on_chan_event(
  6932. int cmd, struct cfg80211_registered_device *rdev,
  6933. struct net_device *netdev, u64 cookie,
  6934. struct ieee80211_channel *chan,
  6935. enum nl80211_channel_type channel_type,
  6936. unsigned int duration, gfp_t gfp)
  6937. {
  6938. struct sk_buff *msg;
  6939. void *hdr;
  6940. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  6941. if (!msg)
  6942. return;
  6943. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  6944. if (!hdr) {
  6945. nlmsg_free(msg);
  6946. return;
  6947. }
  6948. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  6949. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  6950. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
  6951. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
  6952. NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
  6953. if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
  6954. NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
  6955. genlmsg_end(msg, hdr);
  6956. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6957. nl80211_mlme_mcgrp.id, gfp);
  6958. return;
  6959. nla_put_failure:
  6960. genlmsg_cancel(msg, hdr);
  6961. nlmsg_free(msg);
  6962. }
  6963. void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
  6964. struct net_device *netdev, u64 cookie,
  6965. struct ieee80211_channel *chan,
  6966. enum nl80211_channel_type channel_type,
  6967. unsigned int duration, gfp_t gfp)
  6968. {
  6969. nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
  6970. rdev, netdev, cookie, chan,
  6971. channel_type, duration, gfp);
  6972. }
  6973. void nl80211_send_remain_on_channel_cancel(
  6974. struct cfg80211_registered_device *rdev, struct net_device *netdev,
  6975. u64 cookie, struct ieee80211_channel *chan,
  6976. enum nl80211_channel_type channel_type, gfp_t gfp)
  6977. {
  6978. nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  6979. rdev, netdev, cookie, chan,
  6980. channel_type, 0, gfp);
  6981. }
  6982. void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
  6983. struct net_device *dev, const u8 *mac_addr,
  6984. struct station_info *sinfo, gfp_t gfp)
  6985. {
  6986. struct sk_buff *msg;
  6987. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  6988. if (!msg)
  6989. return;
  6990. if (nl80211_send_station(msg, 0, 0, 0,
  6991. rdev, dev, mac_addr, sinfo) < 0) {
  6992. nlmsg_free(msg);
  6993. return;
  6994. }
  6995. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  6996. nl80211_mlme_mcgrp.id, gfp);
  6997. }
  6998. void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
  6999. struct net_device *dev, const u8 *mac_addr,
  7000. gfp_t gfp)
  7001. {
  7002. struct sk_buff *msg;
  7003. void *hdr;
  7004. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  7005. if (!msg)
  7006. return;
  7007. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
  7008. if (!hdr) {
  7009. nlmsg_free(msg);
  7010. return;
  7011. }
  7012. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  7013. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
  7014. genlmsg_end(msg, hdr);
  7015. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7016. nl80211_mlme_mcgrp.id, gfp);
  7017. return;
  7018. nla_put_failure:
  7019. genlmsg_cancel(msg, hdr);
  7020. nlmsg_free(msg);
  7021. }
  7022. static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
  7023. const u8 *addr, gfp_t gfp)
  7024. {
  7025. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7026. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  7027. struct sk_buff *msg;
  7028. void *hdr;
  7029. int err;
  7030. u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
  7031. if (!nlpid)
  7032. return false;
  7033. msg = nlmsg_new(100, gfp);
  7034. if (!msg)
  7035. return true;
  7036. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  7037. if (!hdr) {
  7038. nlmsg_free(msg);
  7039. return true;
  7040. }
  7041. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7042. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  7043. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  7044. err = genlmsg_end(msg, hdr);
  7045. if (err < 0) {
  7046. nlmsg_free(msg);
  7047. return true;
  7048. }
  7049. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
  7050. return true;
  7051. nla_put_failure:
  7052. genlmsg_cancel(msg, hdr);
  7053. nlmsg_free(msg);
  7054. return true;
  7055. }
  7056. bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
  7057. {
  7058. return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
  7059. addr, gfp);
  7060. }
  7061. bool nl80211_unexpected_4addr_frame(struct net_device *dev,
  7062. const u8 *addr, gfp_t gfp)
  7063. {
  7064. return __nl80211_unexpected_frame(dev,
  7065. NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
  7066. addr, gfp);
  7067. }
  7068. int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
  7069. struct net_device *netdev, u32 nlpid,
  7070. int freq, int sig_dbm,
  7071. const u8 *buf, size_t len, gfp_t gfp)
  7072. {
  7073. struct sk_buff *msg;
  7074. void *hdr;
  7075. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  7076. if (!msg)
  7077. return -ENOMEM;
  7078. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  7079. if (!hdr) {
  7080. nlmsg_free(msg);
  7081. return -ENOMEM;
  7082. }
  7083. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7084. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7085. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
  7086. if (sig_dbm)
  7087. NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
  7088. NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
  7089. genlmsg_end(msg, hdr);
  7090. return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
  7091. nla_put_failure:
  7092. genlmsg_cancel(msg, hdr);
  7093. nlmsg_free(msg);
  7094. return -ENOBUFS;
  7095. }
  7096. void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
  7097. struct net_device *netdev, u64 cookie,
  7098. const u8 *buf, size_t len, bool ack,
  7099. gfp_t gfp)
  7100. {
  7101. struct sk_buff *msg;
  7102. void *hdr;
  7103. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  7104. if (!msg)
  7105. return;
  7106. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
  7107. if (!hdr) {
  7108. nlmsg_free(msg);
  7109. return;
  7110. }
  7111. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7112. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7113. NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
  7114. NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
  7115. if (ack)
  7116. NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
  7117. genlmsg_end(msg, hdr);
  7118. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7119. nl80211_mlme_mcgrp.id, gfp);
  7120. return;
  7121. nla_put_failure:
  7122. genlmsg_cancel(msg, hdr);
  7123. nlmsg_free(msg);
  7124. }
  7125. void
  7126. nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
  7127. struct net_device *netdev,
  7128. enum nl80211_cqm_rssi_threshold_event rssi_event,
  7129. gfp_t gfp)
  7130. {
  7131. struct sk_buff *msg;
  7132. struct nlattr *pinfoattr;
  7133. void *hdr;
  7134. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  7135. if (!msg)
  7136. return;
  7137. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
  7138. if (!hdr) {
  7139. nlmsg_free(msg);
  7140. return;
  7141. }
  7142. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7143. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7144. pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
  7145. if (!pinfoattr)
  7146. goto nla_put_failure;
  7147. NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
  7148. rssi_event);
  7149. nla_nest_end(msg, pinfoattr);
  7150. genlmsg_end(msg, hdr);
  7151. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7152. nl80211_mlme_mcgrp.id, gfp);
  7153. return;
  7154. nla_put_failure:
  7155. genlmsg_cancel(msg, hdr);
  7156. nlmsg_free(msg);
  7157. }
  7158. void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
  7159. struct net_device *netdev, const u8 *bssid,
  7160. const u8 *replay_ctr, gfp_t gfp)
  7161. {
  7162. struct sk_buff *msg;
  7163. struct nlattr *rekey_attr;
  7164. void *hdr;
  7165. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  7166. if (!msg)
  7167. return;
  7168. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
  7169. if (!hdr) {
  7170. nlmsg_free(msg);
  7171. return;
  7172. }
  7173. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7174. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7175. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
  7176. rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
  7177. if (!rekey_attr)
  7178. goto nla_put_failure;
  7179. NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
  7180. NL80211_REPLAY_CTR_LEN, replay_ctr);
  7181. nla_nest_end(msg, rekey_attr);
  7182. genlmsg_end(msg, hdr);
  7183. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7184. nl80211_mlme_mcgrp.id, gfp);
  7185. return;
  7186. nla_put_failure:
  7187. genlmsg_cancel(msg, hdr);
  7188. nlmsg_free(msg);
  7189. }
  7190. void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
  7191. struct net_device *netdev, int index,
  7192. const u8 *bssid, bool preauth, gfp_t gfp)
  7193. {
  7194. struct sk_buff *msg;
  7195. struct nlattr *attr;
  7196. void *hdr;
  7197. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  7198. if (!msg)
  7199. return;
  7200. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
  7201. if (!hdr) {
  7202. nlmsg_free(msg);
  7203. return;
  7204. }
  7205. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7206. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7207. attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
  7208. if (!attr)
  7209. goto nla_put_failure;
  7210. NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
  7211. NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
  7212. if (preauth)
  7213. NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
  7214. nla_nest_end(msg, attr);
  7215. genlmsg_end(msg, hdr);
  7216. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7217. nl80211_mlme_mcgrp.id, gfp);
  7218. return;
  7219. nla_put_failure:
  7220. genlmsg_cancel(msg, hdr);
  7221. nlmsg_free(msg);
  7222. }
  7223. static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
  7224. struct net_device *netdev,
  7225. struct cfg80211_chan_def *chandef,
  7226. gfp_t gfp)
  7227. {
  7228. struct sk_buff *msg;
  7229. void *hdr;
  7230. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  7231. if (!msg)
  7232. return;
  7233. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
  7234. if (!hdr) {
  7235. nlmsg_free(msg);
  7236. return;
  7237. }
  7238. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  7239. goto nla_put_failure;
  7240. if (nl80211_send_chandef(msg, chandef))
  7241. goto nla_put_failure;
  7242. genlmsg_end(msg, hdr);
  7243. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7244. nl80211_mlme_mcgrp.id, gfp);
  7245. return;
  7246. nla_put_failure:
  7247. genlmsg_cancel(msg, hdr);
  7248. nlmsg_free(msg);
  7249. }
  7250. void cfg80211_ch_switch_notify(struct net_device *dev,
  7251. struct cfg80211_chan_def *chandef)
  7252. {
  7253. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7254. struct wiphy *wiphy = wdev->wiphy;
  7255. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  7256. wdev_lock(wdev);
  7257. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  7258. wdev->iftype != NL80211_IFTYPE_P2P_GO))
  7259. goto out;
  7260. wdev->channel = chandef->chan;
  7261. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
  7262. out:
  7263. wdev_unlock(wdev);
  7264. return;
  7265. }
  7266. EXPORT_SYMBOL(cfg80211_ch_switch_notify);
  7267. void
  7268. nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
  7269. struct net_device *netdev, const u8 *peer,
  7270. u32 num_packets, gfp_t gfp)
  7271. {
  7272. struct sk_buff *msg;
  7273. struct nlattr *pinfoattr;
  7274. void *hdr;
  7275. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  7276. if (!msg)
  7277. return;
  7278. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
  7279. if (!hdr) {
  7280. nlmsg_free(msg);
  7281. return;
  7282. }
  7283. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7284. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7285. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
  7286. pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
  7287. if (!pinfoattr)
  7288. goto nla_put_failure;
  7289. NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
  7290. nla_nest_end(msg, pinfoattr);
  7291. genlmsg_end(msg, hdr);
  7292. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7293. nl80211_mlme_mcgrp.id, gfp);
  7294. return;
  7295. nla_put_failure:
  7296. genlmsg_cancel(msg, hdr);
  7297. nlmsg_free(msg);
  7298. }
  7299. void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  7300. u64 cookie, bool acked, gfp_t gfp)
  7301. {
  7302. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7303. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  7304. struct sk_buff *msg;
  7305. void *hdr;
  7306. int err;
  7307. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  7308. if (!msg)
  7309. return;
  7310. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
  7311. if (!hdr) {
  7312. nlmsg_free(msg);
  7313. return;
  7314. }
  7315. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7316. NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
  7317. NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
  7318. NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
  7319. if (acked)
  7320. NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
  7321. err = genlmsg_end(msg, hdr);
  7322. if (err < 0) {
  7323. nlmsg_free(msg);
  7324. return;
  7325. }
  7326. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7327. nl80211_mlme_mcgrp.id, gfp);
  7328. return;
  7329. nla_put_failure:
  7330. genlmsg_cancel(msg, hdr);
  7331. nlmsg_free(msg);
  7332. }
  7333. EXPORT_SYMBOL(cfg80211_probe_status);
  7334. void cfg80211_report_obss_beacon(struct wiphy *wiphy,
  7335. const u8 *frame, size_t len,
  7336. int freq, int sig_dbm, gfp_t gfp)
  7337. {
  7338. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  7339. struct sk_buff *msg;
  7340. void *hdr;
  7341. u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
  7342. if (!nlpid)
  7343. return;
  7344. msg = nlmsg_new(len + 100, gfp);
  7345. if (!msg)
  7346. return;
  7347. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  7348. if (!hdr) {
  7349. nlmsg_free(msg);
  7350. return;
  7351. }
  7352. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7353. if (freq)
  7354. NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
  7355. if (sig_dbm)
  7356. NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
  7357. NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
  7358. genlmsg_end(msg, hdr);
  7359. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
  7360. return;
  7361. nla_put_failure:
  7362. genlmsg_cancel(msg, hdr);
  7363. nlmsg_free(msg);
  7364. }
  7365. EXPORT_SYMBOL(cfg80211_report_obss_beacon);
  7366. void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
  7367. enum nl80211_tdls_operation oper,
  7368. u16 reason_code, gfp_t gfp)
  7369. {
  7370. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7371. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  7372. struct sk_buff *msg;
  7373. void *hdr;
  7374. int err;
  7375. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  7376. if (!msg)
  7377. return;
  7378. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
  7379. if (!hdr) {
  7380. nlmsg_free(msg);
  7381. return;
  7382. }
  7383. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  7384. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  7385. nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
  7386. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
  7387. (reason_code > 0 &&
  7388. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
  7389. goto nla_put_failure;
  7390. err = genlmsg_end(msg, hdr);
  7391. if (err < 0) {
  7392. nlmsg_free(msg);
  7393. return;
  7394. }
  7395. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7396. nl80211_mlme_mcgrp.id, gfp);
  7397. return;
  7398. nla_put_failure:
  7399. genlmsg_cancel(msg, hdr);
  7400. nlmsg_free(msg);
  7401. }
  7402. EXPORT_SYMBOL(cfg80211_tdls_oper_request);
  7403. static int nl80211_netlink_notify(struct notifier_block * nb,
  7404. unsigned long state,
  7405. void *_notify)
  7406. {
  7407. struct netlink_notify *notify = _notify;
  7408. struct cfg80211_registered_device *rdev;
  7409. struct wireless_dev *wdev;
  7410. if (state != NETLINK_URELEASE)
  7411. return NOTIFY_DONE;
  7412. rcu_read_lock();
  7413. list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
  7414. list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
  7415. cfg80211_mlme_unregister_socket(wdev, notify->pid);
  7416. if (rdev->ap_beacons_nlpid == notify->pid)
  7417. rdev->ap_beacons_nlpid = 0;
  7418. }
  7419. rcu_read_unlock();
  7420. return NOTIFY_DONE;
  7421. }
  7422. static struct notifier_block nl80211_netlink_notifier = {
  7423. .notifier_call = nl80211_netlink_notify,
  7424. };
  7425. void cfg80211_ft_event(struct net_device *netdev,
  7426. struct cfg80211_ft_event_params *ft_event)
  7427. {
  7428. struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
  7429. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  7430. struct sk_buff *msg;
  7431. void *hdr;
  7432. int err;
  7433. if (!ft_event->target_ap)
  7434. return;
  7435. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7436. if (!msg)
  7437. return;
  7438. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
  7439. if (!hdr) {
  7440. nlmsg_free(msg);
  7441. return;
  7442. }
  7443. nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
  7444. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
  7445. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
  7446. if (ft_event->ies)
  7447. nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
  7448. if (ft_event->ric_ies)
  7449. nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
  7450. ft_event->ric_ies);
  7451. err = genlmsg_end(msg, hdr);
  7452. if (err < 0) {
  7453. nlmsg_free(msg);
  7454. return;
  7455. }
  7456. genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
  7457. nl80211_mlme_mcgrp.id, GFP_KERNEL);
  7458. }
  7459. EXPORT_SYMBOL(cfg80211_ft_event);
  7460. void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp)
  7461. {
  7462. struct wireless_dev *wdev = netdev->ieee80211_ptr;
  7463. struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
  7464. nl80211_send_mlme_event(rdev, netdev, NULL, 0,
  7465. NL80211_CMD_STOP_AP, gfp);
  7466. }
  7467. EXPORT_SYMBOL(cfg80211_ap_stopped);
  7468. /* initialisation/exit functions */
  7469. int nl80211_init(void)
  7470. {
  7471. int err;
  7472. err = genl_register_family_with_ops(&nl80211_fam,
  7473. nl80211_ops, ARRAY_SIZE(nl80211_ops));
  7474. if (err)
  7475. return err;
  7476. err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
  7477. if (err)
  7478. goto err_out;
  7479. err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
  7480. if (err)
  7481. goto err_out;
  7482. err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
  7483. if (err)
  7484. goto err_out;
  7485. err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
  7486. if (err)
  7487. goto err_out;
  7488. #ifdef CONFIG_NL80211_TESTMODE
  7489. err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
  7490. if (err)
  7491. goto err_out;
  7492. #endif
  7493. err = genl_register_mc_group(&nl80211_fam, &nl80211_vendor_mcgrp);
  7494. if (err)
  7495. goto err_out;
  7496. err = netlink_register_notifier(&nl80211_netlink_notifier);
  7497. if (err)
  7498. goto err_out;
  7499. return 0;
  7500. err_out:
  7501. genl_unregister_family(&nl80211_fam);
  7502. return err;
  7503. }
  7504. void nl80211_exit(void)
  7505. {
  7506. netlink_unregister_notifier(&nl80211_netlink_notifier);
  7507. genl_unregister_family(&nl80211_fam);
  7508. }