nl80211.c 300 KB

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