123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006 |
- /*
- * This is the new netlink-based wireless configuration interface.
- *
- * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
- */
- #include <linux/if.h>
- #include <linux/module.h>
- #include <linux/err.h>
- #include <linux/slab.h>
- #include <linux/list.h>
- #include <linux/if_ether.h>
- #include <linux/ieee80211.h>
- #include <linux/nl80211.h>
- #include <linux/rtnetlink.h>
- #include <linux/netlink.h>
- #include <linux/etherdevice.h>
- #include <net/net_namespace.h>
- #include <net/genetlink.h>
- #include <net/cfg80211.h>
- #include <net/sock.h>
- #include "core.h"
- #include "nl80211.h"
- #include "reg.h"
- static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type);
- static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
- struct genl_info *info,
- struct cfg80211_crypto_settings *settings,
- int cipher_limit);
- static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
- struct genl_info *info);
- static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
- struct genl_info *info);
- /* the netlink family */
- static struct genl_family nl80211_fam = {
- .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
- .name = "nl80211", /* have users key off the name instead */
- .hdrsize = 0, /* no private header */
- .version = 1, /* no particular meaning now */
- .maxattr = NL80211_ATTR_MAX,
- .netnsok = true,
- .pre_doit = nl80211_pre_doit,
- .post_doit = nl80211_post_doit,
- };
- /* internal helper: get rdev and dev */
- static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
- struct cfg80211_registered_device **rdev,
- struct net_device **dev)
- {
- int ifindex;
- if (!attrs[NL80211_ATTR_IFINDEX])
- return -EINVAL;
- ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
- *dev = dev_get_by_index(netns, ifindex);
- if (!*dev)
- return -ENODEV;
- *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex);
- if (IS_ERR(*rdev)) {
- dev_put(*dev);
- return PTR_ERR(*rdev);
- }
- return 0;
- }
- static int validate_beacon_head(const struct nlattr *attr)
- {
- const u8 *data = nla_data(attr);
- unsigned int len = nla_len(attr);
- const struct element *elem;
- const struct ieee80211_mgmt *mgmt = (void *)data;
- unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
- u.beacon.variable);
- if (len < fixedlen)
- goto err;
- if (ieee80211_hdrlen(mgmt->frame_control) !=
- offsetof(struct ieee80211_mgmt, u.beacon))
- goto err;
- data += fixedlen;
- len -= fixedlen;
- for_each_element(elem, data, len) {
- /* nothing */
- }
- if (for_each_element_completed(elem, data, len))
- return 0;
- err:
- return -EINVAL;
- }
- /* policy for the attributes */
- static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
- [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
- .len = 20-1 },
- [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
- [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
- [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
- [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
- [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
- [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
- [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
- [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
- [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
- [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
- [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
- .len = WLAN_MAX_KEY_LEN },
- [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
- [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
- [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
- [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
- [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
- [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
- [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
- [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
- [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
- [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
- [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
- .len = NL80211_MAX_SUPP_RATES },
- [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
- [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
- [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
- [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_MESH_ID_LEN },
- [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_BINARY,
- .len = ETH_ALEN },
- [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
- [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
- [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
- [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
- [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
- [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
- .len = NL80211_MAX_SUPP_RATES },
- [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
- [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
- [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
- [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
- [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
- [NL80211_ATTR_IE] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
- [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
- [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_SSID_LEN },
- [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
- [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
- [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
- [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
- [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
- [NL80211_ATTR_STA_FLAGS2] = {
- .len = sizeof(struct nl80211_sta_flag_update),
- },
- [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
- [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
- [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
- [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
- [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
- [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
- [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
- [NL80211_ATTR_PID] = { .type = NLA_U32 },
- [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
- [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
- [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
- [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
- [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
- [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
- [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
- [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
- [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
- [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
- [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
- [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
- [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
- [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
- [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
- [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
- [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
- [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
- [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
- [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
- [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
- [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
- [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
- [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
- [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
- [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
- [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
- [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
- [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
- [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
- [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
- [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
- [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
- [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
- [NL80211_ATTR_HT_CAPABILITY_MASK] = {
- .len = NL80211_HT_CAPABILITY_LEN
- },
- [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
- [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
- [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
- [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
- [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
- [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
- [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
- [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
- [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
- [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
- [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
- [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
- [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
- [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
- [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
- .len = NL80211_VHT_CAPABILITY_LEN,
- },
- [NL80211_ATTR_MDID] = { .type = NLA_U16 },
- [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
- [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
- [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
- [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
- [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
- [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
- [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
- [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
- [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
- [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
- [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
- [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
- [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
- [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
- [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
- [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
- .len = IEEE80211_QOS_MAP_LEN_MAX },
- [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
- [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
- [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
- };
- /* policy for the key attributes */
- static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
- [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
- [NL80211_KEY_IDX] = { .type = NLA_U8 },
- [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
- [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
- [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
- [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
- [NL80211_KEY_TYPE] = { .type = NLA_U32 },
- [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
- };
- /* policy for the key default flags */
- static const struct nla_policy
- nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
- [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
- [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
- };
- /* policy for WoWLAN attributes */
- static const struct nla_policy
- nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
- [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
- [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
- [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
- [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
- [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
- [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
- [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
- [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
- };
- /* policy for GTK rekey offload attributes */
- static const struct nla_policy
- nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
- [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
- [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
- [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
- };
- static const struct nla_policy
- nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
- [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_SSID_LEN },
- };
- /* policy for packet pattern attributes */
- static const struct nla_policy
- nl80211_packet_pattern_policy[MAX_NL80211_WOWLAN_PKTPAT + 1] = {
- [NL80211_WOWLAN_PKTPAT_MASK] = { .type = NLA_BINARY, },
- [NL80211_WOWLAN_PKTPAT_PATTERN] = { .type = NLA_BINARY, }
- };
- /* ifidx get helper */
- static int nl80211_get_ifidx(struct netlink_callback *cb)
- {
- int res;
- res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
- nl80211_fam.attrbuf, nl80211_fam.maxattr,
- nl80211_policy);
- if (res)
- return res;
- if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
- return -EINVAL;
- res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
- if (!res)
- return -EINVAL;
- return res;
- }
- static int nl80211_prepare_netdev_dump(struct sk_buff *skb,
- struct netlink_callback *cb,
- struct cfg80211_registered_device **rdev,
- struct net_device **dev)
- {
- int ifidx = cb->args[0];
- int err;
- if (!ifidx)
- ifidx = nl80211_get_ifidx(cb);
- if (ifidx < 0)
- return ifidx;
- cb->args[0] = ifidx;
- rtnl_lock();
- *dev = __dev_get_by_index(sock_net(skb->sk), ifidx);
- if (!*dev) {
- err = -ENODEV;
- goto out_rtnl;
- }
- *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx);
- if (IS_ERR(*rdev)) {
- err = PTR_ERR(*rdev);
- goto out_rtnl;
- }
- return 0;
- out_rtnl:
- rtnl_unlock();
- return err;
- }
- static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev)
- {
- cfg80211_unlock_rdev(rdev);
- rtnl_unlock();
- }
- /* IE validation */
- static bool is_valid_ie_attr(const struct nlattr *attr)
- {
- const u8 *pos;
- int len;
- if (!attr)
- return true;
- pos = nla_data(attr);
- len = nla_len(attr);
- while (len) {
- u8 elemlen;
- if (len < 2)
- return false;
- len -= 2;
- elemlen = pos[1];
- if (elemlen > len)
- return false;
- len -= elemlen;
- pos += 2 + elemlen;
- }
- return true;
- }
- /* message building helper */
- static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
- int flags, u8 cmd)
- {
- /* since there is no private header just add the generic one */
- return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
- }
- static int nl80211_msg_put_channel(struct sk_buff *msg,
- struct ieee80211_channel *chan)
- {
- NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
- chan->center_freq);
- if (chan->flags & IEEE80211_CHAN_DISABLED)
- NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
- if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
- NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
- if (chan->flags & IEEE80211_CHAN_NO_IBSS)
- NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
- if (chan->flags & IEEE80211_CHAN_RADAR)
- NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
- if (chan->flags & IEEE80211_CHAN_NO_20MHZ)
- NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ);
- if (chan->flags & IEEE80211_CHAN_NO_10MHZ)
- NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ);
- NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
- DBM_TO_MBM(chan->max_power));
- return 0;
- nla_put_failure:
- return -ENOBUFS;
- }
- /* netlink command implementations */
- struct key_parse {
- struct key_params p;
- int idx;
- int type;
- bool def, defmgmt;
- bool def_uni, def_multi;
- };
- static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
- {
- struct nlattr *tb[NL80211_KEY_MAX + 1];
- int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
- nl80211_key_policy);
- if (err)
- return err;
- k->def = !!tb[NL80211_KEY_DEFAULT];
- k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
- if (k->def) {
- k->def_uni = true;
- k->def_multi = true;
- }
- if (k->defmgmt)
- k->def_multi = true;
- if (tb[NL80211_KEY_IDX])
- k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
- if (tb[NL80211_KEY_DATA]) {
- k->p.key = nla_data(tb[NL80211_KEY_DATA]);
- k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
- }
- if (tb[NL80211_KEY_SEQ]) {
- k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
- k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
- }
- if (tb[NL80211_KEY_CIPHER])
- k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
- if (tb[NL80211_KEY_TYPE]) {
- k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
- if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
- return -EINVAL;
- }
- if (tb[NL80211_KEY_DEFAULT_TYPES]) {
- struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
- err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
- tb[NL80211_KEY_DEFAULT_TYPES],
- nl80211_key_default_policy);
- if (err)
- return err;
- k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
- k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
- }
- return 0;
- }
- static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
- {
- if (info->attrs[NL80211_ATTR_KEY_DATA]) {
- k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
- k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
- }
- if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
- k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
- k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
- }
- if (info->attrs[NL80211_ATTR_KEY_IDX])
- k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
- if (info->attrs[NL80211_ATTR_KEY_CIPHER])
- k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
- k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
- k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
- if (k->def) {
- k->def_uni = true;
- k->def_multi = true;
- }
- if (k->defmgmt)
- k->def_multi = true;
- if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
- k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
- if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
- struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
- int err = nla_parse_nested(
- kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
- info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
- nl80211_key_default_policy);
- if (err)
- return err;
- k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
- k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
- }
- return 0;
- }
- static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
- {
- int err;
- memset(k, 0, sizeof(*k));
- k->idx = -1;
- k->type = -1;
- if (info->attrs[NL80211_ATTR_KEY])
- err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
- else
- err = nl80211_parse_key_old(info, k);
- if (err)
- return err;
- if (k->def && k->defmgmt)
- return -EINVAL;
- if (k->defmgmt) {
- if (k->def_uni || !k->def_multi)
- return -EINVAL;
- }
- if (k->idx != -1) {
- if (k->defmgmt) {
- if (k->idx < 4 || k->idx > 5)
- return -EINVAL;
- } else if (k->def) {
- if (k->idx < 0 || k->idx > 3)
- return -EINVAL;
- } else {
- if (k->idx < 0 || k->idx > 5)
- return -EINVAL;
- }
- }
- return 0;
- }
- static struct cfg80211_cached_keys *
- nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
- struct nlattr *keys)
- {
- struct key_parse parse;
- struct nlattr *key;
- struct cfg80211_cached_keys *result;
- int rem, err, def = 0;
- result = kzalloc(sizeof(*result), GFP_KERNEL);
- if (!result)
- return ERR_PTR(-ENOMEM);
- result->def = -1;
- result->defmgmt = -1;
- nla_for_each_nested(key, keys, rem) {
- memset(&parse, 0, sizeof(parse));
- parse.idx = -1;
- err = nl80211_parse_key_new(key, &parse);
- if (err)
- goto error;
- err = -EINVAL;
- if (!parse.p.key)
- goto error;
- if (parse.idx < 0 || parse.idx > 4)
- goto error;
- if (parse.def) {
- if (def)
- goto error;
- def = 1;
- result->def = parse.idx;
- if (!parse.def_uni || !parse.def_multi)
- goto error;
- } else if (parse.defmgmt)
- goto error;
- err = cfg80211_validate_key_settings(rdev, &parse.p,
- parse.idx, false, NULL);
- if (err)
- goto error;
- result->params[parse.idx].cipher = parse.p.cipher;
- result->params[parse.idx].key_len = parse.p.key_len;
- result->params[parse.idx].key = result->data[parse.idx];
- memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
- }
- return result;
- error:
- kfree(result);
- return ERR_PTR(err);
- }
- static int nl80211_key_allowed(struct wireless_dev *wdev)
- {
- ASSERT_WDEV_LOCK(wdev);
- switch (wdev->iftype) {
- case NL80211_IFTYPE_AP:
- case NL80211_IFTYPE_AP_VLAN:
- case NL80211_IFTYPE_P2P_GO:
- case NL80211_IFTYPE_MESH_POINT:
- break;
- case NL80211_IFTYPE_ADHOC:
- if (!wdev->current_bss)
- return -ENOLINK;
- break;
- case NL80211_IFTYPE_STATION:
- case NL80211_IFTYPE_P2P_CLIENT:
- if (wdev->sme_state != CFG80211_SME_CONNECTED)
- return -ENOLINK;
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
- static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
- {
- struct nlattr *nl_modes = nla_nest_start(msg, attr);
- int i;
- if (!nl_modes)
- goto nla_put_failure;
- i = 0;
- while (ifmodes) {
- if (ifmodes & 1)
- NLA_PUT_FLAG(msg, i);
- ifmodes >>= 1;
- i++;
- }
- nla_nest_end(msg, nl_modes);
- return 0;
- nla_put_failure:
- return -ENOBUFS;
- }
- static int nl80211_put_iface_combinations(struct wiphy *wiphy,
- struct sk_buff *msg)
- {
- struct nlattr *nl_combis;
- int i, j;
- nl_combis = nla_nest_start(msg,
- NL80211_ATTR_INTERFACE_COMBINATIONS);
- if (!nl_combis)
- goto nla_put_failure;
- for (i = 0; i < wiphy->n_iface_combinations; i++) {
- const struct ieee80211_iface_combination *c;
- struct nlattr *nl_combi, *nl_limits;
- c = &wiphy->iface_combinations[i];
- nl_combi = nla_nest_start(msg, i + 1);
- if (!nl_combi)
- goto nla_put_failure;
- nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
- if (!nl_limits)
- goto nla_put_failure;
- for (j = 0; j < c->n_limits; j++) {
- struct nlattr *nl_limit;
- nl_limit = nla_nest_start(msg, j + 1);
- if (!nl_limit)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX,
- c->limits[j].max);
- if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
- c->limits[j].types))
- goto nla_put_failure;
- nla_nest_end(msg, nl_limit);
- }
- nla_nest_end(msg, nl_limits);
- if (c->beacon_int_infra_match)
- NLA_PUT_FLAG(msg,
- NL80211_IFACE_COMB_STA_AP_BI_MATCH);
- NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
- c->num_different_channels);
- NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM,
- c->max_interfaces);
- nla_nest_end(msg, nl_combi);
- }
- nla_nest_end(msg, nl_combis);
- return 0;
- nla_put_failure:
- return -ENOBUFS;
- }
- static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
- struct cfg80211_registered_device *dev)
- {
- void *hdr;
- struct nlattr *nl_bands, *nl_band;
- struct nlattr *nl_freqs, *nl_freq;
- struct nlattr *nl_rates, *nl_rate;
- struct nlattr *nl_cmds;
- enum ieee80211_band band;
- struct ieee80211_channel *chan;
- struct ieee80211_rate *rate;
- int i;
- const struct ieee80211_txrx_stypes *mgmt_stypes =
- dev->wiphy.mgmt_stypes;
- hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
- if (!hdr)
- return -1;
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
- NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
- NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
- cfg80211_rdev_list_generation);
- NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
- dev->wiphy.retry_short);
- NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
- dev->wiphy.retry_long);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
- dev->wiphy.frag_threshold);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
- dev->wiphy.rts_threshold);
- NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
- dev->wiphy.coverage_class);
- NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
- dev->wiphy.max_scan_ssids);
- NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
- dev->wiphy.max_sched_scan_ssids);
- NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
- dev->wiphy.max_scan_ie_len);
- NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
- dev->wiphy.max_sched_scan_ie_len);
- NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS,
- dev->wiphy.max_match_sets);
- if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)
- NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN);
- if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH)
- NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH);
- if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD)
- NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD);
- if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)
- NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT);
- if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)
- NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT);
- if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)
- NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP);
- NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
- sizeof(u32) * dev->wiphy.n_cipher_suites,
- dev->wiphy.cipher_suites);
- NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
- dev->wiphy.max_num_pmkids);
- if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL)
- NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
- dev->wiphy.available_antennas_tx);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
- dev->wiphy.available_antennas_rx);
- if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD)
- NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
- dev->wiphy.probe_resp_offload);
- if ((dev->wiphy.available_antennas_tx ||
- dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) {
- u32 tx_ant = 0, rx_ant = 0;
- int res;
- res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant);
- if (!res) {
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant);
- }
- }
- if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
- dev->wiphy.interface_modes))
- goto nla_put_failure;
- nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
- if (!nl_bands)
- goto nla_put_failure;
- for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
- if (!dev->wiphy.bands[band])
- continue;
- nl_band = nla_nest_start(msg, band);
- if (!nl_band)
- goto nla_put_failure;
- /* add HT info */
- if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
- NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
- sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
- &dev->wiphy.bands[band]->ht_cap.mcs);
- NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
- dev->wiphy.bands[band]->ht_cap.cap);
- NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
- dev->wiphy.bands[band]->ht_cap.ampdu_factor);
- NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
- dev->wiphy.bands[band]->ht_cap.ampdu_density);
- }
- /* add VHT info */
- if (dev->wiphy.bands[band]->vht_cap.vht_supported &&
- (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
- sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs),
- &dev->wiphy.bands[band]->vht_cap.vht_mcs) ||
- nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
- dev->wiphy.bands[band]->vht_cap.cap)))
- goto nla_put_failure;
- /* add frequencies */
- nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
- if (!nl_freqs)
- goto nla_put_failure;
- for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
- nl_freq = nla_nest_start(msg, i);
- if (!nl_freq)
- goto nla_put_failure;
- chan = &dev->wiphy.bands[band]->channels[i];
- if (nl80211_msg_put_channel(msg, chan))
- goto nla_put_failure;
- nla_nest_end(msg, nl_freq);
- }
- nla_nest_end(msg, nl_freqs);
- /* add bitrates */
- nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
- if (!nl_rates)
- goto nla_put_failure;
- for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
- nl_rate = nla_nest_start(msg, i);
- if (!nl_rate)
- goto nla_put_failure;
- rate = &dev->wiphy.bands[band]->bitrates[i];
- NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
- rate->bitrate);
- if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
- NLA_PUT_FLAG(msg,
- NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
- nla_nest_end(msg, nl_rate);
- }
- nla_nest_end(msg, nl_rates);
- nla_nest_end(msg, nl_band);
- }
- nla_nest_end(msg, nl_bands);
- nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
- if (!nl_cmds)
- goto nla_put_failure;
- i = 0;
- #define CMD(op, n) \
- do { \
- if (dev->ops->op) { \
- i++; \
- NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
- } \
- } while (0)
- CMD(add_virtual_intf, NEW_INTERFACE);
- CMD(change_virtual_intf, SET_INTERFACE);
- CMD(add_key, NEW_KEY);
- CMD(start_ap, START_AP);
- CMD(add_station, NEW_STATION);
- CMD(add_mpath, NEW_MPATH);
- CMD(update_mesh_config, SET_MESH_CONFIG);
- CMD(change_bss, SET_BSS);
- CMD(auth, AUTHENTICATE);
- CMD(assoc, ASSOCIATE);
- CMD(deauth, DEAUTHENTICATE);
- CMD(disassoc, DISASSOCIATE);
- CMD(join_ibss, JOIN_IBSS);
- CMD(join_mesh, JOIN_MESH);
- CMD(set_pmksa, SET_PMKSA);
- CMD(del_pmksa, DEL_PMKSA);
- CMD(flush_pmksa, FLUSH_PMKSA);
- if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
- CMD(remain_on_channel, REMAIN_ON_CHANNEL);
- CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
- CMD(mgmt_tx, FRAME);
- CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
- if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
- i++;
- NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS);
- }
- CMD(set_channel, SET_CHANNEL);
- CMD(set_wds_peer, SET_WDS_PEER);
- if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
- CMD(tdls_mgmt, TDLS_MGMT);
- CMD(tdls_oper, TDLS_OPER);
- }
- if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
- CMD(sched_scan_start, START_SCHED_SCAN);
- CMD(probe_client, PROBE_CLIENT);
- CMD(set_noack_map, SET_NOACK_MAP);
- if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
- i++;
- NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS);
- }
- CMD(set_qos_map, SET_QOS_MAP);
- #ifdef CONFIG_NL80211_TESTMODE
- CMD(testmode_cmd, TESTMODE);
- #endif
- #undef CMD
- if (dev->ops->connect || dev->ops->auth) {
- i++;
- NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT);
- }
- if (dev->ops->disconnect || dev->ops->deauth) {
- i++;
- NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT);
- }
- nla_nest_end(msg, nl_cmds);
- if (dev->ops->remain_on_channel &&
- dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
- NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
- dev->wiphy.max_remain_on_channel_duration);
- if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)
- NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK);
- if (mgmt_stypes) {
- u16 stypes;
- struct nlattr *nl_ftypes, *nl_ifs;
- enum nl80211_iftype ift;
- nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
- if (!nl_ifs)
- goto nla_put_failure;
- for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
- nl_ftypes = nla_nest_start(msg, ift);
- if (!nl_ftypes)
- goto nla_put_failure;
- i = 0;
- stypes = mgmt_stypes[ift].tx;
- while (stypes) {
- if (stypes & 1)
- NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
- (i << 4) | IEEE80211_FTYPE_MGMT);
- stypes >>= 1;
- i++;
- }
- nla_nest_end(msg, nl_ftypes);
- }
- nla_nest_end(msg, nl_ifs);
- nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
- if (!nl_ifs)
- goto nla_put_failure;
- for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
- nl_ftypes = nla_nest_start(msg, ift);
- if (!nl_ftypes)
- goto nla_put_failure;
- i = 0;
- stypes = mgmt_stypes[ift].rx;
- while (stypes) {
- if (stypes & 1)
- NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE,
- (i << 4) | IEEE80211_FTYPE_MGMT);
- stypes >>= 1;
- i++;
- }
- nla_nest_end(msg, nl_ftypes);
- }
- nla_nest_end(msg, nl_ifs);
- }
- if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) {
- struct nlattr *nl_wowlan;
- nl_wowlan = nla_nest_start(msg,
- NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
- if (!nl_wowlan)
- goto nla_put_failure;
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
- if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
- if (dev->wiphy.wowlan.n_patterns) {
- struct nl80211_wowlan_pattern_support pat = {
- .max_patterns = dev->wiphy.wowlan.n_patterns,
- .min_pattern_len =
- dev->wiphy.wowlan.pattern_min_len,
- .max_pattern_len =
- dev->wiphy.wowlan.pattern_max_len,
- };
- NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
- sizeof(pat), &pat);
- }
- nla_nest_end(msg, nl_wowlan);
- }
- if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
- dev->wiphy.software_iftypes))
- goto nla_put_failure;
- if (nl80211_put_iface_combinations(&dev->wiphy, msg))
- goto nla_put_failure;
- if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME)
- NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME,
- dev->wiphy.ap_sme_capa);
- NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features);
- if (dev->wiphy.ht_capa_mod_mask)
- NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
- sizeof(*dev->wiphy.ht_capa_mod_mask),
- dev->wiphy.ht_capa_mod_mask);
- if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
- dev->wiphy.max_acl_mac_addrs)
- NLA_PUT_U32(msg, NL80211_ATTR_MAC_ACL_MAX,
- dev->wiphy.max_acl_mac_addrs);
- if (dev->wiphy.max_ap_assoc_sta &&
- nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
- dev->wiphy.max_ap_assoc_sta))
- goto nla_put_failure;
- if (dev->wiphy.n_vendor_commands) {
- const struct nl80211_vendor_cmd_info *info;
- struct nlattr *nested;
- nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
- if (!nested)
- goto nla_put_failure;
- for (i = 0; i < dev->wiphy.n_vendor_commands; i++) {
- info = &dev->wiphy.vendor_commands[i].info;
- if (nla_put(msg, i + 1, sizeof(*info), info))
- goto nla_put_failure;
- }
- nla_nest_end(msg, nested);
- }
- if (dev->wiphy.n_vendor_events) {
- const struct nl80211_vendor_cmd_info *info;
- struct nlattr *nested;
- nested = nla_nest_start(msg,
- NL80211_ATTR_VENDOR_EVENTS);
- if (!nested)
- goto nla_put_failure;
- for (i = 0; i < dev->wiphy.n_vendor_events; i++) {
- info = &dev->wiphy.vendor_events[i];
- if (nla_put(msg, i + 1, sizeof(*info), info))
- goto nla_put_failure;
- }
- nla_nest_end(msg, nested);
- }
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
- {
- int idx = 0;
- int start = cb->args[0];
- struct cfg80211_registered_device *dev;
- mutex_lock(&cfg80211_mutex);
- list_for_each_entry(dev, &cfg80211_rdev_list, list) {
- if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
- continue;
- if (++idx <= start)
- continue;
- if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- dev) < 0) {
- idx--;
- break;
- }
- }
- mutex_unlock(&cfg80211_mutex);
- cb->args[0] = idx;
- return skb->len;
- }
- static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
- {
- struct sk_buff *msg;
- struct cfg80211_registered_device *dev = info->user_ptr[0];
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) {
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- return genlmsg_reply(msg, info);
- }
- static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
- [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
- [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
- [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
- [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
- [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
- };
- static int parse_txq_params(struct nlattr *tb[],
- struct ieee80211_txq_params *txq_params)
- {
- if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
- !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
- !tb[NL80211_TXQ_ATTR_AIFS])
- return -EINVAL;
- txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
- txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
- txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
- txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
- txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
- return 0;
- }
- static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
- {
- /*
- * You can only set the channel explicitly for AP, mesh
- * and WDS type interfaces; all others have their channel
- * managed via their respective "establish a connection"
- * command (connect, join, ...)
- *
- * Monitors are special as they are normally slaved to
- * whatever else is going on, so they behave as though
- * you tried setting the wiphy channel itself.
- */
- return !wdev ||
- wdev->iftype == NL80211_IFTYPE_AP ||
- wdev->iftype == NL80211_IFTYPE_WDS ||
- wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
- wdev->iftype == NL80211_IFTYPE_MONITOR ||
- wdev->iftype == NL80211_IFTYPE_P2P_GO;
- }
- static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
- struct wireless_dev *wdev,
- struct genl_info *info)
- {
- enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
- u32 freq;
- int result;
- if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
- return -EINVAL;
- if (!nl80211_can_set_dev_channel(wdev))
- return -EOPNOTSUPP;
- if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
- channel_type = nla_get_u32(info->attrs[
- NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
- if (channel_type != NL80211_CHAN_NO_HT &&
- channel_type != NL80211_CHAN_HT20 &&
- channel_type != NL80211_CHAN_HT40PLUS &&
- channel_type != NL80211_CHAN_HT40MINUS)
- return -EINVAL;
- }
- freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
- mutex_lock(&rdev->devlist_mtx);
- if (wdev) {
- wdev_lock(wdev);
- result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
- wdev_unlock(wdev);
- } else {
- result = cfg80211_set_freq(rdev, NULL, freq, channel_type);
- }
- mutex_unlock(&rdev->devlist_mtx);
- return result;
- }
- static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *netdev = info->user_ptr[1];
- return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
- }
- static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- const u8 *bssid;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (netif_running(dev))
- return -EBUSY;
- if (!rdev->ops->set_wds_peer)
- return -EOPNOTSUPP;
- if (wdev->iftype != NL80211_IFTYPE_WDS)
- return -EOPNOTSUPP;
- bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid);
- }
- static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev;
- struct net_device *netdev = NULL;
- struct wireless_dev *wdev;
- int result = 0, rem_txq_params = 0;
- struct nlattr *nl_txq_params;
- u32 changed;
- u8 retry_short = 0, retry_long = 0;
- u32 frag_threshold = 0, rts_threshold = 0;
- u8 coverage_class = 0;
- /*
- * Try to find the wiphy and netdev. Normally this
- * function shouldn't need the netdev, but this is
- * done for backward compatibility -- previously
- * setting the channel was done per wiphy, but now
- * it is per netdev. Previous userland like hostapd
- * also passed a netdev to set_wiphy, so that it is
- * possible to let that go to the right netdev!
- */
- mutex_lock(&cfg80211_mutex);
- if (info->attrs[NL80211_ATTR_IFINDEX]) {
- int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
- netdev = dev_get_by_index(genl_info_net(info), ifindex);
- if (netdev && netdev->ieee80211_ptr) {
- rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
- mutex_lock(&rdev->mtx);
- } else
- netdev = NULL;
- }
- if (!netdev) {
- rdev = __cfg80211_rdev_from_info(info);
- if (IS_ERR(rdev)) {
- mutex_unlock(&cfg80211_mutex);
- return PTR_ERR(rdev);
- }
- wdev = NULL;
- netdev = NULL;
- result = 0;
- mutex_lock(&rdev->mtx);
- } else if (netif_running(netdev) &&
- nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
- wdev = netdev->ieee80211_ptr;
- else
- wdev = NULL;
- /*
- * end workaround code, by now the rdev is available
- * and locked, and wdev may or may not be NULL.
- */
- if (info->attrs[NL80211_ATTR_WIPHY_NAME])
- result = cfg80211_dev_rename(
- rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
- mutex_unlock(&cfg80211_mutex);
- if (result)
- goto bad_res;
- if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
- struct ieee80211_txq_params txq_params;
- struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
- if (!rdev->ops->set_txq_params) {
- result = -EOPNOTSUPP;
- goto bad_res;
- }
- if (!netdev) {
- result = -EINVAL;
- goto bad_res;
- }
- if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
- result = -EINVAL;
- goto bad_res;
- }
- if (!netif_running(netdev)) {
- result = -ENETDOWN;
- goto bad_res;
- }
- nla_for_each_nested(nl_txq_params,
- info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
- rem_txq_params) {
- nla_parse(tb, NL80211_TXQ_ATTR_MAX,
- nla_data(nl_txq_params),
- nla_len(nl_txq_params),
- txq_params_policy);
- result = parse_txq_params(tb, &txq_params);
- if (result)
- goto bad_res;
- result = rdev->ops->set_txq_params(&rdev->wiphy,
- netdev,
- &txq_params);
- if (result)
- goto bad_res;
- }
- }
- if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
- result = __nl80211_set_channel(rdev, wdev, info);
- if (result)
- goto bad_res;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
- enum nl80211_tx_power_setting type;
- int idx, mbm = 0;
- if (!rdev->ops->set_tx_power) {
- result = -EOPNOTSUPP;
- goto bad_res;
- }
- idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
- type = nla_get_u32(info->attrs[idx]);
- if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
- (type != NL80211_TX_POWER_AUTOMATIC)) {
- result = -EINVAL;
- goto bad_res;
- }
- if (type != NL80211_TX_POWER_AUTOMATIC) {
- idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
- mbm = nla_get_u32(info->attrs[idx]);
- }
- result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm);
- if (result)
- goto bad_res;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
- info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
- u32 tx_ant, rx_ant;
- if ((!rdev->wiphy.available_antennas_tx &&
- !rdev->wiphy.available_antennas_rx) ||
- !rdev->ops->set_antenna) {
- result = -EOPNOTSUPP;
- goto bad_res;
- }
- tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
- rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
- /* reject antenna configurations which don't match the
- * available antenna masks, except for the "all" mask */
- if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
- (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
- result = -EINVAL;
- goto bad_res;
- }
- tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
- rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
- result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant);
- if (result)
- goto bad_res;
- }
- changed = 0;
- if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
- retry_short = nla_get_u8(
- info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
- if (retry_short == 0) {
- result = -EINVAL;
- goto bad_res;
- }
- changed |= WIPHY_PARAM_RETRY_SHORT;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
- retry_long = nla_get_u8(
- info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
- if (retry_long == 0) {
- result = -EINVAL;
- goto bad_res;
- }
- changed |= WIPHY_PARAM_RETRY_LONG;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
- frag_threshold = nla_get_u32(
- info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
- if (frag_threshold < 256) {
- result = -EINVAL;
- goto bad_res;
- }
- if (frag_threshold != (u32) -1) {
- /*
- * Fragments (apart from the last one) are required to
- * have even length. Make the fragmentation code
- * simpler by stripping LSB should someone try to use
- * odd threshold value.
- */
- frag_threshold &= ~0x1;
- }
- changed |= WIPHY_PARAM_FRAG_THRESHOLD;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
- rts_threshold = nla_get_u32(
- info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
- changed |= WIPHY_PARAM_RTS_THRESHOLD;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
- coverage_class = nla_get_u8(
- info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
- changed |= WIPHY_PARAM_COVERAGE_CLASS;
- }
- if (changed) {
- u8 old_retry_short, old_retry_long;
- u32 old_frag_threshold, old_rts_threshold;
- u8 old_coverage_class;
- if (!rdev->ops->set_wiphy_params) {
- result = -EOPNOTSUPP;
- goto bad_res;
- }
- old_retry_short = rdev->wiphy.retry_short;
- old_retry_long = rdev->wiphy.retry_long;
- old_frag_threshold = rdev->wiphy.frag_threshold;
- old_rts_threshold = rdev->wiphy.rts_threshold;
- old_coverage_class = rdev->wiphy.coverage_class;
- if (changed & WIPHY_PARAM_RETRY_SHORT)
- rdev->wiphy.retry_short = retry_short;
- if (changed & WIPHY_PARAM_RETRY_LONG)
- rdev->wiphy.retry_long = retry_long;
- if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
- rdev->wiphy.frag_threshold = frag_threshold;
- if (changed & WIPHY_PARAM_RTS_THRESHOLD)
- rdev->wiphy.rts_threshold = rts_threshold;
- if (changed & WIPHY_PARAM_COVERAGE_CLASS)
- rdev->wiphy.coverage_class = coverage_class;
- result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
- if (result) {
- rdev->wiphy.retry_short = old_retry_short;
- rdev->wiphy.retry_long = old_retry_long;
- rdev->wiphy.frag_threshold = old_frag_threshold;
- rdev->wiphy.rts_threshold = old_rts_threshold;
- rdev->wiphy.coverage_class = old_coverage_class;
- }
- }
- bad_res:
- mutex_unlock(&rdev->mtx);
- if (netdev)
- dev_put(netdev);
- return result;
- }
- static int nl80211_send_chandef(struct sk_buff *msg,
- struct cfg80211_chan_def *chandef)
- {
- WARN_ON(!cfg80211_chandef_valid(chandef));
- if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
- chandef->chan->center_freq))
- return -ENOBUFS;
- switch (chandef->width) {
- case NL80211_CHAN_WIDTH_20_NOHT:
- case NL80211_CHAN_WIDTH_20:
- case NL80211_CHAN_WIDTH_40:
- if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
- cfg80211_get_chandef_type(chandef)))
- return -ENOBUFS;
- break;
- default:
- break;
- }
- if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
- return -ENOBUFS;
- if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
- return -ENOBUFS;
- if (chandef->center_freq2 &&
- nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
- return -ENOBUFS;
- return 0;
- }
- static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
- struct cfg80211_registered_device *rdev,
- struct net_device *dev)
- {
- void *hdr;
- hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
- if (!hdr)
- return -1;
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
- NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dev->dev_addr);
- NLA_PUT_U32(msg, NL80211_ATTR_GENERATION,
- rdev->devlist_generation ^
- (cfg80211_rdev_list_generation << 2));
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
- {
- int wp_idx = 0;
- int if_idx = 0;
- int wp_start = cb->args[0];
- int if_start = cb->args[1];
- struct cfg80211_registered_device *rdev;
- struct wireless_dev *wdev;
- mutex_lock(&cfg80211_mutex);
- list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
- if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
- continue;
- if (wp_idx < wp_start) {
- wp_idx++;
- continue;
- }
- if_idx = 0;
- mutex_lock(&rdev->devlist_mtx);
- list_for_each_entry(wdev, &rdev->netdev_list, list) {
- if (if_idx < if_start) {
- if_idx++;
- continue;
- }
- if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- rdev, wdev->netdev) < 0) {
- mutex_unlock(&rdev->devlist_mtx);
- goto out;
- }
- if_idx++;
- }
- mutex_unlock(&rdev->devlist_mtx);
- wp_idx++;
- }
- out:
- mutex_unlock(&cfg80211_mutex);
- cb->args[0] = wp_idx;
- cb->args[1] = if_idx;
- return skb->len;
- }
- static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
- {
- struct sk_buff *msg;
- struct cfg80211_registered_device *dev = info->user_ptr[0];
- struct net_device *netdev = info->user_ptr[1];
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
- dev, netdev) < 0) {
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- return genlmsg_reply(msg, info);
- }
- static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
- [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
- [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
- [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
- [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
- [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
- };
- static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
- {
- struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
- int flag;
- *mntrflags = 0;
- if (!nla)
- return -EINVAL;
- if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
- nla, mntr_flags_policy))
- return -EINVAL;
- for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
- if (flags[flag])
- *mntrflags |= (1<<flag);
- return 0;
- }
- static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u8 use_4addr,
- enum nl80211_iftype iftype)
- {
- if (!use_4addr) {
- if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
- return -EBUSY;
- return 0;
- }
- switch (iftype) {
- case NL80211_IFTYPE_AP_VLAN:
- if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
- return 0;
- break;
- case NL80211_IFTYPE_STATION:
- if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
- return 0;
- break;
- default:
- break;
- }
- return -EOPNOTSUPP;
- }
- static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct vif_params params;
- int err;
- enum nl80211_iftype otype, ntype;
- struct net_device *dev = info->user_ptr[1];
- u32 _flags, *flags = NULL;
- bool change = false;
- memset(¶ms, 0, sizeof(params));
- otype = ntype = dev->ieee80211_ptr->iftype;
- if (info->attrs[NL80211_ATTR_IFTYPE]) {
- ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
- if (otype != ntype)
- change = true;
- if (ntype > NL80211_IFTYPE_MAX)
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_MESH_ID]) {
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- if (ntype != NL80211_IFTYPE_MESH_POINT)
- return -EINVAL;
- if (netif_running(dev))
- return -EBUSY;
- wdev_lock(wdev);
- BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
- IEEE80211_MAX_MESH_ID_LEN);
- wdev->mesh_id_up_len =
- nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
- memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
- wdev->mesh_id_up_len);
- wdev_unlock(wdev);
- }
- if (info->attrs[NL80211_ATTR_4ADDR]) {
- params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
- change = true;
- err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
- if (err)
- return err;
- } else {
- params.use_4addr = -1;
- }
- if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
- if (ntype != NL80211_IFTYPE_MONITOR)
- return -EINVAL;
- err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
- &_flags);
- if (err)
- return err;
- flags = &_flags;
- change = true;
- }
- if (change)
- err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
- else
- err = 0;
- if (!err && params.use_4addr != -1)
- dev->ieee80211_ptr->use_4addr = params.use_4addr;
- return err;
- }
- static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct vif_params params;
- struct net_device *dev;
- int err;
- enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
- u32 flags;
- memset(¶ms, 0, sizeof(params));
- if (!info->attrs[NL80211_ATTR_IFNAME])
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_IFTYPE]) {
- type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
- if (type > NL80211_IFTYPE_MAX)
- return -EINVAL;
- }
- if (!rdev->ops->add_virtual_intf ||
- !(rdev->wiphy.interface_modes & (1 << type)))
- return -EOPNOTSUPP;
- if (info->attrs[NL80211_ATTR_4ADDR]) {
- params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
- err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
- if (err)
- return err;
- }
- err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
- info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
- &flags);
- dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
- nla_data(info->attrs[NL80211_ATTR_IFNAME]),
- type, err ? NULL : &flags, ¶ms);
- if (IS_ERR(dev))
- return PTR_ERR(dev);
- if (type == NL80211_IFTYPE_MESH_POINT &&
- info->attrs[NL80211_ATTR_MESH_ID]) {
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- wdev_lock(wdev);
- BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
- IEEE80211_MAX_MESH_ID_LEN);
- wdev->mesh_id_up_len =
- nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
- memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
- wdev->mesh_id_up_len);
- wdev_unlock(wdev);
- }
- return 0;
- }
- static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- if (!rdev->ops->del_virtual_intf)
- return -EOPNOTSUPP;
- return rdev->ops->del_virtual_intf(&rdev->wiphy, dev);
- }
- static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u16 noack_map;
- if (!info->attrs[NL80211_ATTR_NOACK_MAP])
- return -EINVAL;
- if (!rdev->ops->set_noack_map)
- return -EOPNOTSUPP;
- noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
- return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map);
- }
- struct get_key_cookie {
- struct sk_buff *msg;
- int error;
- int idx;
- };
- static void get_key_callback(void *c, struct key_params *params)
- {
- struct nlattr *key;
- struct get_key_cookie *cookie = c;
- if (params->key)
- NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
- params->key_len, params->key);
- if (params->seq)
- NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
- params->seq_len, params->seq);
- if (params->cipher)
- NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
- params->cipher);
- key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
- if (!key)
- goto nla_put_failure;
- if (params->key)
- NLA_PUT(cookie->msg, NL80211_KEY_DATA,
- params->key_len, params->key);
- if (params->seq)
- NLA_PUT(cookie->msg, NL80211_KEY_SEQ,
- params->seq_len, params->seq);
- if (params->cipher)
- NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER,
- params->cipher);
- NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx);
- nla_nest_end(cookie->msg, key);
- return;
- nla_put_failure:
- cookie->error = 1;
- }
- static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- struct net_device *dev = info->user_ptr[1];
- u8 key_idx = 0;
- const u8 *mac_addr = NULL;
- bool pairwise;
- struct get_key_cookie cookie = {
- .error = 0,
- };
- void *hdr;
- struct sk_buff *msg;
- if (info->attrs[NL80211_ATTR_KEY_IDX])
- key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
- if (key_idx > 5)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_MAC])
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- pairwise = !!mac_addr;
- if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
- u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
- if (kt >= NUM_NL80211_KEYTYPES)
- return -EINVAL;
- if (kt != NL80211_KEYTYPE_GROUP &&
- kt != NL80211_KEYTYPE_PAIRWISE)
- return -EINVAL;
- pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
- }
- if (!rdev->ops->get_key)
- return -EOPNOTSUPP;
- if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
- return -ENOENT;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_NEW_KEY);
- if (!hdr)
- goto nla_put_failure;
- cookie.msg = msg;
- cookie.idx = key_idx;
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
- if (mac_addr)
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
- err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise,
- mac_addr, &cookie, get_key_callback);
- if (err)
- goto free_msg;
- if (cookie.error)
- goto nla_put_failure;
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- nla_put_failure:
- err = -ENOBUFS;
- free_msg:
- nlmsg_free(msg);
- return err;
- }
- static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct key_parse key;
- int err;
- struct net_device *dev = info->user_ptr[1];
- err = nl80211_parse_key(info, &key);
- if (err)
- return err;
- if (key.idx < 0)
- return -EINVAL;
- /* only support setting default key */
- if (!key.def && !key.defmgmt)
- return -EINVAL;
- wdev_lock(dev->ieee80211_ptr);
- if (key.def) {
- if (!rdev->ops->set_default_key) {
- err = -EOPNOTSUPP;
- goto out;
- }
- err = nl80211_key_allowed(dev->ieee80211_ptr);
- if (err)
- goto out;
- err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx,
- key.def_uni, key.def_multi);
- if (err)
- goto out;
- #ifdef CONFIG_CFG80211_WEXT
- dev->ieee80211_ptr->wext.default_key = key.idx;
- #endif
- } else {
- if (key.def_uni || !key.def_multi) {
- err = -EINVAL;
- goto out;
- }
- if (!rdev->ops->set_default_mgmt_key) {
- err = -EOPNOTSUPP;
- goto out;
- }
- err = nl80211_key_allowed(dev->ieee80211_ptr);
- if (err)
- goto out;
- err = rdev->ops->set_default_mgmt_key(&rdev->wiphy,
- dev, key.idx);
- if (err)
- goto out;
- #ifdef CONFIG_CFG80211_WEXT
- dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
- #endif
- }
- out:
- wdev_unlock(dev->ieee80211_ptr);
- return err;
- }
- static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- struct net_device *dev = info->user_ptr[1];
- struct key_parse key;
- const u8 *mac_addr = NULL;
- err = nl80211_parse_key(info, &key);
- if (err)
- return err;
- if (!key.p.key)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_MAC])
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (key.type == -1) {
- if (mac_addr)
- key.type = NL80211_KEYTYPE_PAIRWISE;
- else
- key.type = NL80211_KEYTYPE_GROUP;
- }
- /* for now */
- if (key.type != NL80211_KEYTYPE_PAIRWISE &&
- key.type != NL80211_KEYTYPE_GROUP)
- return -EINVAL;
- if (!rdev->ops->add_key)
- return -EOPNOTSUPP;
- if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
- key.type == NL80211_KEYTYPE_PAIRWISE,
- mac_addr))
- return -EINVAL;
- wdev_lock(dev->ieee80211_ptr);
- err = nl80211_key_allowed(dev->ieee80211_ptr);
- if (!err)
- err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx,
- key.type == NL80211_KEYTYPE_PAIRWISE,
- mac_addr, &key.p);
- wdev_unlock(dev->ieee80211_ptr);
- return err;
- }
- static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- struct net_device *dev = info->user_ptr[1];
- u8 *mac_addr = NULL;
- struct key_parse key;
- err = nl80211_parse_key(info, &key);
- if (err)
- return err;
- if (info->attrs[NL80211_ATTR_MAC])
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (key.type == -1) {
- if (mac_addr)
- key.type = NL80211_KEYTYPE_PAIRWISE;
- else
- key.type = NL80211_KEYTYPE_GROUP;
- }
- /* for now */
- if (key.type != NL80211_KEYTYPE_PAIRWISE &&
- key.type != NL80211_KEYTYPE_GROUP)
- return -EINVAL;
- if (!rdev->ops->del_key)
- return -EOPNOTSUPP;
- wdev_lock(dev->ieee80211_ptr);
- err = nl80211_key_allowed(dev->ieee80211_ptr);
- if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
- !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
- err = -ENOENT;
- if (!err)
- err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx,
- key.type == NL80211_KEYTYPE_PAIRWISE,
- mac_addr);
- #ifdef CONFIG_CFG80211_WEXT
- if (!err) {
- if (key.idx == dev->ieee80211_ptr->wext.default_key)
- dev->ieee80211_ptr->wext.default_key = -1;
- else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
- dev->ieee80211_ptr->wext.default_mgmt_key = -1;
- }
- #endif
- wdev_unlock(dev->ieee80211_ptr);
- return err;
- }
- /* This function returns an error or the number of nested attributes */
- static int validate_acl_mac_addrs(struct nlattr *nl_attr)
- {
- struct nlattr *attr;
- int n_entries = 0, tmp;
- nla_for_each_nested(attr, nl_attr, tmp) {
- if (nla_len(attr) != ETH_ALEN)
- return -EINVAL;
- n_entries++;
- }
- return n_entries;
- }
- /*
- * This function parses ACL information and allocates memory for ACL data.
- * On successful return, the calling function is responsible to free the
- * ACL buffer returned by this function.
- */
- static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
- struct genl_info *info)
- {
- enum nl80211_acl_policy acl_policy;
- struct nlattr *attr;
- struct cfg80211_acl_data *acl;
- int i = 0, n_entries, tmp;
- if (!wiphy->max_acl_mac_addrs)
- return ERR_PTR(-EOPNOTSUPP);
- if (!info->attrs[NL80211_ATTR_ACL_POLICY])
- return ERR_PTR(-EINVAL);
- acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
- if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
- acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
- return ERR_PTR(-EINVAL);
- if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
- return ERR_PTR(-EINVAL);
- n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
- if (n_entries < 0)
- return ERR_PTR(n_entries);
- if (n_entries > wiphy->max_acl_mac_addrs)
- return ERR_PTR(-ENOTSUPP);
- acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
- GFP_KERNEL);
- if (!acl)
- return ERR_PTR(-ENOMEM);
- nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
- memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
- i++;
- }
- acl->n_acl_entries = n_entries;
- acl->acl_policy = acl_policy;
- return acl;
- }
- static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct cfg80211_acl_data *acl;
- int err;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- if (!dev->ieee80211_ptr->beacon_interval)
- return -EINVAL;
- acl = parse_acl_data(&rdev->wiphy, info);
- if (IS_ERR(acl))
- return PTR_ERR(acl);
- err = rdev->ops->set_mac_acl(&rdev->wiphy, dev, acl);
- kfree(acl);
- return err;
- }
- static int nl80211_parse_beacon(struct nlattr *attrs[],
- struct cfg80211_beacon_data *bcn)
- {
- bool haveinfo = false;
- if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
- !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
- !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
- !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
- return -EINVAL;
- memset(bcn, 0, sizeof(*bcn));
- if (attrs[NL80211_ATTR_BEACON_HEAD]) {
- int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD]);
- if (ret)
- return ret;
- bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
- bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
- if (!bcn->head_len)
- return -EINVAL;
- haveinfo = true;
- }
- if (attrs[NL80211_ATTR_BEACON_TAIL]) {
- bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
- bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
- haveinfo = true;
- }
- if (!haveinfo)
- return -EINVAL;
- if (attrs[NL80211_ATTR_IE]) {
- bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
- bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
- }
- if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
- bcn->proberesp_ies =
- nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
- bcn->proberesp_ies_len =
- nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
- }
- if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
- bcn->assocresp_ies =
- nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
- bcn->assocresp_ies_len =
- nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
- }
- if (attrs[NL80211_ATTR_PROBE_RESP]) {
- bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
- bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
- }
- return 0;
- }
- static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct cfg80211_ap_settings params;
- int err;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- if (!rdev->ops->start_ap)
- return -EOPNOTSUPP;
- if (wdev->beacon_interval)
- return -EALREADY;
- memset(¶ms, 0, sizeof(params));
- /* these are required for START_AP */
- if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
- !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
- !info->attrs[NL80211_ATTR_BEACON_HEAD])
- return -EINVAL;
- err = nl80211_parse_beacon(info->attrs, ¶ms.beacon);
- if (err)
- return err;
- params.beacon_interval =
- nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
- params.dtim_period =
- nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
- err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
- if (err)
- return err;
- /*
- * In theory, some of these attributes should be required here
- * but since they were not used when the command was originally
- * added, keep them optional for old user space programs to let
- * them continue to work with drivers that do not need the
- * additional information -- drivers must check!
- */
- if (info->attrs[NL80211_ATTR_SSID]) {
- params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
- params.ssid_len =
- nla_len(info->attrs[NL80211_ATTR_SSID]);
- if (params.ssid_len == 0 ||
- params.ssid_len > IEEE80211_MAX_SSID_LEN)
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
- params.hidden_ssid = nla_get_u32(
- info->attrs[NL80211_ATTR_HIDDEN_SSID]);
- if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
- params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
- params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
- return -EINVAL;
- }
- params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
- if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
- params.auth_type = nla_get_u32(
- info->attrs[NL80211_ATTR_AUTH_TYPE]);
- if (!nl80211_valid_auth_type(params.auth_type))
- return -EINVAL;
- } else
- params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
- err = nl80211_crypto_settings(rdev, info, ¶ms.crypto,
- NL80211_MAX_NR_CIPHER_SUITES);
- if (err)
- return err;
- if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
- if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
- return -EOPNOTSUPP;
- params.inactivity_timeout = nla_get_u16(
- info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
- }
- if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
- params.acl = parse_acl_data(&rdev->wiphy, info);
- if (IS_ERR(params.acl))
- return PTR_ERR(params.acl);
- }
- err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms);
- if (!err)
- wdev->beacon_interval = params.beacon_interval;
- kfree(params.acl);
- return err;
- }
- static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct cfg80211_beacon_data params;
- int err;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- if (!rdev->ops->change_beacon)
- return -EOPNOTSUPP;
- if (!wdev->beacon_interval)
- return -EINVAL;
- err = nl80211_parse_beacon(info->attrs, ¶ms);
- if (err)
- return err;
- return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms);
- }
- static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- int err;
- if (!rdev->ops->stop_ap)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- if (!wdev->beacon_interval)
- return -ENOENT;
- err = rdev->ops->stop_ap(&rdev->wiphy, dev);
- wdev->beacon_interval = 0;
- return err;
- }
- static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
- [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
- [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
- [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
- [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
- [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
- [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
- };
- static int parse_station_flags(struct genl_info *info,
- enum nl80211_iftype iftype,
- struct station_parameters *params)
- {
- struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
- struct nlattr *nla;
- int flag;
- /*
- * Try parsing the new attribute first so userspace
- * can specify both for older kernels.
- */
- nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
- if (nla) {
- struct nl80211_sta_flag_update *sta_flags;
- sta_flags = nla_data(nla);
- params->sta_flags_mask = sta_flags->mask;
- params->sta_flags_set = sta_flags->set;
- if ((params->sta_flags_mask |
- params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
- return -EINVAL;
- return 0;
- }
- /* if present, parse the old attribute */
- nla = info->attrs[NL80211_ATTR_STA_FLAGS];
- if (!nla)
- return 0;
- if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
- nla, sta_flags_policy))
- return -EINVAL;
- /*
- * Only allow certain flags for interface types so that
- * other attributes are silently ignored. Remember that
- * this is backward compatibility code with old userspace
- * and shouldn't be hit in other cases anyway.
- */
- switch (iftype) {
- case NL80211_IFTYPE_AP:
- case NL80211_IFTYPE_AP_VLAN:
- case NL80211_IFTYPE_P2P_GO:
- params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
- BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
- BIT(NL80211_STA_FLAG_WME) |
- BIT(NL80211_STA_FLAG_MFP);
- break;
- case NL80211_IFTYPE_P2P_CLIENT:
- case NL80211_IFTYPE_STATION:
- params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
- BIT(NL80211_STA_FLAG_TDLS_PEER);
- break;
- case NL80211_IFTYPE_MESH_POINT:
- params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
- BIT(NL80211_STA_FLAG_MFP) |
- BIT(NL80211_STA_FLAG_AUTHORIZED);
- default:
- return -EINVAL;
- }
- for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
- if (flags[flag])
- params->sta_flags_set |= (1<<flag);
- return 0;
- }
- static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
- int attr)
- {
- struct nlattr *rate;
- u32 bitrate;
- u16 bitrate_compat;
- rate = nla_nest_start(msg, attr);
- if (!rate)
- return false;
- /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
- bitrate = cfg80211_calculate_bitrate(info);
- /* report 16-bit bitrate only if we can */
- bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
- if (bitrate > 0 &&
- nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
- return false;
- if (bitrate_compat > 0 &&
- nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
- return false;
- if (info->flags & RATE_INFO_FLAGS_MCS) {
- if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
- return false;
- if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
- nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
- return false;
- if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
- nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
- return false;
- } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
- if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
- return false;
- if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
- return false;
- if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
- nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
- return false;
- if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
- nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
- return false;
- if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
- nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
- return false;
- if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
- nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
- return false;
- if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
- nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
- return false;
- }
- nla_nest_end(msg, rate);
- return true;
- }
- static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
- int flags,
- struct cfg80211_registered_device *rdev,
- struct net_device *dev,
- const u8 *mac_addr, struct station_info *sinfo)
- {
- void *hdr;
- struct nlattr *sinfoattr, *bss_param;
- hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
- if (!hdr)
- return -1;
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
- NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation);
- sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
- if (!sinfoattr)
- goto nla_put_failure;
- if (sinfo->filled & STATION_INFO_CONNECTED_TIME)
- NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME,
- sinfo->connected_time);
- if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
- NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
- sinfo->inactive_time);
- if (sinfo->filled & STATION_INFO_RX_BYTES)
- NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
- sinfo->rx_bytes);
- if (sinfo->filled & STATION_INFO_TX_BYTES)
- NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
- sinfo->tx_bytes);
- if (sinfo->filled & STATION_INFO_LLID)
- NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
- sinfo->llid);
- if (sinfo->filled & STATION_INFO_PLID)
- NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
- sinfo->plid);
- if (sinfo->filled & STATION_INFO_PLINK_STATE)
- NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
- sinfo->plink_state);
- switch (rdev->wiphy.signal_type) {
- case CFG80211_SIGNAL_TYPE_MBM:
- if (sinfo->filled & STATION_INFO_SIGNAL)
- NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
- sinfo->signal);
- if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
- NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
- sinfo->signal_avg);
- break;
- default:
- break;
- }
- if (sinfo->filled & STATION_INFO_TX_BITRATE) {
- if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
- NL80211_STA_INFO_TX_BITRATE))
- goto nla_put_failure;
- }
- if (sinfo->filled & STATION_INFO_RX_BITRATE) {
- if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
- NL80211_STA_INFO_RX_BITRATE))
- goto nla_put_failure;
- }
- if (sinfo->filled & STATION_INFO_RX_PACKETS)
- NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
- sinfo->rx_packets);
- if (sinfo->filled & STATION_INFO_TX_PACKETS)
- NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
- sinfo->tx_packets);
- if (sinfo->filled & STATION_INFO_TX_RETRIES)
- NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES,
- sinfo->tx_retries);
- if (sinfo->filled & STATION_INFO_TX_FAILED)
- NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED,
- sinfo->tx_failed);
- if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT)
- NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS,
- sinfo->beacon_loss_count);
- if (sinfo->filled & STATION_INFO_BSS_PARAM) {
- bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
- if (!bss_param)
- goto nla_put_failure;
- if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT)
- NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT);
- if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE)
- NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE);
- if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME)
- NLA_PUT_FLAG(msg,
- NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME);
- NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
- sinfo->bss_param.dtim_period);
- NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
- sinfo->bss_param.beacon_interval);
- nla_nest_end(msg, bss_param);
- }
- if (sinfo->filled & STATION_INFO_STA_FLAGS)
- NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS,
- sizeof(struct nl80211_sta_flag_update),
- &sinfo->sta_flags);
- nla_nest_end(msg, sinfoattr);
- if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES)
- NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
- sinfo->assoc_req_ies);
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int nl80211_dump_station(struct sk_buff *skb,
- struct netlink_callback *cb)
- {
- struct station_info sinfo;
- struct cfg80211_registered_device *dev;
- struct net_device *netdev;
- u8 mac_addr[ETH_ALEN];
- int sta_idx = cb->args[1];
- int err;
- err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
- if (err)
- return err;
- if (!dev->ops->dump_station) {
- err = -EOPNOTSUPP;
- goto out_err;
- }
- while (1) {
- memset(&sinfo, 0, sizeof(sinfo));
- err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
- mac_addr, &sinfo);
- if (err == -ENOENT)
- break;
- if (err)
- goto out_err;
- if (nl80211_send_station(skb,
- NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- dev, netdev, mac_addr,
- &sinfo) < 0)
- goto out;
- sta_idx++;
- }
- out:
- cb->args[1] = sta_idx;
- err = skb->len;
- out_err:
- nl80211_finish_netdev_dump(dev);
- return err;
- }
- static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct station_info sinfo;
- struct sk_buff *msg;
- u8 *mac_addr = NULL;
- int err;
- memset(&sinfo, 0, sizeof(sinfo));
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (!rdev->ops->get_station)
- return -EOPNOTSUPP;
- err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo);
- if (err)
- return err;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
- rdev, dev, mac_addr, &sinfo) < 0) {
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- return genlmsg_reply(msg, info);
- }
- /*
- * Get vlan interface making sure it is running and on the right wiphy.
- */
- static struct net_device *get_vlan(struct genl_info *info,
- struct cfg80211_registered_device *rdev)
- {
- struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
- struct net_device *v;
- int ret;
- if (!vlanattr)
- return NULL;
- v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
- if (!v)
- return ERR_PTR(-ENODEV);
- if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
- ret = -EINVAL;
- goto error;
- }
- if (!netif_running(v)) {
- ret = -ENETDOWN;
- goto error;
- }
- return v;
- error:
- dev_put(v);
- return ERR_PTR(ret);
- }
- static int nl80211_parse_sta_channel_info(struct genl_info *info,
- struct station_parameters *params)
- {
- if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
- params->supported_channels =
- nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
- params->supported_channels_len =
- nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
- /*
- * Need to include at least one (first channel, number of
- * channels) tuple for each subband, and must have proper
- * tuples for the rest of the data as well.
- */
- if (params->supported_channels_len < 2)
- return -EINVAL;
- if (params->supported_channels_len % 2)
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
- params->supported_oper_classes =
- nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
- params->supported_oper_classes_len =
- nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
- /*
- * The value of the Length field of the Supported Operating
- * Classes element is between 2 and 253.
- */
- if (params->supported_oper_classes_len < 2 ||
- params->supported_oper_classes_len > 253)
- return -EINVAL;
- }
- return 0;
- }
- static struct nla_policy
- nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
- [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
- [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
- };
- static int nl80211_set_station_tdls(struct genl_info *info,
- struct station_parameters *params)
- {
- struct nlattr *tb[NL80211_STA_WME_MAX + 1];
- struct nlattr *nla;
- int err;
- /* Dummy STA entry gets updated once the peer capabilities are known */
- if (info->attrs[NL80211_ATTR_PEER_AID])
- params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
- params->ht_capa =
- nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
- if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
- params->vht_capa =
- nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
- err = nl80211_parse_sta_channel_info(info, params);
- if (err)
- return err;
- /* parse WME attributes if present */
- if (!info->attrs[NL80211_ATTR_STA_WME])
- return 0;
- nla = info->attrs[NL80211_ATTR_STA_WME];
- err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
- nl80211_sta_wme_policy);
- if (err)
- return err;
- if (tb[NL80211_STA_WME_UAPSD_QUEUES])
- params->uapsd_queues = nla_get_u8(
- tb[NL80211_STA_WME_UAPSD_QUEUES]);
- if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
- return -EINVAL;
- if (tb[NL80211_STA_WME_MAX_SP])
- params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
- if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
- return -EINVAL;
- params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
- return 0;
- }
- static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- struct net_device *dev = info->user_ptr[1];
- struct station_parameters params;
- u8 *mac_addr = NULL;
- memset(¶ms, 0, sizeof(params));
- params.listen_interval = -1;
- params.plink_state = -1;
- if (info->attrs[NL80211_ATTR_STA_AID])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
- params.supported_rates =
- nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
- params.supported_rates_len =
- nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
- }
- if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
- params.capability =
- nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
- params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
- }
- if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
- params.ext_capab =
- nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
- params.ext_capab_len =
- nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
- }
- if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
- params.listen_interval =
- nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
- params.ht_capa =
- nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
- if (!rdev->ops->change_station)
- return -EOPNOTSUPP;
- if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
- params.plink_action =
- nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
- if (info->attrs[NL80211_ATTR_STA_PLINK_STATE])
- params.plink_state =
- nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
- switch (dev->ieee80211_ptr->iftype) {
- case NL80211_IFTYPE_AP:
- case NL80211_IFTYPE_AP_VLAN:
- case NL80211_IFTYPE_P2P_GO:
- /* disallow mesh-specific things */
- if (params.plink_action)
- return -EINVAL;
- /* TDLS can't be set, ... */
- if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
- return -EINVAL;
- /*
- * ... but don't bother the driver with it. This works around
- * a hostapd/wpa_supplicant issue -- it always includes the
- * TLDS_PEER flag in the mask even for AP mode.
- */
- params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
- /* accept only the listed bits */
- if (params.sta_flags_mask &
- ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
- BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
- BIT(NL80211_STA_FLAG_WME) |
- BIT(NL80211_STA_FLAG_MFP)))
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
- info->attrs[NL80211_ATTR_VHT_CAPABILITY])
- return -EINVAL;
- /* must be last in here for error handling */
- params.vlan = get_vlan(info, rdev);
- if (IS_ERR(params.vlan))
- return PTR_ERR(params.vlan);
- break;
- case NL80211_IFTYPE_P2P_CLIENT:
- case NL80211_IFTYPE_STATION:
- /*
- * Don't allow userspace to change the TDLS_PEER flag,
- * but silently ignore attempts to change it since we
- * don't have state here to verify that it doesn't try
- * to change the flag.
- */
- params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
- /* Include parameters for TDLS peer (driver will check) */
- err = nl80211_set_station_tdls(info, ¶ms);
- if (err)
- return err;
- /* disallow things sta doesn't support */
- if (params.plink_action)
- return -EINVAL;
- if (params.sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
- BIT(NL80211_STA_FLAG_WME)))
- return -EINVAL;
- break;
- case NL80211_IFTYPE_ADHOC:
- /* disallow things sta doesn't support */
- if (params.plink_action)
- return -EINVAL;
- if (params.ht_capa)
- return -EINVAL;
- if (params.listen_interval >= 0)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
- info->attrs[NL80211_ATTR_VHT_CAPABILITY])
- return -EINVAL;
- /* reject any changes other than AUTHORIZED */
- if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
- return -EINVAL;
- break;
- case NL80211_IFTYPE_MESH_POINT:
- /* disallow things mesh doesn't support */
- if (params.vlan)
- return -EINVAL;
- if (params.ht_capa)
- return -EINVAL;
- if (params.listen_interval >= 0)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_STA_CAPABILITY])
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY])
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY] ||
- info->attrs[NL80211_ATTR_VHT_CAPABILITY])
- return -EINVAL;
- /*
- * No special handling for TDLS here -- the userspace
- * mesh code doesn't have this bug.
- */
- if (params.sta_flags_mask &
- ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
- BIT(NL80211_STA_FLAG_MFP) |
- BIT(NL80211_STA_FLAG_AUTHORIZED)))
- return -EINVAL;
- break;
- default:
- return -EOPNOTSUPP;
- }
- /* be aware of params.vlan when changing code here */
- err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms);
- if (params.vlan)
- dev_put(params.vlan);
- return err;
- }
- static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- struct net_device *dev = info->user_ptr[1];
- struct station_parameters params;
- u8 *mac_addr = NULL;
- memset(¶ms, 0, sizeof(params));
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_STA_AID] &&
- !info->attrs[NL80211_ATTR_PEER_AID])
- return -EINVAL;
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- params.supported_rates =
- nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
- params.supported_rates_len =
- nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
- params.listen_interval =
- nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
- if (info->attrs[NL80211_ATTR_PEER_AID])
- params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
- else
- params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
- if (!params.aid || params.aid > IEEE80211_MAX_AID)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
- params.capability =
- nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
- params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
- }
- if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
- params.ext_capab =
- nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
- params.ext_capab_len =
- nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
- }
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
- params.ht_capa =
- nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
- if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
- params.vht_capa =
- nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
- if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
- params.plink_action =
- nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
- err = nl80211_parse_sta_channel_info(info, ¶ms);
- if (err)
- return err;
- if (!rdev->ops->add_station)
- return -EOPNOTSUPP;
- if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms))
- return -EINVAL;
- /* HT requires QoS, but if we don't have that just ignore HT/VHT
- * as userspace might just pass through the capabilities from the IEs
- * directly, rather than enforcing this restriction and returning an
- * error in this case.
- */
- if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
- params.ht_capa = NULL;
- switch (dev->ieee80211_ptr->iftype) {
- case NL80211_IFTYPE_AP:
- case NL80211_IFTYPE_AP_VLAN:
- case NL80211_IFTYPE_P2P_GO:
- /* parse WME attributes if sta is WME capable */
- if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
- (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) &&
- info->attrs[NL80211_ATTR_STA_WME]) {
- struct nlattr *tb[NL80211_STA_WME_MAX + 1];
- struct nlattr *nla;
- nla = info->attrs[NL80211_ATTR_STA_WME];
- err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
- nl80211_sta_wme_policy);
- if (err)
- return err;
- if (tb[NL80211_STA_WME_UAPSD_QUEUES])
- params.uapsd_queues =
- nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]);
- if (params.uapsd_queues &
- ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
- return -EINVAL;
- if (tb[NL80211_STA_WME_MAX_SP])
- params.max_sp =
- nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
- if (params.max_sp &
- ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
- return -EINVAL;
- params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
- }
- /* TDLS peers cannot be added */
- if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
- info->attrs[NL80211_ATTR_PEER_AID])
- return -EINVAL;
- /* but don't bother the driver with it */
- params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
- /* must be last in here for error handling */
- params.vlan = get_vlan(info, rdev);
- if (IS_ERR(params.vlan))
- return PTR_ERR(params.vlan);
- break;
- case NL80211_IFTYPE_MESH_POINT:
- /* TDLS peers cannot be added */
- if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
- info->attrs[NL80211_ATTR_PEER_AID])
- return -EINVAL;
- break;
- case NL80211_IFTYPE_STATION:
- case NL80211_IFTYPE_P2P_CLIENT:
- /* Only TDLS peers can be added */
- if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
- return -EINVAL;
- /* Can only add if TDLS ... */
- if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
- return -EOPNOTSUPP;
- /* ... with external setup is supported */
- if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
- return -EOPNOTSUPP;
- break;
- default:
- return -EOPNOTSUPP;
- }
- /* be aware of params.vlan when changing code here */
- err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms);
- if (params.vlan)
- dev_put(params.vlan);
- return err;
- }
- static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u8 *mac_addr = NULL;
- if (info->attrs[NL80211_ATTR_MAC])
- mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EINVAL;
- if (!rdev->ops->del_station)
- return -EOPNOTSUPP;
- return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr);
- }
- static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
- int flags, struct net_device *dev,
- u8 *dst, u8 *next_hop,
- struct mpath_info *pinfo)
- {
- void *hdr;
- struct nlattr *pinfoattr;
- hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
- if (!hdr)
- return -1;
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
- NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
- NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation);
- pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
- if (!pinfoattr)
- goto nla_put_failure;
- if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
- NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
- pinfo->frame_qlen);
- if (pinfo->filled & MPATH_INFO_SN)
- NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN,
- pinfo->sn);
- if (pinfo->filled & MPATH_INFO_METRIC)
- NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
- pinfo->metric);
- if (pinfo->filled & MPATH_INFO_EXPTIME)
- NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
- pinfo->exptime);
- if (pinfo->filled & MPATH_INFO_FLAGS)
- NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
- pinfo->flags);
- if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
- NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
- pinfo->discovery_timeout);
- if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
- NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
- pinfo->discovery_retries);
- nla_nest_end(msg, pinfoattr);
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int nl80211_dump_mpath(struct sk_buff *skb,
- struct netlink_callback *cb)
- {
- struct mpath_info pinfo;
- struct cfg80211_registered_device *dev;
- struct net_device *netdev;
- u8 dst[ETH_ALEN];
- u8 next_hop[ETH_ALEN];
- int path_idx = cb->args[1];
- int err;
- err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
- if (err)
- return err;
- if (!dev->ops->dump_mpath) {
- err = -EOPNOTSUPP;
- goto out_err;
- }
- if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
- err = -EOPNOTSUPP;
- goto out_err;
- }
- while (1) {
- err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
- dst, next_hop, &pinfo);
- if (err == -ENOENT)
- break;
- if (err)
- goto out_err;
- if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- netdev, dst, next_hop,
- &pinfo) < 0)
- goto out;
- path_idx++;
- }
- out:
- cb->args[1] = path_idx;
- err = skb->len;
- out_err:
- nl80211_finish_netdev_dump(dev);
- return err;
- }
- static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- struct net_device *dev = info->user_ptr[1];
- struct mpath_info pinfo;
- struct sk_buff *msg;
- u8 *dst = NULL;
- u8 next_hop[ETH_ALEN];
- memset(&pinfo, 0, sizeof(pinfo));
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (!rdev->ops->get_mpath)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
- return -EOPNOTSUPP;
- err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo);
- if (err)
- return err;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
- dev, dst, next_hop, &pinfo) < 0) {
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- return genlmsg_reply(msg, info);
- }
- static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u8 *dst = NULL;
- u8 *next_hop = NULL;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
- return -EINVAL;
- dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
- next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
- if (!rdev->ops->change_mpath)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
- return -EOPNOTSUPP;
- return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop);
- }
- static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u8 *dst = NULL;
- u8 *next_hop = NULL;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
- return -EINVAL;
- dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
- next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
- if (!rdev->ops->add_mpath)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
- return -EOPNOTSUPP;
- return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop);
- }
- static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u8 *dst = NULL;
- if (info->attrs[NL80211_ATTR_MAC])
- dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (!rdev->ops->del_mpath)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
- return -EOPNOTSUPP;
- return rdev->ops->del_mpath(&rdev->wiphy, dev, dst);
- }
- static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct bss_parameters params;
- memset(¶ms, 0, sizeof(params));
- /* default to not changing parameters */
- params.use_cts_prot = -1;
- params.use_short_preamble = -1;
- params.use_short_slot_time = -1;
- params.ap_isolate = -1;
- params.ht_opmode = -1;
- if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
- params.use_cts_prot =
- nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
- if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
- params.use_short_preamble =
- nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
- if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
- params.use_short_slot_time =
- nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
- if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
- params.basic_rates =
- nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
- params.basic_rates_len =
- nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
- }
- if (info->attrs[NL80211_ATTR_AP_ISOLATE])
- params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
- if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
- params.ht_opmode =
- nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
- if (!rdev->ops->change_bss)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms);
- }
- static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
- [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
- [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
- [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
- [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
- [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
- [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
- };
- static int parse_reg_rule(struct nlattr *tb[],
- struct ieee80211_reg_rule *reg_rule)
- {
- struct ieee80211_freq_range *freq_range = ®_rule->freq_range;
- struct ieee80211_power_rule *power_rule = ®_rule->power_rule;
- if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
- return -EINVAL;
- if (!tb[NL80211_ATTR_FREQ_RANGE_START])
- return -EINVAL;
- if (!tb[NL80211_ATTR_FREQ_RANGE_END])
- return -EINVAL;
- if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
- return -EINVAL;
- if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
- return -EINVAL;
- reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
- freq_range->start_freq_khz =
- nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
- freq_range->end_freq_khz =
- nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
- freq_range->max_bandwidth_khz =
- nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
- power_rule->max_eirp =
- nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
- if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
- power_rule->max_antenna_gain =
- nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
- return 0;
- }
- static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
- {
- int r;
- char *data = NULL;
- /*
- * You should only get this when cfg80211 hasn't yet initialized
- * completely when built-in to the kernel right between the time
- * window between nl80211_init() and regulatory_init(), if that is
- * even possible.
- */
- mutex_lock(&cfg80211_mutex);
- if (unlikely(!cfg80211_regdomain)) {
- mutex_unlock(&cfg80211_mutex);
- return -EINPROGRESS;
- }
- mutex_unlock(&cfg80211_mutex);
- if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
- return -EINVAL;
- data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
- r = regulatory_hint_user(data);
- return r;
- }
- static int nl80211_get_mesh_config(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct mesh_config cur_params;
- int err = 0;
- void *hdr;
- struct nlattr *pinfoattr;
- struct sk_buff *msg;
- if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
- return -EOPNOTSUPP;
- if (!rdev->ops->get_mesh_config)
- return -EOPNOTSUPP;
- wdev_lock(wdev);
- /* If not connected, get default parameters */
- if (!wdev->mesh_id_len)
- memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
- else
- err = rdev->ops->get_mesh_config(&rdev->wiphy, dev,
- &cur_params);
- wdev_unlock(wdev);
- if (err)
- return err;
- /* Draw up a netlink message to send back */
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_GET_MESH_CONFIG);
- if (!hdr)
- goto out;
- pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
- if (!pinfoattr)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
- cur_params.dot11MeshRetryTimeout);
- NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
- cur_params.dot11MeshConfirmTimeout);
- NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
- cur_params.dot11MeshHoldingTimeout);
- NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
- cur_params.dot11MeshMaxPeerLinks);
- NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
- cur_params.dot11MeshMaxRetries);
- NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
- cur_params.dot11MeshTTL);
- NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
- cur_params.element_ttl);
- NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
- cur_params.auto_open_plinks);
- NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
- cur_params.dot11MeshHWMPmaxPREQretries);
- NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
- cur_params.path_refresh_time);
- NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
- cur_params.min_discovery_timeout);
- NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
- cur_params.dot11MeshHWMPactivePathTimeout);
- NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
- cur_params.dot11MeshHWMPpreqMinInterval);
- NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
- cur_params.dot11MeshHWMPperrMinInterval);
- NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
- cur_params.dot11MeshHWMPnetDiameterTraversalTime);
- NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
- cur_params.dot11MeshHWMPRootMode);
- NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
- cur_params.dot11MeshHWMPRannInterval);
- NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
- cur_params.dot11MeshGateAnnouncementProtocol);
- NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING,
- cur_params.dot11MeshForwarding);
- NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
- cur_params.rssi_threshold);
- nla_nest_end(msg, pinfoattr);
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- out:
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
- [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
- [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
- [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
- [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
- [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
- [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
- [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
- [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
- [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
- [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
- [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
- [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
- [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
- [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
- [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
- [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
- [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
- [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
- [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
- [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32},
- };
- static const struct nla_policy
- nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
- [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
- [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
- [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
- [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
- .len = IEEE80211_MAX_DATA_LEN },
- [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
- };
- static int nl80211_parse_mesh_config(struct genl_info *info,
- struct mesh_config *cfg,
- u32 *mask_out)
- {
- struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
- u32 mask = 0;
- #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
- do {\
- if (table[attr_num]) {\
- cfg->param = nla_fn(table[attr_num]); \
- mask |= (1 << (attr_num - 1)); \
- } \
- } while (0);\
- if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
- return -EINVAL;
- if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
- info->attrs[NL80211_ATTR_MESH_CONFIG],
- nl80211_meshconf_params_policy))
- return -EINVAL;
- /* This makes sure that there aren't more than 32 mesh config
- * parameters (otherwise our bitfield scheme would not work.) */
- BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
- /* Fill in the params struct */
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
- mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
- mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
- mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
- mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
- mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
- mask, NL80211_MESHCONF_TTL, nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
- mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
- mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
- mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
- nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
- mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
- mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
- nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
- mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
- nla_get_u32);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
- mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
- nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
- mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
- nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
- dot11MeshHWMPnetDiameterTraversalTime,
- mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
- nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
- dot11MeshHWMPRootMode, mask,
- NL80211_MESHCONF_HWMP_ROOTMODE,
- nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
- dot11MeshHWMPRannInterval, mask,
- NL80211_MESHCONF_HWMP_RANN_INTERVAL,
- nla_get_u16);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
- dot11MeshGateAnnouncementProtocol, mask,
- NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
- nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding,
- mask, NL80211_MESHCONF_FORWARDING, nla_get_u8);
- FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold,
- mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32);
- if (mask_out)
- *mask_out = mask;
- return 0;
- #undef FILL_IN_MESH_PARAM_IF_SET
- }
- static int nl80211_parse_mesh_setup(struct genl_info *info,
- struct mesh_setup *setup)
- {
- struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
- if (!info->attrs[NL80211_ATTR_MESH_SETUP])
- return -EINVAL;
- if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
- info->attrs[NL80211_ATTR_MESH_SETUP],
- nl80211_mesh_setup_params_policy))
- return -EINVAL;
- if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
- setup->path_sel_proto =
- (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
- IEEE80211_PATH_PROTOCOL_VENDOR :
- IEEE80211_PATH_PROTOCOL_HWMP;
- if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
- setup->path_metric =
- (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
- IEEE80211_PATH_METRIC_VENDOR :
- IEEE80211_PATH_METRIC_AIRTIME;
- if (tb[NL80211_MESH_SETUP_IE]) {
- struct nlattr *ieattr =
- tb[NL80211_MESH_SETUP_IE];
- if (!is_valid_ie_attr(ieattr))
- return -EINVAL;
- setup->ie = nla_data(ieattr);
- setup->ie_len = nla_len(ieattr);
- }
- setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
- setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
- return 0;
- }
- static int nl80211_update_mesh_config(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct mesh_config cfg;
- u32 mask;
- int err;
- if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
- return -EOPNOTSUPP;
- if (!rdev->ops->update_mesh_config)
- return -EOPNOTSUPP;
- err = nl80211_parse_mesh_config(info, &cfg, &mask);
- if (err)
- return err;
- wdev_lock(wdev);
- if (!wdev->mesh_id_len)
- err = -ENOLINK;
- if (!err)
- err = rdev->ops->update_mesh_config(&rdev->wiphy, dev,
- mask, &cfg);
- wdev_unlock(wdev);
- return err;
- }
- static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
- {
- struct sk_buff *msg;
- void *hdr = NULL;
- struct nlattr *nl_reg_rules;
- unsigned int i;
- int err = -EINVAL;
- mutex_lock(&cfg80211_mutex);
- if (!cfg80211_regdomain)
- goto out;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg) {
- err = -ENOBUFS;
- goto out;
- }
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_GET_REG);
- if (!hdr)
- goto put_failure;
- NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
- cfg80211_regdomain->alpha2);
- if (cfg80211_regdomain->dfs_region)
- NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION,
- cfg80211_regdomain->dfs_region);
- nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
- if (!nl_reg_rules)
- goto nla_put_failure;
- for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
- struct nlattr *nl_reg_rule;
- const struct ieee80211_reg_rule *reg_rule;
- const struct ieee80211_freq_range *freq_range;
- const struct ieee80211_power_rule *power_rule;
- reg_rule = &cfg80211_regdomain->reg_rules[i];
- freq_range = ®_rule->freq_range;
- power_rule = ®_rule->power_rule;
- nl_reg_rule = nla_nest_start(msg, i);
- if (!nl_reg_rule)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
- reg_rule->flags);
- NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
- freq_range->start_freq_khz);
- NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
- freq_range->end_freq_khz);
- NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
- freq_range->max_bandwidth_khz);
- NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
- power_rule->max_antenna_gain);
- NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
- power_rule->max_eirp);
- nla_nest_end(msg, nl_reg_rule);
- }
- nla_nest_end(msg, nl_reg_rules);
- genlmsg_end(msg, hdr);
- err = genlmsg_reply(msg, info);
- goto out;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- put_failure:
- nlmsg_free(msg);
- err = -EMSGSIZE;
- out:
- mutex_unlock(&cfg80211_mutex);
- return err;
- }
- static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
- {
- struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
- struct nlattr *nl_reg_rule;
- char *alpha2 = NULL;
- int rem_reg_rules = 0, r = 0;
- u32 num_rules = 0, rule_idx = 0, size_of_regd;
- u8 dfs_region = 0;
- struct ieee80211_regdomain *rd = NULL;
- if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_REG_RULES])
- return -EINVAL;
- alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
- if (info->attrs[NL80211_ATTR_DFS_REGION])
- dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
- nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
- rem_reg_rules) {
- num_rules++;
- if (num_rules > NL80211_MAX_SUPP_REG_RULES)
- return -EINVAL;
- }
- mutex_lock(&cfg80211_mutex);
- if (!reg_is_valid_request(alpha2)) {
- r = -EINVAL;
- goto bad_reg;
- }
- size_of_regd = sizeof(struct ieee80211_regdomain) +
- (num_rules * sizeof(struct ieee80211_reg_rule));
- rd = kzalloc(size_of_regd, GFP_KERNEL);
- if (!rd) {
- r = -ENOMEM;
- goto bad_reg;
- }
- rd->n_reg_rules = num_rules;
- rd->alpha2[0] = alpha2[0];
- rd->alpha2[1] = alpha2[1];
- /*
- * Disable DFS master mode if the DFS region was
- * not supported or known on this kernel.
- */
- if (reg_supported_dfs_region(dfs_region))
- rd->dfs_region = dfs_region;
- nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
- rem_reg_rules) {
- nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
- nla_data(nl_reg_rule), nla_len(nl_reg_rule),
- reg_rule_policy);
- r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
- if (r)
- goto bad_reg;
- rule_idx++;
- if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
- r = -EINVAL;
- goto bad_reg;
- }
- }
- BUG_ON(rule_idx != num_rules);
- r = set_regdom(rd);
- mutex_unlock(&cfg80211_mutex);
- return r;
- bad_reg:
- mutex_unlock(&cfg80211_mutex);
- kfree(rd);
- return r;
- }
- static int validate_scan_freqs(struct nlattr *freqs)
- {
- struct nlattr *attr1, *attr2;
- int n_channels = 0, tmp1, tmp2;
- nla_for_each_nested(attr1, freqs, tmp1) {
- n_channels++;
- /*
- * Some hardware has a limited channel list for
- * scanning, and it is pretty much nonsensical
- * to scan for a channel twice, so disallow that
- * and don't require drivers to check that the
- * channel list they get isn't longer than what
- * they can scan, as long as they can scan all
- * the channels they registered at once.
- */
- nla_for_each_nested(attr2, freqs, tmp2)
- if (attr1 != attr2 &&
- nla_get_u32(attr1) == nla_get_u32(attr2))
- return 0;
- }
- return n_channels;
- }
- static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct cfg80211_scan_request *request;
- struct nlattr *attr;
- struct wiphy *wiphy;
- int err, tmp, n_ssids = 0, n_channels, i;
- size_t ie_len;
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- wiphy = &rdev->wiphy;
- if (!rdev->ops->scan)
- return -EOPNOTSUPP;
- if (rdev->scan_req)
- return -EBUSY;
- if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
- n_channels = validate_scan_freqs(
- info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
- if (!n_channels)
- return -EINVAL;
- } else {
- enum ieee80211_band band;
- n_channels = 0;
- for (band = 0; band < IEEE80211_NUM_BANDS; band++)
- if (wiphy->bands[band])
- n_channels += wiphy->bands[band]->n_channels;
- }
- if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
- nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
- n_ssids++;
- if (n_ssids > wiphy->max_scan_ssids)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_IE])
- ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- else
- ie_len = 0;
- if (ie_len > wiphy->max_scan_ie_len)
- return -EINVAL;
- request = kzalloc(sizeof(*request)
- + sizeof(*request->ssids) * n_ssids
- + sizeof(*request->channels) * n_channels
- + ie_len, GFP_KERNEL);
- if (!request)
- return -ENOMEM;
- if (n_ssids)
- request->ssids = (void *)&request->channels[n_channels];
- request->n_ssids = n_ssids;
- if (ie_len) {
- if (request->ssids)
- request->ie = (void *)(request->ssids + n_ssids);
- else
- request->ie = (void *)(request->channels + n_channels);
- }
- i = 0;
- if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
- /* user specified, bail out if channel not found */
- nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
- struct ieee80211_channel *chan;
- chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
- if (!chan) {
- err = -EINVAL;
- goto out_free;
- }
- /* ignore disabled channels */
- if (chan->flags & IEEE80211_CHAN_DISABLED)
- continue;
- request->channels[i] = chan;
- i++;
- }
- } else {
- enum ieee80211_band band;
- /* all channels */
- for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
- int j;
- if (!wiphy->bands[band])
- continue;
- for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
- struct ieee80211_channel *chan;
- chan = &wiphy->bands[band]->channels[j];
- if (chan->flags & IEEE80211_CHAN_DISABLED)
- continue;
- request->channels[i] = chan;
- i++;
- }
- }
- }
- if (!i) {
- err = -EINVAL;
- goto out_free;
- }
- request->n_channels = i;
- i = 0;
- if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
- nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
- if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
- err = -EINVAL;
- goto out_free;
- }
- request->ssids[i].ssid_len = nla_len(attr);
- memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
- i++;
- }
- }
- if (info->attrs[NL80211_ATTR_IE]) {
- request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- memcpy((void *)request->ie,
- nla_data(info->attrs[NL80211_ATTR_IE]),
- request->ie_len);
- }
- for (i = 0; i < IEEE80211_NUM_BANDS; i++)
- if (wiphy->bands[i])
- request->rates[i] =
- (1 << wiphy->bands[i]->n_bitrates) - 1;
- if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
- nla_for_each_nested(attr,
- info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
- tmp) {
- enum ieee80211_band band = nla_type(attr);
- if (band < 0 || band >= IEEE80211_NUM_BANDS) {
- err = -EINVAL;
- goto out_free;
- }
- err = ieee80211_get_ratemask(wiphy->bands[band],
- nla_data(attr),
- nla_len(attr),
- &request->rates[band]);
- if (err)
- goto out_free;
- }
- }
- for (i = 0; i < IEEE80211_NUM_BANDS; i++)
- if (wiphy->bands[i])
- request->rates[i] =
- (1 << wiphy->bands[i]->n_bitrates) - 1;
- if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
- nla_for_each_nested(attr,
- info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
- tmp) {
- enum ieee80211_band band = nla_type(attr);
- if (band < 0 || band >= IEEE80211_NUM_BANDS) {
- err = -EINVAL;
- goto out_free;
- }
- if (!wiphy->bands[band])
- continue;
- err = ieee80211_get_ratemask(wiphy->bands[band],
- nla_data(attr),
- nla_len(attr),
- &request->rates[band]);
- if (err)
- goto out_free;
- }
- }
- request->no_cck =
- nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
- request->dev = dev;
- request->wiphy = &rdev->wiphy;
- request->no_cck =
- nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
- rdev->scan_req = request;
- err = rdev->ops->scan(&rdev->wiphy, dev, request);
- if (!err) {
- nl80211_send_scan_start(rdev, dev);
- dev_hold(dev);
- } else {
- out_free:
- rdev->scan_req = NULL;
- kfree(request);
- }
- return err;
- }
- static int nl80211_start_sched_scan(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_sched_scan_request *request;
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct nlattr *attr;
- struct wiphy *wiphy;
- int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
- u32 interval;
- enum ieee80211_band band;
- size_t ie_len;
- struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
- if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
- !rdev->ops->sched_scan_start)
- return -EOPNOTSUPP;
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
- return -EINVAL;
- interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
- if (interval == 0)
- return -EINVAL;
- wiphy = &rdev->wiphy;
- if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
- n_channels = validate_scan_freqs(
- info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
- if (!n_channels)
- return -EINVAL;
- } else {
- n_channels = 0;
- for (band = 0; band < IEEE80211_NUM_BANDS; band++)
- if (wiphy->bands[band])
- n_channels += wiphy->bands[band]->n_channels;
- }
- if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
- nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
- tmp)
- n_ssids++;
- if (n_ssids > wiphy->max_sched_scan_ssids)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
- nla_for_each_nested(attr,
- info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
- tmp)
- n_match_sets++;
- if (n_match_sets > wiphy->max_match_sets)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_IE])
- ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- else
- ie_len = 0;
- if (ie_len > wiphy->max_sched_scan_ie_len)
- return -EINVAL;
- mutex_lock(&rdev->sched_scan_mtx);
- if (rdev->sched_scan_req) {
- err = -EINPROGRESS;
- goto out;
- }
- request = kzalloc(sizeof(*request)
- + sizeof(*request->ssids) * n_ssids
- + sizeof(*request->match_sets) * n_match_sets
- + sizeof(*request->channels) * n_channels
- + ie_len, GFP_KERNEL);
- if (!request) {
- err = -ENOMEM;
- goto out;
- }
- if (n_ssids)
- request->ssids = (void *)&request->channels[n_channels];
- request->n_ssids = n_ssids;
- if (ie_len) {
- if (request->ssids)
- request->ie = (void *)(request->ssids + n_ssids);
- else
- request->ie = (void *)(request->channels + n_channels);
- }
- if (n_match_sets) {
- if (request->ie)
- request->match_sets = (void *)(request->ie + ie_len);
- else if (request->ssids)
- request->match_sets =
- (void *)(request->ssids + n_ssids);
- else
- request->match_sets =
- (void *)(request->channels + n_channels);
- }
- request->n_match_sets = n_match_sets;
- i = 0;
- if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
- /* user specified, bail out if channel not found */
- nla_for_each_nested(attr,
- info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
- tmp) {
- struct ieee80211_channel *chan;
- chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
- if (!chan) {
- err = -EINVAL;
- goto out_free;
- }
- /* ignore disabled channels */
- if (chan->flags & IEEE80211_CHAN_DISABLED)
- continue;
- request->channels[i] = chan;
- i++;
- }
- } else {
- /* all channels */
- for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
- int j;
- if (!wiphy->bands[band])
- continue;
- for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
- struct ieee80211_channel *chan;
- chan = &wiphy->bands[band]->channels[j];
- if (chan->flags & IEEE80211_CHAN_DISABLED)
- continue;
- request->channels[i] = chan;
- i++;
- }
- }
- }
- if (!i) {
- err = -EINVAL;
- goto out_free;
- }
- request->n_channels = i;
- i = 0;
- if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
- nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
- tmp) {
- if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
- err = -EINVAL;
- goto out_free;
- }
- request->ssids[i].ssid_len = nla_len(attr);
- memcpy(request->ssids[i].ssid, nla_data(attr),
- nla_len(attr));
- i++;
- }
- }
- i = 0;
- if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
- nla_for_each_nested(attr,
- info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
- tmp) {
- struct nlattr *ssid;
- nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
- nla_data(attr), nla_len(attr),
- nl80211_match_policy);
- ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID];
- if (ssid) {
- if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
- err = -EINVAL;
- goto out_free;
- }
- memcpy(request->match_sets[i].ssid.ssid,
- nla_data(ssid), nla_len(ssid));
- request->match_sets[i].ssid.ssid_len =
- nla_len(ssid);
- }
- i++;
- }
- }
- if (info->attrs[NL80211_ATTR_IE]) {
- request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- memcpy((void *)request->ie,
- nla_data(info->attrs[NL80211_ATTR_IE]),
- request->ie_len);
- }
- request->dev = dev;
- request->wiphy = &rdev->wiphy;
- request->interval = interval;
- err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request);
- if (!err) {
- rdev->sched_scan_req = request;
- nl80211_send_sched_scan(rdev, dev,
- NL80211_CMD_START_SCHED_SCAN);
- goto out;
- }
- out_free:
- kfree(request);
- out:
- mutex_unlock(&rdev->sched_scan_mtx);
- return err;
- }
- static int nl80211_stop_sched_scan(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
- !rdev->ops->sched_scan_stop)
- return -EOPNOTSUPP;
- mutex_lock(&rdev->sched_scan_mtx);
- err = __cfg80211_stop_sched_scan(rdev, false);
- mutex_unlock(&rdev->sched_scan_mtx);
- return err;
- }
- static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
- u32 seq, int flags,
- struct cfg80211_registered_device *rdev,
- struct wireless_dev *wdev,
- struct cfg80211_internal_bss *intbss)
- {
- struct cfg80211_bss *res = &intbss->pub;
- void *hdr;
- struct nlattr *bss;
- ASSERT_WDEV_LOCK(wdev);
- hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags,
- NL80211_CMD_NEW_SCAN_RESULTS);
- if (!hdr)
- return -1;
- genl_dump_check_consistent(cb, hdr, &nl80211_fam);
- NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex);
- bss = nla_nest_start(msg, NL80211_ATTR_BSS);
- if (!bss)
- goto nla_put_failure;
- if (!is_zero_ether_addr(res->bssid))
- NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
- if (res->information_elements && res->len_information_elements)
- NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
- res->len_information_elements,
- res->information_elements);
- if (res->beacon_ies && res->len_beacon_ies &&
- res->beacon_ies != res->information_elements)
- NLA_PUT(msg, NL80211_BSS_BEACON_IES,
- res->len_beacon_ies, res->beacon_ies);
- if (res->tsf)
- NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
- if (res->beacon_interval)
- NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
- NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
- NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
- NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO,
- jiffies_to_msecs(jiffies - intbss->ts));
- switch (rdev->wiphy.signal_type) {
- case CFG80211_SIGNAL_TYPE_MBM:
- NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
- break;
- case CFG80211_SIGNAL_TYPE_UNSPEC:
- NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
- break;
- default:
- break;
- }
- switch (wdev->iftype) {
- case NL80211_IFTYPE_P2P_CLIENT:
- case NL80211_IFTYPE_STATION:
- if (intbss == wdev->current_bss)
- NLA_PUT_U32(msg, NL80211_BSS_STATUS,
- NL80211_BSS_STATUS_ASSOCIATED);
- break;
- case NL80211_IFTYPE_ADHOC:
- if (intbss == wdev->current_bss)
- NLA_PUT_U32(msg, NL80211_BSS_STATUS,
- NL80211_BSS_STATUS_IBSS_JOINED);
- break;
- default:
- break;
- }
- nla_nest_end(msg, bss);
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int nl80211_dump_scan(struct sk_buff *skb,
- struct netlink_callback *cb)
- {
- struct cfg80211_registered_device *rdev;
- struct net_device *dev;
- struct cfg80211_internal_bss *scan;
- struct wireless_dev *wdev;
- int start = cb->args[1], idx = 0;
- int err;
- err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev);
- if (err)
- return err;
- wdev = dev->ieee80211_ptr;
- wdev_lock(wdev);
- spin_lock_bh(&rdev->bss_lock);
- cfg80211_bss_expire(rdev);
- cb->seq = rdev->bss_generation;
- list_for_each_entry(scan, &rdev->bss_list, list) {
- if (++idx <= start)
- continue;
- if (nl80211_send_bss(skb, cb,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- rdev, wdev, scan) < 0) {
- idx--;
- break;
- }
- }
- spin_unlock_bh(&rdev->bss_lock);
- wdev_unlock(wdev);
- cb->args[1] = idx;
- nl80211_finish_netdev_dump(rdev);
- return skb->len;
- }
- static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq,
- int flags, struct net_device *dev,
- struct survey_info *survey)
- {
- void *hdr;
- struct nlattr *infoattr;
- hdr = nl80211hdr_put(msg, pid, seq, flags,
- NL80211_CMD_NEW_SURVEY_RESULTS);
- if (!hdr)
- return -ENOMEM;
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
- if (!infoattr)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY,
- survey->channel->center_freq);
- if (survey->filled & SURVEY_INFO_NOISE_DBM)
- NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE,
- survey->noise);
- if (survey->filled & SURVEY_INFO_IN_USE)
- NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE);
- if (survey->filled & SURVEY_INFO_CHANNEL_TIME)
- NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
- survey->channel_time);
- if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
- NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
- survey->channel_time_busy);
- if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
- NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
- survey->channel_time_ext_busy);
- if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX)
- NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
- survey->channel_time_rx);
- if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX)
- NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
- survey->channel_time_tx);
- nla_nest_end(msg, infoattr);
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int nl80211_dump_survey(struct sk_buff *skb,
- struct netlink_callback *cb)
- {
- struct survey_info survey;
- struct cfg80211_registered_device *dev;
- struct net_device *netdev;
- int survey_idx = cb->args[1];
- int res;
- res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev);
- if (res)
- return res;
- if (!dev->ops->dump_survey) {
- res = -EOPNOTSUPP;
- goto out_err;
- }
- while (1) {
- struct ieee80211_channel *chan;
- res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx,
- &survey);
- if (res == -ENOENT)
- break;
- if (res)
- goto out_err;
- /* Survey without a channel doesn't make sense */
- if (!survey.channel) {
- res = -EINVAL;
- goto out;
- }
- chan = ieee80211_get_channel(&dev->wiphy,
- survey.channel->center_freq);
- if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
- survey_idx++;
- continue;
- }
- if (nl80211_send_survey(skb,
- NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- netdev,
- &survey) < 0)
- goto out;
- survey_idx++;
- }
- out:
- cb->args[1] = survey_idx;
- res = skb->len;
- out_err:
- nl80211_finish_netdev_dump(dev);
- return res;
- }
- static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
- {
- return auth_type <= NL80211_AUTHTYPE_MAX;
- }
- static bool nl80211_valid_wpa_versions(u32 wpa_versions)
- {
- return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
- NL80211_WPA_VERSION_2 |
- /*SEC_PRODUCT_FEATURE_WLAN_SUPPORT_WAPI*/
- NL80211_WAPI_VERSION_1 ));
- }
- static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct ieee80211_channel *chan;
- const u8 *bssid, *ssid, *ie = NULL;
- int err, ssid_len, ie_len = 0;
- enum nl80211_auth_type auth_type;
- struct key_parse key;
- bool local_state_change;
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_SSID])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
- return -EINVAL;
- err = nl80211_parse_key(info, &key);
- if (err)
- return err;
- if (key.idx >= 0) {
- if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
- return -EINVAL;
- if (!key.p.key || !key.p.key_len)
- return -EINVAL;
- if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
- key.p.key_len != WLAN_KEY_LEN_WEP40) &&
- (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
- key.p.key_len != WLAN_KEY_LEN_WEP104))
- return -EINVAL;
- if (key.idx > 4)
- return -EINVAL;
- } else {
- key.p.key_len = 0;
- key.p.key = NULL;
- }
- if (key.idx >= 0) {
- int i;
- bool ok = false;
- for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
- if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
- ok = true;
- break;
- }
- }
- if (!ok)
- return -EINVAL;
- }
- if (!rdev->ops->auth)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- chan = ieee80211_get_channel(&rdev->wiphy,
- nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
- if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
- return -EINVAL;
- ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
- ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
- if (info->attrs[NL80211_ATTR_IE]) {
- ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- }
- auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
- if (!nl80211_valid_auth_type(auth_type))
- return -EINVAL;
- local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
- /*
- * Since we no longer track auth state, ignore
- * requests to only change local state.
- */
- if (local_state_change)
- return 0;
- return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
- ssid, ssid_len, ie, ie_len,
- key.p.key, key.p.key_len, key.idx);
- }
- static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
- struct genl_info *info,
- struct cfg80211_crypto_settings *settings,
- int cipher_limit)
- {
- memset(settings, 0, sizeof(*settings));
- settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
- if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
- u16 proto;
- proto = nla_get_u16(
- info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
- settings->control_port_ethertype = cpu_to_be16(proto);
- if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
- proto != ETH_P_PAE)
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
- settings->control_port_no_encrypt = true;
- } else
- settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
- if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
- void *data;
- int len, i;
- data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
- len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
- settings->n_ciphers_pairwise = len / sizeof(u32);
- if (len % sizeof(u32))
- return -EINVAL;
- if (settings->n_ciphers_pairwise > cipher_limit)
- return -EINVAL;
- memcpy(settings->ciphers_pairwise, data, len);
- for (i = 0; i < settings->n_ciphers_pairwise; i++)
- if (!cfg80211_supported_cipher_suite(
- &rdev->wiphy,
- settings->ciphers_pairwise[i]))
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
- settings->cipher_group =
- nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
- if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
- settings->cipher_group))
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
- settings->wpa_versions =
- nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
- if (!nl80211_valid_wpa_versions(settings->wpa_versions))
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
- void *data;
- int len;
- data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
- len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
- settings->n_akm_suites = len / sizeof(u32);
- if (len % sizeof(u32))
- return -EINVAL;
- if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
- return -EINVAL;
- memcpy(settings->akm_suites, data, len);
- }
- return 0;
- }
- static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct cfg80211_crypto_settings crypto;
- struct ieee80211_channel *chan;
- const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
- int err, ssid_len, ie_len = 0;
- bool use_mfp = false;
- u32 flags = 0;
- struct ieee80211_ht_cap *ht_capa = NULL;
- struct ieee80211_ht_cap *ht_capa_mask = NULL;
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MAC] ||
- !info->attrs[NL80211_ATTR_SSID] ||
- !info->attrs[NL80211_ATTR_WIPHY_FREQ])
- return -EINVAL;
- if (!rdev->ops->assoc)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- chan = ieee80211_get_channel(&rdev->wiphy,
- nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
- if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
- return -EINVAL;
- ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
- ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
- if (info->attrs[NL80211_ATTR_IE]) {
- ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- }
- if (info->attrs[NL80211_ATTR_USE_MFP]) {
- enum nl80211_mfp mfp =
- nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
- if (mfp == NL80211_MFP_REQUIRED)
- use_mfp = true;
- else if (mfp != NL80211_MFP_NO)
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_PREV_BSSID])
- prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
- if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
- flags |= ASSOC_REQ_DISABLE_HT;
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
- ht_capa_mask =
- nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
- if (!ht_capa_mask)
- return -EINVAL;
- ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
- }
- err = nl80211_crypto_settings(rdev, info, &crypto, 1);
- if (!err)
- err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
- ssid, ssid_len, ie, ie_len, use_mfp,
- &crypto, flags, ht_capa,
- ht_capa_mask);
- return err;
- }
- static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- const u8 *ie = NULL, *bssid;
- int ie_len = 0;
- u16 reason_code;
- bool local_state_change;
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_REASON_CODE])
- return -EINVAL;
- if (!rdev->ops->deauth)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
- if (reason_code == 0) {
- /* Reason Code 0 is reserved */
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_IE]) {
- ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- }
- local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
- return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
- local_state_change);
- }
- static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- const u8 *ie = NULL, *bssid;
- int ie_len = 0;
- u16 reason_code;
- bool local_state_change;
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_REASON_CODE])
- return -EINVAL;
- if (!rdev->ops->disassoc)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
- if (reason_code == 0) {
- /* Reason Code 0 is reserved */
- return -EINVAL;
- }
- if (info->attrs[NL80211_ATTR_IE]) {
- ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- }
- local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
- return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
- local_state_change);
- }
- static bool
- nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
- int mcast_rate[IEEE80211_NUM_BANDS],
- int rateval)
- {
- struct wiphy *wiphy = &rdev->wiphy;
- bool found = false;
- int band, i;
- for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
- struct ieee80211_supported_band *sband;
- sband = wiphy->bands[band];
- if (!sband)
- continue;
- for (i = 0; i < sband->n_bitrates; i++) {
- if (sband->bitrates[i].bitrate == rateval) {
- mcast_rate[band] = i + 1;
- found = true;
- break;
- }
- }
- }
- return found;
- }
- static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct cfg80211_ibss_params ibss;
- struct wiphy *wiphy;
- struct cfg80211_cached_keys *connkeys = NULL;
- int err;
- memset(&ibss, 0, sizeof(ibss));
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
- !info->attrs[NL80211_ATTR_SSID] ||
- !nla_len(info->attrs[NL80211_ATTR_SSID]))
- return -EINVAL;
- ibss.beacon_interval = 100;
- if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
- ibss.beacon_interval =
- nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
- if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
- return -EINVAL;
- }
- if (!rdev->ops->join_ibss)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
- return -EOPNOTSUPP;
- wiphy = &rdev->wiphy;
- if (info->attrs[NL80211_ATTR_MAC]) {
- ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (!is_valid_ether_addr(ibss.bssid))
- return -EINVAL;
- }
- ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
- ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
- if (info->attrs[NL80211_ATTR_IE]) {
- ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- }
- if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
- enum nl80211_channel_type channel_type;
- channel_type = nla_get_u32(
- info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
- if (channel_type != NL80211_CHAN_NO_HT &&
- channel_type != NL80211_CHAN_HT20 &&
- channel_type != NL80211_CHAN_HT40MINUS &&
- channel_type != NL80211_CHAN_HT40PLUS)
- return -EINVAL;
- if (channel_type != NL80211_CHAN_NO_HT &&
- !(wiphy->features & NL80211_FEATURE_HT_IBSS))
- return -EINVAL;
- ibss.channel_type = channel_type;
- } else {
- ibss.channel_type = NL80211_CHAN_NO_HT;
- }
- ibss.channel = rdev_freq_to_chan(rdev,
- nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
- ibss.channel_type);
- if (!ibss.channel ||
- ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
- ibss.channel->flags & IEEE80211_CHAN_DISABLED)
- return -EINVAL;
- /* Both channels should be able to initiate communication */
- if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
- ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
- !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
- ibss.channel_type))
- return -EINVAL;
- ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
- ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
- if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
- u8 *rates =
- nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
- int n_rates =
- nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
- struct ieee80211_supported_band *sband =
- wiphy->bands[ibss.channel->band];
- err = ieee80211_get_ratemask(sband, rates, n_rates,
- &ibss.basic_rates);
- if (err)
- return err;
- }
- if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
- !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
- nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
- return -EINVAL;
- if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
- connkeys = nl80211_parse_connkeys(rdev,
- info->attrs[NL80211_ATTR_KEYS]);
- if (IS_ERR(connkeys))
- return PTR_ERR(connkeys);
- }
- ibss.control_port =
- nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
- err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
- if (err)
- kfree(connkeys);
- return err;
- }
- static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- if (!rdev->ops->leave_ibss)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
- return -EOPNOTSUPP;
- return cfg80211_leave_ibss(rdev, dev, false);
- }
- static struct sk_buff *
- __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
- struct wireless_dev *wdev, int approxlen,
- u32 portid, u32 seq, enum nl80211_commands cmd,
- enum nl80211_attrs attr,
- const struct nl80211_vendor_cmd_info *info,
- gfp_t gfp)
- {
- struct sk_buff *skb;
- void *hdr;
- struct nlattr *data;
- skb = nlmsg_new(approxlen + 100, gfp);
- if (!skb)
- return NULL;
- hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
- if (!hdr) {
- kfree_skb(skb);
- return NULL;
- }
- if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
- goto nla_put_failure;
- if (info) {
- if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
- info->vendor_id))
- goto nla_put_failure;
- if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
- info->subcmd))
- goto nla_put_failure;
- }
- if (wdev) {
- if (wdev->netdev &&
- nla_put_u32(skb, NL80211_ATTR_IFINDEX,
- wdev->netdev->ifindex))
- goto nla_put_failure;
- }
- data = nla_nest_start(skb, attr);
- ((void **)skb->cb)[0] = rdev;
- ((void **)skb->cb)[1] = hdr;
- ((void **)skb->cb)[2] = data;
- return skb;
- nla_put_failure:
- kfree_skb(skb);
- return NULL;
- }
- static struct genl_multicast_group nl80211_vendor_mcgrp = {
- .name = "vendor",
- };
- #ifdef CONFIG_NL80211_TESTMODE
- static struct genl_multicast_group nl80211_testmode_mcgrp = {
- .name = "testmode",
- };
- static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int err;
- if (!info->attrs[NL80211_ATTR_TESTDATA])
- return -EINVAL;
- err = -EOPNOTSUPP;
- if (rdev->ops->testmode_cmd) {
- rdev->cur_cmd_info = info;
- err = rdev->ops->testmode_cmd(&rdev->wiphy,
- nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
- nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
- rdev->cur_cmd_info = NULL;
- }
- return err;
- }
- static int nl80211_testmode_dump(struct sk_buff *skb,
- struct netlink_callback *cb)
- {
- struct cfg80211_registered_device *rdev;
- int err;
- long phy_idx;
- void *data = NULL;
- int data_len = 0;
- if (cb->args[0]) {
- /*
- * 0 is a valid index, but not valid for args[0],
- * so we need to offset by 1.
- */
- phy_idx = cb->args[0] - 1;
- } else {
- err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
- nl80211_fam.attrbuf, nl80211_fam.maxattr,
- nl80211_policy);
- if (err)
- return err;
- if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) {
- phy_idx = nla_get_u32(
- nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]);
- } else {
- struct net_device *netdev;
- err = get_rdev_dev_by_ifindex(sock_net(skb->sk),
- nl80211_fam.attrbuf,
- &rdev, &netdev);
- if (err)
- return err;
- dev_put(netdev);
- phy_idx = rdev->wiphy_idx;
- cfg80211_unlock_rdev(rdev);
- }
- if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
- cb->args[1] =
- (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
- }
- if (cb->args[1]) {
- data = nla_data((void *)cb->args[1]);
- data_len = nla_len((void *)cb->args[1]);
- }
- mutex_lock(&cfg80211_mutex);
- rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
- if (!rdev) {
- mutex_unlock(&cfg80211_mutex);
- return -ENOENT;
- }
- cfg80211_lock_rdev(rdev);
- mutex_unlock(&cfg80211_mutex);
- if (!rdev->ops->testmode_dump) {
- err = -EOPNOTSUPP;
- goto out_err;
- }
- while (1) {
- void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
- NL80211_CMD_TESTMODE);
- struct nlattr *tmdata;
- if (!hdr)
- break;
- if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) {
- genlmsg_cancel(skb, hdr);
- break;
- }
- tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
- if (!tmdata) {
- genlmsg_cancel(skb, hdr);
- break;
- }
- err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb,
- data, data_len);
- nla_nest_end(skb, tmdata);
- if (err == -ENOBUFS || err == -ENOENT) {
- genlmsg_cancel(skb, hdr);
- break;
- } else if (err) {
- genlmsg_cancel(skb, hdr);
- goto out_err;
- }
- genlmsg_end(skb, hdr);
- }
- err = skb->len;
- /* see above */
- cb->args[0] = phy_idx + 1;
- out_err:
- cfg80211_unlock_rdev(rdev);
- return err;
- }
- #endif
- struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
- struct wireless_dev *wdev,
- enum nl80211_commands cmd,
- enum nl80211_attrs attr,
- int vendor_event_idx,
- int approxlen, gfp_t gfp)
- {
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
- const struct nl80211_vendor_cmd_info *info;
- switch (cmd) {
- case NL80211_CMD_TESTMODE:
- if (WARN_ON(vendor_event_idx != -1))
- return NULL;
- info = NULL;
- break;
- case NL80211_CMD_VENDOR:
- if (WARN_ON(vendor_event_idx < 0 ||
- vendor_event_idx >= wiphy->n_vendor_events))
- return NULL;
- info = &wiphy->vendor_events[vendor_event_idx];
- break;
- default:
- WARN_ON(1);
- return NULL;
- }
- return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
- cmd, attr, info, gfp);
- }
- EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
- void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
- {
- struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
- void *hdr = ((void **)skb->cb)[1];
- struct nlattr *data = ((void **)skb->cb)[2];
- /* clear CB data for netlink core to own from now on */
- memset(skb->cb, 0, sizeof(skb->cb));
- nla_nest_end(skb, data);
- genlmsg_end(skb, hdr);
- if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
- nl80211_vendor_mcgrp.id, gfp);
- else
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
- nl80211_testmode_mcgrp.id, gfp);
- }
- EXPORT_SYMBOL(__cfg80211_send_event_skb);
- static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct cfg80211_connect_params connect;
- struct wiphy *wiphy;
- struct cfg80211_cached_keys *connkeys = NULL;
- int err;
- memset(&connect, 0, sizeof(connect));
- if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_SSID] ||
- !nla_len(info->attrs[NL80211_ATTR_SSID]))
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
- connect.auth_type =
- nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
- if (!nl80211_valid_auth_type(connect.auth_type))
- return -EINVAL;
- } else
- connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
- connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
- err = nl80211_crypto_settings(rdev, info, &connect.crypto,
- NL80211_MAX_NR_CIPHER_SUITES);
- if (err)
- return err;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- wiphy = &rdev->wiphy;
- connect.bg_scan_period = -1;
- if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
- (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
- connect.bg_scan_period =
- nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
- }
- if (info->attrs[NL80211_ATTR_MAC])
- connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- else if (info->attrs[NL80211_ATTR_MAC_HINT])
- connect.bssid_hint =
- nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
- connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
- connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
- if (info->attrs[NL80211_ATTR_IE]) {
- connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- }
- if (info->attrs[NL80211_ATTR_USE_MFP]) {
- connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
- if (connect.mfp != NL80211_MFP_REQUIRED &&
- connect.mfp != NL80211_MFP_NO)
- return -EINVAL;
- } else {
- connect.mfp = NL80211_MFP_NO;
- }
- if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
- connect.channel =
- ieee80211_get_channel(wiphy,
- nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
- if (!connect.channel ||
- connect.channel->flags & IEEE80211_CHAN_DISABLED)
- return -EINVAL;
- } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
- connect.channel_hint =
- ieee80211_get_channel(wiphy,
- nla_get_u32(
- info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]));
- if (!connect.channel_hint ||
- connect.channel_hint->flags & IEEE80211_CHAN_DISABLED)
- return -EINVAL;
- }
- if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
- connkeys = nl80211_parse_connkeys(rdev,
- info->attrs[NL80211_ATTR_KEYS]);
- if (IS_ERR(connkeys))
- return PTR_ERR(connkeys);
- }
- if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
- connect.flags |= ASSOC_REQ_DISABLE_HT;
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
- memcpy(&connect.ht_capa_mask,
- nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
- sizeof(connect.ht_capa_mask));
- if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
- if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
- return -EINVAL;
- memcpy(&connect.ht_capa,
- nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
- sizeof(connect.ht_capa));
- }
- err = cfg80211_connect(rdev, dev, &connect, connkeys);
- if (err)
- kfree(connkeys);
- return err;
- }
- static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u16 reason;
- if (!info->attrs[NL80211_ATTR_REASON_CODE])
- reason = WLAN_REASON_DEAUTH_LEAVING;
- else
- reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
- if (reason == 0)
- return -EINVAL;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- return cfg80211_disconnect(rdev, dev, reason, true);
- }
- static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net *net;
- int err;
- u32 pid;
- if (!info->attrs[NL80211_ATTR_PID])
- return -EINVAL;
- pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
- net = get_net_ns_by_pid(pid);
- if (IS_ERR(net))
- return PTR_ERR(net);
- err = 0;
- /* check if anything to do */
- if (!net_eq(wiphy_net(&rdev->wiphy), net))
- err = cfg80211_switch_netns(rdev, net);
- put_net(net);
- return err;
- }
- static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
- struct cfg80211_pmksa *pmksa) = NULL;
- struct net_device *dev = info->user_ptr[1];
- struct cfg80211_pmksa pmksa;
- memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!info->attrs[NL80211_ATTR_PMKID])
- return -EINVAL;
- pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
- pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- switch (info->genlhdr->cmd) {
- case NL80211_CMD_SET_PMKSA:
- rdev_ops = rdev->ops->set_pmksa;
- break;
- case NL80211_CMD_DEL_PMKSA:
- rdev_ops = rdev->ops->del_pmksa;
- break;
- default:
- WARN_ON(1);
- break;
- }
- if (!rdev_ops)
- return -EOPNOTSUPP;
- return rdev_ops(&rdev->wiphy, dev, &pmksa);
- }
- static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- if (!rdev->ops->flush_pmksa)
- return -EOPNOTSUPP;
- return rdev->ops->flush_pmksa(&rdev->wiphy, dev);
- }
- static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u8 action_code, dialog_token;
- u32 peer_capability = 0;
- u16 status_code;
- u8 *peer;
- if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
- !rdev->ops->tdls_mgmt)
- return -EOPNOTSUPP;
- if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
- !info->attrs[NL80211_ATTR_STATUS_CODE] ||
- !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
- !info->attrs[NL80211_ATTR_IE] ||
- !info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
- action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
- status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
- dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
- if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
- peer_capability =
- nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
- return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code,
- dialog_token, status_code, peer_capability,
- nla_data(info->attrs[NL80211_ATTR_IE]),
- nla_len(info->attrs[NL80211_ATTR_IE]));
- }
- static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- enum nl80211_tdls_operation operation;
- u8 *peer;
- if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
- !rdev->ops->tdls_oper)
- return -EOPNOTSUPP;
- if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
- !info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
- peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
- return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation);
- }
- static int nl80211_remain_on_channel(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct ieee80211_channel *chan;
- struct sk_buff *msg;
- void *hdr;
- u64 cookie;
- enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
- u32 freq, duration;
- int err;
- if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
- !info->attrs[NL80211_ATTR_DURATION])
- return -EINVAL;
- duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
- /*
- * We should be on that channel for at least one jiffie,
- * and more than 5 seconds seems excessive.
- */
- if (!duration || !msecs_to_jiffies(duration) ||
- duration > rdev->wiphy.max_remain_on_channel_duration)
- return -EINVAL;
- if (!rdev->ops->remain_on_channel ||
- !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
- return -EOPNOTSUPP;
- if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
- channel_type = nla_get_u32(
- info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
- if (channel_type != NL80211_CHAN_NO_HT &&
- channel_type != NL80211_CHAN_HT20 &&
- channel_type != NL80211_CHAN_HT40PLUS &&
- channel_type != NL80211_CHAN_HT40MINUS)
- return -EINVAL;
- }
- freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
- chan = rdev_freq_to_chan(rdev, freq, channel_type);
- if (chan == NULL)
- return -EINVAL;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_REMAIN_ON_CHANNEL);
- if (!hdr) {
- err = -ENOBUFS;
- goto free_msg;
- }
- err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan,
- channel_type, duration, &cookie);
- if (err)
- goto free_msg;
- NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- nla_put_failure:
- err = -ENOBUFS;
- free_msg:
- nlmsg_free(msg);
- return err;
- }
- static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u64 cookie;
- if (!info->attrs[NL80211_ATTR_COOKIE])
- return -EINVAL;
- if (!rdev->ops->cancel_remain_on_channel)
- return -EOPNOTSUPP;
- cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
- return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie);
- }
- static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
- u8 *rates, u8 rates_len)
- {
- u8 i;
- u32 mask = 0;
- for (i = 0; i < rates_len; i++) {
- int rate = (rates[i] & 0x7f) * 5;
- int ridx;
- for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
- struct ieee80211_rate *srate =
- &sband->bitrates[ridx];
- if (rate == srate->bitrate) {
- mask |= 1 << ridx;
- break;
- }
- }
- if (ridx == sband->n_bitrates)
- return 0; /* rate not found */
- }
- return mask;
- }
- static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
- u8 *rates, u8 rates_len,
- u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
- {
- u8 i;
- memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
- for (i = 0; i < rates_len; i++) {
- int ridx, rbit;
- ridx = rates[i] / 8;
- rbit = BIT(rates[i] % 8);
- /* check validity */
- if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
- return false;
- /* check availability */
- if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
- mcs[ridx] |= rbit;
- else
- return false;
- }
- return true;
- }
- static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
- [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
- .len = NL80211_MAX_SUPP_RATES },
- [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
- .len = NL80211_MAX_SUPP_HT_RATES },
- };
- static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct nlattr *tb[NL80211_TXRATE_MAX + 1];
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct cfg80211_bitrate_mask mask;
- int rem, i;
- struct net_device *dev = info->user_ptr[1];
- struct nlattr *tx_rates;
- struct ieee80211_supported_band *sband;
- if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
- return -EINVAL;
- if (!rdev->ops->set_bitrate_mask)
- return -EOPNOTSUPP;
- memset(&mask, 0, sizeof(mask));
- /* Default to all rates enabled */
- for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
- sband = rdev->wiphy.bands[i];
- mask.control[i].legacy =
- sband ? (1 << sband->n_bitrates) - 1 : 0;
- if (sband)
- memcpy(mask.control[i].mcs,
- sband->ht_cap.mcs.rx_mask,
- sizeof(mask.control[i].mcs));
- else
- memset(mask.control[i].mcs, 0,
- sizeof(mask.control[i].mcs));
- }
- /*
- * The nested attribute uses enum nl80211_band as the index. This maps
- * directly to the enum ieee80211_band values used in cfg80211.
- */
- BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
- nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
- {
- enum ieee80211_band band = nla_type(tx_rates);
- if (band < 0 || band >= IEEE80211_NUM_BANDS)
- return -EINVAL;
- sband = rdev->wiphy.bands[band];
- if (sband == NULL)
- return -EINVAL;
- nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
- nla_len(tx_rates), nl80211_txattr_policy);
- if (tb[NL80211_TXRATE_LEGACY]) {
- mask.control[band].legacy = rateset_to_mask(
- sband,
- nla_data(tb[NL80211_TXRATE_LEGACY]),
- nla_len(tb[NL80211_TXRATE_LEGACY]));
- }
- if (tb[NL80211_TXRATE_MCS]) {
- if (!ht_rateset_to_mask(
- sband,
- nla_data(tb[NL80211_TXRATE_MCS]),
- nla_len(tb[NL80211_TXRATE_MCS]),
- mask.control[band].mcs))
- return -EINVAL;
- }
- if (mask.control[band].legacy == 0) {
- /* don't allow empty legacy rates if HT
- * is not even supported. */
- if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
- return -EINVAL;
- for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
- if (mask.control[band].mcs[i])
- break;
- /* legacy and mcs rates may not be both empty */
- if (i == IEEE80211_HT_MCS_MASK_LEN)
- return -EINVAL;
- }
- }
- return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask);
- }
- static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
- if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_FRAME_TYPE])
- frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- /* not much point in registering if we can't reply */
- if (!rdev->ops->mgmt_tx)
- return -EOPNOTSUPP;
- return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid,
- frame_type,
- nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
- nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
- }
- static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct ieee80211_channel *chan;
- enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
- bool channel_type_valid = false;
- u32 freq;
- int err;
- void *hdr = NULL;
- u64 cookie;
- struct sk_buff *msg = NULL;
- unsigned int wait = 0;
- bool offchan, no_cck, dont_wait_for_ack;
- dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
- if (!info->attrs[NL80211_ATTR_FRAME] ||
- !info->attrs[NL80211_ATTR_WIPHY_FREQ])
- return -EINVAL;
- if (!rdev->ops->mgmt_tx)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- if (info->attrs[NL80211_ATTR_DURATION]) {
- if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
- return -EINVAL;
- wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
- }
- if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
- channel_type = nla_get_u32(
- info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
- if (channel_type != NL80211_CHAN_NO_HT &&
- channel_type != NL80211_CHAN_HT20 &&
- channel_type != NL80211_CHAN_HT40PLUS &&
- channel_type != NL80211_CHAN_HT40MINUS)
- return -EINVAL;
- channel_type_valid = true;
- }
- offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
- if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
- return -EINVAL;
- no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
- freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
- chan = rdev_freq_to_chan(rdev, freq, channel_type);
- if (chan == NULL)
- return -EINVAL;
- if (!dont_wait_for_ack) {
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_FRAME);
- if (!hdr) {
- err = -ENOBUFS;
- goto free_msg;
- }
- }
- err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type,
- channel_type_valid, wait,
- nla_data(info->attrs[NL80211_ATTR_FRAME]),
- nla_len(info->attrs[NL80211_ATTR_FRAME]),
- no_cck, dont_wait_for_ack, &cookie);
- if (err)
- goto free_msg;
- if (msg) {
- NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- }
- return 0;
- nla_put_failure:
- err = -ENOBUFS;
- free_msg:
- nlmsg_free(msg);
- return err;
- }
- static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- u64 cookie;
- if (!info->attrs[NL80211_ATTR_COOKIE])
- return -EINVAL;
- if (!rdev->ops->mgmt_tx_cancel_wait)
- return -EOPNOTSUPP;
- if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
- dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
- return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie);
- }
- static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct wireless_dev *wdev;
- struct net_device *dev = info->user_ptr[1];
- u8 ps_state;
- bool state;
- int err;
- if (!info->attrs[NL80211_ATTR_PS_STATE])
- return -EINVAL;
- ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
- if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
- return -EINVAL;
- wdev = dev->ieee80211_ptr;
- if (!rdev->ops->set_power_mgmt)
- return -EOPNOTSUPP;
- state = (ps_state == NL80211_PS_ENABLED) ? true : false;
- if (state == wdev->ps)
- return 0;
- err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state,
- wdev->ps_timeout);
- if (!err)
- wdev->ps = state;
- return err;
- }
- static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- enum nl80211_ps_state ps_state;
- struct wireless_dev *wdev;
- struct net_device *dev = info->user_ptr[1];
- struct sk_buff *msg;
- void *hdr;
- int err;
- wdev = dev->ieee80211_ptr;
- if (!rdev->ops->set_power_mgmt)
- return -EOPNOTSUPP;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_GET_POWER_SAVE);
- if (!hdr) {
- err = -ENOBUFS;
- goto free_msg;
- }
- if (wdev->ps)
- ps_state = NL80211_PS_ENABLED;
- else
- ps_state = NL80211_PS_DISABLED;
- NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- nla_put_failure:
- err = -ENOBUFS;
- free_msg:
- nlmsg_free(msg);
- return err;
- }
- static struct nla_policy
- nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
- [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
- [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
- [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
- };
- static int nl80211_set_cqm_rssi(struct genl_info *info,
- s32 threshold, u32 hysteresis)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct wireless_dev *wdev;
- struct net_device *dev = info->user_ptr[1];
- if (threshold > 0)
- return -EINVAL;
- wdev = dev->ieee80211_ptr;
- if (!rdev->ops->set_cqm_rssi_config)
- return -EOPNOTSUPP;
- if (wdev->iftype != NL80211_IFTYPE_STATION &&
- wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
- return -EOPNOTSUPP;
- return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev,
- threshold, hysteresis);
- }
- static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
- {
- struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
- struct nlattr *cqm;
- int err;
- cqm = info->attrs[NL80211_ATTR_CQM];
- if (!cqm) {
- err = -EINVAL;
- goto out;
- }
- err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
- nl80211_attr_cqm_policy);
- if (err)
- goto out;
- if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
- attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
- s32 threshold;
- u32 hysteresis;
- threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
- hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
- err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
- } else
- err = -EINVAL;
- out:
- return err;
- }
- static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct mesh_config cfg;
- struct mesh_setup setup;
- int err;
- /* start with default */
- memcpy(&cfg, &default_mesh_config, sizeof(cfg));
- memcpy(&setup, &default_mesh_setup, sizeof(setup));
- if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
- /* and parse parameters if given */
- err = nl80211_parse_mesh_config(info, &cfg, NULL);
- if (err)
- return err;
- }
- if (!info->attrs[NL80211_ATTR_MESH_ID] ||
- !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
- return -EINVAL;
- setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
- setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
- if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
- !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
- nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
- return -EINVAL;
- if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
- /* parse additional setup parameters if given */
- err = nl80211_parse_mesh_setup(info, &setup);
- if (err)
- return err;
- }
- return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
- }
- static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- return cfg80211_leave_mesh(rdev, dev);
- }
- static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct sk_buff *msg;
- void *hdr;
- if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
- return -EOPNOTSUPP;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_GET_WOWLAN);
- if (!hdr)
- goto nla_put_failure;
- if (rdev->wowlan) {
- struct nlattr *nl_wowlan;
- nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
- if (!nl_wowlan)
- goto nla_put_failure;
- if (rdev->wowlan->any)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY);
- if (rdev->wowlan->disconnect)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT);
- if (rdev->wowlan->magic_pkt)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT);
- if (rdev->wowlan->gtk_rekey_failure)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE);
- if (rdev->wowlan->eap_identity_req)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST);
- if (rdev->wowlan->four_way_handshake)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE);
- if (rdev->wowlan->rfkill_release)
- NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE);
- if (rdev->wowlan->n_patterns) {
- struct nlattr *nl_pats, *nl_pat;
- int i, pat_len;
- nl_pats = nla_nest_start(msg,
- NL80211_WOWLAN_TRIG_PKT_PATTERN);
- if (!nl_pats)
- goto nla_put_failure;
- for (i = 0; i < rdev->wowlan->n_patterns; i++) {
- nl_pat = nla_nest_start(msg, i + 1);
- if (!nl_pat)
- goto nla_put_failure;
- pat_len = rdev->wowlan->patterns[i].pattern_len;
- NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK,
- DIV_ROUND_UP(pat_len, 8),
- rdev->wowlan->patterns[i].mask);
- NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
- pat_len,
- rdev->wowlan->patterns[i].pattern);
- nla_nest_end(msg, nl_pat);
- }
- nla_nest_end(msg, nl_pats);
- }
- nla_nest_end(msg, nl_wowlan);
- }
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- nla_put_failure:
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
- struct cfg80211_wowlan no_triggers = {};
- struct cfg80211_wowlan new_triggers = {};
- struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan;
- int err, i;
- if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns)
- return -EOPNOTSUPP;
- if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS])
- goto no_triggers;
- err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
- nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
- nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
- nl80211_wowlan_policy);
- if (err)
- return err;
- if (tb[NL80211_WOWLAN_TRIG_ANY]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
- return -EINVAL;
- new_triggers.any = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
- return -EINVAL;
- new_triggers.disconnect = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
- return -EINVAL;
- new_triggers.magic_pkt = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
- return -EINVAL;
- if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
- return -EINVAL;
- new_triggers.gtk_rekey_failure = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
- return -EINVAL;
- new_triggers.eap_identity_req = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
- return -EINVAL;
- new_triggers.four_way_handshake = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
- if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
- return -EINVAL;
- new_triggers.rfkill_release = true;
- }
- if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
- struct nlattr *pat;
- int n_patterns = 0;
- int rem, pat_len, mask_len;
- struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
- nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
- rem)
- n_patterns++;
- if (n_patterns > wowlan->n_patterns)
- return -EINVAL;
- new_triggers.patterns = kcalloc(n_patterns,
- sizeof(new_triggers.patterns[0]),
- GFP_KERNEL);
- if (!new_triggers.patterns)
- return -ENOMEM;
- new_triggers.n_patterns = n_patterns;
- i = 0;
- nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
- rem) {
- nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
- nla_data(pat), nla_len(pat), nl80211_packet_pattern_policy);
- err = -EINVAL;
- if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
- !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
- goto error;
- pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
- mask_len = DIV_ROUND_UP(pat_len, 8);
- if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
- mask_len)
- goto error;
- if (pat_len > wowlan->pattern_max_len ||
- pat_len < wowlan->pattern_min_len)
- goto error;
- new_triggers.patterns[i].mask =
- kmalloc(mask_len + pat_len, GFP_KERNEL);
- if (!new_triggers.patterns[i].mask) {
- err = -ENOMEM;
- goto error;
- }
- new_triggers.patterns[i].pattern =
- new_triggers.patterns[i].mask + mask_len;
- memcpy(new_triggers.patterns[i].mask,
- nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
- mask_len);
- new_triggers.patterns[i].pattern_len = pat_len;
- memcpy(new_triggers.patterns[i].pattern,
- nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
- pat_len);
- i++;
- }
- }
- if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) {
- struct cfg80211_wowlan *ntrig;
- ntrig = kmemdup(&new_triggers, sizeof(new_triggers),
- GFP_KERNEL);
- if (!ntrig) {
- err = -ENOMEM;
- goto error;
- }
- cfg80211_rdev_free_wowlan(rdev);
- rdev->wowlan = ntrig;
- } else {
- no_triggers:
- cfg80211_rdev_free_wowlan(rdev);
- rdev->wowlan = NULL;
- }
- return 0;
- error:
- for (i = 0; i < new_triggers.n_patterns; i++)
- kfree(new_triggers.patterns[i].mask);
- kfree(new_triggers.patterns);
- return err;
- }
- static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct nlattr *tb[NUM_NL80211_REKEY_DATA];
- struct cfg80211_gtk_rekey_data rekey_data;
- int err;
- if (!info->attrs[NL80211_ATTR_REKEY_DATA])
- return -EINVAL;
- err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
- nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
- nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
- nl80211_rekey_policy);
- if (err)
- return err;
- if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
- !tb[NL80211_REKEY_DATA_KCK])
- return -EINVAL;
- if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
- return -ERANGE;
- if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
- return -ERANGE;
- if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
- return -ERANGE;
- memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
- NL80211_KEK_LEN);
- memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
- NL80211_KCK_LEN);
- memcpy(rekey_data.replay_ctr,
- nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
- NL80211_REPLAY_CTR_LEN);
- wdev_lock(wdev);
- if (!wdev->current_bss) {
- err = -ENOTCONN;
- goto out;
- }
- if (!rdev->ops->set_rekey_data) {
- err = -EOPNOTSUPP;
- goto out;
- }
- err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data);
- out:
- wdev_unlock(wdev);
- return err;
- }
- static int nl80211_register_unexpected_frame(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- if (wdev->iftype != NL80211_IFTYPE_AP &&
- wdev->iftype != NL80211_IFTYPE_P2P_GO)
- return -EINVAL;
- if (wdev->ap_unexpected_nlpid)
- return -EBUSY;
- wdev->ap_unexpected_nlpid = info->snd_pid;
- return 0;
- }
- static int nl80211_probe_client(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct sk_buff *msg;
- void *hdr;
- const u8 *addr;
- u64 cookie;
- int err;
- if (wdev->iftype != NL80211_IFTYPE_AP &&
- wdev->iftype != NL80211_IFTYPE_P2P_GO)
- return -EOPNOTSUPP;
- if (!info->attrs[NL80211_ATTR_MAC])
- return -EINVAL;
- if (!rdev->ops->probe_client)
- return -EOPNOTSUPP;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
- NL80211_CMD_PROBE_CLIENT);
- if (!hdr) {
- err = -ENOBUFS;
- goto free_msg;
- }
- addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
- err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie);
- if (err)
- goto free_msg;
- NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
- genlmsg_end(msg, hdr);
- return genlmsg_reply(msg, info);
- nla_put_failure:
- err = -ENOBUFS;
- free_msg:
- nlmsg_free(msg);
- return err;
- }
- static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
- return -EOPNOTSUPP;
- if (rdev->ap_beacons_nlpid)
- return -EBUSY;
- rdev->ap_beacons_nlpid = info->snd_pid;
- return 0;
- }
- static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct cfg80211_update_ft_ies_params ft_params;
- struct net_device *dev = info->user_ptr[1];
- if (!rdev->ops->update_ft_ies)
- return -EOPNOTSUPP;
- if (!info->attrs[NL80211_ATTR_MDID] ||
- !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
- return -EINVAL;
- memset(&ft_params, 0, sizeof(ft_params));
- ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
- ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
- ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
- return rdev->ops->update_ft_ies(&rdev->wiphy, dev, &ft_params);
- }
- static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct net_device *dev = info->user_ptr[1];
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- int i, err;
- u32 vid, subcmd;
- if (!rdev->wiphy.vendor_commands)
- return -EOPNOTSUPP;
- if (IS_ERR(wdev)) {
- err = PTR_ERR(wdev);
- if (err != -EINVAL)
- return err;
- wdev = NULL;
- } else if (wdev->wiphy != &rdev->wiphy) {
- return -EINVAL;
- }
- if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
- !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
- return -EINVAL;
- vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
- subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
- for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
- const struct wiphy_vendor_command *vcmd;
- void *data = NULL;
- int len = 0;
- vcmd = &rdev->wiphy.vendor_commands[i];
- if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
- continue;
- if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
- WIPHY_VENDOR_CMD_NEED_NETDEV)) {
- if (!wdev)
- return -EINVAL;
- if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
- !wdev->netdev)
- return -EINVAL;
- if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
- if (wdev->netdev &&
- !netif_running(wdev->netdev))
- return -ENETDOWN;
- }
- } else {
- wdev = NULL;
- }
- if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
- data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
- len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
- }
- rdev->cur_cmd_info = info;
- err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
- data, len);
- rdev->cur_cmd_info = NULL;
- return err;
- }
- return -EOPNOTSUPP;
- }
- struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
- enum nl80211_commands cmd,
- enum nl80211_attrs attr,
- int approxlen)
- {
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
- if (WARN_ON(!rdev->cur_cmd_info))
- return NULL;
- return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
- 0,
- 0,
- cmd, attr, NULL, GFP_KERNEL);
- }
- EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
- int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
- {
- struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
- void *hdr = ((void **)skb->cb)[1];
- struct nlattr *data = ((void **)skb->cb)[2];
- if (WARN_ON(!rdev->cur_cmd_info)) {
- kfree_skb(skb);
- return -EINVAL;
- }
- nla_nest_end(skb, data);
- genlmsg_end(skb, hdr);
- return genlmsg_reply(skb, rdev->cur_cmd_info);
- }
- EXPORT_SYMBOL(cfg80211_vendor_cmd_reply);
- static int nl80211_set_qos_map(struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev = info->user_ptr[0];
- struct cfg80211_qos_map *qos_map = NULL;
- struct net_device *dev = info->user_ptr[1];
- u8 *pos, len, num_des, des_len, des;
- int ret;
- if (!rdev->ops->set_qos_map)
- return -EOPNOTSUPP;
- if (info->attrs[NL80211_ATTR_QOS_MAP]) {
- pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
- len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
- if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
- len > IEEE80211_QOS_MAP_LEN_MAX)
- return -EINVAL;
- qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
- if (!qos_map)
- return -ENOMEM;
- num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
- if (num_des) {
- des_len = num_des *
- sizeof(struct cfg80211_dscp_exception);
- memcpy(qos_map->dscp_exception, pos, des_len);
- qos_map->num_des = num_des;
- for (des = 0; des < num_des; des++) {
- if (qos_map->dscp_exception[des].up > 7) {
- kfree(qos_map);
- return -EINVAL;
- }
- }
- pos += des_len;
- }
- memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
- }
- wdev_lock(dev->ieee80211_ptr);
- ret = nl80211_key_allowed(dev->ieee80211_ptr);
- if (!ret)
- ret = rdev->ops->set_qos_map(&rdev->wiphy, dev, qos_map);
- wdev_unlock(dev->ieee80211_ptr);
- kfree(qos_map);
- return ret;
- }
- #define NL80211_FLAG_NEED_WIPHY 0x01
- #define NL80211_FLAG_NEED_NETDEV 0x02
- #define NL80211_FLAG_NEED_RTNL 0x04
- #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
- #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
- NL80211_FLAG_CHECK_NETDEV_UP)
- static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
- struct genl_info *info)
- {
- struct cfg80211_registered_device *rdev;
- struct net_device *dev;
- int err;
- bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
- if (rtnl)
- rtnl_lock();
- if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
- rdev = cfg80211_get_dev_from_info(info);
- if (IS_ERR(rdev)) {
- if (rtnl)
- rtnl_unlock();
- return PTR_ERR(rdev);
- }
- info->user_ptr[0] = rdev;
- } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
- err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs,
- &rdev, &dev);
- if (err) {
- if (rtnl)
- rtnl_unlock();
- return err;
- }
- if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
- !netif_running(dev)) {
- cfg80211_unlock_rdev(rdev);
- dev_put(dev);
- if (rtnl)
- rtnl_unlock();
- return -ENETDOWN;
- }
- info->user_ptr[0] = rdev;
- info->user_ptr[1] = dev;
- }
- return 0;
- }
- static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
- struct genl_info *info)
- {
- if (info->user_ptr[0])
- cfg80211_unlock_rdev(info->user_ptr[0]);
- if (info->user_ptr[1])
- dev_put(info->user_ptr[1]);
- if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
- rtnl_unlock();
- }
- static struct genl_ops nl80211_ops[] = {
- {
- .cmd = NL80211_CMD_GET_WIPHY,
- .doit = nl80211_get_wiphy,
- .dumpit = nl80211_dump_wiphy,
- .policy = nl80211_policy,
- /* can be retrieved by unprivileged users */
- .internal_flags = NL80211_FLAG_NEED_WIPHY,
- },
- {
- .cmd = NL80211_CMD_SET_WIPHY,
- .doit = nl80211_set_wiphy,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_INTERFACE,
- .doit = nl80211_get_interface,
- .dumpit = nl80211_dump_interface,
- .policy = nl80211_policy,
- /* can be retrieved by unprivileged users */
- .internal_flags = NL80211_FLAG_NEED_NETDEV,
- },
- {
- .cmd = NL80211_CMD_SET_INTERFACE,
- .doit = nl80211_set_interface,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_NEW_INTERFACE,
- .doit = nl80211_new_interface,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_WIPHY |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DEL_INTERFACE,
- .doit = nl80211_del_interface,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_KEY,
- .doit = nl80211_get_key,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_KEY,
- .doit = nl80211_set_key,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_NEW_KEY,
- .doit = nl80211_new_key,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DEL_KEY,
- .doit = nl80211_del_key,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_BEACON,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .doit = nl80211_set_beacon,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_START_AP,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .doit = nl80211_start_ap,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_STOP_AP,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .doit = nl80211_stop_ap,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_STATION,
- .doit = nl80211_get_station,
- .dumpit = nl80211_dump_station,
- .policy = nl80211_policy,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_STATION,
- .doit = nl80211_set_station,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_NEW_STATION,
- .doit = nl80211_new_station,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DEL_STATION,
- .doit = nl80211_del_station,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_MPATH,
- .doit = nl80211_get_mpath,
- .dumpit = nl80211_dump_mpath,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_MPATH,
- .doit = nl80211_set_mpath,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_NEW_MPATH,
- .doit = nl80211_new_mpath,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DEL_MPATH,
- .doit = nl80211_del_mpath,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_BSS,
- .doit = nl80211_set_bss,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_REG,
- .doit = nl80211_get_reg,
- .policy = nl80211_policy,
- /* can be retrieved by unprivileged users */
- },
- {
- .cmd = NL80211_CMD_SET_REG,
- .doit = nl80211_set_reg,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- },
- {
- .cmd = NL80211_CMD_REQ_SET_REG,
- .doit = nl80211_req_set_reg,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- },
- {
- .cmd = NL80211_CMD_GET_MESH_CONFIG,
- .doit = nl80211_get_mesh_config,
- .policy = nl80211_policy,
- /* can be retrieved by unprivileged users */
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_MESH_CONFIG,
- .doit = nl80211_update_mesh_config,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_TRIGGER_SCAN,
- .doit = nl80211_trigger_scan,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_SCAN,
- .policy = nl80211_policy,
- .dumpit = nl80211_dump_scan,
- },
- {
- .cmd = NL80211_CMD_START_SCHED_SCAN,
- .doit = nl80211_start_sched_scan,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_STOP_SCHED_SCAN,
- .doit = nl80211_stop_sched_scan,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_AUTHENTICATE,
- .doit = nl80211_authenticate,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_ASSOCIATE,
- .doit = nl80211_associate,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DEAUTHENTICATE,
- .doit = nl80211_deauthenticate,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DISASSOCIATE,
- .doit = nl80211_disassociate,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_JOIN_IBSS,
- .doit = nl80211_join_ibss,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_LEAVE_IBSS,
- .doit = nl80211_leave_ibss,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- #ifdef CONFIG_NL80211_TESTMODE
- {
- .cmd = NL80211_CMD_TESTMODE,
- .doit = nl80211_testmode_do,
- .dumpit = nl80211_testmode_dump,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_WIPHY |
- NL80211_FLAG_NEED_RTNL,
- },
- #endif
- {
- .cmd = NL80211_CMD_CONNECT,
- .doit = nl80211_connect,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DISCONNECT,
- .doit = nl80211_disconnect,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_WIPHY_NETNS,
- .doit = nl80211_wiphy_netns,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_WIPHY |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_SURVEY,
- .policy = nl80211_policy,
- .dumpit = nl80211_dump_survey,
- },
- {
- .cmd = NL80211_CMD_SET_PMKSA,
- .doit = nl80211_setdel_pmksa,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_DEL_PMKSA,
- .doit = nl80211_setdel_pmksa,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_FLUSH_PMKSA,
- .doit = nl80211_flush_pmksa,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
- .doit = nl80211_remain_on_channel,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
- .doit = nl80211_cancel_remain_on_channel,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
- .doit = nl80211_set_tx_bitrate_mask,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_REGISTER_FRAME,
- .doit = nl80211_register_mgmt,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_FRAME,
- .doit = nl80211_tx_mgmt,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
- .doit = nl80211_tx_mgmt_cancel_wait,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_POWER_SAVE,
- .doit = nl80211_set_power_save,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_POWER_SAVE,
- .doit = nl80211_get_power_save,
- .policy = nl80211_policy,
- /* can be retrieved by unprivileged users */
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_CQM,
- .doit = nl80211_set_cqm,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_CHANNEL,
- .doit = nl80211_set_channel,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_WDS_PEER,
- .doit = nl80211_set_wds_peer,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_JOIN_MESH,
- .doit = nl80211_join_mesh,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_LEAVE_MESH,
- .doit = nl80211_leave_mesh,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_GET_WOWLAN,
- .doit = nl80211_get_wowlan,
- .policy = nl80211_policy,
- /* can be retrieved by unprivileged users */
- .internal_flags = NL80211_FLAG_NEED_WIPHY |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_WOWLAN,
- .doit = nl80211_set_wowlan,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_WIPHY |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
- .doit = nl80211_set_rekey_data,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_TDLS_MGMT,
- .doit = nl80211_tdls_mgmt,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_TDLS_OPER,
- .doit = nl80211_tdls_oper,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_UNEXPECTED_FRAME,
- .doit = nl80211_register_unexpected_frame,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_PROBE_CLIENT,
- .doit = nl80211_probe_client,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_REGISTER_BEACONS,
- .doit = nl80211_register_beacons,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_WIPHY |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_NOACK_MAP,
- .doit = nl80211_set_noack_map,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_MAC_ACL,
- .doit = nl80211_set_mac_acl,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_UPDATE_FT_IES,
- .doit = nl80211_update_ft_ies,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_VENDOR,
- .doit = nl80211_vendor_cmd,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV |
- NL80211_FLAG_NEED_RTNL,
- },
- {
- .cmd = NL80211_CMD_SET_QOS_MAP,
- .doit = nl80211_set_qos_map,
- .policy = nl80211_policy,
- .flags = GENL_ADMIN_PERM,
- .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
- NL80211_FLAG_NEED_RTNL,
- },
- };
- static struct genl_multicast_group nl80211_mlme_mcgrp = {
- .name = "mlme",
- };
- /* multicast groups */
- static struct genl_multicast_group nl80211_config_mcgrp = {
- .name = "config",
- };
- static struct genl_multicast_group nl80211_scan_mcgrp = {
- .name = "scan",
- };
- static struct genl_multicast_group nl80211_regulatory_mcgrp = {
- .name = "regulatory",
- };
- /* notification functions */
- void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return;
- if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_config_mcgrp.id, GFP_KERNEL);
- }
- static int nl80211_add_scan_req(struct sk_buff *msg,
- struct cfg80211_registered_device *rdev)
- {
- struct cfg80211_scan_request *req = rdev->scan_req;
- struct nlattr *nest;
- int i;
- ASSERT_RDEV_LOCK(rdev);
- if (WARN_ON(!req))
- return 0;
- nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
- if (!nest)
- goto nla_put_failure;
- for (i = 0; i < req->n_ssids; i++)
- NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid);
- nla_nest_end(msg, nest);
- nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
- if (!nest)
- goto nla_put_failure;
- for (i = 0; i < req->n_channels; i++)
- NLA_PUT_U32(msg, i, req->channels[i]->center_freq);
- nla_nest_end(msg, nest);
- if (req->ie)
- NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie);
- return 0;
- nla_put_failure:
- return -ENOBUFS;
- }
- static int nl80211_send_scan_msg(struct sk_buff *msg,
- struct cfg80211_registered_device *rdev,
- struct net_device *netdev,
- u32 pid, u32 seq, int flags,
- u32 cmd)
- {
- void *hdr;
- hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
- if (!hdr)
- return -1;
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- /* ignore errors and send incomplete event anyway */
- nl80211_add_scan_req(msg, rdev);
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- static int
- nl80211_send_sched_scan_msg(struct sk_buff *msg,
- struct cfg80211_registered_device *rdev,
- struct net_device *netdev,
- u32 pid, u32 seq, int flags, u32 cmd)
- {
- void *hdr;
- hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
- if (!hdr)
- return -1;
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- return genlmsg_end(msg, hdr);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- return -EMSGSIZE;
- }
- void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
- struct net_device *netdev)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
- if (!msg)
- return;
- if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
- NL80211_CMD_TRIGGER_SCAN) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_scan_mcgrp.id, GFP_KERNEL);
- }
- void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
- struct net_device *netdev)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return;
- if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
- NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_scan_mcgrp.id, GFP_KERNEL);
- }
- void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
- struct net_device *netdev)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return;
- if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0,
- NL80211_CMD_SCAN_ABORTED) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_scan_mcgrp.id, GFP_KERNEL);
- }
- void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
- struct net_device *netdev)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return;
- if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
- NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_scan_mcgrp.id, GFP_KERNEL);
- }
- void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u32 cmd)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
- if (!msg)
- return;
- if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_scan_mcgrp.id, GFP_KERNEL);
- }
- /*
- * This can happen on global regulatory changes or device specific settings
- * based on custom world regulatory domains.
- */
- void nl80211_send_reg_change_event(struct regulatory_request *request)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- /* Userspace can always count this one always being set */
- NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
- if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
- NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
- NL80211_REGDOM_TYPE_WORLD);
- else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
- NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
- NL80211_REGDOM_TYPE_CUSTOM_WORLD);
- else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
- request->intersect)
- NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
- NL80211_REGDOM_TYPE_INTERSECTION);
- else {
- NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
- NL80211_REGDOM_TYPE_COUNTRY);
- NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
- }
- if (wiphy_idx_valid(request->wiphy_idx))
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
- genlmsg_end(msg, hdr);
- rcu_read_lock();
- genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
- GFP_ATOMIC);
- rcu_read_unlock();
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
- struct net_device *netdev,
- const u8 *buf, size_t len,
- enum nl80211_commands cmd, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *buf,
- size_t len, gfp_t gfp)
- {
- nl80211_send_mlme_event(rdev, netdev, buf, len,
- NL80211_CMD_AUTHENTICATE, gfp);
- }
- void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *buf,
- size_t len, gfp_t gfp)
- {
- nl80211_send_mlme_event(rdev, netdev, buf, len,
- NL80211_CMD_ASSOCIATE, gfp);
- }
- void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *buf,
- size_t len, gfp_t gfp)
- {
- nl80211_send_mlme_event(rdev, netdev, buf, len,
- NL80211_CMD_DEAUTHENTICATE, gfp);
- }
- void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *buf,
- size_t len, gfp_t gfp)
- {
- nl80211_send_mlme_event(rdev, netdev, buf, len,
- NL80211_CMD_DISASSOCIATE, gfp);
- }
- void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *buf,
- size_t len, gfp_t gfp)
- {
- nl80211_send_mlme_event(rdev, netdev, buf, len,
- NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp);
- }
- void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *buf,
- size_t len, gfp_t gfp)
- {
- nl80211_send_mlme_event(rdev, netdev, buf, len,
- NL80211_CMD_UNPROT_DISASSOCIATE, gfp);
- }
- static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, int cmd,
- const u8 *addr, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *addr,
- gfp_t gfp)
- {
- nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
- addr, gfp);
- }
- void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *addr,
- gfp_t gfp)
- {
- nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
- addr, gfp);
- }
- void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *bssid,
- const u8 *req_ie, size_t req_ie_len,
- const u8 *resp_ie, size_t resp_ie_len,
- u16 status, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- if (bssid)
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
- NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status);
- if (req_ie)
- NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
- if (resp_ie)
- NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *bssid,
- const u8 *req_ie, size_t req_ie_len,
- const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
- if (req_ie)
- NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie);
- if (resp_ie)
- NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u16 reason,
- const u8 *ie, size_t ie_len, bool from_ap)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- if (from_ap && reason)
- NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason);
- if (from_ap)
- NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP);
- if (ie)
- NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, GFP_KERNEL);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *bssid,
- gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev,
- struct net_device *netdev,
- const u8 *macaddr, const u8* ie, u8 ie_len,
- gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr);
- if (ie_len && ie)
- NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *addr,
- enum nl80211_key_type key_type, int key_id,
- const u8 *tsc, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- if (addr)
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
- NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
- if (key_id != -1)
- NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
- if (tsc)
- NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
- struct ieee80211_channel *channel_before,
- struct ieee80211_channel *channel_after)
- {
- struct sk_buff *msg;
- void *hdr;
- struct nlattr *nl_freq;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- /*
- * Since we are applying the beacon hint to a wiphy we know its
- * wiphy_idx is valid
- */
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
- /* Before */
- nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
- if (!nl_freq)
- goto nla_put_failure;
- if (nl80211_msg_put_channel(msg, channel_before))
- goto nla_put_failure;
- nla_nest_end(msg, nl_freq);
- /* After */
- nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
- if (!nl_freq)
- goto nla_put_failure;
- if (nl80211_msg_put_channel(msg, channel_after))
- goto nla_put_failure;
- nla_nest_end(msg, nl_freq);
- genlmsg_end(msg, hdr);
- rcu_read_lock();
- genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
- GFP_ATOMIC);
- rcu_read_unlock();
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- static void nl80211_send_remain_on_chan_event(
- int cmd, struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u64 cookie,
- struct ieee80211_channel *chan,
- enum nl80211_channel_type channel_type,
- unsigned int duration, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type);
- NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
- if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL)
- NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u64 cookie,
- struct ieee80211_channel *chan,
- enum nl80211_channel_type channel_type,
- unsigned int duration, gfp_t gfp)
- {
- nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
- rdev, netdev, cookie, chan,
- channel_type, duration, gfp);
- }
- void nl80211_send_remain_on_channel_cancel(
- struct cfg80211_registered_device *rdev, struct net_device *netdev,
- u64 cookie, struct ieee80211_channel *chan,
- enum nl80211_channel_type channel_type, gfp_t gfp)
- {
- nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
- rdev, netdev, cookie, chan,
- channel_type, 0, gfp);
- }
- void nl80211_send_sta_event(struct cfg80211_registered_device *rdev,
- struct net_device *dev, const u8 *mac_addr,
- struct station_info *sinfo, gfp_t gfp)
- {
- struct sk_buff *msg;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- if (nl80211_send_station(msg, 0, 0, 0,
- rdev, dev, mac_addr, sinfo) < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- }
- void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev,
- struct net_device *dev, const u8 *mac_addr,
- gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
- const u8 *addr, gfp_t gfp)
- {
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
- struct sk_buff *msg;
- void *hdr;
- int err;
- u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid);
- if (!nlpid)
- return false;
- msg = nlmsg_new(100, gfp);
- if (!msg)
- return true;
- hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
- if (!hdr) {
- nlmsg_free(msg);
- return true;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
- err = genlmsg_end(msg, hdr);
- if (err < 0) {
- nlmsg_free(msg);
- return true;
- }
- genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
- return true;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- return true;
- }
- bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp)
- {
- return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
- addr, gfp);
- }
- bool nl80211_unexpected_4addr_frame(struct net_device *dev,
- const u8 *addr, gfp_t gfp)
- {
- return __nl80211_unexpected_frame(dev,
- NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
- addr, gfp);
- }
- int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u32 nlpid,
- int freq, int sig_dbm,
- const u8 *buf, size_t len, gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return -ENOMEM;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
- if (!hdr) {
- nlmsg_free(msg);
- return -ENOMEM;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
- if (sig_dbm)
- NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
- NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
- genlmsg_end(msg, hdr);
- return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- return -ENOBUFS;
- }
- void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, u64 cookie,
- const u8 *buf, size_t len, bool ack,
- gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
- NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
- if (ack)
- NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void
- nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev,
- struct net_device *netdev,
- enum nl80211_cqm_rssi_threshold_event rssi_event,
- gfp_t gfp)
- {
- struct sk_buff *msg;
- struct nlattr *pinfoattr;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
- if (!pinfoattr)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
- rssi_event);
- nla_nest_end(msg, pinfoattr);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *bssid,
- const u8 *replay_ctr, gfp_t gfp)
- {
- struct sk_buff *msg;
- struct nlattr *rekey_attr;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
- rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
- if (!rekey_attr)
- goto nla_put_failure;
- NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR,
- NL80211_REPLAY_CTR_LEN, replay_ctr);
- nla_nest_end(msg, rekey_attr);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, int index,
- const u8 *bssid, bool preauth, gfp_t gfp)
- {
- struct sk_buff *msg;
- struct nlattr *attr;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
- if (!attr)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index);
- NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid);
- if (preauth)
- NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH);
- nla_nest_end(msg, attr);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
- struct net_device *netdev,
- struct cfg80211_chan_def *chandef,
- gfp_t gfp)
- {
- struct sk_buff *msg;
- void *hdr;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
- goto nla_put_failure;
- if (nl80211_send_chandef(msg, chandef))
- goto nla_put_failure;
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void cfg80211_ch_switch_notify(struct net_device *dev,
- struct cfg80211_chan_def *chandef)
- {
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct wiphy *wiphy = wdev->wiphy;
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
- wdev_lock(wdev);
- if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
- wdev->iftype != NL80211_IFTYPE_P2P_GO))
- goto out;
- wdev->channel = chandef->chan;
- nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
- out:
- wdev_unlock(wdev);
- return;
- }
- EXPORT_SYMBOL(cfg80211_ch_switch_notify);
- void
- nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev,
- struct net_device *netdev, const u8 *peer,
- u32 num_packets, gfp_t gfp)
- {
- struct sk_buff *msg;
- struct nlattr *pinfoattr;
- void *hdr;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer);
- pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
- if (!pinfoattr)
- goto nla_put_failure;
- NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets);
- nla_nest_end(msg, pinfoattr);
- genlmsg_end(msg, hdr);
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
- u64 cookie, bool acked, gfp_t gfp)
- {
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
- struct sk_buff *msg;
- void *hdr;
- int err;
- msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
- NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
- NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
- if (acked)
- NLA_PUT_FLAG(msg, NL80211_ATTR_ACK);
- err = genlmsg_end(msg, hdr);
- if (err < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- EXPORT_SYMBOL(cfg80211_probe_status);
- void cfg80211_report_obss_beacon(struct wiphy *wiphy,
- const u8 *frame, size_t len,
- int freq, int sig_dbm, gfp_t gfp)
- {
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
- struct sk_buff *msg;
- void *hdr;
- u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid);
- if (!nlpid)
- return;
- msg = nlmsg_new(len + 100, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- if (freq)
- NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
- if (sig_dbm)
- NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm);
- NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame);
- genlmsg_end(msg, hdr);
- genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- EXPORT_SYMBOL(cfg80211_report_obss_beacon);
- void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
- enum nl80211_tdls_operation oper,
- u16 reason_code, gfp_t gfp)
- {
- struct wireless_dev *wdev = dev->ieee80211_ptr;
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
- struct sk_buff *msg;
- void *hdr;
- int err;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
- nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
- nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
- nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
- (reason_code > 0 &&
- nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
- goto nla_put_failure;
- err = genlmsg_end(msg, hdr);
- if (err < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, gfp);
- return;
- nla_put_failure:
- genlmsg_cancel(msg, hdr);
- nlmsg_free(msg);
- }
- EXPORT_SYMBOL(cfg80211_tdls_oper_request);
- static int nl80211_netlink_notify(struct notifier_block * nb,
- unsigned long state,
- void *_notify)
- {
- struct netlink_notify *notify = _notify;
- struct cfg80211_registered_device *rdev;
- struct wireless_dev *wdev;
- if (state != NETLINK_URELEASE)
- return NOTIFY_DONE;
- rcu_read_lock();
- list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
- list_for_each_entry_rcu(wdev, &rdev->netdev_list, list)
- cfg80211_mlme_unregister_socket(wdev, notify->pid);
- if (rdev->ap_beacons_nlpid == notify->pid)
- rdev->ap_beacons_nlpid = 0;
- }
- rcu_read_unlock();
- return NOTIFY_DONE;
- }
- static struct notifier_block nl80211_netlink_notifier = {
- .notifier_call = nl80211_netlink_notify,
- };
- void cfg80211_ft_event(struct net_device *netdev,
- struct cfg80211_ft_event_params *ft_event)
- {
- struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
- struct sk_buff *msg;
- void *hdr;
- int err;
- if (!ft_event->target_ap)
- return;
- msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
- if (!msg)
- return;
- hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
- if (!hdr) {
- nlmsg_free(msg);
- return;
- }
- nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
- nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
- nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
- if (ft_event->ies)
- nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
- if (ft_event->ric_ies)
- nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
- ft_event->ric_ies);
- err = genlmsg_end(msg, hdr);
- if (err < 0) {
- nlmsg_free(msg);
- return;
- }
- genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
- nl80211_mlme_mcgrp.id, GFP_KERNEL);
- }
- EXPORT_SYMBOL(cfg80211_ft_event);
- void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp)
- {
- struct wireless_dev *wdev = netdev->ieee80211_ptr;
- struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
- nl80211_send_mlme_event(rdev, netdev, NULL, 0,
- NL80211_CMD_STOP_AP, gfp);
- }
- EXPORT_SYMBOL(cfg80211_ap_stopped);
- /* initialisation/exit functions */
- int nl80211_init(void)
- {
- int err;
- err = genl_register_family_with_ops(&nl80211_fam,
- nl80211_ops, ARRAY_SIZE(nl80211_ops));
- if (err)
- return err;
- err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
- if (err)
- goto err_out;
- err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
- if (err)
- goto err_out;
- err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
- if (err)
- goto err_out;
- err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
- if (err)
- goto err_out;
- #ifdef CONFIG_NL80211_TESTMODE
- err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
- if (err)
- goto err_out;
- #endif
- err = genl_register_mc_group(&nl80211_fam, &nl80211_vendor_mcgrp);
- if (err)
- goto err_out;
- err = netlink_register_notifier(&nl80211_netlink_notifier);
- if (err)
- goto err_out;
- return 0;
- err_out:
- genl_unregister_family(&nl80211_fam);
- return err;
- }
- void nl80211_exit(void)
- {
- netlink_unregister_notifier(&nl80211_netlink_notifier);
- genl_unregister_family(&nl80211_fam);
- }
|