nl80211.c 340 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986
  1. /*
  2. * This is the new netlink-based wireless configuration interface.
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. */
  7. #include <linux/if.h>
  8. #include <linux/module.h>
  9. #include <linux/err.h>
  10. #include <linux/slab.h>
  11. #include <linux/list.h>
  12. #include <linux/if_ether.h>
  13. #include <linux/ieee80211.h>
  14. #include <linux/nl80211.h>
  15. #include <linux/rtnetlink.h>
  16. #include <linux/netlink.h>
  17. #include <linux/etherdevice.h>
  18. #include <net/net_namespace.h>
  19. #include <net/genetlink.h>
  20. #include <net/cfg80211.h>
  21. #include <net/sock.h>
  22. #include <net/inet_connection_sock.h>
  23. #include "core.h"
  24. #include "nl80211.h"
  25. #include "reg.h"
  26. #include "rdev-ops.h"
  27. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  28. struct genl_info *info,
  29. struct cfg80211_crypto_settings *settings,
  30. int cipher_limit);
  31. static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
  32. struct genl_info *info);
  33. static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
  34. struct genl_info *info);
  35. /* the netlink family */
  36. static struct genl_family nl80211_fam = {
  37. .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
  38. .name = NL80211_GENL_NAME, /* have users key off the name instead */
  39. .hdrsize = 0, /* no private header */
  40. .version = 1, /* no particular meaning now */
  41. .maxattr = NL80211_ATTR_MAX,
  42. .netnsok = true,
  43. .pre_doit = nl80211_pre_doit,
  44. .post_doit = nl80211_post_doit,
  45. };
  46. /* multicast groups */
  47. enum nl80211_multicast_groups {
  48. NL80211_MCGRP_CONFIG,
  49. NL80211_MCGRP_SCAN,
  50. NL80211_MCGRP_REGULATORY,
  51. NL80211_MCGRP_MLME,
  52. NL80211_MCGRP_VENDOR,
  53. NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
  54. };
  55. static const struct genl_multicast_group nl80211_mcgrps[] = {
  56. [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
  57. [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
  58. [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
  59. [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
  60. [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
  61. #ifdef CONFIG_NL80211_TESTMODE
  62. [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
  63. #endif
  64. };
  65. /* returns ERR_PTR values */
  66. static struct wireless_dev *
  67. __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
  68. {
  69. struct cfg80211_registered_device *rdev;
  70. struct wireless_dev *result = NULL;
  71. bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
  72. bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
  73. u64 wdev_id;
  74. int wiphy_idx = -1;
  75. int ifidx = -1;
  76. ASSERT_RTNL();
  77. if (!have_ifidx && !have_wdev_id)
  78. return ERR_PTR(-EINVAL);
  79. if (have_ifidx)
  80. ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
  81. if (have_wdev_id) {
  82. wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
  83. wiphy_idx = wdev_id >> 32;
  84. }
  85. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  86. struct wireless_dev *wdev;
  87. if (wiphy_net(&rdev->wiphy) != netns)
  88. continue;
  89. if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
  90. continue;
  91. list_for_each_entry(wdev, &rdev->wdev_list, list) {
  92. if (have_ifidx && wdev->netdev &&
  93. wdev->netdev->ifindex == ifidx) {
  94. result = wdev;
  95. break;
  96. }
  97. if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
  98. result = wdev;
  99. break;
  100. }
  101. }
  102. if (result)
  103. break;
  104. }
  105. if (result)
  106. return result;
  107. return ERR_PTR(-ENODEV);
  108. }
  109. static struct cfg80211_registered_device *
  110. __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
  111. {
  112. struct cfg80211_registered_device *rdev = NULL, *tmp;
  113. struct net_device *netdev;
  114. ASSERT_RTNL();
  115. if (!attrs[NL80211_ATTR_WIPHY] &&
  116. !attrs[NL80211_ATTR_IFINDEX] &&
  117. !attrs[NL80211_ATTR_WDEV])
  118. return ERR_PTR(-EINVAL);
  119. if (attrs[NL80211_ATTR_WIPHY])
  120. rdev = cfg80211_rdev_by_wiphy_idx(
  121. nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
  122. if (attrs[NL80211_ATTR_WDEV]) {
  123. u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
  124. struct wireless_dev *wdev;
  125. bool found = false;
  126. tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
  127. if (tmp) {
  128. /* make sure wdev exists */
  129. list_for_each_entry(wdev, &tmp->wdev_list, list) {
  130. if (wdev->identifier != (u32)wdev_id)
  131. continue;
  132. found = true;
  133. break;
  134. }
  135. if (!found)
  136. tmp = NULL;
  137. if (rdev && tmp != rdev)
  138. return ERR_PTR(-EINVAL);
  139. rdev = tmp;
  140. }
  141. }
  142. if (attrs[NL80211_ATTR_IFINDEX]) {
  143. int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
  144. netdev = __dev_get_by_index(netns, ifindex);
  145. if (netdev) {
  146. if (netdev->ieee80211_ptr)
  147. tmp = wiphy_to_rdev(
  148. netdev->ieee80211_ptr->wiphy);
  149. else
  150. tmp = NULL;
  151. /* not wireless device -- return error */
  152. if (!tmp)
  153. return ERR_PTR(-EINVAL);
  154. /* mismatch -- return error */
  155. if (rdev && tmp != rdev)
  156. return ERR_PTR(-EINVAL);
  157. rdev = tmp;
  158. }
  159. }
  160. if (!rdev)
  161. return ERR_PTR(-ENODEV);
  162. if (netns != wiphy_net(&rdev->wiphy))
  163. return ERR_PTR(-ENODEV);
  164. return rdev;
  165. }
  166. /*
  167. * This function returns a pointer to the driver
  168. * that the genl_info item that is passed refers to.
  169. *
  170. * The result of this can be a PTR_ERR and hence must
  171. * be checked with IS_ERR() for errors.
  172. */
  173. static struct cfg80211_registered_device *
  174. cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
  175. {
  176. return __cfg80211_rdev_from_attrs(netns, info->attrs);
  177. }
  178. /* policy for the attributes */
  179. static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
  180. [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
  181. [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
  182. .len = 20-1 },
  183. [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
  184. [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
  185. [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
  186. [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
  187. [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
  188. [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
  189. [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
  190. [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
  191. [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
  192. [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
  193. [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
  194. [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
  195. [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
  196. [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
  197. [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
  198. [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
  199. [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
  200. [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
  201. [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
  202. .len = WLAN_MAX_KEY_LEN },
  203. [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
  204. [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
  205. [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
  206. [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  207. [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
  208. [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
  209. [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
  210. [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
  211. .len = IEEE80211_MAX_DATA_LEN },
  212. [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
  213. .len = IEEE80211_MAX_DATA_LEN },
  214. [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
  215. [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
  216. [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
  217. [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
  218. .len = NL80211_MAX_SUPP_RATES },
  219. [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
  220. [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
  221. [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
  222. [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
  223. .len = IEEE80211_MAX_MESH_ID_LEN },
  224. [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
  225. [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
  226. [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
  227. [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
  228. [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
  229. [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
  230. [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
  231. .len = NL80211_MAX_SUPP_RATES },
  232. [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
  233. [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
  234. [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
  235. [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
  236. [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
  237. [NL80211_ATTR_IE] = { .type = NLA_BINARY,
  238. .len = IEEE80211_MAX_DATA_LEN },
  239. [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
  240. [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
  241. [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
  242. .len = IEEE80211_MAX_SSID_LEN },
  243. [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
  244. [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
  245. [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
  246. [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
  247. [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
  248. [NL80211_ATTR_STA_FLAGS2] = {
  249. .len = sizeof(struct nl80211_sta_flag_update),
  250. },
  251. [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
  252. [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
  253. [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
  254. [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
  255. [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
  256. [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
  257. [NL80211_ATTR_PID] = { .type = NLA_U32 },
  258. [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
  259. [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
  260. .len = WLAN_PMKID_LEN },
  261. [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
  262. [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
  263. [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
  264. [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
  265. .len = IEEE80211_MAX_DATA_LEN },
  266. [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
  267. [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
  268. [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
  269. [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
  270. [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
  271. [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
  272. [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
  273. [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
  274. [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
  275. [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
  276. [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
  277. [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
  278. [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  279. [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
  280. [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
  281. [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
  282. [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
  283. [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
  284. [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
  285. [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
  286. .len = IEEE80211_MAX_DATA_LEN },
  287. [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
  288. .len = IEEE80211_MAX_DATA_LEN },
  289. [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
  290. [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
  291. [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
  292. [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
  293. [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
  294. [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
  295. [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
  296. [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
  297. [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
  298. [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
  299. [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
  300. .len = IEEE80211_MAX_DATA_LEN },
  301. [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
  302. [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
  303. [NL80211_ATTR_HT_CAPABILITY_MASK] = {
  304. .len = NL80211_HT_CAPABILITY_LEN
  305. },
  306. [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
  307. [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
  308. [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
  309. [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
  310. [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
  311. [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
  312. [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
  313. [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
  314. [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
  315. [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
  316. [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
  317. [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
  318. [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
  319. [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
  320. [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
  321. [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
  322. [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
  323. .len = NL80211_VHT_CAPABILITY_LEN,
  324. },
  325. [NL80211_ATTR_MDID] = { .type = NLA_U16 },
  326. [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
  327. .len = IEEE80211_MAX_DATA_LEN },
  328. [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
  329. [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
  330. [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
  331. [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
  332. [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
  333. [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
  334. [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
  335. [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
  336. [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
  337. [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
  338. [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
  339. [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
  340. [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
  341. [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
  342. .len = IEEE80211_QOS_MAP_LEN_MAX },
  343. [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
  344. [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
  345. [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
  346. [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
  347. [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
  348. [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
  349. [NL80211_ATTR_TSID] = { .type = NLA_U8 },
  350. [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
  351. [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
  352. [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
  353. [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
  354. [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
  355. [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
  356. [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
  357. [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
  358. };
  359. /* policy for the key attributes */
  360. static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
  361. [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
  362. [NL80211_KEY_IDX] = { .type = NLA_U8 },
  363. [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
  364. [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  365. [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
  366. [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
  367. [NL80211_KEY_TYPE] = { .type = NLA_U32 },
  368. [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  369. };
  370. /* policy for the key default flags */
  371. static const struct nla_policy
  372. nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
  373. [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
  374. [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
  375. };
  376. /* policy for WoWLAN attributes */
  377. static const struct nla_policy
  378. nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
  379. [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
  380. [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
  381. [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
  382. [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
  383. [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
  384. [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
  385. [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
  386. [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
  387. [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
  388. [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
  389. };
  390. static const struct nla_policy
  391. nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
  392. [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
  393. [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
  394. [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
  395. [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
  396. [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
  397. [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
  398. [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
  399. .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
  400. },
  401. [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
  402. .len = sizeof(struct nl80211_wowlan_tcp_data_token)
  403. },
  404. [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
  405. [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
  406. [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
  407. };
  408. /* policy for coalesce rule attributes */
  409. static const struct nla_policy
  410. nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
  411. [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
  412. [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
  413. [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
  414. };
  415. /* policy for GTK rekey offload attributes */
  416. static const struct nla_policy
  417. nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
  418. [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
  419. [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
  420. [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
  421. };
  422. static const struct nla_policy
  423. nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
  424. [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
  425. .len = IEEE80211_MAX_SSID_LEN },
  426. [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
  427. };
  428. static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
  429. struct netlink_callback *cb,
  430. struct cfg80211_registered_device **rdev,
  431. struct wireless_dev **wdev)
  432. {
  433. int err;
  434. rtnl_lock();
  435. if (!cb->args[0]) {
  436. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  437. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  438. nl80211_policy);
  439. if (err)
  440. goto out_unlock;
  441. *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
  442. nl80211_fam.attrbuf);
  443. if (IS_ERR(*wdev)) {
  444. err = PTR_ERR(*wdev);
  445. goto out_unlock;
  446. }
  447. *rdev = wiphy_to_rdev((*wdev)->wiphy);
  448. /* 0 is the first index - add 1 to parse only once */
  449. cb->args[0] = (*rdev)->wiphy_idx + 1;
  450. cb->args[1] = (*wdev)->identifier;
  451. } else {
  452. /* subtract the 1 again here */
  453. struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
  454. struct wireless_dev *tmp;
  455. if (!wiphy) {
  456. err = -ENODEV;
  457. goto out_unlock;
  458. }
  459. *rdev = wiphy_to_rdev(wiphy);
  460. *wdev = NULL;
  461. list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
  462. if (tmp->identifier == cb->args[1]) {
  463. *wdev = tmp;
  464. break;
  465. }
  466. }
  467. if (!*wdev) {
  468. err = -ENODEV;
  469. goto out_unlock;
  470. }
  471. }
  472. return 0;
  473. out_unlock:
  474. rtnl_unlock();
  475. return err;
  476. }
  477. static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
  478. {
  479. rtnl_unlock();
  480. }
  481. /* IE validation */
  482. static bool is_valid_ie_attr(const struct nlattr *attr)
  483. {
  484. const u8 *pos;
  485. int len;
  486. if (!attr)
  487. return true;
  488. pos = nla_data(attr);
  489. len = nla_len(attr);
  490. while (len) {
  491. u8 elemlen;
  492. if (len < 2)
  493. return false;
  494. len -= 2;
  495. elemlen = pos[1];
  496. if (elemlen > len)
  497. return false;
  498. len -= elemlen;
  499. pos += 2 + elemlen;
  500. }
  501. return true;
  502. }
  503. /* message building helper */
  504. static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
  505. int flags, u8 cmd)
  506. {
  507. /* since there is no private header just add the generic one */
  508. return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
  509. }
  510. static int nl80211_msg_put_channel(struct sk_buff *msg,
  511. struct ieee80211_channel *chan,
  512. bool large)
  513. {
  514. /* Some channels must be completely excluded from the
  515. * list to protect old user-space tools from breaking
  516. */
  517. if (!large && chan->flags &
  518. (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
  519. return 0;
  520. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
  521. chan->center_freq))
  522. goto nla_put_failure;
  523. if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
  524. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
  525. goto nla_put_failure;
  526. if (chan->flags & IEEE80211_CHAN_NO_IR) {
  527. if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
  528. goto nla_put_failure;
  529. if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
  530. goto nla_put_failure;
  531. }
  532. if (chan->flags & IEEE80211_CHAN_RADAR) {
  533. if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
  534. goto nla_put_failure;
  535. if (large) {
  536. u32 time;
  537. time = elapsed_jiffies_msecs(chan->dfs_state_entered);
  538. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
  539. chan->dfs_state))
  540. goto nla_put_failure;
  541. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
  542. time))
  543. goto nla_put_failure;
  544. if (nla_put_u32(msg,
  545. NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
  546. chan->dfs_cac_ms))
  547. goto nla_put_failure;
  548. }
  549. }
  550. if (large) {
  551. if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
  552. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
  553. goto nla_put_failure;
  554. if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
  555. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
  556. goto nla_put_failure;
  557. if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
  558. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
  559. goto nla_put_failure;
  560. if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
  561. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
  562. goto nla_put_failure;
  563. if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
  564. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
  565. goto nla_put_failure;
  566. if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
  567. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
  568. goto nla_put_failure;
  569. if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
  570. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
  571. goto nla_put_failure;
  572. if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
  573. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
  574. goto nla_put_failure;
  575. }
  576. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
  577. DBM_TO_MBM(chan->max_power)))
  578. goto nla_put_failure;
  579. return 0;
  580. nla_put_failure:
  581. return -ENOBUFS;
  582. }
  583. /* netlink command implementations */
  584. struct key_parse {
  585. struct key_params p;
  586. int idx;
  587. int type;
  588. bool def, defmgmt;
  589. bool def_uni, def_multi;
  590. };
  591. static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
  592. {
  593. struct nlattr *tb[NL80211_KEY_MAX + 1];
  594. int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
  595. nl80211_key_policy);
  596. if (err)
  597. return err;
  598. k->def = !!tb[NL80211_KEY_DEFAULT];
  599. k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
  600. if (k->def) {
  601. k->def_uni = true;
  602. k->def_multi = true;
  603. }
  604. if (k->defmgmt)
  605. k->def_multi = true;
  606. if (tb[NL80211_KEY_IDX])
  607. k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
  608. if (tb[NL80211_KEY_DATA]) {
  609. k->p.key = nla_data(tb[NL80211_KEY_DATA]);
  610. k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
  611. }
  612. if (tb[NL80211_KEY_SEQ]) {
  613. k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
  614. k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
  615. }
  616. if (tb[NL80211_KEY_CIPHER])
  617. k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
  618. if (tb[NL80211_KEY_TYPE]) {
  619. k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
  620. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  621. return -EINVAL;
  622. }
  623. if (tb[NL80211_KEY_DEFAULT_TYPES]) {
  624. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  625. err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  626. tb[NL80211_KEY_DEFAULT_TYPES],
  627. nl80211_key_default_policy);
  628. if (err)
  629. return err;
  630. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  631. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  632. }
  633. return 0;
  634. }
  635. static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
  636. {
  637. if (info->attrs[NL80211_ATTR_KEY_DATA]) {
  638. k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
  639. k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
  640. }
  641. if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
  642. k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
  643. k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
  644. }
  645. if (info->attrs[NL80211_ATTR_KEY_IDX])
  646. k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  647. if (info->attrs[NL80211_ATTR_KEY_CIPHER])
  648. k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
  649. k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
  650. k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
  651. if (k->def) {
  652. k->def_uni = true;
  653. k->def_multi = true;
  654. }
  655. if (k->defmgmt)
  656. k->def_multi = true;
  657. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  658. k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  659. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  660. return -EINVAL;
  661. }
  662. if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
  663. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  664. int err = nla_parse_nested(
  665. kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  666. info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
  667. nl80211_key_default_policy);
  668. if (err)
  669. return err;
  670. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  671. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  672. }
  673. return 0;
  674. }
  675. static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
  676. {
  677. int err;
  678. memset(k, 0, sizeof(*k));
  679. k->idx = -1;
  680. k->type = -1;
  681. if (info->attrs[NL80211_ATTR_KEY])
  682. err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
  683. else
  684. err = nl80211_parse_key_old(info, k);
  685. if (err)
  686. return err;
  687. if (k->def && k->defmgmt)
  688. return -EINVAL;
  689. if (k->defmgmt) {
  690. if (k->def_uni || !k->def_multi)
  691. return -EINVAL;
  692. }
  693. if (k->idx != -1) {
  694. if (k->defmgmt) {
  695. if (k->idx < 4 || k->idx > 5)
  696. return -EINVAL;
  697. } else if (k->def) {
  698. if (k->idx < 0 || k->idx > 3)
  699. return -EINVAL;
  700. } else {
  701. if (k->idx < 0 || k->idx > 5)
  702. return -EINVAL;
  703. }
  704. }
  705. return 0;
  706. }
  707. static struct cfg80211_cached_keys *
  708. nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
  709. struct nlattr *keys, bool *no_ht)
  710. {
  711. struct key_parse parse;
  712. struct nlattr *key;
  713. struct cfg80211_cached_keys *result;
  714. int rem, err, def = 0;
  715. result = kzalloc(sizeof(*result), GFP_KERNEL);
  716. if (!result)
  717. return ERR_PTR(-ENOMEM);
  718. result->def = -1;
  719. result->defmgmt = -1;
  720. nla_for_each_nested(key, keys, rem) {
  721. memset(&parse, 0, sizeof(parse));
  722. parse.idx = -1;
  723. err = nl80211_parse_key_new(key, &parse);
  724. if (err)
  725. goto error;
  726. err = -EINVAL;
  727. if (!parse.p.key)
  728. goto error;
  729. if (parse.idx < 0 || parse.idx > 4)
  730. goto error;
  731. if (parse.def) {
  732. if (def)
  733. goto error;
  734. def = 1;
  735. result->def = parse.idx;
  736. if (!parse.def_uni || !parse.def_multi)
  737. goto error;
  738. } else if (parse.defmgmt)
  739. goto error;
  740. err = cfg80211_validate_key_settings(rdev, &parse.p,
  741. parse.idx, false, NULL);
  742. if (err)
  743. goto error;
  744. result->params[parse.idx].cipher = parse.p.cipher;
  745. result->params[parse.idx].key_len = parse.p.key_len;
  746. result->params[parse.idx].key = result->data[parse.idx];
  747. memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
  748. if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
  749. parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
  750. if (no_ht)
  751. *no_ht = true;
  752. }
  753. }
  754. return result;
  755. error:
  756. kfree(result);
  757. return ERR_PTR(err);
  758. }
  759. static int nl80211_key_allowed(struct wireless_dev *wdev)
  760. {
  761. ASSERT_WDEV_LOCK(wdev);
  762. switch (wdev->iftype) {
  763. case NL80211_IFTYPE_AP:
  764. case NL80211_IFTYPE_AP_VLAN:
  765. case NL80211_IFTYPE_P2P_GO:
  766. case NL80211_IFTYPE_MESH_POINT:
  767. break;
  768. case NL80211_IFTYPE_ADHOC:
  769. case NL80211_IFTYPE_STATION:
  770. case NL80211_IFTYPE_P2P_CLIENT:
  771. if (!wdev->current_bss)
  772. return -ENOLINK;
  773. break;
  774. case NL80211_IFTYPE_UNSPECIFIED:
  775. case NL80211_IFTYPE_OCB:
  776. case NL80211_IFTYPE_MONITOR:
  777. case NL80211_IFTYPE_P2P_DEVICE:
  778. case NL80211_IFTYPE_WDS:
  779. case NUM_NL80211_IFTYPES:
  780. return -EINVAL;
  781. }
  782. return 0;
  783. }
  784. static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
  785. struct nlattr *tb)
  786. {
  787. struct ieee80211_channel *chan;
  788. if (tb == NULL)
  789. return NULL;
  790. chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
  791. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  792. return NULL;
  793. return chan;
  794. }
  795. static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
  796. {
  797. struct nlattr *nl_modes = nla_nest_start(msg, attr);
  798. int i;
  799. if (!nl_modes)
  800. goto nla_put_failure;
  801. i = 0;
  802. while (ifmodes) {
  803. if ((ifmodes & 1) && nla_put_flag(msg, i))
  804. goto nla_put_failure;
  805. ifmodes >>= 1;
  806. i++;
  807. }
  808. nla_nest_end(msg, nl_modes);
  809. return 0;
  810. nla_put_failure:
  811. return -ENOBUFS;
  812. }
  813. static int nl80211_put_iface_combinations(struct wiphy *wiphy,
  814. struct sk_buff *msg,
  815. bool large)
  816. {
  817. struct nlattr *nl_combis;
  818. int i, j;
  819. nl_combis = nla_nest_start(msg,
  820. NL80211_ATTR_INTERFACE_COMBINATIONS);
  821. if (!nl_combis)
  822. goto nla_put_failure;
  823. for (i = 0; i < wiphy->n_iface_combinations; i++) {
  824. const struct ieee80211_iface_combination *c;
  825. struct nlattr *nl_combi, *nl_limits;
  826. c = &wiphy->iface_combinations[i];
  827. nl_combi = nla_nest_start(msg, i + 1);
  828. if (!nl_combi)
  829. goto nla_put_failure;
  830. nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
  831. if (!nl_limits)
  832. goto nla_put_failure;
  833. for (j = 0; j < c->n_limits; j++) {
  834. struct nlattr *nl_limit;
  835. nl_limit = nla_nest_start(msg, j + 1);
  836. if (!nl_limit)
  837. goto nla_put_failure;
  838. if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
  839. c->limits[j].max))
  840. goto nla_put_failure;
  841. if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
  842. c->limits[j].types))
  843. goto nla_put_failure;
  844. nla_nest_end(msg, nl_limit);
  845. }
  846. nla_nest_end(msg, nl_limits);
  847. if (c->beacon_int_infra_match &&
  848. nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
  849. goto nla_put_failure;
  850. if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
  851. c->num_different_channels) ||
  852. nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
  853. c->max_interfaces))
  854. goto nla_put_failure;
  855. if (large &&
  856. (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
  857. c->radar_detect_widths) ||
  858. nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
  859. c->radar_detect_regions)))
  860. goto nla_put_failure;
  861. nla_nest_end(msg, nl_combi);
  862. }
  863. nla_nest_end(msg, nl_combis);
  864. return 0;
  865. nla_put_failure:
  866. return -ENOBUFS;
  867. }
  868. #ifdef CONFIG_PM
  869. static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
  870. struct sk_buff *msg)
  871. {
  872. const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
  873. struct nlattr *nl_tcp;
  874. if (!tcp)
  875. return 0;
  876. nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
  877. if (!nl_tcp)
  878. return -ENOBUFS;
  879. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  880. tcp->data_payload_max))
  881. return -ENOBUFS;
  882. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  883. tcp->data_payload_max))
  884. return -ENOBUFS;
  885. if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
  886. return -ENOBUFS;
  887. if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  888. sizeof(*tcp->tok), tcp->tok))
  889. return -ENOBUFS;
  890. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
  891. tcp->data_interval_max))
  892. return -ENOBUFS;
  893. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  894. tcp->wake_payload_max))
  895. return -ENOBUFS;
  896. nla_nest_end(msg, nl_tcp);
  897. return 0;
  898. }
  899. static int nl80211_send_wowlan(struct sk_buff *msg,
  900. struct cfg80211_registered_device *rdev,
  901. bool large)
  902. {
  903. struct nlattr *nl_wowlan;
  904. if (!rdev->wiphy.wowlan)
  905. return 0;
  906. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
  907. if (!nl_wowlan)
  908. return -ENOBUFS;
  909. if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
  910. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  911. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
  912. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  913. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
  914. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  915. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
  916. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
  917. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
  918. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  919. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
  920. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  921. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
  922. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  923. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
  924. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
  925. return -ENOBUFS;
  926. if (rdev->wiphy.wowlan->n_patterns) {
  927. struct nl80211_pattern_support pat = {
  928. .max_patterns = rdev->wiphy.wowlan->n_patterns,
  929. .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
  930. .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
  931. .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
  932. };
  933. if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  934. sizeof(pat), &pat))
  935. return -ENOBUFS;
  936. }
  937. if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
  938. nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
  939. rdev->wiphy.wowlan->max_nd_match_sets))
  940. return -ENOBUFS;
  941. if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
  942. return -ENOBUFS;
  943. nla_nest_end(msg, nl_wowlan);
  944. return 0;
  945. }
  946. #endif
  947. static int nl80211_send_coalesce(struct sk_buff *msg,
  948. struct cfg80211_registered_device *rdev)
  949. {
  950. struct nl80211_coalesce_rule_support rule;
  951. if (!rdev->wiphy.coalesce)
  952. return 0;
  953. rule.max_rules = rdev->wiphy.coalesce->n_rules;
  954. rule.max_delay = rdev->wiphy.coalesce->max_delay;
  955. rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
  956. rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
  957. rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
  958. rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
  959. if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
  960. return -ENOBUFS;
  961. return 0;
  962. }
  963. static int nl80211_send_band_rateinfo(struct sk_buff *msg,
  964. struct ieee80211_supported_band *sband)
  965. {
  966. struct nlattr *nl_rates, *nl_rate;
  967. struct ieee80211_rate *rate;
  968. int i;
  969. /* add HT info */
  970. if (sband->ht_cap.ht_supported &&
  971. (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
  972. sizeof(sband->ht_cap.mcs),
  973. &sband->ht_cap.mcs) ||
  974. nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
  975. sband->ht_cap.cap) ||
  976. nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
  977. sband->ht_cap.ampdu_factor) ||
  978. nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
  979. sband->ht_cap.ampdu_density)))
  980. return -ENOBUFS;
  981. /* add VHT info */
  982. if (sband->vht_cap.vht_supported &&
  983. (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
  984. sizeof(sband->vht_cap.vht_mcs),
  985. &sband->vht_cap.vht_mcs) ||
  986. nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
  987. sband->vht_cap.cap)))
  988. return -ENOBUFS;
  989. /* add bitrates */
  990. nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
  991. if (!nl_rates)
  992. return -ENOBUFS;
  993. for (i = 0; i < sband->n_bitrates; i++) {
  994. nl_rate = nla_nest_start(msg, i);
  995. if (!nl_rate)
  996. return -ENOBUFS;
  997. rate = &sband->bitrates[i];
  998. if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
  999. rate->bitrate))
  1000. return -ENOBUFS;
  1001. if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
  1002. nla_put_flag(msg,
  1003. NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
  1004. return -ENOBUFS;
  1005. nla_nest_end(msg, nl_rate);
  1006. }
  1007. nla_nest_end(msg, nl_rates);
  1008. return 0;
  1009. }
  1010. static int
  1011. nl80211_send_mgmt_stypes(struct sk_buff *msg,
  1012. const struct ieee80211_txrx_stypes *mgmt_stypes)
  1013. {
  1014. u16 stypes;
  1015. struct nlattr *nl_ftypes, *nl_ifs;
  1016. enum nl80211_iftype ift;
  1017. int i;
  1018. if (!mgmt_stypes)
  1019. return 0;
  1020. nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
  1021. if (!nl_ifs)
  1022. return -ENOBUFS;
  1023. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  1024. nl_ftypes = nla_nest_start(msg, ift);
  1025. if (!nl_ftypes)
  1026. return -ENOBUFS;
  1027. i = 0;
  1028. stypes = mgmt_stypes[ift].tx;
  1029. while (stypes) {
  1030. if ((stypes & 1) &&
  1031. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
  1032. (i << 4) | IEEE80211_FTYPE_MGMT))
  1033. return -ENOBUFS;
  1034. stypes >>= 1;
  1035. i++;
  1036. }
  1037. nla_nest_end(msg, nl_ftypes);
  1038. }
  1039. nla_nest_end(msg, nl_ifs);
  1040. nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
  1041. if (!nl_ifs)
  1042. return -ENOBUFS;
  1043. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  1044. nl_ftypes = nla_nest_start(msg, ift);
  1045. if (!nl_ftypes)
  1046. return -ENOBUFS;
  1047. i = 0;
  1048. stypes = mgmt_stypes[ift].rx;
  1049. while (stypes) {
  1050. if ((stypes & 1) &&
  1051. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
  1052. (i << 4) | IEEE80211_FTYPE_MGMT))
  1053. return -ENOBUFS;
  1054. stypes >>= 1;
  1055. i++;
  1056. }
  1057. nla_nest_end(msg, nl_ftypes);
  1058. }
  1059. nla_nest_end(msg, nl_ifs);
  1060. return 0;
  1061. }
  1062. struct nl80211_dump_wiphy_state {
  1063. s64 filter_wiphy;
  1064. long start;
  1065. long split_start, band_start, chan_start;
  1066. bool split;
  1067. };
  1068. static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
  1069. enum nl80211_commands cmd,
  1070. struct sk_buff *msg, u32 portid, u32 seq,
  1071. int flags, struct nl80211_dump_wiphy_state *state)
  1072. {
  1073. void *hdr;
  1074. struct nlattr *nl_bands, *nl_band;
  1075. struct nlattr *nl_freqs, *nl_freq;
  1076. struct nlattr *nl_cmds;
  1077. enum ieee80211_band band;
  1078. struct ieee80211_channel *chan;
  1079. int i;
  1080. const struct ieee80211_txrx_stypes *mgmt_stypes =
  1081. rdev->wiphy.mgmt_stypes;
  1082. u32 features;
  1083. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  1084. if (!hdr)
  1085. return -ENOBUFS;
  1086. if (WARN_ON(!state))
  1087. return -EINVAL;
  1088. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  1089. nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
  1090. wiphy_name(&rdev->wiphy)) ||
  1091. nla_put_u32(msg, NL80211_ATTR_GENERATION,
  1092. cfg80211_rdev_list_generation))
  1093. goto nla_put_failure;
  1094. if (cmd != NL80211_CMD_NEW_WIPHY)
  1095. goto finish;
  1096. switch (state->split_start) {
  1097. case 0:
  1098. if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
  1099. rdev->wiphy.retry_short) ||
  1100. nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
  1101. rdev->wiphy.retry_long) ||
  1102. nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
  1103. rdev->wiphy.frag_threshold) ||
  1104. nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
  1105. rdev->wiphy.rts_threshold) ||
  1106. nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
  1107. rdev->wiphy.coverage_class) ||
  1108. nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
  1109. rdev->wiphy.max_scan_ssids) ||
  1110. nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
  1111. rdev->wiphy.max_sched_scan_ssids) ||
  1112. nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
  1113. rdev->wiphy.max_scan_ie_len) ||
  1114. nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
  1115. rdev->wiphy.max_sched_scan_ie_len) ||
  1116. nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
  1117. rdev->wiphy.max_match_sets))
  1118. goto nla_put_failure;
  1119. if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
  1120. nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
  1121. goto nla_put_failure;
  1122. if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
  1123. nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
  1124. goto nla_put_failure;
  1125. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
  1126. nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
  1127. goto nla_put_failure;
  1128. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
  1129. nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
  1130. goto nla_put_failure;
  1131. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  1132. nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
  1133. goto nla_put_failure;
  1134. if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
  1135. nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
  1136. goto nla_put_failure;
  1137. state->split_start++;
  1138. if (state->split)
  1139. break;
  1140. case 1:
  1141. if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
  1142. sizeof(u32) * rdev->wiphy.n_cipher_suites,
  1143. rdev->wiphy.cipher_suites))
  1144. goto nla_put_failure;
  1145. if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
  1146. rdev->wiphy.max_num_pmkids))
  1147. goto nla_put_failure;
  1148. if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  1149. nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
  1150. goto nla_put_failure;
  1151. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
  1152. rdev->wiphy.available_antennas_tx) ||
  1153. nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
  1154. rdev->wiphy.available_antennas_rx))
  1155. goto nla_put_failure;
  1156. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
  1157. nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
  1158. rdev->wiphy.probe_resp_offload))
  1159. goto nla_put_failure;
  1160. if ((rdev->wiphy.available_antennas_tx ||
  1161. rdev->wiphy.available_antennas_rx) &&
  1162. rdev->ops->get_antenna) {
  1163. u32 tx_ant = 0, rx_ant = 0;
  1164. int res;
  1165. res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
  1166. if (!res) {
  1167. if (nla_put_u32(msg,
  1168. NL80211_ATTR_WIPHY_ANTENNA_TX,
  1169. tx_ant) ||
  1170. nla_put_u32(msg,
  1171. NL80211_ATTR_WIPHY_ANTENNA_RX,
  1172. rx_ant))
  1173. goto nla_put_failure;
  1174. }
  1175. }
  1176. state->split_start++;
  1177. if (state->split)
  1178. break;
  1179. case 2:
  1180. if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
  1181. rdev->wiphy.interface_modes))
  1182. goto nla_put_failure;
  1183. state->split_start++;
  1184. if (state->split)
  1185. break;
  1186. case 3:
  1187. nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
  1188. if (!nl_bands)
  1189. goto nla_put_failure;
  1190. for (band = state->band_start;
  1191. band < IEEE80211_NUM_BANDS; band++) {
  1192. struct ieee80211_supported_band *sband;
  1193. sband = rdev->wiphy.bands[band];
  1194. if (!sband)
  1195. continue;
  1196. nl_band = nla_nest_start(msg, band);
  1197. if (!nl_band)
  1198. goto nla_put_failure;
  1199. switch (state->chan_start) {
  1200. case 0:
  1201. if (nl80211_send_band_rateinfo(msg, sband))
  1202. goto nla_put_failure;
  1203. state->chan_start++;
  1204. if (state->split)
  1205. break;
  1206. default:
  1207. /* add frequencies */
  1208. nl_freqs = nla_nest_start(
  1209. msg, NL80211_BAND_ATTR_FREQS);
  1210. if (!nl_freqs)
  1211. goto nla_put_failure;
  1212. for (i = state->chan_start - 1;
  1213. i < sband->n_channels;
  1214. i++) {
  1215. nl_freq = nla_nest_start(msg, i);
  1216. if (!nl_freq)
  1217. goto nla_put_failure;
  1218. chan = &sband->channels[i];
  1219. if (nl80211_msg_put_channel(
  1220. msg, chan,
  1221. state->split))
  1222. goto nla_put_failure;
  1223. nla_nest_end(msg, nl_freq);
  1224. if (state->split)
  1225. break;
  1226. }
  1227. if (i < sband->n_channels)
  1228. state->chan_start = i + 2;
  1229. else
  1230. state->chan_start = 0;
  1231. nla_nest_end(msg, nl_freqs);
  1232. }
  1233. nla_nest_end(msg, nl_band);
  1234. if (state->split) {
  1235. /* start again here */
  1236. if (state->chan_start)
  1237. band--;
  1238. break;
  1239. }
  1240. }
  1241. nla_nest_end(msg, nl_bands);
  1242. if (band < IEEE80211_NUM_BANDS)
  1243. state->band_start = band + 1;
  1244. else
  1245. state->band_start = 0;
  1246. /* if bands & channels are done, continue outside */
  1247. if (state->band_start == 0 && state->chan_start == 0)
  1248. state->split_start++;
  1249. if (state->split)
  1250. break;
  1251. case 4:
  1252. nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
  1253. if (!nl_cmds)
  1254. goto nla_put_failure;
  1255. i = 0;
  1256. #define CMD(op, n) \
  1257. do { \
  1258. if (rdev->ops->op) { \
  1259. i++; \
  1260. if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
  1261. goto nla_put_failure; \
  1262. } \
  1263. } while (0)
  1264. CMD(add_virtual_intf, NEW_INTERFACE);
  1265. CMD(change_virtual_intf, SET_INTERFACE);
  1266. CMD(add_key, NEW_KEY);
  1267. CMD(start_ap, START_AP);
  1268. CMD(add_station, NEW_STATION);
  1269. CMD(add_mpath, NEW_MPATH);
  1270. CMD(update_mesh_config, SET_MESH_CONFIG);
  1271. CMD(change_bss, SET_BSS);
  1272. CMD(auth, AUTHENTICATE);
  1273. CMD(assoc, ASSOCIATE);
  1274. CMD(deauth, DEAUTHENTICATE);
  1275. CMD(disassoc, DISASSOCIATE);
  1276. CMD(join_ibss, JOIN_IBSS);
  1277. CMD(join_mesh, JOIN_MESH);
  1278. CMD(set_pmksa, SET_PMKSA);
  1279. CMD(del_pmksa, DEL_PMKSA);
  1280. CMD(flush_pmksa, FLUSH_PMKSA);
  1281. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
  1282. CMD(remain_on_channel, REMAIN_ON_CHANNEL);
  1283. CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
  1284. CMD(mgmt_tx, FRAME);
  1285. CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
  1286. if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
  1287. i++;
  1288. if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
  1289. goto nla_put_failure;
  1290. }
  1291. if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
  1292. rdev->ops->join_mesh) {
  1293. i++;
  1294. if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
  1295. goto nla_put_failure;
  1296. }
  1297. CMD(set_wds_peer, SET_WDS_PEER);
  1298. if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
  1299. CMD(tdls_mgmt, TDLS_MGMT);
  1300. CMD(tdls_oper, TDLS_OPER);
  1301. }
  1302. if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  1303. CMD(sched_scan_start, START_SCHED_SCAN);
  1304. CMD(probe_client, PROBE_CLIENT);
  1305. CMD(set_noack_map, SET_NOACK_MAP);
  1306. if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
  1307. i++;
  1308. if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
  1309. goto nla_put_failure;
  1310. }
  1311. CMD(start_p2p_device, START_P2P_DEVICE);
  1312. CMD(set_mcast_rate, SET_MCAST_RATE);
  1313. #ifdef CONFIG_NL80211_TESTMODE
  1314. CMD(testmode_cmd, TESTMODE);
  1315. #endif
  1316. if (state->split) {
  1317. CMD(crit_proto_start, CRIT_PROTOCOL_START);
  1318. CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
  1319. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
  1320. CMD(channel_switch, CHANNEL_SWITCH);
  1321. CMD(set_qos_map, SET_QOS_MAP);
  1322. if (rdev->wiphy.features &
  1323. NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
  1324. CMD(add_tx_ts, ADD_TX_TS);
  1325. }
  1326. /* add into the if now */
  1327. #undef CMD
  1328. if (rdev->ops->connect || rdev->ops->auth) {
  1329. i++;
  1330. if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
  1331. goto nla_put_failure;
  1332. }
  1333. if (rdev->ops->disconnect || rdev->ops->deauth) {
  1334. i++;
  1335. if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
  1336. goto nla_put_failure;
  1337. }
  1338. nla_nest_end(msg, nl_cmds);
  1339. state->split_start++;
  1340. if (state->split)
  1341. break;
  1342. case 5:
  1343. if (rdev->ops->remain_on_channel &&
  1344. (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
  1345. nla_put_u32(msg,
  1346. NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
  1347. rdev->wiphy.max_remain_on_channel_duration))
  1348. goto nla_put_failure;
  1349. if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
  1350. nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
  1351. goto nla_put_failure;
  1352. if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
  1353. goto nla_put_failure;
  1354. state->split_start++;
  1355. if (state->split)
  1356. break;
  1357. case 6:
  1358. #ifdef CONFIG_PM
  1359. if (nl80211_send_wowlan(msg, rdev, state->split))
  1360. goto nla_put_failure;
  1361. state->split_start++;
  1362. if (state->split)
  1363. break;
  1364. #else
  1365. state->split_start++;
  1366. #endif
  1367. case 7:
  1368. if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
  1369. rdev->wiphy.software_iftypes))
  1370. goto nla_put_failure;
  1371. if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
  1372. state->split))
  1373. goto nla_put_failure;
  1374. state->split_start++;
  1375. if (state->split)
  1376. break;
  1377. case 8:
  1378. if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
  1379. nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
  1380. rdev->wiphy.ap_sme_capa))
  1381. goto nla_put_failure;
  1382. features = rdev->wiphy.features;
  1383. /*
  1384. * We can only add the per-channel limit information if the
  1385. * dump is split, otherwise it makes it too big. Therefore
  1386. * only advertise it in that case.
  1387. */
  1388. if (state->split)
  1389. features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
  1390. if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
  1391. goto nla_put_failure;
  1392. if (rdev->wiphy.ht_capa_mod_mask &&
  1393. nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
  1394. sizeof(*rdev->wiphy.ht_capa_mod_mask),
  1395. rdev->wiphy.ht_capa_mod_mask))
  1396. goto nla_put_failure;
  1397. if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
  1398. rdev->wiphy.max_acl_mac_addrs &&
  1399. nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
  1400. rdev->wiphy.max_acl_mac_addrs))
  1401. goto nla_put_failure;
  1402. /*
  1403. * Any information below this point is only available to
  1404. * applications that can deal with it being split. This
  1405. * helps ensure that newly added capabilities don't break
  1406. * older tools by overrunning their buffers.
  1407. *
  1408. * We still increment split_start so that in the split
  1409. * case we'll continue with more data in the next round,
  1410. * but break unconditionally so unsplit data stops here.
  1411. */
  1412. state->split_start++;
  1413. break;
  1414. case 9:
  1415. if (rdev->wiphy.extended_capabilities &&
  1416. (nla_put(msg, NL80211_ATTR_EXT_CAPA,
  1417. rdev->wiphy.extended_capabilities_len,
  1418. rdev->wiphy.extended_capabilities) ||
  1419. nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
  1420. rdev->wiphy.extended_capabilities_len,
  1421. rdev->wiphy.extended_capabilities_mask)))
  1422. goto nla_put_failure;
  1423. if (rdev->wiphy.vht_capa_mod_mask &&
  1424. nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
  1425. sizeof(*rdev->wiphy.vht_capa_mod_mask),
  1426. rdev->wiphy.vht_capa_mod_mask))
  1427. goto nla_put_failure;
  1428. state->split_start++;
  1429. break;
  1430. case 10:
  1431. if (nl80211_send_coalesce(msg, rdev))
  1432. goto nla_put_failure;
  1433. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
  1434. (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
  1435. nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
  1436. goto nla_put_failure;
  1437. if (rdev->wiphy.max_ap_assoc_sta &&
  1438. nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
  1439. rdev->wiphy.max_ap_assoc_sta))
  1440. goto nla_put_failure;
  1441. state->split_start++;
  1442. break;
  1443. case 11:
  1444. if (rdev->wiphy.n_vendor_commands) {
  1445. const struct nl80211_vendor_cmd_info *info;
  1446. struct nlattr *nested;
  1447. nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
  1448. if (!nested)
  1449. goto nla_put_failure;
  1450. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  1451. info = &rdev->wiphy.vendor_commands[i].info;
  1452. if (nla_put(msg, i + 1, sizeof(*info), info))
  1453. goto nla_put_failure;
  1454. }
  1455. nla_nest_end(msg, nested);
  1456. }
  1457. if (rdev->wiphy.n_vendor_events) {
  1458. const struct nl80211_vendor_cmd_info *info;
  1459. struct nlattr *nested;
  1460. nested = nla_nest_start(msg,
  1461. NL80211_ATTR_VENDOR_EVENTS);
  1462. if (!nested)
  1463. goto nla_put_failure;
  1464. for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
  1465. info = &rdev->wiphy.vendor_events[i];
  1466. if (nla_put(msg, i + 1, sizeof(*info), info))
  1467. goto nla_put_failure;
  1468. }
  1469. nla_nest_end(msg, nested);
  1470. }
  1471. state->split_start++;
  1472. break;
  1473. case 12:
  1474. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
  1475. nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
  1476. rdev->wiphy.max_num_csa_counters))
  1477. goto nla_put_failure;
  1478. if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  1479. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  1480. goto nla_put_failure;
  1481. if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
  1482. sizeof(rdev->wiphy.ext_features),
  1483. rdev->wiphy.ext_features))
  1484. goto nla_put_failure;
  1485. /* done */
  1486. state->split_start = 0;
  1487. break;
  1488. }
  1489. finish:
  1490. genlmsg_end(msg, hdr);
  1491. return 0;
  1492. nla_put_failure:
  1493. genlmsg_cancel(msg, hdr);
  1494. return -EMSGSIZE;
  1495. }
  1496. static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
  1497. struct netlink_callback *cb,
  1498. struct nl80211_dump_wiphy_state *state)
  1499. {
  1500. struct nlattr **tb = nl80211_fam.attrbuf;
  1501. int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  1502. tb, nl80211_fam.maxattr, nl80211_policy);
  1503. /* ignore parse errors for backward compatibility */
  1504. if (ret)
  1505. return 0;
  1506. state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
  1507. if (tb[NL80211_ATTR_WIPHY])
  1508. state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
  1509. if (tb[NL80211_ATTR_WDEV])
  1510. state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
  1511. if (tb[NL80211_ATTR_IFINDEX]) {
  1512. struct net_device *netdev;
  1513. struct cfg80211_registered_device *rdev;
  1514. int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
  1515. netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
  1516. if (!netdev)
  1517. return -ENODEV;
  1518. if (netdev->ieee80211_ptr) {
  1519. rdev = wiphy_to_rdev(
  1520. netdev->ieee80211_ptr->wiphy);
  1521. state->filter_wiphy = rdev->wiphy_idx;
  1522. }
  1523. }
  1524. return 0;
  1525. }
  1526. static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
  1527. {
  1528. int idx = 0, ret;
  1529. struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
  1530. struct cfg80211_registered_device *rdev;
  1531. rtnl_lock();
  1532. if (!state) {
  1533. state = kzalloc(sizeof(*state), GFP_KERNEL);
  1534. if (!state) {
  1535. rtnl_unlock();
  1536. return -ENOMEM;
  1537. }
  1538. state->filter_wiphy = -1;
  1539. ret = nl80211_dump_wiphy_parse(skb, cb, state);
  1540. if (ret) {
  1541. kfree(state);
  1542. rtnl_unlock();
  1543. return ret;
  1544. }
  1545. cb->args[0] = (long)state;
  1546. }
  1547. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  1548. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  1549. continue;
  1550. if (++idx <= state->start)
  1551. continue;
  1552. if (state->filter_wiphy != -1 &&
  1553. state->filter_wiphy != rdev->wiphy_idx)
  1554. continue;
  1555. /* attempt to fit multiple wiphy data chunks into the skb */
  1556. do {
  1557. ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
  1558. skb,
  1559. NETLINK_CB(cb->skb).portid,
  1560. cb->nlh->nlmsg_seq,
  1561. NLM_F_MULTI, state);
  1562. if (ret < 0) {
  1563. /*
  1564. * If sending the wiphy data didn't fit (ENOBUFS
  1565. * or EMSGSIZE returned), this SKB is still
  1566. * empty (so it's not too big because another
  1567. * wiphy dataset is already in the skb) and
  1568. * we've not tried to adjust the dump allocation
  1569. * yet ... then adjust the alloc size to be
  1570. * bigger, and return 1 but with the empty skb.
  1571. * This results in an empty message being RX'ed
  1572. * in userspace, but that is ignored.
  1573. *
  1574. * We can then retry with the larger buffer.
  1575. */
  1576. if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
  1577. !skb->len && !state->split &&
  1578. cb->min_dump_alloc < 4096) {
  1579. cb->min_dump_alloc = 4096;
  1580. state->split_start = 0;
  1581. rtnl_unlock();
  1582. return 1;
  1583. }
  1584. idx--;
  1585. break;
  1586. }
  1587. } while (state->split_start > 0);
  1588. break;
  1589. }
  1590. rtnl_unlock();
  1591. state->start = idx;
  1592. return skb->len;
  1593. }
  1594. static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
  1595. {
  1596. kfree((void *)cb->args[0]);
  1597. return 0;
  1598. }
  1599. static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
  1600. {
  1601. struct sk_buff *msg;
  1602. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1603. struct nl80211_dump_wiphy_state state = {};
  1604. msg = nlmsg_new(4096, GFP_KERNEL);
  1605. if (!msg)
  1606. return -ENOMEM;
  1607. if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
  1608. info->snd_portid, info->snd_seq, 0,
  1609. &state) < 0) {
  1610. nlmsg_free(msg);
  1611. return -ENOBUFS;
  1612. }
  1613. return genlmsg_reply(msg, info);
  1614. }
  1615. static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
  1616. [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
  1617. [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
  1618. [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
  1619. [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
  1620. [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
  1621. };
  1622. static int parse_txq_params(struct nlattr *tb[],
  1623. struct ieee80211_txq_params *txq_params)
  1624. {
  1625. if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
  1626. !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
  1627. !tb[NL80211_TXQ_ATTR_AIFS])
  1628. return -EINVAL;
  1629. txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
  1630. txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
  1631. txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
  1632. txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
  1633. txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
  1634. if (txq_params->ac >= NL80211_NUM_ACS)
  1635. return -EINVAL;
  1636. return 0;
  1637. }
  1638. static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
  1639. {
  1640. /*
  1641. * You can only set the channel explicitly for WDS interfaces,
  1642. * all others have their channel managed via their respective
  1643. * "establish a connection" command (connect, join, ...)
  1644. *
  1645. * For AP/GO and mesh mode, the channel can be set with the
  1646. * channel userspace API, but is only stored and passed to the
  1647. * low-level driver when the AP starts or the mesh is joined.
  1648. * This is for backward compatibility, userspace can also give
  1649. * the channel in the start-ap or join-mesh commands instead.
  1650. *
  1651. * Monitors are special as they are normally slaved to
  1652. * whatever else is going on, so they have their own special
  1653. * operation to set the monitor channel if possible.
  1654. */
  1655. return !wdev ||
  1656. wdev->iftype == NL80211_IFTYPE_AP ||
  1657. wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
  1658. wdev->iftype == NL80211_IFTYPE_MONITOR ||
  1659. wdev->iftype == NL80211_IFTYPE_P2P_GO;
  1660. }
  1661. static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
  1662. struct genl_info *info,
  1663. struct cfg80211_chan_def *chandef)
  1664. {
  1665. u32 control_freq;
  1666. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  1667. return -EINVAL;
  1668. control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  1669. chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
  1670. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  1671. chandef->center_freq1 = control_freq;
  1672. chandef->center_freq2 = 0;
  1673. /* Primary channel not allowed */
  1674. if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
  1675. return -EINVAL;
  1676. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  1677. enum nl80211_channel_type chantype;
  1678. chantype = nla_get_u32(
  1679. info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  1680. switch (chantype) {
  1681. case NL80211_CHAN_NO_HT:
  1682. case NL80211_CHAN_HT20:
  1683. case NL80211_CHAN_HT40PLUS:
  1684. case NL80211_CHAN_HT40MINUS:
  1685. cfg80211_chandef_create(chandef, chandef->chan,
  1686. chantype);
  1687. break;
  1688. default:
  1689. return -EINVAL;
  1690. }
  1691. } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
  1692. chandef->width =
  1693. nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
  1694. if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
  1695. chandef->center_freq1 =
  1696. nla_get_u32(
  1697. info->attrs[NL80211_ATTR_CENTER_FREQ1]);
  1698. if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
  1699. chandef->center_freq2 =
  1700. nla_get_u32(
  1701. info->attrs[NL80211_ATTR_CENTER_FREQ2]);
  1702. }
  1703. if (!cfg80211_chandef_valid(chandef))
  1704. return -EINVAL;
  1705. if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
  1706. IEEE80211_CHAN_DISABLED))
  1707. return -EINVAL;
  1708. if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
  1709. chandef->width == NL80211_CHAN_WIDTH_10) &&
  1710. !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
  1711. return -EINVAL;
  1712. return 0;
  1713. }
  1714. static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
  1715. struct net_device *dev,
  1716. struct genl_info *info)
  1717. {
  1718. struct cfg80211_chan_def chandef;
  1719. int result;
  1720. enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
  1721. struct wireless_dev *wdev = NULL;
  1722. if (dev)
  1723. wdev = dev->ieee80211_ptr;
  1724. if (!nl80211_can_set_dev_channel(wdev))
  1725. return -EOPNOTSUPP;
  1726. if (wdev)
  1727. iftype = wdev->iftype;
  1728. result = nl80211_parse_chandef(rdev, info, &chandef);
  1729. if (result)
  1730. return result;
  1731. switch (iftype) {
  1732. case NL80211_IFTYPE_AP:
  1733. case NL80211_IFTYPE_P2P_GO:
  1734. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
  1735. result = -EINVAL;
  1736. break;
  1737. }
  1738. if (wdev->beacon_interval) {
  1739. if (!dev || !rdev->ops->set_ap_chanwidth ||
  1740. !(rdev->wiphy.features &
  1741. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
  1742. result = -EBUSY;
  1743. break;
  1744. }
  1745. /* Only allow dynamic channel width changes */
  1746. if (chandef.chan != wdev->preset_chandef.chan) {
  1747. result = -EBUSY;
  1748. break;
  1749. }
  1750. result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
  1751. if (result)
  1752. break;
  1753. }
  1754. wdev->preset_chandef = chandef;
  1755. result = 0;
  1756. break;
  1757. case NL80211_IFTYPE_MESH_POINT:
  1758. result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
  1759. break;
  1760. case NL80211_IFTYPE_MONITOR:
  1761. result = cfg80211_set_monitor_channel(rdev, &chandef);
  1762. break;
  1763. default:
  1764. result = -EINVAL;
  1765. }
  1766. return result;
  1767. }
  1768. static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
  1769. {
  1770. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1771. struct net_device *netdev = info->user_ptr[1];
  1772. return __nl80211_set_channel(rdev, netdev, info);
  1773. }
  1774. static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
  1775. {
  1776. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1777. struct net_device *dev = info->user_ptr[1];
  1778. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1779. const u8 *bssid;
  1780. if (!info->attrs[NL80211_ATTR_MAC])
  1781. return -EINVAL;
  1782. if (netif_running(dev))
  1783. return -EBUSY;
  1784. if (!rdev->ops->set_wds_peer)
  1785. return -EOPNOTSUPP;
  1786. if (wdev->iftype != NL80211_IFTYPE_WDS)
  1787. return -EOPNOTSUPP;
  1788. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1789. return rdev_set_wds_peer(rdev, dev, bssid);
  1790. }
  1791. static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
  1792. {
  1793. struct cfg80211_registered_device *rdev;
  1794. struct net_device *netdev = NULL;
  1795. struct wireless_dev *wdev;
  1796. int result = 0, rem_txq_params = 0;
  1797. struct nlattr *nl_txq_params;
  1798. u32 changed;
  1799. u8 retry_short = 0, retry_long = 0;
  1800. u32 frag_threshold = 0, rts_threshold = 0;
  1801. u8 coverage_class = 0;
  1802. ASSERT_RTNL();
  1803. /*
  1804. * Try to find the wiphy and netdev. Normally this
  1805. * function shouldn't need the netdev, but this is
  1806. * done for backward compatibility -- previously
  1807. * setting the channel was done per wiphy, but now
  1808. * it is per netdev. Previous userland like hostapd
  1809. * also passed a netdev to set_wiphy, so that it is
  1810. * possible to let that go to the right netdev!
  1811. */
  1812. if (info->attrs[NL80211_ATTR_IFINDEX]) {
  1813. int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
  1814. netdev = __dev_get_by_index(genl_info_net(info), ifindex);
  1815. if (netdev && netdev->ieee80211_ptr)
  1816. rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
  1817. else
  1818. netdev = NULL;
  1819. }
  1820. if (!netdev) {
  1821. rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
  1822. info->attrs);
  1823. if (IS_ERR(rdev))
  1824. return PTR_ERR(rdev);
  1825. wdev = NULL;
  1826. netdev = NULL;
  1827. result = 0;
  1828. } else
  1829. wdev = netdev->ieee80211_ptr;
  1830. /*
  1831. * end workaround code, by now the rdev is available
  1832. * and locked, and wdev may or may not be NULL.
  1833. */
  1834. if (info->attrs[NL80211_ATTR_WIPHY_NAME])
  1835. result = cfg80211_dev_rename(
  1836. rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
  1837. if (result)
  1838. return result;
  1839. if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
  1840. struct ieee80211_txq_params txq_params;
  1841. struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
  1842. if (!rdev->ops->set_txq_params)
  1843. return -EOPNOTSUPP;
  1844. if (!netdev)
  1845. return -EINVAL;
  1846. if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  1847. netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  1848. return -EINVAL;
  1849. if (!netif_running(netdev))
  1850. return -ENETDOWN;
  1851. nla_for_each_nested(nl_txq_params,
  1852. info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
  1853. rem_txq_params) {
  1854. result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
  1855. nla_data(nl_txq_params),
  1856. nla_len(nl_txq_params),
  1857. txq_params_policy);
  1858. if (result)
  1859. return result;
  1860. result = parse_txq_params(tb, &txq_params);
  1861. if (result)
  1862. return result;
  1863. result = rdev_set_txq_params(rdev, netdev,
  1864. &txq_params);
  1865. if (result)
  1866. return result;
  1867. }
  1868. }
  1869. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  1870. result = __nl80211_set_channel(
  1871. rdev,
  1872. nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
  1873. info);
  1874. if (result)
  1875. return result;
  1876. }
  1877. if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
  1878. struct wireless_dev *txp_wdev = wdev;
  1879. enum nl80211_tx_power_setting type;
  1880. int idx, mbm = 0;
  1881. if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
  1882. txp_wdev = NULL;
  1883. if (!rdev->ops->set_tx_power)
  1884. return -EOPNOTSUPP;
  1885. idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
  1886. type = nla_get_u32(info->attrs[idx]);
  1887. if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
  1888. (type != NL80211_TX_POWER_AUTOMATIC))
  1889. return -EINVAL;
  1890. if (type != NL80211_TX_POWER_AUTOMATIC) {
  1891. idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
  1892. mbm = nla_get_u32(info->attrs[idx]);
  1893. }
  1894. result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
  1895. if (result)
  1896. return result;
  1897. }
  1898. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  1899. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
  1900. u32 tx_ant, rx_ant;
  1901. if ((!rdev->wiphy.available_antennas_tx &&
  1902. !rdev->wiphy.available_antennas_rx) ||
  1903. !rdev->ops->set_antenna)
  1904. return -EOPNOTSUPP;
  1905. tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
  1906. rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
  1907. /* reject antenna configurations which don't match the
  1908. * available antenna masks, except for the "all" mask */
  1909. if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
  1910. (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
  1911. return -EINVAL;
  1912. tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
  1913. rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
  1914. result = rdev_set_antenna(rdev, tx_ant, rx_ant);
  1915. if (result)
  1916. return result;
  1917. }
  1918. changed = 0;
  1919. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
  1920. retry_short = nla_get_u8(
  1921. info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
  1922. if (retry_short == 0)
  1923. return -EINVAL;
  1924. changed |= WIPHY_PARAM_RETRY_SHORT;
  1925. }
  1926. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
  1927. retry_long = nla_get_u8(
  1928. info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
  1929. if (retry_long == 0)
  1930. return -EINVAL;
  1931. changed |= WIPHY_PARAM_RETRY_LONG;
  1932. }
  1933. if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
  1934. frag_threshold = nla_get_u32(
  1935. info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
  1936. if (frag_threshold < 256)
  1937. return -EINVAL;
  1938. if (frag_threshold != (u32) -1) {
  1939. /*
  1940. * Fragments (apart from the last one) are required to
  1941. * have even length. Make the fragmentation code
  1942. * simpler by stripping LSB should someone try to use
  1943. * odd threshold value.
  1944. */
  1945. frag_threshold &= ~0x1;
  1946. }
  1947. changed |= WIPHY_PARAM_FRAG_THRESHOLD;
  1948. }
  1949. if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
  1950. rts_threshold = nla_get_u32(
  1951. info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
  1952. changed |= WIPHY_PARAM_RTS_THRESHOLD;
  1953. }
  1954. if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
  1955. if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
  1956. return -EINVAL;
  1957. coverage_class = nla_get_u8(
  1958. info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
  1959. changed |= WIPHY_PARAM_COVERAGE_CLASS;
  1960. }
  1961. if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
  1962. if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
  1963. return -EOPNOTSUPP;
  1964. changed |= WIPHY_PARAM_DYN_ACK;
  1965. }
  1966. if (changed) {
  1967. u8 old_retry_short, old_retry_long;
  1968. u32 old_frag_threshold, old_rts_threshold;
  1969. u8 old_coverage_class;
  1970. if (!rdev->ops->set_wiphy_params)
  1971. return -EOPNOTSUPP;
  1972. old_retry_short = rdev->wiphy.retry_short;
  1973. old_retry_long = rdev->wiphy.retry_long;
  1974. old_frag_threshold = rdev->wiphy.frag_threshold;
  1975. old_rts_threshold = rdev->wiphy.rts_threshold;
  1976. old_coverage_class = rdev->wiphy.coverage_class;
  1977. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1978. rdev->wiphy.retry_short = retry_short;
  1979. if (changed & WIPHY_PARAM_RETRY_LONG)
  1980. rdev->wiphy.retry_long = retry_long;
  1981. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  1982. rdev->wiphy.frag_threshold = frag_threshold;
  1983. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  1984. rdev->wiphy.rts_threshold = rts_threshold;
  1985. if (changed & WIPHY_PARAM_COVERAGE_CLASS)
  1986. rdev->wiphy.coverage_class = coverage_class;
  1987. result = rdev_set_wiphy_params(rdev, changed);
  1988. if (result) {
  1989. rdev->wiphy.retry_short = old_retry_short;
  1990. rdev->wiphy.retry_long = old_retry_long;
  1991. rdev->wiphy.frag_threshold = old_frag_threshold;
  1992. rdev->wiphy.rts_threshold = old_rts_threshold;
  1993. rdev->wiphy.coverage_class = old_coverage_class;
  1994. }
  1995. }
  1996. return 0;
  1997. }
  1998. static inline u64 wdev_id(struct wireless_dev *wdev)
  1999. {
  2000. return (u64)wdev->identifier |
  2001. ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
  2002. }
  2003. static int nl80211_send_chandef(struct sk_buff *msg,
  2004. const struct cfg80211_chan_def *chandef)
  2005. {
  2006. if (WARN_ON(!cfg80211_chandef_valid(chandef)))
  2007. return -EINVAL;
  2008. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
  2009. chandef->chan->center_freq))
  2010. return -ENOBUFS;
  2011. switch (chandef->width) {
  2012. case NL80211_CHAN_WIDTH_20_NOHT:
  2013. case NL80211_CHAN_WIDTH_20:
  2014. case NL80211_CHAN_WIDTH_40:
  2015. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  2016. cfg80211_get_chandef_type(chandef)))
  2017. return -ENOBUFS;
  2018. break;
  2019. default:
  2020. break;
  2021. }
  2022. if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
  2023. return -ENOBUFS;
  2024. if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
  2025. return -ENOBUFS;
  2026. if (chandef->center_freq2 &&
  2027. nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
  2028. return -ENOBUFS;
  2029. return 0;
  2030. }
  2031. static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
  2032. struct cfg80211_registered_device *rdev,
  2033. struct wireless_dev *wdev, bool removal)
  2034. {
  2035. struct net_device *dev = wdev->netdev;
  2036. u8 cmd = NL80211_CMD_NEW_INTERFACE;
  2037. void *hdr;
  2038. if (removal)
  2039. cmd = NL80211_CMD_DEL_INTERFACE;
  2040. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  2041. if (!hdr)
  2042. return -1;
  2043. if (dev &&
  2044. (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  2045. nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
  2046. goto nla_put_failure;
  2047. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  2048. nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
  2049. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
  2050. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
  2051. nla_put_u32(msg, NL80211_ATTR_GENERATION,
  2052. rdev->devlist_generation ^
  2053. (cfg80211_rdev_list_generation << 2)))
  2054. goto nla_put_failure;
  2055. if (rdev->ops->get_channel) {
  2056. int ret;
  2057. struct cfg80211_chan_def chandef;
  2058. ret = rdev_get_channel(rdev, wdev, &chandef);
  2059. if (ret == 0) {
  2060. if (nl80211_send_chandef(msg, &chandef))
  2061. goto nla_put_failure;
  2062. }
  2063. }
  2064. if (wdev->ssid_len) {
  2065. if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
  2066. goto nla_put_failure;
  2067. }
  2068. genlmsg_end(msg, hdr);
  2069. return 0;
  2070. nla_put_failure:
  2071. genlmsg_cancel(msg, hdr);
  2072. return -EMSGSIZE;
  2073. }
  2074. static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
  2075. {
  2076. int wp_idx = 0;
  2077. int if_idx = 0;
  2078. int wp_start = cb->args[0];
  2079. int if_start = cb->args[1];
  2080. struct cfg80211_registered_device *rdev;
  2081. struct wireless_dev *wdev;
  2082. rtnl_lock();
  2083. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  2084. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  2085. continue;
  2086. if (wp_idx < wp_start) {
  2087. wp_idx++;
  2088. continue;
  2089. }
  2090. if_idx = 0;
  2091. list_for_each_entry(wdev, &rdev->wdev_list, list) {
  2092. if (if_idx < if_start) {
  2093. if_idx++;
  2094. continue;
  2095. }
  2096. if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
  2097. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  2098. rdev, wdev, false) < 0) {
  2099. goto out;
  2100. }
  2101. if_idx++;
  2102. }
  2103. wp_idx++;
  2104. }
  2105. out:
  2106. rtnl_unlock();
  2107. cb->args[0] = wp_idx;
  2108. cb->args[1] = if_idx;
  2109. return skb->len;
  2110. }
  2111. static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
  2112. {
  2113. struct sk_buff *msg;
  2114. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2115. struct wireless_dev *wdev = info->user_ptr[1];
  2116. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2117. if (!msg)
  2118. return -ENOMEM;
  2119. if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
  2120. rdev, wdev, false) < 0) {
  2121. nlmsg_free(msg);
  2122. return -ENOBUFS;
  2123. }
  2124. return genlmsg_reply(msg, info);
  2125. }
  2126. static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
  2127. [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
  2128. [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
  2129. [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
  2130. [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
  2131. [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
  2132. [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
  2133. };
  2134. static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
  2135. {
  2136. struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
  2137. int flag;
  2138. *mntrflags = 0;
  2139. if (!nla)
  2140. return -EINVAL;
  2141. if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
  2142. nla, mntr_flags_policy))
  2143. return -EINVAL;
  2144. for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
  2145. if (flags[flag])
  2146. *mntrflags |= (1<<flag);
  2147. return 0;
  2148. }
  2149. static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
  2150. struct net_device *netdev, u8 use_4addr,
  2151. enum nl80211_iftype iftype)
  2152. {
  2153. if (!use_4addr) {
  2154. if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
  2155. return -EBUSY;
  2156. return 0;
  2157. }
  2158. switch (iftype) {
  2159. case NL80211_IFTYPE_AP_VLAN:
  2160. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
  2161. return 0;
  2162. break;
  2163. case NL80211_IFTYPE_STATION:
  2164. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
  2165. return 0;
  2166. break;
  2167. default:
  2168. break;
  2169. }
  2170. return -EOPNOTSUPP;
  2171. }
  2172. static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
  2173. {
  2174. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2175. struct vif_params params;
  2176. int err;
  2177. enum nl80211_iftype otype, ntype;
  2178. struct net_device *dev = info->user_ptr[1];
  2179. u32 _flags, *flags = NULL;
  2180. bool change = false;
  2181. memset(&params, 0, sizeof(params));
  2182. otype = ntype = dev->ieee80211_ptr->iftype;
  2183. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  2184. ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  2185. if (otype != ntype)
  2186. change = true;
  2187. if (ntype > NL80211_IFTYPE_MAX)
  2188. return -EINVAL;
  2189. }
  2190. if (info->attrs[NL80211_ATTR_MESH_ID]) {
  2191. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2192. if (ntype != NL80211_IFTYPE_MESH_POINT)
  2193. return -EINVAL;
  2194. if (netif_running(dev))
  2195. return -EBUSY;
  2196. wdev_lock(wdev);
  2197. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  2198. IEEE80211_MAX_MESH_ID_LEN);
  2199. wdev->mesh_id_up_len =
  2200. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  2201. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  2202. wdev->mesh_id_up_len);
  2203. wdev_unlock(wdev);
  2204. }
  2205. if (info->attrs[NL80211_ATTR_4ADDR]) {
  2206. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  2207. change = true;
  2208. err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
  2209. if (err)
  2210. return err;
  2211. } else {
  2212. params.use_4addr = -1;
  2213. }
  2214. if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
  2215. if (ntype != NL80211_IFTYPE_MONITOR)
  2216. return -EINVAL;
  2217. err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
  2218. &_flags);
  2219. if (err)
  2220. return err;
  2221. flags = &_flags;
  2222. change = true;
  2223. }
  2224. if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
  2225. !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
  2226. return -EOPNOTSUPP;
  2227. if (change)
  2228. err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
  2229. else
  2230. err = 0;
  2231. if (!err && params.use_4addr != -1)
  2232. dev->ieee80211_ptr->use_4addr = params.use_4addr;
  2233. return err;
  2234. }
  2235. static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
  2236. {
  2237. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2238. struct vif_params params;
  2239. struct wireless_dev *wdev;
  2240. struct sk_buff *msg, *event;
  2241. int err;
  2242. enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
  2243. u32 flags;
  2244. /* to avoid failing a new interface creation due to pending removal */
  2245. cfg80211_destroy_ifaces(rdev);
  2246. memset(&params, 0, sizeof(params));
  2247. if (!info->attrs[NL80211_ATTR_IFNAME])
  2248. return -EINVAL;
  2249. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  2250. type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  2251. if (type > NL80211_IFTYPE_MAX)
  2252. return -EINVAL;
  2253. }
  2254. if (!rdev->ops->add_virtual_intf ||
  2255. !(rdev->wiphy.interface_modes & (1 << type)))
  2256. return -EOPNOTSUPP;
  2257. if ((type == NL80211_IFTYPE_P2P_DEVICE ||
  2258. rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
  2259. info->attrs[NL80211_ATTR_MAC]) {
  2260. nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
  2261. ETH_ALEN);
  2262. if (!is_valid_ether_addr(params.macaddr))
  2263. return -EADDRNOTAVAIL;
  2264. }
  2265. if (info->attrs[NL80211_ATTR_4ADDR]) {
  2266. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  2267. err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
  2268. if (err)
  2269. return err;
  2270. }
  2271. err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
  2272. info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
  2273. &flags);
  2274. if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
  2275. !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
  2276. return -EOPNOTSUPP;
  2277. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2278. if (!msg)
  2279. return -ENOMEM;
  2280. wdev = rdev_add_virtual_intf(rdev,
  2281. nla_data(info->attrs[NL80211_ATTR_IFNAME]),
  2282. NET_NAME_USER, type, err ? NULL : &flags,
  2283. &params);
  2284. if (WARN_ON(!wdev)) {
  2285. nlmsg_free(msg);
  2286. return -EPROTO;
  2287. } else if (IS_ERR(wdev)) {
  2288. nlmsg_free(msg);
  2289. return PTR_ERR(wdev);
  2290. }
  2291. if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
  2292. wdev->owner_nlportid = info->snd_portid;
  2293. switch (type) {
  2294. case NL80211_IFTYPE_MESH_POINT:
  2295. if (!info->attrs[NL80211_ATTR_MESH_ID])
  2296. break;
  2297. wdev_lock(wdev);
  2298. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  2299. IEEE80211_MAX_MESH_ID_LEN);
  2300. wdev->mesh_id_up_len =
  2301. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  2302. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  2303. wdev->mesh_id_up_len);
  2304. wdev_unlock(wdev);
  2305. break;
  2306. case NL80211_IFTYPE_P2P_DEVICE:
  2307. /*
  2308. * P2P Device doesn't have a netdev, so doesn't go
  2309. * through the netdev notifier and must be added here
  2310. */
  2311. mutex_init(&wdev->mtx);
  2312. INIT_LIST_HEAD(&wdev->event_list);
  2313. spin_lock_init(&wdev->event_lock);
  2314. INIT_LIST_HEAD(&wdev->mgmt_registrations);
  2315. spin_lock_init(&wdev->mgmt_registrations_lock);
  2316. wdev->identifier = ++rdev->wdev_id;
  2317. list_add_rcu(&wdev->list, &rdev->wdev_list);
  2318. rdev->devlist_generation++;
  2319. break;
  2320. default:
  2321. break;
  2322. }
  2323. if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
  2324. rdev, wdev, false) < 0) {
  2325. nlmsg_free(msg);
  2326. return -ENOBUFS;
  2327. }
  2328. event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2329. if (event) {
  2330. if (nl80211_send_iface(event, 0, 0, 0,
  2331. rdev, wdev, false) < 0) {
  2332. nlmsg_free(event);
  2333. goto out;
  2334. }
  2335. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
  2336. event, 0, NL80211_MCGRP_CONFIG,
  2337. GFP_KERNEL);
  2338. }
  2339. out:
  2340. return genlmsg_reply(msg, info);
  2341. }
  2342. static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
  2343. {
  2344. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2345. struct wireless_dev *wdev = info->user_ptr[1];
  2346. struct sk_buff *msg;
  2347. int status;
  2348. if (!rdev->ops->del_virtual_intf)
  2349. return -EOPNOTSUPP;
  2350. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2351. if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
  2352. nlmsg_free(msg);
  2353. msg = NULL;
  2354. }
  2355. /*
  2356. * If we remove a wireless device without a netdev then clear
  2357. * user_ptr[1] so that nl80211_post_doit won't dereference it
  2358. * to check if it needs to do dev_put(). Otherwise it crashes
  2359. * since the wdev has been freed, unlike with a netdev where
  2360. * we need the dev_put() for the netdev to really be freed.
  2361. */
  2362. if (!wdev->netdev)
  2363. info->user_ptr[1] = NULL;
  2364. status = rdev_del_virtual_intf(rdev, wdev);
  2365. if (status >= 0 && msg)
  2366. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
  2367. msg, 0, NL80211_MCGRP_CONFIG,
  2368. GFP_KERNEL);
  2369. else
  2370. nlmsg_free(msg);
  2371. return status;
  2372. }
  2373. static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
  2374. {
  2375. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2376. struct net_device *dev = info->user_ptr[1];
  2377. u16 noack_map;
  2378. if (!info->attrs[NL80211_ATTR_NOACK_MAP])
  2379. return -EINVAL;
  2380. if (!rdev->ops->set_noack_map)
  2381. return -EOPNOTSUPP;
  2382. noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
  2383. return rdev_set_noack_map(rdev, dev, noack_map);
  2384. }
  2385. struct get_key_cookie {
  2386. struct sk_buff *msg;
  2387. int error;
  2388. int idx;
  2389. };
  2390. static void get_key_callback(void *c, struct key_params *params)
  2391. {
  2392. struct nlattr *key;
  2393. struct get_key_cookie *cookie = c;
  2394. if ((params->key &&
  2395. nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
  2396. params->key_len, params->key)) ||
  2397. (params->seq &&
  2398. nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
  2399. params->seq_len, params->seq)) ||
  2400. (params->cipher &&
  2401. nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
  2402. params->cipher)))
  2403. goto nla_put_failure;
  2404. key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
  2405. if (!key)
  2406. goto nla_put_failure;
  2407. if ((params->key &&
  2408. nla_put(cookie->msg, NL80211_KEY_DATA,
  2409. params->key_len, params->key)) ||
  2410. (params->seq &&
  2411. nla_put(cookie->msg, NL80211_KEY_SEQ,
  2412. params->seq_len, params->seq)) ||
  2413. (params->cipher &&
  2414. nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
  2415. params->cipher)))
  2416. goto nla_put_failure;
  2417. if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
  2418. goto nla_put_failure;
  2419. nla_nest_end(cookie->msg, key);
  2420. return;
  2421. nla_put_failure:
  2422. cookie->error = 1;
  2423. }
  2424. static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
  2425. {
  2426. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2427. int err;
  2428. struct net_device *dev = info->user_ptr[1];
  2429. u8 key_idx = 0;
  2430. const u8 *mac_addr = NULL;
  2431. bool pairwise;
  2432. struct get_key_cookie cookie = {
  2433. .error = 0,
  2434. };
  2435. void *hdr;
  2436. struct sk_buff *msg;
  2437. if (info->attrs[NL80211_ATTR_KEY_IDX])
  2438. key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  2439. if (key_idx > 5)
  2440. return -EINVAL;
  2441. if (info->attrs[NL80211_ATTR_MAC])
  2442. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2443. pairwise = !!mac_addr;
  2444. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  2445. u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  2446. if (kt >= NUM_NL80211_KEYTYPES)
  2447. return -EINVAL;
  2448. if (kt != NL80211_KEYTYPE_GROUP &&
  2449. kt != NL80211_KEYTYPE_PAIRWISE)
  2450. return -EINVAL;
  2451. pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
  2452. }
  2453. if (!rdev->ops->get_key)
  2454. return -EOPNOTSUPP;
  2455. if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  2456. return -ENOENT;
  2457. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2458. if (!msg)
  2459. return -ENOMEM;
  2460. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  2461. NL80211_CMD_NEW_KEY);
  2462. if (!hdr)
  2463. goto nla_put_failure;
  2464. cookie.msg = msg;
  2465. cookie.idx = key_idx;
  2466. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  2467. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
  2468. goto nla_put_failure;
  2469. if (mac_addr &&
  2470. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
  2471. goto nla_put_failure;
  2472. err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
  2473. get_key_callback);
  2474. if (err)
  2475. goto free_msg;
  2476. if (cookie.error)
  2477. goto nla_put_failure;
  2478. genlmsg_end(msg, hdr);
  2479. return genlmsg_reply(msg, info);
  2480. nla_put_failure:
  2481. err = -ENOBUFS;
  2482. free_msg:
  2483. nlmsg_free(msg);
  2484. return err;
  2485. }
  2486. static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
  2487. {
  2488. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2489. struct key_parse key;
  2490. int err;
  2491. struct net_device *dev = info->user_ptr[1];
  2492. err = nl80211_parse_key(info, &key);
  2493. if (err)
  2494. return err;
  2495. if (key.idx < 0)
  2496. return -EINVAL;
  2497. /* only support setting default key */
  2498. if (!key.def && !key.defmgmt)
  2499. return -EINVAL;
  2500. wdev_lock(dev->ieee80211_ptr);
  2501. if (key.def) {
  2502. if (!rdev->ops->set_default_key) {
  2503. err = -EOPNOTSUPP;
  2504. goto out;
  2505. }
  2506. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2507. if (err)
  2508. goto out;
  2509. err = rdev_set_default_key(rdev, dev, key.idx,
  2510. key.def_uni, key.def_multi);
  2511. if (err)
  2512. goto out;
  2513. #ifdef CONFIG_CFG80211_WEXT
  2514. dev->ieee80211_ptr->wext.default_key = key.idx;
  2515. #endif
  2516. } else {
  2517. if (key.def_uni || !key.def_multi) {
  2518. err = -EINVAL;
  2519. goto out;
  2520. }
  2521. if (!rdev->ops->set_default_mgmt_key) {
  2522. err = -EOPNOTSUPP;
  2523. goto out;
  2524. }
  2525. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2526. if (err)
  2527. goto out;
  2528. err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
  2529. if (err)
  2530. goto out;
  2531. #ifdef CONFIG_CFG80211_WEXT
  2532. dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
  2533. #endif
  2534. }
  2535. out:
  2536. wdev_unlock(dev->ieee80211_ptr);
  2537. return err;
  2538. }
  2539. static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
  2540. {
  2541. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2542. int err;
  2543. struct net_device *dev = info->user_ptr[1];
  2544. struct key_parse key;
  2545. const u8 *mac_addr = NULL;
  2546. err = nl80211_parse_key(info, &key);
  2547. if (err)
  2548. return err;
  2549. if (!key.p.key)
  2550. return -EINVAL;
  2551. if (info->attrs[NL80211_ATTR_MAC])
  2552. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2553. if (key.type == -1) {
  2554. if (mac_addr)
  2555. key.type = NL80211_KEYTYPE_PAIRWISE;
  2556. else
  2557. key.type = NL80211_KEYTYPE_GROUP;
  2558. }
  2559. /* for now */
  2560. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  2561. key.type != NL80211_KEYTYPE_GROUP)
  2562. return -EINVAL;
  2563. if (!rdev->ops->add_key)
  2564. return -EOPNOTSUPP;
  2565. if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
  2566. key.type == NL80211_KEYTYPE_PAIRWISE,
  2567. mac_addr))
  2568. return -EINVAL;
  2569. wdev_lock(dev->ieee80211_ptr);
  2570. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2571. if (!err)
  2572. err = rdev_add_key(rdev, dev, key.idx,
  2573. key.type == NL80211_KEYTYPE_PAIRWISE,
  2574. mac_addr, &key.p);
  2575. wdev_unlock(dev->ieee80211_ptr);
  2576. return err;
  2577. }
  2578. static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
  2579. {
  2580. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2581. int err;
  2582. struct net_device *dev = info->user_ptr[1];
  2583. u8 *mac_addr = NULL;
  2584. struct key_parse key;
  2585. err = nl80211_parse_key(info, &key);
  2586. if (err)
  2587. return err;
  2588. if (info->attrs[NL80211_ATTR_MAC])
  2589. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2590. if (key.type == -1) {
  2591. if (mac_addr)
  2592. key.type = NL80211_KEYTYPE_PAIRWISE;
  2593. else
  2594. key.type = NL80211_KEYTYPE_GROUP;
  2595. }
  2596. /* for now */
  2597. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  2598. key.type != NL80211_KEYTYPE_GROUP)
  2599. return -EINVAL;
  2600. if (!rdev->ops->del_key)
  2601. return -EOPNOTSUPP;
  2602. wdev_lock(dev->ieee80211_ptr);
  2603. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2604. if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
  2605. !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  2606. err = -ENOENT;
  2607. if (!err)
  2608. err = rdev_del_key(rdev, dev, key.idx,
  2609. key.type == NL80211_KEYTYPE_PAIRWISE,
  2610. mac_addr);
  2611. #ifdef CONFIG_CFG80211_WEXT
  2612. if (!err) {
  2613. if (key.idx == dev->ieee80211_ptr->wext.default_key)
  2614. dev->ieee80211_ptr->wext.default_key = -1;
  2615. else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
  2616. dev->ieee80211_ptr->wext.default_mgmt_key = -1;
  2617. }
  2618. #endif
  2619. wdev_unlock(dev->ieee80211_ptr);
  2620. return err;
  2621. }
  2622. /* This function returns an error or the number of nested attributes */
  2623. static int validate_acl_mac_addrs(struct nlattr *nl_attr)
  2624. {
  2625. struct nlattr *attr;
  2626. int n_entries = 0, tmp;
  2627. nla_for_each_nested(attr, nl_attr, tmp) {
  2628. if (nla_len(attr) != ETH_ALEN)
  2629. return -EINVAL;
  2630. n_entries++;
  2631. }
  2632. return n_entries;
  2633. }
  2634. /*
  2635. * This function parses ACL information and allocates memory for ACL data.
  2636. * On successful return, the calling function is responsible to free the
  2637. * ACL buffer returned by this function.
  2638. */
  2639. static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
  2640. struct genl_info *info)
  2641. {
  2642. enum nl80211_acl_policy acl_policy;
  2643. struct nlattr *attr;
  2644. struct cfg80211_acl_data *acl;
  2645. int i = 0, n_entries, tmp;
  2646. if (!wiphy->max_acl_mac_addrs)
  2647. return ERR_PTR(-EOPNOTSUPP);
  2648. if (!info->attrs[NL80211_ATTR_ACL_POLICY])
  2649. return ERR_PTR(-EINVAL);
  2650. acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
  2651. if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
  2652. acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
  2653. return ERR_PTR(-EINVAL);
  2654. if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
  2655. return ERR_PTR(-EINVAL);
  2656. n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
  2657. if (n_entries < 0)
  2658. return ERR_PTR(n_entries);
  2659. if (n_entries > wiphy->max_acl_mac_addrs)
  2660. return ERR_PTR(-ENOTSUPP);
  2661. acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
  2662. GFP_KERNEL);
  2663. if (!acl)
  2664. return ERR_PTR(-ENOMEM);
  2665. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
  2666. memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
  2667. i++;
  2668. }
  2669. acl->n_acl_entries = n_entries;
  2670. acl->acl_policy = acl_policy;
  2671. return acl;
  2672. }
  2673. static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
  2674. {
  2675. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2676. struct net_device *dev = info->user_ptr[1];
  2677. struct cfg80211_acl_data *acl;
  2678. int err;
  2679. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2680. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2681. return -EOPNOTSUPP;
  2682. if (!dev->ieee80211_ptr->beacon_interval)
  2683. return -EINVAL;
  2684. acl = parse_acl_data(&rdev->wiphy, info);
  2685. if (IS_ERR(acl))
  2686. return PTR_ERR(acl);
  2687. err = rdev_set_mac_acl(rdev, dev, acl);
  2688. kfree(acl);
  2689. return err;
  2690. }
  2691. static int nl80211_parse_beacon(struct nlattr *attrs[],
  2692. struct cfg80211_beacon_data *bcn)
  2693. {
  2694. bool haveinfo = false;
  2695. if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
  2696. !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
  2697. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
  2698. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
  2699. return -EINVAL;
  2700. memset(bcn, 0, sizeof(*bcn));
  2701. if (attrs[NL80211_ATTR_BEACON_HEAD]) {
  2702. bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
  2703. bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
  2704. if (!bcn->head_len)
  2705. return -EINVAL;
  2706. haveinfo = true;
  2707. }
  2708. if (attrs[NL80211_ATTR_BEACON_TAIL]) {
  2709. bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
  2710. bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
  2711. haveinfo = true;
  2712. }
  2713. if (!haveinfo)
  2714. return -EINVAL;
  2715. if (attrs[NL80211_ATTR_IE]) {
  2716. bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
  2717. bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
  2718. }
  2719. if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
  2720. bcn->proberesp_ies =
  2721. nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  2722. bcn->proberesp_ies_len =
  2723. nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  2724. }
  2725. if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
  2726. bcn->assocresp_ies =
  2727. nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  2728. bcn->assocresp_ies_len =
  2729. nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  2730. }
  2731. if (attrs[NL80211_ATTR_PROBE_RESP]) {
  2732. bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
  2733. bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
  2734. }
  2735. return 0;
  2736. }
  2737. static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
  2738. struct cfg80211_ap_settings *params)
  2739. {
  2740. struct wireless_dev *wdev;
  2741. bool ret = false;
  2742. list_for_each_entry(wdev, &rdev->wdev_list, list) {
  2743. if (wdev->iftype != NL80211_IFTYPE_AP &&
  2744. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  2745. continue;
  2746. if (!wdev->preset_chandef.chan)
  2747. continue;
  2748. params->chandef = wdev->preset_chandef;
  2749. ret = true;
  2750. break;
  2751. }
  2752. return ret;
  2753. }
  2754. static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
  2755. enum nl80211_auth_type auth_type,
  2756. enum nl80211_commands cmd)
  2757. {
  2758. if (auth_type > NL80211_AUTHTYPE_MAX)
  2759. return false;
  2760. switch (cmd) {
  2761. case NL80211_CMD_AUTHENTICATE:
  2762. if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
  2763. auth_type == NL80211_AUTHTYPE_SAE)
  2764. return false;
  2765. return true;
  2766. case NL80211_CMD_CONNECT:
  2767. case NL80211_CMD_START_AP:
  2768. /* SAE not supported yet */
  2769. if (auth_type == NL80211_AUTHTYPE_SAE)
  2770. return false;
  2771. return true;
  2772. default:
  2773. return false;
  2774. }
  2775. }
  2776. static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
  2777. {
  2778. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2779. struct net_device *dev = info->user_ptr[1];
  2780. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2781. struct cfg80211_ap_settings params;
  2782. int err;
  2783. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2784. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2785. return -EOPNOTSUPP;
  2786. if (!rdev->ops->start_ap)
  2787. return -EOPNOTSUPP;
  2788. if (wdev->beacon_interval)
  2789. return -EALREADY;
  2790. memset(&params, 0, sizeof(params));
  2791. /* these are required for START_AP */
  2792. if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
  2793. !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
  2794. !info->attrs[NL80211_ATTR_BEACON_HEAD])
  2795. return -EINVAL;
  2796. err = nl80211_parse_beacon(info->attrs, &params.beacon);
  2797. if (err)
  2798. return err;
  2799. params.beacon_interval =
  2800. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  2801. params.dtim_period =
  2802. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  2803. err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
  2804. if (err)
  2805. return err;
  2806. /*
  2807. * In theory, some of these attributes should be required here
  2808. * but since they were not used when the command was originally
  2809. * added, keep them optional for old user space programs to let
  2810. * them continue to work with drivers that do not need the
  2811. * additional information -- drivers must check!
  2812. */
  2813. if (info->attrs[NL80211_ATTR_SSID]) {
  2814. params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  2815. params.ssid_len =
  2816. nla_len(info->attrs[NL80211_ATTR_SSID]);
  2817. if (params.ssid_len == 0 ||
  2818. params.ssid_len > IEEE80211_MAX_SSID_LEN)
  2819. return -EINVAL;
  2820. }
  2821. if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
  2822. params.hidden_ssid = nla_get_u32(
  2823. info->attrs[NL80211_ATTR_HIDDEN_SSID]);
  2824. if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
  2825. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
  2826. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
  2827. return -EINVAL;
  2828. }
  2829. params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  2830. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  2831. params.auth_type = nla_get_u32(
  2832. info->attrs[NL80211_ATTR_AUTH_TYPE]);
  2833. if (!nl80211_valid_auth_type(rdev, params.auth_type,
  2834. NL80211_CMD_START_AP))
  2835. return -EINVAL;
  2836. } else
  2837. params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  2838. err = nl80211_crypto_settings(rdev, info, &params.crypto,
  2839. NL80211_MAX_NR_CIPHER_SUITES);
  2840. if (err)
  2841. return err;
  2842. if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
  2843. if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
  2844. return -EOPNOTSUPP;
  2845. params.inactivity_timeout = nla_get_u16(
  2846. info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
  2847. }
  2848. if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
  2849. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2850. return -EINVAL;
  2851. params.p2p_ctwindow =
  2852. nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
  2853. if (params.p2p_ctwindow > 127)
  2854. return -EINVAL;
  2855. if (params.p2p_ctwindow != 0 &&
  2856. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
  2857. return -EINVAL;
  2858. }
  2859. if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
  2860. u8 tmp;
  2861. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2862. return -EINVAL;
  2863. tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
  2864. if (tmp > 1)
  2865. return -EINVAL;
  2866. params.p2p_opp_ps = tmp;
  2867. if (params.p2p_opp_ps != 0 &&
  2868. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
  2869. return -EINVAL;
  2870. }
  2871. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  2872. err = nl80211_parse_chandef(rdev, info, &params.chandef);
  2873. if (err)
  2874. return err;
  2875. } else if (wdev->preset_chandef.chan) {
  2876. params.chandef = wdev->preset_chandef;
  2877. } else if (!nl80211_get_ap_channel(rdev, &params))
  2878. return -EINVAL;
  2879. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
  2880. wdev->iftype))
  2881. return -EINVAL;
  2882. if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
  2883. params.acl = parse_acl_data(&rdev->wiphy, info);
  2884. if (IS_ERR(params.acl))
  2885. return PTR_ERR(params.acl);
  2886. }
  2887. if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
  2888. params.smps_mode =
  2889. nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
  2890. switch (params.smps_mode) {
  2891. case NL80211_SMPS_OFF:
  2892. break;
  2893. case NL80211_SMPS_STATIC:
  2894. if (!(rdev->wiphy.features &
  2895. NL80211_FEATURE_STATIC_SMPS))
  2896. return -EINVAL;
  2897. break;
  2898. case NL80211_SMPS_DYNAMIC:
  2899. if (!(rdev->wiphy.features &
  2900. NL80211_FEATURE_DYNAMIC_SMPS))
  2901. return -EINVAL;
  2902. break;
  2903. default:
  2904. return -EINVAL;
  2905. }
  2906. } else {
  2907. params.smps_mode = NL80211_SMPS_OFF;
  2908. }
  2909. wdev_lock(wdev);
  2910. err = rdev_start_ap(rdev, dev, &params);
  2911. if (!err) {
  2912. wdev->preset_chandef = params.chandef;
  2913. wdev->beacon_interval = params.beacon_interval;
  2914. wdev->chandef = params.chandef;
  2915. wdev->ssid_len = params.ssid_len;
  2916. memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
  2917. }
  2918. wdev_unlock(wdev);
  2919. kfree(params.acl);
  2920. return err;
  2921. }
  2922. static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
  2923. {
  2924. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2925. struct net_device *dev = info->user_ptr[1];
  2926. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2927. struct cfg80211_beacon_data params;
  2928. int err;
  2929. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2930. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2931. return -EOPNOTSUPP;
  2932. if (!rdev->ops->change_beacon)
  2933. return -EOPNOTSUPP;
  2934. if (!wdev->beacon_interval)
  2935. return -EINVAL;
  2936. err = nl80211_parse_beacon(info->attrs, &params);
  2937. if (err)
  2938. return err;
  2939. wdev_lock(wdev);
  2940. err = rdev_change_beacon(rdev, dev, &params);
  2941. wdev_unlock(wdev);
  2942. return err;
  2943. }
  2944. static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
  2945. {
  2946. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2947. struct net_device *dev = info->user_ptr[1];
  2948. return cfg80211_stop_ap(rdev, dev, false);
  2949. }
  2950. static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
  2951. [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
  2952. [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
  2953. [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
  2954. [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
  2955. [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
  2956. [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
  2957. };
  2958. static int parse_station_flags(struct genl_info *info,
  2959. enum nl80211_iftype iftype,
  2960. struct station_parameters *params)
  2961. {
  2962. struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
  2963. struct nlattr *nla;
  2964. int flag;
  2965. /*
  2966. * Try parsing the new attribute first so userspace
  2967. * can specify both for older kernels.
  2968. */
  2969. nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
  2970. if (nla) {
  2971. struct nl80211_sta_flag_update *sta_flags;
  2972. sta_flags = nla_data(nla);
  2973. params->sta_flags_mask = sta_flags->mask;
  2974. params->sta_flags_set = sta_flags->set;
  2975. params->sta_flags_set &= params->sta_flags_mask;
  2976. if ((params->sta_flags_mask |
  2977. params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
  2978. return -EINVAL;
  2979. return 0;
  2980. }
  2981. /* if present, parse the old attribute */
  2982. nla = info->attrs[NL80211_ATTR_STA_FLAGS];
  2983. if (!nla)
  2984. return 0;
  2985. if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
  2986. nla, sta_flags_policy))
  2987. return -EINVAL;
  2988. /*
  2989. * Only allow certain flags for interface types so that
  2990. * other attributes are silently ignored. Remember that
  2991. * this is backward compatibility code with old userspace
  2992. * and shouldn't be hit in other cases anyway.
  2993. */
  2994. switch (iftype) {
  2995. case NL80211_IFTYPE_AP:
  2996. case NL80211_IFTYPE_AP_VLAN:
  2997. case NL80211_IFTYPE_P2P_GO:
  2998. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  2999. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  3000. BIT(NL80211_STA_FLAG_WME) |
  3001. BIT(NL80211_STA_FLAG_MFP);
  3002. break;
  3003. case NL80211_IFTYPE_P2P_CLIENT:
  3004. case NL80211_IFTYPE_STATION:
  3005. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3006. BIT(NL80211_STA_FLAG_TDLS_PEER);
  3007. break;
  3008. case NL80211_IFTYPE_MESH_POINT:
  3009. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3010. BIT(NL80211_STA_FLAG_MFP) |
  3011. BIT(NL80211_STA_FLAG_AUTHORIZED);
  3012. default:
  3013. return -EINVAL;
  3014. }
  3015. for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
  3016. if (flags[flag]) {
  3017. params->sta_flags_set |= (1<<flag);
  3018. /* no longer support new API additions in old API */
  3019. if (flag > NL80211_STA_FLAG_MAX_OLD_API)
  3020. return -EINVAL;
  3021. }
  3022. }
  3023. return 0;
  3024. }
  3025. static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
  3026. int attr)
  3027. {
  3028. struct nlattr *rate;
  3029. u32 bitrate;
  3030. u16 bitrate_compat;
  3031. enum nl80211_attrs rate_flg;
  3032. rate = nla_nest_start(msg, attr);
  3033. if (!rate)
  3034. return false;
  3035. /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
  3036. bitrate = cfg80211_calculate_bitrate(info);
  3037. /* report 16-bit bitrate only if we can */
  3038. bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
  3039. if (bitrate > 0 &&
  3040. nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
  3041. return false;
  3042. if (bitrate_compat > 0 &&
  3043. nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
  3044. return false;
  3045. switch (info->bw) {
  3046. case RATE_INFO_BW_5:
  3047. rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
  3048. break;
  3049. case RATE_INFO_BW_10:
  3050. rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
  3051. break;
  3052. default:
  3053. WARN_ON(1);
  3054. /* fall through */
  3055. case RATE_INFO_BW_20:
  3056. rate_flg = 0;
  3057. break;
  3058. case RATE_INFO_BW_40:
  3059. rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
  3060. break;
  3061. case RATE_INFO_BW_80:
  3062. rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
  3063. break;
  3064. case RATE_INFO_BW_160:
  3065. rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
  3066. break;
  3067. }
  3068. if (rate_flg && nla_put_flag(msg, rate_flg))
  3069. return false;
  3070. if (info->flags & RATE_INFO_FLAGS_MCS) {
  3071. if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
  3072. return false;
  3073. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  3074. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  3075. return false;
  3076. } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
  3077. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
  3078. return false;
  3079. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
  3080. return false;
  3081. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  3082. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  3083. return false;
  3084. }
  3085. nla_nest_end(msg, rate);
  3086. return true;
  3087. }
  3088. static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
  3089. int id)
  3090. {
  3091. void *attr;
  3092. int i = 0;
  3093. if (!mask)
  3094. return true;
  3095. attr = nla_nest_start(msg, id);
  3096. if (!attr)
  3097. return false;
  3098. for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
  3099. if (!(mask & BIT(i)))
  3100. continue;
  3101. if (nla_put_u8(msg, i, signal[i]))
  3102. return false;
  3103. }
  3104. nla_nest_end(msg, attr);
  3105. return true;
  3106. }
  3107. static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
  3108. u32 seq, int flags,
  3109. struct cfg80211_registered_device *rdev,
  3110. struct net_device *dev,
  3111. const u8 *mac_addr, struct station_info *sinfo)
  3112. {
  3113. void *hdr;
  3114. struct nlattr *sinfoattr, *bss_param;
  3115. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  3116. if (!hdr)
  3117. return -1;
  3118. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  3119. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
  3120. nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
  3121. goto nla_put_failure;
  3122. sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
  3123. if (!sinfoattr)
  3124. goto nla_put_failure;
  3125. #define PUT_SINFO(attr, memb, type) do { \
  3126. if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
  3127. nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
  3128. sinfo->memb)) \
  3129. goto nla_put_failure; \
  3130. } while (0)
  3131. PUT_SINFO(CONNECTED_TIME, connected_time, u32);
  3132. PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
  3133. if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
  3134. BIT(NL80211_STA_INFO_RX_BYTES64)) &&
  3135. nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
  3136. (u32)sinfo->rx_bytes))
  3137. goto nla_put_failure;
  3138. if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
  3139. BIT(NL80211_STA_INFO_TX_BYTES64)) &&
  3140. nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
  3141. (u32)sinfo->tx_bytes))
  3142. goto nla_put_failure;
  3143. PUT_SINFO(RX_BYTES64, rx_bytes, u64);
  3144. PUT_SINFO(TX_BYTES64, tx_bytes, u64);
  3145. PUT_SINFO(LLID, llid, u16);
  3146. PUT_SINFO(PLID, plid, u16);
  3147. PUT_SINFO(PLINK_STATE, plink_state, u8);
  3148. switch (rdev->wiphy.signal_type) {
  3149. case CFG80211_SIGNAL_TYPE_MBM:
  3150. PUT_SINFO(SIGNAL, signal, u8);
  3151. PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
  3152. break;
  3153. default:
  3154. break;
  3155. }
  3156. if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
  3157. if (!nl80211_put_signal(msg, sinfo->chains,
  3158. sinfo->chain_signal,
  3159. NL80211_STA_INFO_CHAIN_SIGNAL))
  3160. goto nla_put_failure;
  3161. }
  3162. if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
  3163. if (!nl80211_put_signal(msg, sinfo->chains,
  3164. sinfo->chain_signal_avg,
  3165. NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
  3166. goto nla_put_failure;
  3167. }
  3168. if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
  3169. if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
  3170. NL80211_STA_INFO_TX_BITRATE))
  3171. goto nla_put_failure;
  3172. }
  3173. if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
  3174. if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
  3175. NL80211_STA_INFO_RX_BITRATE))
  3176. goto nla_put_failure;
  3177. }
  3178. PUT_SINFO(RX_PACKETS, rx_packets, u32);
  3179. PUT_SINFO(TX_PACKETS, tx_packets, u32);
  3180. PUT_SINFO(TX_RETRIES, tx_retries, u32);
  3181. PUT_SINFO(TX_FAILED, tx_failed, u32);
  3182. PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
  3183. PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
  3184. PUT_SINFO(LOCAL_PM, local_pm, u32);
  3185. PUT_SINFO(PEER_PM, peer_pm, u32);
  3186. PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
  3187. if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
  3188. bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
  3189. if (!bss_param)
  3190. goto nla_put_failure;
  3191. if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
  3192. nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
  3193. ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
  3194. nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
  3195. ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
  3196. nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
  3197. nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
  3198. sinfo->bss_param.dtim_period) ||
  3199. nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
  3200. sinfo->bss_param.beacon_interval))
  3201. goto nla_put_failure;
  3202. nla_nest_end(msg, bss_param);
  3203. }
  3204. if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
  3205. nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
  3206. sizeof(struct nl80211_sta_flag_update),
  3207. &sinfo->sta_flags))
  3208. goto nla_put_failure;
  3209. PUT_SINFO(T_OFFSET, t_offset, u64);
  3210. PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
  3211. PUT_SINFO(BEACON_RX, rx_beacon, u64);
  3212. PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
  3213. #undef PUT_SINFO
  3214. if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
  3215. struct nlattr *tidsattr;
  3216. int tid;
  3217. tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
  3218. if (!tidsattr)
  3219. goto nla_put_failure;
  3220. for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
  3221. struct cfg80211_tid_stats *tidstats;
  3222. struct nlattr *tidattr;
  3223. tidstats = &sinfo->pertid[tid];
  3224. if (!tidstats->filled)
  3225. continue;
  3226. tidattr = nla_nest_start(msg, tid + 1);
  3227. if (!tidattr)
  3228. goto nla_put_failure;
  3229. #define PUT_TIDVAL(attr, memb, type) do { \
  3230. if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
  3231. nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
  3232. tidstats->memb)) \
  3233. goto nla_put_failure; \
  3234. } while (0)
  3235. PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
  3236. PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
  3237. PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
  3238. PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
  3239. #undef PUT_TIDVAL
  3240. nla_nest_end(msg, tidattr);
  3241. }
  3242. nla_nest_end(msg, tidsattr);
  3243. }
  3244. nla_nest_end(msg, sinfoattr);
  3245. if (sinfo->assoc_req_ies_len &&
  3246. nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
  3247. sinfo->assoc_req_ies))
  3248. goto nla_put_failure;
  3249. genlmsg_end(msg, hdr);
  3250. return 0;
  3251. nla_put_failure:
  3252. genlmsg_cancel(msg, hdr);
  3253. return -EMSGSIZE;
  3254. }
  3255. static int nl80211_dump_station(struct sk_buff *skb,
  3256. struct netlink_callback *cb)
  3257. {
  3258. struct station_info sinfo;
  3259. struct cfg80211_registered_device *rdev;
  3260. struct wireless_dev *wdev;
  3261. u8 mac_addr[ETH_ALEN];
  3262. int sta_idx = cb->args[2];
  3263. int err;
  3264. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  3265. if (err)
  3266. return err;
  3267. if (!wdev->netdev) {
  3268. err = -EINVAL;
  3269. goto out_err;
  3270. }
  3271. if (!rdev->ops->dump_station) {
  3272. err = -EOPNOTSUPP;
  3273. goto out_err;
  3274. }
  3275. while (1) {
  3276. memset(&sinfo, 0, sizeof(sinfo));
  3277. err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
  3278. mac_addr, &sinfo);
  3279. if (err == -ENOENT)
  3280. break;
  3281. if (err)
  3282. goto out_err;
  3283. if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
  3284. NETLINK_CB(cb->skb).portid,
  3285. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  3286. rdev, wdev->netdev, mac_addr,
  3287. &sinfo) < 0)
  3288. goto out;
  3289. sta_idx++;
  3290. }
  3291. out:
  3292. cb->args[2] = sta_idx;
  3293. err = skb->len;
  3294. out_err:
  3295. nl80211_finish_wdev_dump(rdev);
  3296. return err;
  3297. }
  3298. static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
  3299. {
  3300. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3301. struct net_device *dev = info->user_ptr[1];
  3302. struct station_info sinfo;
  3303. struct sk_buff *msg;
  3304. u8 *mac_addr = NULL;
  3305. int err;
  3306. memset(&sinfo, 0, sizeof(sinfo));
  3307. if (!info->attrs[NL80211_ATTR_MAC])
  3308. return -EINVAL;
  3309. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3310. if (!rdev->ops->get_station)
  3311. return -EOPNOTSUPP;
  3312. err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
  3313. if (err)
  3314. return err;
  3315. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3316. if (!msg)
  3317. return -ENOMEM;
  3318. if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
  3319. info->snd_portid, info->snd_seq, 0,
  3320. rdev, dev, mac_addr, &sinfo) < 0) {
  3321. nlmsg_free(msg);
  3322. return -ENOBUFS;
  3323. }
  3324. return genlmsg_reply(msg, info);
  3325. }
  3326. int cfg80211_check_station_change(struct wiphy *wiphy,
  3327. struct station_parameters *params,
  3328. enum cfg80211_station_type statype)
  3329. {
  3330. if (params->listen_interval != -1)
  3331. return -EINVAL;
  3332. if (params->aid &&
  3333. !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3334. return -EINVAL;
  3335. /* When you run into this, adjust the code below for the new flag */
  3336. BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
  3337. switch (statype) {
  3338. case CFG80211_STA_MESH_PEER_KERNEL:
  3339. case CFG80211_STA_MESH_PEER_USER:
  3340. /*
  3341. * No ignoring the TDLS flag here -- the userspace mesh
  3342. * code doesn't have the bug of including TDLS in the
  3343. * mask everywhere.
  3344. */
  3345. if (params->sta_flags_mask &
  3346. ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3347. BIT(NL80211_STA_FLAG_MFP) |
  3348. BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3349. return -EINVAL;
  3350. break;
  3351. case CFG80211_STA_TDLS_PEER_SETUP:
  3352. case CFG80211_STA_TDLS_PEER_ACTIVE:
  3353. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3354. return -EINVAL;
  3355. /* ignore since it can't change */
  3356. params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3357. break;
  3358. default:
  3359. /* disallow mesh-specific things */
  3360. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
  3361. return -EINVAL;
  3362. if (params->local_pm)
  3363. return -EINVAL;
  3364. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  3365. return -EINVAL;
  3366. }
  3367. if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
  3368. statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
  3369. /* TDLS can't be set, ... */
  3370. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  3371. return -EINVAL;
  3372. /*
  3373. * ... but don't bother the driver with it. This works around
  3374. * a hostapd/wpa_supplicant issue -- it always includes the
  3375. * TLDS_PEER flag in the mask even for AP mode.
  3376. */
  3377. params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3378. }
  3379. if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
  3380. /* reject other things that can't change */
  3381. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
  3382. return -EINVAL;
  3383. if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
  3384. return -EINVAL;
  3385. if (params->supported_rates)
  3386. return -EINVAL;
  3387. if (params->ext_capab || params->ht_capa || params->vht_capa)
  3388. return -EINVAL;
  3389. }
  3390. if (statype != CFG80211_STA_AP_CLIENT) {
  3391. if (params->vlan)
  3392. return -EINVAL;
  3393. }
  3394. switch (statype) {
  3395. case CFG80211_STA_AP_MLME_CLIENT:
  3396. /* Use this only for authorizing/unauthorizing a station */
  3397. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3398. return -EOPNOTSUPP;
  3399. break;
  3400. case CFG80211_STA_AP_CLIENT:
  3401. /* accept only the listed bits */
  3402. if (params->sta_flags_mask &
  3403. ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3404. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3405. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  3406. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  3407. BIT(NL80211_STA_FLAG_WME) |
  3408. BIT(NL80211_STA_FLAG_MFP)))
  3409. return -EINVAL;
  3410. /* but authenticated/associated only if driver handles it */
  3411. if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
  3412. params->sta_flags_mask &
  3413. (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3414. BIT(NL80211_STA_FLAG_ASSOCIATED)))
  3415. return -EINVAL;
  3416. break;
  3417. case CFG80211_STA_IBSS:
  3418. case CFG80211_STA_AP_STA:
  3419. /* reject any changes other than AUTHORIZED */
  3420. if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
  3421. return -EINVAL;
  3422. break;
  3423. case CFG80211_STA_TDLS_PEER_SETUP:
  3424. /* reject any changes other than AUTHORIZED or WME */
  3425. if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3426. BIT(NL80211_STA_FLAG_WME)))
  3427. return -EINVAL;
  3428. /* force (at least) rates when authorizing */
  3429. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
  3430. !params->supported_rates)
  3431. return -EINVAL;
  3432. break;
  3433. case CFG80211_STA_TDLS_PEER_ACTIVE:
  3434. /* reject any changes */
  3435. return -EINVAL;
  3436. case CFG80211_STA_MESH_PEER_KERNEL:
  3437. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  3438. return -EINVAL;
  3439. break;
  3440. case CFG80211_STA_MESH_PEER_USER:
  3441. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
  3442. params->plink_action != NL80211_PLINK_ACTION_BLOCK)
  3443. return -EINVAL;
  3444. break;
  3445. }
  3446. return 0;
  3447. }
  3448. EXPORT_SYMBOL(cfg80211_check_station_change);
  3449. /*
  3450. * Get vlan interface making sure it is running and on the right wiphy.
  3451. */
  3452. static struct net_device *get_vlan(struct genl_info *info,
  3453. struct cfg80211_registered_device *rdev)
  3454. {
  3455. struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
  3456. struct net_device *v;
  3457. int ret;
  3458. if (!vlanattr)
  3459. return NULL;
  3460. v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
  3461. if (!v)
  3462. return ERR_PTR(-ENODEV);
  3463. if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
  3464. ret = -EINVAL;
  3465. goto error;
  3466. }
  3467. if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  3468. v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3469. v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
  3470. ret = -EINVAL;
  3471. goto error;
  3472. }
  3473. if (!netif_running(v)) {
  3474. ret = -ENETDOWN;
  3475. goto error;
  3476. }
  3477. return v;
  3478. error:
  3479. dev_put(v);
  3480. return ERR_PTR(ret);
  3481. }
  3482. static const struct nla_policy
  3483. nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
  3484. [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
  3485. [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
  3486. };
  3487. static int nl80211_parse_sta_wme(struct genl_info *info,
  3488. struct station_parameters *params)
  3489. {
  3490. struct nlattr *tb[NL80211_STA_WME_MAX + 1];
  3491. struct nlattr *nla;
  3492. int err;
  3493. /* parse WME attributes if present */
  3494. if (!info->attrs[NL80211_ATTR_STA_WME])
  3495. return 0;
  3496. nla = info->attrs[NL80211_ATTR_STA_WME];
  3497. err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
  3498. nl80211_sta_wme_policy);
  3499. if (err)
  3500. return err;
  3501. if (tb[NL80211_STA_WME_UAPSD_QUEUES])
  3502. params->uapsd_queues = nla_get_u8(
  3503. tb[NL80211_STA_WME_UAPSD_QUEUES]);
  3504. if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  3505. return -EINVAL;
  3506. if (tb[NL80211_STA_WME_MAX_SP])
  3507. params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
  3508. if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  3509. return -EINVAL;
  3510. params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
  3511. return 0;
  3512. }
  3513. static int nl80211_parse_sta_channel_info(struct genl_info *info,
  3514. struct station_parameters *params)
  3515. {
  3516. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
  3517. params->supported_channels =
  3518. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  3519. params->supported_channels_len =
  3520. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  3521. /*
  3522. * Need to include at least one (first channel, number of
  3523. * channels) tuple for each subband, and must have proper
  3524. * tuples for the rest of the data as well.
  3525. */
  3526. if (params->supported_channels_len < 2)
  3527. return -EINVAL;
  3528. if (params->supported_channels_len % 2)
  3529. return -EINVAL;
  3530. }
  3531. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
  3532. params->supported_oper_classes =
  3533. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  3534. params->supported_oper_classes_len =
  3535. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  3536. /*
  3537. * The value of the Length field of the Supported Operating
  3538. * Classes element is between 2 and 253.
  3539. */
  3540. if (params->supported_oper_classes_len < 2 ||
  3541. params->supported_oper_classes_len > 253)
  3542. return -EINVAL;
  3543. }
  3544. return 0;
  3545. }
  3546. static int nl80211_set_station_tdls(struct genl_info *info,
  3547. struct station_parameters *params)
  3548. {
  3549. int err;
  3550. /* Dummy STA entry gets updated once the peer capabilities are known */
  3551. if (info->attrs[NL80211_ATTR_PEER_AID])
  3552. params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  3553. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  3554. params->ht_capa =
  3555. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  3556. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  3557. params->vht_capa =
  3558. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  3559. err = nl80211_parse_sta_channel_info(info, params);
  3560. if (err)
  3561. return err;
  3562. return nl80211_parse_sta_wme(info, params);
  3563. }
  3564. static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
  3565. {
  3566. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3567. struct net_device *dev = info->user_ptr[1];
  3568. struct station_parameters params;
  3569. u8 *mac_addr;
  3570. int err;
  3571. memset(&params, 0, sizeof(params));
  3572. params.listen_interval = -1;
  3573. if (!rdev->ops->change_station)
  3574. return -EOPNOTSUPP;
  3575. if (info->attrs[NL80211_ATTR_STA_AID])
  3576. return -EINVAL;
  3577. if (!info->attrs[NL80211_ATTR_MAC])
  3578. return -EINVAL;
  3579. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3580. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
  3581. params.supported_rates =
  3582. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  3583. params.supported_rates_len =
  3584. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  3585. }
  3586. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  3587. params.capability =
  3588. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  3589. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  3590. }
  3591. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  3592. params.ext_capab =
  3593. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  3594. params.ext_capab_len =
  3595. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  3596. }
  3597. if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  3598. return -EINVAL;
  3599. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  3600. return -EINVAL;
  3601. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
  3602. params.plink_action =
  3603. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  3604. if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
  3605. return -EINVAL;
  3606. }
  3607. if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
  3608. params.plink_state =
  3609. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
  3610. if (params.plink_state >= NUM_NL80211_PLINK_STATES)
  3611. return -EINVAL;
  3612. params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
  3613. }
  3614. if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
  3615. enum nl80211_mesh_power_mode pm = nla_get_u32(
  3616. info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
  3617. if (pm <= NL80211_MESH_POWER_UNKNOWN ||
  3618. pm > NL80211_MESH_POWER_MAX)
  3619. return -EINVAL;
  3620. params.local_pm = pm;
  3621. }
  3622. /* Include parameters for TDLS peer (will check later) */
  3623. err = nl80211_set_station_tdls(info, &params);
  3624. if (err)
  3625. return err;
  3626. params.vlan = get_vlan(info, rdev);
  3627. if (IS_ERR(params.vlan))
  3628. return PTR_ERR(params.vlan);
  3629. switch (dev->ieee80211_ptr->iftype) {
  3630. case NL80211_IFTYPE_AP:
  3631. case NL80211_IFTYPE_AP_VLAN:
  3632. case NL80211_IFTYPE_P2P_GO:
  3633. case NL80211_IFTYPE_P2P_CLIENT:
  3634. case NL80211_IFTYPE_STATION:
  3635. case NL80211_IFTYPE_ADHOC:
  3636. case NL80211_IFTYPE_MESH_POINT:
  3637. break;
  3638. default:
  3639. err = -EOPNOTSUPP;
  3640. goto out_put_vlan;
  3641. }
  3642. /* driver will call cfg80211_check_station_change() */
  3643. err = rdev_change_station(rdev, dev, mac_addr, &params);
  3644. out_put_vlan:
  3645. if (params.vlan)
  3646. dev_put(params.vlan);
  3647. return err;
  3648. }
  3649. static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
  3650. {
  3651. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3652. int err;
  3653. struct net_device *dev = info->user_ptr[1];
  3654. struct station_parameters params;
  3655. u8 *mac_addr = NULL;
  3656. memset(&params, 0, sizeof(params));
  3657. if (!rdev->ops->add_station)
  3658. return -EOPNOTSUPP;
  3659. if (!info->attrs[NL80211_ATTR_MAC])
  3660. return -EINVAL;
  3661. if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  3662. return -EINVAL;
  3663. if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
  3664. return -EINVAL;
  3665. if (!info->attrs[NL80211_ATTR_STA_AID] &&
  3666. !info->attrs[NL80211_ATTR_PEER_AID])
  3667. return -EINVAL;
  3668. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3669. params.supported_rates =
  3670. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  3671. params.supported_rates_len =
  3672. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  3673. params.listen_interval =
  3674. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  3675. if (info->attrs[NL80211_ATTR_PEER_AID])
  3676. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  3677. else
  3678. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
  3679. if (!params.aid || params.aid > IEEE80211_MAX_AID)
  3680. return -EINVAL;
  3681. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  3682. params.capability =
  3683. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  3684. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  3685. }
  3686. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  3687. params.ext_capab =
  3688. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  3689. params.ext_capab_len =
  3690. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  3691. }
  3692. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  3693. params.ht_capa =
  3694. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  3695. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  3696. params.vht_capa =
  3697. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  3698. if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
  3699. params.opmode_notif_used = true;
  3700. params.opmode_notif =
  3701. nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
  3702. }
  3703. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
  3704. params.plink_action =
  3705. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  3706. if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
  3707. return -EINVAL;
  3708. }
  3709. err = nl80211_parse_sta_channel_info(info, &params);
  3710. if (err)
  3711. return err;
  3712. err = nl80211_parse_sta_wme(info, &params);
  3713. if (err)
  3714. return err;
  3715. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  3716. return -EINVAL;
  3717. /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
  3718. * as userspace might just pass through the capabilities from the IEs
  3719. * directly, rather than enforcing this restriction and returning an
  3720. * error in this case.
  3721. */
  3722. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
  3723. params.ht_capa = NULL;
  3724. params.vht_capa = NULL;
  3725. }
  3726. /* When you run into this, adjust the code below for the new flag */
  3727. BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
  3728. switch (dev->ieee80211_ptr->iftype) {
  3729. case NL80211_IFTYPE_AP:
  3730. case NL80211_IFTYPE_AP_VLAN:
  3731. case NL80211_IFTYPE_P2P_GO:
  3732. /* ignore WME attributes if iface/sta is not capable */
  3733. if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
  3734. !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
  3735. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  3736. /* TDLS peers cannot be added */
  3737. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  3738. info->attrs[NL80211_ATTR_PEER_AID])
  3739. return -EINVAL;
  3740. /* but don't bother the driver with it */
  3741. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3742. /* allow authenticated/associated only if driver handles it */
  3743. if (!(rdev->wiphy.features &
  3744. NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
  3745. params.sta_flags_mask &
  3746. (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3747. BIT(NL80211_STA_FLAG_ASSOCIATED)))
  3748. return -EINVAL;
  3749. /* must be last in here for error handling */
  3750. params.vlan = get_vlan(info, rdev);
  3751. if (IS_ERR(params.vlan))
  3752. return PTR_ERR(params.vlan);
  3753. break;
  3754. case NL80211_IFTYPE_MESH_POINT:
  3755. /* ignore uAPSD data */
  3756. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  3757. /* associated is disallowed */
  3758. if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
  3759. return -EINVAL;
  3760. /* TDLS peers cannot be added */
  3761. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  3762. info->attrs[NL80211_ATTR_PEER_AID])
  3763. return -EINVAL;
  3764. break;
  3765. case NL80211_IFTYPE_STATION:
  3766. case NL80211_IFTYPE_P2P_CLIENT:
  3767. /* ignore uAPSD data */
  3768. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  3769. /* these are disallowed */
  3770. if (params.sta_flags_mask &
  3771. (BIT(NL80211_STA_FLAG_ASSOCIATED) |
  3772. BIT(NL80211_STA_FLAG_AUTHENTICATED)))
  3773. return -EINVAL;
  3774. /* Only TDLS peers can be added */
  3775. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3776. return -EINVAL;
  3777. /* Can only add if TDLS ... */
  3778. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
  3779. return -EOPNOTSUPP;
  3780. /* ... with external setup is supported */
  3781. if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
  3782. return -EOPNOTSUPP;
  3783. /*
  3784. * Older wpa_supplicant versions always mark the TDLS peer
  3785. * as authorized, but it shouldn't yet be.
  3786. */
  3787. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
  3788. break;
  3789. default:
  3790. return -EOPNOTSUPP;
  3791. }
  3792. /* be aware of params.vlan when changing code here */
  3793. err = rdev_add_station(rdev, dev, mac_addr, &params);
  3794. if (params.vlan)
  3795. dev_put(params.vlan);
  3796. return err;
  3797. }
  3798. static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
  3799. {
  3800. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3801. struct net_device *dev = info->user_ptr[1];
  3802. struct station_del_parameters params;
  3803. memset(&params, 0, sizeof(params));
  3804. if (info->attrs[NL80211_ATTR_MAC])
  3805. params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3806. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3807. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  3808. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  3809. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3810. return -EINVAL;
  3811. if (!rdev->ops->del_station)
  3812. return -EOPNOTSUPP;
  3813. if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
  3814. params.subtype =
  3815. nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
  3816. if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
  3817. params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
  3818. return -EINVAL;
  3819. } else {
  3820. /* Default to Deauthentication frame */
  3821. params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
  3822. }
  3823. if (info->attrs[NL80211_ATTR_REASON_CODE]) {
  3824. params.reason_code =
  3825. nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  3826. if (params.reason_code == 0)
  3827. return -EINVAL; /* 0 is reserved */
  3828. } else {
  3829. /* Default to reason code 2 */
  3830. params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
  3831. }
  3832. return rdev_del_station(rdev, dev, &params);
  3833. }
  3834. static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
  3835. int flags, struct net_device *dev,
  3836. u8 *dst, u8 *next_hop,
  3837. struct mpath_info *pinfo)
  3838. {
  3839. void *hdr;
  3840. struct nlattr *pinfoattr;
  3841. hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
  3842. if (!hdr)
  3843. return -1;
  3844. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  3845. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
  3846. nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
  3847. nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
  3848. goto nla_put_failure;
  3849. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
  3850. if (!pinfoattr)
  3851. goto nla_put_failure;
  3852. if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
  3853. nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
  3854. pinfo->frame_qlen))
  3855. goto nla_put_failure;
  3856. if (((pinfo->filled & MPATH_INFO_SN) &&
  3857. nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
  3858. ((pinfo->filled & MPATH_INFO_METRIC) &&
  3859. nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
  3860. pinfo->metric)) ||
  3861. ((pinfo->filled & MPATH_INFO_EXPTIME) &&
  3862. nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
  3863. pinfo->exptime)) ||
  3864. ((pinfo->filled & MPATH_INFO_FLAGS) &&
  3865. nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
  3866. pinfo->flags)) ||
  3867. ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
  3868. nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
  3869. pinfo->discovery_timeout)) ||
  3870. ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
  3871. nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
  3872. pinfo->discovery_retries)))
  3873. goto nla_put_failure;
  3874. nla_nest_end(msg, pinfoattr);
  3875. genlmsg_end(msg, hdr);
  3876. return 0;
  3877. nla_put_failure:
  3878. genlmsg_cancel(msg, hdr);
  3879. return -EMSGSIZE;
  3880. }
  3881. static int nl80211_dump_mpath(struct sk_buff *skb,
  3882. struct netlink_callback *cb)
  3883. {
  3884. struct mpath_info pinfo;
  3885. struct cfg80211_registered_device *rdev;
  3886. struct wireless_dev *wdev;
  3887. u8 dst[ETH_ALEN];
  3888. u8 next_hop[ETH_ALEN];
  3889. int path_idx = cb->args[2];
  3890. int err;
  3891. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  3892. if (err)
  3893. return err;
  3894. if (!rdev->ops->dump_mpath) {
  3895. err = -EOPNOTSUPP;
  3896. goto out_err;
  3897. }
  3898. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
  3899. err = -EOPNOTSUPP;
  3900. goto out_err;
  3901. }
  3902. while (1) {
  3903. err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
  3904. next_hop, &pinfo);
  3905. if (err == -ENOENT)
  3906. break;
  3907. if (err)
  3908. goto out_err;
  3909. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
  3910. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  3911. wdev->netdev, dst, next_hop,
  3912. &pinfo) < 0)
  3913. goto out;
  3914. path_idx++;
  3915. }
  3916. out:
  3917. cb->args[2] = path_idx;
  3918. err = skb->len;
  3919. out_err:
  3920. nl80211_finish_wdev_dump(rdev);
  3921. return err;
  3922. }
  3923. static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
  3924. {
  3925. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3926. int err;
  3927. struct net_device *dev = info->user_ptr[1];
  3928. struct mpath_info pinfo;
  3929. struct sk_buff *msg;
  3930. u8 *dst = NULL;
  3931. u8 next_hop[ETH_ALEN];
  3932. memset(&pinfo, 0, sizeof(pinfo));
  3933. if (!info->attrs[NL80211_ATTR_MAC])
  3934. return -EINVAL;
  3935. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3936. if (!rdev->ops->get_mpath)
  3937. return -EOPNOTSUPP;
  3938. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  3939. return -EOPNOTSUPP;
  3940. err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
  3941. if (err)
  3942. return err;
  3943. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3944. if (!msg)
  3945. return -ENOMEM;
  3946. if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
  3947. dev, dst, next_hop, &pinfo) < 0) {
  3948. nlmsg_free(msg);
  3949. return -ENOBUFS;
  3950. }
  3951. return genlmsg_reply(msg, info);
  3952. }
  3953. static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
  3954. {
  3955. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3956. struct net_device *dev = info->user_ptr[1];
  3957. u8 *dst = NULL;
  3958. u8 *next_hop = NULL;
  3959. if (!info->attrs[NL80211_ATTR_MAC])
  3960. return -EINVAL;
  3961. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  3962. return -EINVAL;
  3963. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3964. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  3965. if (!rdev->ops->change_mpath)
  3966. return -EOPNOTSUPP;
  3967. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  3968. return -EOPNOTSUPP;
  3969. return rdev_change_mpath(rdev, dev, dst, next_hop);
  3970. }
  3971. static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
  3972. {
  3973. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3974. struct net_device *dev = info->user_ptr[1];
  3975. u8 *dst = NULL;
  3976. u8 *next_hop = NULL;
  3977. if (!info->attrs[NL80211_ATTR_MAC])
  3978. return -EINVAL;
  3979. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  3980. return -EINVAL;
  3981. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3982. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  3983. if (!rdev->ops->add_mpath)
  3984. return -EOPNOTSUPP;
  3985. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  3986. return -EOPNOTSUPP;
  3987. return rdev_add_mpath(rdev, dev, dst, next_hop);
  3988. }
  3989. static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
  3990. {
  3991. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3992. struct net_device *dev = info->user_ptr[1];
  3993. u8 *dst = NULL;
  3994. if (info->attrs[NL80211_ATTR_MAC])
  3995. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3996. if (!rdev->ops->del_mpath)
  3997. return -EOPNOTSUPP;
  3998. return rdev_del_mpath(rdev, dev, dst);
  3999. }
  4000. static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
  4001. {
  4002. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4003. int err;
  4004. struct net_device *dev = info->user_ptr[1];
  4005. struct mpath_info pinfo;
  4006. struct sk_buff *msg;
  4007. u8 *dst = NULL;
  4008. u8 mpp[ETH_ALEN];
  4009. memset(&pinfo, 0, sizeof(pinfo));
  4010. if (!info->attrs[NL80211_ATTR_MAC])
  4011. return -EINVAL;
  4012. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4013. if (!rdev->ops->get_mpp)
  4014. return -EOPNOTSUPP;
  4015. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4016. return -EOPNOTSUPP;
  4017. err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
  4018. if (err)
  4019. return err;
  4020. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4021. if (!msg)
  4022. return -ENOMEM;
  4023. if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
  4024. dev, dst, mpp, &pinfo) < 0) {
  4025. nlmsg_free(msg);
  4026. return -ENOBUFS;
  4027. }
  4028. return genlmsg_reply(msg, info);
  4029. }
  4030. static int nl80211_dump_mpp(struct sk_buff *skb,
  4031. struct netlink_callback *cb)
  4032. {
  4033. struct mpath_info pinfo;
  4034. struct cfg80211_registered_device *rdev;
  4035. struct wireless_dev *wdev;
  4036. u8 dst[ETH_ALEN];
  4037. u8 mpp[ETH_ALEN];
  4038. int path_idx = cb->args[2];
  4039. int err;
  4040. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  4041. if (err)
  4042. return err;
  4043. if (!rdev->ops->dump_mpp) {
  4044. err = -EOPNOTSUPP;
  4045. goto out_err;
  4046. }
  4047. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
  4048. err = -EOPNOTSUPP;
  4049. goto out_err;
  4050. }
  4051. while (1) {
  4052. err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
  4053. mpp, &pinfo);
  4054. if (err == -ENOENT)
  4055. break;
  4056. if (err)
  4057. goto out_err;
  4058. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
  4059. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4060. wdev->netdev, dst, mpp,
  4061. &pinfo) < 0)
  4062. goto out;
  4063. path_idx++;
  4064. }
  4065. out:
  4066. cb->args[2] = path_idx;
  4067. err = skb->len;
  4068. out_err:
  4069. nl80211_finish_wdev_dump(rdev);
  4070. return err;
  4071. }
  4072. static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
  4073. {
  4074. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4075. struct net_device *dev = info->user_ptr[1];
  4076. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4077. struct bss_parameters params;
  4078. int err;
  4079. memset(&params, 0, sizeof(params));
  4080. /* default to not changing parameters */
  4081. params.use_cts_prot = -1;
  4082. params.use_short_preamble = -1;
  4083. params.use_short_slot_time = -1;
  4084. params.ap_isolate = -1;
  4085. params.ht_opmode = -1;
  4086. params.p2p_ctwindow = -1;
  4087. params.p2p_opp_ps = -1;
  4088. if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
  4089. params.use_cts_prot =
  4090. nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
  4091. if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
  4092. params.use_short_preamble =
  4093. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
  4094. if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
  4095. params.use_short_slot_time =
  4096. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
  4097. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  4098. params.basic_rates =
  4099. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4100. params.basic_rates_len =
  4101. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4102. }
  4103. if (info->attrs[NL80211_ATTR_AP_ISOLATE])
  4104. params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
  4105. if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
  4106. params.ht_opmode =
  4107. nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
  4108. if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
  4109. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4110. return -EINVAL;
  4111. params.p2p_ctwindow =
  4112. nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
  4113. if (params.p2p_ctwindow < 0)
  4114. return -EINVAL;
  4115. if (params.p2p_ctwindow != 0 &&
  4116. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
  4117. return -EINVAL;
  4118. }
  4119. if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
  4120. u8 tmp;
  4121. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4122. return -EINVAL;
  4123. tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
  4124. if (tmp > 1)
  4125. return -EINVAL;
  4126. params.p2p_opp_ps = tmp;
  4127. if (params.p2p_opp_ps &&
  4128. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
  4129. return -EINVAL;
  4130. }
  4131. if (!rdev->ops->change_bss)
  4132. return -EOPNOTSUPP;
  4133. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  4134. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4135. return -EOPNOTSUPP;
  4136. wdev_lock(wdev);
  4137. err = rdev_change_bss(rdev, dev, &params);
  4138. wdev_unlock(wdev);
  4139. return err;
  4140. }
  4141. static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
  4142. [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
  4143. [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
  4144. [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
  4145. [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
  4146. [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
  4147. [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
  4148. [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
  4149. };
  4150. static int parse_reg_rule(struct nlattr *tb[],
  4151. struct ieee80211_reg_rule *reg_rule)
  4152. {
  4153. struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
  4154. struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
  4155. if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
  4156. return -EINVAL;
  4157. if (!tb[NL80211_ATTR_FREQ_RANGE_START])
  4158. return -EINVAL;
  4159. if (!tb[NL80211_ATTR_FREQ_RANGE_END])
  4160. return -EINVAL;
  4161. if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
  4162. return -EINVAL;
  4163. if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
  4164. return -EINVAL;
  4165. reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
  4166. freq_range->start_freq_khz =
  4167. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
  4168. freq_range->end_freq_khz =
  4169. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
  4170. freq_range->max_bandwidth_khz =
  4171. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
  4172. power_rule->max_eirp =
  4173. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
  4174. if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
  4175. power_rule->max_antenna_gain =
  4176. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
  4177. if (tb[NL80211_ATTR_DFS_CAC_TIME])
  4178. reg_rule->dfs_cac_ms =
  4179. nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
  4180. return 0;
  4181. }
  4182. static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
  4183. {
  4184. char *data = NULL;
  4185. bool is_indoor;
  4186. enum nl80211_user_reg_hint_type user_reg_hint_type;
  4187. u32 owner_nlportid;
  4188. /*
  4189. * You should only get this when cfg80211 hasn't yet initialized
  4190. * completely when built-in to the kernel right between the time
  4191. * window between nl80211_init() and regulatory_init(), if that is
  4192. * even possible.
  4193. */
  4194. if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
  4195. return -EINPROGRESS;
  4196. if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
  4197. user_reg_hint_type =
  4198. nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
  4199. else
  4200. user_reg_hint_type = NL80211_USER_REG_HINT_USER;
  4201. switch (user_reg_hint_type) {
  4202. case NL80211_USER_REG_HINT_USER:
  4203. case NL80211_USER_REG_HINT_CELL_BASE:
  4204. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  4205. return -EINVAL;
  4206. data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  4207. return regulatory_hint_user(data, user_reg_hint_type);
  4208. case NL80211_USER_REG_HINT_INDOOR:
  4209. if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
  4210. owner_nlportid = info->snd_portid;
  4211. is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
  4212. } else {
  4213. owner_nlportid = 0;
  4214. is_indoor = true;
  4215. }
  4216. return regulatory_hint_indoor(is_indoor, owner_nlportid);
  4217. default:
  4218. return -EINVAL;
  4219. }
  4220. }
  4221. static int nl80211_get_mesh_config(struct sk_buff *skb,
  4222. struct genl_info *info)
  4223. {
  4224. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4225. struct net_device *dev = info->user_ptr[1];
  4226. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4227. struct mesh_config cur_params;
  4228. int err = 0;
  4229. void *hdr;
  4230. struct nlattr *pinfoattr;
  4231. struct sk_buff *msg;
  4232. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  4233. return -EOPNOTSUPP;
  4234. if (!rdev->ops->get_mesh_config)
  4235. return -EOPNOTSUPP;
  4236. wdev_lock(wdev);
  4237. /* If not connected, get default parameters */
  4238. if (!wdev->mesh_id_len)
  4239. memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
  4240. else
  4241. err = rdev_get_mesh_config(rdev, dev, &cur_params);
  4242. wdev_unlock(wdev);
  4243. if (err)
  4244. return err;
  4245. /* Draw up a netlink message to send back */
  4246. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4247. if (!msg)
  4248. return -ENOMEM;
  4249. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  4250. NL80211_CMD_GET_MESH_CONFIG);
  4251. if (!hdr)
  4252. goto out;
  4253. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
  4254. if (!pinfoattr)
  4255. goto nla_put_failure;
  4256. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  4257. nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
  4258. cur_params.dot11MeshRetryTimeout) ||
  4259. nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  4260. cur_params.dot11MeshConfirmTimeout) ||
  4261. nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
  4262. cur_params.dot11MeshHoldingTimeout) ||
  4263. nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
  4264. cur_params.dot11MeshMaxPeerLinks) ||
  4265. nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
  4266. cur_params.dot11MeshMaxRetries) ||
  4267. nla_put_u8(msg, NL80211_MESHCONF_TTL,
  4268. cur_params.dot11MeshTTL) ||
  4269. nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
  4270. cur_params.element_ttl) ||
  4271. nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  4272. cur_params.auto_open_plinks) ||
  4273. nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
  4274. cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
  4275. nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  4276. cur_params.dot11MeshHWMPmaxPREQretries) ||
  4277. nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
  4278. cur_params.path_refresh_time) ||
  4279. nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  4280. cur_params.min_discovery_timeout) ||
  4281. nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  4282. cur_params.dot11MeshHWMPactivePathTimeout) ||
  4283. nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  4284. cur_params.dot11MeshHWMPpreqMinInterval) ||
  4285. nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  4286. cur_params.dot11MeshHWMPperrMinInterval) ||
  4287. nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  4288. cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
  4289. nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
  4290. cur_params.dot11MeshHWMPRootMode) ||
  4291. nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  4292. cur_params.dot11MeshHWMPRannInterval) ||
  4293. nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  4294. cur_params.dot11MeshGateAnnouncementProtocol) ||
  4295. nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
  4296. cur_params.dot11MeshForwarding) ||
  4297. nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
  4298. cur_params.rssi_threshold) ||
  4299. nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
  4300. cur_params.ht_opmode) ||
  4301. nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  4302. cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
  4303. nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  4304. cur_params.dot11MeshHWMProotInterval) ||
  4305. nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
  4306. cur_params.dot11MeshHWMPconfirmationInterval) ||
  4307. nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
  4308. cur_params.power_mode) ||
  4309. nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
  4310. cur_params.dot11MeshAwakeWindowDuration) ||
  4311. nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
  4312. cur_params.plink_timeout))
  4313. goto nla_put_failure;
  4314. nla_nest_end(msg, pinfoattr);
  4315. genlmsg_end(msg, hdr);
  4316. return genlmsg_reply(msg, info);
  4317. nla_put_failure:
  4318. genlmsg_cancel(msg, hdr);
  4319. out:
  4320. nlmsg_free(msg);
  4321. return -ENOBUFS;
  4322. }
  4323. static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
  4324. [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
  4325. [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
  4326. [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
  4327. [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
  4328. [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
  4329. [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
  4330. [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
  4331. [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
  4332. [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
  4333. [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
  4334. [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
  4335. [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
  4336. [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
  4337. [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
  4338. [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
  4339. [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
  4340. [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
  4341. [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
  4342. [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
  4343. [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
  4344. [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
  4345. [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
  4346. [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
  4347. [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
  4348. [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
  4349. [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
  4350. [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
  4351. [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
  4352. };
  4353. static const struct nla_policy
  4354. nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
  4355. [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
  4356. [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
  4357. [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
  4358. [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
  4359. [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
  4360. [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
  4361. [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
  4362. .len = IEEE80211_MAX_DATA_LEN },
  4363. [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
  4364. };
  4365. static int nl80211_parse_mesh_config(struct genl_info *info,
  4366. struct mesh_config *cfg,
  4367. u32 *mask_out)
  4368. {
  4369. struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
  4370. u32 mask = 0;
  4371. #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
  4372. do { \
  4373. if (tb[attr]) { \
  4374. if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
  4375. return -EINVAL; \
  4376. cfg->param = fn(tb[attr]); \
  4377. mask |= (1 << (attr - 1)); \
  4378. } \
  4379. } while (0)
  4380. if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
  4381. return -EINVAL;
  4382. if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
  4383. info->attrs[NL80211_ATTR_MESH_CONFIG],
  4384. nl80211_meshconf_params_policy))
  4385. return -EINVAL;
  4386. /* This makes sure that there aren't more than 32 mesh config
  4387. * parameters (otherwise our bitfield scheme would not work.) */
  4388. BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
  4389. /* Fill in the params struct */
  4390. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
  4391. mask, NL80211_MESHCONF_RETRY_TIMEOUT,
  4392. nla_get_u16);
  4393. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
  4394. mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  4395. nla_get_u16);
  4396. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
  4397. mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
  4398. nla_get_u16);
  4399. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
  4400. mask, NL80211_MESHCONF_MAX_PEER_LINKS,
  4401. nla_get_u16);
  4402. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
  4403. mask, NL80211_MESHCONF_MAX_RETRIES,
  4404. nla_get_u8);
  4405. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
  4406. mask, NL80211_MESHCONF_TTL, nla_get_u8);
  4407. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
  4408. mask, NL80211_MESHCONF_ELEMENT_TTL,
  4409. nla_get_u8);
  4410. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
  4411. mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  4412. nla_get_u8);
  4413. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
  4414. 1, 255, mask,
  4415. NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
  4416. nla_get_u32);
  4417. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
  4418. mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  4419. nla_get_u8);
  4420. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
  4421. mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
  4422. nla_get_u32);
  4423. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
  4424. mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  4425. nla_get_u16);
  4426. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
  4427. 1, 65535, mask,
  4428. NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  4429. nla_get_u32);
  4430. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
  4431. 1, 65535, mask,
  4432. NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  4433. nla_get_u16);
  4434. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
  4435. 1, 65535, mask,
  4436. NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  4437. nla_get_u16);
  4438. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  4439. dot11MeshHWMPnetDiameterTraversalTime,
  4440. 1, 65535, mask,
  4441. NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  4442. nla_get_u16);
  4443. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
  4444. mask, NL80211_MESHCONF_HWMP_ROOTMODE,
  4445. nla_get_u8);
  4446. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
  4447. mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  4448. nla_get_u16);
  4449. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  4450. dot11MeshGateAnnouncementProtocol, 0, 1,
  4451. mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  4452. nla_get_u8);
  4453. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
  4454. mask, NL80211_MESHCONF_FORWARDING,
  4455. nla_get_u8);
  4456. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
  4457. mask, NL80211_MESHCONF_RSSI_THRESHOLD,
  4458. nla_get_s32);
  4459. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
  4460. mask, NL80211_MESHCONF_HT_OPMODE,
  4461. nla_get_u16);
  4462. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
  4463. 1, 65535, mask,
  4464. NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  4465. nla_get_u32);
  4466. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
  4467. mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  4468. nla_get_u16);
  4469. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  4470. dot11MeshHWMPconfirmationInterval,
  4471. 1, 65535, mask,
  4472. NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
  4473. nla_get_u16);
  4474. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
  4475. NL80211_MESH_POWER_ACTIVE,
  4476. NL80211_MESH_POWER_MAX,
  4477. mask, NL80211_MESHCONF_POWER_MODE,
  4478. nla_get_u32);
  4479. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
  4480. 0, 65535, mask,
  4481. NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
  4482. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
  4483. mask, NL80211_MESHCONF_PLINK_TIMEOUT,
  4484. nla_get_u32);
  4485. if (mask_out)
  4486. *mask_out = mask;
  4487. return 0;
  4488. #undef FILL_IN_MESH_PARAM_IF_SET
  4489. }
  4490. static int nl80211_parse_mesh_setup(struct genl_info *info,
  4491. struct mesh_setup *setup)
  4492. {
  4493. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4494. struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
  4495. if (!info->attrs[NL80211_ATTR_MESH_SETUP])
  4496. return -EINVAL;
  4497. if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
  4498. info->attrs[NL80211_ATTR_MESH_SETUP],
  4499. nl80211_mesh_setup_params_policy))
  4500. return -EINVAL;
  4501. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
  4502. setup->sync_method =
  4503. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
  4504. IEEE80211_SYNC_METHOD_VENDOR :
  4505. IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
  4506. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
  4507. setup->path_sel_proto =
  4508. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
  4509. IEEE80211_PATH_PROTOCOL_VENDOR :
  4510. IEEE80211_PATH_PROTOCOL_HWMP;
  4511. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
  4512. setup->path_metric =
  4513. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
  4514. IEEE80211_PATH_METRIC_VENDOR :
  4515. IEEE80211_PATH_METRIC_AIRTIME;
  4516. if (tb[NL80211_MESH_SETUP_IE]) {
  4517. struct nlattr *ieattr =
  4518. tb[NL80211_MESH_SETUP_IE];
  4519. if (!is_valid_ie_attr(ieattr))
  4520. return -EINVAL;
  4521. setup->ie = nla_data(ieattr);
  4522. setup->ie_len = nla_len(ieattr);
  4523. }
  4524. if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
  4525. !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
  4526. return -EINVAL;
  4527. setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
  4528. setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
  4529. setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
  4530. if (setup->is_secure)
  4531. setup->user_mpm = true;
  4532. if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
  4533. if (!setup->user_mpm)
  4534. return -EINVAL;
  4535. setup->auth_id =
  4536. nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
  4537. }
  4538. return 0;
  4539. }
  4540. static int nl80211_update_mesh_config(struct sk_buff *skb,
  4541. struct genl_info *info)
  4542. {
  4543. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4544. struct net_device *dev = info->user_ptr[1];
  4545. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4546. struct mesh_config cfg;
  4547. u32 mask;
  4548. int err;
  4549. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  4550. return -EOPNOTSUPP;
  4551. if (!rdev->ops->update_mesh_config)
  4552. return -EOPNOTSUPP;
  4553. err = nl80211_parse_mesh_config(info, &cfg, &mask);
  4554. if (err)
  4555. return err;
  4556. wdev_lock(wdev);
  4557. if (!wdev->mesh_id_len)
  4558. err = -ENOLINK;
  4559. if (!err)
  4560. err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
  4561. wdev_unlock(wdev);
  4562. return err;
  4563. }
  4564. static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
  4565. struct sk_buff *msg)
  4566. {
  4567. struct nlattr *nl_reg_rules;
  4568. unsigned int i;
  4569. if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
  4570. (regdom->dfs_region &&
  4571. nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
  4572. goto nla_put_failure;
  4573. nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
  4574. if (!nl_reg_rules)
  4575. goto nla_put_failure;
  4576. for (i = 0; i < regdom->n_reg_rules; i++) {
  4577. struct nlattr *nl_reg_rule;
  4578. const struct ieee80211_reg_rule *reg_rule;
  4579. const struct ieee80211_freq_range *freq_range;
  4580. const struct ieee80211_power_rule *power_rule;
  4581. unsigned int max_bandwidth_khz;
  4582. reg_rule = &regdom->reg_rules[i];
  4583. freq_range = &reg_rule->freq_range;
  4584. power_rule = &reg_rule->power_rule;
  4585. nl_reg_rule = nla_nest_start(msg, i);
  4586. if (!nl_reg_rule)
  4587. goto nla_put_failure;
  4588. max_bandwidth_khz = freq_range->max_bandwidth_khz;
  4589. if (!max_bandwidth_khz)
  4590. max_bandwidth_khz = reg_get_max_bandwidth(regdom,
  4591. reg_rule);
  4592. if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
  4593. reg_rule->flags) ||
  4594. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
  4595. freq_range->start_freq_khz) ||
  4596. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
  4597. freq_range->end_freq_khz) ||
  4598. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
  4599. max_bandwidth_khz) ||
  4600. nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
  4601. power_rule->max_antenna_gain) ||
  4602. nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
  4603. power_rule->max_eirp) ||
  4604. nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
  4605. reg_rule->dfs_cac_ms))
  4606. goto nla_put_failure;
  4607. nla_nest_end(msg, nl_reg_rule);
  4608. }
  4609. nla_nest_end(msg, nl_reg_rules);
  4610. return 0;
  4611. nla_put_failure:
  4612. return -EMSGSIZE;
  4613. }
  4614. static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
  4615. {
  4616. const struct ieee80211_regdomain *regdom = NULL;
  4617. struct cfg80211_registered_device *rdev;
  4618. struct wiphy *wiphy = NULL;
  4619. struct sk_buff *msg;
  4620. void *hdr;
  4621. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4622. if (!msg)
  4623. return -ENOBUFS;
  4624. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  4625. NL80211_CMD_GET_REG);
  4626. if (!hdr)
  4627. goto put_failure;
  4628. if (info->attrs[NL80211_ATTR_WIPHY]) {
  4629. bool self_managed;
  4630. rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
  4631. if (IS_ERR(rdev)) {
  4632. nlmsg_free(msg);
  4633. return PTR_ERR(rdev);
  4634. }
  4635. wiphy = &rdev->wiphy;
  4636. self_managed = wiphy->regulatory_flags &
  4637. REGULATORY_WIPHY_SELF_MANAGED;
  4638. regdom = get_wiphy_regdom(wiphy);
  4639. /* a self-managed-reg device must have a private regdom */
  4640. if (WARN_ON(!regdom && self_managed)) {
  4641. nlmsg_free(msg);
  4642. return -EINVAL;
  4643. }
  4644. if (regdom &&
  4645. nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  4646. goto nla_put_failure;
  4647. }
  4648. if (!wiphy && reg_last_request_cell_base() &&
  4649. nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
  4650. NL80211_USER_REG_HINT_CELL_BASE))
  4651. goto nla_put_failure;
  4652. rcu_read_lock();
  4653. if (!regdom)
  4654. regdom = rcu_dereference(cfg80211_regdomain);
  4655. if (nl80211_put_regdom(regdom, msg))
  4656. goto nla_put_failure_rcu;
  4657. rcu_read_unlock();
  4658. genlmsg_end(msg, hdr);
  4659. return genlmsg_reply(msg, info);
  4660. nla_put_failure_rcu:
  4661. rcu_read_unlock();
  4662. nla_put_failure:
  4663. genlmsg_cancel(msg, hdr);
  4664. put_failure:
  4665. nlmsg_free(msg);
  4666. return -EMSGSIZE;
  4667. }
  4668. static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
  4669. u32 seq, int flags, struct wiphy *wiphy,
  4670. const struct ieee80211_regdomain *regdom)
  4671. {
  4672. void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
  4673. NL80211_CMD_GET_REG);
  4674. if (!hdr)
  4675. return -1;
  4676. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  4677. if (nl80211_put_regdom(regdom, msg))
  4678. goto nla_put_failure;
  4679. if (!wiphy && reg_last_request_cell_base() &&
  4680. nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
  4681. NL80211_USER_REG_HINT_CELL_BASE))
  4682. goto nla_put_failure;
  4683. if (wiphy &&
  4684. nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  4685. goto nla_put_failure;
  4686. if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  4687. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  4688. goto nla_put_failure;
  4689. genlmsg_end(msg, hdr);
  4690. return 0;
  4691. nla_put_failure:
  4692. genlmsg_cancel(msg, hdr);
  4693. return -EMSGSIZE;
  4694. }
  4695. static int nl80211_get_reg_dump(struct sk_buff *skb,
  4696. struct netlink_callback *cb)
  4697. {
  4698. const struct ieee80211_regdomain *regdom = NULL;
  4699. struct cfg80211_registered_device *rdev;
  4700. int err, reg_idx, start = cb->args[2];
  4701. rtnl_lock();
  4702. if (cfg80211_regdomain && start == 0) {
  4703. err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
  4704. NLM_F_MULTI, NULL,
  4705. rtnl_dereference(cfg80211_regdomain));
  4706. if (err < 0)
  4707. goto out_err;
  4708. }
  4709. /* the global regdom is idx 0 */
  4710. reg_idx = 1;
  4711. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  4712. regdom = get_wiphy_regdom(&rdev->wiphy);
  4713. if (!regdom)
  4714. continue;
  4715. if (++reg_idx <= start)
  4716. continue;
  4717. err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
  4718. NLM_F_MULTI, &rdev->wiphy, regdom);
  4719. if (err < 0) {
  4720. reg_idx--;
  4721. break;
  4722. }
  4723. }
  4724. cb->args[2] = reg_idx;
  4725. err = skb->len;
  4726. out_err:
  4727. rtnl_unlock();
  4728. return err;
  4729. }
  4730. static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
  4731. {
  4732. struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
  4733. struct nlattr *nl_reg_rule;
  4734. char *alpha2;
  4735. int rem_reg_rules, r;
  4736. u32 num_rules = 0, rule_idx = 0, size_of_regd;
  4737. enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
  4738. struct ieee80211_regdomain *rd;
  4739. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  4740. return -EINVAL;
  4741. if (!info->attrs[NL80211_ATTR_REG_RULES])
  4742. return -EINVAL;
  4743. alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  4744. if (info->attrs[NL80211_ATTR_DFS_REGION])
  4745. dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
  4746. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  4747. rem_reg_rules) {
  4748. num_rules++;
  4749. if (num_rules > NL80211_MAX_SUPP_REG_RULES)
  4750. return -EINVAL;
  4751. }
  4752. if (!reg_is_valid_request(alpha2))
  4753. return -EINVAL;
  4754. size_of_regd = sizeof(struct ieee80211_regdomain) +
  4755. num_rules * sizeof(struct ieee80211_reg_rule);
  4756. rd = kzalloc(size_of_regd, GFP_KERNEL);
  4757. if (!rd)
  4758. return -ENOMEM;
  4759. rd->n_reg_rules = num_rules;
  4760. rd->alpha2[0] = alpha2[0];
  4761. rd->alpha2[1] = alpha2[1];
  4762. /*
  4763. * Disable DFS master mode if the DFS region was
  4764. * not supported or known on this kernel.
  4765. */
  4766. if (reg_supported_dfs_region(dfs_region))
  4767. rd->dfs_region = dfs_region;
  4768. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  4769. rem_reg_rules) {
  4770. r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
  4771. nla_data(nl_reg_rule), nla_len(nl_reg_rule),
  4772. reg_rule_policy);
  4773. if (r)
  4774. goto bad_reg;
  4775. r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
  4776. if (r)
  4777. goto bad_reg;
  4778. rule_idx++;
  4779. if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
  4780. r = -EINVAL;
  4781. goto bad_reg;
  4782. }
  4783. }
  4784. r = set_regdom(rd, REGD_SOURCE_CRDA);
  4785. /* set_regdom took ownership */
  4786. rd = NULL;
  4787. bad_reg:
  4788. kfree(rd);
  4789. return r;
  4790. }
  4791. static int validate_scan_freqs(struct nlattr *freqs)
  4792. {
  4793. struct nlattr *attr1, *attr2;
  4794. int n_channels = 0, tmp1, tmp2;
  4795. nla_for_each_nested(attr1, freqs, tmp1) {
  4796. n_channels++;
  4797. /*
  4798. * Some hardware has a limited channel list for
  4799. * scanning, and it is pretty much nonsensical
  4800. * to scan for a channel twice, so disallow that
  4801. * and don't require drivers to check that the
  4802. * channel list they get isn't longer than what
  4803. * they can scan, as long as they can scan all
  4804. * the channels they registered at once.
  4805. */
  4806. nla_for_each_nested(attr2, freqs, tmp2)
  4807. if (attr1 != attr2 &&
  4808. nla_get_u32(attr1) == nla_get_u32(attr2))
  4809. return 0;
  4810. }
  4811. return n_channels;
  4812. }
  4813. static int nl80211_parse_random_mac(struct nlattr **attrs,
  4814. u8 *mac_addr, u8 *mac_addr_mask)
  4815. {
  4816. int i;
  4817. if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
  4818. eth_zero_addr(mac_addr);
  4819. eth_zero_addr(mac_addr_mask);
  4820. mac_addr[0] = 0x2;
  4821. mac_addr_mask[0] = 0x3;
  4822. return 0;
  4823. }
  4824. /* need both or none */
  4825. if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
  4826. return -EINVAL;
  4827. memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
  4828. memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
  4829. /* don't allow or configure an mcast address */
  4830. if (!is_multicast_ether_addr(mac_addr_mask) ||
  4831. is_multicast_ether_addr(mac_addr))
  4832. return -EINVAL;
  4833. /*
  4834. * allow users to pass a MAC address that has bits set outside
  4835. * of the mask, but don't bother drivers with having to deal
  4836. * with such bits
  4837. */
  4838. for (i = 0; i < ETH_ALEN; i++)
  4839. mac_addr[i] &= mac_addr_mask[i];
  4840. return 0;
  4841. }
  4842. static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
  4843. {
  4844. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4845. struct wireless_dev *wdev = info->user_ptr[1];
  4846. struct cfg80211_scan_request *request;
  4847. struct nlattr *attr;
  4848. struct wiphy *wiphy;
  4849. int err, tmp, n_ssids = 0, n_channels, i;
  4850. size_t ie_len;
  4851. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  4852. return -EINVAL;
  4853. wiphy = &rdev->wiphy;
  4854. if (!rdev->ops->scan)
  4855. return -EOPNOTSUPP;
  4856. if (rdev->scan_req || rdev->scan_msg) {
  4857. err = -EBUSY;
  4858. goto unlock;
  4859. }
  4860. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  4861. n_channels = validate_scan_freqs(
  4862. info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  4863. if (!n_channels) {
  4864. err = -EINVAL;
  4865. goto unlock;
  4866. }
  4867. } else {
  4868. n_channels = ieee80211_get_num_supported_channels(wiphy);
  4869. }
  4870. if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
  4871. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
  4872. n_ssids++;
  4873. if (n_ssids > wiphy->max_scan_ssids) {
  4874. err = -EINVAL;
  4875. goto unlock;
  4876. }
  4877. if (info->attrs[NL80211_ATTR_IE])
  4878. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4879. else
  4880. ie_len = 0;
  4881. if (ie_len > wiphy->max_scan_ie_len) {
  4882. err = -EINVAL;
  4883. goto unlock;
  4884. }
  4885. request = kzalloc(sizeof(*request)
  4886. + sizeof(*request->ssids) * n_ssids
  4887. + sizeof(*request->channels) * n_channels
  4888. + ie_len, GFP_KERNEL);
  4889. if (!request) {
  4890. err = -ENOMEM;
  4891. goto unlock;
  4892. }
  4893. if (n_ssids)
  4894. request->ssids = (void *)&request->channels[n_channels];
  4895. request->n_ssids = n_ssids;
  4896. if (ie_len) {
  4897. if (n_ssids)
  4898. request->ie = (void *)(request->ssids + n_ssids);
  4899. else
  4900. request->ie = (void *)(request->channels + n_channels);
  4901. }
  4902. i = 0;
  4903. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  4904. /* user specified, bail out if channel not found */
  4905. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
  4906. struct ieee80211_channel *chan;
  4907. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  4908. if (!chan) {
  4909. err = -EINVAL;
  4910. goto out_free;
  4911. }
  4912. /* ignore disabled channels */
  4913. if (chan->flags & IEEE80211_CHAN_DISABLED)
  4914. continue;
  4915. request->channels[i] = chan;
  4916. i++;
  4917. }
  4918. } else {
  4919. enum ieee80211_band band;
  4920. /* all channels */
  4921. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  4922. int j;
  4923. if (!wiphy->bands[band])
  4924. continue;
  4925. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  4926. struct ieee80211_channel *chan;
  4927. chan = &wiphy->bands[band]->channels[j];
  4928. if (chan->flags & IEEE80211_CHAN_DISABLED)
  4929. continue;
  4930. request->channels[i] = chan;
  4931. i++;
  4932. }
  4933. }
  4934. }
  4935. if (!i) {
  4936. err = -EINVAL;
  4937. goto out_free;
  4938. }
  4939. request->n_channels = i;
  4940. i = 0;
  4941. if (n_ssids) {
  4942. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
  4943. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  4944. err = -EINVAL;
  4945. goto out_free;
  4946. }
  4947. request->ssids[i].ssid_len = nla_len(attr);
  4948. memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
  4949. i++;
  4950. }
  4951. }
  4952. if (info->attrs[NL80211_ATTR_IE]) {
  4953. request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  4954. memcpy((void *)request->ie,
  4955. nla_data(info->attrs[NL80211_ATTR_IE]),
  4956. request->ie_len);
  4957. }
  4958. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  4959. if (wiphy->bands[i])
  4960. request->rates[i] =
  4961. (1 << wiphy->bands[i]->n_bitrates) - 1;
  4962. if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
  4963. nla_for_each_nested(attr,
  4964. info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
  4965. tmp) {
  4966. enum ieee80211_band band = nla_type(attr);
  4967. if (band < 0 || band >= IEEE80211_NUM_BANDS) {
  4968. err = -EINVAL;
  4969. goto out_free;
  4970. }
  4971. if (!wiphy->bands[band])
  4972. continue;
  4973. err = ieee80211_get_ratemask(wiphy->bands[band],
  4974. nla_data(attr),
  4975. nla_len(attr),
  4976. &request->rates[band]);
  4977. if (err)
  4978. goto out_free;
  4979. }
  4980. }
  4981. if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
  4982. request->flags = nla_get_u32(
  4983. info->attrs[NL80211_ATTR_SCAN_FLAGS]);
  4984. if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  4985. !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
  4986. err = -EOPNOTSUPP;
  4987. goto out_free;
  4988. }
  4989. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  4990. if (!(wiphy->features &
  4991. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
  4992. err = -EOPNOTSUPP;
  4993. goto out_free;
  4994. }
  4995. if (wdev->current_bss) {
  4996. err = -EOPNOTSUPP;
  4997. goto out_free;
  4998. }
  4999. err = nl80211_parse_random_mac(info->attrs,
  5000. request->mac_addr,
  5001. request->mac_addr_mask);
  5002. if (err)
  5003. goto out_free;
  5004. }
  5005. }
  5006. request->no_cck =
  5007. nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  5008. request->wdev = wdev;
  5009. request->wiphy = &rdev->wiphy;
  5010. request->scan_start = jiffies;
  5011. rdev->scan_req = request;
  5012. err = rdev_scan(rdev, request);
  5013. if (!err) {
  5014. nl80211_send_scan_start(rdev, wdev);
  5015. if (wdev->netdev)
  5016. dev_hold(wdev->netdev);
  5017. } else {
  5018. out_free:
  5019. rdev->scan_req = NULL;
  5020. kfree(request);
  5021. }
  5022. unlock:
  5023. return err;
  5024. }
  5025. static struct cfg80211_sched_scan_request *
  5026. nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
  5027. struct nlattr **attrs)
  5028. {
  5029. struct cfg80211_sched_scan_request *request;
  5030. struct nlattr *attr;
  5031. int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
  5032. u32 interval;
  5033. enum ieee80211_band band;
  5034. size_t ie_len;
  5035. struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
  5036. s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
  5037. if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
  5038. return ERR_PTR(-EINVAL);
  5039. if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5040. return ERR_PTR(-EINVAL);
  5041. interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
  5042. if (interval == 0)
  5043. return ERR_PTR(-EINVAL);
  5044. if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5045. n_channels = validate_scan_freqs(
  5046. attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  5047. if (!n_channels)
  5048. return ERR_PTR(-EINVAL);
  5049. } else {
  5050. n_channels = ieee80211_get_num_supported_channels(wiphy);
  5051. }
  5052. if (attrs[NL80211_ATTR_SCAN_SSIDS])
  5053. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
  5054. tmp)
  5055. n_ssids++;
  5056. if (n_ssids > wiphy->max_sched_scan_ssids)
  5057. return ERR_PTR(-EINVAL);
  5058. /*
  5059. * First, count the number of 'real' matchsets. Due to an issue with
  5060. * the old implementation, matchsets containing only the RSSI attribute
  5061. * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
  5062. * RSSI for all matchsets, rather than their own matchset for reporting
  5063. * all APs with a strong RSSI. This is needed to be compatible with
  5064. * older userspace that treated a matchset with only the RSSI as the
  5065. * global RSSI for all other matchsets - if there are other matchsets.
  5066. */
  5067. if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  5068. nla_for_each_nested(attr,
  5069. attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  5070. tmp) {
  5071. struct nlattr *rssi;
  5072. err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  5073. nla_data(attr), nla_len(attr),
  5074. nl80211_match_policy);
  5075. if (err)
  5076. return ERR_PTR(err);
  5077. /* add other standalone attributes here */
  5078. if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
  5079. n_match_sets++;
  5080. continue;
  5081. }
  5082. rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
  5083. if (rssi)
  5084. default_match_rssi = nla_get_s32(rssi);
  5085. }
  5086. }
  5087. /* However, if there's no other matchset, add the RSSI one */
  5088. if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
  5089. n_match_sets = 1;
  5090. if (n_match_sets > wiphy->max_match_sets)
  5091. return ERR_PTR(-EINVAL);
  5092. if (attrs[NL80211_ATTR_IE])
  5093. ie_len = nla_len(attrs[NL80211_ATTR_IE]);
  5094. else
  5095. ie_len = 0;
  5096. if (ie_len > wiphy->max_sched_scan_ie_len)
  5097. return ERR_PTR(-EINVAL);
  5098. request = kzalloc(sizeof(*request)
  5099. + sizeof(*request->ssids) * n_ssids
  5100. + sizeof(*request->match_sets) * n_match_sets
  5101. + sizeof(*request->channels) * n_channels
  5102. + ie_len, GFP_KERNEL);
  5103. if (!request)
  5104. return ERR_PTR(-ENOMEM);
  5105. if (n_ssids)
  5106. request->ssids = (void *)&request->channels[n_channels];
  5107. request->n_ssids = n_ssids;
  5108. if (ie_len) {
  5109. if (n_ssids)
  5110. request->ie = (void *)(request->ssids + n_ssids);
  5111. else
  5112. request->ie = (void *)(request->channels + n_channels);
  5113. }
  5114. if (n_match_sets) {
  5115. if (request->ie)
  5116. request->match_sets = (void *)(request->ie + ie_len);
  5117. else if (n_ssids)
  5118. request->match_sets =
  5119. (void *)(request->ssids + n_ssids);
  5120. else
  5121. request->match_sets =
  5122. (void *)(request->channels + n_channels);
  5123. }
  5124. request->n_match_sets = n_match_sets;
  5125. i = 0;
  5126. if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5127. /* user specified, bail out if channel not found */
  5128. nla_for_each_nested(attr,
  5129. attrs[NL80211_ATTR_SCAN_FREQUENCIES],
  5130. tmp) {
  5131. struct ieee80211_channel *chan;
  5132. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  5133. if (!chan) {
  5134. err = -EINVAL;
  5135. goto out_free;
  5136. }
  5137. /* ignore disabled channels */
  5138. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5139. continue;
  5140. request->channels[i] = chan;
  5141. i++;
  5142. }
  5143. } else {
  5144. /* all channels */
  5145. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  5146. int j;
  5147. if (!wiphy->bands[band])
  5148. continue;
  5149. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  5150. struct ieee80211_channel *chan;
  5151. chan = &wiphy->bands[band]->channels[j];
  5152. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5153. continue;
  5154. request->channels[i] = chan;
  5155. i++;
  5156. }
  5157. }
  5158. }
  5159. if (!i) {
  5160. err = -EINVAL;
  5161. goto out_free;
  5162. }
  5163. request->n_channels = i;
  5164. i = 0;
  5165. if (n_ssids) {
  5166. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
  5167. tmp) {
  5168. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  5169. err = -EINVAL;
  5170. goto out_free;
  5171. }
  5172. request->ssids[i].ssid_len = nla_len(attr);
  5173. memcpy(request->ssids[i].ssid, nla_data(attr),
  5174. nla_len(attr));
  5175. i++;
  5176. }
  5177. }
  5178. i = 0;
  5179. if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  5180. nla_for_each_nested(attr,
  5181. attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  5182. tmp) {
  5183. struct nlattr *ssid, *rssi;
  5184. err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  5185. nla_data(attr), nla_len(attr),
  5186. nl80211_match_policy);
  5187. if (err)
  5188. goto out_free;
  5189. ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
  5190. if (ssid) {
  5191. if (WARN_ON(i >= n_match_sets)) {
  5192. /* this indicates a programming error,
  5193. * the loop above should have verified
  5194. * things properly
  5195. */
  5196. err = -EINVAL;
  5197. goto out_free;
  5198. }
  5199. if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
  5200. err = -EINVAL;
  5201. goto out_free;
  5202. }
  5203. memcpy(request->match_sets[i].ssid.ssid,
  5204. nla_data(ssid), nla_len(ssid));
  5205. request->match_sets[i].ssid.ssid_len =
  5206. nla_len(ssid);
  5207. /* special attribute - old implemenation w/a */
  5208. request->match_sets[i].rssi_thold =
  5209. default_match_rssi;
  5210. rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
  5211. if (rssi)
  5212. request->match_sets[i].rssi_thold =
  5213. nla_get_s32(rssi);
  5214. }
  5215. i++;
  5216. }
  5217. /* there was no other matchset, so the RSSI one is alone */
  5218. if (i == 0 && n_match_sets)
  5219. request->match_sets[0].rssi_thold = default_match_rssi;
  5220. request->min_rssi_thold = INT_MAX;
  5221. for (i = 0; i < n_match_sets; i++)
  5222. request->min_rssi_thold =
  5223. min(request->match_sets[i].rssi_thold,
  5224. request->min_rssi_thold);
  5225. } else {
  5226. request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
  5227. }
  5228. if (ie_len) {
  5229. request->ie_len = ie_len;
  5230. memcpy((void *)request->ie,
  5231. nla_data(attrs[NL80211_ATTR_IE]),
  5232. request->ie_len);
  5233. }
  5234. if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
  5235. request->flags = nla_get_u32(
  5236. attrs[NL80211_ATTR_SCAN_FLAGS]);
  5237. if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  5238. !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
  5239. err = -EOPNOTSUPP;
  5240. goto out_free;
  5241. }
  5242. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  5243. u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
  5244. if (!wdev) /* must be net-detect */
  5245. flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  5246. if (!(wiphy->features & flg)) {
  5247. err = -EOPNOTSUPP;
  5248. goto out_free;
  5249. }
  5250. if (wdev && wdev->current_bss) {
  5251. err = -EOPNOTSUPP;
  5252. goto out_free;
  5253. }
  5254. err = nl80211_parse_random_mac(attrs, request->mac_addr,
  5255. request->mac_addr_mask);
  5256. if (err)
  5257. goto out_free;
  5258. }
  5259. }
  5260. if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
  5261. request->delay =
  5262. nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
  5263. request->interval = interval;
  5264. request->scan_start = jiffies;
  5265. return request;
  5266. out_free:
  5267. kfree(request);
  5268. return ERR_PTR(err);
  5269. }
  5270. static int nl80211_start_sched_scan(struct sk_buff *skb,
  5271. struct genl_info *info)
  5272. {
  5273. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5274. struct net_device *dev = info->user_ptr[1];
  5275. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5276. struct cfg80211_sched_scan_request *sched_scan_req;
  5277. int err;
  5278. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  5279. !rdev->ops->sched_scan_start)
  5280. return -EOPNOTSUPP;
  5281. if (rdev->sched_scan_req)
  5282. return -EINPROGRESS;
  5283. sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
  5284. info->attrs);
  5285. err = PTR_ERR_OR_ZERO(sched_scan_req);
  5286. if (err)
  5287. goto out_err;
  5288. err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
  5289. if (err)
  5290. goto out_free;
  5291. sched_scan_req->dev = dev;
  5292. sched_scan_req->wiphy = &rdev->wiphy;
  5293. if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
  5294. sched_scan_req->owner_nlportid = info->snd_portid;
  5295. rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
  5296. nl80211_send_sched_scan(rdev, dev,
  5297. NL80211_CMD_START_SCHED_SCAN);
  5298. return 0;
  5299. out_free:
  5300. kfree(sched_scan_req);
  5301. out_err:
  5302. return err;
  5303. }
  5304. static int nl80211_stop_sched_scan(struct sk_buff *skb,
  5305. struct genl_info *info)
  5306. {
  5307. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5308. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  5309. !rdev->ops->sched_scan_stop)
  5310. return -EOPNOTSUPP;
  5311. return __cfg80211_stop_sched_scan(rdev, false);
  5312. }
  5313. static int nl80211_start_radar_detection(struct sk_buff *skb,
  5314. struct genl_info *info)
  5315. {
  5316. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5317. struct net_device *dev = info->user_ptr[1];
  5318. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5319. struct cfg80211_chan_def chandef;
  5320. enum nl80211_dfs_regions dfs_region;
  5321. unsigned int cac_time_ms;
  5322. int err;
  5323. dfs_region = reg_get_dfs_region(wdev->wiphy);
  5324. if (dfs_region == NL80211_DFS_UNSET)
  5325. return -EINVAL;
  5326. err = nl80211_parse_chandef(rdev, info, &chandef);
  5327. if (err)
  5328. return err;
  5329. if (netif_carrier_ok(dev))
  5330. return -EBUSY;
  5331. if (wdev->cac_started)
  5332. return -EBUSY;
  5333. err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
  5334. wdev->iftype);
  5335. if (err < 0)
  5336. return err;
  5337. if (err == 0)
  5338. return -EINVAL;
  5339. if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
  5340. return -EINVAL;
  5341. if (!rdev->ops->start_radar_detection)
  5342. return -EOPNOTSUPP;
  5343. cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
  5344. if (WARN_ON(!cac_time_ms))
  5345. cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
  5346. err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
  5347. cac_time_ms);
  5348. if (!err) {
  5349. wdev->chandef = chandef;
  5350. wdev->cac_started = true;
  5351. wdev->cac_start_time = jiffies;
  5352. wdev->cac_time_ms = cac_time_ms;
  5353. }
  5354. return err;
  5355. }
  5356. static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
  5357. {
  5358. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5359. struct net_device *dev = info->user_ptr[1];
  5360. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5361. struct cfg80211_csa_settings params;
  5362. /* csa_attrs is defined static to avoid waste of stack size - this
  5363. * function is called under RTNL lock, so this should not be a problem.
  5364. */
  5365. static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
  5366. int err;
  5367. bool need_new_beacon = false;
  5368. int len, i;
  5369. u32 cs_count;
  5370. if (!rdev->ops->channel_switch ||
  5371. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
  5372. return -EOPNOTSUPP;
  5373. switch (dev->ieee80211_ptr->iftype) {
  5374. case NL80211_IFTYPE_AP:
  5375. case NL80211_IFTYPE_P2P_GO:
  5376. need_new_beacon = true;
  5377. /* useless if AP is not running */
  5378. if (!wdev->beacon_interval)
  5379. return -ENOTCONN;
  5380. break;
  5381. case NL80211_IFTYPE_ADHOC:
  5382. if (!wdev->ssid_len)
  5383. return -ENOTCONN;
  5384. break;
  5385. case NL80211_IFTYPE_MESH_POINT:
  5386. if (!wdev->mesh_id_len)
  5387. return -ENOTCONN;
  5388. break;
  5389. default:
  5390. return -EOPNOTSUPP;
  5391. }
  5392. memset(&params, 0, sizeof(params));
  5393. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  5394. !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
  5395. return -EINVAL;
  5396. /* only important for AP, IBSS and mesh create IEs internally */
  5397. if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
  5398. return -EINVAL;
  5399. /* Even though the attribute is u32, the specification says
  5400. * u8, so let's make sure we don't overflow.
  5401. */
  5402. cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
  5403. if (cs_count > 255)
  5404. return -EINVAL;
  5405. params.count = cs_count;
  5406. if (!need_new_beacon)
  5407. goto skip_beacons;
  5408. err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
  5409. if (err)
  5410. return err;
  5411. err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
  5412. info->attrs[NL80211_ATTR_CSA_IES],
  5413. nl80211_policy);
  5414. if (err)
  5415. return err;
  5416. err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
  5417. if (err)
  5418. return err;
  5419. if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
  5420. return -EINVAL;
  5421. len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
  5422. if (!len || (len % sizeof(u16)))
  5423. return -EINVAL;
  5424. params.n_counter_offsets_beacon = len / sizeof(u16);
  5425. if (rdev->wiphy.max_num_csa_counters &&
  5426. (params.n_counter_offsets_beacon >
  5427. rdev->wiphy.max_num_csa_counters))
  5428. return -EINVAL;
  5429. params.counter_offsets_beacon =
  5430. nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
  5431. /* sanity checks - counters should fit and be the same */
  5432. for (i = 0; i < params.n_counter_offsets_beacon; i++) {
  5433. u16 offset = params.counter_offsets_beacon[i];
  5434. if (offset >= params.beacon_csa.tail_len)
  5435. return -EINVAL;
  5436. if (params.beacon_csa.tail[offset] != params.count)
  5437. return -EINVAL;
  5438. }
  5439. if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
  5440. len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
  5441. if (!len || (len % sizeof(u16)))
  5442. return -EINVAL;
  5443. params.n_counter_offsets_presp = len / sizeof(u16);
  5444. if (rdev->wiphy.max_num_csa_counters &&
  5445. (params.n_counter_offsets_beacon >
  5446. rdev->wiphy.max_num_csa_counters))
  5447. return -EINVAL;
  5448. params.counter_offsets_presp =
  5449. nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
  5450. /* sanity checks - counters should fit and be the same */
  5451. for (i = 0; i < params.n_counter_offsets_presp; i++) {
  5452. u16 offset = params.counter_offsets_presp[i];
  5453. if (offset >= params.beacon_csa.probe_resp_len)
  5454. return -EINVAL;
  5455. if (params.beacon_csa.probe_resp[offset] !=
  5456. params.count)
  5457. return -EINVAL;
  5458. }
  5459. }
  5460. skip_beacons:
  5461. err = nl80211_parse_chandef(rdev, info, &params.chandef);
  5462. if (err)
  5463. return err;
  5464. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
  5465. wdev->iftype))
  5466. return -EINVAL;
  5467. err = cfg80211_chandef_dfs_required(wdev->wiphy,
  5468. &params.chandef,
  5469. wdev->iftype);
  5470. if (err < 0)
  5471. return err;
  5472. if (err > 0)
  5473. params.radar_required = true;
  5474. if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
  5475. params.block_tx = true;
  5476. wdev_lock(wdev);
  5477. err = rdev_channel_switch(rdev, dev, &params);
  5478. wdev_unlock(wdev);
  5479. return err;
  5480. }
  5481. static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
  5482. u32 seq, int flags,
  5483. struct cfg80211_registered_device *rdev,
  5484. struct wireless_dev *wdev,
  5485. struct cfg80211_internal_bss *intbss)
  5486. {
  5487. struct cfg80211_bss *res = &intbss->pub;
  5488. const struct cfg80211_bss_ies *ies;
  5489. void *hdr;
  5490. struct nlattr *bss;
  5491. ASSERT_WDEV_LOCK(wdev);
  5492. hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
  5493. NL80211_CMD_NEW_SCAN_RESULTS);
  5494. if (!hdr)
  5495. return -1;
  5496. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  5497. if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
  5498. goto nla_put_failure;
  5499. if (wdev->netdev &&
  5500. nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
  5501. goto nla_put_failure;
  5502. if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
  5503. goto nla_put_failure;
  5504. bss = nla_nest_start(msg, NL80211_ATTR_BSS);
  5505. if (!bss)
  5506. goto nla_put_failure;
  5507. if ((!is_zero_ether_addr(res->bssid) &&
  5508. nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
  5509. goto nla_put_failure;
  5510. rcu_read_lock();
  5511. /* indicate whether we have probe response data or not */
  5512. if (rcu_access_pointer(res->proberesp_ies) &&
  5513. nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
  5514. goto fail_unlock_rcu;
  5515. /* this pointer prefers to be pointed to probe response data
  5516. * but is always valid
  5517. */
  5518. ies = rcu_dereference(res->ies);
  5519. if (ies) {
  5520. if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
  5521. goto fail_unlock_rcu;
  5522. if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
  5523. ies->len, ies->data))
  5524. goto fail_unlock_rcu;
  5525. }
  5526. /* and this pointer is always (unless driver didn't know) beacon data */
  5527. ies = rcu_dereference(res->beacon_ies);
  5528. if (ies && ies->from_beacon) {
  5529. if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
  5530. goto fail_unlock_rcu;
  5531. if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
  5532. ies->len, ies->data))
  5533. goto fail_unlock_rcu;
  5534. }
  5535. rcu_read_unlock();
  5536. if (res->beacon_interval &&
  5537. nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
  5538. goto nla_put_failure;
  5539. if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
  5540. nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
  5541. nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
  5542. nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
  5543. jiffies_to_msecs(jiffies - intbss->ts)))
  5544. goto nla_put_failure;
  5545. switch (rdev->wiphy.signal_type) {
  5546. case CFG80211_SIGNAL_TYPE_MBM:
  5547. if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
  5548. goto nla_put_failure;
  5549. break;
  5550. case CFG80211_SIGNAL_TYPE_UNSPEC:
  5551. if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
  5552. goto nla_put_failure;
  5553. break;
  5554. default:
  5555. break;
  5556. }
  5557. switch (wdev->iftype) {
  5558. case NL80211_IFTYPE_P2P_CLIENT:
  5559. case NL80211_IFTYPE_STATION:
  5560. if (intbss == wdev->current_bss &&
  5561. nla_put_u32(msg, NL80211_BSS_STATUS,
  5562. NL80211_BSS_STATUS_ASSOCIATED))
  5563. goto nla_put_failure;
  5564. break;
  5565. case NL80211_IFTYPE_ADHOC:
  5566. if (intbss == wdev->current_bss &&
  5567. nla_put_u32(msg, NL80211_BSS_STATUS,
  5568. NL80211_BSS_STATUS_IBSS_JOINED))
  5569. goto nla_put_failure;
  5570. break;
  5571. default:
  5572. break;
  5573. }
  5574. nla_nest_end(msg, bss);
  5575. genlmsg_end(msg, hdr);
  5576. return 0;
  5577. fail_unlock_rcu:
  5578. rcu_read_unlock();
  5579. nla_put_failure:
  5580. genlmsg_cancel(msg, hdr);
  5581. return -EMSGSIZE;
  5582. }
  5583. static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
  5584. {
  5585. struct cfg80211_registered_device *rdev;
  5586. struct cfg80211_internal_bss *scan;
  5587. struct wireless_dev *wdev;
  5588. int start = cb->args[2], idx = 0;
  5589. int err;
  5590. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  5591. if (err)
  5592. return err;
  5593. wdev_lock(wdev);
  5594. spin_lock_bh(&rdev->bss_lock);
  5595. cfg80211_bss_expire(rdev);
  5596. cb->seq = rdev->bss_generation;
  5597. list_for_each_entry(scan, &rdev->bss_list, list) {
  5598. if (++idx <= start)
  5599. continue;
  5600. if (nl80211_send_bss(skb, cb,
  5601. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  5602. rdev, wdev, scan) < 0) {
  5603. idx--;
  5604. break;
  5605. }
  5606. }
  5607. spin_unlock_bh(&rdev->bss_lock);
  5608. wdev_unlock(wdev);
  5609. cb->args[2] = idx;
  5610. nl80211_finish_wdev_dump(rdev);
  5611. return skb->len;
  5612. }
  5613. static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
  5614. int flags, struct net_device *dev,
  5615. bool allow_radio_stats,
  5616. struct survey_info *survey)
  5617. {
  5618. void *hdr;
  5619. struct nlattr *infoattr;
  5620. /* skip radio stats if userspace didn't request them */
  5621. if (!survey->channel && !allow_radio_stats)
  5622. return 0;
  5623. hdr = nl80211hdr_put(msg, portid, seq, flags,
  5624. NL80211_CMD_NEW_SURVEY_RESULTS);
  5625. if (!hdr)
  5626. return -ENOMEM;
  5627. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
  5628. goto nla_put_failure;
  5629. infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
  5630. if (!infoattr)
  5631. goto nla_put_failure;
  5632. if (survey->channel &&
  5633. nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
  5634. survey->channel->center_freq))
  5635. goto nla_put_failure;
  5636. if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
  5637. nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
  5638. goto nla_put_failure;
  5639. if ((survey->filled & SURVEY_INFO_IN_USE) &&
  5640. nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
  5641. goto nla_put_failure;
  5642. if ((survey->filled & SURVEY_INFO_TIME) &&
  5643. nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
  5644. survey->time))
  5645. goto nla_put_failure;
  5646. if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
  5647. nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
  5648. survey->time_busy))
  5649. goto nla_put_failure;
  5650. if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
  5651. nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
  5652. survey->time_ext_busy))
  5653. goto nla_put_failure;
  5654. if ((survey->filled & SURVEY_INFO_TIME_RX) &&
  5655. nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
  5656. survey->time_rx))
  5657. goto nla_put_failure;
  5658. if ((survey->filled & SURVEY_INFO_TIME_TX) &&
  5659. nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
  5660. survey->time_tx))
  5661. goto nla_put_failure;
  5662. if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
  5663. nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
  5664. survey->time_scan))
  5665. goto nla_put_failure;
  5666. nla_nest_end(msg, infoattr);
  5667. genlmsg_end(msg, hdr);
  5668. return 0;
  5669. nla_put_failure:
  5670. genlmsg_cancel(msg, hdr);
  5671. return -EMSGSIZE;
  5672. }
  5673. static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
  5674. {
  5675. struct survey_info survey;
  5676. struct cfg80211_registered_device *rdev;
  5677. struct wireless_dev *wdev;
  5678. int survey_idx = cb->args[2];
  5679. int res;
  5680. bool radio_stats;
  5681. res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  5682. if (res)
  5683. return res;
  5684. /* prepare_wdev_dump parsed the attributes */
  5685. radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
  5686. if (!wdev->netdev) {
  5687. res = -EINVAL;
  5688. goto out_err;
  5689. }
  5690. if (!rdev->ops->dump_survey) {
  5691. res = -EOPNOTSUPP;
  5692. goto out_err;
  5693. }
  5694. while (1) {
  5695. res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
  5696. if (res == -ENOENT)
  5697. break;
  5698. if (res)
  5699. goto out_err;
  5700. /* don't send disabled channels, but do send non-channel data */
  5701. if (survey.channel &&
  5702. survey.channel->flags & IEEE80211_CHAN_DISABLED) {
  5703. survey_idx++;
  5704. continue;
  5705. }
  5706. if (nl80211_send_survey(skb,
  5707. NETLINK_CB(cb->skb).portid,
  5708. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  5709. wdev->netdev, radio_stats, &survey) < 0)
  5710. goto out;
  5711. survey_idx++;
  5712. }
  5713. out:
  5714. cb->args[2] = survey_idx;
  5715. res = skb->len;
  5716. out_err:
  5717. nl80211_finish_wdev_dump(rdev);
  5718. return res;
  5719. }
  5720. static bool nl80211_valid_wpa_versions(u32 wpa_versions)
  5721. {
  5722. return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
  5723. NL80211_WPA_VERSION_2));
  5724. }
  5725. static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
  5726. {
  5727. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5728. struct net_device *dev = info->user_ptr[1];
  5729. struct ieee80211_channel *chan;
  5730. const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
  5731. int err, ssid_len, ie_len = 0, sae_data_len = 0;
  5732. enum nl80211_auth_type auth_type;
  5733. struct key_parse key;
  5734. bool local_state_change;
  5735. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  5736. return -EINVAL;
  5737. if (!info->attrs[NL80211_ATTR_MAC])
  5738. return -EINVAL;
  5739. if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
  5740. return -EINVAL;
  5741. if (!info->attrs[NL80211_ATTR_SSID])
  5742. return -EINVAL;
  5743. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  5744. return -EINVAL;
  5745. err = nl80211_parse_key(info, &key);
  5746. if (err)
  5747. return err;
  5748. if (key.idx >= 0) {
  5749. if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
  5750. return -EINVAL;
  5751. if (!key.p.key || !key.p.key_len)
  5752. return -EINVAL;
  5753. if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
  5754. key.p.key_len != WLAN_KEY_LEN_WEP40) &&
  5755. (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
  5756. key.p.key_len != WLAN_KEY_LEN_WEP104))
  5757. return -EINVAL;
  5758. if (key.idx > 4)
  5759. return -EINVAL;
  5760. } else {
  5761. key.p.key_len = 0;
  5762. key.p.key = NULL;
  5763. }
  5764. if (key.idx >= 0) {
  5765. int i;
  5766. bool ok = false;
  5767. for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
  5768. if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
  5769. ok = true;
  5770. break;
  5771. }
  5772. }
  5773. if (!ok)
  5774. return -EINVAL;
  5775. }
  5776. if (!rdev->ops->auth)
  5777. return -EOPNOTSUPP;
  5778. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  5779. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  5780. return -EOPNOTSUPP;
  5781. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  5782. chan = nl80211_get_valid_chan(&rdev->wiphy,
  5783. info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  5784. if (!chan)
  5785. return -EINVAL;
  5786. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  5787. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  5788. if (info->attrs[NL80211_ATTR_IE]) {
  5789. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  5790. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5791. }
  5792. auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  5793. if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
  5794. return -EINVAL;
  5795. if (auth_type == NL80211_AUTHTYPE_SAE &&
  5796. !info->attrs[NL80211_ATTR_SAE_DATA])
  5797. return -EINVAL;
  5798. if (info->attrs[NL80211_ATTR_SAE_DATA]) {
  5799. if (auth_type != NL80211_AUTHTYPE_SAE)
  5800. return -EINVAL;
  5801. sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
  5802. sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
  5803. /* need to include at least Auth Transaction and Status Code */
  5804. if (sae_data_len < 4)
  5805. return -EINVAL;
  5806. }
  5807. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  5808. /*
  5809. * Since we no longer track auth state, ignore
  5810. * requests to only change local state.
  5811. */
  5812. if (local_state_change)
  5813. return 0;
  5814. wdev_lock(dev->ieee80211_ptr);
  5815. err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
  5816. ssid, ssid_len, ie, ie_len,
  5817. key.p.key, key.p.key_len, key.idx,
  5818. sae_data, sae_data_len);
  5819. wdev_unlock(dev->ieee80211_ptr);
  5820. return err;
  5821. }
  5822. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  5823. struct genl_info *info,
  5824. struct cfg80211_crypto_settings *settings,
  5825. int cipher_limit)
  5826. {
  5827. memset(settings, 0, sizeof(*settings));
  5828. settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
  5829. if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
  5830. u16 proto;
  5831. proto = nla_get_u16(
  5832. info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
  5833. settings->control_port_ethertype = cpu_to_be16(proto);
  5834. if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  5835. proto != ETH_P_PAE)
  5836. return -EINVAL;
  5837. if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
  5838. settings->control_port_no_encrypt = true;
  5839. } else
  5840. settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
  5841. if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
  5842. void *data;
  5843. int len, i;
  5844. data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  5845. len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  5846. settings->n_ciphers_pairwise = len / sizeof(u32);
  5847. if (len % sizeof(u32))
  5848. return -EINVAL;
  5849. if (settings->n_ciphers_pairwise > cipher_limit)
  5850. return -EINVAL;
  5851. memcpy(settings->ciphers_pairwise, data, len);
  5852. for (i = 0; i < settings->n_ciphers_pairwise; i++)
  5853. if (!cfg80211_supported_cipher_suite(
  5854. &rdev->wiphy,
  5855. settings->ciphers_pairwise[i]))
  5856. return -EINVAL;
  5857. }
  5858. if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
  5859. settings->cipher_group =
  5860. nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
  5861. if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
  5862. settings->cipher_group))
  5863. return -EINVAL;
  5864. }
  5865. if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
  5866. settings->wpa_versions =
  5867. nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
  5868. if (!nl80211_valid_wpa_versions(settings->wpa_versions))
  5869. return -EINVAL;
  5870. }
  5871. if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
  5872. void *data;
  5873. int len;
  5874. data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
  5875. len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
  5876. settings->n_akm_suites = len / sizeof(u32);
  5877. if (len % sizeof(u32))
  5878. return -EINVAL;
  5879. if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
  5880. return -EINVAL;
  5881. memcpy(settings->akm_suites, data, len);
  5882. }
  5883. return 0;
  5884. }
  5885. static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
  5886. {
  5887. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5888. struct net_device *dev = info->user_ptr[1];
  5889. struct ieee80211_channel *chan;
  5890. struct cfg80211_assoc_request req = {};
  5891. const u8 *bssid, *ssid;
  5892. int err, ssid_len = 0;
  5893. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  5894. return -EINVAL;
  5895. if (!info->attrs[NL80211_ATTR_MAC] ||
  5896. !info->attrs[NL80211_ATTR_SSID] ||
  5897. !info->attrs[NL80211_ATTR_WIPHY_FREQ])
  5898. return -EINVAL;
  5899. if (!rdev->ops->assoc)
  5900. return -EOPNOTSUPP;
  5901. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  5902. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  5903. return -EOPNOTSUPP;
  5904. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  5905. chan = nl80211_get_valid_chan(&rdev->wiphy,
  5906. info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  5907. if (!chan)
  5908. return -EINVAL;
  5909. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  5910. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  5911. if (info->attrs[NL80211_ATTR_IE]) {
  5912. req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  5913. req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5914. }
  5915. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  5916. enum nl80211_mfp mfp =
  5917. nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  5918. if (mfp == NL80211_MFP_REQUIRED)
  5919. req.use_mfp = true;
  5920. else if (mfp != NL80211_MFP_NO)
  5921. return -EINVAL;
  5922. }
  5923. if (info->attrs[NL80211_ATTR_PREV_BSSID])
  5924. req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
  5925. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  5926. req.flags |= ASSOC_REQ_DISABLE_HT;
  5927. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  5928. memcpy(&req.ht_capa_mask,
  5929. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  5930. sizeof(req.ht_capa_mask));
  5931. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  5932. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  5933. return -EINVAL;
  5934. memcpy(&req.ht_capa,
  5935. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  5936. sizeof(req.ht_capa));
  5937. }
  5938. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
  5939. req.flags |= ASSOC_REQ_DISABLE_VHT;
  5940. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  5941. memcpy(&req.vht_capa_mask,
  5942. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
  5943. sizeof(req.vht_capa_mask));
  5944. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
  5945. if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  5946. return -EINVAL;
  5947. memcpy(&req.vht_capa,
  5948. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
  5949. sizeof(req.vht_capa));
  5950. }
  5951. if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
  5952. if (!(rdev->wiphy.features &
  5953. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
  5954. !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
  5955. return -EINVAL;
  5956. req.flags |= ASSOC_REQ_USE_RRM;
  5957. }
  5958. err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
  5959. if (!err) {
  5960. wdev_lock(dev->ieee80211_ptr);
  5961. err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
  5962. ssid, ssid_len, &req);
  5963. wdev_unlock(dev->ieee80211_ptr);
  5964. }
  5965. return err;
  5966. }
  5967. static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
  5968. {
  5969. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5970. struct net_device *dev = info->user_ptr[1];
  5971. const u8 *ie = NULL, *bssid;
  5972. int ie_len = 0, err;
  5973. u16 reason_code;
  5974. bool local_state_change;
  5975. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  5976. return -EINVAL;
  5977. if (!info->attrs[NL80211_ATTR_MAC])
  5978. return -EINVAL;
  5979. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  5980. return -EINVAL;
  5981. if (!rdev->ops->deauth)
  5982. return -EOPNOTSUPP;
  5983. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  5984. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  5985. return -EOPNOTSUPP;
  5986. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  5987. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  5988. if (reason_code == 0) {
  5989. /* Reason Code 0 is reserved */
  5990. return -EINVAL;
  5991. }
  5992. if (info->attrs[NL80211_ATTR_IE]) {
  5993. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  5994. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5995. }
  5996. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  5997. wdev_lock(dev->ieee80211_ptr);
  5998. err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
  5999. local_state_change);
  6000. wdev_unlock(dev->ieee80211_ptr);
  6001. return err;
  6002. }
  6003. static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
  6004. {
  6005. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6006. struct net_device *dev = info->user_ptr[1];
  6007. const u8 *ie = NULL, *bssid;
  6008. int ie_len = 0, err;
  6009. u16 reason_code;
  6010. bool local_state_change;
  6011. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6012. return -EINVAL;
  6013. if (!info->attrs[NL80211_ATTR_MAC])
  6014. return -EINVAL;
  6015. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  6016. return -EINVAL;
  6017. if (!rdev->ops->disassoc)
  6018. return -EOPNOTSUPP;
  6019. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6020. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6021. return -EOPNOTSUPP;
  6022. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6023. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  6024. if (reason_code == 0) {
  6025. /* Reason Code 0 is reserved */
  6026. return -EINVAL;
  6027. }
  6028. if (info->attrs[NL80211_ATTR_IE]) {
  6029. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6030. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6031. }
  6032. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6033. wdev_lock(dev->ieee80211_ptr);
  6034. err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
  6035. local_state_change);
  6036. wdev_unlock(dev->ieee80211_ptr);
  6037. return err;
  6038. }
  6039. static bool
  6040. nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
  6041. int mcast_rate[IEEE80211_NUM_BANDS],
  6042. int rateval)
  6043. {
  6044. struct wiphy *wiphy = &rdev->wiphy;
  6045. bool found = false;
  6046. int band, i;
  6047. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  6048. struct ieee80211_supported_band *sband;
  6049. sband = wiphy->bands[band];
  6050. if (!sband)
  6051. continue;
  6052. for (i = 0; i < sband->n_bitrates; i++) {
  6053. if (sband->bitrates[i].bitrate == rateval) {
  6054. mcast_rate[band] = i + 1;
  6055. found = true;
  6056. break;
  6057. }
  6058. }
  6059. }
  6060. return found;
  6061. }
  6062. static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
  6063. {
  6064. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6065. struct net_device *dev = info->user_ptr[1];
  6066. struct cfg80211_ibss_params ibss;
  6067. struct wiphy *wiphy;
  6068. struct cfg80211_cached_keys *connkeys = NULL;
  6069. int err;
  6070. memset(&ibss, 0, sizeof(ibss));
  6071. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6072. return -EINVAL;
  6073. if (!info->attrs[NL80211_ATTR_SSID] ||
  6074. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  6075. return -EINVAL;
  6076. ibss.beacon_interval = 100;
  6077. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
  6078. ibss.beacon_interval =
  6079. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  6080. if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
  6081. return -EINVAL;
  6082. }
  6083. if (!rdev->ops->join_ibss)
  6084. return -EOPNOTSUPP;
  6085. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  6086. return -EOPNOTSUPP;
  6087. wiphy = &rdev->wiphy;
  6088. if (info->attrs[NL80211_ATTR_MAC]) {
  6089. ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6090. if (!is_valid_ether_addr(ibss.bssid))
  6091. return -EINVAL;
  6092. }
  6093. ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6094. ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6095. if (info->attrs[NL80211_ATTR_IE]) {
  6096. ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6097. ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6098. }
  6099. err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
  6100. if (err)
  6101. return err;
  6102. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
  6103. NL80211_IFTYPE_ADHOC))
  6104. return -EINVAL;
  6105. switch (ibss.chandef.width) {
  6106. case NL80211_CHAN_WIDTH_5:
  6107. case NL80211_CHAN_WIDTH_10:
  6108. case NL80211_CHAN_WIDTH_20_NOHT:
  6109. break;
  6110. case NL80211_CHAN_WIDTH_20:
  6111. case NL80211_CHAN_WIDTH_40:
  6112. if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
  6113. return -EINVAL;
  6114. break;
  6115. case NL80211_CHAN_WIDTH_80:
  6116. case NL80211_CHAN_WIDTH_80P80:
  6117. case NL80211_CHAN_WIDTH_160:
  6118. if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
  6119. return -EINVAL;
  6120. if (!wiphy_ext_feature_isset(&rdev->wiphy,
  6121. NL80211_EXT_FEATURE_VHT_IBSS))
  6122. return -EINVAL;
  6123. break;
  6124. default:
  6125. return -EINVAL;
  6126. }
  6127. ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
  6128. ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  6129. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  6130. u8 *rates =
  6131. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  6132. int n_rates =
  6133. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  6134. struct ieee80211_supported_band *sband =
  6135. wiphy->bands[ibss.chandef.chan->band];
  6136. err = ieee80211_get_ratemask(sband, rates, n_rates,
  6137. &ibss.basic_rates);
  6138. if (err)
  6139. return err;
  6140. }
  6141. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6142. memcpy(&ibss.ht_capa_mask,
  6143. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  6144. sizeof(ibss.ht_capa_mask));
  6145. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  6146. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6147. return -EINVAL;
  6148. memcpy(&ibss.ht_capa,
  6149. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  6150. sizeof(ibss.ht_capa));
  6151. }
  6152. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  6153. !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
  6154. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  6155. return -EINVAL;
  6156. if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  6157. bool no_ht = false;
  6158. connkeys = nl80211_parse_connkeys(rdev,
  6159. info->attrs[NL80211_ATTR_KEYS],
  6160. &no_ht);
  6161. if (IS_ERR(connkeys))
  6162. return PTR_ERR(connkeys);
  6163. if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
  6164. no_ht) {
  6165. kfree(connkeys);
  6166. return -EINVAL;
  6167. }
  6168. }
  6169. ibss.control_port =
  6170. nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
  6171. ibss.userspace_handles_dfs =
  6172. nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
  6173. err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
  6174. if (err)
  6175. kzfree(connkeys);
  6176. return err;
  6177. }
  6178. static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
  6179. {
  6180. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6181. struct net_device *dev = info->user_ptr[1];
  6182. if (!rdev->ops->leave_ibss)
  6183. return -EOPNOTSUPP;
  6184. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  6185. return -EOPNOTSUPP;
  6186. return cfg80211_leave_ibss(rdev, dev, false);
  6187. }
  6188. static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
  6189. {
  6190. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6191. struct net_device *dev = info->user_ptr[1];
  6192. int mcast_rate[IEEE80211_NUM_BANDS];
  6193. u32 nla_rate;
  6194. int err;
  6195. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
  6196. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  6197. return -EOPNOTSUPP;
  6198. if (!rdev->ops->set_mcast_rate)
  6199. return -EOPNOTSUPP;
  6200. memset(mcast_rate, 0, sizeof(mcast_rate));
  6201. if (!info->attrs[NL80211_ATTR_MCAST_RATE])
  6202. return -EINVAL;
  6203. nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
  6204. if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
  6205. return -EINVAL;
  6206. err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
  6207. return err;
  6208. }
  6209. static struct sk_buff *
  6210. __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
  6211. struct wireless_dev *wdev, int approxlen,
  6212. u32 portid, u32 seq, enum nl80211_commands cmd,
  6213. enum nl80211_attrs attr,
  6214. const struct nl80211_vendor_cmd_info *info,
  6215. gfp_t gfp)
  6216. {
  6217. struct sk_buff *skb;
  6218. void *hdr;
  6219. struct nlattr *data;
  6220. skb = nlmsg_new(approxlen + 100, gfp);
  6221. if (!skb)
  6222. return NULL;
  6223. hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
  6224. if (!hdr) {
  6225. kfree_skb(skb);
  6226. return NULL;
  6227. }
  6228. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  6229. goto nla_put_failure;
  6230. if (info) {
  6231. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
  6232. info->vendor_id))
  6233. goto nla_put_failure;
  6234. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
  6235. info->subcmd))
  6236. goto nla_put_failure;
  6237. }
  6238. if (wdev) {
  6239. if (nla_put_u64(skb, NL80211_ATTR_WDEV,
  6240. wdev_id(wdev)))
  6241. goto nla_put_failure;
  6242. if (wdev->netdev &&
  6243. nla_put_u32(skb, NL80211_ATTR_IFINDEX,
  6244. wdev->netdev->ifindex))
  6245. goto nla_put_failure;
  6246. }
  6247. data = nla_nest_start(skb, attr);
  6248. ((void **)skb->cb)[0] = rdev;
  6249. ((void **)skb->cb)[1] = hdr;
  6250. ((void **)skb->cb)[2] = data;
  6251. return skb;
  6252. nla_put_failure:
  6253. kfree_skb(skb);
  6254. return NULL;
  6255. }
  6256. struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
  6257. struct wireless_dev *wdev,
  6258. enum nl80211_commands cmd,
  6259. enum nl80211_attrs attr,
  6260. int vendor_event_idx,
  6261. int approxlen, gfp_t gfp)
  6262. {
  6263. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  6264. const struct nl80211_vendor_cmd_info *info;
  6265. switch (cmd) {
  6266. case NL80211_CMD_TESTMODE:
  6267. if (WARN_ON(vendor_event_idx != -1))
  6268. return NULL;
  6269. info = NULL;
  6270. break;
  6271. case NL80211_CMD_VENDOR:
  6272. if (WARN_ON(vendor_event_idx < 0 ||
  6273. vendor_event_idx >= wiphy->n_vendor_events))
  6274. return NULL;
  6275. info = &wiphy->vendor_events[vendor_event_idx];
  6276. break;
  6277. default:
  6278. WARN_ON(1);
  6279. return NULL;
  6280. }
  6281. return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
  6282. cmd, attr, info, gfp);
  6283. }
  6284. EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
  6285. void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
  6286. {
  6287. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  6288. void *hdr = ((void **)skb->cb)[1];
  6289. struct nlattr *data = ((void **)skb->cb)[2];
  6290. enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
  6291. /* clear CB data for netlink core to own from now on */
  6292. memset(skb->cb, 0, sizeof(skb->cb));
  6293. nla_nest_end(skb, data);
  6294. genlmsg_end(skb, hdr);
  6295. if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
  6296. mcgrp = NL80211_MCGRP_VENDOR;
  6297. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
  6298. mcgrp, gfp);
  6299. }
  6300. EXPORT_SYMBOL(__cfg80211_send_event_skb);
  6301. #ifdef CONFIG_NL80211_TESTMODE
  6302. static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
  6303. {
  6304. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6305. struct wireless_dev *wdev =
  6306. __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
  6307. int err;
  6308. if (!rdev->ops->testmode_cmd)
  6309. return -EOPNOTSUPP;
  6310. if (IS_ERR(wdev)) {
  6311. err = PTR_ERR(wdev);
  6312. if (err != -EINVAL)
  6313. return err;
  6314. wdev = NULL;
  6315. } else if (wdev->wiphy != &rdev->wiphy) {
  6316. return -EINVAL;
  6317. }
  6318. if (!info->attrs[NL80211_ATTR_TESTDATA])
  6319. return -EINVAL;
  6320. rdev->cur_cmd_info = info;
  6321. err = rdev_testmode_cmd(rdev, wdev,
  6322. nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
  6323. nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
  6324. rdev->cur_cmd_info = NULL;
  6325. return err;
  6326. }
  6327. static int nl80211_testmode_dump(struct sk_buff *skb,
  6328. struct netlink_callback *cb)
  6329. {
  6330. struct cfg80211_registered_device *rdev;
  6331. int err;
  6332. long phy_idx;
  6333. void *data = NULL;
  6334. int data_len = 0;
  6335. rtnl_lock();
  6336. if (cb->args[0]) {
  6337. /*
  6338. * 0 is a valid index, but not valid for args[0],
  6339. * so we need to offset by 1.
  6340. */
  6341. phy_idx = cb->args[0] - 1;
  6342. } else {
  6343. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  6344. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  6345. nl80211_policy);
  6346. if (err)
  6347. goto out_err;
  6348. rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
  6349. nl80211_fam.attrbuf);
  6350. if (IS_ERR(rdev)) {
  6351. err = PTR_ERR(rdev);
  6352. goto out_err;
  6353. }
  6354. phy_idx = rdev->wiphy_idx;
  6355. rdev = NULL;
  6356. if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
  6357. cb->args[1] =
  6358. (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
  6359. }
  6360. if (cb->args[1]) {
  6361. data = nla_data((void *)cb->args[1]);
  6362. data_len = nla_len((void *)cb->args[1]);
  6363. }
  6364. rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
  6365. if (!rdev) {
  6366. err = -ENOENT;
  6367. goto out_err;
  6368. }
  6369. if (!rdev->ops->testmode_dump) {
  6370. err = -EOPNOTSUPP;
  6371. goto out_err;
  6372. }
  6373. while (1) {
  6374. void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
  6375. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  6376. NL80211_CMD_TESTMODE);
  6377. struct nlattr *tmdata;
  6378. if (!hdr)
  6379. break;
  6380. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
  6381. genlmsg_cancel(skb, hdr);
  6382. break;
  6383. }
  6384. tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
  6385. if (!tmdata) {
  6386. genlmsg_cancel(skb, hdr);
  6387. break;
  6388. }
  6389. err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
  6390. nla_nest_end(skb, tmdata);
  6391. if (err == -ENOBUFS || err == -ENOENT) {
  6392. genlmsg_cancel(skb, hdr);
  6393. break;
  6394. } else if (err) {
  6395. genlmsg_cancel(skb, hdr);
  6396. goto out_err;
  6397. }
  6398. genlmsg_end(skb, hdr);
  6399. }
  6400. err = skb->len;
  6401. /* see above */
  6402. cb->args[0] = phy_idx + 1;
  6403. out_err:
  6404. rtnl_unlock();
  6405. return err;
  6406. }
  6407. #endif
  6408. static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
  6409. {
  6410. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6411. struct net_device *dev = info->user_ptr[1];
  6412. struct cfg80211_connect_params connect;
  6413. struct wiphy *wiphy;
  6414. struct cfg80211_cached_keys *connkeys = NULL;
  6415. int err;
  6416. memset(&connect, 0, sizeof(connect));
  6417. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6418. return -EINVAL;
  6419. if (!info->attrs[NL80211_ATTR_SSID] ||
  6420. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  6421. return -EINVAL;
  6422. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  6423. connect.auth_type =
  6424. nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  6425. if (!nl80211_valid_auth_type(rdev, connect.auth_type,
  6426. NL80211_CMD_CONNECT))
  6427. return -EINVAL;
  6428. } else
  6429. connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  6430. connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
  6431. err = nl80211_crypto_settings(rdev, info, &connect.crypto,
  6432. NL80211_MAX_NR_CIPHER_SUITES);
  6433. if (err)
  6434. return err;
  6435. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6436. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6437. return -EOPNOTSUPP;
  6438. wiphy = &rdev->wiphy;
  6439. connect.bg_scan_period = -1;
  6440. if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
  6441. (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
  6442. connect.bg_scan_period =
  6443. nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
  6444. }
  6445. if (info->attrs[NL80211_ATTR_MAC])
  6446. connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6447. else if (info->attrs[NL80211_ATTR_MAC_HINT])
  6448. connect.bssid_hint =
  6449. nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
  6450. connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6451. connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6452. if (info->attrs[NL80211_ATTR_IE]) {
  6453. connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6454. connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6455. }
  6456. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  6457. connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  6458. if (connect.mfp != NL80211_MFP_REQUIRED &&
  6459. connect.mfp != NL80211_MFP_NO)
  6460. return -EINVAL;
  6461. } else {
  6462. connect.mfp = NL80211_MFP_NO;
  6463. }
  6464. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  6465. connect.channel = nl80211_get_valid_chan(
  6466. wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  6467. if (!connect.channel)
  6468. return -EINVAL;
  6469. } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
  6470. connect.channel_hint = nl80211_get_valid_chan(
  6471. wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
  6472. if (!connect.channel_hint)
  6473. return -EINVAL;
  6474. }
  6475. if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  6476. connkeys = nl80211_parse_connkeys(rdev,
  6477. info->attrs[NL80211_ATTR_KEYS], NULL);
  6478. if (IS_ERR(connkeys))
  6479. return PTR_ERR(connkeys);
  6480. }
  6481. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  6482. connect.flags |= ASSOC_REQ_DISABLE_HT;
  6483. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6484. memcpy(&connect.ht_capa_mask,
  6485. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  6486. sizeof(connect.ht_capa_mask));
  6487. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  6488. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
  6489. kzfree(connkeys);
  6490. return -EINVAL;
  6491. }
  6492. memcpy(&connect.ht_capa,
  6493. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  6494. sizeof(connect.ht_capa));
  6495. }
  6496. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
  6497. connect.flags |= ASSOC_REQ_DISABLE_VHT;
  6498. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  6499. memcpy(&connect.vht_capa_mask,
  6500. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
  6501. sizeof(connect.vht_capa_mask));
  6502. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
  6503. if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
  6504. kzfree(connkeys);
  6505. return -EINVAL;
  6506. }
  6507. memcpy(&connect.vht_capa,
  6508. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
  6509. sizeof(connect.vht_capa));
  6510. }
  6511. if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
  6512. if (!(rdev->wiphy.features &
  6513. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
  6514. !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
  6515. return -EINVAL;
  6516. connect.flags |= ASSOC_REQ_USE_RRM;
  6517. }
  6518. wdev_lock(dev->ieee80211_ptr);
  6519. err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
  6520. wdev_unlock(dev->ieee80211_ptr);
  6521. if (err)
  6522. kzfree(connkeys);
  6523. return err;
  6524. }
  6525. static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
  6526. {
  6527. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6528. struct net_device *dev = info->user_ptr[1];
  6529. u16 reason;
  6530. int ret;
  6531. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  6532. reason = WLAN_REASON_DEAUTH_LEAVING;
  6533. else
  6534. reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  6535. if (reason == 0)
  6536. return -EINVAL;
  6537. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6538. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6539. return -EOPNOTSUPP;
  6540. wdev_lock(dev->ieee80211_ptr);
  6541. ret = cfg80211_disconnect(rdev, dev, reason, true);
  6542. wdev_unlock(dev->ieee80211_ptr);
  6543. return ret;
  6544. }
  6545. static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
  6546. {
  6547. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6548. struct net *net;
  6549. int err;
  6550. if (info->attrs[NL80211_ATTR_PID]) {
  6551. u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
  6552. net = get_net_ns_by_pid(pid);
  6553. } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
  6554. u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
  6555. net = get_net_ns_by_fd(fd);
  6556. } else {
  6557. return -EINVAL;
  6558. }
  6559. if (IS_ERR(net))
  6560. return PTR_ERR(net);
  6561. err = 0;
  6562. /* check if anything to do */
  6563. if (!net_eq(wiphy_net(&rdev->wiphy), net))
  6564. err = cfg80211_switch_netns(rdev, net);
  6565. put_net(net);
  6566. return err;
  6567. }
  6568. static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
  6569. {
  6570. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6571. int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
  6572. struct cfg80211_pmksa *pmksa) = NULL;
  6573. struct net_device *dev = info->user_ptr[1];
  6574. struct cfg80211_pmksa pmksa;
  6575. memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
  6576. if (!info->attrs[NL80211_ATTR_MAC])
  6577. return -EINVAL;
  6578. if (!info->attrs[NL80211_ATTR_PMKID])
  6579. return -EINVAL;
  6580. pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
  6581. pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6582. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6583. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6584. return -EOPNOTSUPP;
  6585. switch (info->genlhdr->cmd) {
  6586. case NL80211_CMD_SET_PMKSA:
  6587. rdev_ops = rdev->ops->set_pmksa;
  6588. break;
  6589. case NL80211_CMD_DEL_PMKSA:
  6590. rdev_ops = rdev->ops->del_pmksa;
  6591. break;
  6592. default:
  6593. WARN_ON(1);
  6594. break;
  6595. }
  6596. if (!rdev_ops)
  6597. return -EOPNOTSUPP;
  6598. return rdev_ops(&rdev->wiphy, dev, &pmksa);
  6599. }
  6600. static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
  6601. {
  6602. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6603. struct net_device *dev = info->user_ptr[1];
  6604. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6605. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6606. return -EOPNOTSUPP;
  6607. if (!rdev->ops->flush_pmksa)
  6608. return -EOPNOTSUPP;
  6609. return rdev_flush_pmksa(rdev, dev);
  6610. }
  6611. static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
  6612. {
  6613. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6614. struct net_device *dev = info->user_ptr[1];
  6615. u8 action_code, dialog_token;
  6616. u32 peer_capability = 0;
  6617. u16 status_code;
  6618. u8 *peer;
  6619. bool initiator;
  6620. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  6621. !rdev->ops->tdls_mgmt)
  6622. return -EOPNOTSUPP;
  6623. if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
  6624. !info->attrs[NL80211_ATTR_STATUS_CODE] ||
  6625. !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
  6626. !info->attrs[NL80211_ATTR_IE] ||
  6627. !info->attrs[NL80211_ATTR_MAC])
  6628. return -EINVAL;
  6629. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6630. action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
  6631. status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
  6632. dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
  6633. initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
  6634. if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
  6635. peer_capability =
  6636. nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
  6637. return rdev_tdls_mgmt(rdev, dev, peer, action_code,
  6638. dialog_token, status_code, peer_capability,
  6639. initiator,
  6640. nla_data(info->attrs[NL80211_ATTR_IE]),
  6641. nla_len(info->attrs[NL80211_ATTR_IE]));
  6642. }
  6643. static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
  6644. {
  6645. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6646. struct net_device *dev = info->user_ptr[1];
  6647. enum nl80211_tdls_operation operation;
  6648. u8 *peer;
  6649. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  6650. !rdev->ops->tdls_oper)
  6651. return -EOPNOTSUPP;
  6652. if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
  6653. !info->attrs[NL80211_ATTR_MAC])
  6654. return -EINVAL;
  6655. operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
  6656. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6657. return rdev_tdls_oper(rdev, dev, peer, operation);
  6658. }
  6659. static int nl80211_remain_on_channel(struct sk_buff *skb,
  6660. struct genl_info *info)
  6661. {
  6662. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6663. struct wireless_dev *wdev = info->user_ptr[1];
  6664. struct cfg80211_chan_def chandef;
  6665. struct sk_buff *msg;
  6666. void *hdr;
  6667. u64 cookie;
  6668. u32 duration;
  6669. int err;
  6670. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  6671. !info->attrs[NL80211_ATTR_DURATION])
  6672. return -EINVAL;
  6673. duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  6674. if (!rdev->ops->remain_on_channel ||
  6675. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
  6676. return -EOPNOTSUPP;
  6677. /*
  6678. * We should be on that channel for at least a minimum amount of
  6679. * time (10ms) but no longer than the driver supports.
  6680. */
  6681. if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
  6682. duration > rdev->wiphy.max_remain_on_channel_duration)
  6683. return -EINVAL;
  6684. err = nl80211_parse_chandef(rdev, info, &chandef);
  6685. if (err)
  6686. return err;
  6687. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  6688. if (!msg)
  6689. return -ENOMEM;
  6690. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  6691. NL80211_CMD_REMAIN_ON_CHANNEL);
  6692. if (!hdr) {
  6693. err = -ENOBUFS;
  6694. goto free_msg;
  6695. }
  6696. err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
  6697. duration, &cookie);
  6698. if (err)
  6699. goto free_msg;
  6700. if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
  6701. goto nla_put_failure;
  6702. genlmsg_end(msg, hdr);
  6703. return genlmsg_reply(msg, info);
  6704. nla_put_failure:
  6705. err = -ENOBUFS;
  6706. free_msg:
  6707. nlmsg_free(msg);
  6708. return err;
  6709. }
  6710. static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
  6711. struct genl_info *info)
  6712. {
  6713. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6714. struct wireless_dev *wdev = info->user_ptr[1];
  6715. u64 cookie;
  6716. if (!info->attrs[NL80211_ATTR_COOKIE])
  6717. return -EINVAL;
  6718. if (!rdev->ops->cancel_remain_on_channel)
  6719. return -EOPNOTSUPP;
  6720. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  6721. return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
  6722. }
  6723. static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
  6724. u8 *rates, u8 rates_len)
  6725. {
  6726. u8 i;
  6727. u32 mask = 0;
  6728. for (i = 0; i < rates_len; i++) {
  6729. int rate = (rates[i] & 0x7f) * 5;
  6730. int ridx;
  6731. for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
  6732. struct ieee80211_rate *srate =
  6733. &sband->bitrates[ridx];
  6734. if (rate == srate->bitrate) {
  6735. mask |= 1 << ridx;
  6736. break;
  6737. }
  6738. }
  6739. if (ridx == sband->n_bitrates)
  6740. return 0; /* rate not found */
  6741. }
  6742. return mask;
  6743. }
  6744. static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
  6745. u8 *rates, u8 rates_len,
  6746. u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
  6747. {
  6748. u8 i;
  6749. memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
  6750. for (i = 0; i < rates_len; i++) {
  6751. int ridx, rbit;
  6752. ridx = rates[i] / 8;
  6753. rbit = BIT(rates[i] % 8);
  6754. /* check validity */
  6755. if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
  6756. return false;
  6757. /* check availability */
  6758. if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
  6759. mcs[ridx] |= rbit;
  6760. else
  6761. return false;
  6762. }
  6763. return true;
  6764. }
  6765. static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
  6766. {
  6767. u16 mcs_mask = 0;
  6768. switch (vht_mcs_map) {
  6769. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  6770. break;
  6771. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  6772. mcs_mask = 0x00FF;
  6773. break;
  6774. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  6775. mcs_mask = 0x01FF;
  6776. break;
  6777. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  6778. mcs_mask = 0x03FF;
  6779. break;
  6780. default:
  6781. break;
  6782. }
  6783. return mcs_mask;
  6784. }
  6785. static void vht_build_mcs_mask(u16 vht_mcs_map,
  6786. u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  6787. {
  6788. u8 nss;
  6789. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
  6790. vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
  6791. vht_mcs_map >>= 2;
  6792. }
  6793. }
  6794. static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
  6795. struct nl80211_txrate_vht *txrate,
  6796. u16 mcs[NL80211_VHT_NSS_MAX])
  6797. {
  6798. u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  6799. u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
  6800. u8 i;
  6801. if (!sband->vht_cap.vht_supported)
  6802. return false;
  6803. memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
  6804. /* Build vht_mcs_mask from VHT capabilities */
  6805. vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
  6806. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  6807. if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
  6808. mcs[i] = txrate->mcs[i];
  6809. else
  6810. return false;
  6811. }
  6812. return true;
  6813. }
  6814. static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
  6815. [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
  6816. .len = NL80211_MAX_SUPP_RATES },
  6817. [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
  6818. .len = NL80211_MAX_SUPP_HT_RATES },
  6819. [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
  6820. [NL80211_TXRATE_GI] = { .type = NLA_U8 },
  6821. };
  6822. static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
  6823. struct genl_info *info)
  6824. {
  6825. struct nlattr *tb[NL80211_TXRATE_MAX + 1];
  6826. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6827. struct cfg80211_bitrate_mask mask;
  6828. int rem, i;
  6829. struct net_device *dev = info->user_ptr[1];
  6830. struct nlattr *tx_rates;
  6831. struct ieee80211_supported_band *sband;
  6832. u16 vht_tx_mcs_map;
  6833. if (!rdev->ops->set_bitrate_mask)
  6834. return -EOPNOTSUPP;
  6835. memset(&mask, 0, sizeof(mask));
  6836. /* Default to all rates enabled */
  6837. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  6838. sband = rdev->wiphy.bands[i];
  6839. if (!sband)
  6840. continue;
  6841. mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
  6842. memcpy(mask.control[i].ht_mcs,
  6843. sband->ht_cap.mcs.rx_mask,
  6844. sizeof(mask.control[i].ht_mcs));
  6845. if (!sband->vht_cap.vht_supported)
  6846. continue;
  6847. vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  6848. vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
  6849. }
  6850. /* if no rates are given set it back to the defaults */
  6851. if (!info->attrs[NL80211_ATTR_TX_RATES])
  6852. goto out;
  6853. /*
  6854. * The nested attribute uses enum nl80211_band as the index. This maps
  6855. * directly to the enum ieee80211_band values used in cfg80211.
  6856. */
  6857. BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
  6858. nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
  6859. enum ieee80211_band band = nla_type(tx_rates);
  6860. int err;
  6861. if (band < 0 || band >= IEEE80211_NUM_BANDS)
  6862. return -EINVAL;
  6863. sband = rdev->wiphy.bands[band];
  6864. if (sband == NULL)
  6865. return -EINVAL;
  6866. err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
  6867. nla_len(tx_rates), nl80211_txattr_policy);
  6868. if (err)
  6869. return err;
  6870. if (tb[NL80211_TXRATE_LEGACY]) {
  6871. mask.control[band].legacy = rateset_to_mask(
  6872. sband,
  6873. nla_data(tb[NL80211_TXRATE_LEGACY]),
  6874. nla_len(tb[NL80211_TXRATE_LEGACY]));
  6875. if ((mask.control[band].legacy == 0) &&
  6876. nla_len(tb[NL80211_TXRATE_LEGACY]))
  6877. return -EINVAL;
  6878. }
  6879. if (tb[NL80211_TXRATE_HT]) {
  6880. if (!ht_rateset_to_mask(
  6881. sband,
  6882. nla_data(tb[NL80211_TXRATE_HT]),
  6883. nla_len(tb[NL80211_TXRATE_HT]),
  6884. mask.control[band].ht_mcs))
  6885. return -EINVAL;
  6886. }
  6887. if (tb[NL80211_TXRATE_VHT]) {
  6888. if (!vht_set_mcs_mask(
  6889. sband,
  6890. nla_data(tb[NL80211_TXRATE_VHT]),
  6891. mask.control[band].vht_mcs))
  6892. return -EINVAL;
  6893. }
  6894. if (tb[NL80211_TXRATE_GI]) {
  6895. mask.control[band].gi =
  6896. nla_get_u8(tb[NL80211_TXRATE_GI]);
  6897. if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
  6898. return -EINVAL;
  6899. }
  6900. if (mask.control[band].legacy == 0) {
  6901. /* don't allow empty legacy rates if HT or VHT
  6902. * are not even supported.
  6903. */
  6904. if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
  6905. rdev->wiphy.bands[band]->vht_cap.vht_supported))
  6906. return -EINVAL;
  6907. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  6908. if (mask.control[band].ht_mcs[i])
  6909. goto out;
  6910. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  6911. if (mask.control[band].vht_mcs[i])
  6912. goto out;
  6913. /* legacy and mcs rates may not be both empty */
  6914. return -EINVAL;
  6915. }
  6916. }
  6917. out:
  6918. return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
  6919. }
  6920. static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
  6921. {
  6922. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6923. struct wireless_dev *wdev = info->user_ptr[1];
  6924. u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
  6925. if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
  6926. return -EINVAL;
  6927. if (info->attrs[NL80211_ATTR_FRAME_TYPE])
  6928. frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
  6929. switch (wdev->iftype) {
  6930. case NL80211_IFTYPE_STATION:
  6931. case NL80211_IFTYPE_ADHOC:
  6932. case NL80211_IFTYPE_P2P_CLIENT:
  6933. case NL80211_IFTYPE_AP:
  6934. case NL80211_IFTYPE_AP_VLAN:
  6935. case NL80211_IFTYPE_MESH_POINT:
  6936. case NL80211_IFTYPE_P2P_GO:
  6937. case NL80211_IFTYPE_P2P_DEVICE:
  6938. break;
  6939. default:
  6940. return -EOPNOTSUPP;
  6941. }
  6942. /* not much point in registering if we can't reply */
  6943. if (!rdev->ops->mgmt_tx)
  6944. return -EOPNOTSUPP;
  6945. return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
  6946. nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
  6947. nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
  6948. }
  6949. static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
  6950. {
  6951. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6952. struct wireless_dev *wdev = info->user_ptr[1];
  6953. struct cfg80211_chan_def chandef;
  6954. int err;
  6955. void *hdr = NULL;
  6956. u64 cookie;
  6957. struct sk_buff *msg = NULL;
  6958. struct cfg80211_mgmt_tx_params params = {
  6959. .dont_wait_for_ack =
  6960. info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
  6961. };
  6962. if (!info->attrs[NL80211_ATTR_FRAME])
  6963. return -EINVAL;
  6964. if (!rdev->ops->mgmt_tx)
  6965. return -EOPNOTSUPP;
  6966. switch (wdev->iftype) {
  6967. case NL80211_IFTYPE_P2P_DEVICE:
  6968. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  6969. return -EINVAL;
  6970. case NL80211_IFTYPE_STATION:
  6971. case NL80211_IFTYPE_ADHOC:
  6972. case NL80211_IFTYPE_P2P_CLIENT:
  6973. case NL80211_IFTYPE_AP:
  6974. case NL80211_IFTYPE_AP_VLAN:
  6975. case NL80211_IFTYPE_MESH_POINT:
  6976. case NL80211_IFTYPE_P2P_GO:
  6977. break;
  6978. default:
  6979. return -EOPNOTSUPP;
  6980. }
  6981. if (info->attrs[NL80211_ATTR_DURATION]) {
  6982. if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  6983. return -EINVAL;
  6984. params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  6985. /*
  6986. * We should wait on the channel for at least a minimum amount
  6987. * of time (10ms) but no longer than the driver supports.
  6988. */
  6989. if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
  6990. params.wait > rdev->wiphy.max_remain_on_channel_duration)
  6991. return -EINVAL;
  6992. }
  6993. params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
  6994. if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  6995. return -EINVAL;
  6996. params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  6997. /* get the channel if any has been specified, otherwise pass NULL to
  6998. * the driver. The latter will use the current one
  6999. */
  7000. chandef.chan = NULL;
  7001. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7002. err = nl80211_parse_chandef(rdev, info, &chandef);
  7003. if (err)
  7004. return err;
  7005. }
  7006. if (!chandef.chan && params.offchan)
  7007. return -EINVAL;
  7008. params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
  7009. params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
  7010. if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
  7011. int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
  7012. int i;
  7013. if (len % sizeof(u16))
  7014. return -EINVAL;
  7015. params.n_csa_offsets = len / sizeof(u16);
  7016. params.csa_offsets =
  7017. nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
  7018. /* check that all the offsets fit the frame */
  7019. for (i = 0; i < params.n_csa_offsets; i++) {
  7020. if (params.csa_offsets[i] >= params.len)
  7021. return -EINVAL;
  7022. }
  7023. }
  7024. if (!params.dont_wait_for_ack) {
  7025. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7026. if (!msg)
  7027. return -ENOMEM;
  7028. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7029. NL80211_CMD_FRAME);
  7030. if (!hdr) {
  7031. err = -ENOBUFS;
  7032. goto free_msg;
  7033. }
  7034. }
  7035. params.chan = chandef.chan;
  7036. err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
  7037. if (err)
  7038. goto free_msg;
  7039. if (msg) {
  7040. if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
  7041. goto nla_put_failure;
  7042. genlmsg_end(msg, hdr);
  7043. return genlmsg_reply(msg, info);
  7044. }
  7045. return 0;
  7046. nla_put_failure:
  7047. err = -ENOBUFS;
  7048. free_msg:
  7049. nlmsg_free(msg);
  7050. return err;
  7051. }
  7052. static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
  7053. {
  7054. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7055. struct wireless_dev *wdev = info->user_ptr[1];
  7056. u64 cookie;
  7057. if (!info->attrs[NL80211_ATTR_COOKIE])
  7058. return -EINVAL;
  7059. if (!rdev->ops->mgmt_tx_cancel_wait)
  7060. return -EOPNOTSUPP;
  7061. switch (wdev->iftype) {
  7062. case NL80211_IFTYPE_STATION:
  7063. case NL80211_IFTYPE_ADHOC:
  7064. case NL80211_IFTYPE_P2P_CLIENT:
  7065. case NL80211_IFTYPE_AP:
  7066. case NL80211_IFTYPE_AP_VLAN:
  7067. case NL80211_IFTYPE_P2P_GO:
  7068. case NL80211_IFTYPE_P2P_DEVICE:
  7069. break;
  7070. default:
  7071. return -EOPNOTSUPP;
  7072. }
  7073. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  7074. return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
  7075. }
  7076. static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
  7077. {
  7078. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7079. struct wireless_dev *wdev;
  7080. struct net_device *dev = info->user_ptr[1];
  7081. u8 ps_state;
  7082. bool state;
  7083. int err;
  7084. if (!info->attrs[NL80211_ATTR_PS_STATE])
  7085. return -EINVAL;
  7086. ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
  7087. if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
  7088. return -EINVAL;
  7089. wdev = dev->ieee80211_ptr;
  7090. if (!rdev->ops->set_power_mgmt)
  7091. return -EOPNOTSUPP;
  7092. state = (ps_state == NL80211_PS_ENABLED) ? true : false;
  7093. if (state == wdev->ps)
  7094. return 0;
  7095. err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
  7096. if (!err)
  7097. wdev->ps = state;
  7098. return err;
  7099. }
  7100. static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
  7101. {
  7102. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7103. enum nl80211_ps_state ps_state;
  7104. struct wireless_dev *wdev;
  7105. struct net_device *dev = info->user_ptr[1];
  7106. struct sk_buff *msg;
  7107. void *hdr;
  7108. int err;
  7109. wdev = dev->ieee80211_ptr;
  7110. if (!rdev->ops->set_power_mgmt)
  7111. return -EOPNOTSUPP;
  7112. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7113. if (!msg)
  7114. return -ENOMEM;
  7115. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7116. NL80211_CMD_GET_POWER_SAVE);
  7117. if (!hdr) {
  7118. err = -ENOBUFS;
  7119. goto free_msg;
  7120. }
  7121. if (wdev->ps)
  7122. ps_state = NL80211_PS_ENABLED;
  7123. else
  7124. ps_state = NL80211_PS_DISABLED;
  7125. if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
  7126. goto nla_put_failure;
  7127. genlmsg_end(msg, hdr);
  7128. return genlmsg_reply(msg, info);
  7129. nla_put_failure:
  7130. err = -ENOBUFS;
  7131. free_msg:
  7132. nlmsg_free(msg);
  7133. return err;
  7134. }
  7135. static const struct nla_policy
  7136. nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
  7137. [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
  7138. [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
  7139. [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
  7140. [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
  7141. [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
  7142. [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
  7143. };
  7144. static int nl80211_set_cqm_txe(struct genl_info *info,
  7145. u32 rate, u32 pkts, u32 intvl)
  7146. {
  7147. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7148. struct net_device *dev = info->user_ptr[1];
  7149. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7150. if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
  7151. return -EINVAL;
  7152. if (!rdev->ops->set_cqm_txe_config)
  7153. return -EOPNOTSUPP;
  7154. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  7155. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7156. return -EOPNOTSUPP;
  7157. return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
  7158. }
  7159. static int nl80211_set_cqm_rssi(struct genl_info *info,
  7160. s32 threshold, u32 hysteresis)
  7161. {
  7162. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7163. struct net_device *dev = info->user_ptr[1];
  7164. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7165. if (threshold > 0)
  7166. return -EINVAL;
  7167. /* disabling - hysteresis should also be zero then */
  7168. if (threshold == 0)
  7169. hysteresis = 0;
  7170. if (!rdev->ops->set_cqm_rssi_config)
  7171. return -EOPNOTSUPP;
  7172. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  7173. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7174. return -EOPNOTSUPP;
  7175. return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
  7176. }
  7177. static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
  7178. {
  7179. struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
  7180. struct nlattr *cqm;
  7181. int err;
  7182. cqm = info->attrs[NL80211_ATTR_CQM];
  7183. if (!cqm)
  7184. return -EINVAL;
  7185. err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
  7186. nl80211_attr_cqm_policy);
  7187. if (err)
  7188. return err;
  7189. if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
  7190. attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
  7191. s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
  7192. u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
  7193. return nl80211_set_cqm_rssi(info, threshold, hysteresis);
  7194. }
  7195. if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
  7196. attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
  7197. attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
  7198. u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
  7199. u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
  7200. u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
  7201. return nl80211_set_cqm_txe(info, rate, pkts, intvl);
  7202. }
  7203. return -EINVAL;
  7204. }
  7205. static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
  7206. {
  7207. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7208. struct net_device *dev = info->user_ptr[1];
  7209. struct ocb_setup setup = {};
  7210. int err;
  7211. err = nl80211_parse_chandef(rdev, info, &setup.chandef);
  7212. if (err)
  7213. return err;
  7214. return cfg80211_join_ocb(rdev, dev, &setup);
  7215. }
  7216. static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
  7217. {
  7218. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7219. struct net_device *dev = info->user_ptr[1];
  7220. return cfg80211_leave_ocb(rdev, dev);
  7221. }
  7222. static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
  7223. {
  7224. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7225. struct net_device *dev = info->user_ptr[1];
  7226. struct mesh_config cfg;
  7227. struct mesh_setup setup;
  7228. int err;
  7229. /* start with default */
  7230. memcpy(&cfg, &default_mesh_config, sizeof(cfg));
  7231. memcpy(&setup, &default_mesh_setup, sizeof(setup));
  7232. if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
  7233. /* and parse parameters if given */
  7234. err = nl80211_parse_mesh_config(info, &cfg, NULL);
  7235. if (err)
  7236. return err;
  7237. }
  7238. if (!info->attrs[NL80211_ATTR_MESH_ID] ||
  7239. !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
  7240. return -EINVAL;
  7241. setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
  7242. setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  7243. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  7244. !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
  7245. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  7246. return -EINVAL;
  7247. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
  7248. setup.beacon_interval =
  7249. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  7250. if (setup.beacon_interval < 10 ||
  7251. setup.beacon_interval > 10000)
  7252. return -EINVAL;
  7253. }
  7254. if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
  7255. setup.dtim_period =
  7256. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  7257. if (setup.dtim_period < 1 || setup.dtim_period > 100)
  7258. return -EINVAL;
  7259. }
  7260. if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
  7261. /* parse additional setup parameters if given */
  7262. err = nl80211_parse_mesh_setup(info, &setup);
  7263. if (err)
  7264. return err;
  7265. }
  7266. if (setup.user_mpm)
  7267. cfg.auto_open_plinks = false;
  7268. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7269. err = nl80211_parse_chandef(rdev, info, &setup.chandef);
  7270. if (err)
  7271. return err;
  7272. } else {
  7273. /* cfg80211_join_mesh() will sort it out */
  7274. setup.chandef.chan = NULL;
  7275. }
  7276. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  7277. u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  7278. int n_rates =
  7279. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  7280. struct ieee80211_supported_band *sband;
  7281. if (!setup.chandef.chan)
  7282. return -EINVAL;
  7283. sband = rdev->wiphy.bands[setup.chandef.chan->band];
  7284. err = ieee80211_get_ratemask(sband, rates, n_rates,
  7285. &setup.basic_rates);
  7286. if (err)
  7287. return err;
  7288. }
  7289. return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
  7290. }
  7291. static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
  7292. {
  7293. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7294. struct net_device *dev = info->user_ptr[1];
  7295. return cfg80211_leave_mesh(rdev, dev);
  7296. }
  7297. #ifdef CONFIG_PM
  7298. static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
  7299. struct cfg80211_registered_device *rdev)
  7300. {
  7301. struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
  7302. struct nlattr *nl_pats, *nl_pat;
  7303. int i, pat_len;
  7304. if (!wowlan->n_patterns)
  7305. return 0;
  7306. nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
  7307. if (!nl_pats)
  7308. return -ENOBUFS;
  7309. for (i = 0; i < wowlan->n_patterns; i++) {
  7310. nl_pat = nla_nest_start(msg, i + 1);
  7311. if (!nl_pat)
  7312. return -ENOBUFS;
  7313. pat_len = wowlan->patterns[i].pattern_len;
  7314. if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
  7315. wowlan->patterns[i].mask) ||
  7316. nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
  7317. wowlan->patterns[i].pattern) ||
  7318. nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
  7319. wowlan->patterns[i].pkt_offset))
  7320. return -ENOBUFS;
  7321. nla_nest_end(msg, nl_pat);
  7322. }
  7323. nla_nest_end(msg, nl_pats);
  7324. return 0;
  7325. }
  7326. static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
  7327. struct cfg80211_wowlan_tcp *tcp)
  7328. {
  7329. struct nlattr *nl_tcp;
  7330. if (!tcp)
  7331. return 0;
  7332. nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
  7333. if (!nl_tcp)
  7334. return -ENOBUFS;
  7335. if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
  7336. nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
  7337. nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
  7338. nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
  7339. nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
  7340. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  7341. tcp->payload_len, tcp->payload) ||
  7342. nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
  7343. tcp->data_interval) ||
  7344. nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  7345. tcp->wake_len, tcp->wake_data) ||
  7346. nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
  7347. DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
  7348. return -ENOBUFS;
  7349. if (tcp->payload_seq.len &&
  7350. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
  7351. sizeof(tcp->payload_seq), &tcp->payload_seq))
  7352. return -ENOBUFS;
  7353. if (tcp->payload_tok.len &&
  7354. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  7355. sizeof(tcp->payload_tok) + tcp->tokens_size,
  7356. &tcp->payload_tok))
  7357. return -ENOBUFS;
  7358. nla_nest_end(msg, nl_tcp);
  7359. return 0;
  7360. }
  7361. static int nl80211_send_wowlan_nd(struct sk_buff *msg,
  7362. struct cfg80211_sched_scan_request *req)
  7363. {
  7364. struct nlattr *nd, *freqs, *matches, *match;
  7365. int i;
  7366. if (!req)
  7367. return 0;
  7368. nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
  7369. if (!nd)
  7370. return -ENOBUFS;
  7371. if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
  7372. return -ENOBUFS;
  7373. if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
  7374. return -ENOBUFS;
  7375. freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  7376. if (!freqs)
  7377. return -ENOBUFS;
  7378. for (i = 0; i < req->n_channels; i++)
  7379. nla_put_u32(msg, i, req->channels[i]->center_freq);
  7380. nla_nest_end(msg, freqs);
  7381. if (req->n_match_sets) {
  7382. matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
  7383. for (i = 0; i < req->n_match_sets; i++) {
  7384. match = nla_nest_start(msg, i);
  7385. nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
  7386. req->match_sets[i].ssid.ssid_len,
  7387. req->match_sets[i].ssid.ssid);
  7388. nla_nest_end(msg, match);
  7389. }
  7390. nla_nest_end(msg, matches);
  7391. }
  7392. nla_nest_end(msg, nd);
  7393. return 0;
  7394. }
  7395. static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
  7396. {
  7397. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7398. struct sk_buff *msg;
  7399. void *hdr;
  7400. u32 size = NLMSG_DEFAULT_SIZE;
  7401. if (!rdev->wiphy.wowlan)
  7402. return -EOPNOTSUPP;
  7403. if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
  7404. /* adjust size to have room for all the data */
  7405. size += rdev->wiphy.wowlan_config->tcp->tokens_size +
  7406. rdev->wiphy.wowlan_config->tcp->payload_len +
  7407. rdev->wiphy.wowlan_config->tcp->wake_len +
  7408. rdev->wiphy.wowlan_config->tcp->wake_len / 8;
  7409. }
  7410. msg = nlmsg_new(size, GFP_KERNEL);
  7411. if (!msg)
  7412. return -ENOMEM;
  7413. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7414. NL80211_CMD_GET_WOWLAN);
  7415. if (!hdr)
  7416. goto nla_put_failure;
  7417. if (rdev->wiphy.wowlan_config) {
  7418. struct nlattr *nl_wowlan;
  7419. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  7420. if (!nl_wowlan)
  7421. goto nla_put_failure;
  7422. if ((rdev->wiphy.wowlan_config->any &&
  7423. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  7424. (rdev->wiphy.wowlan_config->disconnect &&
  7425. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  7426. (rdev->wiphy.wowlan_config->magic_pkt &&
  7427. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  7428. (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
  7429. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  7430. (rdev->wiphy.wowlan_config->eap_identity_req &&
  7431. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  7432. (rdev->wiphy.wowlan_config->four_way_handshake &&
  7433. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  7434. (rdev->wiphy.wowlan_config->rfkill_release &&
  7435. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
  7436. goto nla_put_failure;
  7437. if (nl80211_send_wowlan_patterns(msg, rdev))
  7438. goto nla_put_failure;
  7439. if (nl80211_send_wowlan_tcp(msg,
  7440. rdev->wiphy.wowlan_config->tcp))
  7441. goto nla_put_failure;
  7442. if (nl80211_send_wowlan_nd(
  7443. msg,
  7444. rdev->wiphy.wowlan_config->nd_config))
  7445. goto nla_put_failure;
  7446. nla_nest_end(msg, nl_wowlan);
  7447. }
  7448. genlmsg_end(msg, hdr);
  7449. return genlmsg_reply(msg, info);
  7450. nla_put_failure:
  7451. nlmsg_free(msg);
  7452. return -ENOBUFS;
  7453. }
  7454. static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
  7455. struct nlattr *attr,
  7456. struct cfg80211_wowlan *trig)
  7457. {
  7458. struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
  7459. struct cfg80211_wowlan_tcp *cfg;
  7460. struct nl80211_wowlan_tcp_data_token *tok = NULL;
  7461. struct nl80211_wowlan_tcp_data_seq *seq = NULL;
  7462. u32 size;
  7463. u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
  7464. int err, port;
  7465. if (!rdev->wiphy.wowlan->tcp)
  7466. return -EINVAL;
  7467. err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
  7468. nla_data(attr), nla_len(attr),
  7469. nl80211_wowlan_tcp_policy);
  7470. if (err)
  7471. return err;
  7472. if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
  7473. !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
  7474. !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
  7475. !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
  7476. !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
  7477. !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
  7478. !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
  7479. !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
  7480. return -EINVAL;
  7481. data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
  7482. if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
  7483. return -EINVAL;
  7484. if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
  7485. rdev->wiphy.wowlan->tcp->data_interval_max ||
  7486. nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
  7487. return -EINVAL;
  7488. wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
  7489. if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
  7490. return -EINVAL;
  7491. wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
  7492. if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
  7493. return -EINVAL;
  7494. if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
  7495. u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
  7496. tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
  7497. tokens_size = tokln - sizeof(*tok);
  7498. if (!tok->len || tokens_size % tok->len)
  7499. return -EINVAL;
  7500. if (!rdev->wiphy.wowlan->tcp->tok)
  7501. return -EINVAL;
  7502. if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
  7503. return -EINVAL;
  7504. if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
  7505. return -EINVAL;
  7506. if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
  7507. return -EINVAL;
  7508. if (tok->offset + tok->len > data_size)
  7509. return -EINVAL;
  7510. }
  7511. if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
  7512. seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
  7513. if (!rdev->wiphy.wowlan->tcp->seq)
  7514. return -EINVAL;
  7515. if (seq->len == 0 || seq->len > 4)
  7516. return -EINVAL;
  7517. if (seq->len + seq->offset > data_size)
  7518. return -EINVAL;
  7519. }
  7520. size = sizeof(*cfg);
  7521. size += data_size;
  7522. size += wake_size + wake_mask_size;
  7523. size += tokens_size;
  7524. cfg = kzalloc(size, GFP_KERNEL);
  7525. if (!cfg)
  7526. return -ENOMEM;
  7527. cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
  7528. cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
  7529. memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
  7530. ETH_ALEN);
  7531. if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
  7532. port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
  7533. else
  7534. port = 0;
  7535. #ifdef CONFIG_INET
  7536. /* allocate a socket and port for it and use it */
  7537. err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
  7538. IPPROTO_TCP, &cfg->sock, 1);
  7539. if (err) {
  7540. kfree(cfg);
  7541. return err;
  7542. }
  7543. if (inet_csk_get_port(cfg->sock->sk, port)) {
  7544. sock_release(cfg->sock);
  7545. kfree(cfg);
  7546. return -EADDRINUSE;
  7547. }
  7548. cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
  7549. #else
  7550. if (!port) {
  7551. kfree(cfg);
  7552. return -EINVAL;
  7553. }
  7554. cfg->src_port = port;
  7555. #endif
  7556. cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
  7557. cfg->payload_len = data_size;
  7558. cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
  7559. memcpy((void *)cfg->payload,
  7560. nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
  7561. data_size);
  7562. if (seq)
  7563. cfg->payload_seq = *seq;
  7564. cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
  7565. cfg->wake_len = wake_size;
  7566. cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
  7567. memcpy((void *)cfg->wake_data,
  7568. nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
  7569. wake_size);
  7570. cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
  7571. data_size + wake_size;
  7572. memcpy((void *)cfg->wake_mask,
  7573. nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
  7574. wake_mask_size);
  7575. if (tok) {
  7576. cfg->tokens_size = tokens_size;
  7577. memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
  7578. }
  7579. trig->tcp = cfg;
  7580. return 0;
  7581. }
  7582. static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
  7583. const struct wiphy_wowlan_support *wowlan,
  7584. struct nlattr *attr,
  7585. struct cfg80211_wowlan *trig)
  7586. {
  7587. struct nlattr **tb;
  7588. int err;
  7589. tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
  7590. if (!tb)
  7591. return -ENOMEM;
  7592. if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
  7593. err = -EOPNOTSUPP;
  7594. goto out;
  7595. }
  7596. err = nla_parse(tb, NL80211_ATTR_MAX,
  7597. nla_data(attr), nla_len(attr),
  7598. nl80211_policy);
  7599. if (err)
  7600. goto out;
  7601. trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
  7602. err = PTR_ERR_OR_ZERO(trig->nd_config);
  7603. if (err)
  7604. trig->nd_config = NULL;
  7605. out:
  7606. kfree(tb);
  7607. return err;
  7608. }
  7609. static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
  7610. {
  7611. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7612. struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
  7613. struct cfg80211_wowlan new_triggers = {};
  7614. struct cfg80211_wowlan *ntrig;
  7615. const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
  7616. int err, i;
  7617. bool prev_enabled = rdev->wiphy.wowlan_config;
  7618. bool regular = false;
  7619. if (!wowlan)
  7620. return -EOPNOTSUPP;
  7621. if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
  7622. cfg80211_rdev_free_wowlan(rdev);
  7623. rdev->wiphy.wowlan_config = NULL;
  7624. goto set_wakeup;
  7625. }
  7626. err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
  7627. nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  7628. nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  7629. nl80211_wowlan_policy);
  7630. if (err)
  7631. return err;
  7632. if (tb[NL80211_WOWLAN_TRIG_ANY]) {
  7633. if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
  7634. return -EINVAL;
  7635. new_triggers.any = true;
  7636. }
  7637. if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
  7638. if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
  7639. return -EINVAL;
  7640. new_triggers.disconnect = true;
  7641. regular = true;
  7642. }
  7643. if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
  7644. if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
  7645. return -EINVAL;
  7646. new_triggers.magic_pkt = true;
  7647. regular = true;
  7648. }
  7649. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
  7650. return -EINVAL;
  7651. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
  7652. if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
  7653. return -EINVAL;
  7654. new_triggers.gtk_rekey_failure = true;
  7655. regular = true;
  7656. }
  7657. if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
  7658. if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
  7659. return -EINVAL;
  7660. new_triggers.eap_identity_req = true;
  7661. regular = true;
  7662. }
  7663. if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
  7664. if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
  7665. return -EINVAL;
  7666. new_triggers.four_way_handshake = true;
  7667. regular = true;
  7668. }
  7669. if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
  7670. if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
  7671. return -EINVAL;
  7672. new_triggers.rfkill_release = true;
  7673. regular = true;
  7674. }
  7675. if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
  7676. struct nlattr *pat;
  7677. int n_patterns = 0;
  7678. int rem, pat_len, mask_len, pkt_offset;
  7679. struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
  7680. regular = true;
  7681. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  7682. rem)
  7683. n_patterns++;
  7684. if (n_patterns > wowlan->n_patterns)
  7685. return -EINVAL;
  7686. new_triggers.patterns = kcalloc(n_patterns,
  7687. sizeof(new_triggers.patterns[0]),
  7688. GFP_KERNEL);
  7689. if (!new_triggers.patterns)
  7690. return -ENOMEM;
  7691. new_triggers.n_patterns = n_patterns;
  7692. i = 0;
  7693. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  7694. rem) {
  7695. u8 *mask_pat;
  7696. nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
  7697. nla_len(pat), NULL);
  7698. err = -EINVAL;
  7699. if (!pat_tb[NL80211_PKTPAT_MASK] ||
  7700. !pat_tb[NL80211_PKTPAT_PATTERN])
  7701. goto error;
  7702. pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
  7703. mask_len = DIV_ROUND_UP(pat_len, 8);
  7704. if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
  7705. goto error;
  7706. if (pat_len > wowlan->pattern_max_len ||
  7707. pat_len < wowlan->pattern_min_len)
  7708. goto error;
  7709. if (!pat_tb[NL80211_PKTPAT_OFFSET])
  7710. pkt_offset = 0;
  7711. else
  7712. pkt_offset = nla_get_u32(
  7713. pat_tb[NL80211_PKTPAT_OFFSET]);
  7714. if (pkt_offset > wowlan->max_pkt_offset)
  7715. goto error;
  7716. new_triggers.patterns[i].pkt_offset = pkt_offset;
  7717. mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
  7718. if (!mask_pat) {
  7719. err = -ENOMEM;
  7720. goto error;
  7721. }
  7722. new_triggers.patterns[i].mask = mask_pat;
  7723. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
  7724. mask_len);
  7725. mask_pat += mask_len;
  7726. new_triggers.patterns[i].pattern = mask_pat;
  7727. new_triggers.patterns[i].pattern_len = pat_len;
  7728. memcpy(mask_pat,
  7729. nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
  7730. pat_len);
  7731. i++;
  7732. }
  7733. }
  7734. if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
  7735. regular = true;
  7736. err = nl80211_parse_wowlan_tcp(
  7737. rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
  7738. &new_triggers);
  7739. if (err)
  7740. goto error;
  7741. }
  7742. if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
  7743. regular = true;
  7744. err = nl80211_parse_wowlan_nd(
  7745. rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
  7746. &new_triggers);
  7747. if (err)
  7748. goto error;
  7749. }
  7750. /* The 'any' trigger means the device continues operating more or less
  7751. * as in its normal operation mode and wakes up the host on most of the
  7752. * normal interrupts (like packet RX, ...)
  7753. * It therefore makes little sense to combine with the more constrained
  7754. * wakeup trigger modes.
  7755. */
  7756. if (new_triggers.any && regular) {
  7757. err = -EINVAL;
  7758. goto error;
  7759. }
  7760. ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
  7761. if (!ntrig) {
  7762. err = -ENOMEM;
  7763. goto error;
  7764. }
  7765. cfg80211_rdev_free_wowlan(rdev);
  7766. rdev->wiphy.wowlan_config = ntrig;
  7767. set_wakeup:
  7768. if (rdev->ops->set_wakeup &&
  7769. prev_enabled != !!rdev->wiphy.wowlan_config)
  7770. rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
  7771. return 0;
  7772. error:
  7773. for (i = 0; i < new_triggers.n_patterns; i++)
  7774. kfree(new_triggers.patterns[i].mask);
  7775. kfree(new_triggers.patterns);
  7776. if (new_triggers.tcp && new_triggers.tcp->sock)
  7777. sock_release(new_triggers.tcp->sock);
  7778. kfree(new_triggers.tcp);
  7779. return err;
  7780. }
  7781. #endif
  7782. static int nl80211_send_coalesce_rules(struct sk_buff *msg,
  7783. struct cfg80211_registered_device *rdev)
  7784. {
  7785. struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
  7786. int i, j, pat_len;
  7787. struct cfg80211_coalesce_rules *rule;
  7788. if (!rdev->coalesce->n_rules)
  7789. return 0;
  7790. nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
  7791. if (!nl_rules)
  7792. return -ENOBUFS;
  7793. for (i = 0; i < rdev->coalesce->n_rules; i++) {
  7794. nl_rule = nla_nest_start(msg, i + 1);
  7795. if (!nl_rule)
  7796. return -ENOBUFS;
  7797. rule = &rdev->coalesce->rules[i];
  7798. if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
  7799. rule->delay))
  7800. return -ENOBUFS;
  7801. if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
  7802. rule->condition))
  7803. return -ENOBUFS;
  7804. nl_pats = nla_nest_start(msg,
  7805. NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
  7806. if (!nl_pats)
  7807. return -ENOBUFS;
  7808. for (j = 0; j < rule->n_patterns; j++) {
  7809. nl_pat = nla_nest_start(msg, j + 1);
  7810. if (!nl_pat)
  7811. return -ENOBUFS;
  7812. pat_len = rule->patterns[j].pattern_len;
  7813. if (nla_put(msg, NL80211_PKTPAT_MASK,
  7814. DIV_ROUND_UP(pat_len, 8),
  7815. rule->patterns[j].mask) ||
  7816. nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
  7817. rule->patterns[j].pattern) ||
  7818. nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
  7819. rule->patterns[j].pkt_offset))
  7820. return -ENOBUFS;
  7821. nla_nest_end(msg, nl_pat);
  7822. }
  7823. nla_nest_end(msg, nl_pats);
  7824. nla_nest_end(msg, nl_rule);
  7825. }
  7826. nla_nest_end(msg, nl_rules);
  7827. return 0;
  7828. }
  7829. static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
  7830. {
  7831. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7832. struct sk_buff *msg;
  7833. void *hdr;
  7834. if (!rdev->wiphy.coalesce)
  7835. return -EOPNOTSUPP;
  7836. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7837. if (!msg)
  7838. return -ENOMEM;
  7839. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7840. NL80211_CMD_GET_COALESCE);
  7841. if (!hdr)
  7842. goto nla_put_failure;
  7843. if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
  7844. goto nla_put_failure;
  7845. genlmsg_end(msg, hdr);
  7846. return genlmsg_reply(msg, info);
  7847. nla_put_failure:
  7848. nlmsg_free(msg);
  7849. return -ENOBUFS;
  7850. }
  7851. void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
  7852. {
  7853. struct cfg80211_coalesce *coalesce = rdev->coalesce;
  7854. int i, j;
  7855. struct cfg80211_coalesce_rules *rule;
  7856. if (!coalesce)
  7857. return;
  7858. for (i = 0; i < coalesce->n_rules; i++) {
  7859. rule = &coalesce->rules[i];
  7860. for (j = 0; j < rule->n_patterns; j++)
  7861. kfree(rule->patterns[j].mask);
  7862. kfree(rule->patterns);
  7863. }
  7864. kfree(coalesce->rules);
  7865. kfree(coalesce);
  7866. rdev->coalesce = NULL;
  7867. }
  7868. static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
  7869. struct nlattr *rule,
  7870. struct cfg80211_coalesce_rules *new_rule)
  7871. {
  7872. int err, i;
  7873. const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
  7874. struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
  7875. int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
  7876. struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
  7877. err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
  7878. nla_len(rule), nl80211_coalesce_policy);
  7879. if (err)
  7880. return err;
  7881. if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
  7882. new_rule->delay =
  7883. nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
  7884. if (new_rule->delay > coalesce->max_delay)
  7885. return -EINVAL;
  7886. if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
  7887. new_rule->condition =
  7888. nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
  7889. if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
  7890. new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
  7891. return -EINVAL;
  7892. if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
  7893. return -EINVAL;
  7894. nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
  7895. rem)
  7896. n_patterns++;
  7897. if (n_patterns > coalesce->n_patterns)
  7898. return -EINVAL;
  7899. new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
  7900. GFP_KERNEL);
  7901. if (!new_rule->patterns)
  7902. return -ENOMEM;
  7903. new_rule->n_patterns = n_patterns;
  7904. i = 0;
  7905. nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
  7906. rem) {
  7907. u8 *mask_pat;
  7908. nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
  7909. nla_len(pat), NULL);
  7910. if (!pat_tb[NL80211_PKTPAT_MASK] ||
  7911. !pat_tb[NL80211_PKTPAT_PATTERN])
  7912. return -EINVAL;
  7913. pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
  7914. mask_len = DIV_ROUND_UP(pat_len, 8);
  7915. if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
  7916. return -EINVAL;
  7917. if (pat_len > coalesce->pattern_max_len ||
  7918. pat_len < coalesce->pattern_min_len)
  7919. return -EINVAL;
  7920. if (!pat_tb[NL80211_PKTPAT_OFFSET])
  7921. pkt_offset = 0;
  7922. else
  7923. pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
  7924. if (pkt_offset > coalesce->max_pkt_offset)
  7925. return -EINVAL;
  7926. new_rule->patterns[i].pkt_offset = pkt_offset;
  7927. mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
  7928. if (!mask_pat)
  7929. return -ENOMEM;
  7930. new_rule->patterns[i].mask = mask_pat;
  7931. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
  7932. mask_len);
  7933. mask_pat += mask_len;
  7934. new_rule->patterns[i].pattern = mask_pat;
  7935. new_rule->patterns[i].pattern_len = pat_len;
  7936. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
  7937. pat_len);
  7938. i++;
  7939. }
  7940. return 0;
  7941. }
  7942. static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
  7943. {
  7944. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7945. const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
  7946. struct cfg80211_coalesce new_coalesce = {};
  7947. struct cfg80211_coalesce *n_coalesce;
  7948. int err, rem_rule, n_rules = 0, i, j;
  7949. struct nlattr *rule;
  7950. struct cfg80211_coalesce_rules *tmp_rule;
  7951. if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
  7952. return -EOPNOTSUPP;
  7953. if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
  7954. cfg80211_rdev_free_coalesce(rdev);
  7955. rdev->ops->set_coalesce(&rdev->wiphy, NULL);
  7956. return 0;
  7957. }
  7958. nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
  7959. rem_rule)
  7960. n_rules++;
  7961. if (n_rules > coalesce->n_rules)
  7962. return -EINVAL;
  7963. new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
  7964. GFP_KERNEL);
  7965. if (!new_coalesce.rules)
  7966. return -ENOMEM;
  7967. new_coalesce.n_rules = n_rules;
  7968. i = 0;
  7969. nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
  7970. rem_rule) {
  7971. err = nl80211_parse_coalesce_rule(rdev, rule,
  7972. &new_coalesce.rules[i]);
  7973. if (err)
  7974. goto error;
  7975. i++;
  7976. }
  7977. err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
  7978. if (err)
  7979. goto error;
  7980. n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
  7981. if (!n_coalesce) {
  7982. err = -ENOMEM;
  7983. goto error;
  7984. }
  7985. cfg80211_rdev_free_coalesce(rdev);
  7986. rdev->coalesce = n_coalesce;
  7987. return 0;
  7988. error:
  7989. for (i = 0; i < new_coalesce.n_rules; i++) {
  7990. tmp_rule = &new_coalesce.rules[i];
  7991. for (j = 0; j < tmp_rule->n_patterns; j++)
  7992. kfree(tmp_rule->patterns[j].mask);
  7993. kfree(tmp_rule->patterns);
  7994. }
  7995. kfree(new_coalesce.rules);
  7996. return err;
  7997. }
  7998. static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
  7999. {
  8000. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8001. struct net_device *dev = info->user_ptr[1];
  8002. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8003. struct nlattr *tb[NUM_NL80211_REKEY_DATA];
  8004. struct cfg80211_gtk_rekey_data rekey_data;
  8005. int err;
  8006. if (!info->attrs[NL80211_ATTR_REKEY_DATA])
  8007. return -EINVAL;
  8008. err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
  8009. nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
  8010. nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
  8011. nl80211_rekey_policy);
  8012. if (err)
  8013. return err;
  8014. if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
  8015. return -ERANGE;
  8016. if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
  8017. return -ERANGE;
  8018. if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
  8019. return -ERANGE;
  8020. rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
  8021. rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
  8022. rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
  8023. wdev_lock(wdev);
  8024. if (!wdev->current_bss) {
  8025. err = -ENOTCONN;
  8026. goto out;
  8027. }
  8028. if (!rdev->ops->set_rekey_data) {
  8029. err = -EOPNOTSUPP;
  8030. goto out;
  8031. }
  8032. err = rdev_set_rekey_data(rdev, dev, &rekey_data);
  8033. out:
  8034. wdev_unlock(wdev);
  8035. return err;
  8036. }
  8037. static int nl80211_register_unexpected_frame(struct sk_buff *skb,
  8038. struct genl_info *info)
  8039. {
  8040. struct net_device *dev = info->user_ptr[1];
  8041. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8042. if (wdev->iftype != NL80211_IFTYPE_AP &&
  8043. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  8044. return -EINVAL;
  8045. if (wdev->ap_unexpected_nlportid)
  8046. return -EBUSY;
  8047. wdev->ap_unexpected_nlportid = info->snd_portid;
  8048. return 0;
  8049. }
  8050. static int nl80211_probe_client(struct sk_buff *skb,
  8051. struct genl_info *info)
  8052. {
  8053. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8054. struct net_device *dev = info->user_ptr[1];
  8055. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8056. struct sk_buff *msg;
  8057. void *hdr;
  8058. const u8 *addr;
  8059. u64 cookie;
  8060. int err;
  8061. if (wdev->iftype != NL80211_IFTYPE_AP &&
  8062. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  8063. return -EOPNOTSUPP;
  8064. if (!info->attrs[NL80211_ATTR_MAC])
  8065. return -EINVAL;
  8066. if (!rdev->ops->probe_client)
  8067. return -EOPNOTSUPP;
  8068. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  8069. if (!msg)
  8070. return -ENOMEM;
  8071. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8072. NL80211_CMD_PROBE_CLIENT);
  8073. if (!hdr) {
  8074. err = -ENOBUFS;
  8075. goto free_msg;
  8076. }
  8077. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  8078. err = rdev_probe_client(rdev, dev, addr, &cookie);
  8079. if (err)
  8080. goto free_msg;
  8081. if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
  8082. goto nla_put_failure;
  8083. genlmsg_end(msg, hdr);
  8084. return genlmsg_reply(msg, info);
  8085. nla_put_failure:
  8086. err = -ENOBUFS;
  8087. free_msg:
  8088. nlmsg_free(msg);
  8089. return err;
  8090. }
  8091. static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
  8092. {
  8093. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8094. struct cfg80211_beacon_registration *reg, *nreg;
  8095. int rv;
  8096. if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
  8097. return -EOPNOTSUPP;
  8098. nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
  8099. if (!nreg)
  8100. return -ENOMEM;
  8101. /* First, check if already registered. */
  8102. spin_lock_bh(&rdev->beacon_registrations_lock);
  8103. list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  8104. if (reg->nlportid == info->snd_portid) {
  8105. rv = -EALREADY;
  8106. goto out_err;
  8107. }
  8108. }
  8109. /* Add it to the list */
  8110. nreg->nlportid = info->snd_portid;
  8111. list_add(&nreg->list, &rdev->beacon_registrations);
  8112. spin_unlock_bh(&rdev->beacon_registrations_lock);
  8113. return 0;
  8114. out_err:
  8115. spin_unlock_bh(&rdev->beacon_registrations_lock);
  8116. kfree(nreg);
  8117. return rv;
  8118. }
  8119. static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
  8120. {
  8121. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8122. struct wireless_dev *wdev = info->user_ptr[1];
  8123. int err;
  8124. if (!rdev->ops->start_p2p_device)
  8125. return -EOPNOTSUPP;
  8126. if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  8127. return -EOPNOTSUPP;
  8128. if (wdev->p2p_started)
  8129. return 0;
  8130. if (rfkill_blocked(rdev->rfkill))
  8131. return -ERFKILL;
  8132. err = rdev_start_p2p_device(rdev, wdev);
  8133. if (err)
  8134. return err;
  8135. wdev->p2p_started = true;
  8136. rdev->opencount++;
  8137. return 0;
  8138. }
  8139. static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
  8140. {
  8141. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8142. struct wireless_dev *wdev = info->user_ptr[1];
  8143. if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  8144. return -EOPNOTSUPP;
  8145. if (!rdev->ops->stop_p2p_device)
  8146. return -EOPNOTSUPP;
  8147. cfg80211_stop_p2p_device(rdev, wdev);
  8148. return 0;
  8149. }
  8150. static int nl80211_get_protocol_features(struct sk_buff *skb,
  8151. struct genl_info *info)
  8152. {
  8153. void *hdr;
  8154. struct sk_buff *msg;
  8155. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  8156. if (!msg)
  8157. return -ENOMEM;
  8158. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8159. NL80211_CMD_GET_PROTOCOL_FEATURES);
  8160. if (!hdr)
  8161. goto nla_put_failure;
  8162. if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
  8163. NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
  8164. goto nla_put_failure;
  8165. genlmsg_end(msg, hdr);
  8166. return genlmsg_reply(msg, info);
  8167. nla_put_failure:
  8168. kfree_skb(msg);
  8169. return -ENOBUFS;
  8170. }
  8171. static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
  8172. {
  8173. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8174. struct cfg80211_update_ft_ies_params ft_params;
  8175. struct net_device *dev = info->user_ptr[1];
  8176. if (!rdev->ops->update_ft_ies)
  8177. return -EOPNOTSUPP;
  8178. if (!info->attrs[NL80211_ATTR_MDID] ||
  8179. !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  8180. return -EINVAL;
  8181. memset(&ft_params, 0, sizeof(ft_params));
  8182. ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
  8183. ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  8184. ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  8185. return rdev_update_ft_ies(rdev, dev, &ft_params);
  8186. }
  8187. static int nl80211_crit_protocol_start(struct sk_buff *skb,
  8188. struct genl_info *info)
  8189. {
  8190. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8191. struct wireless_dev *wdev = info->user_ptr[1];
  8192. enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
  8193. u16 duration;
  8194. int ret;
  8195. if (!rdev->ops->crit_proto_start)
  8196. return -EOPNOTSUPP;
  8197. if (WARN_ON(!rdev->ops->crit_proto_stop))
  8198. return -EINVAL;
  8199. if (rdev->crit_proto_nlportid)
  8200. return -EBUSY;
  8201. /* determine protocol if provided */
  8202. if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
  8203. proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
  8204. if (proto >= NUM_NL80211_CRIT_PROTO)
  8205. return -EINVAL;
  8206. /* timeout must be provided */
  8207. if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
  8208. return -EINVAL;
  8209. duration =
  8210. nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
  8211. if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
  8212. return -ERANGE;
  8213. ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
  8214. if (!ret)
  8215. rdev->crit_proto_nlportid = info->snd_portid;
  8216. return ret;
  8217. }
  8218. static int nl80211_crit_protocol_stop(struct sk_buff *skb,
  8219. struct genl_info *info)
  8220. {
  8221. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8222. struct wireless_dev *wdev = info->user_ptr[1];
  8223. if (!rdev->ops->crit_proto_stop)
  8224. return -EOPNOTSUPP;
  8225. if (rdev->crit_proto_nlportid) {
  8226. rdev->crit_proto_nlportid = 0;
  8227. rdev_crit_proto_stop(rdev, wdev);
  8228. }
  8229. return 0;
  8230. }
  8231. static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
  8232. {
  8233. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8234. struct wireless_dev *wdev =
  8235. __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
  8236. int i, err;
  8237. u32 vid, subcmd;
  8238. if (!rdev->wiphy.vendor_commands)
  8239. return -EOPNOTSUPP;
  8240. if (IS_ERR(wdev)) {
  8241. err = PTR_ERR(wdev);
  8242. if (err != -EINVAL)
  8243. return err;
  8244. wdev = NULL;
  8245. } else if (wdev->wiphy != &rdev->wiphy) {
  8246. return -EINVAL;
  8247. }
  8248. if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
  8249. !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
  8250. return -EINVAL;
  8251. vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
  8252. subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
  8253. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  8254. const struct wiphy_vendor_command *vcmd;
  8255. void *data = NULL;
  8256. int len = 0;
  8257. vcmd = &rdev->wiphy.vendor_commands[i];
  8258. if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
  8259. continue;
  8260. if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
  8261. WIPHY_VENDOR_CMD_NEED_NETDEV)) {
  8262. if (!wdev)
  8263. return -EINVAL;
  8264. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
  8265. !wdev->netdev)
  8266. return -EINVAL;
  8267. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
  8268. if (wdev->netdev &&
  8269. !netif_running(wdev->netdev))
  8270. return -ENETDOWN;
  8271. if (!wdev->netdev && !wdev->p2p_started)
  8272. return -ENETDOWN;
  8273. }
  8274. } else {
  8275. wdev = NULL;
  8276. }
  8277. if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
  8278. data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  8279. len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  8280. }
  8281. rdev->cur_cmd_info = info;
  8282. err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
  8283. data, len);
  8284. rdev->cur_cmd_info = NULL;
  8285. return err;
  8286. }
  8287. return -EOPNOTSUPP;
  8288. }
  8289. struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
  8290. enum nl80211_commands cmd,
  8291. enum nl80211_attrs attr,
  8292. int approxlen)
  8293. {
  8294. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  8295. if (WARN_ON(!rdev->cur_cmd_info))
  8296. return NULL;
  8297. return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
  8298. rdev->cur_cmd_info->snd_portid,
  8299. rdev->cur_cmd_info->snd_seq,
  8300. cmd, attr, NULL, GFP_KERNEL);
  8301. }
  8302. EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
  8303. int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
  8304. {
  8305. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  8306. void *hdr = ((void **)skb->cb)[1];
  8307. struct nlattr *data = ((void **)skb->cb)[2];
  8308. /* clear CB data for netlink core to own from now on */
  8309. memset(skb->cb, 0, sizeof(skb->cb));
  8310. if (WARN_ON(!rdev->cur_cmd_info)) {
  8311. kfree_skb(skb);
  8312. return -EINVAL;
  8313. }
  8314. nla_nest_end(skb, data);
  8315. genlmsg_end(skb, hdr);
  8316. return genlmsg_reply(skb, rdev->cur_cmd_info);
  8317. }
  8318. EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
  8319. static int nl80211_set_qos_map(struct sk_buff *skb,
  8320. struct genl_info *info)
  8321. {
  8322. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8323. struct cfg80211_qos_map *qos_map = NULL;
  8324. struct net_device *dev = info->user_ptr[1];
  8325. u8 *pos, len, num_des, des_len, des;
  8326. int ret;
  8327. if (!rdev->ops->set_qos_map)
  8328. return -EOPNOTSUPP;
  8329. if (info->attrs[NL80211_ATTR_QOS_MAP]) {
  8330. pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
  8331. len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
  8332. if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
  8333. len > IEEE80211_QOS_MAP_LEN_MAX)
  8334. return -EINVAL;
  8335. qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
  8336. if (!qos_map)
  8337. return -ENOMEM;
  8338. num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
  8339. if (num_des) {
  8340. des_len = num_des *
  8341. sizeof(struct cfg80211_dscp_exception);
  8342. memcpy(qos_map->dscp_exception, pos, des_len);
  8343. qos_map->num_des = num_des;
  8344. for (des = 0; des < num_des; des++) {
  8345. if (qos_map->dscp_exception[des].up > 7) {
  8346. kfree(qos_map);
  8347. return -EINVAL;
  8348. }
  8349. }
  8350. pos += des_len;
  8351. }
  8352. memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
  8353. }
  8354. wdev_lock(dev->ieee80211_ptr);
  8355. ret = nl80211_key_allowed(dev->ieee80211_ptr);
  8356. if (!ret)
  8357. ret = rdev_set_qos_map(rdev, dev, qos_map);
  8358. wdev_unlock(dev->ieee80211_ptr);
  8359. kfree(qos_map);
  8360. return ret;
  8361. }
  8362. static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
  8363. {
  8364. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8365. struct net_device *dev = info->user_ptr[1];
  8366. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8367. const u8 *peer;
  8368. u8 tsid, up;
  8369. u16 admitted_time = 0;
  8370. int err;
  8371. if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
  8372. return -EOPNOTSUPP;
  8373. if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
  8374. !info->attrs[NL80211_ATTR_USER_PRIO])
  8375. return -EINVAL;
  8376. tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
  8377. if (tsid >= IEEE80211_NUM_TIDS)
  8378. return -EINVAL;
  8379. up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
  8380. if (up >= IEEE80211_NUM_UPS)
  8381. return -EINVAL;
  8382. /* WMM uses TIDs 0-7 even for TSPEC */
  8383. if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
  8384. /* TODO: handle 802.11 TSPEC/admission control
  8385. * need more attributes for that (e.g. BA session requirement);
  8386. * change the WMM adminssion test above to allow both then
  8387. */
  8388. return -EINVAL;
  8389. }
  8390. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  8391. if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
  8392. admitted_time =
  8393. nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
  8394. if (!admitted_time)
  8395. return -EINVAL;
  8396. }
  8397. wdev_lock(wdev);
  8398. switch (wdev->iftype) {
  8399. case NL80211_IFTYPE_STATION:
  8400. case NL80211_IFTYPE_P2P_CLIENT:
  8401. if (wdev->current_bss)
  8402. break;
  8403. err = -ENOTCONN;
  8404. goto out;
  8405. default:
  8406. err = -EOPNOTSUPP;
  8407. goto out;
  8408. }
  8409. err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
  8410. out:
  8411. wdev_unlock(wdev);
  8412. return err;
  8413. }
  8414. static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
  8415. {
  8416. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8417. struct net_device *dev = info->user_ptr[1];
  8418. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8419. const u8 *peer;
  8420. u8 tsid;
  8421. int err;
  8422. if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
  8423. return -EINVAL;
  8424. tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
  8425. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  8426. wdev_lock(wdev);
  8427. err = rdev_del_tx_ts(rdev, dev, tsid, peer);
  8428. wdev_unlock(wdev);
  8429. return err;
  8430. }
  8431. static int nl80211_tdls_channel_switch(struct sk_buff *skb,
  8432. struct genl_info *info)
  8433. {
  8434. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8435. struct net_device *dev = info->user_ptr[1];
  8436. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8437. struct cfg80211_chan_def chandef = {};
  8438. const u8 *addr;
  8439. u8 oper_class;
  8440. int err;
  8441. if (!rdev->ops->tdls_channel_switch ||
  8442. !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
  8443. return -EOPNOTSUPP;
  8444. switch (dev->ieee80211_ptr->iftype) {
  8445. case NL80211_IFTYPE_STATION:
  8446. case NL80211_IFTYPE_P2P_CLIENT:
  8447. break;
  8448. default:
  8449. return -EOPNOTSUPP;
  8450. }
  8451. if (!info->attrs[NL80211_ATTR_MAC] ||
  8452. !info->attrs[NL80211_ATTR_OPER_CLASS])
  8453. return -EINVAL;
  8454. err = nl80211_parse_chandef(rdev, info, &chandef);
  8455. if (err)
  8456. return err;
  8457. /*
  8458. * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
  8459. * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
  8460. * specification is not defined for them.
  8461. */
  8462. if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
  8463. chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
  8464. chandef.width != NL80211_CHAN_WIDTH_20)
  8465. return -EINVAL;
  8466. /* we will be active on the TDLS link */
  8467. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
  8468. return -EINVAL;
  8469. /* don't allow switching to DFS channels */
  8470. if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
  8471. return -EINVAL;
  8472. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  8473. oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
  8474. wdev_lock(wdev);
  8475. err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
  8476. wdev_unlock(wdev);
  8477. return err;
  8478. }
  8479. static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
  8480. struct genl_info *info)
  8481. {
  8482. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8483. struct net_device *dev = info->user_ptr[1];
  8484. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8485. const u8 *addr;
  8486. if (!rdev->ops->tdls_channel_switch ||
  8487. !rdev->ops->tdls_cancel_channel_switch ||
  8488. !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
  8489. return -EOPNOTSUPP;
  8490. switch (dev->ieee80211_ptr->iftype) {
  8491. case NL80211_IFTYPE_STATION:
  8492. case NL80211_IFTYPE_P2P_CLIENT:
  8493. break;
  8494. default:
  8495. return -EOPNOTSUPP;
  8496. }
  8497. if (!info->attrs[NL80211_ATTR_MAC])
  8498. return -EINVAL;
  8499. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  8500. wdev_lock(wdev);
  8501. rdev_tdls_cancel_channel_switch(rdev, dev, addr);
  8502. wdev_unlock(wdev);
  8503. return 0;
  8504. }
  8505. #define NL80211_FLAG_NEED_WIPHY 0x01
  8506. #define NL80211_FLAG_NEED_NETDEV 0x02
  8507. #define NL80211_FLAG_NEED_RTNL 0x04
  8508. #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
  8509. #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
  8510. NL80211_FLAG_CHECK_NETDEV_UP)
  8511. #define NL80211_FLAG_NEED_WDEV 0x10
  8512. /* If a netdev is associated, it must be UP, P2P must be started */
  8513. #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
  8514. NL80211_FLAG_CHECK_NETDEV_UP)
  8515. #define NL80211_FLAG_CLEAR_SKB 0x20
  8516. static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
  8517. struct genl_info *info)
  8518. {
  8519. struct cfg80211_registered_device *rdev;
  8520. struct wireless_dev *wdev;
  8521. struct net_device *dev;
  8522. bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
  8523. if (rtnl)
  8524. rtnl_lock();
  8525. if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
  8526. rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
  8527. if (IS_ERR(rdev)) {
  8528. if (rtnl)
  8529. rtnl_unlock();
  8530. return PTR_ERR(rdev);
  8531. }
  8532. info->user_ptr[0] = rdev;
  8533. } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
  8534. ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
  8535. ASSERT_RTNL();
  8536. wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
  8537. info->attrs);
  8538. if (IS_ERR(wdev)) {
  8539. if (rtnl)
  8540. rtnl_unlock();
  8541. return PTR_ERR(wdev);
  8542. }
  8543. dev = wdev->netdev;
  8544. rdev = wiphy_to_rdev(wdev->wiphy);
  8545. if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
  8546. if (!dev) {
  8547. if (rtnl)
  8548. rtnl_unlock();
  8549. return -EINVAL;
  8550. }
  8551. info->user_ptr[1] = dev;
  8552. } else {
  8553. info->user_ptr[1] = wdev;
  8554. }
  8555. if (dev) {
  8556. if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
  8557. !netif_running(dev)) {
  8558. if (rtnl)
  8559. rtnl_unlock();
  8560. return -ENETDOWN;
  8561. }
  8562. dev_hold(dev);
  8563. } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
  8564. if (!wdev->p2p_started) {
  8565. if (rtnl)
  8566. rtnl_unlock();
  8567. return -ENETDOWN;
  8568. }
  8569. }
  8570. info->user_ptr[0] = rdev;
  8571. }
  8572. return 0;
  8573. }
  8574. static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
  8575. struct genl_info *info)
  8576. {
  8577. if (info->user_ptr[1]) {
  8578. if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
  8579. struct wireless_dev *wdev = info->user_ptr[1];
  8580. if (wdev->netdev)
  8581. dev_put(wdev->netdev);
  8582. } else {
  8583. dev_put(info->user_ptr[1]);
  8584. }
  8585. }
  8586. if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
  8587. rtnl_unlock();
  8588. /* If needed, clear the netlink message payload from the SKB
  8589. * as it might contain key data that shouldn't stick around on
  8590. * the heap after the SKB is freed. The netlink message header
  8591. * is still needed for further processing, so leave it intact.
  8592. */
  8593. if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
  8594. struct nlmsghdr *nlh = nlmsg_hdr(skb);
  8595. memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
  8596. }
  8597. }
  8598. static const struct genl_ops nl80211_ops[] = {
  8599. {
  8600. .cmd = NL80211_CMD_GET_WIPHY,
  8601. .doit = nl80211_get_wiphy,
  8602. .dumpit = nl80211_dump_wiphy,
  8603. .done = nl80211_dump_wiphy_done,
  8604. .policy = nl80211_policy,
  8605. /* can be retrieved by unprivileged users */
  8606. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  8607. NL80211_FLAG_NEED_RTNL,
  8608. },
  8609. {
  8610. .cmd = NL80211_CMD_SET_WIPHY,
  8611. .doit = nl80211_set_wiphy,
  8612. .policy = nl80211_policy,
  8613. .flags = GENL_ADMIN_PERM,
  8614. .internal_flags = NL80211_FLAG_NEED_RTNL,
  8615. },
  8616. {
  8617. .cmd = NL80211_CMD_GET_INTERFACE,
  8618. .doit = nl80211_get_interface,
  8619. .dumpit = nl80211_dump_interface,
  8620. .policy = nl80211_policy,
  8621. /* can be retrieved by unprivileged users */
  8622. .internal_flags = NL80211_FLAG_NEED_WDEV |
  8623. NL80211_FLAG_NEED_RTNL,
  8624. },
  8625. {
  8626. .cmd = NL80211_CMD_SET_INTERFACE,
  8627. .doit = nl80211_set_interface,
  8628. .policy = nl80211_policy,
  8629. .flags = GENL_ADMIN_PERM,
  8630. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  8631. NL80211_FLAG_NEED_RTNL,
  8632. },
  8633. {
  8634. .cmd = NL80211_CMD_NEW_INTERFACE,
  8635. .doit = nl80211_new_interface,
  8636. .policy = nl80211_policy,
  8637. .flags = GENL_ADMIN_PERM,
  8638. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  8639. NL80211_FLAG_NEED_RTNL,
  8640. },
  8641. {
  8642. .cmd = NL80211_CMD_DEL_INTERFACE,
  8643. .doit = nl80211_del_interface,
  8644. .policy = nl80211_policy,
  8645. .flags = GENL_ADMIN_PERM,
  8646. .internal_flags = NL80211_FLAG_NEED_WDEV |
  8647. NL80211_FLAG_NEED_RTNL,
  8648. },
  8649. {
  8650. .cmd = NL80211_CMD_GET_KEY,
  8651. .doit = nl80211_get_key,
  8652. .policy = nl80211_policy,
  8653. .flags = GENL_ADMIN_PERM,
  8654. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8655. NL80211_FLAG_NEED_RTNL,
  8656. },
  8657. {
  8658. .cmd = NL80211_CMD_SET_KEY,
  8659. .doit = nl80211_set_key,
  8660. .policy = nl80211_policy,
  8661. .flags = GENL_ADMIN_PERM,
  8662. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8663. NL80211_FLAG_NEED_RTNL |
  8664. NL80211_FLAG_CLEAR_SKB,
  8665. },
  8666. {
  8667. .cmd = NL80211_CMD_NEW_KEY,
  8668. .doit = nl80211_new_key,
  8669. .policy = nl80211_policy,
  8670. .flags = GENL_ADMIN_PERM,
  8671. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8672. NL80211_FLAG_NEED_RTNL |
  8673. NL80211_FLAG_CLEAR_SKB,
  8674. },
  8675. {
  8676. .cmd = NL80211_CMD_DEL_KEY,
  8677. .doit = nl80211_del_key,
  8678. .policy = nl80211_policy,
  8679. .flags = GENL_ADMIN_PERM,
  8680. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8681. NL80211_FLAG_NEED_RTNL,
  8682. },
  8683. {
  8684. .cmd = NL80211_CMD_SET_BEACON,
  8685. .policy = nl80211_policy,
  8686. .flags = GENL_ADMIN_PERM,
  8687. .doit = nl80211_set_beacon,
  8688. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8689. NL80211_FLAG_NEED_RTNL,
  8690. },
  8691. {
  8692. .cmd = NL80211_CMD_START_AP,
  8693. .policy = nl80211_policy,
  8694. .flags = GENL_ADMIN_PERM,
  8695. .doit = nl80211_start_ap,
  8696. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8697. NL80211_FLAG_NEED_RTNL,
  8698. },
  8699. {
  8700. .cmd = NL80211_CMD_STOP_AP,
  8701. .policy = nl80211_policy,
  8702. .flags = GENL_ADMIN_PERM,
  8703. .doit = nl80211_stop_ap,
  8704. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8705. NL80211_FLAG_NEED_RTNL,
  8706. },
  8707. {
  8708. .cmd = NL80211_CMD_GET_STATION,
  8709. .doit = nl80211_get_station,
  8710. .dumpit = nl80211_dump_station,
  8711. .policy = nl80211_policy,
  8712. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  8713. NL80211_FLAG_NEED_RTNL,
  8714. },
  8715. {
  8716. .cmd = NL80211_CMD_SET_STATION,
  8717. .doit = nl80211_set_station,
  8718. .policy = nl80211_policy,
  8719. .flags = GENL_ADMIN_PERM,
  8720. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8721. NL80211_FLAG_NEED_RTNL,
  8722. },
  8723. {
  8724. .cmd = NL80211_CMD_NEW_STATION,
  8725. .doit = nl80211_new_station,
  8726. .policy = nl80211_policy,
  8727. .flags = GENL_ADMIN_PERM,
  8728. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8729. NL80211_FLAG_NEED_RTNL,
  8730. },
  8731. {
  8732. .cmd = NL80211_CMD_DEL_STATION,
  8733. .doit = nl80211_del_station,
  8734. .policy = nl80211_policy,
  8735. .flags = GENL_ADMIN_PERM,
  8736. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8737. NL80211_FLAG_NEED_RTNL,
  8738. },
  8739. {
  8740. .cmd = NL80211_CMD_GET_MPATH,
  8741. .doit = nl80211_get_mpath,
  8742. .dumpit = nl80211_dump_mpath,
  8743. .policy = nl80211_policy,
  8744. .flags = GENL_ADMIN_PERM,
  8745. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8746. NL80211_FLAG_NEED_RTNL,
  8747. },
  8748. {
  8749. .cmd = NL80211_CMD_GET_MPP,
  8750. .doit = nl80211_get_mpp,
  8751. .dumpit = nl80211_dump_mpp,
  8752. .policy = nl80211_policy,
  8753. .flags = GENL_ADMIN_PERM,
  8754. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8755. NL80211_FLAG_NEED_RTNL,
  8756. },
  8757. {
  8758. .cmd = NL80211_CMD_SET_MPATH,
  8759. .doit = nl80211_set_mpath,
  8760. .policy = nl80211_policy,
  8761. .flags = GENL_ADMIN_PERM,
  8762. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8763. NL80211_FLAG_NEED_RTNL,
  8764. },
  8765. {
  8766. .cmd = NL80211_CMD_NEW_MPATH,
  8767. .doit = nl80211_new_mpath,
  8768. .policy = nl80211_policy,
  8769. .flags = GENL_ADMIN_PERM,
  8770. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8771. NL80211_FLAG_NEED_RTNL,
  8772. },
  8773. {
  8774. .cmd = NL80211_CMD_DEL_MPATH,
  8775. .doit = nl80211_del_mpath,
  8776. .policy = nl80211_policy,
  8777. .flags = GENL_ADMIN_PERM,
  8778. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8779. NL80211_FLAG_NEED_RTNL,
  8780. },
  8781. {
  8782. .cmd = NL80211_CMD_SET_BSS,
  8783. .doit = nl80211_set_bss,
  8784. .policy = nl80211_policy,
  8785. .flags = GENL_ADMIN_PERM,
  8786. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8787. NL80211_FLAG_NEED_RTNL,
  8788. },
  8789. {
  8790. .cmd = NL80211_CMD_GET_REG,
  8791. .doit = nl80211_get_reg_do,
  8792. .dumpit = nl80211_get_reg_dump,
  8793. .policy = nl80211_policy,
  8794. .internal_flags = NL80211_FLAG_NEED_RTNL,
  8795. /* can be retrieved by unprivileged users */
  8796. },
  8797. {
  8798. .cmd = NL80211_CMD_SET_REG,
  8799. .doit = nl80211_set_reg,
  8800. .policy = nl80211_policy,
  8801. .flags = GENL_ADMIN_PERM,
  8802. .internal_flags = NL80211_FLAG_NEED_RTNL,
  8803. },
  8804. {
  8805. .cmd = NL80211_CMD_REQ_SET_REG,
  8806. .doit = nl80211_req_set_reg,
  8807. .policy = nl80211_policy,
  8808. .flags = GENL_ADMIN_PERM,
  8809. },
  8810. {
  8811. .cmd = NL80211_CMD_GET_MESH_CONFIG,
  8812. .doit = nl80211_get_mesh_config,
  8813. .policy = nl80211_policy,
  8814. /* can be retrieved by unprivileged users */
  8815. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8816. NL80211_FLAG_NEED_RTNL,
  8817. },
  8818. {
  8819. .cmd = NL80211_CMD_SET_MESH_CONFIG,
  8820. .doit = nl80211_update_mesh_config,
  8821. .policy = nl80211_policy,
  8822. .flags = GENL_ADMIN_PERM,
  8823. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8824. NL80211_FLAG_NEED_RTNL,
  8825. },
  8826. {
  8827. .cmd = NL80211_CMD_TRIGGER_SCAN,
  8828. .doit = nl80211_trigger_scan,
  8829. .policy = nl80211_policy,
  8830. .flags = GENL_ADMIN_PERM,
  8831. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  8832. NL80211_FLAG_NEED_RTNL,
  8833. },
  8834. {
  8835. .cmd = NL80211_CMD_GET_SCAN,
  8836. .policy = nl80211_policy,
  8837. .dumpit = nl80211_dump_scan,
  8838. },
  8839. {
  8840. .cmd = NL80211_CMD_START_SCHED_SCAN,
  8841. .doit = nl80211_start_sched_scan,
  8842. .policy = nl80211_policy,
  8843. .flags = GENL_ADMIN_PERM,
  8844. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8845. NL80211_FLAG_NEED_RTNL,
  8846. },
  8847. {
  8848. .cmd = NL80211_CMD_STOP_SCHED_SCAN,
  8849. .doit = nl80211_stop_sched_scan,
  8850. .policy = nl80211_policy,
  8851. .flags = GENL_ADMIN_PERM,
  8852. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8853. NL80211_FLAG_NEED_RTNL,
  8854. },
  8855. {
  8856. .cmd = NL80211_CMD_AUTHENTICATE,
  8857. .doit = nl80211_authenticate,
  8858. .policy = nl80211_policy,
  8859. .flags = GENL_ADMIN_PERM,
  8860. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8861. NL80211_FLAG_NEED_RTNL |
  8862. NL80211_FLAG_CLEAR_SKB,
  8863. },
  8864. {
  8865. .cmd = NL80211_CMD_ASSOCIATE,
  8866. .doit = nl80211_associate,
  8867. .policy = nl80211_policy,
  8868. .flags = GENL_ADMIN_PERM,
  8869. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8870. NL80211_FLAG_NEED_RTNL,
  8871. },
  8872. {
  8873. .cmd = NL80211_CMD_DEAUTHENTICATE,
  8874. .doit = nl80211_deauthenticate,
  8875. .policy = nl80211_policy,
  8876. .flags = GENL_ADMIN_PERM,
  8877. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8878. NL80211_FLAG_NEED_RTNL,
  8879. },
  8880. {
  8881. .cmd = NL80211_CMD_DISASSOCIATE,
  8882. .doit = nl80211_disassociate,
  8883. .policy = nl80211_policy,
  8884. .flags = GENL_ADMIN_PERM,
  8885. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8886. NL80211_FLAG_NEED_RTNL,
  8887. },
  8888. {
  8889. .cmd = NL80211_CMD_JOIN_IBSS,
  8890. .doit = nl80211_join_ibss,
  8891. .policy = nl80211_policy,
  8892. .flags = GENL_ADMIN_PERM,
  8893. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8894. NL80211_FLAG_NEED_RTNL,
  8895. },
  8896. {
  8897. .cmd = NL80211_CMD_LEAVE_IBSS,
  8898. .doit = nl80211_leave_ibss,
  8899. .policy = nl80211_policy,
  8900. .flags = GENL_ADMIN_PERM,
  8901. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8902. NL80211_FLAG_NEED_RTNL,
  8903. },
  8904. #ifdef CONFIG_NL80211_TESTMODE
  8905. {
  8906. .cmd = NL80211_CMD_TESTMODE,
  8907. .doit = nl80211_testmode_do,
  8908. .dumpit = nl80211_testmode_dump,
  8909. .policy = nl80211_policy,
  8910. .flags = GENL_ADMIN_PERM,
  8911. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  8912. NL80211_FLAG_NEED_RTNL,
  8913. },
  8914. #endif
  8915. {
  8916. .cmd = NL80211_CMD_CONNECT,
  8917. .doit = nl80211_connect,
  8918. .policy = nl80211_policy,
  8919. .flags = GENL_ADMIN_PERM,
  8920. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8921. NL80211_FLAG_NEED_RTNL,
  8922. },
  8923. {
  8924. .cmd = NL80211_CMD_DISCONNECT,
  8925. .doit = nl80211_disconnect,
  8926. .policy = nl80211_policy,
  8927. .flags = GENL_ADMIN_PERM,
  8928. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8929. NL80211_FLAG_NEED_RTNL,
  8930. },
  8931. {
  8932. .cmd = NL80211_CMD_SET_WIPHY_NETNS,
  8933. .doit = nl80211_wiphy_netns,
  8934. .policy = nl80211_policy,
  8935. .flags = GENL_ADMIN_PERM,
  8936. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  8937. NL80211_FLAG_NEED_RTNL,
  8938. },
  8939. {
  8940. .cmd = NL80211_CMD_GET_SURVEY,
  8941. .policy = nl80211_policy,
  8942. .dumpit = nl80211_dump_survey,
  8943. },
  8944. {
  8945. .cmd = NL80211_CMD_SET_PMKSA,
  8946. .doit = nl80211_setdel_pmksa,
  8947. .policy = nl80211_policy,
  8948. .flags = GENL_ADMIN_PERM,
  8949. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8950. NL80211_FLAG_NEED_RTNL,
  8951. },
  8952. {
  8953. .cmd = NL80211_CMD_DEL_PMKSA,
  8954. .doit = nl80211_setdel_pmksa,
  8955. .policy = nl80211_policy,
  8956. .flags = GENL_ADMIN_PERM,
  8957. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8958. NL80211_FLAG_NEED_RTNL,
  8959. },
  8960. {
  8961. .cmd = NL80211_CMD_FLUSH_PMKSA,
  8962. .doit = nl80211_flush_pmksa,
  8963. .policy = nl80211_policy,
  8964. .flags = GENL_ADMIN_PERM,
  8965. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  8966. NL80211_FLAG_NEED_RTNL,
  8967. },
  8968. {
  8969. .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
  8970. .doit = nl80211_remain_on_channel,
  8971. .policy = nl80211_policy,
  8972. .flags = GENL_ADMIN_PERM,
  8973. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  8974. NL80211_FLAG_NEED_RTNL,
  8975. },
  8976. {
  8977. .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  8978. .doit = nl80211_cancel_remain_on_channel,
  8979. .policy = nl80211_policy,
  8980. .flags = GENL_ADMIN_PERM,
  8981. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  8982. NL80211_FLAG_NEED_RTNL,
  8983. },
  8984. {
  8985. .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
  8986. .doit = nl80211_set_tx_bitrate_mask,
  8987. .policy = nl80211_policy,
  8988. .flags = GENL_ADMIN_PERM,
  8989. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  8990. NL80211_FLAG_NEED_RTNL,
  8991. },
  8992. {
  8993. .cmd = NL80211_CMD_REGISTER_FRAME,
  8994. .doit = nl80211_register_mgmt,
  8995. .policy = nl80211_policy,
  8996. .flags = GENL_ADMIN_PERM,
  8997. .internal_flags = NL80211_FLAG_NEED_WDEV |
  8998. NL80211_FLAG_NEED_RTNL,
  8999. },
  9000. {
  9001. .cmd = NL80211_CMD_FRAME,
  9002. .doit = nl80211_tx_mgmt,
  9003. .policy = nl80211_policy,
  9004. .flags = GENL_ADMIN_PERM,
  9005. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  9006. NL80211_FLAG_NEED_RTNL,
  9007. },
  9008. {
  9009. .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
  9010. .doit = nl80211_tx_mgmt_cancel_wait,
  9011. .policy = nl80211_policy,
  9012. .flags = GENL_ADMIN_PERM,
  9013. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  9014. NL80211_FLAG_NEED_RTNL,
  9015. },
  9016. {
  9017. .cmd = NL80211_CMD_SET_POWER_SAVE,
  9018. .doit = nl80211_set_power_save,
  9019. .policy = nl80211_policy,
  9020. .flags = GENL_ADMIN_PERM,
  9021. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9022. NL80211_FLAG_NEED_RTNL,
  9023. },
  9024. {
  9025. .cmd = NL80211_CMD_GET_POWER_SAVE,
  9026. .doit = nl80211_get_power_save,
  9027. .policy = nl80211_policy,
  9028. /* can be retrieved by unprivileged users */
  9029. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9030. NL80211_FLAG_NEED_RTNL,
  9031. },
  9032. {
  9033. .cmd = NL80211_CMD_SET_CQM,
  9034. .doit = nl80211_set_cqm,
  9035. .policy = nl80211_policy,
  9036. .flags = GENL_ADMIN_PERM,
  9037. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9038. NL80211_FLAG_NEED_RTNL,
  9039. },
  9040. {
  9041. .cmd = NL80211_CMD_SET_CHANNEL,
  9042. .doit = nl80211_set_channel,
  9043. .policy = nl80211_policy,
  9044. .flags = GENL_ADMIN_PERM,
  9045. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9046. NL80211_FLAG_NEED_RTNL,
  9047. },
  9048. {
  9049. .cmd = NL80211_CMD_SET_WDS_PEER,
  9050. .doit = nl80211_set_wds_peer,
  9051. .policy = nl80211_policy,
  9052. .flags = GENL_ADMIN_PERM,
  9053. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9054. NL80211_FLAG_NEED_RTNL,
  9055. },
  9056. {
  9057. .cmd = NL80211_CMD_JOIN_MESH,
  9058. .doit = nl80211_join_mesh,
  9059. .policy = nl80211_policy,
  9060. .flags = GENL_ADMIN_PERM,
  9061. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9062. NL80211_FLAG_NEED_RTNL,
  9063. },
  9064. {
  9065. .cmd = NL80211_CMD_LEAVE_MESH,
  9066. .doit = nl80211_leave_mesh,
  9067. .policy = nl80211_policy,
  9068. .flags = GENL_ADMIN_PERM,
  9069. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9070. NL80211_FLAG_NEED_RTNL,
  9071. },
  9072. {
  9073. .cmd = NL80211_CMD_JOIN_OCB,
  9074. .doit = nl80211_join_ocb,
  9075. .policy = nl80211_policy,
  9076. .flags = GENL_ADMIN_PERM,
  9077. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9078. NL80211_FLAG_NEED_RTNL,
  9079. },
  9080. {
  9081. .cmd = NL80211_CMD_LEAVE_OCB,
  9082. .doit = nl80211_leave_ocb,
  9083. .policy = nl80211_policy,
  9084. .flags = GENL_ADMIN_PERM,
  9085. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9086. NL80211_FLAG_NEED_RTNL,
  9087. },
  9088. #ifdef CONFIG_PM
  9089. {
  9090. .cmd = NL80211_CMD_GET_WOWLAN,
  9091. .doit = nl80211_get_wowlan,
  9092. .policy = nl80211_policy,
  9093. /* can be retrieved by unprivileged users */
  9094. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9095. NL80211_FLAG_NEED_RTNL,
  9096. },
  9097. {
  9098. .cmd = NL80211_CMD_SET_WOWLAN,
  9099. .doit = nl80211_set_wowlan,
  9100. .policy = nl80211_policy,
  9101. .flags = GENL_ADMIN_PERM,
  9102. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9103. NL80211_FLAG_NEED_RTNL,
  9104. },
  9105. #endif
  9106. {
  9107. .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
  9108. .doit = nl80211_set_rekey_data,
  9109. .policy = nl80211_policy,
  9110. .flags = GENL_ADMIN_PERM,
  9111. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9112. NL80211_FLAG_NEED_RTNL |
  9113. NL80211_FLAG_CLEAR_SKB,
  9114. },
  9115. {
  9116. .cmd = NL80211_CMD_TDLS_MGMT,
  9117. .doit = nl80211_tdls_mgmt,
  9118. .policy = nl80211_policy,
  9119. .flags = GENL_ADMIN_PERM,
  9120. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9121. NL80211_FLAG_NEED_RTNL,
  9122. },
  9123. {
  9124. .cmd = NL80211_CMD_TDLS_OPER,
  9125. .doit = nl80211_tdls_oper,
  9126. .policy = nl80211_policy,
  9127. .flags = GENL_ADMIN_PERM,
  9128. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9129. NL80211_FLAG_NEED_RTNL,
  9130. },
  9131. {
  9132. .cmd = NL80211_CMD_UNEXPECTED_FRAME,
  9133. .doit = nl80211_register_unexpected_frame,
  9134. .policy = nl80211_policy,
  9135. .flags = GENL_ADMIN_PERM,
  9136. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9137. NL80211_FLAG_NEED_RTNL,
  9138. },
  9139. {
  9140. .cmd = NL80211_CMD_PROBE_CLIENT,
  9141. .doit = nl80211_probe_client,
  9142. .policy = nl80211_policy,
  9143. .flags = GENL_ADMIN_PERM,
  9144. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9145. NL80211_FLAG_NEED_RTNL,
  9146. },
  9147. {
  9148. .cmd = NL80211_CMD_REGISTER_BEACONS,
  9149. .doit = nl80211_register_beacons,
  9150. .policy = nl80211_policy,
  9151. .flags = GENL_ADMIN_PERM,
  9152. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9153. NL80211_FLAG_NEED_RTNL,
  9154. },
  9155. {
  9156. .cmd = NL80211_CMD_SET_NOACK_MAP,
  9157. .doit = nl80211_set_noack_map,
  9158. .policy = nl80211_policy,
  9159. .flags = GENL_ADMIN_PERM,
  9160. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9161. NL80211_FLAG_NEED_RTNL,
  9162. },
  9163. {
  9164. .cmd = NL80211_CMD_START_P2P_DEVICE,
  9165. .doit = nl80211_start_p2p_device,
  9166. .policy = nl80211_policy,
  9167. .flags = GENL_ADMIN_PERM,
  9168. .internal_flags = NL80211_FLAG_NEED_WDEV |
  9169. NL80211_FLAG_NEED_RTNL,
  9170. },
  9171. {
  9172. .cmd = NL80211_CMD_STOP_P2P_DEVICE,
  9173. .doit = nl80211_stop_p2p_device,
  9174. .policy = nl80211_policy,
  9175. .flags = GENL_ADMIN_PERM,
  9176. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  9177. NL80211_FLAG_NEED_RTNL,
  9178. },
  9179. {
  9180. .cmd = NL80211_CMD_SET_MCAST_RATE,
  9181. .doit = nl80211_set_mcast_rate,
  9182. .policy = nl80211_policy,
  9183. .flags = GENL_ADMIN_PERM,
  9184. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9185. NL80211_FLAG_NEED_RTNL,
  9186. },
  9187. {
  9188. .cmd = NL80211_CMD_SET_MAC_ACL,
  9189. .doit = nl80211_set_mac_acl,
  9190. .policy = nl80211_policy,
  9191. .flags = GENL_ADMIN_PERM,
  9192. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9193. NL80211_FLAG_NEED_RTNL,
  9194. },
  9195. {
  9196. .cmd = NL80211_CMD_RADAR_DETECT,
  9197. .doit = nl80211_start_radar_detection,
  9198. .policy = nl80211_policy,
  9199. .flags = GENL_ADMIN_PERM,
  9200. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9201. NL80211_FLAG_NEED_RTNL,
  9202. },
  9203. {
  9204. .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
  9205. .doit = nl80211_get_protocol_features,
  9206. .policy = nl80211_policy,
  9207. },
  9208. {
  9209. .cmd = NL80211_CMD_UPDATE_FT_IES,
  9210. .doit = nl80211_update_ft_ies,
  9211. .policy = nl80211_policy,
  9212. .flags = GENL_ADMIN_PERM,
  9213. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9214. NL80211_FLAG_NEED_RTNL,
  9215. },
  9216. {
  9217. .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
  9218. .doit = nl80211_crit_protocol_start,
  9219. .policy = nl80211_policy,
  9220. .flags = GENL_ADMIN_PERM,
  9221. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  9222. NL80211_FLAG_NEED_RTNL,
  9223. },
  9224. {
  9225. .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
  9226. .doit = nl80211_crit_protocol_stop,
  9227. .policy = nl80211_policy,
  9228. .flags = GENL_ADMIN_PERM,
  9229. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  9230. NL80211_FLAG_NEED_RTNL,
  9231. },
  9232. {
  9233. .cmd = NL80211_CMD_GET_COALESCE,
  9234. .doit = nl80211_get_coalesce,
  9235. .policy = nl80211_policy,
  9236. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9237. NL80211_FLAG_NEED_RTNL,
  9238. },
  9239. {
  9240. .cmd = NL80211_CMD_SET_COALESCE,
  9241. .doit = nl80211_set_coalesce,
  9242. .policy = nl80211_policy,
  9243. .flags = GENL_ADMIN_PERM,
  9244. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9245. NL80211_FLAG_NEED_RTNL,
  9246. },
  9247. {
  9248. .cmd = NL80211_CMD_CHANNEL_SWITCH,
  9249. .doit = nl80211_channel_switch,
  9250. .policy = nl80211_policy,
  9251. .flags = GENL_ADMIN_PERM,
  9252. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9253. NL80211_FLAG_NEED_RTNL,
  9254. },
  9255. {
  9256. .cmd = NL80211_CMD_VENDOR,
  9257. .doit = nl80211_vendor_cmd,
  9258. .policy = nl80211_policy,
  9259. .flags = GENL_ADMIN_PERM,
  9260. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9261. NL80211_FLAG_NEED_RTNL,
  9262. },
  9263. {
  9264. .cmd = NL80211_CMD_SET_QOS_MAP,
  9265. .doit = nl80211_set_qos_map,
  9266. .policy = nl80211_policy,
  9267. .flags = GENL_ADMIN_PERM,
  9268. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9269. NL80211_FLAG_NEED_RTNL,
  9270. },
  9271. {
  9272. .cmd = NL80211_CMD_ADD_TX_TS,
  9273. .doit = nl80211_add_tx_ts,
  9274. .policy = nl80211_policy,
  9275. .flags = GENL_ADMIN_PERM,
  9276. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9277. NL80211_FLAG_NEED_RTNL,
  9278. },
  9279. {
  9280. .cmd = NL80211_CMD_DEL_TX_TS,
  9281. .doit = nl80211_del_tx_ts,
  9282. .policy = nl80211_policy,
  9283. .flags = GENL_ADMIN_PERM,
  9284. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9285. NL80211_FLAG_NEED_RTNL,
  9286. },
  9287. {
  9288. .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
  9289. .doit = nl80211_tdls_channel_switch,
  9290. .policy = nl80211_policy,
  9291. .flags = GENL_ADMIN_PERM,
  9292. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9293. NL80211_FLAG_NEED_RTNL,
  9294. },
  9295. {
  9296. .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
  9297. .doit = nl80211_tdls_cancel_channel_switch,
  9298. .policy = nl80211_policy,
  9299. .flags = GENL_ADMIN_PERM,
  9300. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9301. NL80211_FLAG_NEED_RTNL,
  9302. },
  9303. };
  9304. /* notification functions */
  9305. void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
  9306. enum nl80211_commands cmd)
  9307. {
  9308. struct sk_buff *msg;
  9309. struct nl80211_dump_wiphy_state state = {};
  9310. WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
  9311. cmd != NL80211_CMD_DEL_WIPHY);
  9312. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9313. if (!msg)
  9314. return;
  9315. if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
  9316. nlmsg_free(msg);
  9317. return;
  9318. }
  9319. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9320. NL80211_MCGRP_CONFIG, GFP_KERNEL);
  9321. }
  9322. static int nl80211_add_scan_req(struct sk_buff *msg,
  9323. struct cfg80211_registered_device *rdev)
  9324. {
  9325. struct cfg80211_scan_request *req = rdev->scan_req;
  9326. struct nlattr *nest;
  9327. int i;
  9328. if (WARN_ON(!req))
  9329. return 0;
  9330. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
  9331. if (!nest)
  9332. goto nla_put_failure;
  9333. for (i = 0; i < req->n_ssids; i++) {
  9334. if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
  9335. goto nla_put_failure;
  9336. }
  9337. nla_nest_end(msg, nest);
  9338. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  9339. if (!nest)
  9340. goto nla_put_failure;
  9341. for (i = 0; i < req->n_channels; i++) {
  9342. if (nla_put_u32(msg, i, req->channels[i]->center_freq))
  9343. goto nla_put_failure;
  9344. }
  9345. nla_nest_end(msg, nest);
  9346. if (req->ie &&
  9347. nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
  9348. goto nla_put_failure;
  9349. if (req->flags &&
  9350. nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
  9351. goto nla_put_failure;
  9352. return 0;
  9353. nla_put_failure:
  9354. return -ENOBUFS;
  9355. }
  9356. static int nl80211_send_scan_msg(struct sk_buff *msg,
  9357. struct cfg80211_registered_device *rdev,
  9358. struct wireless_dev *wdev,
  9359. u32 portid, u32 seq, int flags,
  9360. u32 cmd)
  9361. {
  9362. void *hdr;
  9363. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  9364. if (!hdr)
  9365. return -1;
  9366. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9367. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  9368. wdev->netdev->ifindex)) ||
  9369. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
  9370. goto nla_put_failure;
  9371. /* ignore errors and send incomplete event anyway */
  9372. nl80211_add_scan_req(msg, rdev);
  9373. genlmsg_end(msg, hdr);
  9374. return 0;
  9375. nla_put_failure:
  9376. genlmsg_cancel(msg, hdr);
  9377. return -EMSGSIZE;
  9378. }
  9379. static int
  9380. nl80211_send_sched_scan_msg(struct sk_buff *msg,
  9381. struct cfg80211_registered_device *rdev,
  9382. struct net_device *netdev,
  9383. u32 portid, u32 seq, int flags, u32 cmd)
  9384. {
  9385. void *hdr;
  9386. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  9387. if (!hdr)
  9388. return -1;
  9389. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9390. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  9391. goto nla_put_failure;
  9392. genlmsg_end(msg, hdr);
  9393. return 0;
  9394. nla_put_failure:
  9395. genlmsg_cancel(msg, hdr);
  9396. return -EMSGSIZE;
  9397. }
  9398. void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
  9399. struct wireless_dev *wdev)
  9400. {
  9401. struct sk_buff *msg;
  9402. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9403. if (!msg)
  9404. return;
  9405. if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
  9406. NL80211_CMD_TRIGGER_SCAN) < 0) {
  9407. nlmsg_free(msg);
  9408. return;
  9409. }
  9410. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9411. NL80211_MCGRP_SCAN, GFP_KERNEL);
  9412. }
  9413. struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
  9414. struct wireless_dev *wdev, bool aborted)
  9415. {
  9416. struct sk_buff *msg;
  9417. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9418. if (!msg)
  9419. return NULL;
  9420. if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
  9421. aborted ? NL80211_CMD_SCAN_ABORTED :
  9422. NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
  9423. nlmsg_free(msg);
  9424. return NULL;
  9425. }
  9426. return msg;
  9427. }
  9428. void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
  9429. struct sk_buff *msg)
  9430. {
  9431. if (!msg)
  9432. return;
  9433. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9434. NL80211_MCGRP_SCAN, GFP_KERNEL);
  9435. }
  9436. void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
  9437. struct net_device *netdev)
  9438. {
  9439. struct sk_buff *msg;
  9440. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9441. if (!msg)
  9442. return;
  9443. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
  9444. NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
  9445. nlmsg_free(msg);
  9446. return;
  9447. }
  9448. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9449. NL80211_MCGRP_SCAN, GFP_KERNEL);
  9450. }
  9451. void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
  9452. struct net_device *netdev, u32 cmd)
  9453. {
  9454. struct sk_buff *msg;
  9455. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9456. if (!msg)
  9457. return;
  9458. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
  9459. nlmsg_free(msg);
  9460. return;
  9461. }
  9462. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9463. NL80211_MCGRP_SCAN, GFP_KERNEL);
  9464. }
  9465. static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
  9466. struct regulatory_request *request)
  9467. {
  9468. /* Userspace can always count this one always being set */
  9469. if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
  9470. goto nla_put_failure;
  9471. if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
  9472. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  9473. NL80211_REGDOM_TYPE_WORLD))
  9474. goto nla_put_failure;
  9475. } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
  9476. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  9477. NL80211_REGDOM_TYPE_CUSTOM_WORLD))
  9478. goto nla_put_failure;
  9479. } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
  9480. request->intersect) {
  9481. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  9482. NL80211_REGDOM_TYPE_INTERSECTION))
  9483. goto nla_put_failure;
  9484. } else {
  9485. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  9486. NL80211_REGDOM_TYPE_COUNTRY) ||
  9487. nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
  9488. request->alpha2))
  9489. goto nla_put_failure;
  9490. }
  9491. if (request->wiphy_idx != WIPHY_IDX_INVALID) {
  9492. struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
  9493. if (wiphy &&
  9494. nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
  9495. goto nla_put_failure;
  9496. if (wiphy &&
  9497. wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  9498. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  9499. goto nla_put_failure;
  9500. }
  9501. return true;
  9502. nla_put_failure:
  9503. return false;
  9504. }
  9505. /*
  9506. * This can happen on global regulatory changes or device specific settings
  9507. * based on custom regulatory domains.
  9508. */
  9509. void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
  9510. struct regulatory_request *request)
  9511. {
  9512. struct sk_buff *msg;
  9513. void *hdr;
  9514. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9515. if (!msg)
  9516. return;
  9517. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
  9518. if (!hdr) {
  9519. nlmsg_free(msg);
  9520. return;
  9521. }
  9522. if (nl80211_reg_change_event_fill(msg, request) == false)
  9523. goto nla_put_failure;
  9524. genlmsg_end(msg, hdr);
  9525. rcu_read_lock();
  9526. genlmsg_multicast_allns(&nl80211_fam, msg, 0,
  9527. NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
  9528. rcu_read_unlock();
  9529. return;
  9530. nla_put_failure:
  9531. genlmsg_cancel(msg, hdr);
  9532. nlmsg_free(msg);
  9533. }
  9534. static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
  9535. struct net_device *netdev,
  9536. const u8 *buf, size_t len,
  9537. enum nl80211_commands cmd, gfp_t gfp,
  9538. int uapsd_queues)
  9539. {
  9540. struct sk_buff *msg;
  9541. void *hdr;
  9542. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9543. if (!msg)
  9544. return;
  9545. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  9546. if (!hdr) {
  9547. nlmsg_free(msg);
  9548. return;
  9549. }
  9550. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9551. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9552. nla_put(msg, NL80211_ATTR_FRAME, len, buf))
  9553. goto nla_put_failure;
  9554. if (uapsd_queues >= 0) {
  9555. struct nlattr *nla_wmm =
  9556. nla_nest_start(msg, NL80211_ATTR_STA_WME);
  9557. if (!nla_wmm)
  9558. goto nla_put_failure;
  9559. if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
  9560. uapsd_queues))
  9561. goto nla_put_failure;
  9562. nla_nest_end(msg, nla_wmm);
  9563. }
  9564. genlmsg_end(msg, hdr);
  9565. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9566. NL80211_MCGRP_MLME, gfp);
  9567. return;
  9568. nla_put_failure:
  9569. genlmsg_cancel(msg, hdr);
  9570. nlmsg_free(msg);
  9571. }
  9572. void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
  9573. struct net_device *netdev, const u8 *buf,
  9574. size_t len, gfp_t gfp)
  9575. {
  9576. nl80211_send_mlme_event(rdev, netdev, buf, len,
  9577. NL80211_CMD_AUTHENTICATE, gfp, -1);
  9578. }
  9579. void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
  9580. struct net_device *netdev, const u8 *buf,
  9581. size_t len, gfp_t gfp, int uapsd_queues)
  9582. {
  9583. nl80211_send_mlme_event(rdev, netdev, buf, len,
  9584. NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
  9585. }
  9586. void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
  9587. struct net_device *netdev, const u8 *buf,
  9588. size_t len, gfp_t gfp)
  9589. {
  9590. nl80211_send_mlme_event(rdev, netdev, buf, len,
  9591. NL80211_CMD_DEAUTHENTICATE, gfp, -1);
  9592. }
  9593. void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
  9594. struct net_device *netdev, const u8 *buf,
  9595. size_t len, gfp_t gfp)
  9596. {
  9597. nl80211_send_mlme_event(rdev, netdev, buf, len,
  9598. NL80211_CMD_DISASSOCIATE, gfp, -1);
  9599. }
  9600. void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
  9601. size_t len)
  9602. {
  9603. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9604. struct wiphy *wiphy = wdev->wiphy;
  9605. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9606. const struct ieee80211_mgmt *mgmt = (void *)buf;
  9607. u32 cmd;
  9608. if (WARN_ON(len < 2))
  9609. return;
  9610. if (ieee80211_is_deauth(mgmt->frame_control))
  9611. cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
  9612. else
  9613. cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
  9614. trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
  9615. nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
  9616. }
  9617. EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
  9618. static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
  9619. struct net_device *netdev, int cmd,
  9620. const u8 *addr, gfp_t gfp)
  9621. {
  9622. struct sk_buff *msg;
  9623. void *hdr;
  9624. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9625. if (!msg)
  9626. return;
  9627. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  9628. if (!hdr) {
  9629. nlmsg_free(msg);
  9630. return;
  9631. }
  9632. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9633. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9634. nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
  9635. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  9636. goto nla_put_failure;
  9637. genlmsg_end(msg, hdr);
  9638. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9639. NL80211_MCGRP_MLME, gfp);
  9640. return;
  9641. nla_put_failure:
  9642. genlmsg_cancel(msg, hdr);
  9643. nlmsg_free(msg);
  9644. }
  9645. void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
  9646. struct net_device *netdev, const u8 *addr,
  9647. gfp_t gfp)
  9648. {
  9649. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
  9650. addr, gfp);
  9651. }
  9652. void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
  9653. struct net_device *netdev, const u8 *addr,
  9654. gfp_t gfp)
  9655. {
  9656. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
  9657. addr, gfp);
  9658. }
  9659. void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
  9660. struct net_device *netdev, const u8 *bssid,
  9661. const u8 *req_ie, size_t req_ie_len,
  9662. const u8 *resp_ie, size_t resp_ie_len,
  9663. u16 status, gfp_t gfp)
  9664. {
  9665. struct sk_buff *msg;
  9666. void *hdr;
  9667. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9668. if (!msg)
  9669. return;
  9670. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
  9671. if (!hdr) {
  9672. nlmsg_free(msg);
  9673. return;
  9674. }
  9675. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9676. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9677. (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
  9678. nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
  9679. (req_ie &&
  9680. nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
  9681. (resp_ie &&
  9682. nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
  9683. goto nla_put_failure;
  9684. genlmsg_end(msg, hdr);
  9685. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9686. NL80211_MCGRP_MLME, gfp);
  9687. return;
  9688. nla_put_failure:
  9689. genlmsg_cancel(msg, hdr);
  9690. nlmsg_free(msg);
  9691. }
  9692. void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
  9693. struct net_device *netdev, const u8 *bssid,
  9694. const u8 *req_ie, size_t req_ie_len,
  9695. const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
  9696. {
  9697. struct sk_buff *msg;
  9698. void *hdr;
  9699. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9700. if (!msg)
  9701. return;
  9702. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
  9703. if (!hdr) {
  9704. nlmsg_free(msg);
  9705. return;
  9706. }
  9707. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9708. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9709. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
  9710. (req_ie &&
  9711. nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
  9712. (resp_ie &&
  9713. nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
  9714. goto nla_put_failure;
  9715. genlmsg_end(msg, hdr);
  9716. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9717. NL80211_MCGRP_MLME, gfp);
  9718. return;
  9719. nla_put_failure:
  9720. genlmsg_cancel(msg, hdr);
  9721. nlmsg_free(msg);
  9722. }
  9723. void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
  9724. struct net_device *netdev, u16 reason,
  9725. const u8 *ie, size_t ie_len, bool from_ap)
  9726. {
  9727. struct sk_buff *msg;
  9728. void *hdr;
  9729. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9730. if (!msg)
  9731. return;
  9732. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
  9733. if (!hdr) {
  9734. nlmsg_free(msg);
  9735. return;
  9736. }
  9737. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9738. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9739. (from_ap && reason &&
  9740. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
  9741. (from_ap &&
  9742. nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
  9743. (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
  9744. goto nla_put_failure;
  9745. genlmsg_end(msg, hdr);
  9746. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9747. NL80211_MCGRP_MLME, GFP_KERNEL);
  9748. return;
  9749. nla_put_failure:
  9750. genlmsg_cancel(msg, hdr);
  9751. nlmsg_free(msg);
  9752. }
  9753. void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
  9754. struct net_device *netdev, const u8 *bssid,
  9755. gfp_t gfp)
  9756. {
  9757. struct sk_buff *msg;
  9758. void *hdr;
  9759. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9760. if (!msg)
  9761. return;
  9762. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
  9763. if (!hdr) {
  9764. nlmsg_free(msg);
  9765. return;
  9766. }
  9767. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9768. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9769. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
  9770. goto nla_put_failure;
  9771. genlmsg_end(msg, hdr);
  9772. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9773. NL80211_MCGRP_MLME, gfp);
  9774. return;
  9775. nla_put_failure:
  9776. genlmsg_cancel(msg, hdr);
  9777. nlmsg_free(msg);
  9778. }
  9779. void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
  9780. const u8* ie, u8 ie_len, gfp_t gfp)
  9781. {
  9782. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9783. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  9784. struct sk_buff *msg;
  9785. void *hdr;
  9786. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
  9787. return;
  9788. trace_cfg80211_notify_new_peer_candidate(dev, addr);
  9789. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9790. if (!msg)
  9791. return;
  9792. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
  9793. if (!hdr) {
  9794. nlmsg_free(msg);
  9795. return;
  9796. }
  9797. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9798. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  9799. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  9800. (ie_len && ie &&
  9801. nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
  9802. goto nla_put_failure;
  9803. genlmsg_end(msg, hdr);
  9804. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9805. NL80211_MCGRP_MLME, gfp);
  9806. return;
  9807. nla_put_failure:
  9808. genlmsg_cancel(msg, hdr);
  9809. nlmsg_free(msg);
  9810. }
  9811. EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
  9812. void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
  9813. struct net_device *netdev, const u8 *addr,
  9814. enum nl80211_key_type key_type, int key_id,
  9815. const u8 *tsc, gfp_t gfp)
  9816. {
  9817. struct sk_buff *msg;
  9818. void *hdr;
  9819. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9820. if (!msg)
  9821. return;
  9822. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
  9823. if (!hdr) {
  9824. nlmsg_free(msg);
  9825. return;
  9826. }
  9827. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9828. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  9829. (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
  9830. nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
  9831. (key_id != -1 &&
  9832. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
  9833. (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
  9834. goto nla_put_failure;
  9835. genlmsg_end(msg, hdr);
  9836. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9837. NL80211_MCGRP_MLME, gfp);
  9838. return;
  9839. nla_put_failure:
  9840. genlmsg_cancel(msg, hdr);
  9841. nlmsg_free(msg);
  9842. }
  9843. void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
  9844. struct ieee80211_channel *channel_before,
  9845. struct ieee80211_channel *channel_after)
  9846. {
  9847. struct sk_buff *msg;
  9848. void *hdr;
  9849. struct nlattr *nl_freq;
  9850. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  9851. if (!msg)
  9852. return;
  9853. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
  9854. if (!hdr) {
  9855. nlmsg_free(msg);
  9856. return;
  9857. }
  9858. /*
  9859. * Since we are applying the beacon hint to a wiphy we know its
  9860. * wiphy_idx is valid
  9861. */
  9862. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  9863. goto nla_put_failure;
  9864. /* Before */
  9865. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
  9866. if (!nl_freq)
  9867. goto nla_put_failure;
  9868. if (nl80211_msg_put_channel(msg, channel_before, false))
  9869. goto nla_put_failure;
  9870. nla_nest_end(msg, nl_freq);
  9871. /* After */
  9872. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
  9873. if (!nl_freq)
  9874. goto nla_put_failure;
  9875. if (nl80211_msg_put_channel(msg, channel_after, false))
  9876. goto nla_put_failure;
  9877. nla_nest_end(msg, nl_freq);
  9878. genlmsg_end(msg, hdr);
  9879. rcu_read_lock();
  9880. genlmsg_multicast_allns(&nl80211_fam, msg, 0,
  9881. NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
  9882. rcu_read_unlock();
  9883. return;
  9884. nla_put_failure:
  9885. genlmsg_cancel(msg, hdr);
  9886. nlmsg_free(msg);
  9887. }
  9888. static void nl80211_send_remain_on_chan_event(
  9889. int cmd, struct cfg80211_registered_device *rdev,
  9890. struct wireless_dev *wdev, u64 cookie,
  9891. struct ieee80211_channel *chan,
  9892. unsigned int duration, gfp_t gfp)
  9893. {
  9894. struct sk_buff *msg;
  9895. void *hdr;
  9896. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9897. if (!msg)
  9898. return;
  9899. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  9900. if (!hdr) {
  9901. nlmsg_free(msg);
  9902. return;
  9903. }
  9904. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9905. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  9906. wdev->netdev->ifindex)) ||
  9907. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
  9908. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
  9909. nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  9910. NL80211_CHAN_NO_HT) ||
  9911. nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
  9912. goto nla_put_failure;
  9913. if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
  9914. nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
  9915. goto nla_put_failure;
  9916. genlmsg_end(msg, hdr);
  9917. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9918. NL80211_MCGRP_MLME, gfp);
  9919. return;
  9920. nla_put_failure:
  9921. genlmsg_cancel(msg, hdr);
  9922. nlmsg_free(msg);
  9923. }
  9924. void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
  9925. struct ieee80211_channel *chan,
  9926. unsigned int duration, gfp_t gfp)
  9927. {
  9928. struct wiphy *wiphy = wdev->wiphy;
  9929. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9930. trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
  9931. nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
  9932. rdev, wdev, cookie, chan,
  9933. duration, gfp);
  9934. }
  9935. EXPORT_SYMBOL(cfg80211_ready_on_channel);
  9936. void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
  9937. struct ieee80211_channel *chan,
  9938. gfp_t gfp)
  9939. {
  9940. struct wiphy *wiphy = wdev->wiphy;
  9941. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9942. trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
  9943. nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  9944. rdev, wdev, cookie, chan, 0, gfp);
  9945. }
  9946. EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
  9947. void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
  9948. struct station_info *sinfo, gfp_t gfp)
  9949. {
  9950. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  9951. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9952. struct sk_buff *msg;
  9953. trace_cfg80211_new_sta(dev, mac_addr, sinfo);
  9954. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9955. if (!msg)
  9956. return;
  9957. if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
  9958. rdev, dev, mac_addr, sinfo) < 0) {
  9959. nlmsg_free(msg);
  9960. return;
  9961. }
  9962. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9963. NL80211_MCGRP_MLME, gfp);
  9964. }
  9965. EXPORT_SYMBOL(cfg80211_new_sta);
  9966. void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
  9967. struct station_info *sinfo, gfp_t gfp)
  9968. {
  9969. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  9970. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9971. struct sk_buff *msg;
  9972. struct station_info empty_sinfo = {};
  9973. if (!sinfo)
  9974. sinfo = &empty_sinfo;
  9975. trace_cfg80211_del_sta(dev, mac_addr);
  9976. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9977. if (!msg)
  9978. return;
  9979. if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
  9980. rdev, dev, mac_addr, sinfo) < 0) {
  9981. nlmsg_free(msg);
  9982. return;
  9983. }
  9984. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  9985. NL80211_MCGRP_MLME, gfp);
  9986. }
  9987. EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
  9988. void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
  9989. enum nl80211_connect_failed_reason reason,
  9990. gfp_t gfp)
  9991. {
  9992. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  9993. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9994. struct sk_buff *msg;
  9995. void *hdr;
  9996. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  9997. if (!msg)
  9998. return;
  9999. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
  10000. if (!hdr) {
  10001. nlmsg_free(msg);
  10002. return;
  10003. }
  10004. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  10005. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
  10006. nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
  10007. goto nla_put_failure;
  10008. genlmsg_end(msg, hdr);
  10009. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10010. NL80211_MCGRP_MLME, gfp);
  10011. return;
  10012. nla_put_failure:
  10013. genlmsg_cancel(msg, hdr);
  10014. nlmsg_free(msg);
  10015. }
  10016. EXPORT_SYMBOL(cfg80211_conn_failed);
  10017. static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
  10018. const u8 *addr, gfp_t gfp)
  10019. {
  10020. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10021. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  10022. struct sk_buff *msg;
  10023. void *hdr;
  10024. u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
  10025. if (!nlportid)
  10026. return false;
  10027. msg = nlmsg_new(100, gfp);
  10028. if (!msg)
  10029. return true;
  10030. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  10031. if (!hdr) {
  10032. nlmsg_free(msg);
  10033. return true;
  10034. }
  10035. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10036. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  10037. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  10038. goto nla_put_failure;
  10039. genlmsg_end(msg, hdr);
  10040. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  10041. return true;
  10042. nla_put_failure:
  10043. genlmsg_cancel(msg, hdr);
  10044. nlmsg_free(msg);
  10045. return true;
  10046. }
  10047. bool cfg80211_rx_spurious_frame(struct net_device *dev,
  10048. const u8 *addr, gfp_t gfp)
  10049. {
  10050. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10051. bool ret;
  10052. trace_cfg80211_rx_spurious_frame(dev, addr);
  10053. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  10054. wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
  10055. trace_cfg80211_return_bool(false);
  10056. return false;
  10057. }
  10058. ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
  10059. addr, gfp);
  10060. trace_cfg80211_return_bool(ret);
  10061. return ret;
  10062. }
  10063. EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
  10064. bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
  10065. const u8 *addr, gfp_t gfp)
  10066. {
  10067. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10068. bool ret;
  10069. trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
  10070. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  10071. wdev->iftype != NL80211_IFTYPE_P2P_GO &&
  10072. wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
  10073. trace_cfg80211_return_bool(false);
  10074. return false;
  10075. }
  10076. ret = __nl80211_unexpected_frame(dev,
  10077. NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
  10078. addr, gfp);
  10079. trace_cfg80211_return_bool(ret);
  10080. return ret;
  10081. }
  10082. EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
  10083. int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
  10084. struct wireless_dev *wdev, u32 nlportid,
  10085. int freq, int sig_dbm,
  10086. const u8 *buf, size_t len, u32 flags, gfp_t gfp)
  10087. {
  10088. struct net_device *netdev = wdev->netdev;
  10089. struct sk_buff *msg;
  10090. void *hdr;
  10091. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10092. if (!msg)
  10093. return -ENOMEM;
  10094. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  10095. if (!hdr) {
  10096. nlmsg_free(msg);
  10097. return -ENOMEM;
  10098. }
  10099. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10100. (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  10101. netdev->ifindex)) ||
  10102. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
  10103. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
  10104. (sig_dbm &&
  10105. nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
  10106. nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
  10107. (flags &&
  10108. nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
  10109. goto nla_put_failure;
  10110. genlmsg_end(msg, hdr);
  10111. return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  10112. nla_put_failure:
  10113. genlmsg_cancel(msg, hdr);
  10114. nlmsg_free(msg);
  10115. return -ENOBUFS;
  10116. }
  10117. void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
  10118. const u8 *buf, size_t len, bool ack, gfp_t gfp)
  10119. {
  10120. struct wiphy *wiphy = wdev->wiphy;
  10121. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10122. struct net_device *netdev = wdev->netdev;
  10123. struct sk_buff *msg;
  10124. void *hdr;
  10125. trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
  10126. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10127. if (!msg)
  10128. return;
  10129. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
  10130. if (!hdr) {
  10131. nlmsg_free(msg);
  10132. return;
  10133. }
  10134. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10135. (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  10136. netdev->ifindex)) ||
  10137. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
  10138. nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
  10139. nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
  10140. (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
  10141. goto nla_put_failure;
  10142. genlmsg_end(msg, hdr);
  10143. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10144. NL80211_MCGRP_MLME, gfp);
  10145. return;
  10146. nla_put_failure:
  10147. genlmsg_cancel(msg, hdr);
  10148. nlmsg_free(msg);
  10149. }
  10150. EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
  10151. static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
  10152. const char *mac, gfp_t gfp)
  10153. {
  10154. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10155. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  10156. struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10157. void **cb;
  10158. if (!msg)
  10159. return NULL;
  10160. cb = (void **)msg->cb;
  10161. cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
  10162. if (!cb[0]) {
  10163. nlmsg_free(msg);
  10164. return NULL;
  10165. }
  10166. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10167. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
  10168. goto nla_put_failure;
  10169. if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
  10170. goto nla_put_failure;
  10171. cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
  10172. if (!cb[1])
  10173. goto nla_put_failure;
  10174. cb[2] = rdev;
  10175. return msg;
  10176. nla_put_failure:
  10177. nlmsg_free(msg);
  10178. return NULL;
  10179. }
  10180. static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
  10181. {
  10182. void **cb = (void **)msg->cb;
  10183. struct cfg80211_registered_device *rdev = cb[2];
  10184. nla_nest_end(msg, cb[1]);
  10185. genlmsg_end(msg, cb[0]);
  10186. memset(msg->cb, 0, sizeof(msg->cb));
  10187. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10188. NL80211_MCGRP_MLME, gfp);
  10189. }
  10190. void cfg80211_cqm_rssi_notify(struct net_device *dev,
  10191. enum nl80211_cqm_rssi_threshold_event rssi_event,
  10192. gfp_t gfp)
  10193. {
  10194. struct sk_buff *msg;
  10195. trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
  10196. if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
  10197. rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
  10198. return;
  10199. msg = cfg80211_prepare_cqm(dev, NULL, gfp);
  10200. if (!msg)
  10201. return;
  10202. if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
  10203. rssi_event))
  10204. goto nla_put_failure;
  10205. cfg80211_send_cqm(msg, gfp);
  10206. return;
  10207. nla_put_failure:
  10208. nlmsg_free(msg);
  10209. }
  10210. EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
  10211. void cfg80211_cqm_txe_notify(struct net_device *dev,
  10212. const u8 *peer, u32 num_packets,
  10213. u32 rate, u32 intvl, gfp_t gfp)
  10214. {
  10215. struct sk_buff *msg;
  10216. msg = cfg80211_prepare_cqm(dev, peer, gfp);
  10217. if (!msg)
  10218. return;
  10219. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
  10220. goto nla_put_failure;
  10221. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
  10222. goto nla_put_failure;
  10223. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
  10224. goto nla_put_failure;
  10225. cfg80211_send_cqm(msg, gfp);
  10226. return;
  10227. nla_put_failure:
  10228. nlmsg_free(msg);
  10229. }
  10230. EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
  10231. void cfg80211_cqm_pktloss_notify(struct net_device *dev,
  10232. const u8 *peer, u32 num_packets, gfp_t gfp)
  10233. {
  10234. struct sk_buff *msg;
  10235. trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
  10236. msg = cfg80211_prepare_cqm(dev, peer, gfp);
  10237. if (!msg)
  10238. return;
  10239. if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
  10240. goto nla_put_failure;
  10241. cfg80211_send_cqm(msg, gfp);
  10242. return;
  10243. nla_put_failure:
  10244. nlmsg_free(msg);
  10245. }
  10246. EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
  10247. void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
  10248. {
  10249. struct sk_buff *msg;
  10250. msg = cfg80211_prepare_cqm(dev, NULL, gfp);
  10251. if (!msg)
  10252. return;
  10253. if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
  10254. goto nla_put_failure;
  10255. cfg80211_send_cqm(msg, gfp);
  10256. return;
  10257. nla_put_failure:
  10258. nlmsg_free(msg);
  10259. }
  10260. EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
  10261. static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
  10262. struct net_device *netdev, const u8 *bssid,
  10263. const u8 *replay_ctr, gfp_t gfp)
  10264. {
  10265. struct sk_buff *msg;
  10266. struct nlattr *rekey_attr;
  10267. void *hdr;
  10268. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10269. if (!msg)
  10270. return;
  10271. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
  10272. if (!hdr) {
  10273. nlmsg_free(msg);
  10274. return;
  10275. }
  10276. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10277. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  10278. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
  10279. goto nla_put_failure;
  10280. rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
  10281. if (!rekey_attr)
  10282. goto nla_put_failure;
  10283. if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
  10284. NL80211_REPLAY_CTR_LEN, replay_ctr))
  10285. goto nla_put_failure;
  10286. nla_nest_end(msg, rekey_attr);
  10287. genlmsg_end(msg, hdr);
  10288. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10289. NL80211_MCGRP_MLME, gfp);
  10290. return;
  10291. nla_put_failure:
  10292. genlmsg_cancel(msg, hdr);
  10293. nlmsg_free(msg);
  10294. }
  10295. void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
  10296. const u8 *replay_ctr, gfp_t gfp)
  10297. {
  10298. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10299. struct wiphy *wiphy = wdev->wiphy;
  10300. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10301. trace_cfg80211_gtk_rekey_notify(dev, bssid);
  10302. nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
  10303. }
  10304. EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
  10305. static void
  10306. nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
  10307. struct net_device *netdev, int index,
  10308. const u8 *bssid, bool preauth, gfp_t gfp)
  10309. {
  10310. struct sk_buff *msg;
  10311. struct nlattr *attr;
  10312. void *hdr;
  10313. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10314. if (!msg)
  10315. return;
  10316. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
  10317. if (!hdr) {
  10318. nlmsg_free(msg);
  10319. return;
  10320. }
  10321. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10322. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  10323. goto nla_put_failure;
  10324. attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
  10325. if (!attr)
  10326. goto nla_put_failure;
  10327. if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
  10328. nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
  10329. (preauth &&
  10330. nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
  10331. goto nla_put_failure;
  10332. nla_nest_end(msg, attr);
  10333. genlmsg_end(msg, hdr);
  10334. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10335. NL80211_MCGRP_MLME, gfp);
  10336. return;
  10337. nla_put_failure:
  10338. genlmsg_cancel(msg, hdr);
  10339. nlmsg_free(msg);
  10340. }
  10341. void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
  10342. const u8 *bssid, bool preauth, gfp_t gfp)
  10343. {
  10344. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10345. struct wiphy *wiphy = wdev->wiphy;
  10346. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10347. trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
  10348. nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
  10349. }
  10350. EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
  10351. static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
  10352. struct net_device *netdev,
  10353. struct cfg80211_chan_def *chandef,
  10354. gfp_t gfp,
  10355. enum nl80211_commands notif,
  10356. u8 count)
  10357. {
  10358. struct sk_buff *msg;
  10359. void *hdr;
  10360. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10361. if (!msg)
  10362. return;
  10363. hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
  10364. if (!hdr) {
  10365. nlmsg_free(msg);
  10366. return;
  10367. }
  10368. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  10369. goto nla_put_failure;
  10370. if (nl80211_send_chandef(msg, chandef))
  10371. goto nla_put_failure;
  10372. if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
  10373. (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
  10374. goto nla_put_failure;
  10375. genlmsg_end(msg, hdr);
  10376. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10377. NL80211_MCGRP_MLME, gfp);
  10378. return;
  10379. nla_put_failure:
  10380. genlmsg_cancel(msg, hdr);
  10381. nlmsg_free(msg);
  10382. }
  10383. void cfg80211_ch_switch_notify(struct net_device *dev,
  10384. struct cfg80211_chan_def *chandef)
  10385. {
  10386. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10387. struct wiphy *wiphy = wdev->wiphy;
  10388. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10389. ASSERT_WDEV_LOCK(wdev);
  10390. trace_cfg80211_ch_switch_notify(dev, chandef);
  10391. wdev->chandef = *chandef;
  10392. wdev->preset_chandef = *chandef;
  10393. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
  10394. NL80211_CMD_CH_SWITCH_NOTIFY, 0);
  10395. }
  10396. EXPORT_SYMBOL(cfg80211_ch_switch_notify);
  10397. void cfg80211_ch_switch_started_notify(struct net_device *dev,
  10398. struct cfg80211_chan_def *chandef,
  10399. u8 count)
  10400. {
  10401. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10402. struct wiphy *wiphy = wdev->wiphy;
  10403. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10404. trace_cfg80211_ch_switch_started_notify(dev, chandef);
  10405. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
  10406. NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
  10407. }
  10408. EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
  10409. void
  10410. nl80211_radar_notify(struct cfg80211_registered_device *rdev,
  10411. const struct cfg80211_chan_def *chandef,
  10412. enum nl80211_radar_event event,
  10413. struct net_device *netdev, gfp_t gfp)
  10414. {
  10415. struct sk_buff *msg;
  10416. void *hdr;
  10417. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10418. if (!msg)
  10419. return;
  10420. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
  10421. if (!hdr) {
  10422. nlmsg_free(msg);
  10423. return;
  10424. }
  10425. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  10426. goto nla_put_failure;
  10427. /* NOP and radar events don't need a netdev parameter */
  10428. if (netdev) {
  10429. struct wireless_dev *wdev = netdev->ieee80211_ptr;
  10430. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  10431. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
  10432. goto nla_put_failure;
  10433. }
  10434. if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
  10435. goto nla_put_failure;
  10436. if (nl80211_send_chandef(msg, chandef))
  10437. goto nla_put_failure;
  10438. genlmsg_end(msg, hdr);
  10439. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10440. NL80211_MCGRP_MLME, gfp);
  10441. return;
  10442. nla_put_failure:
  10443. genlmsg_cancel(msg, hdr);
  10444. nlmsg_free(msg);
  10445. }
  10446. void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  10447. u64 cookie, bool acked, gfp_t gfp)
  10448. {
  10449. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10450. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  10451. struct sk_buff *msg;
  10452. void *hdr;
  10453. trace_cfg80211_probe_status(dev, addr, cookie, acked);
  10454. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10455. if (!msg)
  10456. return;
  10457. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
  10458. if (!hdr) {
  10459. nlmsg_free(msg);
  10460. return;
  10461. }
  10462. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10463. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  10464. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  10465. nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
  10466. (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
  10467. goto nla_put_failure;
  10468. genlmsg_end(msg, hdr);
  10469. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10470. NL80211_MCGRP_MLME, gfp);
  10471. return;
  10472. nla_put_failure:
  10473. genlmsg_cancel(msg, hdr);
  10474. nlmsg_free(msg);
  10475. }
  10476. EXPORT_SYMBOL(cfg80211_probe_status);
  10477. void cfg80211_report_obss_beacon(struct wiphy *wiphy,
  10478. const u8 *frame, size_t len,
  10479. int freq, int sig_dbm)
  10480. {
  10481. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10482. struct sk_buff *msg;
  10483. void *hdr;
  10484. struct cfg80211_beacon_registration *reg;
  10485. trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
  10486. spin_lock_bh(&rdev->beacon_registrations_lock);
  10487. list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  10488. msg = nlmsg_new(len + 100, GFP_ATOMIC);
  10489. if (!msg) {
  10490. spin_unlock_bh(&rdev->beacon_registrations_lock);
  10491. return;
  10492. }
  10493. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  10494. if (!hdr)
  10495. goto nla_put_failure;
  10496. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10497. (freq &&
  10498. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
  10499. (sig_dbm &&
  10500. nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
  10501. nla_put(msg, NL80211_ATTR_FRAME, len, frame))
  10502. goto nla_put_failure;
  10503. genlmsg_end(msg, hdr);
  10504. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
  10505. }
  10506. spin_unlock_bh(&rdev->beacon_registrations_lock);
  10507. return;
  10508. nla_put_failure:
  10509. spin_unlock_bh(&rdev->beacon_registrations_lock);
  10510. if (hdr)
  10511. genlmsg_cancel(msg, hdr);
  10512. nlmsg_free(msg);
  10513. }
  10514. EXPORT_SYMBOL(cfg80211_report_obss_beacon);
  10515. #ifdef CONFIG_PM
  10516. static int cfg80211_net_detect_results(struct sk_buff *msg,
  10517. struct cfg80211_wowlan_wakeup *wakeup)
  10518. {
  10519. struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
  10520. struct nlattr *nl_results, *nl_match, *nl_freqs;
  10521. int i, j;
  10522. nl_results = nla_nest_start(
  10523. msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
  10524. if (!nl_results)
  10525. return -EMSGSIZE;
  10526. for (i = 0; i < nd->n_matches; i++) {
  10527. struct cfg80211_wowlan_nd_match *match = nd->matches[i];
  10528. nl_match = nla_nest_start(msg, i);
  10529. if (!nl_match)
  10530. break;
  10531. /* The SSID attribute is optional in nl80211, but for
  10532. * simplicity reasons it's always present in the
  10533. * cfg80211 structure. If a driver can't pass the
  10534. * SSID, that needs to be changed. A zero length SSID
  10535. * is still a valid SSID (wildcard), so it cannot be
  10536. * used for this purpose.
  10537. */
  10538. if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
  10539. match->ssid.ssid)) {
  10540. nla_nest_cancel(msg, nl_match);
  10541. goto out;
  10542. }
  10543. if (match->n_channels) {
  10544. nl_freqs = nla_nest_start(
  10545. msg, NL80211_ATTR_SCAN_FREQUENCIES);
  10546. if (!nl_freqs) {
  10547. nla_nest_cancel(msg, nl_match);
  10548. goto out;
  10549. }
  10550. for (j = 0; j < match->n_channels; j++) {
  10551. if (nla_put_u32(msg, j, match->channels[j])) {
  10552. nla_nest_cancel(msg, nl_freqs);
  10553. nla_nest_cancel(msg, nl_match);
  10554. goto out;
  10555. }
  10556. }
  10557. nla_nest_end(msg, nl_freqs);
  10558. }
  10559. nla_nest_end(msg, nl_match);
  10560. }
  10561. out:
  10562. nla_nest_end(msg, nl_results);
  10563. return 0;
  10564. }
  10565. void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
  10566. struct cfg80211_wowlan_wakeup *wakeup,
  10567. gfp_t gfp)
  10568. {
  10569. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  10570. struct sk_buff *msg;
  10571. void *hdr;
  10572. int size = 200;
  10573. trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
  10574. if (wakeup)
  10575. size += wakeup->packet_present_len;
  10576. msg = nlmsg_new(size, gfp);
  10577. if (!msg)
  10578. return;
  10579. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
  10580. if (!hdr)
  10581. goto free_msg;
  10582. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10583. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
  10584. goto free_msg;
  10585. if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  10586. wdev->netdev->ifindex))
  10587. goto free_msg;
  10588. if (wakeup) {
  10589. struct nlattr *reasons;
  10590. reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  10591. if (!reasons)
  10592. goto free_msg;
  10593. if (wakeup->disconnect &&
  10594. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
  10595. goto free_msg;
  10596. if (wakeup->magic_pkt &&
  10597. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
  10598. goto free_msg;
  10599. if (wakeup->gtk_rekey_failure &&
  10600. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
  10601. goto free_msg;
  10602. if (wakeup->eap_identity_req &&
  10603. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
  10604. goto free_msg;
  10605. if (wakeup->four_way_handshake &&
  10606. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
  10607. goto free_msg;
  10608. if (wakeup->rfkill_release &&
  10609. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
  10610. goto free_msg;
  10611. if (wakeup->pattern_idx >= 0 &&
  10612. nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  10613. wakeup->pattern_idx))
  10614. goto free_msg;
  10615. if (wakeup->tcp_match &&
  10616. nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
  10617. goto free_msg;
  10618. if (wakeup->tcp_connlost &&
  10619. nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
  10620. goto free_msg;
  10621. if (wakeup->tcp_nomoretokens &&
  10622. nla_put_flag(msg,
  10623. NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
  10624. goto free_msg;
  10625. if (wakeup->packet) {
  10626. u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
  10627. u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
  10628. if (!wakeup->packet_80211) {
  10629. pkt_attr =
  10630. NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
  10631. len_attr =
  10632. NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
  10633. }
  10634. if (wakeup->packet_len &&
  10635. nla_put_u32(msg, len_attr, wakeup->packet_len))
  10636. goto free_msg;
  10637. if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
  10638. wakeup->packet))
  10639. goto free_msg;
  10640. }
  10641. if (wakeup->net_detect &&
  10642. cfg80211_net_detect_results(msg, wakeup))
  10643. goto free_msg;
  10644. nla_nest_end(msg, reasons);
  10645. }
  10646. genlmsg_end(msg, hdr);
  10647. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10648. NL80211_MCGRP_MLME, gfp);
  10649. return;
  10650. free_msg:
  10651. nlmsg_free(msg);
  10652. }
  10653. EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
  10654. #endif
  10655. void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
  10656. enum nl80211_tdls_operation oper,
  10657. u16 reason_code, gfp_t gfp)
  10658. {
  10659. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10660. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  10661. struct sk_buff *msg;
  10662. void *hdr;
  10663. trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
  10664. reason_code);
  10665. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10666. if (!msg)
  10667. return;
  10668. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
  10669. if (!hdr) {
  10670. nlmsg_free(msg);
  10671. return;
  10672. }
  10673. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10674. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  10675. nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
  10676. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
  10677. (reason_code > 0 &&
  10678. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
  10679. goto nla_put_failure;
  10680. genlmsg_end(msg, hdr);
  10681. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10682. NL80211_MCGRP_MLME, gfp);
  10683. return;
  10684. nla_put_failure:
  10685. genlmsg_cancel(msg, hdr);
  10686. nlmsg_free(msg);
  10687. }
  10688. EXPORT_SYMBOL(cfg80211_tdls_oper_request);
  10689. static int nl80211_netlink_notify(struct notifier_block * nb,
  10690. unsigned long state,
  10691. void *_notify)
  10692. {
  10693. struct netlink_notify *notify = _notify;
  10694. struct cfg80211_registered_device *rdev;
  10695. struct wireless_dev *wdev;
  10696. struct cfg80211_beacon_registration *reg, *tmp;
  10697. if (state != NETLINK_URELEASE)
  10698. return NOTIFY_DONE;
  10699. rcu_read_lock();
  10700. list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
  10701. bool schedule_destroy_work = false;
  10702. bool schedule_scan_stop = false;
  10703. struct cfg80211_sched_scan_request *sched_scan_req =
  10704. rcu_dereference(rdev->sched_scan_req);
  10705. if (sched_scan_req && notify->portid &&
  10706. sched_scan_req->owner_nlportid == notify->portid)
  10707. schedule_scan_stop = true;
  10708. list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
  10709. cfg80211_mlme_unregister_socket(wdev, notify->portid);
  10710. if (wdev->owner_nlportid == notify->portid)
  10711. schedule_destroy_work = true;
  10712. }
  10713. spin_lock_bh(&rdev->beacon_registrations_lock);
  10714. list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
  10715. list) {
  10716. if (reg->nlportid == notify->portid) {
  10717. list_del(&reg->list);
  10718. kfree(reg);
  10719. break;
  10720. }
  10721. }
  10722. spin_unlock_bh(&rdev->beacon_registrations_lock);
  10723. if (schedule_destroy_work) {
  10724. struct cfg80211_iface_destroy *destroy;
  10725. destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
  10726. if (destroy) {
  10727. destroy->nlportid = notify->portid;
  10728. spin_lock(&rdev->destroy_list_lock);
  10729. list_add(&destroy->list, &rdev->destroy_list);
  10730. spin_unlock(&rdev->destroy_list_lock);
  10731. schedule_work(&rdev->destroy_work);
  10732. }
  10733. } else if (schedule_scan_stop) {
  10734. sched_scan_req->owner_nlportid = 0;
  10735. if (rdev->ops->sched_scan_stop &&
  10736. rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  10737. schedule_work(&rdev->sched_scan_stop_wk);
  10738. }
  10739. }
  10740. rcu_read_unlock();
  10741. /*
  10742. * It is possible that the user space process that is controlling the
  10743. * indoor setting disappeared, so notify the regulatory core.
  10744. */
  10745. regulatory_netlink_notify(notify->portid);
  10746. return NOTIFY_OK;
  10747. }
  10748. static struct notifier_block nl80211_netlink_notifier = {
  10749. .notifier_call = nl80211_netlink_notify,
  10750. };
  10751. void cfg80211_ft_event(struct net_device *netdev,
  10752. struct cfg80211_ft_event_params *ft_event)
  10753. {
  10754. struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
  10755. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10756. struct sk_buff *msg;
  10757. void *hdr;
  10758. trace_cfg80211_ft_event(wiphy, netdev, ft_event);
  10759. if (!ft_event->target_ap)
  10760. return;
  10761. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10762. if (!msg)
  10763. return;
  10764. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
  10765. if (!hdr)
  10766. goto out;
  10767. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10768. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  10769. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
  10770. goto out;
  10771. if (ft_event->ies &&
  10772. nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
  10773. goto out;
  10774. if (ft_event->ric_ies &&
  10775. nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
  10776. ft_event->ric_ies))
  10777. goto out;
  10778. genlmsg_end(msg, hdr);
  10779. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10780. NL80211_MCGRP_MLME, GFP_KERNEL);
  10781. return;
  10782. out:
  10783. nlmsg_free(msg);
  10784. }
  10785. EXPORT_SYMBOL(cfg80211_ft_event);
  10786. void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
  10787. {
  10788. struct cfg80211_registered_device *rdev;
  10789. struct sk_buff *msg;
  10790. void *hdr;
  10791. u32 nlportid;
  10792. rdev = wiphy_to_rdev(wdev->wiphy);
  10793. if (!rdev->crit_proto_nlportid)
  10794. return;
  10795. nlportid = rdev->crit_proto_nlportid;
  10796. rdev->crit_proto_nlportid = 0;
  10797. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10798. if (!msg)
  10799. return;
  10800. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
  10801. if (!hdr)
  10802. goto nla_put_failure;
  10803. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10804. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
  10805. goto nla_put_failure;
  10806. genlmsg_end(msg, hdr);
  10807. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  10808. return;
  10809. nla_put_failure:
  10810. if (hdr)
  10811. genlmsg_cancel(msg, hdr);
  10812. nlmsg_free(msg);
  10813. }
  10814. EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
  10815. void nl80211_send_ap_stopped(struct wireless_dev *wdev)
  10816. {
  10817. struct wiphy *wiphy = wdev->wiphy;
  10818. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10819. struct sk_buff *msg;
  10820. void *hdr;
  10821. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10822. if (!msg)
  10823. return;
  10824. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
  10825. if (!hdr)
  10826. goto out;
  10827. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10828. nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
  10829. nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
  10830. goto out;
  10831. genlmsg_end(msg, hdr);
  10832. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
  10833. NL80211_MCGRP_MLME, GFP_KERNEL);
  10834. return;
  10835. out:
  10836. nlmsg_free(msg);
  10837. }
  10838. /* initialisation/exit functions */
  10839. int nl80211_init(void)
  10840. {
  10841. int err;
  10842. err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
  10843. nl80211_mcgrps);
  10844. if (err)
  10845. return err;
  10846. err = netlink_register_notifier(&nl80211_netlink_notifier);
  10847. if (err)
  10848. goto err_out;
  10849. return 0;
  10850. err_out:
  10851. genl_unregister_family(&nl80211_fam);
  10852. return err;
  10853. }
  10854. void nl80211_exit(void)
  10855. {
  10856. netlink_unregister_notifier(&nl80211_netlink_notifier);
  10857. genl_unregister_family(&nl80211_fam);
  10858. }