nl80211.c 307 KB

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