nl80211.c 383 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609
  1. /*
  2. * This is the new netlink-based wireless configuration interface.
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. * Copyright 2015-2016 Intel Deutschland GmbH
  7. */
  8. #include <linux/if.h>
  9. #include <linux/module.h>
  10. #include <linux/err.h>
  11. #include <linux/slab.h>
  12. #include <linux/list.h>
  13. #include <linux/if_ether.h>
  14. #include <linux/ieee80211.h>
  15. #include <linux/nl80211.h>
  16. #include <linux/rtnetlink.h>
  17. #include <linux/netlink.h>
  18. #include <linux/nospec.h>
  19. #include <linux/etherdevice.h>
  20. #include <net/net_namespace.h>
  21. #include <net/genetlink.h>
  22. #include <net/cfg80211.h>
  23. #include <net/sock.h>
  24. #include <net/inet_connection_sock.h>
  25. #include "core.h"
  26. #include "nl80211.h"
  27. #include "reg.h"
  28. #include "rdev-ops.h"
  29. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  30. struct genl_info *info,
  31. struct cfg80211_crypto_settings *settings,
  32. int cipher_limit);
  33. static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
  34. struct genl_info *info);
  35. static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
  36. struct genl_info *info);
  37. /* the netlink family */
  38. static struct genl_family nl80211_fam = {
  39. .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
  40. .name = NL80211_GENL_NAME, /* have users key off the name instead */
  41. .hdrsize = 0, /* no private header */
  42. .version = 1, /* no particular meaning now */
  43. .maxattr = NL80211_ATTR_MAX,
  44. .netnsok = true,
  45. .pre_doit = nl80211_pre_doit,
  46. .post_doit = nl80211_post_doit,
  47. };
  48. /* multicast groups */
  49. enum nl80211_multicast_groups {
  50. NL80211_MCGRP_CONFIG,
  51. NL80211_MCGRP_SCAN,
  52. NL80211_MCGRP_REGULATORY,
  53. NL80211_MCGRP_MLME,
  54. NL80211_MCGRP_VENDOR,
  55. NL80211_MCGRP_NAN,
  56. NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
  57. };
  58. static const struct genl_multicast_group nl80211_mcgrps[] = {
  59. [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
  60. [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
  61. [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
  62. [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
  63. [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
  64. [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
  65. #ifdef CONFIG_NL80211_TESTMODE
  66. [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
  67. #endif
  68. };
  69. /* returns ERR_PTR values */
  70. static struct wireless_dev *
  71. __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
  72. {
  73. struct cfg80211_registered_device *rdev;
  74. struct wireless_dev *result = NULL;
  75. bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
  76. bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
  77. u64 wdev_id;
  78. int wiphy_idx = -1;
  79. int ifidx = -1;
  80. ASSERT_RTNL();
  81. if (!have_ifidx && !have_wdev_id)
  82. return ERR_PTR(-EINVAL);
  83. if (have_ifidx)
  84. ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
  85. if (have_wdev_id) {
  86. wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
  87. wiphy_idx = wdev_id >> 32;
  88. }
  89. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  90. struct wireless_dev *wdev;
  91. if (wiphy_net(&rdev->wiphy) != netns)
  92. continue;
  93. if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
  94. continue;
  95. list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
  96. if (have_ifidx && wdev->netdev &&
  97. wdev->netdev->ifindex == ifidx) {
  98. result = wdev;
  99. break;
  100. }
  101. if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
  102. result = wdev;
  103. break;
  104. }
  105. }
  106. if (result)
  107. break;
  108. }
  109. if (result)
  110. return result;
  111. return ERR_PTR(-ENODEV);
  112. }
  113. static struct cfg80211_registered_device *
  114. __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
  115. {
  116. struct cfg80211_registered_device *rdev = NULL, *tmp;
  117. struct net_device *netdev;
  118. ASSERT_RTNL();
  119. if (!attrs[NL80211_ATTR_WIPHY] &&
  120. !attrs[NL80211_ATTR_IFINDEX] &&
  121. !attrs[NL80211_ATTR_WDEV])
  122. return ERR_PTR(-EINVAL);
  123. if (attrs[NL80211_ATTR_WIPHY])
  124. rdev = cfg80211_rdev_by_wiphy_idx(
  125. nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
  126. if (attrs[NL80211_ATTR_WDEV]) {
  127. u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
  128. struct wireless_dev *wdev;
  129. bool found = false;
  130. tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
  131. if (tmp) {
  132. /* make sure wdev exists */
  133. list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
  134. if (wdev->identifier != (u32)wdev_id)
  135. continue;
  136. found = true;
  137. break;
  138. }
  139. if (!found)
  140. tmp = NULL;
  141. if (rdev && tmp != rdev)
  142. return ERR_PTR(-EINVAL);
  143. rdev = tmp;
  144. }
  145. }
  146. if (attrs[NL80211_ATTR_IFINDEX]) {
  147. int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
  148. netdev = __dev_get_by_index(netns, ifindex);
  149. if (netdev) {
  150. if (netdev->ieee80211_ptr)
  151. tmp = wiphy_to_rdev(
  152. netdev->ieee80211_ptr->wiphy);
  153. else
  154. tmp = NULL;
  155. /* not wireless device -- return error */
  156. if (!tmp)
  157. return ERR_PTR(-EINVAL);
  158. /* mismatch -- return error */
  159. if (rdev && tmp != rdev)
  160. return ERR_PTR(-EINVAL);
  161. rdev = tmp;
  162. }
  163. }
  164. if (!rdev)
  165. return ERR_PTR(-ENODEV);
  166. if (netns != wiphy_net(&rdev->wiphy))
  167. return ERR_PTR(-ENODEV);
  168. return rdev;
  169. }
  170. /*
  171. * This function returns a pointer to the driver
  172. * that the genl_info item that is passed refers to.
  173. *
  174. * The result of this can be a PTR_ERR and hence must
  175. * be checked with IS_ERR() for errors.
  176. */
  177. static struct cfg80211_registered_device *
  178. cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
  179. {
  180. return __cfg80211_rdev_from_attrs(netns, info->attrs);
  181. }
  182. /* policy for the attributes */
  183. static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
  184. [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
  185. [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
  186. .len = 20-1 },
  187. [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
  188. [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
  189. [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
  190. [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
  191. [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
  192. [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
  193. [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
  194. [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
  195. [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
  196. [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
  197. [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
  198. [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
  199. [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
  200. [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
  201. [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
  202. [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
  203. [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
  204. [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
  205. [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
  206. .len = WLAN_MAX_KEY_LEN },
  207. [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
  208. [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
  209. [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
  210. [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  211. [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
  212. [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
  213. [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
  214. [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
  215. .len = IEEE80211_MAX_DATA_LEN },
  216. [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
  217. .len = IEEE80211_MAX_DATA_LEN },
  218. [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
  219. [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
  220. [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
  221. [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
  222. .len = NL80211_MAX_SUPP_RATES },
  223. [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
  224. [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
  225. [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
  226. [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
  227. .len = IEEE80211_MAX_MESH_ID_LEN },
  228. [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
  229. [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
  230. [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
  231. [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
  232. [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
  233. [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
  234. [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
  235. .len = NL80211_MAX_SUPP_RATES },
  236. [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
  237. [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
  238. [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
  239. [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
  240. [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
  241. [NL80211_ATTR_IE] = { .type = NLA_BINARY,
  242. .len = IEEE80211_MAX_DATA_LEN },
  243. [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
  244. [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
  245. [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
  246. .len = IEEE80211_MAX_SSID_LEN },
  247. [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
  248. [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
  249. [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
  250. [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
  251. [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
  252. [NL80211_ATTR_STA_FLAGS2] = {
  253. .len = sizeof(struct nl80211_sta_flag_update),
  254. },
  255. [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
  256. [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
  257. [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
  258. [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
  259. [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
  260. [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
  261. [NL80211_ATTR_PID] = { .type = NLA_U32 },
  262. [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
  263. [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
  264. [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
  265. [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
  266. [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
  267. [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
  268. .len = IEEE80211_MAX_DATA_LEN },
  269. [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
  270. [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
  271. [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
  272. [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
  273. [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
  274. [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
  275. [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
  276. [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
  277. [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
  278. [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
  279. [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
  280. [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
  281. [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  282. [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
  283. [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
  284. [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
  285. [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
  286. [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
  287. [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
  288. [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
  289. .len = IEEE80211_MAX_DATA_LEN },
  290. [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
  291. .len = IEEE80211_MAX_DATA_LEN },
  292. [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
  293. [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
  294. [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
  295. [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
  296. [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
  297. [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
  298. [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
  299. [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
  300. [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
  301. [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
  302. [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
  303. .len = IEEE80211_MAX_DATA_LEN },
  304. [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
  305. [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
  306. [NL80211_ATTR_HT_CAPABILITY_MASK] = {
  307. .len = NL80211_HT_CAPABILITY_LEN
  308. },
  309. [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
  310. [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
  311. [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
  312. [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
  313. [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
  314. [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
  315. [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
  316. [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
  317. [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
  318. [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
  319. [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
  320. [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
  321. [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
  322. [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
  323. [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
  324. [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
  325. [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
  326. [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
  327. .len = NL80211_VHT_CAPABILITY_LEN,
  328. },
  329. [NL80211_ATTR_MDID] = { .type = NLA_U16 },
  330. [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
  331. .len = IEEE80211_MAX_DATA_LEN },
  332. [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
  333. [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
  334. [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
  335. [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
  336. [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
  337. [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
  338. [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
  339. [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
  340. [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
  341. [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
  342. [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
  343. [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
  344. [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
  345. [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
  346. .len = IEEE80211_QOS_MAP_LEN_MAX },
  347. [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
  348. [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
  349. [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
  350. [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
  351. [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
  352. [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
  353. [NL80211_ATTR_TSID] = { .type = NLA_U8 },
  354. [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
  355. [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
  356. [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
  357. [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
  358. [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
  359. [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
  360. [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
  361. [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
  362. [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
  363. [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
  364. [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
  365. [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
  366. .len = VHT_MUMIMO_GROUPS_DATA_LEN
  367. },
  368. [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
  369. [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
  370. [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
  371. [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
  372. [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
  373. };
  374. /* policy for the key attributes */
  375. static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
  376. [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
  377. [NL80211_KEY_IDX] = { .type = NLA_U8 },
  378. [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
  379. [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  380. [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
  381. [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
  382. [NL80211_KEY_TYPE] = { .type = NLA_U32 },
  383. [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  384. };
  385. /* policy for the key default flags */
  386. static const struct nla_policy
  387. nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
  388. [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
  389. [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
  390. };
  391. /* policy for WoWLAN attributes */
  392. static const struct nla_policy
  393. nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
  394. [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
  395. [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
  396. [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
  397. [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
  398. [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
  399. [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
  400. [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
  401. [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
  402. [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
  403. [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
  404. };
  405. static const struct nla_policy
  406. nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
  407. [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
  408. [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
  409. [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
  410. [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
  411. [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
  412. [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
  413. [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
  414. .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
  415. },
  416. [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
  417. .len = sizeof(struct nl80211_wowlan_tcp_data_token)
  418. },
  419. [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
  420. [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
  421. [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
  422. };
  423. /* policy for coalesce rule attributes */
  424. static const struct nla_policy
  425. nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
  426. [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
  427. [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
  428. [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
  429. };
  430. /* policy for GTK rekey offload attributes */
  431. static const struct nla_policy
  432. nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
  433. [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
  434. [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
  435. [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
  436. };
  437. static const struct nla_policy
  438. nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
  439. [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
  440. .len = IEEE80211_MAX_SSID_LEN },
  441. [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
  442. };
  443. static const struct nla_policy
  444. nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
  445. [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
  446. [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
  447. };
  448. static const struct nla_policy
  449. nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
  450. [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
  451. [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
  452. [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
  453. .len = sizeof(struct nl80211_bss_select_rssi_adjust)
  454. },
  455. };
  456. /* policy for NAN function attributes */
  457. static const struct nla_policy
  458. nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
  459. [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
  460. [NL80211_NAN_FUNC_SERVICE_ID] = {
  461. .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
  462. [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
  463. [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
  464. [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
  465. [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
  466. [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
  467. [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
  468. [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
  469. [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
  470. [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
  471. .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
  472. [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
  473. [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
  474. [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
  475. [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
  476. [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
  477. };
  478. /* policy for Service Response Filter attributes */
  479. static const struct nla_policy
  480. nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
  481. [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
  482. [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
  483. .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
  484. [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
  485. [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
  486. };
  487. /* policy for packet pattern attributes */
  488. static const struct nla_policy
  489. nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
  490. [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
  491. [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
  492. [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
  493. };
  494. static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
  495. struct netlink_callback *cb,
  496. struct cfg80211_registered_device **rdev,
  497. struct wireless_dev **wdev)
  498. {
  499. int err;
  500. if (!cb->args[0]) {
  501. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  502. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  503. nl80211_policy);
  504. if (err)
  505. return err;
  506. *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
  507. nl80211_fam.attrbuf);
  508. if (IS_ERR(*wdev))
  509. return PTR_ERR(*wdev);
  510. *rdev = wiphy_to_rdev((*wdev)->wiphy);
  511. /* 0 is the first index - add 1 to parse only once */
  512. cb->args[0] = (*rdev)->wiphy_idx + 1;
  513. cb->args[1] = (*wdev)->identifier;
  514. } else {
  515. /* subtract the 1 again here */
  516. struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
  517. struct wireless_dev *tmp;
  518. if (!wiphy)
  519. return -ENODEV;
  520. *rdev = wiphy_to_rdev(wiphy);
  521. *wdev = NULL;
  522. list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
  523. if (tmp->identifier == cb->args[1]) {
  524. *wdev = tmp;
  525. break;
  526. }
  527. }
  528. if (!*wdev)
  529. return -ENODEV;
  530. }
  531. return 0;
  532. }
  533. /* IE validation */
  534. static bool is_valid_ie_attr(const struct nlattr *attr)
  535. {
  536. const u8 *pos;
  537. int len;
  538. if (!attr)
  539. return true;
  540. pos = nla_data(attr);
  541. len = nla_len(attr);
  542. while (len) {
  543. u8 elemlen;
  544. if (len < 2)
  545. return false;
  546. len -= 2;
  547. elemlen = pos[1];
  548. if (elemlen > len)
  549. return false;
  550. len -= elemlen;
  551. pos += 2 + elemlen;
  552. }
  553. return true;
  554. }
  555. /* message building helper */
  556. static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
  557. int flags, u8 cmd)
  558. {
  559. /* since there is no private header just add the generic one */
  560. return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
  561. }
  562. static int nl80211_msg_put_channel(struct sk_buff *msg,
  563. struct ieee80211_channel *chan,
  564. bool large)
  565. {
  566. /* Some channels must be completely excluded from the
  567. * list to protect old user-space tools from breaking
  568. */
  569. if (!large && chan->flags &
  570. (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
  571. return 0;
  572. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
  573. chan->center_freq))
  574. goto nla_put_failure;
  575. if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
  576. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
  577. goto nla_put_failure;
  578. if (chan->flags & IEEE80211_CHAN_NO_IR) {
  579. if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
  580. goto nla_put_failure;
  581. if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
  582. goto nla_put_failure;
  583. }
  584. if (chan->flags & IEEE80211_CHAN_RADAR) {
  585. if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
  586. goto nla_put_failure;
  587. if (large) {
  588. u32 time;
  589. time = elapsed_jiffies_msecs(chan->dfs_state_entered);
  590. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
  591. chan->dfs_state))
  592. goto nla_put_failure;
  593. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
  594. time))
  595. goto nla_put_failure;
  596. if (nla_put_u32(msg,
  597. NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
  598. chan->dfs_cac_ms))
  599. goto nla_put_failure;
  600. }
  601. }
  602. if (large) {
  603. if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
  604. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
  605. goto nla_put_failure;
  606. if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
  607. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
  608. goto nla_put_failure;
  609. if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
  610. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
  611. goto nla_put_failure;
  612. if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
  613. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
  614. goto nla_put_failure;
  615. if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
  616. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
  617. goto nla_put_failure;
  618. if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
  619. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
  620. goto nla_put_failure;
  621. if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
  622. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
  623. goto nla_put_failure;
  624. if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
  625. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
  626. goto nla_put_failure;
  627. }
  628. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
  629. DBM_TO_MBM(chan->max_power)))
  630. goto nla_put_failure;
  631. return 0;
  632. nla_put_failure:
  633. return -ENOBUFS;
  634. }
  635. /* netlink command implementations */
  636. struct key_parse {
  637. struct key_params p;
  638. int idx;
  639. int type;
  640. bool def, defmgmt;
  641. bool def_uni, def_multi;
  642. };
  643. static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
  644. {
  645. struct nlattr *tb[NL80211_KEY_MAX + 1];
  646. int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
  647. nl80211_key_policy);
  648. if (err)
  649. return err;
  650. k->def = !!tb[NL80211_KEY_DEFAULT];
  651. k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
  652. if (k->def) {
  653. k->def_uni = true;
  654. k->def_multi = true;
  655. }
  656. if (k->defmgmt)
  657. k->def_multi = true;
  658. if (tb[NL80211_KEY_IDX])
  659. k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
  660. if (tb[NL80211_KEY_DATA]) {
  661. k->p.key = nla_data(tb[NL80211_KEY_DATA]);
  662. k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
  663. }
  664. if (tb[NL80211_KEY_SEQ]) {
  665. k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
  666. k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
  667. }
  668. if (tb[NL80211_KEY_CIPHER])
  669. k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
  670. if (tb[NL80211_KEY_TYPE]) {
  671. k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
  672. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  673. return -EINVAL;
  674. }
  675. if (tb[NL80211_KEY_DEFAULT_TYPES]) {
  676. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  677. err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  678. tb[NL80211_KEY_DEFAULT_TYPES],
  679. nl80211_key_default_policy);
  680. if (err)
  681. return err;
  682. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  683. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  684. }
  685. return 0;
  686. }
  687. static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
  688. {
  689. if (info->attrs[NL80211_ATTR_KEY_DATA]) {
  690. k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
  691. k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
  692. }
  693. if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
  694. k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
  695. k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
  696. }
  697. if (info->attrs[NL80211_ATTR_KEY_IDX])
  698. k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  699. if (info->attrs[NL80211_ATTR_KEY_CIPHER])
  700. k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
  701. k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
  702. k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
  703. if (k->def) {
  704. k->def_uni = true;
  705. k->def_multi = true;
  706. }
  707. if (k->defmgmt)
  708. k->def_multi = true;
  709. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  710. k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  711. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  712. return -EINVAL;
  713. }
  714. if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
  715. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  716. int err = nla_parse_nested(
  717. kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  718. info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
  719. nl80211_key_default_policy);
  720. if (err)
  721. return err;
  722. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  723. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  724. }
  725. return 0;
  726. }
  727. static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
  728. {
  729. int err;
  730. memset(k, 0, sizeof(*k));
  731. k->idx = -1;
  732. k->type = -1;
  733. if (info->attrs[NL80211_ATTR_KEY])
  734. err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
  735. else
  736. err = nl80211_parse_key_old(info, k);
  737. if (err)
  738. return err;
  739. if (k->def && k->defmgmt)
  740. return -EINVAL;
  741. if (k->defmgmt) {
  742. if (k->def_uni || !k->def_multi)
  743. return -EINVAL;
  744. }
  745. if (k->idx != -1) {
  746. if (k->defmgmt) {
  747. if (k->idx < 4 || k->idx > 5)
  748. return -EINVAL;
  749. } else if (k->def) {
  750. if (k->idx < 0 || k->idx > 3)
  751. return -EINVAL;
  752. } else {
  753. if (k->idx < 0 || k->idx > 5)
  754. return -EINVAL;
  755. }
  756. }
  757. return 0;
  758. }
  759. static struct cfg80211_cached_keys *
  760. nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
  761. struct nlattr *keys, bool *no_ht)
  762. {
  763. struct key_parse parse;
  764. struct nlattr *key;
  765. struct cfg80211_cached_keys *result;
  766. int rem, err, def = 0;
  767. bool have_key = false;
  768. nla_for_each_nested(key, keys, rem) {
  769. have_key = true;
  770. break;
  771. }
  772. if (!have_key)
  773. return NULL;
  774. result = kzalloc(sizeof(*result), GFP_KERNEL);
  775. if (!result)
  776. return ERR_PTR(-ENOMEM);
  777. result->def = -1;
  778. nla_for_each_nested(key, keys, rem) {
  779. memset(&parse, 0, sizeof(parse));
  780. parse.idx = -1;
  781. err = nl80211_parse_key_new(key, &parse);
  782. if (err)
  783. goto error;
  784. err = -EINVAL;
  785. if (!parse.p.key)
  786. goto error;
  787. if (parse.idx < 0 || parse.idx > 3)
  788. goto error;
  789. if (parse.def) {
  790. if (def)
  791. goto error;
  792. def = 1;
  793. result->def = parse.idx;
  794. if (!parse.def_uni || !parse.def_multi)
  795. goto error;
  796. } else if (parse.defmgmt)
  797. goto error;
  798. err = cfg80211_validate_key_settings(rdev, &parse.p,
  799. parse.idx, false, NULL);
  800. if (err)
  801. goto error;
  802. if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  803. parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
  804. err = -EINVAL;
  805. goto error;
  806. }
  807. result->params[parse.idx].cipher = parse.p.cipher;
  808. result->params[parse.idx].key_len = parse.p.key_len;
  809. result->params[parse.idx].key = result->data[parse.idx];
  810. memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
  811. /* must be WEP key if we got here */
  812. if (no_ht)
  813. *no_ht = true;
  814. }
  815. if (result->def < 0) {
  816. err = -EINVAL;
  817. goto error;
  818. }
  819. return result;
  820. error:
  821. kfree(result);
  822. return ERR_PTR(err);
  823. }
  824. static int nl80211_key_allowed(struct wireless_dev *wdev)
  825. {
  826. ASSERT_WDEV_LOCK(wdev);
  827. switch (wdev->iftype) {
  828. case NL80211_IFTYPE_AP:
  829. case NL80211_IFTYPE_AP_VLAN:
  830. case NL80211_IFTYPE_P2P_GO:
  831. case NL80211_IFTYPE_MESH_POINT:
  832. break;
  833. case NL80211_IFTYPE_ADHOC:
  834. case NL80211_IFTYPE_STATION:
  835. case NL80211_IFTYPE_P2P_CLIENT:
  836. if (!wdev->current_bss)
  837. return -ENOLINK;
  838. break;
  839. case NL80211_IFTYPE_UNSPECIFIED:
  840. case NL80211_IFTYPE_OCB:
  841. case NL80211_IFTYPE_MONITOR:
  842. case NL80211_IFTYPE_NAN:
  843. case NL80211_IFTYPE_P2P_DEVICE:
  844. case NL80211_IFTYPE_WDS:
  845. case NUM_NL80211_IFTYPES:
  846. return -EINVAL;
  847. }
  848. return 0;
  849. }
  850. static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
  851. struct nlattr *tb)
  852. {
  853. struct ieee80211_channel *chan;
  854. if (tb == NULL)
  855. return NULL;
  856. chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
  857. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  858. return NULL;
  859. return chan;
  860. }
  861. static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
  862. {
  863. struct nlattr *nl_modes = nla_nest_start(msg, attr);
  864. int i;
  865. if (!nl_modes)
  866. goto nla_put_failure;
  867. i = 0;
  868. while (ifmodes) {
  869. if ((ifmodes & 1) && nla_put_flag(msg, i))
  870. goto nla_put_failure;
  871. ifmodes >>= 1;
  872. i++;
  873. }
  874. nla_nest_end(msg, nl_modes);
  875. return 0;
  876. nla_put_failure:
  877. return -ENOBUFS;
  878. }
  879. static int nl80211_put_iface_combinations(struct wiphy *wiphy,
  880. struct sk_buff *msg,
  881. bool large)
  882. {
  883. struct nlattr *nl_combis;
  884. int i, j;
  885. nl_combis = nla_nest_start(msg,
  886. NL80211_ATTR_INTERFACE_COMBINATIONS);
  887. if (!nl_combis)
  888. goto nla_put_failure;
  889. for (i = 0; i < wiphy->n_iface_combinations; i++) {
  890. const struct ieee80211_iface_combination *c;
  891. struct nlattr *nl_combi, *nl_limits;
  892. c = &wiphy->iface_combinations[i];
  893. nl_combi = nla_nest_start(msg, i + 1);
  894. if (!nl_combi)
  895. goto nla_put_failure;
  896. nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
  897. if (!nl_limits)
  898. goto nla_put_failure;
  899. for (j = 0; j < c->n_limits; j++) {
  900. struct nlattr *nl_limit;
  901. nl_limit = nla_nest_start(msg, j + 1);
  902. if (!nl_limit)
  903. goto nla_put_failure;
  904. if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
  905. c->limits[j].max))
  906. goto nla_put_failure;
  907. if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
  908. c->limits[j].types))
  909. goto nla_put_failure;
  910. nla_nest_end(msg, nl_limit);
  911. }
  912. nla_nest_end(msg, nl_limits);
  913. if (c->beacon_int_infra_match &&
  914. nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
  915. goto nla_put_failure;
  916. if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
  917. c->num_different_channels) ||
  918. nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
  919. c->max_interfaces))
  920. goto nla_put_failure;
  921. if (large &&
  922. (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
  923. c->radar_detect_widths) ||
  924. nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
  925. c->radar_detect_regions)))
  926. goto nla_put_failure;
  927. nla_nest_end(msg, nl_combi);
  928. }
  929. nla_nest_end(msg, nl_combis);
  930. return 0;
  931. nla_put_failure:
  932. return -ENOBUFS;
  933. }
  934. #ifdef CONFIG_PM
  935. static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
  936. struct sk_buff *msg)
  937. {
  938. const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
  939. struct nlattr *nl_tcp;
  940. if (!tcp)
  941. return 0;
  942. nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
  943. if (!nl_tcp)
  944. return -ENOBUFS;
  945. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  946. tcp->data_payload_max))
  947. return -ENOBUFS;
  948. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  949. tcp->data_payload_max))
  950. return -ENOBUFS;
  951. if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
  952. return -ENOBUFS;
  953. if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  954. sizeof(*tcp->tok), tcp->tok))
  955. return -ENOBUFS;
  956. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
  957. tcp->data_interval_max))
  958. return -ENOBUFS;
  959. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  960. tcp->wake_payload_max))
  961. return -ENOBUFS;
  962. nla_nest_end(msg, nl_tcp);
  963. return 0;
  964. }
  965. static int nl80211_send_wowlan(struct sk_buff *msg,
  966. struct cfg80211_registered_device *rdev,
  967. bool large)
  968. {
  969. struct nlattr *nl_wowlan;
  970. if (!rdev->wiphy.wowlan)
  971. return 0;
  972. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
  973. if (!nl_wowlan)
  974. return -ENOBUFS;
  975. if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
  976. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  977. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
  978. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  979. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
  980. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  981. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
  982. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
  983. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
  984. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  985. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
  986. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  987. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
  988. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  989. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
  990. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
  991. return -ENOBUFS;
  992. if (rdev->wiphy.wowlan->n_patterns) {
  993. struct nl80211_pattern_support pat = {
  994. .max_patterns = rdev->wiphy.wowlan->n_patterns,
  995. .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
  996. .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
  997. .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
  998. };
  999. if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  1000. sizeof(pat), &pat))
  1001. return -ENOBUFS;
  1002. }
  1003. if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
  1004. nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
  1005. rdev->wiphy.wowlan->max_nd_match_sets))
  1006. return -ENOBUFS;
  1007. if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
  1008. return -ENOBUFS;
  1009. nla_nest_end(msg, nl_wowlan);
  1010. return 0;
  1011. }
  1012. #endif
  1013. static int nl80211_send_coalesce(struct sk_buff *msg,
  1014. struct cfg80211_registered_device *rdev)
  1015. {
  1016. struct nl80211_coalesce_rule_support rule;
  1017. if (!rdev->wiphy.coalesce)
  1018. return 0;
  1019. rule.max_rules = rdev->wiphy.coalesce->n_rules;
  1020. rule.max_delay = rdev->wiphy.coalesce->max_delay;
  1021. rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
  1022. rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
  1023. rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
  1024. rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
  1025. if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
  1026. return -ENOBUFS;
  1027. return 0;
  1028. }
  1029. static int nl80211_send_band_rateinfo(struct sk_buff *msg,
  1030. struct ieee80211_supported_band *sband)
  1031. {
  1032. struct nlattr *nl_rates, *nl_rate;
  1033. struct ieee80211_rate *rate;
  1034. int i;
  1035. /* add HT info */
  1036. if (sband->ht_cap.ht_supported &&
  1037. (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
  1038. sizeof(sband->ht_cap.mcs),
  1039. &sband->ht_cap.mcs) ||
  1040. nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
  1041. sband->ht_cap.cap) ||
  1042. nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
  1043. sband->ht_cap.ampdu_factor) ||
  1044. nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
  1045. sband->ht_cap.ampdu_density)))
  1046. return -ENOBUFS;
  1047. /* add VHT info */
  1048. if (sband->vht_cap.vht_supported &&
  1049. (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
  1050. sizeof(sband->vht_cap.vht_mcs),
  1051. &sband->vht_cap.vht_mcs) ||
  1052. nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
  1053. sband->vht_cap.cap)))
  1054. return -ENOBUFS;
  1055. /* add bitrates */
  1056. nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
  1057. if (!nl_rates)
  1058. return -ENOBUFS;
  1059. for (i = 0; i < sband->n_bitrates; i++) {
  1060. nl_rate = nla_nest_start(msg, i);
  1061. if (!nl_rate)
  1062. return -ENOBUFS;
  1063. rate = &sband->bitrates[i];
  1064. if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
  1065. rate->bitrate))
  1066. return -ENOBUFS;
  1067. if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
  1068. nla_put_flag(msg,
  1069. NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
  1070. return -ENOBUFS;
  1071. nla_nest_end(msg, nl_rate);
  1072. }
  1073. nla_nest_end(msg, nl_rates);
  1074. return 0;
  1075. }
  1076. static int
  1077. nl80211_send_mgmt_stypes(struct sk_buff *msg,
  1078. const struct ieee80211_txrx_stypes *mgmt_stypes)
  1079. {
  1080. u16 stypes;
  1081. struct nlattr *nl_ftypes, *nl_ifs;
  1082. enum nl80211_iftype ift;
  1083. int i;
  1084. if (!mgmt_stypes)
  1085. return 0;
  1086. nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
  1087. if (!nl_ifs)
  1088. return -ENOBUFS;
  1089. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  1090. nl_ftypes = nla_nest_start(msg, ift);
  1091. if (!nl_ftypes)
  1092. return -ENOBUFS;
  1093. i = 0;
  1094. stypes = mgmt_stypes[ift].tx;
  1095. while (stypes) {
  1096. if ((stypes & 1) &&
  1097. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
  1098. (i << 4) | IEEE80211_FTYPE_MGMT))
  1099. return -ENOBUFS;
  1100. stypes >>= 1;
  1101. i++;
  1102. }
  1103. nla_nest_end(msg, nl_ftypes);
  1104. }
  1105. nla_nest_end(msg, nl_ifs);
  1106. nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
  1107. if (!nl_ifs)
  1108. return -ENOBUFS;
  1109. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  1110. nl_ftypes = nla_nest_start(msg, ift);
  1111. if (!nl_ftypes)
  1112. return -ENOBUFS;
  1113. i = 0;
  1114. stypes = mgmt_stypes[ift].rx;
  1115. while (stypes) {
  1116. if ((stypes & 1) &&
  1117. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
  1118. (i << 4) | IEEE80211_FTYPE_MGMT))
  1119. return -ENOBUFS;
  1120. stypes >>= 1;
  1121. i++;
  1122. }
  1123. nla_nest_end(msg, nl_ftypes);
  1124. }
  1125. nla_nest_end(msg, nl_ifs);
  1126. return 0;
  1127. }
  1128. struct nl80211_dump_wiphy_state {
  1129. s64 filter_wiphy;
  1130. long start;
  1131. long split_start, band_start, chan_start, capa_start;
  1132. bool split;
  1133. };
  1134. static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
  1135. enum nl80211_commands cmd,
  1136. struct sk_buff *msg, u32 portid, u32 seq,
  1137. int flags, struct nl80211_dump_wiphy_state *state)
  1138. {
  1139. void *hdr;
  1140. struct nlattr *nl_bands, *nl_band;
  1141. struct nlattr *nl_freqs, *nl_freq;
  1142. struct nlattr *nl_cmds;
  1143. enum nl80211_band band;
  1144. struct ieee80211_channel *chan;
  1145. int i;
  1146. const struct ieee80211_txrx_stypes *mgmt_stypes =
  1147. rdev->wiphy.mgmt_stypes;
  1148. u32 features;
  1149. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  1150. if (!hdr)
  1151. return -ENOBUFS;
  1152. if (WARN_ON(!state))
  1153. return -EINVAL;
  1154. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  1155. nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
  1156. wiphy_name(&rdev->wiphy)) ||
  1157. nla_put_u32(msg, NL80211_ATTR_GENERATION,
  1158. cfg80211_rdev_list_generation))
  1159. goto nla_put_failure;
  1160. if (cmd != NL80211_CMD_NEW_WIPHY)
  1161. goto finish;
  1162. switch (state->split_start) {
  1163. case 0:
  1164. if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
  1165. rdev->wiphy.retry_short) ||
  1166. nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
  1167. rdev->wiphy.retry_long) ||
  1168. nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
  1169. rdev->wiphy.frag_threshold) ||
  1170. nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
  1171. rdev->wiphy.rts_threshold) ||
  1172. nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
  1173. rdev->wiphy.coverage_class) ||
  1174. nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
  1175. rdev->wiphy.max_scan_ssids) ||
  1176. nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
  1177. rdev->wiphy.max_sched_scan_ssids) ||
  1178. nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
  1179. rdev->wiphy.max_scan_ie_len) ||
  1180. nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
  1181. rdev->wiphy.max_sched_scan_ie_len) ||
  1182. nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
  1183. rdev->wiphy.max_match_sets) ||
  1184. nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
  1185. rdev->wiphy.max_sched_scan_plans) ||
  1186. nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
  1187. rdev->wiphy.max_sched_scan_plan_interval) ||
  1188. nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
  1189. rdev->wiphy.max_sched_scan_plan_iterations))
  1190. goto nla_put_failure;
  1191. if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
  1192. nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
  1193. goto nla_put_failure;
  1194. if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
  1195. nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
  1196. goto nla_put_failure;
  1197. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
  1198. nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
  1199. goto nla_put_failure;
  1200. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
  1201. nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
  1202. goto nla_put_failure;
  1203. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  1204. nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
  1205. goto nla_put_failure;
  1206. if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
  1207. nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
  1208. goto nla_put_failure;
  1209. state->split_start++;
  1210. if (state->split)
  1211. break;
  1212. case 1:
  1213. if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
  1214. sizeof(u32) * rdev->wiphy.n_cipher_suites,
  1215. rdev->wiphy.cipher_suites))
  1216. goto nla_put_failure;
  1217. if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
  1218. rdev->wiphy.max_num_pmkids))
  1219. goto nla_put_failure;
  1220. if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  1221. nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
  1222. goto nla_put_failure;
  1223. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
  1224. rdev->wiphy.available_antennas_tx) ||
  1225. nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
  1226. rdev->wiphy.available_antennas_rx))
  1227. goto nla_put_failure;
  1228. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
  1229. nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
  1230. rdev->wiphy.probe_resp_offload))
  1231. goto nla_put_failure;
  1232. if ((rdev->wiphy.available_antennas_tx ||
  1233. rdev->wiphy.available_antennas_rx) &&
  1234. rdev->ops->get_antenna) {
  1235. u32 tx_ant = 0, rx_ant = 0;
  1236. int res;
  1237. res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
  1238. if (!res) {
  1239. if (nla_put_u32(msg,
  1240. NL80211_ATTR_WIPHY_ANTENNA_TX,
  1241. tx_ant) ||
  1242. nla_put_u32(msg,
  1243. NL80211_ATTR_WIPHY_ANTENNA_RX,
  1244. rx_ant))
  1245. goto nla_put_failure;
  1246. }
  1247. }
  1248. state->split_start++;
  1249. if (state->split)
  1250. break;
  1251. case 2:
  1252. if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
  1253. rdev->wiphy.interface_modes))
  1254. goto nla_put_failure;
  1255. state->split_start++;
  1256. if (state->split)
  1257. break;
  1258. case 3:
  1259. nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
  1260. if (!nl_bands)
  1261. goto nla_put_failure;
  1262. for (band = state->band_start;
  1263. band < NUM_NL80211_BANDS; band++) {
  1264. struct ieee80211_supported_band *sband;
  1265. sband = rdev->wiphy.bands[band];
  1266. if (!sband)
  1267. continue;
  1268. nl_band = nla_nest_start(msg, band);
  1269. if (!nl_band)
  1270. goto nla_put_failure;
  1271. switch (state->chan_start) {
  1272. case 0:
  1273. if (nl80211_send_band_rateinfo(msg, sband))
  1274. goto nla_put_failure;
  1275. state->chan_start++;
  1276. if (state->split)
  1277. break;
  1278. default:
  1279. /* add frequencies */
  1280. nl_freqs = nla_nest_start(
  1281. msg, NL80211_BAND_ATTR_FREQS);
  1282. if (!nl_freqs)
  1283. goto nla_put_failure;
  1284. for (i = state->chan_start - 1;
  1285. i < sband->n_channels;
  1286. i++) {
  1287. nl_freq = nla_nest_start(msg, i);
  1288. if (!nl_freq)
  1289. goto nla_put_failure;
  1290. chan = &sband->channels[i];
  1291. if (nl80211_msg_put_channel(
  1292. msg, chan,
  1293. state->split))
  1294. goto nla_put_failure;
  1295. nla_nest_end(msg, nl_freq);
  1296. if (state->split)
  1297. break;
  1298. }
  1299. if (i < sband->n_channels)
  1300. state->chan_start = i + 2;
  1301. else
  1302. state->chan_start = 0;
  1303. nla_nest_end(msg, nl_freqs);
  1304. }
  1305. nla_nest_end(msg, nl_band);
  1306. if (state->split) {
  1307. /* start again here */
  1308. if (state->chan_start)
  1309. band--;
  1310. break;
  1311. }
  1312. }
  1313. nla_nest_end(msg, nl_bands);
  1314. if (band < NUM_NL80211_BANDS)
  1315. state->band_start = band + 1;
  1316. else
  1317. state->band_start = 0;
  1318. /* if bands & channels are done, continue outside */
  1319. if (state->band_start == 0 && state->chan_start == 0)
  1320. state->split_start++;
  1321. if (state->split)
  1322. break;
  1323. case 4:
  1324. nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
  1325. if (!nl_cmds)
  1326. goto nla_put_failure;
  1327. i = 0;
  1328. #define CMD(op, n) \
  1329. do { \
  1330. if (rdev->ops->op) { \
  1331. i++; \
  1332. if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
  1333. goto nla_put_failure; \
  1334. } \
  1335. } while (0)
  1336. CMD(add_virtual_intf, NEW_INTERFACE);
  1337. CMD(change_virtual_intf, SET_INTERFACE);
  1338. CMD(add_key, NEW_KEY);
  1339. CMD(start_ap, START_AP);
  1340. CMD(add_station, NEW_STATION);
  1341. CMD(add_mpath, NEW_MPATH);
  1342. CMD(update_mesh_config, SET_MESH_CONFIG);
  1343. CMD(change_bss, SET_BSS);
  1344. CMD(auth, AUTHENTICATE);
  1345. CMD(assoc, ASSOCIATE);
  1346. CMD(deauth, DEAUTHENTICATE);
  1347. CMD(disassoc, DISASSOCIATE);
  1348. CMD(join_ibss, JOIN_IBSS);
  1349. CMD(join_mesh, JOIN_MESH);
  1350. CMD(set_pmksa, SET_PMKSA);
  1351. CMD(del_pmksa, DEL_PMKSA);
  1352. CMD(flush_pmksa, FLUSH_PMKSA);
  1353. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
  1354. CMD(remain_on_channel, REMAIN_ON_CHANNEL);
  1355. CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
  1356. CMD(mgmt_tx, FRAME);
  1357. CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
  1358. if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
  1359. i++;
  1360. if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
  1361. goto nla_put_failure;
  1362. }
  1363. if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
  1364. rdev->ops->join_mesh) {
  1365. i++;
  1366. if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
  1367. goto nla_put_failure;
  1368. }
  1369. CMD(set_wds_peer, SET_WDS_PEER);
  1370. if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
  1371. CMD(tdls_mgmt, TDLS_MGMT);
  1372. CMD(tdls_oper, TDLS_OPER);
  1373. }
  1374. if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  1375. CMD(sched_scan_start, START_SCHED_SCAN);
  1376. CMD(probe_client, PROBE_CLIENT);
  1377. CMD(set_noack_map, SET_NOACK_MAP);
  1378. if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
  1379. i++;
  1380. if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
  1381. goto nla_put_failure;
  1382. }
  1383. CMD(start_p2p_device, START_P2P_DEVICE);
  1384. CMD(set_mcast_rate, SET_MCAST_RATE);
  1385. #ifdef CONFIG_NL80211_TESTMODE
  1386. CMD(testmode_cmd, TESTMODE);
  1387. #endif
  1388. if (state->split) {
  1389. CMD(crit_proto_start, CRIT_PROTOCOL_START);
  1390. CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
  1391. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
  1392. CMD(channel_switch, CHANNEL_SWITCH);
  1393. CMD(set_qos_map, SET_QOS_MAP);
  1394. if (rdev->wiphy.features &
  1395. NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
  1396. CMD(add_tx_ts, ADD_TX_TS);
  1397. }
  1398. /* add into the if now */
  1399. #undef CMD
  1400. if (rdev->ops->connect || rdev->ops->auth) {
  1401. i++;
  1402. if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
  1403. goto nla_put_failure;
  1404. }
  1405. if (rdev->ops->disconnect || rdev->ops->deauth) {
  1406. i++;
  1407. if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
  1408. goto nla_put_failure;
  1409. }
  1410. nla_nest_end(msg, nl_cmds);
  1411. state->split_start++;
  1412. if (state->split)
  1413. break;
  1414. case 5:
  1415. if (rdev->ops->remain_on_channel &&
  1416. (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
  1417. nla_put_u32(msg,
  1418. NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
  1419. rdev->wiphy.max_remain_on_channel_duration))
  1420. goto nla_put_failure;
  1421. if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
  1422. nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
  1423. goto nla_put_failure;
  1424. if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
  1425. goto nla_put_failure;
  1426. state->split_start++;
  1427. if (state->split)
  1428. break;
  1429. case 6:
  1430. #ifdef CONFIG_PM
  1431. if (nl80211_send_wowlan(msg, rdev, state->split))
  1432. goto nla_put_failure;
  1433. state->split_start++;
  1434. if (state->split)
  1435. break;
  1436. #else
  1437. state->split_start++;
  1438. #endif
  1439. case 7:
  1440. if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
  1441. rdev->wiphy.software_iftypes))
  1442. goto nla_put_failure;
  1443. if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
  1444. state->split))
  1445. goto nla_put_failure;
  1446. state->split_start++;
  1447. if (state->split)
  1448. break;
  1449. case 8:
  1450. if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
  1451. nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
  1452. rdev->wiphy.ap_sme_capa))
  1453. goto nla_put_failure;
  1454. features = rdev->wiphy.features;
  1455. /*
  1456. * We can only add the per-channel limit information if the
  1457. * dump is split, otherwise it makes it too big. Therefore
  1458. * only advertise it in that case.
  1459. */
  1460. if (state->split)
  1461. features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
  1462. if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
  1463. goto nla_put_failure;
  1464. if (rdev->wiphy.ht_capa_mod_mask &&
  1465. nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
  1466. sizeof(*rdev->wiphy.ht_capa_mod_mask),
  1467. rdev->wiphy.ht_capa_mod_mask))
  1468. goto nla_put_failure;
  1469. if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
  1470. rdev->wiphy.max_acl_mac_addrs &&
  1471. nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
  1472. rdev->wiphy.max_acl_mac_addrs))
  1473. goto nla_put_failure;
  1474. /*
  1475. * Any information below this point is only available to
  1476. * applications that can deal with it being split. This
  1477. * helps ensure that newly added capabilities don't break
  1478. * older tools by overrunning their buffers.
  1479. *
  1480. * We still increment split_start so that in the split
  1481. * case we'll continue with more data in the next round,
  1482. * but break unconditionally so unsplit data stops here.
  1483. */
  1484. state->split_start++;
  1485. break;
  1486. case 9:
  1487. if (rdev->wiphy.extended_capabilities &&
  1488. (nla_put(msg, NL80211_ATTR_EXT_CAPA,
  1489. rdev->wiphy.extended_capabilities_len,
  1490. rdev->wiphy.extended_capabilities) ||
  1491. nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
  1492. rdev->wiphy.extended_capabilities_len,
  1493. rdev->wiphy.extended_capabilities_mask)))
  1494. goto nla_put_failure;
  1495. if (rdev->wiphy.vht_capa_mod_mask &&
  1496. nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
  1497. sizeof(*rdev->wiphy.vht_capa_mod_mask),
  1498. rdev->wiphy.vht_capa_mod_mask))
  1499. goto nla_put_failure;
  1500. state->split_start++;
  1501. break;
  1502. case 10:
  1503. if (nl80211_send_coalesce(msg, rdev))
  1504. goto nla_put_failure;
  1505. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
  1506. (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
  1507. nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
  1508. goto nla_put_failure;
  1509. if (rdev->wiphy.max_ap_assoc_sta &&
  1510. nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
  1511. rdev->wiphy.max_ap_assoc_sta))
  1512. goto nla_put_failure;
  1513. state->split_start++;
  1514. break;
  1515. case 11:
  1516. if (rdev->wiphy.n_vendor_commands) {
  1517. const struct nl80211_vendor_cmd_info *info;
  1518. struct nlattr *nested;
  1519. nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
  1520. if (!nested)
  1521. goto nla_put_failure;
  1522. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  1523. info = &rdev->wiphy.vendor_commands[i].info;
  1524. if (nla_put(msg, i + 1, sizeof(*info), info))
  1525. goto nla_put_failure;
  1526. }
  1527. nla_nest_end(msg, nested);
  1528. }
  1529. if (rdev->wiphy.n_vendor_events) {
  1530. const struct nl80211_vendor_cmd_info *info;
  1531. struct nlattr *nested;
  1532. nested = nla_nest_start(msg,
  1533. NL80211_ATTR_VENDOR_EVENTS);
  1534. if (!nested)
  1535. goto nla_put_failure;
  1536. for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
  1537. info = &rdev->wiphy.vendor_events[i];
  1538. if (nla_put(msg, i + 1, sizeof(*info), info))
  1539. goto nla_put_failure;
  1540. }
  1541. nla_nest_end(msg, nested);
  1542. }
  1543. state->split_start++;
  1544. break;
  1545. case 12:
  1546. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
  1547. nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
  1548. rdev->wiphy.max_num_csa_counters))
  1549. goto nla_put_failure;
  1550. if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  1551. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  1552. goto nla_put_failure;
  1553. if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
  1554. sizeof(rdev->wiphy.ext_features),
  1555. rdev->wiphy.ext_features))
  1556. goto nla_put_failure;
  1557. if (rdev->wiphy.bss_select_support) {
  1558. struct nlattr *nested;
  1559. u32 bss_select_support = rdev->wiphy.bss_select_support;
  1560. nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
  1561. if (!nested)
  1562. goto nla_put_failure;
  1563. i = 0;
  1564. while (bss_select_support) {
  1565. if ((bss_select_support & 1) &&
  1566. nla_put_flag(msg, i))
  1567. goto nla_put_failure;
  1568. i++;
  1569. bss_select_support >>= 1;
  1570. }
  1571. nla_nest_end(msg, nested);
  1572. }
  1573. state->split_start++;
  1574. break;
  1575. case 13:
  1576. if (rdev->wiphy.num_iftype_ext_capab &&
  1577. rdev->wiphy.iftype_ext_capab) {
  1578. struct nlattr *nested_ext_capab, *nested;
  1579. nested = nla_nest_start(msg,
  1580. NL80211_ATTR_IFTYPE_EXT_CAPA);
  1581. if (!nested)
  1582. goto nla_put_failure;
  1583. for (i = state->capa_start;
  1584. i < rdev->wiphy.num_iftype_ext_capab; i++) {
  1585. const struct wiphy_iftype_ext_capab *capab;
  1586. capab = &rdev->wiphy.iftype_ext_capab[i];
  1587. nested_ext_capab = nla_nest_start(msg, i);
  1588. if (!nested_ext_capab ||
  1589. nla_put_u32(msg, NL80211_ATTR_IFTYPE,
  1590. capab->iftype) ||
  1591. nla_put(msg, NL80211_ATTR_EXT_CAPA,
  1592. capab->extended_capabilities_len,
  1593. capab->extended_capabilities) ||
  1594. nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
  1595. capab->extended_capabilities_len,
  1596. capab->extended_capabilities_mask))
  1597. goto nla_put_failure;
  1598. nla_nest_end(msg, nested_ext_capab);
  1599. if (state->split)
  1600. break;
  1601. }
  1602. nla_nest_end(msg, nested);
  1603. if (i < rdev->wiphy.num_iftype_ext_capab) {
  1604. state->capa_start = i + 1;
  1605. break;
  1606. }
  1607. }
  1608. /* done */
  1609. state->split_start = 0;
  1610. break;
  1611. }
  1612. finish:
  1613. genlmsg_end(msg, hdr);
  1614. return 0;
  1615. nla_put_failure:
  1616. genlmsg_cancel(msg, hdr);
  1617. return -EMSGSIZE;
  1618. }
  1619. static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
  1620. struct netlink_callback *cb,
  1621. struct nl80211_dump_wiphy_state *state)
  1622. {
  1623. struct nlattr **tb = nl80211_fam.attrbuf;
  1624. int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  1625. tb, nl80211_fam.maxattr, nl80211_policy);
  1626. /* ignore parse errors for backward compatibility */
  1627. if (ret)
  1628. return 0;
  1629. state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
  1630. if (tb[NL80211_ATTR_WIPHY])
  1631. state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
  1632. if (tb[NL80211_ATTR_WDEV])
  1633. state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
  1634. if (tb[NL80211_ATTR_IFINDEX]) {
  1635. struct net_device *netdev;
  1636. struct cfg80211_registered_device *rdev;
  1637. int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
  1638. netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
  1639. if (!netdev)
  1640. return -ENODEV;
  1641. if (netdev->ieee80211_ptr) {
  1642. rdev = wiphy_to_rdev(
  1643. netdev->ieee80211_ptr->wiphy);
  1644. state->filter_wiphy = rdev->wiphy_idx;
  1645. }
  1646. }
  1647. return 0;
  1648. }
  1649. static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
  1650. {
  1651. int idx = 0, ret;
  1652. struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
  1653. struct cfg80211_registered_device *rdev;
  1654. rtnl_lock();
  1655. if (!state) {
  1656. state = kzalloc(sizeof(*state), GFP_KERNEL);
  1657. if (!state) {
  1658. rtnl_unlock();
  1659. return -ENOMEM;
  1660. }
  1661. state->filter_wiphy = -1;
  1662. ret = nl80211_dump_wiphy_parse(skb, cb, state);
  1663. if (ret) {
  1664. kfree(state);
  1665. rtnl_unlock();
  1666. return ret;
  1667. }
  1668. cb->args[0] = (long)state;
  1669. }
  1670. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  1671. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  1672. continue;
  1673. if (++idx <= state->start)
  1674. continue;
  1675. if (state->filter_wiphy != -1 &&
  1676. state->filter_wiphy != rdev->wiphy_idx)
  1677. continue;
  1678. /* attempt to fit multiple wiphy data chunks into the skb */
  1679. do {
  1680. ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
  1681. skb,
  1682. NETLINK_CB(cb->skb).portid,
  1683. cb->nlh->nlmsg_seq,
  1684. NLM_F_MULTI, state);
  1685. if (ret < 0) {
  1686. /*
  1687. * If sending the wiphy data didn't fit (ENOBUFS
  1688. * or EMSGSIZE returned), this SKB is still
  1689. * empty (so it's not too big because another
  1690. * wiphy dataset is already in the skb) and
  1691. * we've not tried to adjust the dump allocation
  1692. * yet ... then adjust the alloc size to be
  1693. * bigger, and return 1 but with the empty skb.
  1694. * This results in an empty message being RX'ed
  1695. * in userspace, but that is ignored.
  1696. *
  1697. * We can then retry with the larger buffer.
  1698. */
  1699. if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
  1700. !skb->len && !state->split &&
  1701. cb->min_dump_alloc < 4096) {
  1702. cb->min_dump_alloc = 4096;
  1703. state->split_start = 0;
  1704. rtnl_unlock();
  1705. return 1;
  1706. }
  1707. idx--;
  1708. break;
  1709. }
  1710. } while (state->split_start > 0);
  1711. break;
  1712. }
  1713. rtnl_unlock();
  1714. state->start = idx;
  1715. return skb->len;
  1716. }
  1717. static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
  1718. {
  1719. kfree((void *)cb->args[0]);
  1720. return 0;
  1721. }
  1722. static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
  1723. {
  1724. struct sk_buff *msg;
  1725. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1726. struct nl80211_dump_wiphy_state state = {};
  1727. msg = nlmsg_new(4096, GFP_KERNEL);
  1728. if (!msg)
  1729. return -ENOMEM;
  1730. if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
  1731. info->snd_portid, info->snd_seq, 0,
  1732. &state) < 0) {
  1733. nlmsg_free(msg);
  1734. return -ENOBUFS;
  1735. }
  1736. return genlmsg_reply(msg, info);
  1737. }
  1738. static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
  1739. [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
  1740. [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
  1741. [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
  1742. [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
  1743. [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
  1744. };
  1745. static int parse_txq_params(struct nlattr *tb[],
  1746. struct ieee80211_txq_params *txq_params)
  1747. {
  1748. u8 ac;
  1749. if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
  1750. !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
  1751. !tb[NL80211_TXQ_ATTR_AIFS])
  1752. return -EINVAL;
  1753. ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
  1754. txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
  1755. txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
  1756. txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
  1757. txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
  1758. if (ac >= NL80211_NUM_ACS)
  1759. return -EINVAL;
  1760. txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
  1761. return 0;
  1762. }
  1763. static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
  1764. {
  1765. /*
  1766. * You can only set the channel explicitly for WDS interfaces,
  1767. * all others have their channel managed via their respective
  1768. * "establish a connection" command (connect, join, ...)
  1769. *
  1770. * For AP/GO and mesh mode, the channel can be set with the
  1771. * channel userspace API, but is only stored and passed to the
  1772. * low-level driver when the AP starts or the mesh is joined.
  1773. * This is for backward compatibility, userspace can also give
  1774. * the channel in the start-ap or join-mesh commands instead.
  1775. *
  1776. * Monitors are special as they are normally slaved to
  1777. * whatever else is going on, so they have their own special
  1778. * operation to set the monitor channel if possible.
  1779. */
  1780. return !wdev ||
  1781. wdev->iftype == NL80211_IFTYPE_AP ||
  1782. wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
  1783. wdev->iftype == NL80211_IFTYPE_MONITOR ||
  1784. wdev->iftype == NL80211_IFTYPE_P2P_GO;
  1785. }
  1786. static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
  1787. struct genl_info *info,
  1788. struct cfg80211_chan_def *chandef)
  1789. {
  1790. u32 control_freq;
  1791. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  1792. return -EINVAL;
  1793. control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  1794. chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
  1795. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  1796. chandef->center_freq1 = control_freq;
  1797. chandef->center_freq2 = 0;
  1798. /* Primary channel not allowed */
  1799. if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
  1800. return -EINVAL;
  1801. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  1802. enum nl80211_channel_type chantype;
  1803. chantype = nla_get_u32(
  1804. info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  1805. switch (chantype) {
  1806. case NL80211_CHAN_NO_HT:
  1807. case NL80211_CHAN_HT20:
  1808. case NL80211_CHAN_HT40PLUS:
  1809. case NL80211_CHAN_HT40MINUS:
  1810. cfg80211_chandef_create(chandef, chandef->chan,
  1811. chantype);
  1812. break;
  1813. default:
  1814. return -EINVAL;
  1815. }
  1816. } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
  1817. chandef->width =
  1818. nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
  1819. if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
  1820. chandef->center_freq1 =
  1821. nla_get_u32(
  1822. info->attrs[NL80211_ATTR_CENTER_FREQ1]);
  1823. if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
  1824. chandef->center_freq2 =
  1825. nla_get_u32(
  1826. info->attrs[NL80211_ATTR_CENTER_FREQ2]);
  1827. }
  1828. if (!cfg80211_chandef_valid(chandef))
  1829. return -EINVAL;
  1830. if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
  1831. IEEE80211_CHAN_DISABLED))
  1832. return -EINVAL;
  1833. if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
  1834. chandef->width == NL80211_CHAN_WIDTH_10) &&
  1835. !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
  1836. return -EINVAL;
  1837. return 0;
  1838. }
  1839. static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
  1840. struct net_device *dev,
  1841. struct genl_info *info)
  1842. {
  1843. struct cfg80211_chan_def chandef;
  1844. int result;
  1845. enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
  1846. struct wireless_dev *wdev = NULL;
  1847. if (dev)
  1848. wdev = dev->ieee80211_ptr;
  1849. if (!nl80211_can_set_dev_channel(wdev))
  1850. return -EOPNOTSUPP;
  1851. if (wdev)
  1852. iftype = wdev->iftype;
  1853. result = nl80211_parse_chandef(rdev, info, &chandef);
  1854. if (result)
  1855. return result;
  1856. switch (iftype) {
  1857. case NL80211_IFTYPE_AP:
  1858. case NL80211_IFTYPE_P2P_GO:
  1859. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
  1860. iftype)) {
  1861. result = -EINVAL;
  1862. break;
  1863. }
  1864. if (wdev->beacon_interval) {
  1865. if (!dev || !rdev->ops->set_ap_chanwidth ||
  1866. !(rdev->wiphy.features &
  1867. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
  1868. result = -EBUSY;
  1869. break;
  1870. }
  1871. /* Only allow dynamic channel width changes */
  1872. if (chandef.chan != wdev->preset_chandef.chan) {
  1873. result = -EBUSY;
  1874. break;
  1875. }
  1876. result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
  1877. if (result)
  1878. break;
  1879. }
  1880. wdev->preset_chandef = chandef;
  1881. result = 0;
  1882. break;
  1883. case NL80211_IFTYPE_MESH_POINT:
  1884. result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
  1885. break;
  1886. case NL80211_IFTYPE_MONITOR:
  1887. result = cfg80211_set_monitor_channel(rdev, &chandef);
  1888. break;
  1889. default:
  1890. result = -EINVAL;
  1891. }
  1892. return result;
  1893. }
  1894. static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
  1895. {
  1896. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1897. struct net_device *netdev = info->user_ptr[1];
  1898. return __nl80211_set_channel(rdev, netdev, info);
  1899. }
  1900. static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
  1901. {
  1902. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1903. struct net_device *dev = info->user_ptr[1];
  1904. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1905. const u8 *bssid;
  1906. if (!info->attrs[NL80211_ATTR_MAC])
  1907. return -EINVAL;
  1908. if (netif_running(dev))
  1909. return -EBUSY;
  1910. if (!rdev->ops->set_wds_peer)
  1911. return -EOPNOTSUPP;
  1912. if (wdev->iftype != NL80211_IFTYPE_WDS)
  1913. return -EOPNOTSUPP;
  1914. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1915. return rdev_set_wds_peer(rdev, dev, bssid);
  1916. }
  1917. static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
  1918. {
  1919. struct cfg80211_registered_device *rdev;
  1920. struct net_device *netdev = NULL;
  1921. struct wireless_dev *wdev;
  1922. int result = 0, rem_txq_params = 0;
  1923. struct nlattr *nl_txq_params;
  1924. u32 changed;
  1925. u8 retry_short = 0, retry_long = 0;
  1926. u32 frag_threshold = 0, rts_threshold = 0;
  1927. u8 coverage_class = 0;
  1928. ASSERT_RTNL();
  1929. /*
  1930. * Try to find the wiphy and netdev. Normally this
  1931. * function shouldn't need the netdev, but this is
  1932. * done for backward compatibility -- previously
  1933. * setting the channel was done per wiphy, but now
  1934. * it is per netdev. Previous userland like hostapd
  1935. * also passed a netdev to set_wiphy, so that it is
  1936. * possible to let that go to the right netdev!
  1937. */
  1938. if (info->attrs[NL80211_ATTR_IFINDEX]) {
  1939. int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
  1940. netdev = __dev_get_by_index(genl_info_net(info), ifindex);
  1941. if (netdev && netdev->ieee80211_ptr)
  1942. rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
  1943. else
  1944. netdev = NULL;
  1945. }
  1946. if (!netdev) {
  1947. rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
  1948. info->attrs);
  1949. if (IS_ERR(rdev))
  1950. return PTR_ERR(rdev);
  1951. wdev = NULL;
  1952. netdev = NULL;
  1953. result = 0;
  1954. } else
  1955. wdev = netdev->ieee80211_ptr;
  1956. /*
  1957. * end workaround code, by now the rdev is available
  1958. * and locked, and wdev may or may not be NULL.
  1959. */
  1960. if (info->attrs[NL80211_ATTR_WIPHY_NAME])
  1961. result = cfg80211_dev_rename(
  1962. rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
  1963. if (result)
  1964. return result;
  1965. if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
  1966. struct ieee80211_txq_params txq_params;
  1967. struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
  1968. if (!rdev->ops->set_txq_params)
  1969. return -EOPNOTSUPP;
  1970. if (!netdev)
  1971. return -EINVAL;
  1972. if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  1973. netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  1974. return -EINVAL;
  1975. if (!netif_running(netdev))
  1976. return -ENETDOWN;
  1977. nla_for_each_nested(nl_txq_params,
  1978. info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
  1979. rem_txq_params) {
  1980. result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
  1981. nla_data(nl_txq_params),
  1982. nla_len(nl_txq_params),
  1983. txq_params_policy);
  1984. if (result)
  1985. return result;
  1986. result = parse_txq_params(tb, &txq_params);
  1987. if (result)
  1988. return result;
  1989. result = rdev_set_txq_params(rdev, netdev,
  1990. &txq_params);
  1991. if (result)
  1992. return result;
  1993. }
  1994. }
  1995. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  1996. result = __nl80211_set_channel(
  1997. rdev,
  1998. nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
  1999. info);
  2000. if (result)
  2001. return result;
  2002. }
  2003. if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
  2004. struct wireless_dev *txp_wdev = wdev;
  2005. enum nl80211_tx_power_setting type;
  2006. int idx, mbm = 0;
  2007. if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
  2008. txp_wdev = NULL;
  2009. if (!rdev->ops->set_tx_power)
  2010. return -EOPNOTSUPP;
  2011. idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
  2012. type = nla_get_u32(info->attrs[idx]);
  2013. if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
  2014. (type != NL80211_TX_POWER_AUTOMATIC))
  2015. return -EINVAL;
  2016. if (type != NL80211_TX_POWER_AUTOMATIC) {
  2017. idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
  2018. mbm = nla_get_u32(info->attrs[idx]);
  2019. }
  2020. result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
  2021. if (result)
  2022. return result;
  2023. }
  2024. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  2025. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
  2026. u32 tx_ant, rx_ant;
  2027. if ((!rdev->wiphy.available_antennas_tx &&
  2028. !rdev->wiphy.available_antennas_rx) ||
  2029. !rdev->ops->set_antenna)
  2030. return -EOPNOTSUPP;
  2031. tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
  2032. rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
  2033. /* reject antenna configurations which don't match the
  2034. * available antenna masks, except for the "all" mask */
  2035. if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
  2036. (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
  2037. return -EINVAL;
  2038. tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
  2039. rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
  2040. result = rdev_set_antenna(rdev, tx_ant, rx_ant);
  2041. if (result)
  2042. return result;
  2043. }
  2044. changed = 0;
  2045. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
  2046. retry_short = nla_get_u8(
  2047. info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
  2048. if (retry_short == 0)
  2049. return -EINVAL;
  2050. changed |= WIPHY_PARAM_RETRY_SHORT;
  2051. }
  2052. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
  2053. retry_long = nla_get_u8(
  2054. info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
  2055. if (retry_long == 0)
  2056. return -EINVAL;
  2057. changed |= WIPHY_PARAM_RETRY_LONG;
  2058. }
  2059. if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
  2060. frag_threshold = nla_get_u32(
  2061. info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
  2062. if (frag_threshold < 256)
  2063. return -EINVAL;
  2064. if (frag_threshold != (u32) -1) {
  2065. /*
  2066. * Fragments (apart from the last one) are required to
  2067. * have even length. Make the fragmentation code
  2068. * simpler by stripping LSB should someone try to use
  2069. * odd threshold value.
  2070. */
  2071. frag_threshold &= ~0x1;
  2072. }
  2073. changed |= WIPHY_PARAM_FRAG_THRESHOLD;
  2074. }
  2075. if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
  2076. rts_threshold = nla_get_u32(
  2077. info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
  2078. changed |= WIPHY_PARAM_RTS_THRESHOLD;
  2079. }
  2080. if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
  2081. if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
  2082. return -EINVAL;
  2083. coverage_class = nla_get_u8(
  2084. info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
  2085. changed |= WIPHY_PARAM_COVERAGE_CLASS;
  2086. }
  2087. if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
  2088. if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
  2089. return -EOPNOTSUPP;
  2090. changed |= WIPHY_PARAM_DYN_ACK;
  2091. }
  2092. if (changed) {
  2093. u8 old_retry_short, old_retry_long;
  2094. u32 old_frag_threshold, old_rts_threshold;
  2095. u8 old_coverage_class;
  2096. if (!rdev->ops->set_wiphy_params)
  2097. return -EOPNOTSUPP;
  2098. old_retry_short = rdev->wiphy.retry_short;
  2099. old_retry_long = rdev->wiphy.retry_long;
  2100. old_frag_threshold = rdev->wiphy.frag_threshold;
  2101. old_rts_threshold = rdev->wiphy.rts_threshold;
  2102. old_coverage_class = rdev->wiphy.coverage_class;
  2103. if (changed & WIPHY_PARAM_RETRY_SHORT)
  2104. rdev->wiphy.retry_short = retry_short;
  2105. if (changed & WIPHY_PARAM_RETRY_LONG)
  2106. rdev->wiphy.retry_long = retry_long;
  2107. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  2108. rdev->wiphy.frag_threshold = frag_threshold;
  2109. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  2110. rdev->wiphy.rts_threshold = rts_threshold;
  2111. if (changed & WIPHY_PARAM_COVERAGE_CLASS)
  2112. rdev->wiphy.coverage_class = coverage_class;
  2113. result = rdev_set_wiphy_params(rdev, changed);
  2114. if (result) {
  2115. rdev->wiphy.retry_short = old_retry_short;
  2116. rdev->wiphy.retry_long = old_retry_long;
  2117. rdev->wiphy.frag_threshold = old_frag_threshold;
  2118. rdev->wiphy.rts_threshold = old_rts_threshold;
  2119. rdev->wiphy.coverage_class = old_coverage_class;
  2120. return result;
  2121. }
  2122. }
  2123. return 0;
  2124. }
  2125. static inline u64 wdev_id(struct wireless_dev *wdev)
  2126. {
  2127. return (u64)wdev->identifier |
  2128. ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
  2129. }
  2130. static int nl80211_send_chandef(struct sk_buff *msg,
  2131. const struct cfg80211_chan_def *chandef)
  2132. {
  2133. if (WARN_ON(!cfg80211_chandef_valid(chandef)))
  2134. return -EINVAL;
  2135. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
  2136. chandef->chan->center_freq))
  2137. return -ENOBUFS;
  2138. switch (chandef->width) {
  2139. case NL80211_CHAN_WIDTH_20_NOHT:
  2140. case NL80211_CHAN_WIDTH_20:
  2141. case NL80211_CHAN_WIDTH_40:
  2142. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  2143. cfg80211_get_chandef_type(chandef)))
  2144. return -ENOBUFS;
  2145. break;
  2146. default:
  2147. break;
  2148. }
  2149. if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
  2150. return -ENOBUFS;
  2151. if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
  2152. return -ENOBUFS;
  2153. if (chandef->center_freq2 &&
  2154. nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
  2155. return -ENOBUFS;
  2156. return 0;
  2157. }
  2158. static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
  2159. struct cfg80211_registered_device *rdev,
  2160. struct wireless_dev *wdev, bool removal)
  2161. {
  2162. struct net_device *dev = wdev->netdev;
  2163. u8 cmd = NL80211_CMD_NEW_INTERFACE;
  2164. void *hdr;
  2165. if (removal)
  2166. cmd = NL80211_CMD_DEL_INTERFACE;
  2167. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  2168. if (!hdr)
  2169. return -1;
  2170. if (dev &&
  2171. (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  2172. nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
  2173. goto nla_put_failure;
  2174. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  2175. nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
  2176. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  2177. NL80211_ATTR_PAD) ||
  2178. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
  2179. nla_put_u32(msg, NL80211_ATTR_GENERATION,
  2180. rdev->devlist_generation ^
  2181. (cfg80211_rdev_list_generation << 2)))
  2182. goto nla_put_failure;
  2183. if (rdev->ops->get_channel) {
  2184. int ret;
  2185. struct cfg80211_chan_def chandef;
  2186. ret = rdev_get_channel(rdev, wdev, &chandef);
  2187. if (ret == 0) {
  2188. if (nl80211_send_chandef(msg, &chandef))
  2189. goto nla_put_failure;
  2190. }
  2191. }
  2192. if (rdev->ops->get_tx_power) {
  2193. int dbm, ret;
  2194. ret = rdev_get_tx_power(rdev, wdev, &dbm);
  2195. if (ret == 0 &&
  2196. nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
  2197. DBM_TO_MBM(dbm)))
  2198. goto nla_put_failure;
  2199. }
  2200. if (wdev->ssid_len) {
  2201. if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
  2202. goto nla_put_failure;
  2203. }
  2204. genlmsg_end(msg, hdr);
  2205. return 0;
  2206. nla_put_failure:
  2207. genlmsg_cancel(msg, hdr);
  2208. return -EMSGSIZE;
  2209. }
  2210. static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
  2211. {
  2212. int wp_idx = 0;
  2213. int if_idx = 0;
  2214. int wp_start = cb->args[0];
  2215. int if_start = cb->args[1];
  2216. int filter_wiphy = -1;
  2217. struct cfg80211_registered_device *rdev;
  2218. struct wireless_dev *wdev;
  2219. int ret;
  2220. rtnl_lock();
  2221. if (!cb->args[2]) {
  2222. struct nl80211_dump_wiphy_state state = {
  2223. .filter_wiphy = -1,
  2224. };
  2225. ret = nl80211_dump_wiphy_parse(skb, cb, &state);
  2226. if (ret)
  2227. goto out_unlock;
  2228. filter_wiphy = state.filter_wiphy;
  2229. /*
  2230. * if filtering, set cb->args[2] to +1 since 0 is the default
  2231. * value needed to determine that parsing is necessary.
  2232. */
  2233. if (filter_wiphy >= 0)
  2234. cb->args[2] = filter_wiphy + 1;
  2235. else
  2236. cb->args[2] = -1;
  2237. } else if (cb->args[2] > 0) {
  2238. filter_wiphy = cb->args[2] - 1;
  2239. }
  2240. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  2241. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  2242. continue;
  2243. if (wp_idx < wp_start) {
  2244. wp_idx++;
  2245. continue;
  2246. }
  2247. if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
  2248. continue;
  2249. if_idx = 0;
  2250. list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
  2251. if (if_idx < if_start) {
  2252. if_idx++;
  2253. continue;
  2254. }
  2255. if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
  2256. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  2257. rdev, wdev, false) < 0) {
  2258. goto out;
  2259. }
  2260. if_idx++;
  2261. }
  2262. wp_idx++;
  2263. }
  2264. out:
  2265. cb->args[0] = wp_idx;
  2266. cb->args[1] = if_idx;
  2267. ret = skb->len;
  2268. out_unlock:
  2269. rtnl_unlock();
  2270. return ret;
  2271. }
  2272. static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
  2273. {
  2274. struct sk_buff *msg;
  2275. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2276. struct wireless_dev *wdev = info->user_ptr[1];
  2277. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2278. if (!msg)
  2279. return -ENOMEM;
  2280. if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
  2281. rdev, wdev, false) < 0) {
  2282. nlmsg_free(msg);
  2283. return -ENOBUFS;
  2284. }
  2285. return genlmsg_reply(msg, info);
  2286. }
  2287. static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
  2288. [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
  2289. [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
  2290. [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
  2291. [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
  2292. [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
  2293. [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
  2294. };
  2295. static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
  2296. {
  2297. struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
  2298. int flag;
  2299. *mntrflags = 0;
  2300. if (!nla)
  2301. return -EINVAL;
  2302. if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
  2303. nla, mntr_flags_policy))
  2304. return -EINVAL;
  2305. for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
  2306. if (flags[flag])
  2307. *mntrflags |= (1<<flag);
  2308. return 0;
  2309. }
  2310. static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
  2311. struct net_device *netdev, u8 use_4addr,
  2312. enum nl80211_iftype iftype)
  2313. {
  2314. if (!use_4addr) {
  2315. if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
  2316. return -EBUSY;
  2317. return 0;
  2318. }
  2319. switch (iftype) {
  2320. case NL80211_IFTYPE_AP_VLAN:
  2321. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
  2322. return 0;
  2323. break;
  2324. case NL80211_IFTYPE_STATION:
  2325. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
  2326. return 0;
  2327. break;
  2328. default:
  2329. break;
  2330. }
  2331. return -EOPNOTSUPP;
  2332. }
  2333. static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
  2334. {
  2335. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2336. struct vif_params params;
  2337. int err;
  2338. enum nl80211_iftype otype, ntype;
  2339. struct net_device *dev = info->user_ptr[1];
  2340. u32 _flags, *flags = NULL;
  2341. bool change = false;
  2342. memset(&params, 0, sizeof(params));
  2343. otype = ntype = dev->ieee80211_ptr->iftype;
  2344. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  2345. ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  2346. if (otype != ntype)
  2347. change = true;
  2348. if (ntype > NL80211_IFTYPE_MAX)
  2349. return -EINVAL;
  2350. }
  2351. if (info->attrs[NL80211_ATTR_MESH_ID]) {
  2352. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2353. if (ntype != NL80211_IFTYPE_MESH_POINT)
  2354. return -EINVAL;
  2355. if (netif_running(dev))
  2356. return -EBUSY;
  2357. wdev_lock(wdev);
  2358. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  2359. IEEE80211_MAX_MESH_ID_LEN);
  2360. wdev->mesh_id_up_len =
  2361. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  2362. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  2363. wdev->mesh_id_up_len);
  2364. wdev_unlock(wdev);
  2365. }
  2366. if (info->attrs[NL80211_ATTR_4ADDR]) {
  2367. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  2368. change = true;
  2369. err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
  2370. if (err)
  2371. return err;
  2372. } else {
  2373. params.use_4addr = -1;
  2374. }
  2375. if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
  2376. if (ntype != NL80211_IFTYPE_MONITOR)
  2377. return -EINVAL;
  2378. err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
  2379. &_flags);
  2380. if (err)
  2381. return err;
  2382. flags = &_flags;
  2383. change = true;
  2384. }
  2385. if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
  2386. const u8 *mumimo_groups;
  2387. u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
  2388. if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
  2389. return -EOPNOTSUPP;
  2390. mumimo_groups =
  2391. nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
  2392. /* bits 0 and 63 are reserved and must be zero */
  2393. if ((mumimo_groups[0] & BIT(7)) ||
  2394. (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
  2395. return -EINVAL;
  2396. memcpy(params.vht_mumimo_groups, mumimo_groups,
  2397. VHT_MUMIMO_GROUPS_DATA_LEN);
  2398. change = true;
  2399. }
  2400. if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
  2401. u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
  2402. if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
  2403. return -EOPNOTSUPP;
  2404. nla_memcpy(params.macaddr,
  2405. info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
  2406. ETH_ALEN);
  2407. change = true;
  2408. }
  2409. if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
  2410. !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
  2411. return -EOPNOTSUPP;
  2412. if (change)
  2413. err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
  2414. else
  2415. err = 0;
  2416. if (!err && params.use_4addr != -1)
  2417. dev->ieee80211_ptr->use_4addr = params.use_4addr;
  2418. return err;
  2419. }
  2420. static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
  2421. {
  2422. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2423. struct vif_params params;
  2424. struct wireless_dev *wdev;
  2425. struct sk_buff *msg;
  2426. int err;
  2427. enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
  2428. u32 flags;
  2429. /* to avoid failing a new interface creation due to pending removal */
  2430. cfg80211_destroy_ifaces(rdev);
  2431. memset(&params, 0, sizeof(params));
  2432. if (!info->attrs[NL80211_ATTR_IFNAME])
  2433. return -EINVAL;
  2434. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  2435. type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  2436. if (type > NL80211_IFTYPE_MAX)
  2437. return -EINVAL;
  2438. }
  2439. if (!rdev->ops->add_virtual_intf ||
  2440. !(rdev->wiphy.interface_modes & (1 << type)))
  2441. return -EOPNOTSUPP;
  2442. if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
  2443. rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
  2444. info->attrs[NL80211_ATTR_MAC]) {
  2445. nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
  2446. ETH_ALEN);
  2447. if (!is_valid_ether_addr(params.macaddr))
  2448. return -EADDRNOTAVAIL;
  2449. }
  2450. if (info->attrs[NL80211_ATTR_4ADDR]) {
  2451. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  2452. err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
  2453. if (err)
  2454. return err;
  2455. }
  2456. err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
  2457. info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
  2458. &flags);
  2459. if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
  2460. !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
  2461. return -EOPNOTSUPP;
  2462. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2463. if (!msg)
  2464. return -ENOMEM;
  2465. wdev = rdev_add_virtual_intf(rdev,
  2466. nla_data(info->attrs[NL80211_ATTR_IFNAME]),
  2467. NET_NAME_USER, type, err ? NULL : &flags,
  2468. &params);
  2469. if (WARN_ON(!wdev)) {
  2470. nlmsg_free(msg);
  2471. return -EPROTO;
  2472. } else if (IS_ERR(wdev)) {
  2473. nlmsg_free(msg);
  2474. return PTR_ERR(wdev);
  2475. }
  2476. if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
  2477. wdev->owner_nlportid = info->snd_portid;
  2478. switch (type) {
  2479. case NL80211_IFTYPE_MESH_POINT:
  2480. if (!info->attrs[NL80211_ATTR_MESH_ID])
  2481. break;
  2482. wdev_lock(wdev);
  2483. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  2484. IEEE80211_MAX_MESH_ID_LEN);
  2485. wdev->mesh_id_up_len =
  2486. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  2487. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  2488. wdev->mesh_id_up_len);
  2489. wdev_unlock(wdev);
  2490. break;
  2491. case NL80211_IFTYPE_NAN:
  2492. case NL80211_IFTYPE_P2P_DEVICE:
  2493. /*
  2494. * P2P Device and NAN do not have a netdev, so don't go
  2495. * through the netdev notifier and must be added here
  2496. */
  2497. mutex_init(&wdev->mtx);
  2498. INIT_LIST_HEAD(&wdev->event_list);
  2499. spin_lock_init(&wdev->event_lock);
  2500. INIT_LIST_HEAD(&wdev->mgmt_registrations);
  2501. spin_lock_init(&wdev->mgmt_registrations_lock);
  2502. wdev->identifier = ++rdev->wdev_id;
  2503. list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
  2504. rdev->devlist_generation++;
  2505. break;
  2506. default:
  2507. break;
  2508. }
  2509. if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
  2510. rdev, wdev, false) < 0) {
  2511. nlmsg_free(msg);
  2512. return -ENOBUFS;
  2513. }
  2514. /*
  2515. * For wdevs which have no associated netdev object (e.g. of type
  2516. * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
  2517. * For all other types, the event will be generated from the
  2518. * netdev notifier
  2519. */
  2520. if (!wdev->netdev)
  2521. nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
  2522. return genlmsg_reply(msg, info);
  2523. }
  2524. static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
  2525. {
  2526. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2527. struct wireless_dev *wdev = info->user_ptr[1];
  2528. if (!rdev->ops->del_virtual_intf)
  2529. return -EOPNOTSUPP;
  2530. /*
  2531. * If we remove a wireless device without a netdev then clear
  2532. * user_ptr[1] so that nl80211_post_doit won't dereference it
  2533. * to check if it needs to do dev_put(). Otherwise it crashes
  2534. * since the wdev has been freed, unlike with a netdev where
  2535. * we need the dev_put() for the netdev to really be freed.
  2536. */
  2537. if (!wdev->netdev)
  2538. info->user_ptr[1] = NULL;
  2539. return rdev_del_virtual_intf(rdev, wdev);
  2540. }
  2541. static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
  2542. {
  2543. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2544. struct net_device *dev = info->user_ptr[1];
  2545. u16 noack_map;
  2546. if (!info->attrs[NL80211_ATTR_NOACK_MAP])
  2547. return -EINVAL;
  2548. if (!rdev->ops->set_noack_map)
  2549. return -EOPNOTSUPP;
  2550. noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
  2551. return rdev_set_noack_map(rdev, dev, noack_map);
  2552. }
  2553. struct get_key_cookie {
  2554. struct sk_buff *msg;
  2555. int error;
  2556. int idx;
  2557. };
  2558. static void get_key_callback(void *c, struct key_params *params)
  2559. {
  2560. struct nlattr *key;
  2561. struct get_key_cookie *cookie = c;
  2562. if ((params->key &&
  2563. nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
  2564. params->key_len, params->key)) ||
  2565. (params->seq &&
  2566. nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
  2567. params->seq_len, params->seq)) ||
  2568. (params->cipher &&
  2569. nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
  2570. params->cipher)))
  2571. goto nla_put_failure;
  2572. key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
  2573. if (!key)
  2574. goto nla_put_failure;
  2575. if ((params->key &&
  2576. nla_put(cookie->msg, NL80211_KEY_DATA,
  2577. params->key_len, params->key)) ||
  2578. (params->seq &&
  2579. nla_put(cookie->msg, NL80211_KEY_SEQ,
  2580. params->seq_len, params->seq)) ||
  2581. (params->cipher &&
  2582. nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
  2583. params->cipher)))
  2584. goto nla_put_failure;
  2585. if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
  2586. goto nla_put_failure;
  2587. nla_nest_end(cookie->msg, key);
  2588. return;
  2589. nla_put_failure:
  2590. cookie->error = 1;
  2591. }
  2592. static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
  2593. {
  2594. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2595. int err;
  2596. struct net_device *dev = info->user_ptr[1];
  2597. u8 key_idx = 0;
  2598. const u8 *mac_addr = NULL;
  2599. bool pairwise;
  2600. struct get_key_cookie cookie = {
  2601. .error = 0,
  2602. };
  2603. void *hdr;
  2604. struct sk_buff *msg;
  2605. if (info->attrs[NL80211_ATTR_KEY_IDX])
  2606. key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  2607. if (key_idx > 5)
  2608. return -EINVAL;
  2609. if (info->attrs[NL80211_ATTR_MAC])
  2610. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2611. pairwise = !!mac_addr;
  2612. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  2613. u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  2614. if (kt >= NUM_NL80211_KEYTYPES)
  2615. return -EINVAL;
  2616. if (kt != NL80211_KEYTYPE_GROUP &&
  2617. kt != NL80211_KEYTYPE_PAIRWISE)
  2618. return -EINVAL;
  2619. pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
  2620. }
  2621. if (!rdev->ops->get_key)
  2622. return -EOPNOTSUPP;
  2623. if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  2624. return -ENOENT;
  2625. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2626. if (!msg)
  2627. return -ENOMEM;
  2628. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  2629. NL80211_CMD_NEW_KEY);
  2630. if (!hdr)
  2631. goto nla_put_failure;
  2632. cookie.msg = msg;
  2633. cookie.idx = key_idx;
  2634. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  2635. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
  2636. goto nla_put_failure;
  2637. if (mac_addr &&
  2638. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
  2639. goto nla_put_failure;
  2640. err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
  2641. get_key_callback);
  2642. if (err)
  2643. goto free_msg;
  2644. if (cookie.error)
  2645. goto nla_put_failure;
  2646. genlmsg_end(msg, hdr);
  2647. return genlmsg_reply(msg, info);
  2648. nla_put_failure:
  2649. err = -ENOBUFS;
  2650. free_msg:
  2651. nlmsg_free(msg);
  2652. return err;
  2653. }
  2654. static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
  2655. {
  2656. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2657. struct key_parse key;
  2658. int err;
  2659. struct net_device *dev = info->user_ptr[1];
  2660. err = nl80211_parse_key(info, &key);
  2661. if (err)
  2662. return err;
  2663. if (key.idx < 0)
  2664. return -EINVAL;
  2665. /* only support setting default key */
  2666. if (!key.def && !key.defmgmt)
  2667. return -EINVAL;
  2668. wdev_lock(dev->ieee80211_ptr);
  2669. if (key.def) {
  2670. if (!rdev->ops->set_default_key) {
  2671. err = -EOPNOTSUPP;
  2672. goto out;
  2673. }
  2674. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2675. if (err)
  2676. goto out;
  2677. err = rdev_set_default_key(rdev, dev, key.idx,
  2678. key.def_uni, key.def_multi);
  2679. if (err)
  2680. goto out;
  2681. #ifdef CONFIG_CFG80211_WEXT
  2682. dev->ieee80211_ptr->wext.default_key = key.idx;
  2683. #endif
  2684. } else {
  2685. if (key.def_uni || !key.def_multi) {
  2686. err = -EINVAL;
  2687. goto out;
  2688. }
  2689. if (!rdev->ops->set_default_mgmt_key) {
  2690. err = -EOPNOTSUPP;
  2691. goto out;
  2692. }
  2693. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2694. if (err)
  2695. goto out;
  2696. err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
  2697. if (err)
  2698. goto out;
  2699. #ifdef CONFIG_CFG80211_WEXT
  2700. dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
  2701. #endif
  2702. }
  2703. out:
  2704. wdev_unlock(dev->ieee80211_ptr);
  2705. return err;
  2706. }
  2707. static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
  2708. {
  2709. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2710. int err;
  2711. struct net_device *dev = info->user_ptr[1];
  2712. struct key_parse key;
  2713. const u8 *mac_addr = NULL;
  2714. err = nl80211_parse_key(info, &key);
  2715. if (err)
  2716. return err;
  2717. if (!key.p.key)
  2718. return -EINVAL;
  2719. if (info->attrs[NL80211_ATTR_MAC])
  2720. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2721. if (key.type == -1) {
  2722. if (mac_addr)
  2723. key.type = NL80211_KEYTYPE_PAIRWISE;
  2724. else
  2725. key.type = NL80211_KEYTYPE_GROUP;
  2726. }
  2727. /* for now */
  2728. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  2729. key.type != NL80211_KEYTYPE_GROUP)
  2730. return -EINVAL;
  2731. if (!rdev->ops->add_key)
  2732. return -EOPNOTSUPP;
  2733. if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
  2734. key.type == NL80211_KEYTYPE_PAIRWISE,
  2735. mac_addr))
  2736. return -EINVAL;
  2737. wdev_lock(dev->ieee80211_ptr);
  2738. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2739. if (!err)
  2740. err = rdev_add_key(rdev, dev, key.idx,
  2741. key.type == NL80211_KEYTYPE_PAIRWISE,
  2742. mac_addr, &key.p);
  2743. wdev_unlock(dev->ieee80211_ptr);
  2744. return err;
  2745. }
  2746. static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
  2747. {
  2748. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2749. int err;
  2750. struct net_device *dev = info->user_ptr[1];
  2751. u8 *mac_addr = NULL;
  2752. struct key_parse key;
  2753. err = nl80211_parse_key(info, &key);
  2754. if (err)
  2755. return err;
  2756. if (info->attrs[NL80211_ATTR_MAC])
  2757. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2758. if (key.type == -1) {
  2759. if (mac_addr)
  2760. key.type = NL80211_KEYTYPE_PAIRWISE;
  2761. else
  2762. key.type = NL80211_KEYTYPE_GROUP;
  2763. }
  2764. /* for now */
  2765. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  2766. key.type != NL80211_KEYTYPE_GROUP)
  2767. return -EINVAL;
  2768. if (!rdev->ops->del_key)
  2769. return -EOPNOTSUPP;
  2770. wdev_lock(dev->ieee80211_ptr);
  2771. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2772. if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
  2773. !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  2774. err = -ENOENT;
  2775. if (!err)
  2776. err = rdev_del_key(rdev, dev, key.idx,
  2777. key.type == NL80211_KEYTYPE_PAIRWISE,
  2778. mac_addr);
  2779. #ifdef CONFIG_CFG80211_WEXT
  2780. if (!err) {
  2781. if (key.idx == dev->ieee80211_ptr->wext.default_key)
  2782. dev->ieee80211_ptr->wext.default_key = -1;
  2783. else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
  2784. dev->ieee80211_ptr->wext.default_mgmt_key = -1;
  2785. }
  2786. #endif
  2787. wdev_unlock(dev->ieee80211_ptr);
  2788. return err;
  2789. }
  2790. /* This function returns an error or the number of nested attributes */
  2791. static int validate_acl_mac_addrs(struct nlattr *nl_attr)
  2792. {
  2793. struct nlattr *attr;
  2794. int n_entries = 0, tmp;
  2795. nla_for_each_nested(attr, nl_attr, tmp) {
  2796. if (nla_len(attr) != ETH_ALEN)
  2797. return -EINVAL;
  2798. n_entries++;
  2799. }
  2800. return n_entries;
  2801. }
  2802. /*
  2803. * This function parses ACL information and allocates memory for ACL data.
  2804. * On successful return, the calling function is responsible to free the
  2805. * ACL buffer returned by this function.
  2806. */
  2807. static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
  2808. struct genl_info *info)
  2809. {
  2810. enum nl80211_acl_policy acl_policy;
  2811. struct nlattr *attr;
  2812. struct cfg80211_acl_data *acl;
  2813. int i = 0, n_entries, tmp;
  2814. if (!wiphy->max_acl_mac_addrs)
  2815. return ERR_PTR(-EOPNOTSUPP);
  2816. if (!info->attrs[NL80211_ATTR_ACL_POLICY])
  2817. return ERR_PTR(-EINVAL);
  2818. acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
  2819. if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
  2820. acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
  2821. return ERR_PTR(-EINVAL);
  2822. if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
  2823. return ERR_PTR(-EINVAL);
  2824. n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
  2825. if (n_entries < 0)
  2826. return ERR_PTR(n_entries);
  2827. if (n_entries > wiphy->max_acl_mac_addrs)
  2828. return ERR_PTR(-ENOTSUPP);
  2829. acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
  2830. GFP_KERNEL);
  2831. if (!acl)
  2832. return ERR_PTR(-ENOMEM);
  2833. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
  2834. memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
  2835. i++;
  2836. }
  2837. acl->n_acl_entries = n_entries;
  2838. acl->acl_policy = acl_policy;
  2839. return acl;
  2840. }
  2841. static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
  2842. {
  2843. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2844. struct net_device *dev = info->user_ptr[1];
  2845. struct cfg80211_acl_data *acl;
  2846. int err;
  2847. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2848. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2849. return -EOPNOTSUPP;
  2850. if (!dev->ieee80211_ptr->beacon_interval)
  2851. return -EINVAL;
  2852. acl = parse_acl_data(&rdev->wiphy, info);
  2853. if (IS_ERR(acl))
  2854. return PTR_ERR(acl);
  2855. err = rdev_set_mac_acl(rdev, dev, acl);
  2856. kfree(acl);
  2857. return err;
  2858. }
  2859. static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
  2860. u8 *rates, u8 rates_len)
  2861. {
  2862. u8 i;
  2863. u32 mask = 0;
  2864. for (i = 0; i < rates_len; i++) {
  2865. int rate = (rates[i] & 0x7f) * 5;
  2866. int ridx;
  2867. for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
  2868. struct ieee80211_rate *srate =
  2869. &sband->bitrates[ridx];
  2870. if (rate == srate->bitrate) {
  2871. mask |= 1 << ridx;
  2872. break;
  2873. }
  2874. }
  2875. if (ridx == sband->n_bitrates)
  2876. return 0; /* rate not found */
  2877. }
  2878. return mask;
  2879. }
  2880. static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
  2881. u8 *rates, u8 rates_len,
  2882. u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
  2883. {
  2884. u8 i;
  2885. memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
  2886. for (i = 0; i < rates_len; i++) {
  2887. int ridx, rbit;
  2888. ridx = rates[i] / 8;
  2889. rbit = BIT(rates[i] % 8);
  2890. /* check validity */
  2891. if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
  2892. return false;
  2893. /* check availability */
  2894. if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
  2895. mcs[ridx] |= rbit;
  2896. else
  2897. return false;
  2898. }
  2899. return true;
  2900. }
  2901. static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
  2902. {
  2903. u16 mcs_mask = 0;
  2904. switch (vht_mcs_map) {
  2905. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  2906. break;
  2907. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  2908. mcs_mask = 0x00FF;
  2909. break;
  2910. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  2911. mcs_mask = 0x01FF;
  2912. break;
  2913. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  2914. mcs_mask = 0x03FF;
  2915. break;
  2916. default:
  2917. break;
  2918. }
  2919. return mcs_mask;
  2920. }
  2921. static void vht_build_mcs_mask(u16 vht_mcs_map,
  2922. u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  2923. {
  2924. u8 nss;
  2925. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
  2926. vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
  2927. vht_mcs_map >>= 2;
  2928. }
  2929. }
  2930. static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
  2931. struct nl80211_txrate_vht *txrate,
  2932. u16 mcs[NL80211_VHT_NSS_MAX])
  2933. {
  2934. u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  2935. u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
  2936. u8 i;
  2937. if (!sband->vht_cap.vht_supported)
  2938. return false;
  2939. memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
  2940. /* Build vht_mcs_mask from VHT capabilities */
  2941. vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
  2942. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  2943. if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
  2944. mcs[i] = txrate->mcs[i];
  2945. else
  2946. return false;
  2947. }
  2948. return true;
  2949. }
  2950. static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
  2951. [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
  2952. .len = NL80211_MAX_SUPP_RATES },
  2953. [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
  2954. .len = NL80211_MAX_SUPP_HT_RATES },
  2955. [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
  2956. [NL80211_TXRATE_GI] = { .type = NLA_U8 },
  2957. };
  2958. static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
  2959. struct cfg80211_bitrate_mask *mask)
  2960. {
  2961. struct nlattr *tb[NL80211_TXRATE_MAX + 1];
  2962. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2963. int rem, i;
  2964. struct nlattr *tx_rates;
  2965. struct ieee80211_supported_band *sband;
  2966. u16 vht_tx_mcs_map;
  2967. memset(mask, 0, sizeof(*mask));
  2968. /* Default to all rates enabled */
  2969. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  2970. sband = rdev->wiphy.bands[i];
  2971. if (!sband)
  2972. continue;
  2973. mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
  2974. memcpy(mask->control[i].ht_mcs,
  2975. sband->ht_cap.mcs.rx_mask,
  2976. sizeof(mask->control[i].ht_mcs));
  2977. if (!sband->vht_cap.vht_supported)
  2978. continue;
  2979. vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  2980. vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
  2981. }
  2982. /* if no rates are given set it back to the defaults */
  2983. if (!info->attrs[NL80211_ATTR_TX_RATES])
  2984. goto out;
  2985. /* The nested attribute uses enum nl80211_band as the index. This maps
  2986. * directly to the enum nl80211_band values used in cfg80211.
  2987. */
  2988. BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
  2989. nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
  2990. enum nl80211_band band = nla_type(tx_rates);
  2991. int err;
  2992. if (band < 0 || band >= NUM_NL80211_BANDS)
  2993. return -EINVAL;
  2994. sband = rdev->wiphy.bands[band];
  2995. if (sband == NULL)
  2996. return -EINVAL;
  2997. err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
  2998. nla_len(tx_rates), nl80211_txattr_policy);
  2999. if (err)
  3000. return err;
  3001. if (tb[NL80211_TXRATE_LEGACY]) {
  3002. mask->control[band].legacy = rateset_to_mask(
  3003. sband,
  3004. nla_data(tb[NL80211_TXRATE_LEGACY]),
  3005. nla_len(tb[NL80211_TXRATE_LEGACY]));
  3006. if ((mask->control[band].legacy == 0) &&
  3007. nla_len(tb[NL80211_TXRATE_LEGACY]))
  3008. return -EINVAL;
  3009. }
  3010. if (tb[NL80211_TXRATE_HT]) {
  3011. if (!ht_rateset_to_mask(
  3012. sband,
  3013. nla_data(tb[NL80211_TXRATE_HT]),
  3014. nla_len(tb[NL80211_TXRATE_HT]),
  3015. mask->control[band].ht_mcs))
  3016. return -EINVAL;
  3017. }
  3018. if (tb[NL80211_TXRATE_VHT]) {
  3019. if (!vht_set_mcs_mask(
  3020. sband,
  3021. nla_data(tb[NL80211_TXRATE_VHT]),
  3022. mask->control[band].vht_mcs))
  3023. return -EINVAL;
  3024. }
  3025. if (tb[NL80211_TXRATE_GI]) {
  3026. mask->control[band].gi =
  3027. nla_get_u8(tb[NL80211_TXRATE_GI]);
  3028. if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
  3029. return -EINVAL;
  3030. }
  3031. if (mask->control[band].legacy == 0) {
  3032. /* don't allow empty legacy rates if HT or VHT
  3033. * are not even supported.
  3034. */
  3035. if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
  3036. rdev->wiphy.bands[band]->vht_cap.vht_supported))
  3037. return -EINVAL;
  3038. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  3039. if (mask->control[band].ht_mcs[i])
  3040. goto out;
  3041. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  3042. if (mask->control[band].vht_mcs[i])
  3043. goto out;
  3044. /* legacy and mcs rates may not be both empty */
  3045. return -EINVAL;
  3046. }
  3047. }
  3048. out:
  3049. return 0;
  3050. }
  3051. static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
  3052. enum nl80211_band band,
  3053. struct cfg80211_bitrate_mask *beacon_rate)
  3054. {
  3055. u32 count_ht, count_vht, i;
  3056. u32 rate = beacon_rate->control[band].legacy;
  3057. /* Allow only one rate */
  3058. if (hweight32(rate) > 1)
  3059. return -EINVAL;
  3060. count_ht = 0;
  3061. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  3062. if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
  3063. return -EINVAL;
  3064. } else if (beacon_rate->control[band].ht_mcs[i]) {
  3065. count_ht++;
  3066. if (count_ht > 1)
  3067. return -EINVAL;
  3068. }
  3069. if (count_ht && rate)
  3070. return -EINVAL;
  3071. }
  3072. count_vht = 0;
  3073. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  3074. if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
  3075. return -EINVAL;
  3076. } else if (beacon_rate->control[band].vht_mcs[i]) {
  3077. count_vht++;
  3078. if (count_vht > 1)
  3079. return -EINVAL;
  3080. }
  3081. if (count_vht && rate)
  3082. return -EINVAL;
  3083. }
  3084. if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
  3085. return -EINVAL;
  3086. if (rate &&
  3087. !wiphy_ext_feature_isset(&rdev->wiphy,
  3088. NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
  3089. return -EINVAL;
  3090. if (count_ht &&
  3091. !wiphy_ext_feature_isset(&rdev->wiphy,
  3092. NL80211_EXT_FEATURE_BEACON_RATE_HT))
  3093. return -EINVAL;
  3094. if (count_vht &&
  3095. !wiphy_ext_feature_isset(&rdev->wiphy,
  3096. NL80211_EXT_FEATURE_BEACON_RATE_VHT))
  3097. return -EINVAL;
  3098. return 0;
  3099. }
  3100. static int nl80211_parse_beacon(struct nlattr *attrs[],
  3101. struct cfg80211_beacon_data *bcn)
  3102. {
  3103. bool haveinfo = false;
  3104. if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
  3105. !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
  3106. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
  3107. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
  3108. return -EINVAL;
  3109. memset(bcn, 0, sizeof(*bcn));
  3110. if (attrs[NL80211_ATTR_BEACON_HEAD]) {
  3111. bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
  3112. bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
  3113. if (!bcn->head_len)
  3114. return -EINVAL;
  3115. haveinfo = true;
  3116. }
  3117. if (attrs[NL80211_ATTR_BEACON_TAIL]) {
  3118. bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
  3119. bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
  3120. haveinfo = true;
  3121. }
  3122. if (!haveinfo)
  3123. return -EINVAL;
  3124. if (attrs[NL80211_ATTR_IE]) {
  3125. bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
  3126. bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
  3127. }
  3128. if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
  3129. bcn->proberesp_ies =
  3130. nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  3131. bcn->proberesp_ies_len =
  3132. nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  3133. }
  3134. if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
  3135. bcn->assocresp_ies =
  3136. nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  3137. bcn->assocresp_ies_len =
  3138. nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  3139. }
  3140. if (attrs[NL80211_ATTR_PROBE_RESP]) {
  3141. bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
  3142. bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
  3143. }
  3144. return 0;
  3145. }
  3146. static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
  3147. struct cfg80211_ap_settings *params)
  3148. {
  3149. struct wireless_dev *wdev;
  3150. bool ret = false;
  3151. list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
  3152. if (wdev->iftype != NL80211_IFTYPE_AP &&
  3153. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  3154. continue;
  3155. if (!wdev->preset_chandef.chan)
  3156. continue;
  3157. params->chandef = wdev->preset_chandef;
  3158. ret = true;
  3159. break;
  3160. }
  3161. return ret;
  3162. }
  3163. static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
  3164. enum nl80211_auth_type auth_type,
  3165. enum nl80211_commands cmd)
  3166. {
  3167. if (auth_type > NL80211_AUTHTYPE_MAX)
  3168. return false;
  3169. switch (cmd) {
  3170. case NL80211_CMD_AUTHENTICATE:
  3171. if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
  3172. auth_type == NL80211_AUTHTYPE_SAE)
  3173. return false;
  3174. return true;
  3175. case NL80211_CMD_CONNECT:
  3176. case NL80211_CMD_START_AP:
  3177. /* SAE not supported yet */
  3178. if (auth_type == NL80211_AUTHTYPE_SAE)
  3179. return false;
  3180. return true;
  3181. default:
  3182. return false;
  3183. }
  3184. }
  3185. static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
  3186. {
  3187. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3188. struct net_device *dev = info->user_ptr[1];
  3189. struct wireless_dev *wdev = dev->ieee80211_ptr;
  3190. struct cfg80211_ap_settings params;
  3191. int err;
  3192. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3193. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3194. return -EOPNOTSUPP;
  3195. if (!rdev->ops->start_ap)
  3196. return -EOPNOTSUPP;
  3197. if (wdev->beacon_interval)
  3198. return -EALREADY;
  3199. memset(&params, 0, sizeof(params));
  3200. /* these are required for START_AP */
  3201. if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
  3202. !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
  3203. !info->attrs[NL80211_ATTR_BEACON_HEAD])
  3204. return -EINVAL;
  3205. err = nl80211_parse_beacon(info->attrs, &params.beacon);
  3206. if (err)
  3207. return err;
  3208. params.beacon_interval =
  3209. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  3210. params.dtim_period =
  3211. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  3212. err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
  3213. if (err)
  3214. return err;
  3215. /*
  3216. * In theory, some of these attributes should be required here
  3217. * but since they were not used when the command was originally
  3218. * added, keep them optional for old user space programs to let
  3219. * them continue to work with drivers that do not need the
  3220. * additional information -- drivers must check!
  3221. */
  3222. if (info->attrs[NL80211_ATTR_SSID]) {
  3223. params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  3224. params.ssid_len =
  3225. nla_len(info->attrs[NL80211_ATTR_SSID]);
  3226. if (params.ssid_len == 0 ||
  3227. params.ssid_len > IEEE80211_MAX_SSID_LEN)
  3228. return -EINVAL;
  3229. }
  3230. if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
  3231. params.hidden_ssid = nla_get_u32(
  3232. info->attrs[NL80211_ATTR_HIDDEN_SSID]);
  3233. if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
  3234. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
  3235. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
  3236. return -EINVAL;
  3237. }
  3238. params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  3239. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  3240. params.auth_type = nla_get_u32(
  3241. info->attrs[NL80211_ATTR_AUTH_TYPE]);
  3242. if (!nl80211_valid_auth_type(rdev, params.auth_type,
  3243. NL80211_CMD_START_AP))
  3244. return -EINVAL;
  3245. } else
  3246. params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  3247. err = nl80211_crypto_settings(rdev, info, &params.crypto,
  3248. NL80211_MAX_NR_CIPHER_SUITES);
  3249. if (err)
  3250. return err;
  3251. if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
  3252. if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
  3253. return -EOPNOTSUPP;
  3254. params.inactivity_timeout = nla_get_u16(
  3255. info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
  3256. }
  3257. if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
  3258. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3259. return -EINVAL;
  3260. params.p2p_ctwindow =
  3261. nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
  3262. if (params.p2p_ctwindow > 127)
  3263. return -EINVAL;
  3264. if (params.p2p_ctwindow != 0 &&
  3265. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
  3266. return -EINVAL;
  3267. }
  3268. if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
  3269. u8 tmp;
  3270. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3271. return -EINVAL;
  3272. tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
  3273. if (tmp > 1)
  3274. return -EINVAL;
  3275. params.p2p_opp_ps = tmp;
  3276. if (params.p2p_opp_ps != 0 &&
  3277. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
  3278. return -EINVAL;
  3279. }
  3280. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  3281. err = nl80211_parse_chandef(rdev, info, &params.chandef);
  3282. if (err)
  3283. return err;
  3284. } else if (wdev->preset_chandef.chan) {
  3285. params.chandef = wdev->preset_chandef;
  3286. } else if (!nl80211_get_ap_channel(rdev, &params))
  3287. return -EINVAL;
  3288. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
  3289. wdev->iftype))
  3290. return -EINVAL;
  3291. if (info->attrs[NL80211_ATTR_TX_RATES]) {
  3292. err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
  3293. if (err)
  3294. return err;
  3295. err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
  3296. &params.beacon_rate);
  3297. if (err)
  3298. return err;
  3299. }
  3300. if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
  3301. params.smps_mode =
  3302. nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
  3303. switch (params.smps_mode) {
  3304. case NL80211_SMPS_OFF:
  3305. break;
  3306. case NL80211_SMPS_STATIC:
  3307. if (!(rdev->wiphy.features &
  3308. NL80211_FEATURE_STATIC_SMPS))
  3309. return -EINVAL;
  3310. break;
  3311. case NL80211_SMPS_DYNAMIC:
  3312. if (!(rdev->wiphy.features &
  3313. NL80211_FEATURE_DYNAMIC_SMPS))
  3314. return -EINVAL;
  3315. break;
  3316. default:
  3317. return -EINVAL;
  3318. }
  3319. } else {
  3320. params.smps_mode = NL80211_SMPS_OFF;
  3321. }
  3322. params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
  3323. if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
  3324. return -EOPNOTSUPP;
  3325. if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
  3326. params.acl = parse_acl_data(&rdev->wiphy, info);
  3327. if (IS_ERR(params.acl))
  3328. return PTR_ERR(params.acl);
  3329. }
  3330. wdev_lock(wdev);
  3331. err = rdev_start_ap(rdev, dev, &params);
  3332. if (!err) {
  3333. wdev->preset_chandef = params.chandef;
  3334. wdev->beacon_interval = params.beacon_interval;
  3335. wdev->chandef = params.chandef;
  3336. wdev->ssid_len = params.ssid_len;
  3337. memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
  3338. }
  3339. wdev_unlock(wdev);
  3340. kfree(params.acl);
  3341. return err;
  3342. }
  3343. static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
  3344. {
  3345. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3346. struct net_device *dev = info->user_ptr[1];
  3347. struct wireless_dev *wdev = dev->ieee80211_ptr;
  3348. struct cfg80211_beacon_data params;
  3349. int err;
  3350. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3351. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3352. return -EOPNOTSUPP;
  3353. if (!rdev->ops->change_beacon)
  3354. return -EOPNOTSUPP;
  3355. if (!wdev->beacon_interval)
  3356. return -EINVAL;
  3357. err = nl80211_parse_beacon(info->attrs, &params);
  3358. if (err)
  3359. return err;
  3360. wdev_lock(wdev);
  3361. err = rdev_change_beacon(rdev, dev, &params);
  3362. wdev_unlock(wdev);
  3363. return err;
  3364. }
  3365. static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
  3366. {
  3367. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3368. struct net_device *dev = info->user_ptr[1];
  3369. return cfg80211_stop_ap(rdev, dev, false);
  3370. }
  3371. static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
  3372. [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
  3373. [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
  3374. [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
  3375. [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
  3376. [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
  3377. [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
  3378. };
  3379. static int parse_station_flags(struct genl_info *info,
  3380. enum nl80211_iftype iftype,
  3381. struct station_parameters *params)
  3382. {
  3383. struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
  3384. struct nlattr *nla;
  3385. int flag;
  3386. /*
  3387. * Try parsing the new attribute first so userspace
  3388. * can specify both for older kernels.
  3389. */
  3390. nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
  3391. if (nla) {
  3392. struct nl80211_sta_flag_update *sta_flags;
  3393. sta_flags = nla_data(nla);
  3394. params->sta_flags_mask = sta_flags->mask;
  3395. params->sta_flags_set = sta_flags->set;
  3396. params->sta_flags_set &= params->sta_flags_mask;
  3397. if ((params->sta_flags_mask |
  3398. params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
  3399. return -EINVAL;
  3400. return 0;
  3401. }
  3402. /* if present, parse the old attribute */
  3403. nla = info->attrs[NL80211_ATTR_STA_FLAGS];
  3404. if (!nla)
  3405. return 0;
  3406. if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
  3407. nla, sta_flags_policy))
  3408. return -EINVAL;
  3409. /*
  3410. * Only allow certain flags for interface types so that
  3411. * other attributes are silently ignored. Remember that
  3412. * this is backward compatibility code with old userspace
  3413. * and shouldn't be hit in other cases anyway.
  3414. */
  3415. switch (iftype) {
  3416. case NL80211_IFTYPE_AP:
  3417. case NL80211_IFTYPE_AP_VLAN:
  3418. case NL80211_IFTYPE_P2P_GO:
  3419. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3420. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  3421. BIT(NL80211_STA_FLAG_WME) |
  3422. BIT(NL80211_STA_FLAG_MFP);
  3423. break;
  3424. case NL80211_IFTYPE_P2P_CLIENT:
  3425. case NL80211_IFTYPE_STATION:
  3426. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3427. BIT(NL80211_STA_FLAG_TDLS_PEER);
  3428. break;
  3429. case NL80211_IFTYPE_MESH_POINT:
  3430. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3431. BIT(NL80211_STA_FLAG_MFP) |
  3432. BIT(NL80211_STA_FLAG_AUTHORIZED);
  3433. default:
  3434. return -EINVAL;
  3435. }
  3436. for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
  3437. if (flags[flag]) {
  3438. params->sta_flags_set |= (1<<flag);
  3439. /* no longer support new API additions in old API */
  3440. if (flag > NL80211_STA_FLAG_MAX_OLD_API)
  3441. return -EINVAL;
  3442. }
  3443. }
  3444. return 0;
  3445. }
  3446. static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
  3447. int attr)
  3448. {
  3449. struct nlattr *rate;
  3450. u32 bitrate;
  3451. u16 bitrate_compat;
  3452. enum nl80211_rate_info rate_flg;
  3453. rate = nla_nest_start(msg, attr);
  3454. if (!rate)
  3455. return false;
  3456. /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
  3457. bitrate = cfg80211_calculate_bitrate(info);
  3458. /* report 16-bit bitrate only if we can */
  3459. bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
  3460. if (bitrate > 0 &&
  3461. nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
  3462. return false;
  3463. if (bitrate_compat > 0 &&
  3464. nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
  3465. return false;
  3466. switch (info->bw) {
  3467. case RATE_INFO_BW_5:
  3468. rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
  3469. break;
  3470. case RATE_INFO_BW_10:
  3471. rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
  3472. break;
  3473. default:
  3474. WARN_ON(1);
  3475. /* fall through */
  3476. case RATE_INFO_BW_20:
  3477. rate_flg = 0;
  3478. break;
  3479. case RATE_INFO_BW_40:
  3480. rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
  3481. break;
  3482. case RATE_INFO_BW_80:
  3483. rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
  3484. break;
  3485. case RATE_INFO_BW_160:
  3486. rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
  3487. break;
  3488. }
  3489. if (rate_flg && nla_put_flag(msg, rate_flg))
  3490. return false;
  3491. if (info->flags & RATE_INFO_FLAGS_MCS) {
  3492. if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
  3493. return false;
  3494. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  3495. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  3496. return false;
  3497. } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
  3498. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
  3499. return false;
  3500. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
  3501. return false;
  3502. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  3503. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  3504. return false;
  3505. }
  3506. nla_nest_end(msg, rate);
  3507. return true;
  3508. }
  3509. static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
  3510. int id)
  3511. {
  3512. void *attr;
  3513. int i = 0;
  3514. if (!mask)
  3515. return true;
  3516. attr = nla_nest_start(msg, id);
  3517. if (!attr)
  3518. return false;
  3519. for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
  3520. if (!(mask & BIT(i)))
  3521. continue;
  3522. if (nla_put_u8(msg, i, signal[i]))
  3523. return false;
  3524. }
  3525. nla_nest_end(msg, attr);
  3526. return true;
  3527. }
  3528. static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
  3529. u32 seq, int flags,
  3530. struct cfg80211_registered_device *rdev,
  3531. struct net_device *dev,
  3532. const u8 *mac_addr, struct station_info *sinfo)
  3533. {
  3534. void *hdr;
  3535. struct nlattr *sinfoattr, *bss_param;
  3536. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  3537. if (!hdr)
  3538. return -1;
  3539. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  3540. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
  3541. nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
  3542. goto nla_put_failure;
  3543. sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
  3544. if (!sinfoattr)
  3545. goto nla_put_failure;
  3546. #define PUT_SINFO(attr, memb, type) do { \
  3547. BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
  3548. if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
  3549. nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
  3550. sinfo->memb)) \
  3551. goto nla_put_failure; \
  3552. } while (0)
  3553. #define PUT_SINFO_U64(attr, memb) do { \
  3554. if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
  3555. nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
  3556. sinfo->memb, NL80211_STA_INFO_PAD)) \
  3557. goto nla_put_failure; \
  3558. } while (0)
  3559. PUT_SINFO(CONNECTED_TIME, connected_time, u32);
  3560. PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
  3561. if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
  3562. BIT(NL80211_STA_INFO_RX_BYTES64)) &&
  3563. nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
  3564. (u32)sinfo->rx_bytes))
  3565. goto nla_put_failure;
  3566. if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
  3567. BIT(NL80211_STA_INFO_TX_BYTES64)) &&
  3568. nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
  3569. (u32)sinfo->tx_bytes))
  3570. goto nla_put_failure;
  3571. PUT_SINFO_U64(RX_BYTES64, rx_bytes);
  3572. PUT_SINFO_U64(TX_BYTES64, tx_bytes);
  3573. PUT_SINFO(LLID, llid, u16);
  3574. PUT_SINFO(PLID, plid, u16);
  3575. PUT_SINFO(PLINK_STATE, plink_state, u8);
  3576. PUT_SINFO_U64(RX_DURATION, rx_duration);
  3577. switch (rdev->wiphy.signal_type) {
  3578. case CFG80211_SIGNAL_TYPE_MBM:
  3579. PUT_SINFO(SIGNAL, signal, u8);
  3580. PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
  3581. break;
  3582. default:
  3583. break;
  3584. }
  3585. if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
  3586. if (!nl80211_put_signal(msg, sinfo->chains,
  3587. sinfo->chain_signal,
  3588. NL80211_STA_INFO_CHAIN_SIGNAL))
  3589. goto nla_put_failure;
  3590. }
  3591. if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
  3592. if (!nl80211_put_signal(msg, sinfo->chains,
  3593. sinfo->chain_signal_avg,
  3594. NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
  3595. goto nla_put_failure;
  3596. }
  3597. if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
  3598. if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
  3599. NL80211_STA_INFO_TX_BITRATE))
  3600. goto nla_put_failure;
  3601. }
  3602. if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
  3603. if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
  3604. NL80211_STA_INFO_RX_BITRATE))
  3605. goto nla_put_failure;
  3606. }
  3607. PUT_SINFO(RX_PACKETS, rx_packets, u32);
  3608. PUT_SINFO(TX_PACKETS, tx_packets, u32);
  3609. PUT_SINFO(TX_RETRIES, tx_retries, u32);
  3610. PUT_SINFO(TX_FAILED, tx_failed, u32);
  3611. PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
  3612. PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
  3613. PUT_SINFO(LOCAL_PM, local_pm, u32);
  3614. PUT_SINFO(PEER_PM, peer_pm, u32);
  3615. PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
  3616. if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
  3617. bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
  3618. if (!bss_param)
  3619. goto nla_put_failure;
  3620. if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
  3621. nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
  3622. ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
  3623. nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
  3624. ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
  3625. nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
  3626. nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
  3627. sinfo->bss_param.dtim_period) ||
  3628. nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
  3629. sinfo->bss_param.beacon_interval))
  3630. goto nla_put_failure;
  3631. nla_nest_end(msg, bss_param);
  3632. }
  3633. if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
  3634. nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
  3635. sizeof(struct nl80211_sta_flag_update),
  3636. &sinfo->sta_flags))
  3637. goto nla_put_failure;
  3638. PUT_SINFO_U64(T_OFFSET, t_offset);
  3639. PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
  3640. PUT_SINFO_U64(BEACON_RX, rx_beacon);
  3641. PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
  3642. #undef PUT_SINFO
  3643. #undef PUT_SINFO_U64
  3644. if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
  3645. struct nlattr *tidsattr;
  3646. int tid;
  3647. tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
  3648. if (!tidsattr)
  3649. goto nla_put_failure;
  3650. for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
  3651. struct cfg80211_tid_stats *tidstats;
  3652. struct nlattr *tidattr;
  3653. tidstats = &sinfo->pertid[tid];
  3654. if (!tidstats->filled)
  3655. continue;
  3656. tidattr = nla_nest_start(msg, tid + 1);
  3657. if (!tidattr)
  3658. goto nla_put_failure;
  3659. #define PUT_TIDVAL_U64(attr, memb) do { \
  3660. if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
  3661. nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
  3662. tidstats->memb, NL80211_TID_STATS_PAD)) \
  3663. goto nla_put_failure; \
  3664. } while (0)
  3665. PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
  3666. PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
  3667. PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
  3668. PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
  3669. #undef PUT_TIDVAL_U64
  3670. nla_nest_end(msg, tidattr);
  3671. }
  3672. nla_nest_end(msg, tidsattr);
  3673. }
  3674. nla_nest_end(msg, sinfoattr);
  3675. if (sinfo->assoc_req_ies_len &&
  3676. nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
  3677. sinfo->assoc_req_ies))
  3678. goto nla_put_failure;
  3679. genlmsg_end(msg, hdr);
  3680. return 0;
  3681. nla_put_failure:
  3682. genlmsg_cancel(msg, hdr);
  3683. return -EMSGSIZE;
  3684. }
  3685. static int nl80211_dump_station(struct sk_buff *skb,
  3686. struct netlink_callback *cb)
  3687. {
  3688. struct station_info sinfo;
  3689. struct cfg80211_registered_device *rdev;
  3690. struct wireless_dev *wdev;
  3691. u8 mac_addr[ETH_ALEN];
  3692. int sta_idx = cb->args[2];
  3693. int err;
  3694. rtnl_lock();
  3695. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  3696. if (err)
  3697. goto out_err;
  3698. if (!wdev->netdev) {
  3699. err = -EINVAL;
  3700. goto out_err;
  3701. }
  3702. if (!rdev->ops->dump_station) {
  3703. err = -EOPNOTSUPP;
  3704. goto out_err;
  3705. }
  3706. while (1) {
  3707. memset(&sinfo, 0, sizeof(sinfo));
  3708. err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
  3709. mac_addr, &sinfo);
  3710. if (err == -ENOENT)
  3711. break;
  3712. if (err)
  3713. goto out_err;
  3714. if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
  3715. NETLINK_CB(cb->skb).portid,
  3716. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  3717. rdev, wdev->netdev, mac_addr,
  3718. &sinfo) < 0)
  3719. goto out;
  3720. sta_idx++;
  3721. }
  3722. out:
  3723. cb->args[2] = sta_idx;
  3724. err = skb->len;
  3725. out_err:
  3726. rtnl_unlock();
  3727. return err;
  3728. }
  3729. static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
  3730. {
  3731. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3732. struct net_device *dev = info->user_ptr[1];
  3733. struct station_info sinfo;
  3734. struct sk_buff *msg;
  3735. u8 *mac_addr = NULL;
  3736. int err;
  3737. memset(&sinfo, 0, sizeof(sinfo));
  3738. if (!info->attrs[NL80211_ATTR_MAC])
  3739. return -EINVAL;
  3740. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3741. if (!rdev->ops->get_station)
  3742. return -EOPNOTSUPP;
  3743. err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
  3744. if (err)
  3745. return err;
  3746. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3747. if (!msg)
  3748. return -ENOMEM;
  3749. if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
  3750. info->snd_portid, info->snd_seq, 0,
  3751. rdev, dev, mac_addr, &sinfo) < 0) {
  3752. nlmsg_free(msg);
  3753. return -ENOBUFS;
  3754. }
  3755. return genlmsg_reply(msg, info);
  3756. }
  3757. int cfg80211_check_station_change(struct wiphy *wiphy,
  3758. struct station_parameters *params,
  3759. enum cfg80211_station_type statype)
  3760. {
  3761. if (params->listen_interval != -1 &&
  3762. statype != CFG80211_STA_AP_CLIENT_UNASSOC)
  3763. return -EINVAL;
  3764. if (params->support_p2p_ps != -1 &&
  3765. statype != CFG80211_STA_AP_CLIENT_UNASSOC)
  3766. return -EINVAL;
  3767. if (params->aid &&
  3768. !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  3769. statype != CFG80211_STA_AP_CLIENT_UNASSOC)
  3770. return -EINVAL;
  3771. /* When you run into this, adjust the code below for the new flag */
  3772. BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
  3773. switch (statype) {
  3774. case CFG80211_STA_MESH_PEER_KERNEL:
  3775. case CFG80211_STA_MESH_PEER_USER:
  3776. /*
  3777. * No ignoring the TDLS flag here -- the userspace mesh
  3778. * code doesn't have the bug of including TDLS in the
  3779. * mask everywhere.
  3780. */
  3781. if (params->sta_flags_mask &
  3782. ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3783. BIT(NL80211_STA_FLAG_MFP) |
  3784. BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3785. return -EINVAL;
  3786. break;
  3787. case CFG80211_STA_TDLS_PEER_SETUP:
  3788. case CFG80211_STA_TDLS_PEER_ACTIVE:
  3789. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3790. return -EINVAL;
  3791. /* ignore since it can't change */
  3792. params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3793. break;
  3794. default:
  3795. /* disallow mesh-specific things */
  3796. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
  3797. return -EINVAL;
  3798. if (params->local_pm)
  3799. return -EINVAL;
  3800. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  3801. return -EINVAL;
  3802. }
  3803. if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
  3804. statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
  3805. /* TDLS can't be set, ... */
  3806. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  3807. return -EINVAL;
  3808. /*
  3809. * ... but don't bother the driver with it. This works around
  3810. * a hostapd/wpa_supplicant issue -- it always includes the
  3811. * TLDS_PEER flag in the mask even for AP mode.
  3812. */
  3813. params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3814. }
  3815. if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
  3816. statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
  3817. /* reject other things that can't change */
  3818. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
  3819. return -EINVAL;
  3820. if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
  3821. return -EINVAL;
  3822. if (params->supported_rates)
  3823. return -EINVAL;
  3824. if (params->ext_capab || params->ht_capa || params->vht_capa)
  3825. return -EINVAL;
  3826. }
  3827. if (statype != CFG80211_STA_AP_CLIENT &&
  3828. statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
  3829. if (params->vlan)
  3830. return -EINVAL;
  3831. }
  3832. switch (statype) {
  3833. case CFG80211_STA_AP_MLME_CLIENT:
  3834. /* Use this only for authorizing/unauthorizing a station */
  3835. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3836. return -EOPNOTSUPP;
  3837. break;
  3838. case CFG80211_STA_AP_CLIENT:
  3839. case CFG80211_STA_AP_CLIENT_UNASSOC:
  3840. /* accept only the listed bits */
  3841. if (params->sta_flags_mask &
  3842. ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3843. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3844. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  3845. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  3846. BIT(NL80211_STA_FLAG_WME) |
  3847. BIT(NL80211_STA_FLAG_MFP)))
  3848. return -EINVAL;
  3849. /* but authenticated/associated only if driver handles it */
  3850. if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
  3851. params->sta_flags_mask &
  3852. (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3853. BIT(NL80211_STA_FLAG_ASSOCIATED)))
  3854. return -EINVAL;
  3855. break;
  3856. case CFG80211_STA_IBSS:
  3857. case CFG80211_STA_AP_STA:
  3858. /* reject any changes other than AUTHORIZED */
  3859. if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
  3860. return -EINVAL;
  3861. break;
  3862. case CFG80211_STA_TDLS_PEER_SETUP:
  3863. /* reject any changes other than AUTHORIZED or WME */
  3864. if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3865. BIT(NL80211_STA_FLAG_WME)))
  3866. return -EINVAL;
  3867. /* force (at least) rates when authorizing */
  3868. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
  3869. !params->supported_rates)
  3870. return -EINVAL;
  3871. break;
  3872. case CFG80211_STA_TDLS_PEER_ACTIVE:
  3873. /* reject any changes */
  3874. return -EINVAL;
  3875. case CFG80211_STA_MESH_PEER_KERNEL:
  3876. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  3877. return -EINVAL;
  3878. break;
  3879. case CFG80211_STA_MESH_PEER_USER:
  3880. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
  3881. params->plink_action != NL80211_PLINK_ACTION_BLOCK)
  3882. return -EINVAL;
  3883. break;
  3884. }
  3885. return 0;
  3886. }
  3887. EXPORT_SYMBOL(cfg80211_check_station_change);
  3888. /*
  3889. * Get vlan interface making sure it is running and on the right wiphy.
  3890. */
  3891. static struct net_device *get_vlan(struct genl_info *info,
  3892. struct cfg80211_registered_device *rdev)
  3893. {
  3894. struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
  3895. struct net_device *v;
  3896. int ret;
  3897. if (!vlanattr)
  3898. return NULL;
  3899. v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
  3900. if (!v)
  3901. return ERR_PTR(-ENODEV);
  3902. if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
  3903. ret = -EINVAL;
  3904. goto error;
  3905. }
  3906. if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  3907. v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3908. v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
  3909. ret = -EINVAL;
  3910. goto error;
  3911. }
  3912. if (!netif_running(v)) {
  3913. ret = -ENETDOWN;
  3914. goto error;
  3915. }
  3916. return v;
  3917. error:
  3918. dev_put(v);
  3919. return ERR_PTR(ret);
  3920. }
  3921. static const struct nla_policy
  3922. nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
  3923. [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
  3924. [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
  3925. };
  3926. static int nl80211_parse_sta_wme(struct genl_info *info,
  3927. struct station_parameters *params)
  3928. {
  3929. struct nlattr *tb[NL80211_STA_WME_MAX + 1];
  3930. struct nlattr *nla;
  3931. int err;
  3932. /* parse WME attributes if present */
  3933. if (!info->attrs[NL80211_ATTR_STA_WME])
  3934. return 0;
  3935. nla = info->attrs[NL80211_ATTR_STA_WME];
  3936. err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
  3937. nl80211_sta_wme_policy);
  3938. if (err)
  3939. return err;
  3940. if (tb[NL80211_STA_WME_UAPSD_QUEUES])
  3941. params->uapsd_queues = nla_get_u8(
  3942. tb[NL80211_STA_WME_UAPSD_QUEUES]);
  3943. if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  3944. return -EINVAL;
  3945. if (tb[NL80211_STA_WME_MAX_SP])
  3946. params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
  3947. if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  3948. return -EINVAL;
  3949. params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
  3950. return 0;
  3951. }
  3952. static int nl80211_parse_sta_channel_info(struct genl_info *info,
  3953. struct station_parameters *params)
  3954. {
  3955. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
  3956. params->supported_channels =
  3957. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  3958. params->supported_channels_len =
  3959. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  3960. /*
  3961. * Need to include at least one (first channel, number of
  3962. * channels) tuple for each subband, and must have proper
  3963. * tuples for the rest of the data as well.
  3964. */
  3965. if (params->supported_channels_len < 2)
  3966. return -EINVAL;
  3967. if (params->supported_channels_len % 2)
  3968. return -EINVAL;
  3969. }
  3970. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
  3971. params->supported_oper_classes =
  3972. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  3973. params->supported_oper_classes_len =
  3974. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  3975. /*
  3976. * The value of the Length field of the Supported Operating
  3977. * Classes element is between 2 and 253.
  3978. */
  3979. if (params->supported_oper_classes_len < 2 ||
  3980. params->supported_oper_classes_len > 253)
  3981. return -EINVAL;
  3982. }
  3983. return 0;
  3984. }
  3985. static int nl80211_set_station_tdls(struct genl_info *info,
  3986. struct station_parameters *params)
  3987. {
  3988. int err;
  3989. /* Dummy STA entry gets updated once the peer capabilities are known */
  3990. if (info->attrs[NL80211_ATTR_PEER_AID])
  3991. params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  3992. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  3993. params->ht_capa =
  3994. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  3995. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  3996. params->vht_capa =
  3997. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  3998. err = nl80211_parse_sta_channel_info(info, params);
  3999. if (err)
  4000. return err;
  4001. return nl80211_parse_sta_wme(info, params);
  4002. }
  4003. static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
  4004. {
  4005. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4006. struct net_device *dev = info->user_ptr[1];
  4007. struct station_parameters params;
  4008. u8 *mac_addr;
  4009. int err;
  4010. memset(&params, 0, sizeof(params));
  4011. if (!rdev->ops->change_station)
  4012. return -EOPNOTSUPP;
  4013. /*
  4014. * AID and listen_interval properties can be set only for unassociated
  4015. * station. Include these parameters here and will check them in
  4016. * cfg80211_check_station_change().
  4017. */
  4018. if (info->attrs[NL80211_ATTR_STA_AID])
  4019. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
  4020. if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  4021. params.listen_interval =
  4022. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  4023. else
  4024. params.listen_interval = -1;
  4025. if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
  4026. u8 tmp;
  4027. tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
  4028. if (tmp >= NUM_NL80211_P2P_PS_STATUS)
  4029. return -EINVAL;
  4030. params.support_p2p_ps = tmp;
  4031. } else {
  4032. params.support_p2p_ps = -1;
  4033. }
  4034. if (!info->attrs[NL80211_ATTR_MAC])
  4035. return -EINVAL;
  4036. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4037. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
  4038. params.supported_rates =
  4039. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4040. params.supported_rates_len =
  4041. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4042. }
  4043. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  4044. params.capability =
  4045. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  4046. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  4047. }
  4048. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  4049. params.ext_capab =
  4050. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4051. params.ext_capab_len =
  4052. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4053. }
  4054. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  4055. return -EINVAL;
  4056. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
  4057. params.plink_action =
  4058. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  4059. if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
  4060. return -EINVAL;
  4061. }
  4062. if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
  4063. params.plink_state =
  4064. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
  4065. if (params.plink_state >= NUM_NL80211_PLINK_STATES)
  4066. return -EINVAL;
  4067. if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
  4068. params.peer_aid = nla_get_u16(
  4069. info->attrs[NL80211_ATTR_MESH_PEER_AID]);
  4070. if (params.peer_aid > IEEE80211_MAX_AID)
  4071. return -EINVAL;
  4072. }
  4073. params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
  4074. }
  4075. if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
  4076. enum nl80211_mesh_power_mode pm = nla_get_u32(
  4077. info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
  4078. if (pm <= NL80211_MESH_POWER_UNKNOWN ||
  4079. pm > NL80211_MESH_POWER_MAX)
  4080. return -EINVAL;
  4081. params.local_pm = pm;
  4082. }
  4083. /* Include parameters for TDLS peer (will check later) */
  4084. err = nl80211_set_station_tdls(info, &params);
  4085. if (err)
  4086. return err;
  4087. params.vlan = get_vlan(info, rdev);
  4088. if (IS_ERR(params.vlan))
  4089. return PTR_ERR(params.vlan);
  4090. switch (dev->ieee80211_ptr->iftype) {
  4091. case NL80211_IFTYPE_AP:
  4092. case NL80211_IFTYPE_AP_VLAN:
  4093. case NL80211_IFTYPE_P2P_GO:
  4094. case NL80211_IFTYPE_P2P_CLIENT:
  4095. case NL80211_IFTYPE_STATION:
  4096. case NL80211_IFTYPE_ADHOC:
  4097. case NL80211_IFTYPE_MESH_POINT:
  4098. break;
  4099. default:
  4100. err = -EOPNOTSUPP;
  4101. goto out_put_vlan;
  4102. }
  4103. /* driver will call cfg80211_check_station_change() */
  4104. err = rdev_change_station(rdev, dev, mac_addr, &params);
  4105. out_put_vlan:
  4106. if (params.vlan)
  4107. dev_put(params.vlan);
  4108. return err;
  4109. }
  4110. static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
  4111. {
  4112. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4113. int err;
  4114. struct net_device *dev = info->user_ptr[1];
  4115. struct station_parameters params;
  4116. u8 *mac_addr = NULL;
  4117. u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  4118. BIT(NL80211_STA_FLAG_ASSOCIATED);
  4119. memset(&params, 0, sizeof(params));
  4120. if (!rdev->ops->add_station)
  4121. return -EOPNOTSUPP;
  4122. if (!info->attrs[NL80211_ATTR_MAC])
  4123. return -EINVAL;
  4124. if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  4125. return -EINVAL;
  4126. if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
  4127. return -EINVAL;
  4128. if (!info->attrs[NL80211_ATTR_STA_AID] &&
  4129. !info->attrs[NL80211_ATTR_PEER_AID])
  4130. return -EINVAL;
  4131. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4132. params.supported_rates =
  4133. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4134. params.supported_rates_len =
  4135. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4136. params.listen_interval =
  4137. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  4138. if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
  4139. u8 tmp;
  4140. tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
  4141. if (tmp >= NUM_NL80211_P2P_PS_STATUS)
  4142. return -EINVAL;
  4143. params.support_p2p_ps = tmp;
  4144. } else {
  4145. /*
  4146. * if not specified, assume it's supported for P2P GO interface,
  4147. * and is NOT supported for AP interface
  4148. */
  4149. params.support_p2p_ps =
  4150. dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
  4151. }
  4152. if (info->attrs[NL80211_ATTR_PEER_AID])
  4153. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  4154. else
  4155. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
  4156. if (!params.aid || params.aid > IEEE80211_MAX_AID)
  4157. return -EINVAL;
  4158. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  4159. params.capability =
  4160. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  4161. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  4162. }
  4163. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  4164. params.ext_capab =
  4165. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4166. params.ext_capab_len =
  4167. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4168. }
  4169. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  4170. params.ht_capa =
  4171. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  4172. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  4173. params.vht_capa =
  4174. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  4175. if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
  4176. params.opmode_notif_used = true;
  4177. params.opmode_notif =
  4178. nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
  4179. }
  4180. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
  4181. params.plink_action =
  4182. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  4183. if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
  4184. return -EINVAL;
  4185. }
  4186. err = nl80211_parse_sta_channel_info(info, &params);
  4187. if (err)
  4188. return err;
  4189. err = nl80211_parse_sta_wme(info, &params);
  4190. if (err)
  4191. return err;
  4192. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  4193. return -EINVAL;
  4194. /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
  4195. * as userspace might just pass through the capabilities from the IEs
  4196. * directly, rather than enforcing this restriction and returning an
  4197. * error in this case.
  4198. */
  4199. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
  4200. params.ht_capa = NULL;
  4201. params.vht_capa = NULL;
  4202. }
  4203. /* When you run into this, adjust the code below for the new flag */
  4204. BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
  4205. switch (dev->ieee80211_ptr->iftype) {
  4206. case NL80211_IFTYPE_AP:
  4207. case NL80211_IFTYPE_AP_VLAN:
  4208. case NL80211_IFTYPE_P2P_GO:
  4209. /* ignore WME attributes if iface/sta is not capable */
  4210. if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
  4211. !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
  4212. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  4213. /* TDLS peers cannot be added */
  4214. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  4215. info->attrs[NL80211_ATTR_PEER_AID])
  4216. return -EINVAL;
  4217. /* but don't bother the driver with it */
  4218. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  4219. /* allow authenticated/associated only if driver handles it */
  4220. if (!(rdev->wiphy.features &
  4221. NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
  4222. params.sta_flags_mask & auth_assoc)
  4223. return -EINVAL;
  4224. /* Older userspace, or userspace wanting to be compatible with
  4225. * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
  4226. * and assoc flags in the mask, but assumes the station will be
  4227. * added as associated anyway since this was the required driver
  4228. * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
  4229. * introduced.
  4230. * In order to not bother drivers with this quirk in the API
  4231. * set the flags in both the mask and set for new stations in
  4232. * this case.
  4233. */
  4234. if (!(params.sta_flags_mask & auth_assoc)) {
  4235. params.sta_flags_mask |= auth_assoc;
  4236. params.sta_flags_set |= auth_assoc;
  4237. }
  4238. /* must be last in here for error handling */
  4239. params.vlan = get_vlan(info, rdev);
  4240. if (IS_ERR(params.vlan))
  4241. return PTR_ERR(params.vlan);
  4242. break;
  4243. case NL80211_IFTYPE_MESH_POINT:
  4244. /* ignore uAPSD data */
  4245. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  4246. /* associated is disallowed */
  4247. if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
  4248. return -EINVAL;
  4249. /* TDLS peers cannot be added */
  4250. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  4251. info->attrs[NL80211_ATTR_PEER_AID])
  4252. return -EINVAL;
  4253. break;
  4254. case NL80211_IFTYPE_STATION:
  4255. case NL80211_IFTYPE_P2P_CLIENT:
  4256. /* ignore uAPSD data */
  4257. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  4258. /* these are disallowed */
  4259. if (params.sta_flags_mask &
  4260. (BIT(NL80211_STA_FLAG_ASSOCIATED) |
  4261. BIT(NL80211_STA_FLAG_AUTHENTICATED)))
  4262. return -EINVAL;
  4263. /* Only TDLS peers can be added */
  4264. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  4265. return -EINVAL;
  4266. /* Can only add if TDLS ... */
  4267. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
  4268. return -EOPNOTSUPP;
  4269. /* ... with external setup is supported */
  4270. if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
  4271. return -EOPNOTSUPP;
  4272. /*
  4273. * Older wpa_supplicant versions always mark the TDLS peer
  4274. * as authorized, but it shouldn't yet be.
  4275. */
  4276. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
  4277. break;
  4278. default:
  4279. return -EOPNOTSUPP;
  4280. }
  4281. /* be aware of params.vlan when changing code here */
  4282. err = rdev_add_station(rdev, dev, mac_addr, &params);
  4283. if (params.vlan)
  4284. dev_put(params.vlan);
  4285. return err;
  4286. }
  4287. static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
  4288. {
  4289. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4290. struct net_device *dev = info->user_ptr[1];
  4291. struct station_del_parameters params;
  4292. memset(&params, 0, sizeof(params));
  4293. if (info->attrs[NL80211_ATTR_MAC])
  4294. params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4295. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  4296. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  4297. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  4298. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4299. return -EINVAL;
  4300. if (!rdev->ops->del_station)
  4301. return -EOPNOTSUPP;
  4302. if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
  4303. params.subtype =
  4304. nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
  4305. if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
  4306. params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
  4307. return -EINVAL;
  4308. } else {
  4309. /* Default to Deauthentication frame */
  4310. params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
  4311. }
  4312. if (info->attrs[NL80211_ATTR_REASON_CODE]) {
  4313. params.reason_code =
  4314. nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  4315. if (params.reason_code == 0)
  4316. return -EINVAL; /* 0 is reserved */
  4317. } else {
  4318. /* Default to reason code 2 */
  4319. params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
  4320. }
  4321. return rdev_del_station(rdev, dev, &params);
  4322. }
  4323. static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
  4324. int flags, struct net_device *dev,
  4325. u8 *dst, u8 *next_hop,
  4326. struct mpath_info *pinfo)
  4327. {
  4328. void *hdr;
  4329. struct nlattr *pinfoattr;
  4330. hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
  4331. if (!hdr)
  4332. return -1;
  4333. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  4334. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
  4335. nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
  4336. nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
  4337. goto nla_put_failure;
  4338. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
  4339. if (!pinfoattr)
  4340. goto nla_put_failure;
  4341. if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
  4342. nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
  4343. pinfo->frame_qlen))
  4344. goto nla_put_failure;
  4345. if (((pinfo->filled & MPATH_INFO_SN) &&
  4346. nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
  4347. ((pinfo->filled & MPATH_INFO_METRIC) &&
  4348. nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
  4349. pinfo->metric)) ||
  4350. ((pinfo->filled & MPATH_INFO_EXPTIME) &&
  4351. nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
  4352. pinfo->exptime)) ||
  4353. ((pinfo->filled & MPATH_INFO_FLAGS) &&
  4354. nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
  4355. pinfo->flags)) ||
  4356. ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
  4357. nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
  4358. pinfo->discovery_timeout)) ||
  4359. ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
  4360. nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
  4361. pinfo->discovery_retries)))
  4362. goto nla_put_failure;
  4363. nla_nest_end(msg, pinfoattr);
  4364. genlmsg_end(msg, hdr);
  4365. return 0;
  4366. nla_put_failure:
  4367. genlmsg_cancel(msg, hdr);
  4368. return -EMSGSIZE;
  4369. }
  4370. static int nl80211_dump_mpath(struct sk_buff *skb,
  4371. struct netlink_callback *cb)
  4372. {
  4373. struct mpath_info pinfo;
  4374. struct cfg80211_registered_device *rdev;
  4375. struct wireless_dev *wdev;
  4376. u8 dst[ETH_ALEN];
  4377. u8 next_hop[ETH_ALEN];
  4378. int path_idx = cb->args[2];
  4379. int err;
  4380. rtnl_lock();
  4381. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  4382. if (err)
  4383. goto out_err;
  4384. if (!rdev->ops->dump_mpath) {
  4385. err = -EOPNOTSUPP;
  4386. goto out_err;
  4387. }
  4388. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
  4389. err = -EOPNOTSUPP;
  4390. goto out_err;
  4391. }
  4392. while (1) {
  4393. err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
  4394. next_hop, &pinfo);
  4395. if (err == -ENOENT)
  4396. break;
  4397. if (err)
  4398. goto out_err;
  4399. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
  4400. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4401. wdev->netdev, dst, next_hop,
  4402. &pinfo) < 0)
  4403. goto out;
  4404. path_idx++;
  4405. }
  4406. out:
  4407. cb->args[2] = path_idx;
  4408. err = skb->len;
  4409. out_err:
  4410. rtnl_unlock();
  4411. return err;
  4412. }
  4413. static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
  4414. {
  4415. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4416. int err;
  4417. struct net_device *dev = info->user_ptr[1];
  4418. struct mpath_info pinfo;
  4419. struct sk_buff *msg;
  4420. u8 *dst = NULL;
  4421. u8 next_hop[ETH_ALEN];
  4422. memset(&pinfo, 0, sizeof(pinfo));
  4423. if (!info->attrs[NL80211_ATTR_MAC])
  4424. return -EINVAL;
  4425. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4426. if (!rdev->ops->get_mpath)
  4427. return -EOPNOTSUPP;
  4428. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4429. return -EOPNOTSUPP;
  4430. err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
  4431. if (err)
  4432. return err;
  4433. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4434. if (!msg)
  4435. return -ENOMEM;
  4436. if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
  4437. dev, dst, next_hop, &pinfo) < 0) {
  4438. nlmsg_free(msg);
  4439. return -ENOBUFS;
  4440. }
  4441. return genlmsg_reply(msg, info);
  4442. }
  4443. static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
  4444. {
  4445. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4446. struct net_device *dev = info->user_ptr[1];
  4447. u8 *dst = NULL;
  4448. u8 *next_hop = NULL;
  4449. if (!info->attrs[NL80211_ATTR_MAC])
  4450. return -EINVAL;
  4451. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  4452. return -EINVAL;
  4453. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4454. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  4455. if (!rdev->ops->change_mpath)
  4456. return -EOPNOTSUPP;
  4457. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4458. return -EOPNOTSUPP;
  4459. return rdev_change_mpath(rdev, dev, dst, next_hop);
  4460. }
  4461. static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
  4462. {
  4463. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4464. struct net_device *dev = info->user_ptr[1];
  4465. u8 *dst = NULL;
  4466. u8 *next_hop = NULL;
  4467. if (!info->attrs[NL80211_ATTR_MAC])
  4468. return -EINVAL;
  4469. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  4470. return -EINVAL;
  4471. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4472. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  4473. if (!rdev->ops->add_mpath)
  4474. return -EOPNOTSUPP;
  4475. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4476. return -EOPNOTSUPP;
  4477. return rdev_add_mpath(rdev, dev, dst, next_hop);
  4478. }
  4479. static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
  4480. {
  4481. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4482. struct net_device *dev = info->user_ptr[1];
  4483. u8 *dst = NULL;
  4484. if (info->attrs[NL80211_ATTR_MAC])
  4485. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4486. if (!rdev->ops->del_mpath)
  4487. return -EOPNOTSUPP;
  4488. return rdev_del_mpath(rdev, dev, dst);
  4489. }
  4490. static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
  4491. {
  4492. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4493. int err;
  4494. struct net_device *dev = info->user_ptr[1];
  4495. struct mpath_info pinfo;
  4496. struct sk_buff *msg;
  4497. u8 *dst = NULL;
  4498. u8 mpp[ETH_ALEN];
  4499. memset(&pinfo, 0, sizeof(pinfo));
  4500. if (!info->attrs[NL80211_ATTR_MAC])
  4501. return -EINVAL;
  4502. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4503. if (!rdev->ops->get_mpp)
  4504. return -EOPNOTSUPP;
  4505. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4506. return -EOPNOTSUPP;
  4507. err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
  4508. if (err)
  4509. return err;
  4510. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4511. if (!msg)
  4512. return -ENOMEM;
  4513. if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
  4514. dev, dst, mpp, &pinfo) < 0) {
  4515. nlmsg_free(msg);
  4516. return -ENOBUFS;
  4517. }
  4518. return genlmsg_reply(msg, info);
  4519. }
  4520. static int nl80211_dump_mpp(struct sk_buff *skb,
  4521. struct netlink_callback *cb)
  4522. {
  4523. struct mpath_info pinfo;
  4524. struct cfg80211_registered_device *rdev;
  4525. struct wireless_dev *wdev;
  4526. u8 dst[ETH_ALEN];
  4527. u8 mpp[ETH_ALEN];
  4528. int path_idx = cb->args[2];
  4529. int err;
  4530. rtnl_lock();
  4531. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  4532. if (err)
  4533. goto out_err;
  4534. if (!rdev->ops->dump_mpp) {
  4535. err = -EOPNOTSUPP;
  4536. goto out_err;
  4537. }
  4538. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
  4539. err = -EOPNOTSUPP;
  4540. goto out_err;
  4541. }
  4542. while (1) {
  4543. err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
  4544. mpp, &pinfo);
  4545. if (err == -ENOENT)
  4546. break;
  4547. if (err)
  4548. goto out_err;
  4549. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
  4550. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4551. wdev->netdev, dst, mpp,
  4552. &pinfo) < 0)
  4553. goto out;
  4554. path_idx++;
  4555. }
  4556. out:
  4557. cb->args[2] = path_idx;
  4558. err = skb->len;
  4559. out_err:
  4560. rtnl_unlock();
  4561. return err;
  4562. }
  4563. static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
  4564. {
  4565. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4566. struct net_device *dev = info->user_ptr[1];
  4567. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4568. struct bss_parameters params;
  4569. int err;
  4570. memset(&params, 0, sizeof(params));
  4571. /* default to not changing parameters */
  4572. params.use_cts_prot = -1;
  4573. params.use_short_preamble = -1;
  4574. params.use_short_slot_time = -1;
  4575. params.ap_isolate = -1;
  4576. params.ht_opmode = -1;
  4577. params.p2p_ctwindow = -1;
  4578. params.p2p_opp_ps = -1;
  4579. if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
  4580. params.use_cts_prot =
  4581. nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
  4582. if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
  4583. params.use_short_preamble =
  4584. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
  4585. if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
  4586. params.use_short_slot_time =
  4587. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
  4588. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  4589. params.basic_rates =
  4590. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4591. params.basic_rates_len =
  4592. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4593. }
  4594. if (info->attrs[NL80211_ATTR_AP_ISOLATE])
  4595. params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
  4596. if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
  4597. params.ht_opmode =
  4598. nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
  4599. if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
  4600. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4601. return -EINVAL;
  4602. params.p2p_ctwindow =
  4603. nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
  4604. if (params.p2p_ctwindow < 0)
  4605. return -EINVAL;
  4606. if (params.p2p_ctwindow != 0 &&
  4607. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
  4608. return -EINVAL;
  4609. }
  4610. if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
  4611. u8 tmp;
  4612. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4613. return -EINVAL;
  4614. tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
  4615. if (tmp > 1)
  4616. return -EINVAL;
  4617. params.p2p_opp_ps = tmp;
  4618. if (params.p2p_opp_ps &&
  4619. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
  4620. return -EINVAL;
  4621. }
  4622. if (!rdev->ops->change_bss)
  4623. return -EOPNOTSUPP;
  4624. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  4625. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4626. return -EOPNOTSUPP;
  4627. wdev_lock(wdev);
  4628. err = rdev_change_bss(rdev, dev, &params);
  4629. wdev_unlock(wdev);
  4630. return err;
  4631. }
  4632. static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
  4633. {
  4634. char *data = NULL;
  4635. bool is_indoor;
  4636. enum nl80211_user_reg_hint_type user_reg_hint_type;
  4637. u32 owner_nlportid;
  4638. /*
  4639. * You should only get this when cfg80211 hasn't yet initialized
  4640. * completely when built-in to the kernel right between the time
  4641. * window between nl80211_init() and regulatory_init(), if that is
  4642. * even possible.
  4643. */
  4644. if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
  4645. return -EINPROGRESS;
  4646. if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
  4647. user_reg_hint_type =
  4648. nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
  4649. else
  4650. user_reg_hint_type = NL80211_USER_REG_HINT_USER;
  4651. switch (user_reg_hint_type) {
  4652. case NL80211_USER_REG_HINT_USER:
  4653. case NL80211_USER_REG_HINT_CELL_BASE:
  4654. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  4655. return -EINVAL;
  4656. data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  4657. return regulatory_hint_user(data, user_reg_hint_type);
  4658. case NL80211_USER_REG_HINT_INDOOR:
  4659. if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
  4660. owner_nlportid = info->snd_portid;
  4661. is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
  4662. } else {
  4663. owner_nlportid = 0;
  4664. is_indoor = true;
  4665. }
  4666. return regulatory_hint_indoor(is_indoor, owner_nlportid);
  4667. default:
  4668. return -EINVAL;
  4669. }
  4670. }
  4671. static int nl80211_get_mesh_config(struct sk_buff *skb,
  4672. struct genl_info *info)
  4673. {
  4674. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4675. struct net_device *dev = info->user_ptr[1];
  4676. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4677. struct mesh_config cur_params;
  4678. int err = 0;
  4679. void *hdr;
  4680. struct nlattr *pinfoattr;
  4681. struct sk_buff *msg;
  4682. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  4683. return -EOPNOTSUPP;
  4684. if (!rdev->ops->get_mesh_config)
  4685. return -EOPNOTSUPP;
  4686. wdev_lock(wdev);
  4687. /* If not connected, get default parameters */
  4688. if (!wdev->mesh_id_len)
  4689. memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
  4690. else
  4691. err = rdev_get_mesh_config(rdev, dev, &cur_params);
  4692. wdev_unlock(wdev);
  4693. if (err)
  4694. return err;
  4695. /* Draw up a netlink message to send back */
  4696. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4697. if (!msg)
  4698. return -ENOMEM;
  4699. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  4700. NL80211_CMD_GET_MESH_CONFIG);
  4701. if (!hdr)
  4702. goto out;
  4703. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
  4704. if (!pinfoattr)
  4705. goto nla_put_failure;
  4706. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  4707. nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
  4708. cur_params.dot11MeshRetryTimeout) ||
  4709. nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  4710. cur_params.dot11MeshConfirmTimeout) ||
  4711. nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
  4712. cur_params.dot11MeshHoldingTimeout) ||
  4713. nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
  4714. cur_params.dot11MeshMaxPeerLinks) ||
  4715. nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
  4716. cur_params.dot11MeshMaxRetries) ||
  4717. nla_put_u8(msg, NL80211_MESHCONF_TTL,
  4718. cur_params.dot11MeshTTL) ||
  4719. nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
  4720. cur_params.element_ttl) ||
  4721. nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  4722. cur_params.auto_open_plinks) ||
  4723. nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
  4724. cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
  4725. nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  4726. cur_params.dot11MeshHWMPmaxPREQretries) ||
  4727. nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
  4728. cur_params.path_refresh_time) ||
  4729. nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  4730. cur_params.min_discovery_timeout) ||
  4731. nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  4732. cur_params.dot11MeshHWMPactivePathTimeout) ||
  4733. nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  4734. cur_params.dot11MeshHWMPpreqMinInterval) ||
  4735. nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  4736. cur_params.dot11MeshHWMPperrMinInterval) ||
  4737. nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  4738. cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
  4739. nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
  4740. cur_params.dot11MeshHWMPRootMode) ||
  4741. nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  4742. cur_params.dot11MeshHWMPRannInterval) ||
  4743. nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  4744. cur_params.dot11MeshGateAnnouncementProtocol) ||
  4745. nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
  4746. cur_params.dot11MeshForwarding) ||
  4747. nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
  4748. cur_params.rssi_threshold) ||
  4749. nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
  4750. cur_params.ht_opmode) ||
  4751. nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  4752. cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
  4753. nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  4754. cur_params.dot11MeshHWMProotInterval) ||
  4755. nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
  4756. cur_params.dot11MeshHWMPconfirmationInterval) ||
  4757. nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
  4758. cur_params.power_mode) ||
  4759. nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
  4760. cur_params.dot11MeshAwakeWindowDuration) ||
  4761. nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
  4762. cur_params.plink_timeout))
  4763. goto nla_put_failure;
  4764. nla_nest_end(msg, pinfoattr);
  4765. genlmsg_end(msg, hdr);
  4766. return genlmsg_reply(msg, info);
  4767. nla_put_failure:
  4768. genlmsg_cancel(msg, hdr);
  4769. out:
  4770. nlmsg_free(msg);
  4771. return -ENOBUFS;
  4772. }
  4773. static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
  4774. [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
  4775. [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
  4776. [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
  4777. [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
  4778. [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
  4779. [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
  4780. [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
  4781. [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
  4782. [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
  4783. [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
  4784. [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
  4785. [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
  4786. [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
  4787. [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
  4788. [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
  4789. [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
  4790. [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
  4791. [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
  4792. [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
  4793. [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
  4794. [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
  4795. [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
  4796. [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
  4797. [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
  4798. [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
  4799. [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
  4800. [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
  4801. [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
  4802. };
  4803. static const struct nla_policy
  4804. nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
  4805. [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
  4806. [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
  4807. [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
  4808. [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
  4809. [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
  4810. [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
  4811. [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
  4812. .len = IEEE80211_MAX_DATA_LEN },
  4813. [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
  4814. };
  4815. static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
  4816. {
  4817. u8 val = nla_get_u8(nla);
  4818. if (val < min || val > max)
  4819. return -EINVAL;
  4820. *out = val;
  4821. return 0;
  4822. }
  4823. static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
  4824. {
  4825. u8 val = nla_get_u8(nla);
  4826. if (val < min || val > max)
  4827. return -EINVAL;
  4828. *out = val;
  4829. return 0;
  4830. }
  4831. static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
  4832. {
  4833. u16 val = nla_get_u16(nla);
  4834. if (val < min || val > max)
  4835. return -EINVAL;
  4836. *out = val;
  4837. return 0;
  4838. }
  4839. static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
  4840. {
  4841. u32 val = nla_get_u32(nla);
  4842. if (val < min || val > max)
  4843. return -EINVAL;
  4844. *out = val;
  4845. return 0;
  4846. }
  4847. static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
  4848. {
  4849. s32 val = nla_get_s32(nla);
  4850. if (val < min || val > max)
  4851. return -EINVAL;
  4852. *out = val;
  4853. return 0;
  4854. }
  4855. static int nl80211_check_power_mode(const struct nlattr *nla,
  4856. enum nl80211_mesh_power_mode min,
  4857. enum nl80211_mesh_power_mode max,
  4858. enum nl80211_mesh_power_mode *out)
  4859. {
  4860. u32 val = nla_get_u32(nla);
  4861. if (val < min || val > max)
  4862. return -EINVAL;
  4863. *out = val;
  4864. return 0;
  4865. }
  4866. static int nl80211_parse_mesh_config(struct genl_info *info,
  4867. struct mesh_config *cfg,
  4868. u32 *mask_out)
  4869. {
  4870. struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
  4871. u32 mask = 0;
  4872. u16 ht_opmode;
  4873. #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
  4874. do { \
  4875. if (tb[attr]) { \
  4876. if (fn(tb[attr], min, max, &cfg->param)) \
  4877. return -EINVAL; \
  4878. mask |= (1 << (attr - 1)); \
  4879. } \
  4880. } while (0)
  4881. if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
  4882. return -EINVAL;
  4883. if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
  4884. info->attrs[NL80211_ATTR_MESH_CONFIG],
  4885. nl80211_meshconf_params_policy))
  4886. return -EINVAL;
  4887. /* This makes sure that there aren't more than 32 mesh config
  4888. * parameters (otherwise our bitfield scheme would not work.) */
  4889. BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
  4890. /* Fill in the params struct */
  4891. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
  4892. mask, NL80211_MESHCONF_RETRY_TIMEOUT,
  4893. nl80211_check_u16);
  4894. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
  4895. mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  4896. nl80211_check_u16);
  4897. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
  4898. mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
  4899. nl80211_check_u16);
  4900. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
  4901. mask, NL80211_MESHCONF_MAX_PEER_LINKS,
  4902. nl80211_check_u16);
  4903. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
  4904. mask, NL80211_MESHCONF_MAX_RETRIES,
  4905. nl80211_check_u8);
  4906. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
  4907. mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
  4908. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
  4909. mask, NL80211_MESHCONF_ELEMENT_TTL,
  4910. nl80211_check_u8);
  4911. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
  4912. mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  4913. nl80211_check_bool);
  4914. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
  4915. 1, 255, mask,
  4916. NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
  4917. nl80211_check_u32);
  4918. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
  4919. mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  4920. nl80211_check_u8);
  4921. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
  4922. mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
  4923. nl80211_check_u32);
  4924. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
  4925. mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  4926. nl80211_check_u16);
  4927. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
  4928. 1, 65535, mask,
  4929. NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  4930. nl80211_check_u32);
  4931. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
  4932. 1, 65535, mask,
  4933. NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  4934. nl80211_check_u16);
  4935. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
  4936. 1, 65535, mask,
  4937. NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  4938. nl80211_check_u16);
  4939. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  4940. dot11MeshHWMPnetDiameterTraversalTime,
  4941. 1, 65535, mask,
  4942. NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  4943. nl80211_check_u16);
  4944. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
  4945. mask, NL80211_MESHCONF_HWMP_ROOTMODE,
  4946. nl80211_check_u8);
  4947. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
  4948. mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  4949. nl80211_check_u16);
  4950. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  4951. dot11MeshGateAnnouncementProtocol, 0, 1,
  4952. mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  4953. nl80211_check_bool);
  4954. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
  4955. mask, NL80211_MESHCONF_FORWARDING,
  4956. nl80211_check_bool);
  4957. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
  4958. mask, NL80211_MESHCONF_RSSI_THRESHOLD,
  4959. nl80211_check_s32);
  4960. /*
  4961. * Check HT operation mode based on
  4962. * IEEE 802.11 2012 8.4.2.59 HT Operation element.
  4963. */
  4964. if (tb[NL80211_MESHCONF_HT_OPMODE]) {
  4965. ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
  4966. if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
  4967. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
  4968. IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
  4969. return -EINVAL;
  4970. if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) &&
  4971. (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
  4972. return -EINVAL;
  4973. switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) {
  4974. case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
  4975. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  4976. if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)
  4977. return -EINVAL;
  4978. break;
  4979. case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
  4980. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  4981. if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
  4982. return -EINVAL;
  4983. break;
  4984. }
  4985. cfg->ht_opmode = ht_opmode;
  4986. mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
  4987. }
  4988. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
  4989. 1, 65535, mask,
  4990. NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  4991. nl80211_check_u32);
  4992. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
  4993. mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  4994. nl80211_check_u16);
  4995. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  4996. dot11MeshHWMPconfirmationInterval,
  4997. 1, 65535, mask,
  4998. NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
  4999. nl80211_check_u16);
  5000. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
  5001. NL80211_MESH_POWER_ACTIVE,
  5002. NL80211_MESH_POWER_MAX,
  5003. mask, NL80211_MESHCONF_POWER_MODE,
  5004. nl80211_check_power_mode);
  5005. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
  5006. 0, 65535, mask,
  5007. NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
  5008. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
  5009. mask, NL80211_MESHCONF_PLINK_TIMEOUT,
  5010. nl80211_check_u32);
  5011. if (mask_out)
  5012. *mask_out = mask;
  5013. return 0;
  5014. #undef FILL_IN_MESH_PARAM_IF_SET
  5015. }
  5016. static int nl80211_parse_mesh_setup(struct genl_info *info,
  5017. struct mesh_setup *setup)
  5018. {
  5019. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5020. struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
  5021. if (!info->attrs[NL80211_ATTR_MESH_SETUP])
  5022. return -EINVAL;
  5023. if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
  5024. info->attrs[NL80211_ATTR_MESH_SETUP],
  5025. nl80211_mesh_setup_params_policy))
  5026. return -EINVAL;
  5027. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
  5028. setup->sync_method =
  5029. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
  5030. IEEE80211_SYNC_METHOD_VENDOR :
  5031. IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
  5032. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
  5033. setup->path_sel_proto =
  5034. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
  5035. IEEE80211_PATH_PROTOCOL_VENDOR :
  5036. IEEE80211_PATH_PROTOCOL_HWMP;
  5037. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
  5038. setup->path_metric =
  5039. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
  5040. IEEE80211_PATH_METRIC_VENDOR :
  5041. IEEE80211_PATH_METRIC_AIRTIME;
  5042. if (tb[NL80211_MESH_SETUP_IE]) {
  5043. struct nlattr *ieattr =
  5044. tb[NL80211_MESH_SETUP_IE];
  5045. if (!is_valid_ie_attr(ieattr))
  5046. return -EINVAL;
  5047. setup->ie = nla_data(ieattr);
  5048. setup->ie_len = nla_len(ieattr);
  5049. }
  5050. if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
  5051. !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
  5052. return -EINVAL;
  5053. setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
  5054. setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
  5055. setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
  5056. if (setup->is_secure)
  5057. setup->user_mpm = true;
  5058. if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
  5059. if (!setup->user_mpm)
  5060. return -EINVAL;
  5061. setup->auth_id =
  5062. nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
  5063. }
  5064. return 0;
  5065. }
  5066. static int nl80211_update_mesh_config(struct sk_buff *skb,
  5067. struct genl_info *info)
  5068. {
  5069. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5070. struct net_device *dev = info->user_ptr[1];
  5071. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5072. struct mesh_config cfg;
  5073. u32 mask;
  5074. int err;
  5075. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  5076. return -EOPNOTSUPP;
  5077. if (!rdev->ops->update_mesh_config)
  5078. return -EOPNOTSUPP;
  5079. err = nl80211_parse_mesh_config(info, &cfg, &mask);
  5080. if (err)
  5081. return err;
  5082. wdev_lock(wdev);
  5083. if (!wdev->mesh_id_len)
  5084. err = -ENOLINK;
  5085. if (!err)
  5086. err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
  5087. wdev_unlock(wdev);
  5088. return err;
  5089. }
  5090. static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
  5091. struct sk_buff *msg)
  5092. {
  5093. struct nlattr *nl_reg_rules;
  5094. unsigned int i;
  5095. if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
  5096. (regdom->dfs_region &&
  5097. nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
  5098. goto nla_put_failure;
  5099. nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
  5100. if (!nl_reg_rules)
  5101. goto nla_put_failure;
  5102. for (i = 0; i < regdom->n_reg_rules; i++) {
  5103. struct nlattr *nl_reg_rule;
  5104. const struct ieee80211_reg_rule *reg_rule;
  5105. const struct ieee80211_freq_range *freq_range;
  5106. const struct ieee80211_power_rule *power_rule;
  5107. unsigned int max_bandwidth_khz;
  5108. reg_rule = &regdom->reg_rules[i];
  5109. freq_range = &reg_rule->freq_range;
  5110. power_rule = &reg_rule->power_rule;
  5111. nl_reg_rule = nla_nest_start(msg, i);
  5112. if (!nl_reg_rule)
  5113. goto nla_put_failure;
  5114. max_bandwidth_khz = freq_range->max_bandwidth_khz;
  5115. if (!max_bandwidth_khz)
  5116. max_bandwidth_khz = reg_get_max_bandwidth(regdom,
  5117. reg_rule);
  5118. if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
  5119. reg_rule->flags) ||
  5120. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
  5121. freq_range->start_freq_khz) ||
  5122. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
  5123. freq_range->end_freq_khz) ||
  5124. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
  5125. max_bandwidth_khz) ||
  5126. nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
  5127. power_rule->max_antenna_gain) ||
  5128. nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
  5129. power_rule->max_eirp) ||
  5130. nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
  5131. reg_rule->dfs_cac_ms))
  5132. goto nla_put_failure;
  5133. nla_nest_end(msg, nl_reg_rule);
  5134. }
  5135. nla_nest_end(msg, nl_reg_rules);
  5136. return 0;
  5137. nla_put_failure:
  5138. return -EMSGSIZE;
  5139. }
  5140. static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
  5141. {
  5142. const struct ieee80211_regdomain *regdom = NULL;
  5143. struct cfg80211_registered_device *rdev;
  5144. struct wiphy *wiphy = NULL;
  5145. struct sk_buff *msg;
  5146. void *hdr;
  5147. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5148. if (!msg)
  5149. return -ENOBUFS;
  5150. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  5151. NL80211_CMD_GET_REG);
  5152. if (!hdr)
  5153. goto put_failure;
  5154. if (info->attrs[NL80211_ATTR_WIPHY]) {
  5155. bool self_managed;
  5156. rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
  5157. if (IS_ERR(rdev)) {
  5158. nlmsg_free(msg);
  5159. return PTR_ERR(rdev);
  5160. }
  5161. wiphy = &rdev->wiphy;
  5162. self_managed = wiphy->regulatory_flags &
  5163. REGULATORY_WIPHY_SELF_MANAGED;
  5164. regdom = get_wiphy_regdom(wiphy);
  5165. /* a self-managed-reg device must have a private regdom */
  5166. if (WARN_ON(!regdom && self_managed)) {
  5167. nlmsg_free(msg);
  5168. return -EINVAL;
  5169. }
  5170. if (regdom &&
  5171. nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  5172. goto nla_put_failure;
  5173. }
  5174. if (!wiphy && reg_last_request_cell_base() &&
  5175. nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
  5176. NL80211_USER_REG_HINT_CELL_BASE))
  5177. goto nla_put_failure;
  5178. rcu_read_lock();
  5179. if (!regdom)
  5180. regdom = rcu_dereference(cfg80211_regdomain);
  5181. if (nl80211_put_regdom(regdom, msg))
  5182. goto nla_put_failure_rcu;
  5183. rcu_read_unlock();
  5184. genlmsg_end(msg, hdr);
  5185. return genlmsg_reply(msg, info);
  5186. nla_put_failure_rcu:
  5187. rcu_read_unlock();
  5188. nla_put_failure:
  5189. genlmsg_cancel(msg, hdr);
  5190. put_failure:
  5191. nlmsg_free(msg);
  5192. return -EMSGSIZE;
  5193. }
  5194. static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
  5195. u32 seq, int flags, struct wiphy *wiphy,
  5196. const struct ieee80211_regdomain *regdom)
  5197. {
  5198. void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
  5199. NL80211_CMD_GET_REG);
  5200. if (!hdr)
  5201. return -1;
  5202. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  5203. if (nl80211_put_regdom(regdom, msg))
  5204. goto nla_put_failure;
  5205. if (!wiphy && reg_last_request_cell_base() &&
  5206. nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
  5207. NL80211_USER_REG_HINT_CELL_BASE))
  5208. goto nla_put_failure;
  5209. if (wiphy &&
  5210. nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  5211. goto nla_put_failure;
  5212. if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  5213. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  5214. goto nla_put_failure;
  5215. genlmsg_end(msg, hdr);
  5216. return 0;
  5217. nla_put_failure:
  5218. genlmsg_cancel(msg, hdr);
  5219. return -EMSGSIZE;
  5220. }
  5221. static int nl80211_get_reg_dump(struct sk_buff *skb,
  5222. struct netlink_callback *cb)
  5223. {
  5224. const struct ieee80211_regdomain *regdom = NULL;
  5225. struct cfg80211_registered_device *rdev;
  5226. int err, reg_idx, start = cb->args[2];
  5227. rtnl_lock();
  5228. if (cfg80211_regdomain && start == 0) {
  5229. err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
  5230. NLM_F_MULTI, NULL,
  5231. rtnl_dereference(cfg80211_regdomain));
  5232. if (err < 0)
  5233. goto out_err;
  5234. }
  5235. /* the global regdom is idx 0 */
  5236. reg_idx = 1;
  5237. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  5238. regdom = get_wiphy_regdom(&rdev->wiphy);
  5239. if (!regdom)
  5240. continue;
  5241. if (++reg_idx <= start)
  5242. continue;
  5243. err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
  5244. NLM_F_MULTI, &rdev->wiphy, regdom);
  5245. if (err < 0) {
  5246. reg_idx--;
  5247. break;
  5248. }
  5249. }
  5250. cb->args[2] = reg_idx;
  5251. err = skb->len;
  5252. out_err:
  5253. rtnl_unlock();
  5254. return err;
  5255. }
  5256. #ifdef CONFIG_CFG80211_CRDA_SUPPORT
  5257. static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
  5258. [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
  5259. [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
  5260. [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
  5261. [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
  5262. [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
  5263. [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
  5264. [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
  5265. };
  5266. static int parse_reg_rule(struct nlattr *tb[],
  5267. struct ieee80211_reg_rule *reg_rule)
  5268. {
  5269. struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
  5270. struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
  5271. if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
  5272. return -EINVAL;
  5273. if (!tb[NL80211_ATTR_FREQ_RANGE_START])
  5274. return -EINVAL;
  5275. if (!tb[NL80211_ATTR_FREQ_RANGE_END])
  5276. return -EINVAL;
  5277. if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
  5278. return -EINVAL;
  5279. if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
  5280. return -EINVAL;
  5281. reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
  5282. freq_range->start_freq_khz =
  5283. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
  5284. freq_range->end_freq_khz =
  5285. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
  5286. freq_range->max_bandwidth_khz =
  5287. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
  5288. power_rule->max_eirp =
  5289. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
  5290. if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
  5291. power_rule->max_antenna_gain =
  5292. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
  5293. if (tb[NL80211_ATTR_DFS_CAC_TIME])
  5294. reg_rule->dfs_cac_ms =
  5295. nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
  5296. return 0;
  5297. }
  5298. static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
  5299. {
  5300. struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
  5301. struct nlattr *nl_reg_rule;
  5302. char *alpha2;
  5303. int rem_reg_rules, r;
  5304. u32 num_rules = 0, rule_idx = 0, size_of_regd;
  5305. enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
  5306. struct ieee80211_regdomain *rd;
  5307. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  5308. return -EINVAL;
  5309. if (!info->attrs[NL80211_ATTR_REG_RULES])
  5310. return -EINVAL;
  5311. alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  5312. if (info->attrs[NL80211_ATTR_DFS_REGION])
  5313. dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
  5314. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  5315. rem_reg_rules) {
  5316. num_rules++;
  5317. if (num_rules > NL80211_MAX_SUPP_REG_RULES)
  5318. return -EINVAL;
  5319. }
  5320. if (!reg_is_valid_request(alpha2))
  5321. return -EINVAL;
  5322. size_of_regd = sizeof(struct ieee80211_regdomain) +
  5323. num_rules * sizeof(struct ieee80211_reg_rule);
  5324. rd = kzalloc(size_of_regd, GFP_KERNEL);
  5325. if (!rd)
  5326. return -ENOMEM;
  5327. rd->n_reg_rules = num_rules;
  5328. rd->alpha2[0] = alpha2[0];
  5329. rd->alpha2[1] = alpha2[1];
  5330. /*
  5331. * Disable DFS master mode if the DFS region was
  5332. * not supported or known on this kernel.
  5333. */
  5334. if (reg_supported_dfs_region(dfs_region))
  5335. rd->dfs_region = dfs_region;
  5336. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  5337. rem_reg_rules) {
  5338. r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
  5339. nla_data(nl_reg_rule), nla_len(nl_reg_rule),
  5340. reg_rule_policy);
  5341. if (r)
  5342. goto bad_reg;
  5343. r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
  5344. if (r)
  5345. goto bad_reg;
  5346. rule_idx++;
  5347. if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
  5348. r = -EINVAL;
  5349. goto bad_reg;
  5350. }
  5351. }
  5352. /* set_regdom takes ownership of rd */
  5353. return set_regdom(rd, REGD_SOURCE_CRDA);
  5354. bad_reg:
  5355. kfree(rd);
  5356. return r;
  5357. }
  5358. #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
  5359. static int validate_scan_freqs(struct nlattr *freqs)
  5360. {
  5361. struct nlattr *attr1, *attr2;
  5362. int n_channels = 0, tmp1, tmp2;
  5363. nla_for_each_nested(attr1, freqs, tmp1)
  5364. if (nla_len(attr1) != sizeof(u32))
  5365. return 0;
  5366. nla_for_each_nested(attr1, freqs, tmp1) {
  5367. n_channels++;
  5368. /*
  5369. * Some hardware has a limited channel list for
  5370. * scanning, and it is pretty much nonsensical
  5371. * to scan for a channel twice, so disallow that
  5372. * and don't require drivers to check that the
  5373. * channel list they get isn't longer than what
  5374. * they can scan, as long as they can scan all
  5375. * the channels they registered at once.
  5376. */
  5377. nla_for_each_nested(attr2, freqs, tmp2)
  5378. if (attr1 != attr2 &&
  5379. nla_get_u32(attr1) == nla_get_u32(attr2))
  5380. return 0;
  5381. }
  5382. return n_channels;
  5383. }
  5384. static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
  5385. {
  5386. return b < NUM_NL80211_BANDS && wiphy->bands[b];
  5387. }
  5388. static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
  5389. struct cfg80211_bss_selection *bss_select)
  5390. {
  5391. struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
  5392. struct nlattr *nest;
  5393. int err;
  5394. bool found = false;
  5395. int i;
  5396. /* only process one nested attribute */
  5397. nest = nla_data(nla);
  5398. if (!nla_ok(nest, nla_len(nest)))
  5399. return -EINVAL;
  5400. err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
  5401. nla_len(nest), nl80211_bss_select_policy);
  5402. if (err)
  5403. return err;
  5404. /* only one attribute may be given */
  5405. for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
  5406. if (attr[i]) {
  5407. if (found)
  5408. return -EINVAL;
  5409. found = true;
  5410. }
  5411. }
  5412. bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
  5413. if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
  5414. bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
  5415. if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
  5416. bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
  5417. bss_select->param.band_pref =
  5418. nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
  5419. if (!is_band_valid(wiphy, bss_select->param.band_pref))
  5420. return -EINVAL;
  5421. }
  5422. if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
  5423. struct nl80211_bss_select_rssi_adjust *adj_param;
  5424. adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
  5425. bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
  5426. bss_select->param.adjust.band = adj_param->band;
  5427. bss_select->param.adjust.delta = adj_param->delta;
  5428. if (!is_band_valid(wiphy, bss_select->param.adjust.band))
  5429. return -EINVAL;
  5430. }
  5431. /* user-space did not provide behaviour attribute */
  5432. if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
  5433. return -EINVAL;
  5434. if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
  5435. return -EINVAL;
  5436. return 0;
  5437. }
  5438. static int nl80211_parse_random_mac(struct nlattr **attrs,
  5439. u8 *mac_addr, u8 *mac_addr_mask)
  5440. {
  5441. int i;
  5442. if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
  5443. eth_zero_addr(mac_addr);
  5444. eth_zero_addr(mac_addr_mask);
  5445. mac_addr[0] = 0x2;
  5446. mac_addr_mask[0] = 0x3;
  5447. return 0;
  5448. }
  5449. /* need both or none */
  5450. if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
  5451. return -EINVAL;
  5452. memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
  5453. memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
  5454. /* don't allow or configure an mcast address */
  5455. if (!is_multicast_ether_addr(mac_addr_mask) ||
  5456. is_multicast_ether_addr(mac_addr))
  5457. return -EINVAL;
  5458. /*
  5459. * allow users to pass a MAC address that has bits set outside
  5460. * of the mask, but don't bother drivers with having to deal
  5461. * with such bits
  5462. */
  5463. for (i = 0; i < ETH_ALEN; i++)
  5464. mac_addr[i] &= mac_addr_mask[i];
  5465. return 0;
  5466. }
  5467. static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
  5468. {
  5469. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5470. struct wireless_dev *wdev = info->user_ptr[1];
  5471. struct cfg80211_scan_request *request;
  5472. struct nlattr *attr;
  5473. struct wiphy *wiphy;
  5474. int err, tmp, n_ssids = 0, n_channels, i;
  5475. size_t ie_len;
  5476. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  5477. return -EINVAL;
  5478. wiphy = &rdev->wiphy;
  5479. if (wdev->iftype == NL80211_IFTYPE_NAN)
  5480. return -EOPNOTSUPP;
  5481. if (!rdev->ops->scan)
  5482. return -EOPNOTSUPP;
  5483. if (rdev->scan_req || rdev->scan_msg) {
  5484. err = -EBUSY;
  5485. goto unlock;
  5486. }
  5487. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5488. n_channels = validate_scan_freqs(
  5489. info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  5490. if (!n_channels) {
  5491. err = -EINVAL;
  5492. goto unlock;
  5493. }
  5494. } else {
  5495. n_channels = ieee80211_get_num_supported_channels(wiphy);
  5496. }
  5497. if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
  5498. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
  5499. n_ssids++;
  5500. if (n_ssids > wiphy->max_scan_ssids) {
  5501. err = -EINVAL;
  5502. goto unlock;
  5503. }
  5504. if (info->attrs[NL80211_ATTR_IE])
  5505. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5506. else
  5507. ie_len = 0;
  5508. if (ie_len > wiphy->max_scan_ie_len) {
  5509. err = -EINVAL;
  5510. goto unlock;
  5511. }
  5512. request = kzalloc(sizeof(*request)
  5513. + sizeof(*request->ssids) * n_ssids
  5514. + sizeof(*request->channels) * n_channels
  5515. + ie_len, GFP_KERNEL);
  5516. if (!request) {
  5517. err = -ENOMEM;
  5518. goto unlock;
  5519. }
  5520. if (n_ssids)
  5521. request->ssids = (void *)&request->channels[n_channels];
  5522. request->n_ssids = n_ssids;
  5523. if (ie_len) {
  5524. if (n_ssids)
  5525. request->ie = (void *)(request->ssids + n_ssids);
  5526. else
  5527. request->ie = (void *)(request->channels + n_channels);
  5528. }
  5529. i = 0;
  5530. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5531. /* user specified, bail out if channel not found */
  5532. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
  5533. struct ieee80211_channel *chan;
  5534. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  5535. if (!chan) {
  5536. err = -EINVAL;
  5537. goto out_free;
  5538. }
  5539. /* ignore disabled channels */
  5540. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5541. continue;
  5542. request->channels[i] = chan;
  5543. i++;
  5544. }
  5545. } else {
  5546. enum nl80211_band band;
  5547. /* all channels */
  5548. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  5549. int j;
  5550. if (!wiphy->bands[band])
  5551. continue;
  5552. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  5553. struct ieee80211_channel *chan;
  5554. chan = &wiphy->bands[band]->channels[j];
  5555. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5556. continue;
  5557. request->channels[i] = chan;
  5558. i++;
  5559. }
  5560. }
  5561. }
  5562. if (!i) {
  5563. err = -EINVAL;
  5564. goto out_free;
  5565. }
  5566. request->n_channels = i;
  5567. i = 0;
  5568. if (n_ssids) {
  5569. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
  5570. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  5571. err = -EINVAL;
  5572. goto out_free;
  5573. }
  5574. request->ssids[i].ssid_len = nla_len(attr);
  5575. memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
  5576. i++;
  5577. }
  5578. }
  5579. if (info->attrs[NL80211_ATTR_IE]) {
  5580. request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5581. memcpy((void *)request->ie,
  5582. nla_data(info->attrs[NL80211_ATTR_IE]),
  5583. request->ie_len);
  5584. }
  5585. for (i = 0; i < NUM_NL80211_BANDS; i++)
  5586. if (wiphy->bands[i])
  5587. request->rates[i] =
  5588. (1 << wiphy->bands[i]->n_bitrates) - 1;
  5589. if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
  5590. nla_for_each_nested(attr,
  5591. info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
  5592. tmp) {
  5593. enum nl80211_band band = nla_type(attr);
  5594. if (band < 0 || band >= NUM_NL80211_BANDS) {
  5595. err = -EINVAL;
  5596. goto out_free;
  5597. }
  5598. if (!wiphy->bands[band])
  5599. continue;
  5600. err = ieee80211_get_ratemask(wiphy->bands[band],
  5601. nla_data(attr),
  5602. nla_len(attr),
  5603. &request->rates[band]);
  5604. if (err)
  5605. goto out_free;
  5606. }
  5607. }
  5608. if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
  5609. if (!wiphy_ext_feature_isset(wiphy,
  5610. NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
  5611. err = -EOPNOTSUPP;
  5612. goto out_free;
  5613. }
  5614. request->duration =
  5615. nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
  5616. request->duration_mandatory =
  5617. nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
  5618. }
  5619. if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
  5620. request->flags = nla_get_u32(
  5621. info->attrs[NL80211_ATTR_SCAN_FLAGS]);
  5622. if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  5623. !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
  5624. err = -EOPNOTSUPP;
  5625. goto out_free;
  5626. }
  5627. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  5628. if (!(wiphy->features &
  5629. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
  5630. err = -EOPNOTSUPP;
  5631. goto out_free;
  5632. }
  5633. if (wdev->current_bss) {
  5634. err = -EOPNOTSUPP;
  5635. goto out_free;
  5636. }
  5637. err = nl80211_parse_random_mac(info->attrs,
  5638. request->mac_addr,
  5639. request->mac_addr_mask);
  5640. if (err)
  5641. goto out_free;
  5642. }
  5643. }
  5644. request->no_cck =
  5645. nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  5646. /* Initial implementation used NL80211_ATTR_MAC to set the specific
  5647. * BSSID to scan for. This was problematic because that same attribute
  5648. * was already used for another purpose (local random MAC address). The
  5649. * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
  5650. * compatibility with older userspace components, also use the
  5651. * NL80211_ATTR_MAC value here if it can be determined to be used for
  5652. * the specific BSSID use case instead of the random MAC address
  5653. * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
  5654. */
  5655. if (info->attrs[NL80211_ATTR_BSSID])
  5656. memcpy(request->bssid,
  5657. nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
  5658. else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
  5659. info->attrs[NL80211_ATTR_MAC])
  5660. memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
  5661. ETH_ALEN);
  5662. else
  5663. eth_broadcast_addr(request->bssid);
  5664. request->wdev = wdev;
  5665. request->wiphy = &rdev->wiphy;
  5666. request->scan_start = jiffies;
  5667. rdev->scan_req = request;
  5668. err = rdev_scan(rdev, request);
  5669. if (!err) {
  5670. nl80211_send_scan_start(rdev, wdev);
  5671. if (wdev->netdev)
  5672. dev_hold(wdev->netdev);
  5673. } else {
  5674. out_free:
  5675. rdev->scan_req = NULL;
  5676. kfree(request);
  5677. }
  5678. unlock:
  5679. return err;
  5680. }
  5681. static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
  5682. {
  5683. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5684. struct wireless_dev *wdev = info->user_ptr[1];
  5685. if (!rdev->ops->abort_scan)
  5686. return -EOPNOTSUPP;
  5687. if (rdev->scan_msg)
  5688. return 0;
  5689. if (!rdev->scan_req)
  5690. return -ENOENT;
  5691. rdev_abort_scan(rdev, wdev);
  5692. return 0;
  5693. }
  5694. static int
  5695. nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
  5696. struct cfg80211_sched_scan_request *request,
  5697. struct nlattr **attrs)
  5698. {
  5699. int tmp, err, i = 0;
  5700. struct nlattr *attr;
  5701. if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
  5702. u32 interval;
  5703. /*
  5704. * If scan plans are not specified,
  5705. * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
  5706. * case one scan plan will be set with the specified scan
  5707. * interval and infinite number of iterations.
  5708. */
  5709. if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5710. return -EINVAL;
  5711. interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
  5712. if (!interval)
  5713. return -EINVAL;
  5714. request->scan_plans[0].interval =
  5715. DIV_ROUND_UP(interval, MSEC_PER_SEC);
  5716. if (!request->scan_plans[0].interval)
  5717. return -EINVAL;
  5718. if (request->scan_plans[0].interval >
  5719. wiphy->max_sched_scan_plan_interval)
  5720. request->scan_plans[0].interval =
  5721. wiphy->max_sched_scan_plan_interval;
  5722. return 0;
  5723. }
  5724. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
  5725. struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
  5726. if (WARN_ON(i >= n_plans))
  5727. return -EINVAL;
  5728. err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
  5729. nla_data(attr), nla_len(attr),
  5730. nl80211_plan_policy);
  5731. if (err)
  5732. return err;
  5733. if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
  5734. return -EINVAL;
  5735. request->scan_plans[i].interval =
  5736. nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
  5737. if (!request->scan_plans[i].interval ||
  5738. request->scan_plans[i].interval >
  5739. wiphy->max_sched_scan_plan_interval)
  5740. return -EINVAL;
  5741. if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
  5742. request->scan_plans[i].iterations =
  5743. nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
  5744. if (!request->scan_plans[i].iterations ||
  5745. (request->scan_plans[i].iterations >
  5746. wiphy->max_sched_scan_plan_iterations))
  5747. return -EINVAL;
  5748. } else if (i < n_plans - 1) {
  5749. /*
  5750. * All scan plans but the last one must specify
  5751. * a finite number of iterations
  5752. */
  5753. return -EINVAL;
  5754. }
  5755. i++;
  5756. }
  5757. /*
  5758. * The last scan plan must not specify the number of
  5759. * iterations, it is supposed to run infinitely
  5760. */
  5761. if (request->scan_plans[n_plans - 1].iterations)
  5762. return -EINVAL;
  5763. return 0;
  5764. }
  5765. static struct cfg80211_sched_scan_request *
  5766. nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
  5767. struct nlattr **attrs)
  5768. {
  5769. struct cfg80211_sched_scan_request *request;
  5770. struct nlattr *attr;
  5771. int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
  5772. enum nl80211_band band;
  5773. size_t ie_len;
  5774. struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
  5775. s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
  5776. if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
  5777. return ERR_PTR(-EINVAL);
  5778. if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5779. n_channels = validate_scan_freqs(
  5780. attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  5781. if (!n_channels)
  5782. return ERR_PTR(-EINVAL);
  5783. } else {
  5784. n_channels = ieee80211_get_num_supported_channels(wiphy);
  5785. }
  5786. if (attrs[NL80211_ATTR_SCAN_SSIDS])
  5787. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
  5788. tmp)
  5789. n_ssids++;
  5790. if (n_ssids > wiphy->max_sched_scan_ssids)
  5791. return ERR_PTR(-EINVAL);
  5792. /*
  5793. * First, count the number of 'real' matchsets. Due to an issue with
  5794. * the old implementation, matchsets containing only the RSSI attribute
  5795. * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
  5796. * RSSI for all matchsets, rather than their own matchset for reporting
  5797. * all APs with a strong RSSI. This is needed to be compatible with
  5798. * older userspace that treated a matchset with only the RSSI as the
  5799. * global RSSI for all other matchsets - if there are other matchsets.
  5800. */
  5801. if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  5802. nla_for_each_nested(attr,
  5803. attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  5804. tmp) {
  5805. struct nlattr *rssi;
  5806. err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  5807. nla_data(attr), nla_len(attr),
  5808. nl80211_match_policy);
  5809. if (err)
  5810. return ERR_PTR(err);
  5811. /* add other standalone attributes here */
  5812. if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
  5813. n_match_sets++;
  5814. continue;
  5815. }
  5816. rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
  5817. if (rssi)
  5818. default_match_rssi = nla_get_s32(rssi);
  5819. }
  5820. }
  5821. /* However, if there's no other matchset, add the RSSI one */
  5822. if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
  5823. n_match_sets = 1;
  5824. if (n_match_sets > wiphy->max_match_sets)
  5825. return ERR_PTR(-EINVAL);
  5826. if (attrs[NL80211_ATTR_IE])
  5827. ie_len = nla_len(attrs[NL80211_ATTR_IE]);
  5828. else
  5829. ie_len = 0;
  5830. if (ie_len > wiphy->max_sched_scan_ie_len)
  5831. return ERR_PTR(-EINVAL);
  5832. if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
  5833. /*
  5834. * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
  5835. * each scan plan already specifies its own interval
  5836. */
  5837. if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5838. return ERR_PTR(-EINVAL);
  5839. nla_for_each_nested(attr,
  5840. attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
  5841. n_plans++;
  5842. } else {
  5843. /*
  5844. * The scan interval attribute is kept for backward
  5845. * compatibility. If no scan plans are specified and sched scan
  5846. * interval is specified, one scan plan will be set with this
  5847. * scan interval and infinite number of iterations.
  5848. */
  5849. if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5850. return ERR_PTR(-EINVAL);
  5851. n_plans = 1;
  5852. }
  5853. if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
  5854. return ERR_PTR(-EINVAL);
  5855. request = kzalloc(sizeof(*request)
  5856. + sizeof(*request->ssids) * n_ssids
  5857. + sizeof(*request->match_sets) * n_match_sets
  5858. + sizeof(*request->scan_plans) * n_plans
  5859. + sizeof(*request->channels) * n_channels
  5860. + ie_len, GFP_KERNEL);
  5861. if (!request)
  5862. return ERR_PTR(-ENOMEM);
  5863. if (n_ssids)
  5864. request->ssids = (void *)&request->channels[n_channels];
  5865. request->n_ssids = n_ssids;
  5866. if (ie_len) {
  5867. if (n_ssids)
  5868. request->ie = (void *)(request->ssids + n_ssids);
  5869. else
  5870. request->ie = (void *)(request->channels + n_channels);
  5871. }
  5872. if (n_match_sets) {
  5873. if (request->ie)
  5874. request->match_sets = (void *)(request->ie + ie_len);
  5875. else if (n_ssids)
  5876. request->match_sets =
  5877. (void *)(request->ssids + n_ssids);
  5878. else
  5879. request->match_sets =
  5880. (void *)(request->channels + n_channels);
  5881. }
  5882. request->n_match_sets = n_match_sets;
  5883. if (n_match_sets)
  5884. request->scan_plans = (void *)(request->match_sets +
  5885. n_match_sets);
  5886. else if (request->ie)
  5887. request->scan_plans = (void *)(request->ie + ie_len);
  5888. else if (n_ssids)
  5889. request->scan_plans = (void *)(request->ssids + n_ssids);
  5890. else
  5891. request->scan_plans = (void *)(request->channels + n_channels);
  5892. request->n_scan_plans = n_plans;
  5893. i = 0;
  5894. if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5895. /* user specified, bail out if channel not found */
  5896. nla_for_each_nested(attr,
  5897. attrs[NL80211_ATTR_SCAN_FREQUENCIES],
  5898. tmp) {
  5899. struct ieee80211_channel *chan;
  5900. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  5901. if (!chan) {
  5902. err = -EINVAL;
  5903. goto out_free;
  5904. }
  5905. /* ignore disabled channels */
  5906. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5907. continue;
  5908. request->channels[i] = chan;
  5909. i++;
  5910. }
  5911. } else {
  5912. /* all channels */
  5913. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  5914. int j;
  5915. if (!wiphy->bands[band])
  5916. continue;
  5917. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  5918. struct ieee80211_channel *chan;
  5919. chan = &wiphy->bands[band]->channels[j];
  5920. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5921. continue;
  5922. request->channels[i] = chan;
  5923. i++;
  5924. }
  5925. }
  5926. }
  5927. if (!i) {
  5928. err = -EINVAL;
  5929. goto out_free;
  5930. }
  5931. request->n_channels = i;
  5932. i = 0;
  5933. if (n_ssids) {
  5934. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
  5935. tmp) {
  5936. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  5937. err = -EINVAL;
  5938. goto out_free;
  5939. }
  5940. request->ssids[i].ssid_len = nla_len(attr);
  5941. memcpy(request->ssids[i].ssid, nla_data(attr),
  5942. nla_len(attr));
  5943. i++;
  5944. }
  5945. }
  5946. i = 0;
  5947. if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  5948. nla_for_each_nested(attr,
  5949. attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  5950. tmp) {
  5951. struct nlattr *ssid, *rssi;
  5952. err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  5953. nla_data(attr), nla_len(attr),
  5954. nl80211_match_policy);
  5955. if (err)
  5956. goto out_free;
  5957. ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
  5958. if (ssid) {
  5959. if (WARN_ON(i >= n_match_sets)) {
  5960. /* this indicates a programming error,
  5961. * the loop above should have verified
  5962. * things properly
  5963. */
  5964. err = -EINVAL;
  5965. goto out_free;
  5966. }
  5967. if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
  5968. err = -EINVAL;
  5969. goto out_free;
  5970. }
  5971. memcpy(request->match_sets[i].ssid.ssid,
  5972. nla_data(ssid), nla_len(ssid));
  5973. request->match_sets[i].ssid.ssid_len =
  5974. nla_len(ssid);
  5975. /* special attribute - old implementation w/a */
  5976. request->match_sets[i].rssi_thold =
  5977. default_match_rssi;
  5978. rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
  5979. if (rssi)
  5980. request->match_sets[i].rssi_thold =
  5981. nla_get_s32(rssi);
  5982. }
  5983. i++;
  5984. }
  5985. /* there was no other matchset, so the RSSI one is alone */
  5986. if (i == 0 && n_match_sets)
  5987. request->match_sets[0].rssi_thold = default_match_rssi;
  5988. request->min_rssi_thold = INT_MAX;
  5989. for (i = 0; i < n_match_sets; i++)
  5990. request->min_rssi_thold =
  5991. min(request->match_sets[i].rssi_thold,
  5992. request->min_rssi_thold);
  5993. } else {
  5994. request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
  5995. }
  5996. if (ie_len) {
  5997. request->ie_len = ie_len;
  5998. memcpy((void *)request->ie,
  5999. nla_data(attrs[NL80211_ATTR_IE]),
  6000. request->ie_len);
  6001. }
  6002. if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
  6003. request->flags = nla_get_u32(
  6004. attrs[NL80211_ATTR_SCAN_FLAGS]);
  6005. if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  6006. !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
  6007. err = -EOPNOTSUPP;
  6008. goto out_free;
  6009. }
  6010. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  6011. u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
  6012. if (!wdev) /* must be net-detect */
  6013. flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  6014. if (!(wiphy->features & flg)) {
  6015. err = -EOPNOTSUPP;
  6016. goto out_free;
  6017. }
  6018. if (wdev && wdev->current_bss) {
  6019. err = -EOPNOTSUPP;
  6020. goto out_free;
  6021. }
  6022. err = nl80211_parse_random_mac(attrs, request->mac_addr,
  6023. request->mac_addr_mask);
  6024. if (err)
  6025. goto out_free;
  6026. }
  6027. }
  6028. if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
  6029. request->delay =
  6030. nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
  6031. err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
  6032. if (err)
  6033. goto out_free;
  6034. request->scan_start = jiffies;
  6035. return request;
  6036. out_free:
  6037. kfree(request);
  6038. return ERR_PTR(err);
  6039. }
  6040. static int nl80211_start_sched_scan(struct sk_buff *skb,
  6041. struct genl_info *info)
  6042. {
  6043. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6044. struct net_device *dev = info->user_ptr[1];
  6045. struct wireless_dev *wdev = dev->ieee80211_ptr;
  6046. struct cfg80211_sched_scan_request *sched_scan_req;
  6047. int err;
  6048. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  6049. !rdev->ops->sched_scan_start)
  6050. return -EOPNOTSUPP;
  6051. if (rdev->sched_scan_req)
  6052. return -EINPROGRESS;
  6053. sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
  6054. info->attrs);
  6055. err = PTR_ERR_OR_ZERO(sched_scan_req);
  6056. if (err)
  6057. goto out_err;
  6058. err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
  6059. if (err)
  6060. goto out_free;
  6061. sched_scan_req->dev = dev;
  6062. sched_scan_req->wiphy = &rdev->wiphy;
  6063. if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
  6064. sched_scan_req->owner_nlportid = info->snd_portid;
  6065. rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
  6066. nl80211_send_sched_scan(rdev, dev,
  6067. NL80211_CMD_START_SCHED_SCAN);
  6068. return 0;
  6069. out_free:
  6070. kfree(sched_scan_req);
  6071. out_err:
  6072. return err;
  6073. }
  6074. static int nl80211_stop_sched_scan(struct sk_buff *skb,
  6075. struct genl_info *info)
  6076. {
  6077. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6078. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  6079. !rdev->ops->sched_scan_stop)
  6080. return -EOPNOTSUPP;
  6081. return __cfg80211_stop_sched_scan(rdev, false);
  6082. }
  6083. static int nl80211_start_radar_detection(struct sk_buff *skb,
  6084. struct genl_info *info)
  6085. {
  6086. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6087. struct net_device *dev = info->user_ptr[1];
  6088. struct wireless_dev *wdev = dev->ieee80211_ptr;
  6089. struct cfg80211_chan_def chandef;
  6090. enum nl80211_dfs_regions dfs_region;
  6091. unsigned int cac_time_ms;
  6092. int err;
  6093. dfs_region = reg_get_dfs_region(wdev->wiphy);
  6094. if (dfs_region == NL80211_DFS_UNSET)
  6095. return -EINVAL;
  6096. err = nl80211_parse_chandef(rdev, info, &chandef);
  6097. if (err)
  6098. return err;
  6099. if (netif_carrier_ok(dev))
  6100. return -EBUSY;
  6101. if (wdev->cac_started)
  6102. return -EBUSY;
  6103. err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
  6104. wdev->iftype);
  6105. if (err < 0)
  6106. return err;
  6107. if (err == 0)
  6108. return -EINVAL;
  6109. if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
  6110. return -EINVAL;
  6111. if (!rdev->ops->start_radar_detection)
  6112. return -EOPNOTSUPP;
  6113. cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
  6114. if (WARN_ON(!cac_time_ms))
  6115. cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
  6116. err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
  6117. if (!err) {
  6118. wdev->chandef = chandef;
  6119. wdev->cac_started = true;
  6120. wdev->cac_start_time = jiffies;
  6121. wdev->cac_time_ms = cac_time_ms;
  6122. }
  6123. return err;
  6124. }
  6125. static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
  6126. {
  6127. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6128. struct net_device *dev = info->user_ptr[1];
  6129. struct wireless_dev *wdev = dev->ieee80211_ptr;
  6130. struct cfg80211_csa_settings params;
  6131. /* csa_attrs is defined static to avoid waste of stack size - this
  6132. * function is called under RTNL lock, so this should not be a problem.
  6133. */
  6134. static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
  6135. int err;
  6136. bool need_new_beacon = false;
  6137. int len, i;
  6138. u32 cs_count;
  6139. if (!rdev->ops->channel_switch ||
  6140. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
  6141. return -EOPNOTSUPP;
  6142. switch (dev->ieee80211_ptr->iftype) {
  6143. case NL80211_IFTYPE_AP:
  6144. case NL80211_IFTYPE_P2P_GO:
  6145. need_new_beacon = true;
  6146. /* useless if AP is not running */
  6147. if (!wdev->beacon_interval)
  6148. return -ENOTCONN;
  6149. break;
  6150. case NL80211_IFTYPE_ADHOC:
  6151. if (!wdev->ssid_len)
  6152. return -ENOTCONN;
  6153. break;
  6154. case NL80211_IFTYPE_MESH_POINT:
  6155. if (!wdev->mesh_id_len)
  6156. return -ENOTCONN;
  6157. break;
  6158. default:
  6159. return -EOPNOTSUPP;
  6160. }
  6161. memset(&params, 0, sizeof(params));
  6162. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  6163. !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
  6164. return -EINVAL;
  6165. /* only important for AP, IBSS and mesh create IEs internally */
  6166. if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
  6167. return -EINVAL;
  6168. /* Even though the attribute is u32, the specification says
  6169. * u8, so let's make sure we don't overflow.
  6170. */
  6171. cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
  6172. if (cs_count > 255)
  6173. return -EINVAL;
  6174. params.count = cs_count;
  6175. if (!need_new_beacon)
  6176. goto skip_beacons;
  6177. err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
  6178. if (err)
  6179. return err;
  6180. err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
  6181. info->attrs[NL80211_ATTR_CSA_IES],
  6182. nl80211_policy);
  6183. if (err)
  6184. return err;
  6185. err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
  6186. if (err)
  6187. return err;
  6188. if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
  6189. return -EINVAL;
  6190. len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
  6191. if (!len || (len % sizeof(u16)))
  6192. return -EINVAL;
  6193. params.n_counter_offsets_beacon = len / sizeof(u16);
  6194. if (rdev->wiphy.max_num_csa_counters &&
  6195. (params.n_counter_offsets_beacon >
  6196. rdev->wiphy.max_num_csa_counters))
  6197. return -EINVAL;
  6198. params.counter_offsets_beacon =
  6199. nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
  6200. /* sanity checks - counters should fit and be the same */
  6201. for (i = 0; i < params.n_counter_offsets_beacon; i++) {
  6202. u16 offset = params.counter_offsets_beacon[i];
  6203. if (offset >= params.beacon_csa.tail_len)
  6204. return -EINVAL;
  6205. if (params.beacon_csa.tail[offset] != params.count)
  6206. return -EINVAL;
  6207. }
  6208. if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
  6209. len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
  6210. if (!len || (len % sizeof(u16)))
  6211. return -EINVAL;
  6212. params.n_counter_offsets_presp = len / sizeof(u16);
  6213. if (rdev->wiphy.max_num_csa_counters &&
  6214. (params.n_counter_offsets_presp >
  6215. rdev->wiphy.max_num_csa_counters))
  6216. return -EINVAL;
  6217. params.counter_offsets_presp =
  6218. nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
  6219. /* sanity checks - counters should fit and be the same */
  6220. for (i = 0; i < params.n_counter_offsets_presp; i++) {
  6221. u16 offset = params.counter_offsets_presp[i];
  6222. if (offset >= params.beacon_csa.probe_resp_len)
  6223. return -EINVAL;
  6224. if (params.beacon_csa.probe_resp[offset] !=
  6225. params.count)
  6226. return -EINVAL;
  6227. }
  6228. }
  6229. skip_beacons:
  6230. err = nl80211_parse_chandef(rdev, info, &params.chandef);
  6231. if (err)
  6232. return err;
  6233. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
  6234. wdev->iftype))
  6235. return -EINVAL;
  6236. err = cfg80211_chandef_dfs_required(wdev->wiphy,
  6237. &params.chandef,
  6238. wdev->iftype);
  6239. if (err < 0)
  6240. return err;
  6241. if (err > 0)
  6242. params.radar_required = true;
  6243. if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
  6244. params.block_tx = true;
  6245. wdev_lock(wdev);
  6246. err = rdev_channel_switch(rdev, dev, &params);
  6247. wdev_unlock(wdev);
  6248. return err;
  6249. }
  6250. static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
  6251. u32 seq, int flags,
  6252. struct cfg80211_registered_device *rdev,
  6253. struct wireless_dev *wdev,
  6254. struct cfg80211_internal_bss *intbss)
  6255. {
  6256. struct cfg80211_bss *res = &intbss->pub;
  6257. const struct cfg80211_bss_ies *ies;
  6258. void *hdr;
  6259. struct nlattr *bss;
  6260. ASSERT_WDEV_LOCK(wdev);
  6261. hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
  6262. NL80211_CMD_NEW_SCAN_RESULTS);
  6263. if (!hdr)
  6264. return -1;
  6265. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  6266. if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
  6267. goto nla_put_failure;
  6268. if (wdev->netdev &&
  6269. nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
  6270. goto nla_put_failure;
  6271. if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  6272. NL80211_ATTR_PAD))
  6273. goto nla_put_failure;
  6274. bss = nla_nest_start(msg, NL80211_ATTR_BSS);
  6275. if (!bss)
  6276. goto nla_put_failure;
  6277. if ((!is_zero_ether_addr(res->bssid) &&
  6278. nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
  6279. goto nla_put_failure;
  6280. rcu_read_lock();
  6281. /* indicate whether we have probe response data or not */
  6282. if (rcu_access_pointer(res->proberesp_ies) &&
  6283. nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
  6284. goto fail_unlock_rcu;
  6285. /* this pointer prefers to be pointed to probe response data
  6286. * but is always valid
  6287. */
  6288. ies = rcu_dereference(res->ies);
  6289. if (ies) {
  6290. if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
  6291. NL80211_BSS_PAD))
  6292. goto fail_unlock_rcu;
  6293. if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
  6294. ies->len, ies->data))
  6295. goto fail_unlock_rcu;
  6296. }
  6297. /* and this pointer is always (unless driver didn't know) beacon data */
  6298. ies = rcu_dereference(res->beacon_ies);
  6299. if (ies && ies->from_beacon) {
  6300. if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
  6301. NL80211_BSS_PAD))
  6302. goto fail_unlock_rcu;
  6303. if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
  6304. ies->len, ies->data))
  6305. goto fail_unlock_rcu;
  6306. }
  6307. rcu_read_unlock();
  6308. if (res->beacon_interval &&
  6309. nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
  6310. goto nla_put_failure;
  6311. if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
  6312. nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
  6313. nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
  6314. nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
  6315. jiffies_to_msecs(jiffies - intbss->ts)))
  6316. goto nla_put_failure;
  6317. if (intbss->parent_tsf &&
  6318. (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
  6319. intbss->parent_tsf, NL80211_BSS_PAD) ||
  6320. nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
  6321. intbss->parent_bssid)))
  6322. goto nla_put_failure;
  6323. if (intbss->ts_boottime &&
  6324. nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
  6325. intbss->ts_boottime, NL80211_BSS_PAD))
  6326. goto nla_put_failure;
  6327. switch (rdev->wiphy.signal_type) {
  6328. case CFG80211_SIGNAL_TYPE_MBM:
  6329. if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
  6330. goto nla_put_failure;
  6331. break;
  6332. case CFG80211_SIGNAL_TYPE_UNSPEC:
  6333. if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
  6334. goto nla_put_failure;
  6335. break;
  6336. default:
  6337. break;
  6338. }
  6339. switch (wdev->iftype) {
  6340. case NL80211_IFTYPE_P2P_CLIENT:
  6341. case NL80211_IFTYPE_STATION:
  6342. if (intbss == wdev->current_bss &&
  6343. nla_put_u32(msg, NL80211_BSS_STATUS,
  6344. NL80211_BSS_STATUS_ASSOCIATED))
  6345. goto nla_put_failure;
  6346. break;
  6347. case NL80211_IFTYPE_ADHOC:
  6348. if (intbss == wdev->current_bss &&
  6349. nla_put_u32(msg, NL80211_BSS_STATUS,
  6350. NL80211_BSS_STATUS_IBSS_JOINED))
  6351. goto nla_put_failure;
  6352. break;
  6353. default:
  6354. break;
  6355. }
  6356. nla_nest_end(msg, bss);
  6357. genlmsg_end(msg, hdr);
  6358. return 0;
  6359. fail_unlock_rcu:
  6360. rcu_read_unlock();
  6361. nla_put_failure:
  6362. genlmsg_cancel(msg, hdr);
  6363. return -EMSGSIZE;
  6364. }
  6365. static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
  6366. {
  6367. struct cfg80211_registered_device *rdev;
  6368. struct cfg80211_internal_bss *scan;
  6369. struct wireless_dev *wdev;
  6370. int start = cb->args[2], idx = 0;
  6371. int err;
  6372. rtnl_lock();
  6373. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  6374. if (err) {
  6375. rtnl_unlock();
  6376. return err;
  6377. }
  6378. wdev_lock(wdev);
  6379. spin_lock_bh(&rdev->bss_lock);
  6380. cfg80211_bss_expire(rdev);
  6381. cb->seq = rdev->bss_generation;
  6382. list_for_each_entry(scan, &rdev->bss_list, list) {
  6383. if (++idx <= start)
  6384. continue;
  6385. if (nl80211_send_bss(skb, cb,
  6386. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  6387. rdev, wdev, scan) < 0) {
  6388. idx--;
  6389. break;
  6390. }
  6391. }
  6392. spin_unlock_bh(&rdev->bss_lock);
  6393. wdev_unlock(wdev);
  6394. cb->args[2] = idx;
  6395. rtnl_unlock();
  6396. return skb->len;
  6397. }
  6398. static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
  6399. int flags, struct net_device *dev,
  6400. bool allow_radio_stats,
  6401. struct survey_info *survey)
  6402. {
  6403. void *hdr;
  6404. struct nlattr *infoattr;
  6405. /* skip radio stats if userspace didn't request them */
  6406. if (!survey->channel && !allow_radio_stats)
  6407. return 0;
  6408. hdr = nl80211hdr_put(msg, portid, seq, flags,
  6409. NL80211_CMD_NEW_SURVEY_RESULTS);
  6410. if (!hdr)
  6411. return -ENOMEM;
  6412. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
  6413. goto nla_put_failure;
  6414. infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
  6415. if (!infoattr)
  6416. goto nla_put_failure;
  6417. if (survey->channel &&
  6418. nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
  6419. survey->channel->center_freq))
  6420. goto nla_put_failure;
  6421. if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
  6422. nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
  6423. goto nla_put_failure;
  6424. if ((survey->filled & SURVEY_INFO_IN_USE) &&
  6425. nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
  6426. goto nla_put_failure;
  6427. if ((survey->filled & SURVEY_INFO_TIME) &&
  6428. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
  6429. survey->time, NL80211_SURVEY_INFO_PAD))
  6430. goto nla_put_failure;
  6431. if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
  6432. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
  6433. survey->time_busy, NL80211_SURVEY_INFO_PAD))
  6434. goto nla_put_failure;
  6435. if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
  6436. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
  6437. survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
  6438. goto nla_put_failure;
  6439. if ((survey->filled & SURVEY_INFO_TIME_RX) &&
  6440. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
  6441. survey->time_rx, NL80211_SURVEY_INFO_PAD))
  6442. goto nla_put_failure;
  6443. if ((survey->filled & SURVEY_INFO_TIME_TX) &&
  6444. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
  6445. survey->time_tx, NL80211_SURVEY_INFO_PAD))
  6446. goto nla_put_failure;
  6447. if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
  6448. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
  6449. survey->time_scan, NL80211_SURVEY_INFO_PAD))
  6450. goto nla_put_failure;
  6451. nla_nest_end(msg, infoattr);
  6452. genlmsg_end(msg, hdr);
  6453. return 0;
  6454. nla_put_failure:
  6455. genlmsg_cancel(msg, hdr);
  6456. return -EMSGSIZE;
  6457. }
  6458. static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
  6459. {
  6460. struct survey_info survey;
  6461. struct cfg80211_registered_device *rdev;
  6462. struct wireless_dev *wdev;
  6463. int survey_idx = cb->args[2];
  6464. int res;
  6465. bool radio_stats;
  6466. rtnl_lock();
  6467. res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  6468. if (res)
  6469. goto out_err;
  6470. /* prepare_wdev_dump parsed the attributes */
  6471. radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
  6472. if (!wdev->netdev) {
  6473. res = -EINVAL;
  6474. goto out_err;
  6475. }
  6476. if (!rdev->ops->dump_survey) {
  6477. res = -EOPNOTSUPP;
  6478. goto out_err;
  6479. }
  6480. while (1) {
  6481. res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
  6482. if (res == -ENOENT)
  6483. break;
  6484. if (res)
  6485. goto out_err;
  6486. /* don't send disabled channels, but do send non-channel data */
  6487. if (survey.channel &&
  6488. survey.channel->flags & IEEE80211_CHAN_DISABLED) {
  6489. survey_idx++;
  6490. continue;
  6491. }
  6492. if (nl80211_send_survey(skb,
  6493. NETLINK_CB(cb->skb).portid,
  6494. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  6495. wdev->netdev, radio_stats, &survey) < 0)
  6496. goto out;
  6497. survey_idx++;
  6498. }
  6499. out:
  6500. cb->args[2] = survey_idx;
  6501. res = skb->len;
  6502. out_err:
  6503. rtnl_unlock();
  6504. return res;
  6505. }
  6506. static bool nl80211_valid_wpa_versions(u32 wpa_versions)
  6507. {
  6508. return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
  6509. NL80211_WPA_VERSION_2));
  6510. }
  6511. static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
  6512. {
  6513. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6514. struct net_device *dev = info->user_ptr[1];
  6515. struct ieee80211_channel *chan;
  6516. const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
  6517. int err, ssid_len, ie_len = 0, sae_data_len = 0;
  6518. enum nl80211_auth_type auth_type;
  6519. struct key_parse key;
  6520. bool local_state_change;
  6521. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6522. return -EINVAL;
  6523. if (!info->attrs[NL80211_ATTR_MAC])
  6524. return -EINVAL;
  6525. if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
  6526. return -EINVAL;
  6527. if (!info->attrs[NL80211_ATTR_SSID])
  6528. return -EINVAL;
  6529. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  6530. return -EINVAL;
  6531. err = nl80211_parse_key(info, &key);
  6532. if (err)
  6533. return err;
  6534. if (key.idx >= 0) {
  6535. if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
  6536. return -EINVAL;
  6537. if (!key.p.key || !key.p.key_len)
  6538. return -EINVAL;
  6539. if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
  6540. key.p.key_len != WLAN_KEY_LEN_WEP40) &&
  6541. (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
  6542. key.p.key_len != WLAN_KEY_LEN_WEP104))
  6543. return -EINVAL;
  6544. if (key.idx > 3)
  6545. return -EINVAL;
  6546. } else {
  6547. key.p.key_len = 0;
  6548. key.p.key = NULL;
  6549. }
  6550. if (key.idx >= 0) {
  6551. int i;
  6552. bool ok = false;
  6553. for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
  6554. if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
  6555. ok = true;
  6556. break;
  6557. }
  6558. }
  6559. if (!ok)
  6560. return -EINVAL;
  6561. }
  6562. if (!rdev->ops->auth)
  6563. return -EOPNOTSUPP;
  6564. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6565. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6566. return -EOPNOTSUPP;
  6567. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6568. chan = nl80211_get_valid_chan(&rdev->wiphy,
  6569. info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  6570. if (!chan)
  6571. return -EINVAL;
  6572. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6573. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6574. if (info->attrs[NL80211_ATTR_IE]) {
  6575. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6576. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6577. }
  6578. auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  6579. if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
  6580. return -EINVAL;
  6581. if (auth_type == NL80211_AUTHTYPE_SAE &&
  6582. !info->attrs[NL80211_ATTR_SAE_DATA])
  6583. return -EINVAL;
  6584. if (info->attrs[NL80211_ATTR_SAE_DATA]) {
  6585. if (auth_type != NL80211_AUTHTYPE_SAE)
  6586. return -EINVAL;
  6587. sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
  6588. sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
  6589. /* need to include at least Auth Transaction and Status Code */
  6590. if (sae_data_len < 4)
  6591. return -EINVAL;
  6592. }
  6593. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6594. /*
  6595. * Since we no longer track auth state, ignore
  6596. * requests to only change local state.
  6597. */
  6598. if (local_state_change)
  6599. return 0;
  6600. wdev_lock(dev->ieee80211_ptr);
  6601. err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
  6602. ssid, ssid_len, ie, ie_len,
  6603. key.p.key, key.p.key_len, key.idx,
  6604. sae_data, sae_data_len);
  6605. wdev_unlock(dev->ieee80211_ptr);
  6606. return err;
  6607. }
  6608. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  6609. struct genl_info *info,
  6610. struct cfg80211_crypto_settings *settings,
  6611. int cipher_limit)
  6612. {
  6613. memset(settings, 0, sizeof(*settings));
  6614. settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
  6615. if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
  6616. u16 proto;
  6617. proto = nla_get_u16(
  6618. info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
  6619. settings->control_port_ethertype = cpu_to_be16(proto);
  6620. if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  6621. proto != ETH_P_PAE)
  6622. return -EINVAL;
  6623. if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
  6624. settings->control_port_no_encrypt = true;
  6625. } else
  6626. settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
  6627. if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
  6628. void *data;
  6629. int len, i;
  6630. data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  6631. len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  6632. settings->n_ciphers_pairwise = len / sizeof(u32);
  6633. if (len % sizeof(u32))
  6634. return -EINVAL;
  6635. if (settings->n_ciphers_pairwise > cipher_limit)
  6636. return -EINVAL;
  6637. memcpy(settings->ciphers_pairwise, data, len);
  6638. for (i = 0; i < settings->n_ciphers_pairwise; i++)
  6639. if (!cfg80211_supported_cipher_suite(
  6640. &rdev->wiphy,
  6641. settings->ciphers_pairwise[i]))
  6642. return -EINVAL;
  6643. }
  6644. if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
  6645. settings->cipher_group =
  6646. nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
  6647. if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
  6648. settings->cipher_group))
  6649. return -EINVAL;
  6650. }
  6651. if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
  6652. settings->wpa_versions =
  6653. nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
  6654. if (!nl80211_valid_wpa_versions(settings->wpa_versions))
  6655. return -EINVAL;
  6656. }
  6657. if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
  6658. void *data;
  6659. int len;
  6660. data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
  6661. len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
  6662. settings->n_akm_suites = len / sizeof(u32);
  6663. if (len % sizeof(u32))
  6664. return -EINVAL;
  6665. if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
  6666. return -EINVAL;
  6667. memcpy(settings->akm_suites, data, len);
  6668. }
  6669. return 0;
  6670. }
  6671. static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
  6672. {
  6673. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6674. struct net_device *dev = info->user_ptr[1];
  6675. struct ieee80211_channel *chan;
  6676. struct cfg80211_assoc_request req = {};
  6677. const u8 *bssid, *ssid;
  6678. int err, ssid_len = 0;
  6679. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6680. return -EINVAL;
  6681. if (!info->attrs[NL80211_ATTR_MAC] ||
  6682. !info->attrs[NL80211_ATTR_SSID] ||
  6683. !info->attrs[NL80211_ATTR_WIPHY_FREQ])
  6684. return -EINVAL;
  6685. if (!rdev->ops->assoc)
  6686. return -EOPNOTSUPP;
  6687. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6688. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6689. return -EOPNOTSUPP;
  6690. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6691. chan = nl80211_get_valid_chan(&rdev->wiphy,
  6692. info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  6693. if (!chan)
  6694. return -EINVAL;
  6695. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6696. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6697. if (info->attrs[NL80211_ATTR_IE]) {
  6698. req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6699. req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6700. }
  6701. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  6702. enum nl80211_mfp mfp =
  6703. nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  6704. if (mfp == NL80211_MFP_REQUIRED)
  6705. req.use_mfp = true;
  6706. else if (mfp != NL80211_MFP_NO)
  6707. return -EINVAL;
  6708. }
  6709. if (info->attrs[NL80211_ATTR_PREV_BSSID])
  6710. req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
  6711. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  6712. req.flags |= ASSOC_REQ_DISABLE_HT;
  6713. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6714. memcpy(&req.ht_capa_mask,
  6715. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  6716. sizeof(req.ht_capa_mask));
  6717. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  6718. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6719. return -EINVAL;
  6720. memcpy(&req.ht_capa,
  6721. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  6722. sizeof(req.ht_capa));
  6723. }
  6724. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
  6725. req.flags |= ASSOC_REQ_DISABLE_VHT;
  6726. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  6727. memcpy(&req.vht_capa_mask,
  6728. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
  6729. sizeof(req.vht_capa_mask));
  6730. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
  6731. if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  6732. return -EINVAL;
  6733. memcpy(&req.vht_capa,
  6734. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
  6735. sizeof(req.vht_capa));
  6736. }
  6737. if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
  6738. if (!((rdev->wiphy.features &
  6739. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
  6740. (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
  6741. !wiphy_ext_feature_isset(&rdev->wiphy,
  6742. NL80211_EXT_FEATURE_RRM))
  6743. return -EINVAL;
  6744. req.flags |= ASSOC_REQ_USE_RRM;
  6745. }
  6746. err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
  6747. if (!err) {
  6748. wdev_lock(dev->ieee80211_ptr);
  6749. err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
  6750. ssid, ssid_len, &req);
  6751. wdev_unlock(dev->ieee80211_ptr);
  6752. }
  6753. return err;
  6754. }
  6755. static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
  6756. {
  6757. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6758. struct net_device *dev = info->user_ptr[1];
  6759. const u8 *ie = NULL, *bssid;
  6760. int ie_len = 0, err;
  6761. u16 reason_code;
  6762. bool local_state_change;
  6763. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6764. return -EINVAL;
  6765. if (!info->attrs[NL80211_ATTR_MAC])
  6766. return -EINVAL;
  6767. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  6768. return -EINVAL;
  6769. if (!rdev->ops->deauth)
  6770. return -EOPNOTSUPP;
  6771. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6772. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6773. return -EOPNOTSUPP;
  6774. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6775. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  6776. if (reason_code == 0) {
  6777. /* Reason Code 0 is reserved */
  6778. return -EINVAL;
  6779. }
  6780. if (info->attrs[NL80211_ATTR_IE]) {
  6781. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6782. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6783. }
  6784. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6785. wdev_lock(dev->ieee80211_ptr);
  6786. err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
  6787. local_state_change);
  6788. wdev_unlock(dev->ieee80211_ptr);
  6789. return err;
  6790. }
  6791. static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
  6792. {
  6793. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6794. struct net_device *dev = info->user_ptr[1];
  6795. const u8 *ie = NULL, *bssid;
  6796. int ie_len = 0, err;
  6797. u16 reason_code;
  6798. bool local_state_change;
  6799. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6800. return -EINVAL;
  6801. if (!info->attrs[NL80211_ATTR_MAC])
  6802. return -EINVAL;
  6803. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  6804. return -EINVAL;
  6805. if (!rdev->ops->disassoc)
  6806. return -EOPNOTSUPP;
  6807. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6808. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6809. return -EOPNOTSUPP;
  6810. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6811. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  6812. if (reason_code == 0) {
  6813. /* Reason Code 0 is reserved */
  6814. return -EINVAL;
  6815. }
  6816. if (info->attrs[NL80211_ATTR_IE]) {
  6817. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6818. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6819. }
  6820. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6821. wdev_lock(dev->ieee80211_ptr);
  6822. err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
  6823. local_state_change);
  6824. wdev_unlock(dev->ieee80211_ptr);
  6825. return err;
  6826. }
  6827. static bool
  6828. nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
  6829. int mcast_rate[NUM_NL80211_BANDS],
  6830. int rateval)
  6831. {
  6832. struct wiphy *wiphy = &rdev->wiphy;
  6833. bool found = false;
  6834. int band, i;
  6835. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  6836. struct ieee80211_supported_band *sband;
  6837. sband = wiphy->bands[band];
  6838. if (!sband)
  6839. continue;
  6840. for (i = 0; i < sband->n_bitrates; i++) {
  6841. if (sband->bitrates[i].bitrate == rateval) {
  6842. mcast_rate[band] = i + 1;
  6843. found = true;
  6844. break;
  6845. }
  6846. }
  6847. }
  6848. return found;
  6849. }
  6850. static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
  6851. {
  6852. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6853. struct net_device *dev = info->user_ptr[1];
  6854. struct cfg80211_ibss_params ibss;
  6855. struct wiphy *wiphy;
  6856. struct cfg80211_cached_keys *connkeys = NULL;
  6857. int err;
  6858. memset(&ibss, 0, sizeof(ibss));
  6859. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6860. return -EINVAL;
  6861. if (!info->attrs[NL80211_ATTR_SSID] ||
  6862. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  6863. return -EINVAL;
  6864. ibss.beacon_interval = 100;
  6865. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
  6866. ibss.beacon_interval =
  6867. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  6868. err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval);
  6869. if (err)
  6870. return err;
  6871. if (!rdev->ops->join_ibss)
  6872. return -EOPNOTSUPP;
  6873. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  6874. return -EOPNOTSUPP;
  6875. wiphy = &rdev->wiphy;
  6876. if (info->attrs[NL80211_ATTR_MAC]) {
  6877. ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6878. if (!is_valid_ether_addr(ibss.bssid))
  6879. return -EINVAL;
  6880. }
  6881. ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6882. ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6883. if (info->attrs[NL80211_ATTR_IE]) {
  6884. ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6885. ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6886. }
  6887. err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
  6888. if (err)
  6889. return err;
  6890. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
  6891. NL80211_IFTYPE_ADHOC))
  6892. return -EINVAL;
  6893. switch (ibss.chandef.width) {
  6894. case NL80211_CHAN_WIDTH_5:
  6895. case NL80211_CHAN_WIDTH_10:
  6896. case NL80211_CHAN_WIDTH_20_NOHT:
  6897. break;
  6898. case NL80211_CHAN_WIDTH_20:
  6899. case NL80211_CHAN_WIDTH_40:
  6900. if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
  6901. return -EINVAL;
  6902. break;
  6903. case NL80211_CHAN_WIDTH_80:
  6904. case NL80211_CHAN_WIDTH_80P80:
  6905. case NL80211_CHAN_WIDTH_160:
  6906. if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
  6907. return -EINVAL;
  6908. if (!wiphy_ext_feature_isset(&rdev->wiphy,
  6909. NL80211_EXT_FEATURE_VHT_IBSS))
  6910. return -EINVAL;
  6911. break;
  6912. default:
  6913. return -EINVAL;
  6914. }
  6915. ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
  6916. ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  6917. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  6918. u8 *rates =
  6919. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  6920. int n_rates =
  6921. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  6922. struct ieee80211_supported_band *sband =
  6923. wiphy->bands[ibss.chandef.chan->band];
  6924. err = ieee80211_get_ratemask(sband, rates, n_rates,
  6925. &ibss.basic_rates);
  6926. if (err)
  6927. return err;
  6928. }
  6929. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6930. memcpy(&ibss.ht_capa_mask,
  6931. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  6932. sizeof(ibss.ht_capa_mask));
  6933. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  6934. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6935. return -EINVAL;
  6936. memcpy(&ibss.ht_capa,
  6937. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  6938. sizeof(ibss.ht_capa));
  6939. }
  6940. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  6941. !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
  6942. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  6943. return -EINVAL;
  6944. if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  6945. bool no_ht = false;
  6946. connkeys = nl80211_parse_connkeys(rdev,
  6947. info->attrs[NL80211_ATTR_KEYS],
  6948. &no_ht);
  6949. if (IS_ERR(connkeys))
  6950. return PTR_ERR(connkeys);
  6951. if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
  6952. no_ht) {
  6953. kzfree(connkeys);
  6954. return -EINVAL;
  6955. }
  6956. }
  6957. ibss.control_port =
  6958. nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
  6959. ibss.userspace_handles_dfs =
  6960. nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
  6961. err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
  6962. if (err)
  6963. kzfree(connkeys);
  6964. return err;
  6965. }
  6966. static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
  6967. {
  6968. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6969. struct net_device *dev = info->user_ptr[1];
  6970. if (!rdev->ops->leave_ibss)
  6971. return -EOPNOTSUPP;
  6972. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  6973. return -EOPNOTSUPP;
  6974. return cfg80211_leave_ibss(rdev, dev, false);
  6975. }
  6976. static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
  6977. {
  6978. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6979. struct net_device *dev = info->user_ptr[1];
  6980. int mcast_rate[NUM_NL80211_BANDS];
  6981. u32 nla_rate;
  6982. int err;
  6983. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
  6984. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  6985. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
  6986. return -EOPNOTSUPP;
  6987. if (!rdev->ops->set_mcast_rate)
  6988. return -EOPNOTSUPP;
  6989. memset(mcast_rate, 0, sizeof(mcast_rate));
  6990. if (!info->attrs[NL80211_ATTR_MCAST_RATE])
  6991. return -EINVAL;
  6992. nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
  6993. if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
  6994. return -EINVAL;
  6995. err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
  6996. return err;
  6997. }
  6998. static struct sk_buff *
  6999. __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
  7000. struct wireless_dev *wdev, int approxlen,
  7001. u32 portid, u32 seq, enum nl80211_commands cmd,
  7002. enum nl80211_attrs attr,
  7003. const struct nl80211_vendor_cmd_info *info,
  7004. gfp_t gfp)
  7005. {
  7006. struct sk_buff *skb;
  7007. void *hdr;
  7008. struct nlattr *data;
  7009. skb = nlmsg_new(approxlen + 100, gfp);
  7010. if (!skb)
  7011. return NULL;
  7012. hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
  7013. if (!hdr) {
  7014. kfree_skb(skb);
  7015. return NULL;
  7016. }
  7017. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  7018. goto nla_put_failure;
  7019. if (info) {
  7020. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
  7021. info->vendor_id))
  7022. goto nla_put_failure;
  7023. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
  7024. info->subcmd))
  7025. goto nla_put_failure;
  7026. }
  7027. if (wdev) {
  7028. if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
  7029. wdev_id(wdev), NL80211_ATTR_PAD))
  7030. goto nla_put_failure;
  7031. if (wdev->netdev &&
  7032. nla_put_u32(skb, NL80211_ATTR_IFINDEX,
  7033. wdev->netdev->ifindex))
  7034. goto nla_put_failure;
  7035. }
  7036. data = nla_nest_start(skb, attr);
  7037. if (!data)
  7038. goto nla_put_failure;
  7039. ((void **)skb->cb)[0] = rdev;
  7040. ((void **)skb->cb)[1] = hdr;
  7041. ((void **)skb->cb)[2] = data;
  7042. return skb;
  7043. nla_put_failure:
  7044. kfree_skb(skb);
  7045. return NULL;
  7046. }
  7047. struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
  7048. struct wireless_dev *wdev,
  7049. enum nl80211_commands cmd,
  7050. enum nl80211_attrs attr,
  7051. int vendor_event_idx,
  7052. int approxlen, gfp_t gfp)
  7053. {
  7054. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  7055. const struct nl80211_vendor_cmd_info *info;
  7056. switch (cmd) {
  7057. case NL80211_CMD_TESTMODE:
  7058. if (WARN_ON(vendor_event_idx != -1))
  7059. return NULL;
  7060. info = NULL;
  7061. break;
  7062. case NL80211_CMD_VENDOR:
  7063. if (WARN_ON(vendor_event_idx < 0 ||
  7064. vendor_event_idx >= wiphy->n_vendor_events))
  7065. return NULL;
  7066. info = &wiphy->vendor_events[vendor_event_idx];
  7067. break;
  7068. default:
  7069. WARN_ON(1);
  7070. return NULL;
  7071. }
  7072. return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
  7073. cmd, attr, info, gfp);
  7074. }
  7075. EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
  7076. void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
  7077. {
  7078. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  7079. void *hdr = ((void **)skb->cb)[1];
  7080. struct nlattr *data = ((void **)skb->cb)[2];
  7081. enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
  7082. /* clear CB data for netlink core to own from now on */
  7083. memset(skb->cb, 0, sizeof(skb->cb));
  7084. nla_nest_end(skb, data);
  7085. genlmsg_end(skb, hdr);
  7086. if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
  7087. mcgrp = NL80211_MCGRP_VENDOR;
  7088. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
  7089. mcgrp, gfp);
  7090. }
  7091. EXPORT_SYMBOL(__cfg80211_send_event_skb);
  7092. #ifdef CONFIG_NL80211_TESTMODE
  7093. static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
  7094. {
  7095. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7096. struct wireless_dev *wdev =
  7097. __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
  7098. int err;
  7099. if (!rdev->ops->testmode_cmd)
  7100. return -EOPNOTSUPP;
  7101. if (IS_ERR(wdev)) {
  7102. err = PTR_ERR(wdev);
  7103. if (err != -EINVAL)
  7104. return err;
  7105. wdev = NULL;
  7106. } else if (wdev->wiphy != &rdev->wiphy) {
  7107. return -EINVAL;
  7108. }
  7109. if (!info->attrs[NL80211_ATTR_TESTDATA])
  7110. return -EINVAL;
  7111. rdev->cur_cmd_info = info;
  7112. err = rdev_testmode_cmd(rdev, wdev,
  7113. nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
  7114. nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
  7115. rdev->cur_cmd_info = NULL;
  7116. return err;
  7117. }
  7118. static int nl80211_testmode_dump(struct sk_buff *skb,
  7119. struct netlink_callback *cb)
  7120. {
  7121. struct cfg80211_registered_device *rdev;
  7122. int err;
  7123. long phy_idx;
  7124. void *data = NULL;
  7125. int data_len = 0;
  7126. rtnl_lock();
  7127. if (cb->args[0]) {
  7128. /*
  7129. * 0 is a valid index, but not valid for args[0],
  7130. * so we need to offset by 1.
  7131. */
  7132. phy_idx = cb->args[0] - 1;
  7133. } else {
  7134. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  7135. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  7136. nl80211_policy);
  7137. if (err)
  7138. goto out_err;
  7139. rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
  7140. nl80211_fam.attrbuf);
  7141. if (IS_ERR(rdev)) {
  7142. err = PTR_ERR(rdev);
  7143. goto out_err;
  7144. }
  7145. phy_idx = rdev->wiphy_idx;
  7146. rdev = NULL;
  7147. if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
  7148. cb->args[1] =
  7149. (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
  7150. }
  7151. if (cb->args[1]) {
  7152. data = nla_data((void *)cb->args[1]);
  7153. data_len = nla_len((void *)cb->args[1]);
  7154. }
  7155. rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
  7156. if (!rdev) {
  7157. err = -ENOENT;
  7158. goto out_err;
  7159. }
  7160. if (!rdev->ops->testmode_dump) {
  7161. err = -EOPNOTSUPP;
  7162. goto out_err;
  7163. }
  7164. while (1) {
  7165. void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
  7166. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  7167. NL80211_CMD_TESTMODE);
  7168. struct nlattr *tmdata;
  7169. if (!hdr)
  7170. break;
  7171. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
  7172. genlmsg_cancel(skb, hdr);
  7173. break;
  7174. }
  7175. tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
  7176. if (!tmdata) {
  7177. genlmsg_cancel(skb, hdr);
  7178. break;
  7179. }
  7180. err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
  7181. nla_nest_end(skb, tmdata);
  7182. if (err == -ENOBUFS || err == -ENOENT) {
  7183. genlmsg_cancel(skb, hdr);
  7184. break;
  7185. } else if (err) {
  7186. genlmsg_cancel(skb, hdr);
  7187. goto out_err;
  7188. }
  7189. genlmsg_end(skb, hdr);
  7190. }
  7191. err = skb->len;
  7192. /* see above */
  7193. cb->args[0] = phy_idx + 1;
  7194. out_err:
  7195. rtnl_unlock();
  7196. return err;
  7197. }
  7198. #endif
  7199. static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
  7200. {
  7201. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7202. struct net_device *dev = info->user_ptr[1];
  7203. struct cfg80211_connect_params connect;
  7204. struct wiphy *wiphy;
  7205. struct cfg80211_cached_keys *connkeys = NULL;
  7206. int err;
  7207. memset(&connect, 0, sizeof(connect));
  7208. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  7209. return -EINVAL;
  7210. if (!info->attrs[NL80211_ATTR_SSID] ||
  7211. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  7212. return -EINVAL;
  7213. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  7214. connect.auth_type =
  7215. nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  7216. if (!nl80211_valid_auth_type(rdev, connect.auth_type,
  7217. NL80211_CMD_CONNECT))
  7218. return -EINVAL;
  7219. } else
  7220. connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  7221. connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
  7222. err = nl80211_crypto_settings(rdev, info, &connect.crypto,
  7223. NL80211_MAX_NR_CIPHER_SUITES);
  7224. if (err)
  7225. return err;
  7226. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7227. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7228. return -EOPNOTSUPP;
  7229. wiphy = &rdev->wiphy;
  7230. connect.bg_scan_period = -1;
  7231. if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
  7232. (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
  7233. connect.bg_scan_period =
  7234. nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
  7235. }
  7236. if (info->attrs[NL80211_ATTR_MAC])
  7237. connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7238. else if (info->attrs[NL80211_ATTR_MAC_HINT])
  7239. connect.bssid_hint =
  7240. nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
  7241. connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  7242. connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  7243. if (info->attrs[NL80211_ATTR_IE]) {
  7244. connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  7245. connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  7246. }
  7247. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  7248. connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  7249. if (connect.mfp != NL80211_MFP_REQUIRED &&
  7250. connect.mfp != NL80211_MFP_NO)
  7251. return -EINVAL;
  7252. } else {
  7253. connect.mfp = NL80211_MFP_NO;
  7254. }
  7255. if (info->attrs[NL80211_ATTR_PREV_BSSID])
  7256. connect.prev_bssid =
  7257. nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
  7258. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7259. connect.channel = nl80211_get_valid_chan(
  7260. wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  7261. if (!connect.channel)
  7262. return -EINVAL;
  7263. } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
  7264. connect.channel_hint = nl80211_get_valid_chan(
  7265. wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
  7266. if (!connect.channel_hint)
  7267. return -EINVAL;
  7268. }
  7269. if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  7270. connkeys = nl80211_parse_connkeys(rdev,
  7271. info->attrs[NL80211_ATTR_KEYS], NULL);
  7272. if (IS_ERR(connkeys))
  7273. return PTR_ERR(connkeys);
  7274. }
  7275. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  7276. connect.flags |= ASSOC_REQ_DISABLE_HT;
  7277. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  7278. memcpy(&connect.ht_capa_mask,
  7279. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  7280. sizeof(connect.ht_capa_mask));
  7281. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  7282. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
  7283. kzfree(connkeys);
  7284. return -EINVAL;
  7285. }
  7286. memcpy(&connect.ht_capa,
  7287. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  7288. sizeof(connect.ht_capa));
  7289. }
  7290. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
  7291. connect.flags |= ASSOC_REQ_DISABLE_VHT;
  7292. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  7293. memcpy(&connect.vht_capa_mask,
  7294. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
  7295. sizeof(connect.vht_capa_mask));
  7296. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
  7297. if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
  7298. kzfree(connkeys);
  7299. return -EINVAL;
  7300. }
  7301. memcpy(&connect.vht_capa,
  7302. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
  7303. sizeof(connect.vht_capa));
  7304. }
  7305. if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
  7306. if (!((rdev->wiphy.features &
  7307. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
  7308. (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
  7309. !wiphy_ext_feature_isset(&rdev->wiphy,
  7310. NL80211_EXT_FEATURE_RRM)) {
  7311. kzfree(connkeys);
  7312. return -EINVAL;
  7313. }
  7314. connect.flags |= ASSOC_REQ_USE_RRM;
  7315. }
  7316. connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
  7317. if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
  7318. kzfree(connkeys);
  7319. return -EOPNOTSUPP;
  7320. }
  7321. if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
  7322. /* bss selection makes no sense if bssid is set */
  7323. if (connect.bssid) {
  7324. kzfree(connkeys);
  7325. return -EINVAL;
  7326. }
  7327. err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
  7328. wiphy, &connect.bss_select);
  7329. if (err) {
  7330. kzfree(connkeys);
  7331. return err;
  7332. }
  7333. }
  7334. wdev_lock(dev->ieee80211_ptr);
  7335. err = cfg80211_connect(rdev, dev, &connect, connkeys,
  7336. connect.prev_bssid);
  7337. wdev_unlock(dev->ieee80211_ptr);
  7338. if (err)
  7339. kzfree(connkeys);
  7340. return err;
  7341. }
  7342. static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
  7343. {
  7344. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7345. struct net_device *dev = info->user_ptr[1];
  7346. u16 reason;
  7347. int ret;
  7348. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  7349. reason = WLAN_REASON_DEAUTH_LEAVING;
  7350. else
  7351. reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  7352. if (reason == 0)
  7353. return -EINVAL;
  7354. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7355. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7356. return -EOPNOTSUPP;
  7357. wdev_lock(dev->ieee80211_ptr);
  7358. ret = cfg80211_disconnect(rdev, dev, reason, true);
  7359. wdev_unlock(dev->ieee80211_ptr);
  7360. return ret;
  7361. }
  7362. static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
  7363. {
  7364. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7365. struct net *net;
  7366. int err;
  7367. if (info->attrs[NL80211_ATTR_PID]) {
  7368. u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
  7369. net = get_net_ns_by_pid(pid);
  7370. } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
  7371. u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
  7372. net = get_net_ns_by_fd(fd);
  7373. } else {
  7374. return -EINVAL;
  7375. }
  7376. if (IS_ERR(net))
  7377. return PTR_ERR(net);
  7378. err = 0;
  7379. /* check if anything to do */
  7380. if (!net_eq(wiphy_net(&rdev->wiphy), net))
  7381. err = cfg80211_switch_netns(rdev, net);
  7382. put_net(net);
  7383. return err;
  7384. }
  7385. static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
  7386. {
  7387. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7388. int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
  7389. struct cfg80211_pmksa *pmksa) = NULL;
  7390. struct net_device *dev = info->user_ptr[1];
  7391. struct cfg80211_pmksa pmksa;
  7392. memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
  7393. if (!info->attrs[NL80211_ATTR_MAC])
  7394. return -EINVAL;
  7395. if (!info->attrs[NL80211_ATTR_PMKID])
  7396. return -EINVAL;
  7397. pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
  7398. pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7399. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7400. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7401. return -EOPNOTSUPP;
  7402. switch (info->genlhdr->cmd) {
  7403. case NL80211_CMD_SET_PMKSA:
  7404. rdev_ops = rdev->ops->set_pmksa;
  7405. break;
  7406. case NL80211_CMD_DEL_PMKSA:
  7407. rdev_ops = rdev->ops->del_pmksa;
  7408. break;
  7409. default:
  7410. WARN_ON(1);
  7411. break;
  7412. }
  7413. if (!rdev_ops)
  7414. return -EOPNOTSUPP;
  7415. return rdev_ops(&rdev->wiphy, dev, &pmksa);
  7416. }
  7417. static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
  7418. {
  7419. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7420. struct net_device *dev = info->user_ptr[1];
  7421. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7422. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7423. return -EOPNOTSUPP;
  7424. if (!rdev->ops->flush_pmksa)
  7425. return -EOPNOTSUPP;
  7426. return rdev_flush_pmksa(rdev, dev);
  7427. }
  7428. static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
  7429. {
  7430. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7431. struct net_device *dev = info->user_ptr[1];
  7432. u8 action_code, dialog_token;
  7433. u32 peer_capability = 0;
  7434. u16 status_code;
  7435. u8 *peer;
  7436. bool initiator;
  7437. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  7438. !rdev->ops->tdls_mgmt)
  7439. return -EOPNOTSUPP;
  7440. if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
  7441. !info->attrs[NL80211_ATTR_STATUS_CODE] ||
  7442. !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
  7443. !info->attrs[NL80211_ATTR_IE] ||
  7444. !info->attrs[NL80211_ATTR_MAC])
  7445. return -EINVAL;
  7446. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7447. action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
  7448. status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
  7449. dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
  7450. initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
  7451. if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
  7452. peer_capability =
  7453. nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
  7454. return rdev_tdls_mgmt(rdev, dev, peer, action_code,
  7455. dialog_token, status_code, peer_capability,
  7456. initiator,
  7457. nla_data(info->attrs[NL80211_ATTR_IE]),
  7458. nla_len(info->attrs[NL80211_ATTR_IE]));
  7459. }
  7460. static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
  7461. {
  7462. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7463. struct net_device *dev = info->user_ptr[1];
  7464. enum nl80211_tdls_operation operation;
  7465. u8 *peer;
  7466. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  7467. !rdev->ops->tdls_oper)
  7468. return -EOPNOTSUPP;
  7469. if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
  7470. !info->attrs[NL80211_ATTR_MAC])
  7471. return -EINVAL;
  7472. operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
  7473. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7474. return rdev_tdls_oper(rdev, dev, peer, operation);
  7475. }
  7476. static int nl80211_remain_on_channel(struct sk_buff *skb,
  7477. struct genl_info *info)
  7478. {
  7479. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7480. struct wireless_dev *wdev = info->user_ptr[1];
  7481. struct cfg80211_chan_def chandef;
  7482. struct sk_buff *msg;
  7483. void *hdr;
  7484. u64 cookie;
  7485. u32 duration;
  7486. int err;
  7487. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  7488. !info->attrs[NL80211_ATTR_DURATION])
  7489. return -EINVAL;
  7490. duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  7491. if (!rdev->ops->remain_on_channel ||
  7492. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
  7493. return -EOPNOTSUPP;
  7494. /*
  7495. * We should be on that channel for at least a minimum amount of
  7496. * time (10ms) but no longer than the driver supports.
  7497. */
  7498. if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
  7499. duration > rdev->wiphy.max_remain_on_channel_duration)
  7500. return -EINVAL;
  7501. err = nl80211_parse_chandef(rdev, info, &chandef);
  7502. if (err)
  7503. return err;
  7504. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7505. if (!msg)
  7506. return -ENOMEM;
  7507. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7508. NL80211_CMD_REMAIN_ON_CHANNEL);
  7509. if (!hdr) {
  7510. err = -ENOBUFS;
  7511. goto free_msg;
  7512. }
  7513. err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
  7514. duration, &cookie);
  7515. if (err)
  7516. goto free_msg;
  7517. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  7518. NL80211_ATTR_PAD))
  7519. goto nla_put_failure;
  7520. genlmsg_end(msg, hdr);
  7521. return genlmsg_reply(msg, info);
  7522. nla_put_failure:
  7523. err = -ENOBUFS;
  7524. free_msg:
  7525. nlmsg_free(msg);
  7526. return err;
  7527. }
  7528. static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
  7529. struct genl_info *info)
  7530. {
  7531. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7532. struct wireless_dev *wdev = info->user_ptr[1];
  7533. u64 cookie;
  7534. if (!info->attrs[NL80211_ATTR_COOKIE])
  7535. return -EINVAL;
  7536. if (!rdev->ops->cancel_remain_on_channel)
  7537. return -EOPNOTSUPP;
  7538. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  7539. return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
  7540. }
  7541. static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
  7542. struct genl_info *info)
  7543. {
  7544. struct cfg80211_bitrate_mask mask;
  7545. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7546. struct net_device *dev = info->user_ptr[1];
  7547. int err;
  7548. if (!rdev->ops->set_bitrate_mask)
  7549. return -EOPNOTSUPP;
  7550. err = nl80211_parse_tx_bitrate_mask(info, &mask);
  7551. if (err)
  7552. return err;
  7553. return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
  7554. }
  7555. static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
  7556. {
  7557. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7558. struct wireless_dev *wdev = info->user_ptr[1];
  7559. u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
  7560. if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
  7561. return -EINVAL;
  7562. if (info->attrs[NL80211_ATTR_FRAME_TYPE])
  7563. frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
  7564. switch (wdev->iftype) {
  7565. case NL80211_IFTYPE_STATION:
  7566. case NL80211_IFTYPE_ADHOC:
  7567. case NL80211_IFTYPE_P2P_CLIENT:
  7568. case NL80211_IFTYPE_AP:
  7569. case NL80211_IFTYPE_AP_VLAN:
  7570. case NL80211_IFTYPE_MESH_POINT:
  7571. case NL80211_IFTYPE_P2P_GO:
  7572. case NL80211_IFTYPE_P2P_DEVICE:
  7573. break;
  7574. case NL80211_IFTYPE_NAN:
  7575. default:
  7576. return -EOPNOTSUPP;
  7577. }
  7578. /* not much point in registering if we can't reply */
  7579. if (!rdev->ops->mgmt_tx)
  7580. return -EOPNOTSUPP;
  7581. return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
  7582. nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
  7583. nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
  7584. }
  7585. static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
  7586. {
  7587. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7588. struct wireless_dev *wdev = info->user_ptr[1];
  7589. struct cfg80211_chan_def chandef;
  7590. int err;
  7591. void *hdr = NULL;
  7592. u64 cookie;
  7593. struct sk_buff *msg = NULL;
  7594. struct cfg80211_mgmt_tx_params params = {
  7595. .dont_wait_for_ack =
  7596. info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
  7597. };
  7598. if (!info->attrs[NL80211_ATTR_FRAME])
  7599. return -EINVAL;
  7600. if (!rdev->ops->mgmt_tx)
  7601. return -EOPNOTSUPP;
  7602. switch (wdev->iftype) {
  7603. case NL80211_IFTYPE_P2P_DEVICE:
  7604. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  7605. return -EINVAL;
  7606. case NL80211_IFTYPE_STATION:
  7607. case NL80211_IFTYPE_ADHOC:
  7608. case NL80211_IFTYPE_P2P_CLIENT:
  7609. case NL80211_IFTYPE_AP:
  7610. case NL80211_IFTYPE_AP_VLAN:
  7611. case NL80211_IFTYPE_MESH_POINT:
  7612. case NL80211_IFTYPE_P2P_GO:
  7613. break;
  7614. case NL80211_IFTYPE_NAN:
  7615. default:
  7616. return -EOPNOTSUPP;
  7617. }
  7618. if (info->attrs[NL80211_ATTR_DURATION]) {
  7619. if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  7620. return -EINVAL;
  7621. params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  7622. /*
  7623. * We should wait on the channel for at least a minimum amount
  7624. * of time (10ms) but no longer than the driver supports.
  7625. */
  7626. if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
  7627. params.wait > rdev->wiphy.max_remain_on_channel_duration)
  7628. return -EINVAL;
  7629. }
  7630. params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
  7631. if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  7632. return -EINVAL;
  7633. params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  7634. /* get the channel if any has been specified, otherwise pass NULL to
  7635. * the driver. The latter will use the current one
  7636. */
  7637. chandef.chan = NULL;
  7638. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7639. err = nl80211_parse_chandef(rdev, info, &chandef);
  7640. if (err)
  7641. return err;
  7642. }
  7643. if (!chandef.chan && params.offchan)
  7644. return -EINVAL;
  7645. params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
  7646. params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
  7647. if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
  7648. int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
  7649. int i;
  7650. if (len % sizeof(u16))
  7651. return -EINVAL;
  7652. params.n_csa_offsets = len / sizeof(u16);
  7653. params.csa_offsets =
  7654. nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
  7655. /* check that all the offsets fit the frame */
  7656. for (i = 0; i < params.n_csa_offsets; i++) {
  7657. if (params.csa_offsets[i] >= params.len)
  7658. return -EINVAL;
  7659. }
  7660. }
  7661. if (!params.dont_wait_for_ack) {
  7662. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7663. if (!msg)
  7664. return -ENOMEM;
  7665. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7666. NL80211_CMD_FRAME);
  7667. if (!hdr) {
  7668. err = -ENOBUFS;
  7669. goto free_msg;
  7670. }
  7671. }
  7672. params.chan = chandef.chan;
  7673. err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
  7674. if (err)
  7675. goto free_msg;
  7676. if (msg) {
  7677. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  7678. NL80211_ATTR_PAD))
  7679. goto nla_put_failure;
  7680. genlmsg_end(msg, hdr);
  7681. return genlmsg_reply(msg, info);
  7682. }
  7683. return 0;
  7684. nla_put_failure:
  7685. err = -ENOBUFS;
  7686. free_msg:
  7687. nlmsg_free(msg);
  7688. return err;
  7689. }
  7690. static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
  7691. {
  7692. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7693. struct wireless_dev *wdev = info->user_ptr[1];
  7694. u64 cookie;
  7695. if (!info->attrs[NL80211_ATTR_COOKIE])
  7696. return -EINVAL;
  7697. if (!rdev->ops->mgmt_tx_cancel_wait)
  7698. return -EOPNOTSUPP;
  7699. switch (wdev->iftype) {
  7700. case NL80211_IFTYPE_STATION:
  7701. case NL80211_IFTYPE_ADHOC:
  7702. case NL80211_IFTYPE_P2P_CLIENT:
  7703. case NL80211_IFTYPE_AP:
  7704. case NL80211_IFTYPE_AP_VLAN:
  7705. case NL80211_IFTYPE_P2P_GO:
  7706. case NL80211_IFTYPE_P2P_DEVICE:
  7707. break;
  7708. case NL80211_IFTYPE_NAN:
  7709. default:
  7710. return -EOPNOTSUPP;
  7711. }
  7712. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  7713. return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
  7714. }
  7715. static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
  7716. {
  7717. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7718. struct wireless_dev *wdev;
  7719. struct net_device *dev = info->user_ptr[1];
  7720. u8 ps_state;
  7721. bool state;
  7722. int err;
  7723. if (!info->attrs[NL80211_ATTR_PS_STATE])
  7724. return -EINVAL;
  7725. ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
  7726. if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
  7727. return -EINVAL;
  7728. wdev = dev->ieee80211_ptr;
  7729. if (!rdev->ops->set_power_mgmt)
  7730. return -EOPNOTSUPP;
  7731. state = (ps_state == NL80211_PS_ENABLED) ? true : false;
  7732. if (state == wdev->ps)
  7733. return 0;
  7734. err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
  7735. if (!err)
  7736. wdev->ps = state;
  7737. return err;
  7738. }
  7739. static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
  7740. {
  7741. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7742. enum nl80211_ps_state ps_state;
  7743. struct wireless_dev *wdev;
  7744. struct net_device *dev = info->user_ptr[1];
  7745. struct sk_buff *msg;
  7746. void *hdr;
  7747. int err;
  7748. wdev = dev->ieee80211_ptr;
  7749. if (!rdev->ops->set_power_mgmt)
  7750. return -EOPNOTSUPP;
  7751. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7752. if (!msg)
  7753. return -ENOMEM;
  7754. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7755. NL80211_CMD_GET_POWER_SAVE);
  7756. if (!hdr) {
  7757. err = -ENOBUFS;
  7758. goto free_msg;
  7759. }
  7760. if (wdev->ps)
  7761. ps_state = NL80211_PS_ENABLED;
  7762. else
  7763. ps_state = NL80211_PS_DISABLED;
  7764. if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
  7765. goto nla_put_failure;
  7766. genlmsg_end(msg, hdr);
  7767. return genlmsg_reply(msg, info);
  7768. nla_put_failure:
  7769. err = -ENOBUFS;
  7770. free_msg:
  7771. nlmsg_free(msg);
  7772. return err;
  7773. }
  7774. static const struct nla_policy
  7775. nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
  7776. [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
  7777. [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
  7778. [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
  7779. [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
  7780. [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
  7781. [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
  7782. };
  7783. static int nl80211_set_cqm_txe(struct genl_info *info,
  7784. u32 rate, u32 pkts, u32 intvl)
  7785. {
  7786. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7787. struct net_device *dev = info->user_ptr[1];
  7788. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7789. if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
  7790. return -EINVAL;
  7791. if (!rdev->ops->set_cqm_txe_config)
  7792. return -EOPNOTSUPP;
  7793. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  7794. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7795. return -EOPNOTSUPP;
  7796. return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
  7797. }
  7798. static int nl80211_set_cqm_rssi(struct genl_info *info,
  7799. s32 threshold, u32 hysteresis)
  7800. {
  7801. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7802. struct net_device *dev = info->user_ptr[1];
  7803. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7804. if (threshold > 0)
  7805. return -EINVAL;
  7806. /* disabling - hysteresis should also be zero then */
  7807. if (threshold == 0)
  7808. hysteresis = 0;
  7809. if (!rdev->ops->set_cqm_rssi_config)
  7810. return -EOPNOTSUPP;
  7811. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  7812. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7813. return -EOPNOTSUPP;
  7814. return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
  7815. }
  7816. static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
  7817. {
  7818. struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
  7819. struct nlattr *cqm;
  7820. int err;
  7821. cqm = info->attrs[NL80211_ATTR_CQM];
  7822. if (!cqm)
  7823. return -EINVAL;
  7824. err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
  7825. nl80211_attr_cqm_policy);
  7826. if (err)
  7827. return err;
  7828. if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
  7829. attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
  7830. s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
  7831. u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
  7832. return nl80211_set_cqm_rssi(info, threshold, hysteresis);
  7833. }
  7834. if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
  7835. attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
  7836. attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
  7837. u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
  7838. u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
  7839. u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
  7840. return nl80211_set_cqm_txe(info, rate, pkts, intvl);
  7841. }
  7842. return -EINVAL;
  7843. }
  7844. static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
  7845. {
  7846. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7847. struct net_device *dev = info->user_ptr[1];
  7848. struct ocb_setup setup = {};
  7849. int err;
  7850. err = nl80211_parse_chandef(rdev, info, &setup.chandef);
  7851. if (err)
  7852. return err;
  7853. return cfg80211_join_ocb(rdev, dev, &setup);
  7854. }
  7855. static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
  7856. {
  7857. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7858. struct net_device *dev = info->user_ptr[1];
  7859. return cfg80211_leave_ocb(rdev, dev);
  7860. }
  7861. static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
  7862. {
  7863. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7864. struct net_device *dev = info->user_ptr[1];
  7865. struct mesh_config cfg;
  7866. struct mesh_setup setup;
  7867. int err;
  7868. /* start with default */
  7869. memcpy(&cfg, &default_mesh_config, sizeof(cfg));
  7870. memcpy(&setup, &default_mesh_setup, sizeof(setup));
  7871. if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
  7872. /* and parse parameters if given */
  7873. err = nl80211_parse_mesh_config(info, &cfg, NULL);
  7874. if (err)
  7875. return err;
  7876. }
  7877. if (!info->attrs[NL80211_ATTR_MESH_ID] ||
  7878. !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
  7879. return -EINVAL;
  7880. setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
  7881. setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  7882. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  7883. !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
  7884. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  7885. return -EINVAL;
  7886. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
  7887. setup.beacon_interval =
  7888. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  7889. err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval);
  7890. if (err)
  7891. return err;
  7892. }
  7893. if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
  7894. setup.dtim_period =
  7895. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  7896. if (setup.dtim_period < 1 || setup.dtim_period > 100)
  7897. return -EINVAL;
  7898. }
  7899. if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
  7900. /* parse additional setup parameters if given */
  7901. err = nl80211_parse_mesh_setup(info, &setup);
  7902. if (err)
  7903. return err;
  7904. }
  7905. if (setup.user_mpm)
  7906. cfg.auto_open_plinks = false;
  7907. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7908. err = nl80211_parse_chandef(rdev, info, &setup.chandef);
  7909. if (err)
  7910. return err;
  7911. } else {
  7912. /* cfg80211_join_mesh() will sort it out */
  7913. setup.chandef.chan = NULL;
  7914. }
  7915. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  7916. u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  7917. int n_rates =
  7918. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  7919. struct ieee80211_supported_band *sband;
  7920. if (!setup.chandef.chan)
  7921. return -EINVAL;
  7922. sband = rdev->wiphy.bands[setup.chandef.chan->band];
  7923. err = ieee80211_get_ratemask(sband, rates, n_rates,
  7924. &setup.basic_rates);
  7925. if (err)
  7926. return err;
  7927. }
  7928. if (info->attrs[NL80211_ATTR_TX_RATES]) {
  7929. err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
  7930. if (err)
  7931. return err;
  7932. err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
  7933. &setup.beacon_rate);
  7934. if (err)
  7935. return err;
  7936. }
  7937. return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
  7938. }
  7939. static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
  7940. {
  7941. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7942. struct net_device *dev = info->user_ptr[1];
  7943. return cfg80211_leave_mesh(rdev, dev);
  7944. }
  7945. #ifdef CONFIG_PM
  7946. static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
  7947. struct cfg80211_registered_device *rdev)
  7948. {
  7949. struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
  7950. struct nlattr *nl_pats, *nl_pat;
  7951. int i, pat_len;
  7952. if (!wowlan->n_patterns)
  7953. return 0;
  7954. nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
  7955. if (!nl_pats)
  7956. return -ENOBUFS;
  7957. for (i = 0; i < wowlan->n_patterns; i++) {
  7958. nl_pat = nla_nest_start(msg, i + 1);
  7959. if (!nl_pat)
  7960. return -ENOBUFS;
  7961. pat_len = wowlan->patterns[i].pattern_len;
  7962. if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
  7963. wowlan->patterns[i].mask) ||
  7964. nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
  7965. wowlan->patterns[i].pattern) ||
  7966. nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
  7967. wowlan->patterns[i].pkt_offset))
  7968. return -ENOBUFS;
  7969. nla_nest_end(msg, nl_pat);
  7970. }
  7971. nla_nest_end(msg, nl_pats);
  7972. return 0;
  7973. }
  7974. static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
  7975. struct cfg80211_wowlan_tcp *tcp)
  7976. {
  7977. struct nlattr *nl_tcp;
  7978. if (!tcp)
  7979. return 0;
  7980. nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
  7981. if (!nl_tcp)
  7982. return -ENOBUFS;
  7983. if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
  7984. nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
  7985. nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
  7986. nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
  7987. nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
  7988. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  7989. tcp->payload_len, tcp->payload) ||
  7990. nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
  7991. tcp->data_interval) ||
  7992. nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  7993. tcp->wake_len, tcp->wake_data) ||
  7994. nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
  7995. DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
  7996. return -ENOBUFS;
  7997. if (tcp->payload_seq.len &&
  7998. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
  7999. sizeof(tcp->payload_seq), &tcp->payload_seq))
  8000. return -ENOBUFS;
  8001. if (tcp->payload_tok.len &&
  8002. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  8003. sizeof(tcp->payload_tok) + tcp->tokens_size,
  8004. &tcp->payload_tok))
  8005. return -ENOBUFS;
  8006. nla_nest_end(msg, nl_tcp);
  8007. return 0;
  8008. }
  8009. static int nl80211_send_wowlan_nd(struct sk_buff *msg,
  8010. struct cfg80211_sched_scan_request *req)
  8011. {
  8012. struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
  8013. int i;
  8014. if (!req)
  8015. return 0;
  8016. nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
  8017. if (!nd)
  8018. return -ENOBUFS;
  8019. if (req->n_scan_plans == 1 &&
  8020. nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
  8021. req->scan_plans[0].interval * 1000))
  8022. return -ENOBUFS;
  8023. if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
  8024. return -ENOBUFS;
  8025. freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  8026. if (!freqs)
  8027. return -ENOBUFS;
  8028. for (i = 0; i < req->n_channels; i++) {
  8029. if (nla_put_u32(msg, i, req->channels[i]->center_freq))
  8030. return -ENOBUFS;
  8031. }
  8032. nla_nest_end(msg, freqs);
  8033. if (req->n_match_sets) {
  8034. matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
  8035. if (!matches)
  8036. return -ENOBUFS;
  8037. for (i = 0; i < req->n_match_sets; i++) {
  8038. match = nla_nest_start(msg, i);
  8039. if (!match)
  8040. return -ENOBUFS;
  8041. if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
  8042. req->match_sets[i].ssid.ssid_len,
  8043. req->match_sets[i].ssid.ssid))
  8044. return -ENOBUFS;
  8045. nla_nest_end(msg, match);
  8046. }
  8047. nla_nest_end(msg, matches);
  8048. }
  8049. scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
  8050. if (!scan_plans)
  8051. return -ENOBUFS;
  8052. for (i = 0; i < req->n_scan_plans; i++) {
  8053. scan_plan = nla_nest_start(msg, i + 1);
  8054. if (!scan_plan)
  8055. return -ENOBUFS;
  8056. if (!scan_plan ||
  8057. nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
  8058. req->scan_plans[i].interval) ||
  8059. (req->scan_plans[i].iterations &&
  8060. nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
  8061. req->scan_plans[i].iterations)))
  8062. return -ENOBUFS;
  8063. nla_nest_end(msg, scan_plan);
  8064. }
  8065. nla_nest_end(msg, scan_plans);
  8066. nla_nest_end(msg, nd);
  8067. return 0;
  8068. }
  8069. static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
  8070. {
  8071. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8072. struct sk_buff *msg;
  8073. void *hdr;
  8074. u32 size = NLMSG_DEFAULT_SIZE;
  8075. if (!rdev->wiphy.wowlan)
  8076. return -EOPNOTSUPP;
  8077. if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
  8078. /* adjust size to have room for all the data */
  8079. size += rdev->wiphy.wowlan_config->tcp->tokens_size +
  8080. rdev->wiphy.wowlan_config->tcp->payload_len +
  8081. rdev->wiphy.wowlan_config->tcp->wake_len +
  8082. rdev->wiphy.wowlan_config->tcp->wake_len / 8;
  8083. }
  8084. msg = nlmsg_new(size, GFP_KERNEL);
  8085. if (!msg)
  8086. return -ENOMEM;
  8087. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8088. NL80211_CMD_GET_WOWLAN);
  8089. if (!hdr)
  8090. goto nla_put_failure;
  8091. if (rdev->wiphy.wowlan_config) {
  8092. struct nlattr *nl_wowlan;
  8093. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  8094. if (!nl_wowlan)
  8095. goto nla_put_failure;
  8096. if ((rdev->wiphy.wowlan_config->any &&
  8097. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  8098. (rdev->wiphy.wowlan_config->disconnect &&
  8099. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  8100. (rdev->wiphy.wowlan_config->magic_pkt &&
  8101. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  8102. (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
  8103. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  8104. (rdev->wiphy.wowlan_config->eap_identity_req &&
  8105. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  8106. (rdev->wiphy.wowlan_config->four_way_handshake &&
  8107. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  8108. (rdev->wiphy.wowlan_config->rfkill_release &&
  8109. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
  8110. goto nla_put_failure;
  8111. if (nl80211_send_wowlan_patterns(msg, rdev))
  8112. goto nla_put_failure;
  8113. if (nl80211_send_wowlan_tcp(msg,
  8114. rdev->wiphy.wowlan_config->tcp))
  8115. goto nla_put_failure;
  8116. if (nl80211_send_wowlan_nd(
  8117. msg,
  8118. rdev->wiphy.wowlan_config->nd_config))
  8119. goto nla_put_failure;
  8120. nla_nest_end(msg, nl_wowlan);
  8121. }
  8122. genlmsg_end(msg, hdr);
  8123. return genlmsg_reply(msg, info);
  8124. nla_put_failure:
  8125. nlmsg_free(msg);
  8126. return -ENOBUFS;
  8127. }
  8128. static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
  8129. struct nlattr *attr,
  8130. struct cfg80211_wowlan *trig)
  8131. {
  8132. struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
  8133. struct cfg80211_wowlan_tcp *cfg;
  8134. struct nl80211_wowlan_tcp_data_token *tok = NULL;
  8135. struct nl80211_wowlan_tcp_data_seq *seq = NULL;
  8136. u32 size;
  8137. u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
  8138. int err, port;
  8139. if (!rdev->wiphy.wowlan->tcp)
  8140. return -EINVAL;
  8141. err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
  8142. nla_data(attr), nla_len(attr),
  8143. nl80211_wowlan_tcp_policy);
  8144. if (err)
  8145. return err;
  8146. if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
  8147. !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
  8148. !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
  8149. !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
  8150. !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
  8151. !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
  8152. !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
  8153. !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
  8154. return -EINVAL;
  8155. data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
  8156. if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
  8157. return -EINVAL;
  8158. if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
  8159. rdev->wiphy.wowlan->tcp->data_interval_max ||
  8160. nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
  8161. return -EINVAL;
  8162. wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
  8163. if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
  8164. return -EINVAL;
  8165. wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
  8166. if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
  8167. return -EINVAL;
  8168. if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
  8169. u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
  8170. tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
  8171. tokens_size = tokln - sizeof(*tok);
  8172. if (!tok->len || tokens_size % tok->len)
  8173. return -EINVAL;
  8174. if (!rdev->wiphy.wowlan->tcp->tok)
  8175. return -EINVAL;
  8176. if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
  8177. return -EINVAL;
  8178. if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
  8179. return -EINVAL;
  8180. if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
  8181. return -EINVAL;
  8182. if (tok->offset + tok->len > data_size)
  8183. return -EINVAL;
  8184. }
  8185. if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
  8186. seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
  8187. if (!rdev->wiphy.wowlan->tcp->seq)
  8188. return -EINVAL;
  8189. if (seq->len == 0 || seq->len > 4)
  8190. return -EINVAL;
  8191. if (seq->len + seq->offset > data_size)
  8192. return -EINVAL;
  8193. }
  8194. size = sizeof(*cfg);
  8195. size += data_size;
  8196. size += wake_size + wake_mask_size;
  8197. size += tokens_size;
  8198. cfg = kzalloc(size, GFP_KERNEL);
  8199. if (!cfg)
  8200. return -ENOMEM;
  8201. cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
  8202. cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
  8203. memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
  8204. ETH_ALEN);
  8205. if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
  8206. port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
  8207. else
  8208. port = 0;
  8209. #ifdef CONFIG_INET
  8210. /* allocate a socket and port for it and use it */
  8211. err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
  8212. IPPROTO_TCP, &cfg->sock, 1);
  8213. if (err) {
  8214. kfree(cfg);
  8215. return err;
  8216. }
  8217. if (inet_csk_get_port(cfg->sock->sk, port)) {
  8218. sock_release(cfg->sock);
  8219. kfree(cfg);
  8220. return -EADDRINUSE;
  8221. }
  8222. cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
  8223. #else
  8224. if (!port) {
  8225. kfree(cfg);
  8226. return -EINVAL;
  8227. }
  8228. cfg->src_port = port;
  8229. #endif
  8230. cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
  8231. cfg->payload_len = data_size;
  8232. cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
  8233. memcpy((void *)cfg->payload,
  8234. nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
  8235. data_size);
  8236. if (seq)
  8237. cfg->payload_seq = *seq;
  8238. cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
  8239. cfg->wake_len = wake_size;
  8240. cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
  8241. memcpy((void *)cfg->wake_data,
  8242. nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
  8243. wake_size);
  8244. cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
  8245. data_size + wake_size;
  8246. memcpy((void *)cfg->wake_mask,
  8247. nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
  8248. wake_mask_size);
  8249. if (tok) {
  8250. cfg->tokens_size = tokens_size;
  8251. memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
  8252. }
  8253. trig->tcp = cfg;
  8254. return 0;
  8255. }
  8256. static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
  8257. const struct wiphy_wowlan_support *wowlan,
  8258. struct nlattr *attr,
  8259. struct cfg80211_wowlan *trig)
  8260. {
  8261. struct nlattr **tb;
  8262. int err;
  8263. tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
  8264. if (!tb)
  8265. return -ENOMEM;
  8266. if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
  8267. err = -EOPNOTSUPP;
  8268. goto out;
  8269. }
  8270. err = nla_parse(tb, NL80211_ATTR_MAX,
  8271. nla_data(attr), nla_len(attr),
  8272. nl80211_policy);
  8273. if (err)
  8274. goto out;
  8275. trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
  8276. err = PTR_ERR_OR_ZERO(trig->nd_config);
  8277. if (err)
  8278. trig->nd_config = NULL;
  8279. out:
  8280. kfree(tb);
  8281. return err;
  8282. }
  8283. static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
  8284. {
  8285. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8286. struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
  8287. struct cfg80211_wowlan new_triggers = {};
  8288. struct cfg80211_wowlan *ntrig;
  8289. const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
  8290. int err, i;
  8291. bool prev_enabled = rdev->wiphy.wowlan_config;
  8292. bool regular = false;
  8293. if (!wowlan)
  8294. return -EOPNOTSUPP;
  8295. if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
  8296. cfg80211_rdev_free_wowlan(rdev);
  8297. rdev->wiphy.wowlan_config = NULL;
  8298. goto set_wakeup;
  8299. }
  8300. err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
  8301. nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  8302. nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  8303. nl80211_wowlan_policy);
  8304. if (err)
  8305. return err;
  8306. if (tb[NL80211_WOWLAN_TRIG_ANY]) {
  8307. if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
  8308. return -EINVAL;
  8309. new_triggers.any = true;
  8310. }
  8311. if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
  8312. if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
  8313. return -EINVAL;
  8314. new_triggers.disconnect = true;
  8315. regular = true;
  8316. }
  8317. if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
  8318. if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
  8319. return -EINVAL;
  8320. new_triggers.magic_pkt = true;
  8321. regular = true;
  8322. }
  8323. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
  8324. return -EINVAL;
  8325. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
  8326. if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
  8327. return -EINVAL;
  8328. new_triggers.gtk_rekey_failure = true;
  8329. regular = true;
  8330. }
  8331. if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
  8332. if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
  8333. return -EINVAL;
  8334. new_triggers.eap_identity_req = true;
  8335. regular = true;
  8336. }
  8337. if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
  8338. if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
  8339. return -EINVAL;
  8340. new_triggers.four_way_handshake = true;
  8341. regular = true;
  8342. }
  8343. if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
  8344. if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
  8345. return -EINVAL;
  8346. new_triggers.rfkill_release = true;
  8347. regular = true;
  8348. }
  8349. if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
  8350. struct nlattr *pat;
  8351. int n_patterns = 0;
  8352. int rem, pat_len, mask_len, pkt_offset;
  8353. struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
  8354. regular = true;
  8355. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  8356. rem)
  8357. n_patterns++;
  8358. if (n_patterns > wowlan->n_patterns)
  8359. return -EINVAL;
  8360. new_triggers.patterns = kcalloc(n_patterns,
  8361. sizeof(new_triggers.patterns[0]),
  8362. GFP_KERNEL);
  8363. if (!new_triggers.patterns)
  8364. return -ENOMEM;
  8365. new_triggers.n_patterns = n_patterns;
  8366. i = 0;
  8367. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  8368. rem) {
  8369. u8 *mask_pat;
  8370. nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
  8371. nla_len(pat), nl80211_packet_pattern_policy);
  8372. err = -EINVAL;
  8373. if (!pat_tb[NL80211_PKTPAT_MASK] ||
  8374. !pat_tb[NL80211_PKTPAT_PATTERN])
  8375. goto error;
  8376. pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
  8377. mask_len = DIV_ROUND_UP(pat_len, 8);
  8378. if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
  8379. goto error;
  8380. if (pat_len > wowlan->pattern_max_len ||
  8381. pat_len < wowlan->pattern_min_len)
  8382. goto error;
  8383. if (!pat_tb[NL80211_PKTPAT_OFFSET])
  8384. pkt_offset = 0;
  8385. else
  8386. pkt_offset = nla_get_u32(
  8387. pat_tb[NL80211_PKTPAT_OFFSET]);
  8388. if (pkt_offset > wowlan->max_pkt_offset)
  8389. goto error;
  8390. new_triggers.patterns[i].pkt_offset = pkt_offset;
  8391. mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
  8392. if (!mask_pat) {
  8393. err = -ENOMEM;
  8394. goto error;
  8395. }
  8396. new_triggers.patterns[i].mask = mask_pat;
  8397. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
  8398. mask_len);
  8399. mask_pat += mask_len;
  8400. new_triggers.patterns[i].pattern = mask_pat;
  8401. new_triggers.patterns[i].pattern_len = pat_len;
  8402. memcpy(mask_pat,
  8403. nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
  8404. pat_len);
  8405. i++;
  8406. }
  8407. }
  8408. if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
  8409. regular = true;
  8410. err = nl80211_parse_wowlan_tcp(
  8411. rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
  8412. &new_triggers);
  8413. if (err)
  8414. goto error;
  8415. }
  8416. if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
  8417. regular = true;
  8418. err = nl80211_parse_wowlan_nd(
  8419. rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
  8420. &new_triggers);
  8421. if (err)
  8422. goto error;
  8423. }
  8424. /* The 'any' trigger means the device continues operating more or less
  8425. * as in its normal operation mode and wakes up the host on most of the
  8426. * normal interrupts (like packet RX, ...)
  8427. * It therefore makes little sense to combine with the more constrained
  8428. * wakeup trigger modes.
  8429. */
  8430. if (new_triggers.any && regular) {
  8431. err = -EINVAL;
  8432. goto error;
  8433. }
  8434. ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
  8435. if (!ntrig) {
  8436. err = -ENOMEM;
  8437. goto error;
  8438. }
  8439. cfg80211_rdev_free_wowlan(rdev);
  8440. rdev->wiphy.wowlan_config = ntrig;
  8441. set_wakeup:
  8442. if (rdev->ops->set_wakeup &&
  8443. prev_enabled != !!rdev->wiphy.wowlan_config)
  8444. rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
  8445. return 0;
  8446. error:
  8447. for (i = 0; i < new_triggers.n_patterns; i++)
  8448. kfree(new_triggers.patterns[i].mask);
  8449. kfree(new_triggers.patterns);
  8450. if (new_triggers.tcp && new_triggers.tcp->sock)
  8451. sock_release(new_triggers.tcp->sock);
  8452. kfree(new_triggers.tcp);
  8453. kfree(new_triggers.nd_config);
  8454. return err;
  8455. }
  8456. #endif
  8457. static int nl80211_send_coalesce_rules(struct sk_buff *msg,
  8458. struct cfg80211_registered_device *rdev)
  8459. {
  8460. struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
  8461. int i, j, pat_len;
  8462. struct cfg80211_coalesce_rules *rule;
  8463. if (!rdev->coalesce->n_rules)
  8464. return 0;
  8465. nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
  8466. if (!nl_rules)
  8467. return -ENOBUFS;
  8468. for (i = 0; i < rdev->coalesce->n_rules; i++) {
  8469. nl_rule = nla_nest_start(msg, i + 1);
  8470. if (!nl_rule)
  8471. return -ENOBUFS;
  8472. rule = &rdev->coalesce->rules[i];
  8473. if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
  8474. rule->delay))
  8475. return -ENOBUFS;
  8476. if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
  8477. rule->condition))
  8478. return -ENOBUFS;
  8479. nl_pats = nla_nest_start(msg,
  8480. NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
  8481. if (!nl_pats)
  8482. return -ENOBUFS;
  8483. for (j = 0; j < rule->n_patterns; j++) {
  8484. nl_pat = nla_nest_start(msg, j + 1);
  8485. if (!nl_pat)
  8486. return -ENOBUFS;
  8487. pat_len = rule->patterns[j].pattern_len;
  8488. if (nla_put(msg, NL80211_PKTPAT_MASK,
  8489. DIV_ROUND_UP(pat_len, 8),
  8490. rule->patterns[j].mask) ||
  8491. nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
  8492. rule->patterns[j].pattern) ||
  8493. nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
  8494. rule->patterns[j].pkt_offset))
  8495. return -ENOBUFS;
  8496. nla_nest_end(msg, nl_pat);
  8497. }
  8498. nla_nest_end(msg, nl_pats);
  8499. nla_nest_end(msg, nl_rule);
  8500. }
  8501. nla_nest_end(msg, nl_rules);
  8502. return 0;
  8503. }
  8504. static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
  8505. {
  8506. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8507. struct sk_buff *msg;
  8508. void *hdr;
  8509. if (!rdev->wiphy.coalesce)
  8510. return -EOPNOTSUPP;
  8511. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  8512. if (!msg)
  8513. return -ENOMEM;
  8514. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8515. NL80211_CMD_GET_COALESCE);
  8516. if (!hdr)
  8517. goto nla_put_failure;
  8518. if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
  8519. goto nla_put_failure;
  8520. genlmsg_end(msg, hdr);
  8521. return genlmsg_reply(msg, info);
  8522. nla_put_failure:
  8523. nlmsg_free(msg);
  8524. return -ENOBUFS;
  8525. }
  8526. void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
  8527. {
  8528. struct cfg80211_coalesce *coalesce = rdev->coalesce;
  8529. int i, j;
  8530. struct cfg80211_coalesce_rules *rule;
  8531. if (!coalesce)
  8532. return;
  8533. for (i = 0; i < coalesce->n_rules; i++) {
  8534. rule = &coalesce->rules[i];
  8535. for (j = 0; j < rule->n_patterns; j++)
  8536. kfree(rule->patterns[j].mask);
  8537. kfree(rule->patterns);
  8538. }
  8539. kfree(coalesce->rules);
  8540. kfree(coalesce);
  8541. rdev->coalesce = NULL;
  8542. }
  8543. static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
  8544. struct nlattr *rule,
  8545. struct cfg80211_coalesce_rules *new_rule)
  8546. {
  8547. int err, i;
  8548. const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
  8549. struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
  8550. int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
  8551. struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
  8552. err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
  8553. nla_len(rule), nl80211_coalesce_policy);
  8554. if (err)
  8555. return err;
  8556. if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
  8557. new_rule->delay =
  8558. nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
  8559. if (new_rule->delay > coalesce->max_delay)
  8560. return -EINVAL;
  8561. if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
  8562. new_rule->condition =
  8563. nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
  8564. if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
  8565. new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
  8566. return -EINVAL;
  8567. if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
  8568. return -EINVAL;
  8569. nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
  8570. rem)
  8571. n_patterns++;
  8572. if (n_patterns > coalesce->n_patterns)
  8573. return -EINVAL;
  8574. new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
  8575. GFP_KERNEL);
  8576. if (!new_rule->patterns)
  8577. return -ENOMEM;
  8578. new_rule->n_patterns = n_patterns;
  8579. i = 0;
  8580. nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
  8581. rem) {
  8582. u8 *mask_pat;
  8583. nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
  8584. nla_len(pat), nl80211_packet_pattern_policy);
  8585. if (!pat_tb[NL80211_PKTPAT_MASK] ||
  8586. !pat_tb[NL80211_PKTPAT_PATTERN])
  8587. return -EINVAL;
  8588. pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
  8589. mask_len = DIV_ROUND_UP(pat_len, 8);
  8590. if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
  8591. return -EINVAL;
  8592. if (pat_len > coalesce->pattern_max_len ||
  8593. pat_len < coalesce->pattern_min_len)
  8594. return -EINVAL;
  8595. if (!pat_tb[NL80211_PKTPAT_OFFSET])
  8596. pkt_offset = 0;
  8597. else
  8598. pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
  8599. if (pkt_offset > coalesce->max_pkt_offset)
  8600. return -EINVAL;
  8601. new_rule->patterns[i].pkt_offset = pkt_offset;
  8602. mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
  8603. if (!mask_pat)
  8604. return -ENOMEM;
  8605. new_rule->patterns[i].mask = mask_pat;
  8606. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
  8607. mask_len);
  8608. mask_pat += mask_len;
  8609. new_rule->patterns[i].pattern = mask_pat;
  8610. new_rule->patterns[i].pattern_len = pat_len;
  8611. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
  8612. pat_len);
  8613. i++;
  8614. }
  8615. return 0;
  8616. }
  8617. static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
  8618. {
  8619. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8620. const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
  8621. struct cfg80211_coalesce new_coalesce = {};
  8622. struct cfg80211_coalesce *n_coalesce;
  8623. int err, rem_rule, n_rules = 0, i, j;
  8624. struct nlattr *rule;
  8625. struct cfg80211_coalesce_rules *tmp_rule;
  8626. if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
  8627. return -EOPNOTSUPP;
  8628. if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
  8629. cfg80211_rdev_free_coalesce(rdev);
  8630. rdev_set_coalesce(rdev, NULL);
  8631. return 0;
  8632. }
  8633. nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
  8634. rem_rule)
  8635. n_rules++;
  8636. if (n_rules > coalesce->n_rules)
  8637. return -EINVAL;
  8638. new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
  8639. GFP_KERNEL);
  8640. if (!new_coalesce.rules)
  8641. return -ENOMEM;
  8642. new_coalesce.n_rules = n_rules;
  8643. i = 0;
  8644. nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
  8645. rem_rule) {
  8646. err = nl80211_parse_coalesce_rule(rdev, rule,
  8647. &new_coalesce.rules[i]);
  8648. if (err)
  8649. goto error;
  8650. i++;
  8651. }
  8652. err = rdev_set_coalesce(rdev, &new_coalesce);
  8653. if (err)
  8654. goto error;
  8655. n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
  8656. if (!n_coalesce) {
  8657. err = -ENOMEM;
  8658. goto error;
  8659. }
  8660. cfg80211_rdev_free_coalesce(rdev);
  8661. rdev->coalesce = n_coalesce;
  8662. return 0;
  8663. error:
  8664. for (i = 0; i < new_coalesce.n_rules; i++) {
  8665. tmp_rule = &new_coalesce.rules[i];
  8666. for (j = 0; j < tmp_rule->n_patterns; j++)
  8667. kfree(tmp_rule->patterns[j].mask);
  8668. kfree(tmp_rule->patterns);
  8669. }
  8670. kfree(new_coalesce.rules);
  8671. return err;
  8672. }
  8673. static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
  8674. {
  8675. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8676. struct net_device *dev = info->user_ptr[1];
  8677. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8678. struct nlattr *tb[NUM_NL80211_REKEY_DATA];
  8679. struct cfg80211_gtk_rekey_data rekey_data;
  8680. int err;
  8681. if (!info->attrs[NL80211_ATTR_REKEY_DATA])
  8682. return -EINVAL;
  8683. err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
  8684. nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
  8685. nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
  8686. nl80211_rekey_policy);
  8687. if (err)
  8688. return err;
  8689. if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
  8690. !tb[NL80211_REKEY_DATA_KCK])
  8691. return -EINVAL;
  8692. if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
  8693. return -ERANGE;
  8694. if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
  8695. return -ERANGE;
  8696. if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
  8697. return -ERANGE;
  8698. rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
  8699. rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
  8700. rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
  8701. wdev_lock(wdev);
  8702. if (!wdev->current_bss) {
  8703. err = -ENOTCONN;
  8704. goto out;
  8705. }
  8706. if (!rdev->ops->set_rekey_data) {
  8707. err = -EOPNOTSUPP;
  8708. goto out;
  8709. }
  8710. err = rdev_set_rekey_data(rdev, dev, &rekey_data);
  8711. out:
  8712. wdev_unlock(wdev);
  8713. return err;
  8714. }
  8715. static int nl80211_register_unexpected_frame(struct sk_buff *skb,
  8716. struct genl_info *info)
  8717. {
  8718. struct net_device *dev = info->user_ptr[1];
  8719. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8720. if (wdev->iftype != NL80211_IFTYPE_AP &&
  8721. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  8722. return -EINVAL;
  8723. if (wdev->ap_unexpected_nlportid)
  8724. return -EBUSY;
  8725. wdev->ap_unexpected_nlportid = info->snd_portid;
  8726. return 0;
  8727. }
  8728. static int nl80211_probe_client(struct sk_buff *skb,
  8729. struct genl_info *info)
  8730. {
  8731. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8732. struct net_device *dev = info->user_ptr[1];
  8733. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8734. struct sk_buff *msg;
  8735. void *hdr;
  8736. const u8 *addr;
  8737. u64 cookie;
  8738. int err;
  8739. if (wdev->iftype != NL80211_IFTYPE_AP &&
  8740. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  8741. return -EOPNOTSUPP;
  8742. if (!info->attrs[NL80211_ATTR_MAC])
  8743. return -EINVAL;
  8744. if (!rdev->ops->probe_client)
  8745. return -EOPNOTSUPP;
  8746. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  8747. if (!msg)
  8748. return -ENOMEM;
  8749. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8750. NL80211_CMD_PROBE_CLIENT);
  8751. if (!hdr) {
  8752. err = -ENOBUFS;
  8753. goto free_msg;
  8754. }
  8755. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  8756. err = rdev_probe_client(rdev, dev, addr, &cookie);
  8757. if (err)
  8758. goto free_msg;
  8759. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  8760. NL80211_ATTR_PAD))
  8761. goto nla_put_failure;
  8762. genlmsg_end(msg, hdr);
  8763. return genlmsg_reply(msg, info);
  8764. nla_put_failure:
  8765. err = -ENOBUFS;
  8766. free_msg:
  8767. nlmsg_free(msg);
  8768. return err;
  8769. }
  8770. static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
  8771. {
  8772. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8773. struct cfg80211_beacon_registration *reg, *nreg;
  8774. int rv;
  8775. if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
  8776. return -EOPNOTSUPP;
  8777. nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
  8778. if (!nreg)
  8779. return -ENOMEM;
  8780. /* First, check if already registered. */
  8781. spin_lock_bh(&rdev->beacon_registrations_lock);
  8782. list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  8783. if (reg->nlportid == info->snd_portid) {
  8784. rv = -EALREADY;
  8785. goto out_err;
  8786. }
  8787. }
  8788. /* Add it to the list */
  8789. nreg->nlportid = info->snd_portid;
  8790. list_add(&nreg->list, &rdev->beacon_registrations);
  8791. spin_unlock_bh(&rdev->beacon_registrations_lock);
  8792. return 0;
  8793. out_err:
  8794. spin_unlock_bh(&rdev->beacon_registrations_lock);
  8795. kfree(nreg);
  8796. return rv;
  8797. }
  8798. static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
  8799. {
  8800. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8801. struct wireless_dev *wdev = info->user_ptr[1];
  8802. int err;
  8803. if (!rdev->ops->start_p2p_device)
  8804. return -EOPNOTSUPP;
  8805. if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  8806. return -EOPNOTSUPP;
  8807. if (wdev->p2p_started)
  8808. return 0;
  8809. if (rfkill_blocked(rdev->rfkill))
  8810. return -ERFKILL;
  8811. err = rdev_start_p2p_device(rdev, wdev);
  8812. if (err)
  8813. return err;
  8814. wdev->p2p_started = true;
  8815. rdev->opencount++;
  8816. return 0;
  8817. }
  8818. static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
  8819. {
  8820. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8821. struct wireless_dev *wdev = info->user_ptr[1];
  8822. if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  8823. return -EOPNOTSUPP;
  8824. if (!rdev->ops->stop_p2p_device)
  8825. return -EOPNOTSUPP;
  8826. cfg80211_stop_p2p_device(rdev, wdev);
  8827. return 0;
  8828. }
  8829. static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
  8830. {
  8831. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8832. struct wireless_dev *wdev = info->user_ptr[1];
  8833. struct cfg80211_nan_conf conf = {};
  8834. int err;
  8835. if (wdev->iftype != NL80211_IFTYPE_NAN)
  8836. return -EOPNOTSUPP;
  8837. if (wdev->nan_started)
  8838. return -EEXIST;
  8839. if (rfkill_blocked(rdev->rfkill))
  8840. return -ERFKILL;
  8841. if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
  8842. return -EINVAL;
  8843. if (!info->attrs[NL80211_ATTR_NAN_DUAL])
  8844. return -EINVAL;
  8845. conf.master_pref =
  8846. nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
  8847. if (!conf.master_pref)
  8848. return -EINVAL;
  8849. conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
  8850. err = rdev_start_nan(rdev, wdev, &conf);
  8851. if (err)
  8852. return err;
  8853. wdev->nan_started = true;
  8854. rdev->opencount++;
  8855. return 0;
  8856. }
  8857. static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
  8858. {
  8859. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8860. struct wireless_dev *wdev = info->user_ptr[1];
  8861. if (wdev->iftype != NL80211_IFTYPE_NAN)
  8862. return -EOPNOTSUPP;
  8863. cfg80211_stop_nan(rdev, wdev);
  8864. return 0;
  8865. }
  8866. static int validate_nan_filter(struct nlattr *filter_attr)
  8867. {
  8868. struct nlattr *attr;
  8869. int len = 0, n_entries = 0, rem;
  8870. nla_for_each_nested(attr, filter_attr, rem) {
  8871. len += nla_len(attr);
  8872. n_entries++;
  8873. }
  8874. if (len >= U8_MAX)
  8875. return -EINVAL;
  8876. return n_entries;
  8877. }
  8878. static int handle_nan_filter(struct nlattr *attr_filter,
  8879. struct cfg80211_nan_func *func,
  8880. bool tx)
  8881. {
  8882. struct nlattr *attr;
  8883. int n_entries, rem, i;
  8884. struct cfg80211_nan_func_filter *filter;
  8885. n_entries = validate_nan_filter(attr_filter);
  8886. if (n_entries < 0)
  8887. return n_entries;
  8888. BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
  8889. filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
  8890. if (!filter)
  8891. return -ENOMEM;
  8892. i = 0;
  8893. nla_for_each_nested(attr, attr_filter, rem) {
  8894. filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
  8895. GFP_KERNEL);
  8896. filter[i].len = nla_len(attr);
  8897. i++;
  8898. }
  8899. if (tx) {
  8900. func->num_tx_filters = n_entries;
  8901. func->tx_filters = filter;
  8902. } else {
  8903. func->num_rx_filters = n_entries;
  8904. func->rx_filters = filter;
  8905. }
  8906. return 0;
  8907. }
  8908. static int nl80211_nan_add_func(struct sk_buff *skb,
  8909. struct genl_info *info)
  8910. {
  8911. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8912. struct wireless_dev *wdev = info->user_ptr[1];
  8913. struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
  8914. struct cfg80211_nan_func *func;
  8915. struct sk_buff *msg = NULL;
  8916. void *hdr = NULL;
  8917. int err = 0;
  8918. if (wdev->iftype != NL80211_IFTYPE_NAN)
  8919. return -EOPNOTSUPP;
  8920. if (!wdev->nan_started)
  8921. return -ENOTCONN;
  8922. if (!info->attrs[NL80211_ATTR_NAN_FUNC])
  8923. return -EINVAL;
  8924. if (wdev->owner_nlportid &&
  8925. wdev->owner_nlportid != info->snd_portid)
  8926. return -ENOTCONN;
  8927. err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX,
  8928. nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]),
  8929. nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]),
  8930. nl80211_nan_func_policy);
  8931. if (err)
  8932. return err;
  8933. func = kzalloc(sizeof(*func), GFP_KERNEL);
  8934. if (!func)
  8935. return -ENOMEM;
  8936. func->cookie = wdev->wiphy->cookie_counter++;
  8937. if (!tb[NL80211_NAN_FUNC_TYPE] ||
  8938. nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
  8939. err = -EINVAL;
  8940. goto out;
  8941. }
  8942. func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
  8943. if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
  8944. err = -EINVAL;
  8945. goto out;
  8946. }
  8947. memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
  8948. sizeof(func->service_id));
  8949. func->close_range =
  8950. nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
  8951. if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
  8952. func->serv_spec_info_len =
  8953. nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
  8954. func->serv_spec_info =
  8955. kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
  8956. func->serv_spec_info_len,
  8957. GFP_KERNEL);
  8958. if (!func->serv_spec_info) {
  8959. err = -ENOMEM;
  8960. goto out;
  8961. }
  8962. }
  8963. if (tb[NL80211_NAN_FUNC_TTL])
  8964. func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
  8965. switch (func->type) {
  8966. case NL80211_NAN_FUNC_PUBLISH:
  8967. if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
  8968. err = -EINVAL;
  8969. goto out;
  8970. }
  8971. func->publish_type =
  8972. nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
  8973. func->publish_bcast =
  8974. nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
  8975. if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
  8976. func->publish_bcast) {
  8977. err = -EINVAL;
  8978. goto out;
  8979. }
  8980. break;
  8981. case NL80211_NAN_FUNC_SUBSCRIBE:
  8982. func->subscribe_active =
  8983. nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
  8984. break;
  8985. case NL80211_NAN_FUNC_FOLLOW_UP:
  8986. if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
  8987. !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
  8988. !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
  8989. err = -EINVAL;
  8990. goto out;
  8991. }
  8992. func->followup_id =
  8993. nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
  8994. func->followup_reqid =
  8995. nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
  8996. memcpy(func->followup_dest.addr,
  8997. nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
  8998. sizeof(func->followup_dest.addr));
  8999. if (func->ttl) {
  9000. err = -EINVAL;
  9001. goto out;
  9002. }
  9003. break;
  9004. default:
  9005. err = -EINVAL;
  9006. goto out;
  9007. }
  9008. if (tb[NL80211_NAN_FUNC_SRF]) {
  9009. struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
  9010. err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
  9011. nla_data(tb[NL80211_NAN_FUNC_SRF]),
  9012. nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL);
  9013. if (err)
  9014. goto out;
  9015. func->srf_include =
  9016. nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
  9017. if (srf_tb[NL80211_NAN_SRF_BF]) {
  9018. if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
  9019. !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
  9020. err = -EINVAL;
  9021. goto out;
  9022. }
  9023. func->srf_bf_len =
  9024. nla_len(srf_tb[NL80211_NAN_SRF_BF]);
  9025. func->srf_bf =
  9026. kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
  9027. func->srf_bf_len, GFP_KERNEL);
  9028. if (!func->srf_bf) {
  9029. err = -ENOMEM;
  9030. goto out;
  9031. }
  9032. func->srf_bf_idx =
  9033. nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
  9034. } else {
  9035. struct nlattr *attr, *mac_attr =
  9036. srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
  9037. int n_entries, rem, i = 0;
  9038. if (!mac_attr) {
  9039. err = -EINVAL;
  9040. goto out;
  9041. }
  9042. n_entries = validate_acl_mac_addrs(mac_attr);
  9043. if (n_entries <= 0) {
  9044. err = -EINVAL;
  9045. goto out;
  9046. }
  9047. func->srf_num_macs = n_entries;
  9048. func->srf_macs =
  9049. kzalloc(sizeof(*func->srf_macs) * n_entries,
  9050. GFP_KERNEL);
  9051. if (!func->srf_macs) {
  9052. err = -ENOMEM;
  9053. goto out;
  9054. }
  9055. nla_for_each_nested(attr, mac_attr, rem)
  9056. memcpy(func->srf_macs[i++].addr, nla_data(attr),
  9057. sizeof(*func->srf_macs));
  9058. }
  9059. }
  9060. if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
  9061. err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
  9062. func, true);
  9063. if (err)
  9064. goto out;
  9065. }
  9066. if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
  9067. err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
  9068. func, false);
  9069. if (err)
  9070. goto out;
  9071. }
  9072. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9073. if (!msg) {
  9074. err = -ENOMEM;
  9075. goto out;
  9076. }
  9077. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  9078. NL80211_CMD_ADD_NAN_FUNCTION);
  9079. /* This can't really happen - we just allocated 4KB */
  9080. if (WARN_ON(!hdr)) {
  9081. err = -ENOMEM;
  9082. goto out;
  9083. }
  9084. err = rdev_add_nan_func(rdev, wdev, func);
  9085. out:
  9086. if (err < 0) {
  9087. cfg80211_free_nan_func(func);
  9088. nlmsg_free(msg);
  9089. return err;
  9090. }
  9091. /* propagate the instance id and cookie to userspace */
  9092. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
  9093. NL80211_ATTR_PAD))
  9094. goto nla_put_failure;
  9095. func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
  9096. if (!func_attr)
  9097. goto nla_put_failure;
  9098. if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
  9099. func->instance_id))
  9100. goto nla_put_failure;
  9101. nla_nest_end(msg, func_attr);
  9102. genlmsg_end(msg, hdr);
  9103. return genlmsg_reply(msg, info);
  9104. nla_put_failure:
  9105. nlmsg_free(msg);
  9106. return -ENOBUFS;
  9107. }
  9108. static int nl80211_nan_del_func(struct sk_buff *skb,
  9109. struct genl_info *info)
  9110. {
  9111. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9112. struct wireless_dev *wdev = info->user_ptr[1];
  9113. u64 cookie;
  9114. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9115. return -EOPNOTSUPP;
  9116. if (!wdev->nan_started)
  9117. return -ENOTCONN;
  9118. if (!info->attrs[NL80211_ATTR_COOKIE])
  9119. return -EINVAL;
  9120. if (wdev->owner_nlportid &&
  9121. wdev->owner_nlportid != info->snd_portid)
  9122. return -ENOTCONN;
  9123. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  9124. rdev_del_nan_func(rdev, wdev, cookie);
  9125. return 0;
  9126. }
  9127. static int nl80211_nan_change_config(struct sk_buff *skb,
  9128. struct genl_info *info)
  9129. {
  9130. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9131. struct wireless_dev *wdev = info->user_ptr[1];
  9132. struct cfg80211_nan_conf conf = {};
  9133. u32 changed = 0;
  9134. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9135. return -EOPNOTSUPP;
  9136. if (!wdev->nan_started)
  9137. return -ENOTCONN;
  9138. if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
  9139. conf.master_pref =
  9140. nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
  9141. if (conf.master_pref <= 1 || conf.master_pref == 255)
  9142. return -EINVAL;
  9143. changed |= CFG80211_NAN_CONF_CHANGED_PREF;
  9144. }
  9145. if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
  9146. conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
  9147. changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
  9148. }
  9149. if (!changed)
  9150. return -EINVAL;
  9151. return rdev_nan_change_conf(rdev, wdev, &conf, changed);
  9152. }
  9153. void cfg80211_nan_match(struct wireless_dev *wdev,
  9154. struct cfg80211_nan_match_params *match, gfp_t gfp)
  9155. {
  9156. struct wiphy *wiphy = wdev->wiphy;
  9157. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9158. struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
  9159. struct sk_buff *msg;
  9160. void *hdr;
  9161. if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
  9162. return;
  9163. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9164. if (!msg)
  9165. return;
  9166. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
  9167. if (!hdr) {
  9168. nlmsg_free(msg);
  9169. return;
  9170. }
  9171. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9172. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  9173. wdev->netdev->ifindex)) ||
  9174. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  9175. NL80211_ATTR_PAD))
  9176. goto nla_put_failure;
  9177. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
  9178. NL80211_ATTR_PAD) ||
  9179. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
  9180. goto nla_put_failure;
  9181. match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
  9182. if (!match_attr)
  9183. goto nla_put_failure;
  9184. local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
  9185. if (!local_func_attr)
  9186. goto nla_put_failure;
  9187. if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
  9188. goto nla_put_failure;
  9189. nla_nest_end(msg, local_func_attr);
  9190. peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
  9191. if (!peer_func_attr)
  9192. goto nla_put_failure;
  9193. if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
  9194. nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
  9195. goto nla_put_failure;
  9196. if (match->info && match->info_len &&
  9197. nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
  9198. match->info))
  9199. goto nla_put_failure;
  9200. nla_nest_end(msg, peer_func_attr);
  9201. nla_nest_end(msg, match_attr);
  9202. genlmsg_end(msg, hdr);
  9203. if (!wdev->owner_nlportid)
  9204. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
  9205. msg, 0, NL80211_MCGRP_NAN, gfp);
  9206. else
  9207. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
  9208. wdev->owner_nlportid);
  9209. return;
  9210. nla_put_failure:
  9211. nlmsg_free(msg);
  9212. }
  9213. EXPORT_SYMBOL(cfg80211_nan_match);
  9214. void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
  9215. u8 inst_id,
  9216. enum nl80211_nan_func_term_reason reason,
  9217. u64 cookie, gfp_t gfp)
  9218. {
  9219. struct wiphy *wiphy = wdev->wiphy;
  9220. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9221. struct sk_buff *msg;
  9222. struct nlattr *func_attr;
  9223. void *hdr;
  9224. if (WARN_ON(!inst_id))
  9225. return;
  9226. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9227. if (!msg)
  9228. return;
  9229. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
  9230. if (!hdr) {
  9231. nlmsg_free(msg);
  9232. return;
  9233. }
  9234. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9235. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  9236. wdev->netdev->ifindex)) ||
  9237. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  9238. NL80211_ATTR_PAD))
  9239. goto nla_put_failure;
  9240. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  9241. NL80211_ATTR_PAD))
  9242. goto nla_put_failure;
  9243. func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
  9244. if (!func_attr)
  9245. goto nla_put_failure;
  9246. if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
  9247. nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
  9248. goto nla_put_failure;
  9249. nla_nest_end(msg, func_attr);
  9250. genlmsg_end(msg, hdr);
  9251. if (!wdev->owner_nlportid)
  9252. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
  9253. msg, 0, NL80211_MCGRP_NAN, gfp);
  9254. else
  9255. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
  9256. wdev->owner_nlportid);
  9257. return;
  9258. nla_put_failure:
  9259. nlmsg_free(msg);
  9260. }
  9261. EXPORT_SYMBOL(cfg80211_nan_func_terminated);
  9262. static int nl80211_get_protocol_features(struct sk_buff *skb,
  9263. struct genl_info *info)
  9264. {
  9265. void *hdr;
  9266. struct sk_buff *msg;
  9267. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9268. if (!msg)
  9269. return -ENOMEM;
  9270. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  9271. NL80211_CMD_GET_PROTOCOL_FEATURES);
  9272. if (!hdr)
  9273. goto nla_put_failure;
  9274. if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
  9275. NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
  9276. goto nla_put_failure;
  9277. genlmsg_end(msg, hdr);
  9278. return genlmsg_reply(msg, info);
  9279. nla_put_failure:
  9280. kfree_skb(msg);
  9281. return -ENOBUFS;
  9282. }
  9283. static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
  9284. {
  9285. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9286. struct cfg80211_update_ft_ies_params ft_params;
  9287. struct net_device *dev = info->user_ptr[1];
  9288. if (!rdev->ops->update_ft_ies)
  9289. return -EOPNOTSUPP;
  9290. if (!info->attrs[NL80211_ATTR_MDID] ||
  9291. !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  9292. return -EINVAL;
  9293. memset(&ft_params, 0, sizeof(ft_params));
  9294. ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
  9295. ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  9296. ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  9297. return rdev_update_ft_ies(rdev, dev, &ft_params);
  9298. }
  9299. static int nl80211_crit_protocol_start(struct sk_buff *skb,
  9300. struct genl_info *info)
  9301. {
  9302. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9303. struct wireless_dev *wdev = info->user_ptr[1];
  9304. enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
  9305. u16 duration;
  9306. int ret;
  9307. if (!rdev->ops->crit_proto_start)
  9308. return -EOPNOTSUPP;
  9309. if (WARN_ON(!rdev->ops->crit_proto_stop))
  9310. return -EINVAL;
  9311. if (rdev->crit_proto_nlportid)
  9312. return -EBUSY;
  9313. /* determine protocol if provided */
  9314. if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
  9315. proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
  9316. if (proto >= NUM_NL80211_CRIT_PROTO)
  9317. return -EINVAL;
  9318. /* timeout must be provided */
  9319. if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
  9320. return -EINVAL;
  9321. duration =
  9322. nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
  9323. if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
  9324. return -ERANGE;
  9325. ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
  9326. if (!ret)
  9327. rdev->crit_proto_nlportid = info->snd_portid;
  9328. return ret;
  9329. }
  9330. static int nl80211_crit_protocol_stop(struct sk_buff *skb,
  9331. struct genl_info *info)
  9332. {
  9333. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9334. struct wireless_dev *wdev = info->user_ptr[1];
  9335. if (!rdev->ops->crit_proto_stop)
  9336. return -EOPNOTSUPP;
  9337. if (rdev->crit_proto_nlportid) {
  9338. rdev->crit_proto_nlportid = 0;
  9339. rdev_crit_proto_stop(rdev, wdev);
  9340. }
  9341. return 0;
  9342. }
  9343. static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
  9344. {
  9345. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9346. struct wireless_dev *wdev =
  9347. __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
  9348. int i, err;
  9349. u32 vid, subcmd;
  9350. if (!rdev->wiphy.vendor_commands)
  9351. return -EOPNOTSUPP;
  9352. if (IS_ERR(wdev)) {
  9353. err = PTR_ERR(wdev);
  9354. if (err != -EINVAL)
  9355. return err;
  9356. wdev = NULL;
  9357. } else if (wdev->wiphy != &rdev->wiphy) {
  9358. return -EINVAL;
  9359. }
  9360. if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
  9361. !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
  9362. return -EINVAL;
  9363. vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
  9364. subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
  9365. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  9366. const struct wiphy_vendor_command *vcmd;
  9367. void *data = NULL;
  9368. int len = 0;
  9369. vcmd = &rdev->wiphy.vendor_commands[i];
  9370. if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
  9371. continue;
  9372. if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
  9373. WIPHY_VENDOR_CMD_NEED_NETDEV)) {
  9374. if (!wdev)
  9375. return -EINVAL;
  9376. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
  9377. !wdev->netdev)
  9378. return -EINVAL;
  9379. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
  9380. if (wdev->netdev &&
  9381. !netif_running(wdev->netdev))
  9382. return -ENETDOWN;
  9383. if (!wdev->netdev && !wdev->p2p_started)
  9384. return -ENETDOWN;
  9385. }
  9386. if (!vcmd->doit)
  9387. return -EOPNOTSUPP;
  9388. } else {
  9389. wdev = NULL;
  9390. }
  9391. if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
  9392. data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  9393. len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  9394. }
  9395. rdev->cur_cmd_info = info;
  9396. err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
  9397. data, len);
  9398. rdev->cur_cmd_info = NULL;
  9399. return err;
  9400. }
  9401. return -EOPNOTSUPP;
  9402. }
  9403. static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
  9404. struct netlink_callback *cb,
  9405. struct cfg80211_registered_device **rdev,
  9406. struct wireless_dev **wdev)
  9407. {
  9408. u32 vid, subcmd;
  9409. unsigned int i;
  9410. int vcmd_idx = -1;
  9411. int err;
  9412. void *data = NULL;
  9413. unsigned int data_len = 0;
  9414. if (cb->args[0]) {
  9415. /* subtract the 1 again here */
  9416. struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
  9417. struct wireless_dev *tmp;
  9418. if (!wiphy)
  9419. return -ENODEV;
  9420. *rdev = wiphy_to_rdev(wiphy);
  9421. *wdev = NULL;
  9422. if (cb->args[1]) {
  9423. list_for_each_entry(tmp, &wiphy->wdev_list, list) {
  9424. if (tmp->identifier == cb->args[1] - 1) {
  9425. *wdev = tmp;
  9426. break;
  9427. }
  9428. }
  9429. }
  9430. /* keep rtnl locked in successful case */
  9431. return 0;
  9432. }
  9433. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  9434. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  9435. nl80211_policy);
  9436. if (err)
  9437. return err;
  9438. if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
  9439. !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
  9440. return -EINVAL;
  9441. *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
  9442. nl80211_fam.attrbuf);
  9443. if (IS_ERR(*wdev))
  9444. *wdev = NULL;
  9445. *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
  9446. nl80211_fam.attrbuf);
  9447. if (IS_ERR(*rdev))
  9448. return PTR_ERR(*rdev);
  9449. vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
  9450. subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
  9451. for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
  9452. const struct wiphy_vendor_command *vcmd;
  9453. vcmd = &(*rdev)->wiphy.vendor_commands[i];
  9454. if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
  9455. continue;
  9456. if (!vcmd->dumpit)
  9457. return -EOPNOTSUPP;
  9458. vcmd_idx = i;
  9459. break;
  9460. }
  9461. if (vcmd_idx < 0)
  9462. return -EOPNOTSUPP;
  9463. if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
  9464. data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
  9465. data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
  9466. }
  9467. /* 0 is the first index - add 1 to parse only once */
  9468. cb->args[0] = (*rdev)->wiphy_idx + 1;
  9469. /* add 1 to know if it was NULL */
  9470. cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
  9471. cb->args[2] = vcmd_idx;
  9472. cb->args[3] = (unsigned long)data;
  9473. cb->args[4] = data_len;
  9474. /* keep rtnl locked in successful case */
  9475. return 0;
  9476. }
  9477. static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
  9478. struct netlink_callback *cb)
  9479. {
  9480. struct cfg80211_registered_device *rdev;
  9481. struct wireless_dev *wdev;
  9482. unsigned int vcmd_idx;
  9483. const struct wiphy_vendor_command *vcmd;
  9484. void *data;
  9485. int data_len;
  9486. int err;
  9487. struct nlattr *vendor_data;
  9488. rtnl_lock();
  9489. err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
  9490. if (err)
  9491. goto out;
  9492. vcmd_idx = cb->args[2];
  9493. data = (void *)cb->args[3];
  9494. data_len = cb->args[4];
  9495. vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
  9496. if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
  9497. WIPHY_VENDOR_CMD_NEED_NETDEV)) {
  9498. if (!wdev) {
  9499. err = -EINVAL;
  9500. goto out;
  9501. }
  9502. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
  9503. !wdev->netdev) {
  9504. err = -EINVAL;
  9505. goto out;
  9506. }
  9507. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
  9508. if (wdev->netdev &&
  9509. !netif_running(wdev->netdev)) {
  9510. err = -ENETDOWN;
  9511. goto out;
  9512. }
  9513. if (!wdev->netdev && !wdev->p2p_started) {
  9514. err = -ENETDOWN;
  9515. goto out;
  9516. }
  9517. }
  9518. }
  9519. while (1) {
  9520. void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
  9521. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  9522. NL80211_CMD_VENDOR);
  9523. if (!hdr)
  9524. break;
  9525. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9526. (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
  9527. wdev_id(wdev),
  9528. NL80211_ATTR_PAD))) {
  9529. genlmsg_cancel(skb, hdr);
  9530. break;
  9531. }
  9532. vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
  9533. if (!vendor_data) {
  9534. genlmsg_cancel(skb, hdr);
  9535. break;
  9536. }
  9537. err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
  9538. (unsigned long *)&cb->args[5]);
  9539. nla_nest_end(skb, vendor_data);
  9540. if (err == -ENOBUFS || err == -ENOENT) {
  9541. genlmsg_cancel(skb, hdr);
  9542. break;
  9543. } else if (err) {
  9544. genlmsg_cancel(skb, hdr);
  9545. goto out;
  9546. }
  9547. genlmsg_end(skb, hdr);
  9548. }
  9549. err = skb->len;
  9550. out:
  9551. rtnl_unlock();
  9552. return err;
  9553. }
  9554. struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
  9555. enum nl80211_commands cmd,
  9556. enum nl80211_attrs attr,
  9557. int approxlen)
  9558. {
  9559. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9560. if (WARN_ON(!rdev->cur_cmd_info))
  9561. return NULL;
  9562. return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
  9563. rdev->cur_cmd_info->snd_portid,
  9564. rdev->cur_cmd_info->snd_seq,
  9565. cmd, attr, NULL, GFP_KERNEL);
  9566. }
  9567. EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
  9568. int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
  9569. {
  9570. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  9571. void *hdr = ((void **)skb->cb)[1];
  9572. struct nlattr *data = ((void **)skb->cb)[2];
  9573. /* clear CB data for netlink core to own from now on */
  9574. memset(skb->cb, 0, sizeof(skb->cb));
  9575. if (WARN_ON(!rdev->cur_cmd_info)) {
  9576. kfree_skb(skb);
  9577. return -EINVAL;
  9578. }
  9579. nla_nest_end(skb, data);
  9580. genlmsg_end(skb, hdr);
  9581. return genlmsg_reply(skb, rdev->cur_cmd_info);
  9582. }
  9583. EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
  9584. static int nl80211_set_qos_map(struct sk_buff *skb,
  9585. struct genl_info *info)
  9586. {
  9587. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9588. struct cfg80211_qos_map *qos_map = NULL;
  9589. struct net_device *dev = info->user_ptr[1];
  9590. u8 *pos, len, num_des, des_len, des;
  9591. int ret;
  9592. if (!rdev->ops->set_qos_map)
  9593. return -EOPNOTSUPP;
  9594. if (info->attrs[NL80211_ATTR_QOS_MAP]) {
  9595. pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
  9596. len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
  9597. if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
  9598. len > IEEE80211_QOS_MAP_LEN_MAX)
  9599. return -EINVAL;
  9600. qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
  9601. if (!qos_map)
  9602. return -ENOMEM;
  9603. num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
  9604. if (num_des) {
  9605. des_len = num_des *
  9606. sizeof(struct cfg80211_dscp_exception);
  9607. memcpy(qos_map->dscp_exception, pos, des_len);
  9608. qos_map->num_des = num_des;
  9609. for (des = 0; des < num_des; des++) {
  9610. if (qos_map->dscp_exception[des].up > 7) {
  9611. kfree(qos_map);
  9612. return -EINVAL;
  9613. }
  9614. }
  9615. pos += des_len;
  9616. }
  9617. memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
  9618. }
  9619. wdev_lock(dev->ieee80211_ptr);
  9620. ret = nl80211_key_allowed(dev->ieee80211_ptr);
  9621. if (!ret)
  9622. ret = rdev_set_qos_map(rdev, dev, qos_map);
  9623. wdev_unlock(dev->ieee80211_ptr);
  9624. kfree(qos_map);
  9625. return ret;
  9626. }
  9627. static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
  9628. {
  9629. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9630. struct net_device *dev = info->user_ptr[1];
  9631. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9632. const u8 *peer;
  9633. u8 tsid, up;
  9634. u16 admitted_time = 0;
  9635. int err;
  9636. if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
  9637. return -EOPNOTSUPP;
  9638. if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
  9639. !info->attrs[NL80211_ATTR_USER_PRIO])
  9640. return -EINVAL;
  9641. tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
  9642. if (tsid >= IEEE80211_NUM_TIDS)
  9643. return -EINVAL;
  9644. up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
  9645. if (up >= IEEE80211_NUM_UPS)
  9646. return -EINVAL;
  9647. /* WMM uses TIDs 0-7 even for TSPEC */
  9648. if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
  9649. /* TODO: handle 802.11 TSPEC/admission control
  9650. * need more attributes for that (e.g. BA session requirement);
  9651. * change the WMM adminssion test above to allow both then
  9652. */
  9653. return -EINVAL;
  9654. }
  9655. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9656. if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
  9657. admitted_time =
  9658. nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
  9659. if (!admitted_time)
  9660. return -EINVAL;
  9661. }
  9662. wdev_lock(wdev);
  9663. switch (wdev->iftype) {
  9664. case NL80211_IFTYPE_STATION:
  9665. case NL80211_IFTYPE_P2P_CLIENT:
  9666. if (wdev->current_bss)
  9667. break;
  9668. err = -ENOTCONN;
  9669. goto out;
  9670. default:
  9671. err = -EOPNOTSUPP;
  9672. goto out;
  9673. }
  9674. err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
  9675. out:
  9676. wdev_unlock(wdev);
  9677. return err;
  9678. }
  9679. static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
  9680. {
  9681. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9682. struct net_device *dev = info->user_ptr[1];
  9683. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9684. const u8 *peer;
  9685. u8 tsid;
  9686. int err;
  9687. if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
  9688. return -EINVAL;
  9689. tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
  9690. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9691. wdev_lock(wdev);
  9692. err = rdev_del_tx_ts(rdev, dev, tsid, peer);
  9693. wdev_unlock(wdev);
  9694. return err;
  9695. }
  9696. static int nl80211_tdls_channel_switch(struct sk_buff *skb,
  9697. struct genl_info *info)
  9698. {
  9699. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9700. struct net_device *dev = info->user_ptr[1];
  9701. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9702. struct cfg80211_chan_def chandef = {};
  9703. const u8 *addr;
  9704. u8 oper_class;
  9705. int err;
  9706. if (!rdev->ops->tdls_channel_switch ||
  9707. !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
  9708. return -EOPNOTSUPP;
  9709. switch (dev->ieee80211_ptr->iftype) {
  9710. case NL80211_IFTYPE_STATION:
  9711. case NL80211_IFTYPE_P2P_CLIENT:
  9712. break;
  9713. default:
  9714. return -EOPNOTSUPP;
  9715. }
  9716. if (!info->attrs[NL80211_ATTR_MAC] ||
  9717. !info->attrs[NL80211_ATTR_OPER_CLASS])
  9718. return -EINVAL;
  9719. err = nl80211_parse_chandef(rdev, info, &chandef);
  9720. if (err)
  9721. return err;
  9722. /*
  9723. * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
  9724. * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
  9725. * specification is not defined for them.
  9726. */
  9727. if (chandef.chan->band == NL80211_BAND_2GHZ &&
  9728. chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
  9729. chandef.width != NL80211_CHAN_WIDTH_20)
  9730. return -EINVAL;
  9731. /* we will be active on the TDLS link */
  9732. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
  9733. wdev->iftype))
  9734. return -EINVAL;
  9735. /* don't allow switching to DFS channels */
  9736. if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
  9737. return -EINVAL;
  9738. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9739. oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
  9740. wdev_lock(wdev);
  9741. err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
  9742. wdev_unlock(wdev);
  9743. return err;
  9744. }
  9745. static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
  9746. struct genl_info *info)
  9747. {
  9748. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9749. struct net_device *dev = info->user_ptr[1];
  9750. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9751. const u8 *addr;
  9752. if (!rdev->ops->tdls_channel_switch ||
  9753. !rdev->ops->tdls_cancel_channel_switch ||
  9754. !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
  9755. return -EOPNOTSUPP;
  9756. switch (dev->ieee80211_ptr->iftype) {
  9757. case NL80211_IFTYPE_STATION:
  9758. case NL80211_IFTYPE_P2P_CLIENT:
  9759. break;
  9760. default:
  9761. return -EOPNOTSUPP;
  9762. }
  9763. if (!info->attrs[NL80211_ATTR_MAC])
  9764. return -EINVAL;
  9765. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9766. wdev_lock(wdev);
  9767. rdev_tdls_cancel_channel_switch(rdev, dev, addr);
  9768. wdev_unlock(wdev);
  9769. return 0;
  9770. }
  9771. #define NL80211_FLAG_NEED_WIPHY 0x01
  9772. #define NL80211_FLAG_NEED_NETDEV 0x02
  9773. #define NL80211_FLAG_NEED_RTNL 0x04
  9774. #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
  9775. #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
  9776. NL80211_FLAG_CHECK_NETDEV_UP)
  9777. #define NL80211_FLAG_NEED_WDEV 0x10
  9778. /* If a netdev is associated, it must be UP, P2P must be started */
  9779. #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
  9780. NL80211_FLAG_CHECK_NETDEV_UP)
  9781. #define NL80211_FLAG_CLEAR_SKB 0x20
  9782. static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
  9783. struct genl_info *info)
  9784. {
  9785. struct cfg80211_registered_device *rdev;
  9786. struct wireless_dev *wdev;
  9787. struct net_device *dev;
  9788. bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
  9789. if (rtnl)
  9790. rtnl_lock();
  9791. if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
  9792. rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
  9793. if (IS_ERR(rdev)) {
  9794. if (rtnl)
  9795. rtnl_unlock();
  9796. return PTR_ERR(rdev);
  9797. }
  9798. info->user_ptr[0] = rdev;
  9799. } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
  9800. ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
  9801. ASSERT_RTNL();
  9802. wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
  9803. info->attrs);
  9804. if (IS_ERR(wdev)) {
  9805. if (rtnl)
  9806. rtnl_unlock();
  9807. return PTR_ERR(wdev);
  9808. }
  9809. dev = wdev->netdev;
  9810. rdev = wiphy_to_rdev(wdev->wiphy);
  9811. if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
  9812. if (!dev) {
  9813. if (rtnl)
  9814. rtnl_unlock();
  9815. return -EINVAL;
  9816. }
  9817. info->user_ptr[1] = dev;
  9818. } else {
  9819. info->user_ptr[1] = wdev;
  9820. }
  9821. if (dev) {
  9822. if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
  9823. !netif_running(dev)) {
  9824. if (rtnl)
  9825. rtnl_unlock();
  9826. return -ENETDOWN;
  9827. }
  9828. dev_hold(dev);
  9829. } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
  9830. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
  9831. !wdev->p2p_started) {
  9832. if (rtnl)
  9833. rtnl_unlock();
  9834. return -ENETDOWN;
  9835. }
  9836. if (wdev->iftype == NL80211_IFTYPE_NAN &&
  9837. !wdev->nan_started) {
  9838. if (rtnl)
  9839. rtnl_unlock();
  9840. return -ENETDOWN;
  9841. }
  9842. }
  9843. info->user_ptr[0] = rdev;
  9844. }
  9845. return 0;
  9846. }
  9847. static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
  9848. struct genl_info *info)
  9849. {
  9850. if (info->user_ptr[1]) {
  9851. if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
  9852. struct wireless_dev *wdev = info->user_ptr[1];
  9853. if (wdev->netdev)
  9854. dev_put(wdev->netdev);
  9855. } else {
  9856. dev_put(info->user_ptr[1]);
  9857. }
  9858. }
  9859. if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
  9860. rtnl_unlock();
  9861. /* If needed, clear the netlink message payload from the SKB
  9862. * as it might contain key data that shouldn't stick around on
  9863. * the heap after the SKB is freed. The netlink message header
  9864. * is still needed for further processing, so leave it intact.
  9865. */
  9866. if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
  9867. struct nlmsghdr *nlh = nlmsg_hdr(skb);
  9868. memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
  9869. }
  9870. }
  9871. static const struct genl_ops nl80211_ops[] = {
  9872. {
  9873. .cmd = NL80211_CMD_GET_WIPHY,
  9874. .doit = nl80211_get_wiphy,
  9875. .dumpit = nl80211_dump_wiphy,
  9876. .done = nl80211_dump_wiphy_done,
  9877. .policy = nl80211_policy,
  9878. /* can be retrieved by unprivileged users */
  9879. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9880. NL80211_FLAG_NEED_RTNL,
  9881. },
  9882. {
  9883. .cmd = NL80211_CMD_SET_WIPHY,
  9884. .doit = nl80211_set_wiphy,
  9885. .policy = nl80211_policy,
  9886. .flags = GENL_UNS_ADMIN_PERM,
  9887. .internal_flags = NL80211_FLAG_NEED_RTNL,
  9888. },
  9889. {
  9890. .cmd = NL80211_CMD_GET_INTERFACE,
  9891. .doit = nl80211_get_interface,
  9892. .dumpit = nl80211_dump_interface,
  9893. .policy = nl80211_policy,
  9894. /* can be retrieved by unprivileged users */
  9895. .internal_flags = NL80211_FLAG_NEED_WDEV |
  9896. NL80211_FLAG_NEED_RTNL,
  9897. },
  9898. {
  9899. .cmd = NL80211_CMD_SET_INTERFACE,
  9900. .doit = nl80211_set_interface,
  9901. .policy = nl80211_policy,
  9902. .flags = GENL_UNS_ADMIN_PERM,
  9903. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9904. NL80211_FLAG_NEED_RTNL,
  9905. },
  9906. {
  9907. .cmd = NL80211_CMD_NEW_INTERFACE,
  9908. .doit = nl80211_new_interface,
  9909. .policy = nl80211_policy,
  9910. .flags = GENL_UNS_ADMIN_PERM,
  9911. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  9912. NL80211_FLAG_NEED_RTNL,
  9913. },
  9914. {
  9915. .cmd = NL80211_CMD_DEL_INTERFACE,
  9916. .doit = nl80211_del_interface,
  9917. .policy = nl80211_policy,
  9918. .flags = GENL_UNS_ADMIN_PERM,
  9919. .internal_flags = NL80211_FLAG_NEED_WDEV |
  9920. NL80211_FLAG_NEED_RTNL,
  9921. },
  9922. {
  9923. .cmd = NL80211_CMD_GET_KEY,
  9924. .doit = nl80211_get_key,
  9925. .policy = nl80211_policy,
  9926. .flags = GENL_UNS_ADMIN_PERM,
  9927. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9928. NL80211_FLAG_NEED_RTNL,
  9929. },
  9930. {
  9931. .cmd = NL80211_CMD_SET_KEY,
  9932. .doit = nl80211_set_key,
  9933. .policy = nl80211_policy,
  9934. .flags = GENL_UNS_ADMIN_PERM,
  9935. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9936. NL80211_FLAG_NEED_RTNL |
  9937. NL80211_FLAG_CLEAR_SKB,
  9938. },
  9939. {
  9940. .cmd = NL80211_CMD_NEW_KEY,
  9941. .doit = nl80211_new_key,
  9942. .policy = nl80211_policy,
  9943. .flags = GENL_UNS_ADMIN_PERM,
  9944. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9945. NL80211_FLAG_NEED_RTNL |
  9946. NL80211_FLAG_CLEAR_SKB,
  9947. },
  9948. {
  9949. .cmd = NL80211_CMD_DEL_KEY,
  9950. .doit = nl80211_del_key,
  9951. .policy = nl80211_policy,
  9952. .flags = GENL_UNS_ADMIN_PERM,
  9953. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9954. NL80211_FLAG_NEED_RTNL,
  9955. },
  9956. {
  9957. .cmd = NL80211_CMD_SET_BEACON,
  9958. .policy = nl80211_policy,
  9959. .flags = GENL_UNS_ADMIN_PERM,
  9960. .doit = nl80211_set_beacon,
  9961. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9962. NL80211_FLAG_NEED_RTNL,
  9963. },
  9964. {
  9965. .cmd = NL80211_CMD_START_AP,
  9966. .policy = nl80211_policy,
  9967. .flags = GENL_UNS_ADMIN_PERM,
  9968. .doit = nl80211_start_ap,
  9969. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9970. NL80211_FLAG_NEED_RTNL,
  9971. },
  9972. {
  9973. .cmd = NL80211_CMD_STOP_AP,
  9974. .policy = nl80211_policy,
  9975. .flags = GENL_UNS_ADMIN_PERM,
  9976. .doit = nl80211_stop_ap,
  9977. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9978. NL80211_FLAG_NEED_RTNL,
  9979. },
  9980. {
  9981. .cmd = NL80211_CMD_GET_STATION,
  9982. .doit = nl80211_get_station,
  9983. .dumpit = nl80211_dump_station,
  9984. .policy = nl80211_policy,
  9985. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  9986. NL80211_FLAG_NEED_RTNL,
  9987. },
  9988. {
  9989. .cmd = NL80211_CMD_SET_STATION,
  9990. .doit = nl80211_set_station,
  9991. .policy = nl80211_policy,
  9992. .flags = GENL_UNS_ADMIN_PERM,
  9993. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  9994. NL80211_FLAG_NEED_RTNL,
  9995. },
  9996. {
  9997. .cmd = NL80211_CMD_NEW_STATION,
  9998. .doit = nl80211_new_station,
  9999. .policy = nl80211_policy,
  10000. .flags = GENL_UNS_ADMIN_PERM,
  10001. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10002. NL80211_FLAG_NEED_RTNL,
  10003. },
  10004. {
  10005. .cmd = NL80211_CMD_DEL_STATION,
  10006. .doit = nl80211_del_station,
  10007. .policy = nl80211_policy,
  10008. .flags = GENL_UNS_ADMIN_PERM,
  10009. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10010. NL80211_FLAG_NEED_RTNL,
  10011. },
  10012. {
  10013. .cmd = NL80211_CMD_GET_MPATH,
  10014. .doit = nl80211_get_mpath,
  10015. .dumpit = nl80211_dump_mpath,
  10016. .policy = nl80211_policy,
  10017. .flags = GENL_UNS_ADMIN_PERM,
  10018. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10019. NL80211_FLAG_NEED_RTNL,
  10020. },
  10021. {
  10022. .cmd = NL80211_CMD_GET_MPP,
  10023. .doit = nl80211_get_mpp,
  10024. .dumpit = nl80211_dump_mpp,
  10025. .policy = nl80211_policy,
  10026. .flags = GENL_UNS_ADMIN_PERM,
  10027. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10028. NL80211_FLAG_NEED_RTNL,
  10029. },
  10030. {
  10031. .cmd = NL80211_CMD_SET_MPATH,
  10032. .doit = nl80211_set_mpath,
  10033. .policy = nl80211_policy,
  10034. .flags = GENL_UNS_ADMIN_PERM,
  10035. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10036. NL80211_FLAG_NEED_RTNL,
  10037. },
  10038. {
  10039. .cmd = NL80211_CMD_NEW_MPATH,
  10040. .doit = nl80211_new_mpath,
  10041. .policy = nl80211_policy,
  10042. .flags = GENL_UNS_ADMIN_PERM,
  10043. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10044. NL80211_FLAG_NEED_RTNL,
  10045. },
  10046. {
  10047. .cmd = NL80211_CMD_DEL_MPATH,
  10048. .doit = nl80211_del_mpath,
  10049. .policy = nl80211_policy,
  10050. .flags = GENL_UNS_ADMIN_PERM,
  10051. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10052. NL80211_FLAG_NEED_RTNL,
  10053. },
  10054. {
  10055. .cmd = NL80211_CMD_SET_BSS,
  10056. .doit = nl80211_set_bss,
  10057. .policy = nl80211_policy,
  10058. .flags = GENL_UNS_ADMIN_PERM,
  10059. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10060. NL80211_FLAG_NEED_RTNL,
  10061. },
  10062. {
  10063. .cmd = NL80211_CMD_GET_REG,
  10064. .doit = nl80211_get_reg_do,
  10065. .dumpit = nl80211_get_reg_dump,
  10066. .policy = nl80211_policy,
  10067. .internal_flags = NL80211_FLAG_NEED_RTNL,
  10068. /* can be retrieved by unprivileged users */
  10069. },
  10070. #ifdef CONFIG_CFG80211_CRDA_SUPPORT
  10071. {
  10072. .cmd = NL80211_CMD_SET_REG,
  10073. .doit = nl80211_set_reg,
  10074. .policy = nl80211_policy,
  10075. .flags = GENL_ADMIN_PERM,
  10076. .internal_flags = NL80211_FLAG_NEED_RTNL,
  10077. },
  10078. #endif
  10079. {
  10080. .cmd = NL80211_CMD_REQ_SET_REG,
  10081. .doit = nl80211_req_set_reg,
  10082. .policy = nl80211_policy,
  10083. .flags = GENL_ADMIN_PERM,
  10084. },
  10085. {
  10086. .cmd = NL80211_CMD_GET_MESH_CONFIG,
  10087. .doit = nl80211_get_mesh_config,
  10088. .policy = nl80211_policy,
  10089. /* can be retrieved by unprivileged users */
  10090. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10091. NL80211_FLAG_NEED_RTNL,
  10092. },
  10093. {
  10094. .cmd = NL80211_CMD_SET_MESH_CONFIG,
  10095. .doit = nl80211_update_mesh_config,
  10096. .policy = nl80211_policy,
  10097. .flags = GENL_UNS_ADMIN_PERM,
  10098. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10099. NL80211_FLAG_NEED_RTNL,
  10100. },
  10101. {
  10102. .cmd = NL80211_CMD_TRIGGER_SCAN,
  10103. .doit = nl80211_trigger_scan,
  10104. .policy = nl80211_policy,
  10105. .flags = GENL_UNS_ADMIN_PERM,
  10106. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10107. NL80211_FLAG_NEED_RTNL,
  10108. },
  10109. {
  10110. .cmd = NL80211_CMD_ABORT_SCAN,
  10111. .doit = nl80211_abort_scan,
  10112. .policy = nl80211_policy,
  10113. .flags = GENL_UNS_ADMIN_PERM,
  10114. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10115. NL80211_FLAG_NEED_RTNL,
  10116. },
  10117. {
  10118. .cmd = NL80211_CMD_GET_SCAN,
  10119. .policy = nl80211_policy,
  10120. .dumpit = nl80211_dump_scan,
  10121. },
  10122. {
  10123. .cmd = NL80211_CMD_START_SCHED_SCAN,
  10124. .doit = nl80211_start_sched_scan,
  10125. .policy = nl80211_policy,
  10126. .flags = GENL_UNS_ADMIN_PERM,
  10127. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10128. NL80211_FLAG_NEED_RTNL,
  10129. },
  10130. {
  10131. .cmd = NL80211_CMD_STOP_SCHED_SCAN,
  10132. .doit = nl80211_stop_sched_scan,
  10133. .policy = nl80211_policy,
  10134. .flags = GENL_UNS_ADMIN_PERM,
  10135. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10136. NL80211_FLAG_NEED_RTNL,
  10137. },
  10138. {
  10139. .cmd = NL80211_CMD_AUTHENTICATE,
  10140. .doit = nl80211_authenticate,
  10141. .policy = nl80211_policy,
  10142. .flags = GENL_UNS_ADMIN_PERM,
  10143. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10144. NL80211_FLAG_NEED_RTNL |
  10145. NL80211_FLAG_CLEAR_SKB,
  10146. },
  10147. {
  10148. .cmd = NL80211_CMD_ASSOCIATE,
  10149. .doit = nl80211_associate,
  10150. .policy = nl80211_policy,
  10151. .flags = GENL_UNS_ADMIN_PERM,
  10152. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10153. NL80211_FLAG_NEED_RTNL,
  10154. },
  10155. {
  10156. .cmd = NL80211_CMD_DEAUTHENTICATE,
  10157. .doit = nl80211_deauthenticate,
  10158. .policy = nl80211_policy,
  10159. .flags = GENL_UNS_ADMIN_PERM,
  10160. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10161. NL80211_FLAG_NEED_RTNL,
  10162. },
  10163. {
  10164. .cmd = NL80211_CMD_DISASSOCIATE,
  10165. .doit = nl80211_disassociate,
  10166. .policy = nl80211_policy,
  10167. .flags = GENL_UNS_ADMIN_PERM,
  10168. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10169. NL80211_FLAG_NEED_RTNL,
  10170. },
  10171. {
  10172. .cmd = NL80211_CMD_JOIN_IBSS,
  10173. .doit = nl80211_join_ibss,
  10174. .policy = nl80211_policy,
  10175. .flags = GENL_UNS_ADMIN_PERM,
  10176. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10177. NL80211_FLAG_NEED_RTNL,
  10178. },
  10179. {
  10180. .cmd = NL80211_CMD_LEAVE_IBSS,
  10181. .doit = nl80211_leave_ibss,
  10182. .policy = nl80211_policy,
  10183. .flags = GENL_UNS_ADMIN_PERM,
  10184. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10185. NL80211_FLAG_NEED_RTNL,
  10186. },
  10187. #ifdef CONFIG_NL80211_TESTMODE
  10188. {
  10189. .cmd = NL80211_CMD_TESTMODE,
  10190. .doit = nl80211_testmode_do,
  10191. .dumpit = nl80211_testmode_dump,
  10192. .policy = nl80211_policy,
  10193. .flags = GENL_UNS_ADMIN_PERM,
  10194. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10195. NL80211_FLAG_NEED_RTNL,
  10196. },
  10197. #endif
  10198. {
  10199. .cmd = NL80211_CMD_CONNECT,
  10200. .doit = nl80211_connect,
  10201. .policy = nl80211_policy,
  10202. .flags = GENL_UNS_ADMIN_PERM,
  10203. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10204. NL80211_FLAG_NEED_RTNL,
  10205. },
  10206. {
  10207. .cmd = NL80211_CMD_DISCONNECT,
  10208. .doit = nl80211_disconnect,
  10209. .policy = nl80211_policy,
  10210. .flags = GENL_UNS_ADMIN_PERM,
  10211. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10212. NL80211_FLAG_NEED_RTNL,
  10213. },
  10214. {
  10215. .cmd = NL80211_CMD_SET_WIPHY_NETNS,
  10216. .doit = nl80211_wiphy_netns,
  10217. .policy = nl80211_policy,
  10218. .flags = GENL_UNS_ADMIN_PERM,
  10219. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10220. NL80211_FLAG_NEED_RTNL,
  10221. },
  10222. {
  10223. .cmd = NL80211_CMD_GET_SURVEY,
  10224. .policy = nl80211_policy,
  10225. .dumpit = nl80211_dump_survey,
  10226. },
  10227. {
  10228. .cmd = NL80211_CMD_SET_PMKSA,
  10229. .doit = nl80211_setdel_pmksa,
  10230. .policy = nl80211_policy,
  10231. .flags = GENL_UNS_ADMIN_PERM,
  10232. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10233. NL80211_FLAG_NEED_RTNL,
  10234. },
  10235. {
  10236. .cmd = NL80211_CMD_DEL_PMKSA,
  10237. .doit = nl80211_setdel_pmksa,
  10238. .policy = nl80211_policy,
  10239. .flags = GENL_UNS_ADMIN_PERM,
  10240. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10241. NL80211_FLAG_NEED_RTNL,
  10242. },
  10243. {
  10244. .cmd = NL80211_CMD_FLUSH_PMKSA,
  10245. .doit = nl80211_flush_pmksa,
  10246. .policy = nl80211_policy,
  10247. .flags = GENL_UNS_ADMIN_PERM,
  10248. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10249. NL80211_FLAG_NEED_RTNL,
  10250. },
  10251. {
  10252. .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
  10253. .doit = nl80211_remain_on_channel,
  10254. .policy = nl80211_policy,
  10255. .flags = GENL_UNS_ADMIN_PERM,
  10256. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10257. NL80211_FLAG_NEED_RTNL,
  10258. },
  10259. {
  10260. .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  10261. .doit = nl80211_cancel_remain_on_channel,
  10262. .policy = nl80211_policy,
  10263. .flags = GENL_UNS_ADMIN_PERM,
  10264. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10265. NL80211_FLAG_NEED_RTNL,
  10266. },
  10267. {
  10268. .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
  10269. .doit = nl80211_set_tx_bitrate_mask,
  10270. .policy = nl80211_policy,
  10271. .flags = GENL_UNS_ADMIN_PERM,
  10272. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10273. NL80211_FLAG_NEED_RTNL,
  10274. },
  10275. {
  10276. .cmd = NL80211_CMD_REGISTER_FRAME,
  10277. .doit = nl80211_register_mgmt,
  10278. .policy = nl80211_policy,
  10279. .flags = GENL_UNS_ADMIN_PERM,
  10280. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10281. NL80211_FLAG_NEED_RTNL,
  10282. },
  10283. {
  10284. .cmd = NL80211_CMD_FRAME,
  10285. .doit = nl80211_tx_mgmt,
  10286. .policy = nl80211_policy,
  10287. .flags = GENL_UNS_ADMIN_PERM,
  10288. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10289. NL80211_FLAG_NEED_RTNL,
  10290. },
  10291. {
  10292. .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
  10293. .doit = nl80211_tx_mgmt_cancel_wait,
  10294. .policy = nl80211_policy,
  10295. .flags = GENL_UNS_ADMIN_PERM,
  10296. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10297. NL80211_FLAG_NEED_RTNL,
  10298. },
  10299. {
  10300. .cmd = NL80211_CMD_SET_POWER_SAVE,
  10301. .doit = nl80211_set_power_save,
  10302. .policy = nl80211_policy,
  10303. .flags = GENL_UNS_ADMIN_PERM,
  10304. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10305. NL80211_FLAG_NEED_RTNL,
  10306. },
  10307. {
  10308. .cmd = NL80211_CMD_GET_POWER_SAVE,
  10309. .doit = nl80211_get_power_save,
  10310. .policy = nl80211_policy,
  10311. /* can be retrieved by unprivileged users */
  10312. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10313. NL80211_FLAG_NEED_RTNL,
  10314. },
  10315. {
  10316. .cmd = NL80211_CMD_SET_CQM,
  10317. .doit = nl80211_set_cqm,
  10318. .policy = nl80211_policy,
  10319. .flags = GENL_UNS_ADMIN_PERM,
  10320. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10321. NL80211_FLAG_NEED_RTNL,
  10322. },
  10323. {
  10324. .cmd = NL80211_CMD_SET_CHANNEL,
  10325. .doit = nl80211_set_channel,
  10326. .policy = nl80211_policy,
  10327. .flags = GENL_UNS_ADMIN_PERM,
  10328. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10329. NL80211_FLAG_NEED_RTNL,
  10330. },
  10331. {
  10332. .cmd = NL80211_CMD_SET_WDS_PEER,
  10333. .doit = nl80211_set_wds_peer,
  10334. .policy = nl80211_policy,
  10335. .flags = GENL_UNS_ADMIN_PERM,
  10336. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10337. NL80211_FLAG_NEED_RTNL,
  10338. },
  10339. {
  10340. .cmd = NL80211_CMD_JOIN_MESH,
  10341. .doit = nl80211_join_mesh,
  10342. .policy = nl80211_policy,
  10343. .flags = GENL_UNS_ADMIN_PERM,
  10344. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10345. NL80211_FLAG_NEED_RTNL,
  10346. },
  10347. {
  10348. .cmd = NL80211_CMD_LEAVE_MESH,
  10349. .doit = nl80211_leave_mesh,
  10350. .policy = nl80211_policy,
  10351. .flags = GENL_UNS_ADMIN_PERM,
  10352. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10353. NL80211_FLAG_NEED_RTNL,
  10354. },
  10355. {
  10356. .cmd = NL80211_CMD_JOIN_OCB,
  10357. .doit = nl80211_join_ocb,
  10358. .policy = nl80211_policy,
  10359. .flags = GENL_UNS_ADMIN_PERM,
  10360. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10361. NL80211_FLAG_NEED_RTNL,
  10362. },
  10363. {
  10364. .cmd = NL80211_CMD_LEAVE_OCB,
  10365. .doit = nl80211_leave_ocb,
  10366. .policy = nl80211_policy,
  10367. .flags = GENL_UNS_ADMIN_PERM,
  10368. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10369. NL80211_FLAG_NEED_RTNL,
  10370. },
  10371. #ifdef CONFIG_PM
  10372. {
  10373. .cmd = NL80211_CMD_GET_WOWLAN,
  10374. .doit = nl80211_get_wowlan,
  10375. .policy = nl80211_policy,
  10376. /* can be retrieved by unprivileged users */
  10377. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10378. NL80211_FLAG_NEED_RTNL,
  10379. },
  10380. {
  10381. .cmd = NL80211_CMD_SET_WOWLAN,
  10382. .doit = nl80211_set_wowlan,
  10383. .policy = nl80211_policy,
  10384. .flags = GENL_UNS_ADMIN_PERM,
  10385. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10386. NL80211_FLAG_NEED_RTNL,
  10387. },
  10388. #endif
  10389. {
  10390. .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
  10391. .doit = nl80211_set_rekey_data,
  10392. .policy = nl80211_policy,
  10393. .flags = GENL_UNS_ADMIN_PERM,
  10394. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10395. NL80211_FLAG_NEED_RTNL |
  10396. NL80211_FLAG_CLEAR_SKB,
  10397. },
  10398. {
  10399. .cmd = NL80211_CMD_TDLS_MGMT,
  10400. .doit = nl80211_tdls_mgmt,
  10401. .policy = nl80211_policy,
  10402. .flags = GENL_UNS_ADMIN_PERM,
  10403. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10404. NL80211_FLAG_NEED_RTNL,
  10405. },
  10406. {
  10407. .cmd = NL80211_CMD_TDLS_OPER,
  10408. .doit = nl80211_tdls_oper,
  10409. .policy = nl80211_policy,
  10410. .flags = GENL_UNS_ADMIN_PERM,
  10411. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10412. NL80211_FLAG_NEED_RTNL,
  10413. },
  10414. {
  10415. .cmd = NL80211_CMD_UNEXPECTED_FRAME,
  10416. .doit = nl80211_register_unexpected_frame,
  10417. .policy = nl80211_policy,
  10418. .flags = GENL_UNS_ADMIN_PERM,
  10419. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10420. NL80211_FLAG_NEED_RTNL,
  10421. },
  10422. {
  10423. .cmd = NL80211_CMD_PROBE_CLIENT,
  10424. .doit = nl80211_probe_client,
  10425. .policy = nl80211_policy,
  10426. .flags = GENL_UNS_ADMIN_PERM,
  10427. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10428. NL80211_FLAG_NEED_RTNL,
  10429. },
  10430. {
  10431. .cmd = NL80211_CMD_REGISTER_BEACONS,
  10432. .doit = nl80211_register_beacons,
  10433. .policy = nl80211_policy,
  10434. .flags = GENL_UNS_ADMIN_PERM,
  10435. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10436. NL80211_FLAG_NEED_RTNL,
  10437. },
  10438. {
  10439. .cmd = NL80211_CMD_SET_NOACK_MAP,
  10440. .doit = nl80211_set_noack_map,
  10441. .policy = nl80211_policy,
  10442. .flags = GENL_UNS_ADMIN_PERM,
  10443. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10444. NL80211_FLAG_NEED_RTNL,
  10445. },
  10446. {
  10447. .cmd = NL80211_CMD_START_P2P_DEVICE,
  10448. .doit = nl80211_start_p2p_device,
  10449. .policy = nl80211_policy,
  10450. .flags = GENL_UNS_ADMIN_PERM,
  10451. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10452. NL80211_FLAG_NEED_RTNL,
  10453. },
  10454. {
  10455. .cmd = NL80211_CMD_STOP_P2P_DEVICE,
  10456. .doit = nl80211_stop_p2p_device,
  10457. .policy = nl80211_policy,
  10458. .flags = GENL_UNS_ADMIN_PERM,
  10459. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10460. NL80211_FLAG_NEED_RTNL,
  10461. },
  10462. {
  10463. .cmd = NL80211_CMD_START_NAN,
  10464. .doit = nl80211_start_nan,
  10465. .policy = nl80211_policy,
  10466. .flags = GENL_ADMIN_PERM,
  10467. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10468. NL80211_FLAG_NEED_RTNL,
  10469. },
  10470. {
  10471. .cmd = NL80211_CMD_STOP_NAN,
  10472. .doit = nl80211_stop_nan,
  10473. .policy = nl80211_policy,
  10474. .flags = GENL_ADMIN_PERM,
  10475. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10476. NL80211_FLAG_NEED_RTNL,
  10477. },
  10478. {
  10479. .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
  10480. .doit = nl80211_nan_add_func,
  10481. .policy = nl80211_policy,
  10482. .flags = GENL_ADMIN_PERM,
  10483. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10484. NL80211_FLAG_NEED_RTNL,
  10485. },
  10486. {
  10487. .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
  10488. .doit = nl80211_nan_del_func,
  10489. .policy = nl80211_policy,
  10490. .flags = GENL_ADMIN_PERM,
  10491. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10492. NL80211_FLAG_NEED_RTNL,
  10493. },
  10494. {
  10495. .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
  10496. .doit = nl80211_nan_change_config,
  10497. .policy = nl80211_policy,
  10498. .flags = GENL_ADMIN_PERM,
  10499. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10500. NL80211_FLAG_NEED_RTNL,
  10501. },
  10502. {
  10503. .cmd = NL80211_CMD_SET_MCAST_RATE,
  10504. .doit = nl80211_set_mcast_rate,
  10505. .policy = nl80211_policy,
  10506. .flags = GENL_UNS_ADMIN_PERM,
  10507. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10508. NL80211_FLAG_NEED_RTNL,
  10509. },
  10510. {
  10511. .cmd = NL80211_CMD_SET_MAC_ACL,
  10512. .doit = nl80211_set_mac_acl,
  10513. .policy = nl80211_policy,
  10514. .flags = GENL_UNS_ADMIN_PERM,
  10515. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10516. NL80211_FLAG_NEED_RTNL,
  10517. },
  10518. {
  10519. .cmd = NL80211_CMD_RADAR_DETECT,
  10520. .doit = nl80211_start_radar_detection,
  10521. .policy = nl80211_policy,
  10522. .flags = GENL_UNS_ADMIN_PERM,
  10523. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10524. NL80211_FLAG_NEED_RTNL,
  10525. },
  10526. {
  10527. .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
  10528. .doit = nl80211_get_protocol_features,
  10529. .policy = nl80211_policy,
  10530. },
  10531. {
  10532. .cmd = NL80211_CMD_UPDATE_FT_IES,
  10533. .doit = nl80211_update_ft_ies,
  10534. .policy = nl80211_policy,
  10535. .flags = GENL_UNS_ADMIN_PERM,
  10536. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10537. NL80211_FLAG_NEED_RTNL,
  10538. },
  10539. {
  10540. .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
  10541. .doit = nl80211_crit_protocol_start,
  10542. .policy = nl80211_policy,
  10543. .flags = GENL_UNS_ADMIN_PERM,
  10544. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10545. NL80211_FLAG_NEED_RTNL,
  10546. },
  10547. {
  10548. .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
  10549. .doit = nl80211_crit_protocol_stop,
  10550. .policy = nl80211_policy,
  10551. .flags = GENL_UNS_ADMIN_PERM,
  10552. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10553. NL80211_FLAG_NEED_RTNL,
  10554. },
  10555. {
  10556. .cmd = NL80211_CMD_GET_COALESCE,
  10557. .doit = nl80211_get_coalesce,
  10558. .policy = nl80211_policy,
  10559. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10560. NL80211_FLAG_NEED_RTNL,
  10561. },
  10562. {
  10563. .cmd = NL80211_CMD_SET_COALESCE,
  10564. .doit = nl80211_set_coalesce,
  10565. .policy = nl80211_policy,
  10566. .flags = GENL_UNS_ADMIN_PERM,
  10567. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10568. NL80211_FLAG_NEED_RTNL,
  10569. },
  10570. {
  10571. .cmd = NL80211_CMD_CHANNEL_SWITCH,
  10572. .doit = nl80211_channel_switch,
  10573. .policy = nl80211_policy,
  10574. .flags = GENL_UNS_ADMIN_PERM,
  10575. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10576. NL80211_FLAG_NEED_RTNL,
  10577. },
  10578. {
  10579. .cmd = NL80211_CMD_VENDOR,
  10580. .doit = nl80211_vendor_cmd,
  10581. .dumpit = nl80211_vendor_cmd_dump,
  10582. .policy = nl80211_policy,
  10583. .flags = GENL_UNS_ADMIN_PERM,
  10584. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10585. NL80211_FLAG_NEED_RTNL,
  10586. },
  10587. {
  10588. .cmd = NL80211_CMD_SET_QOS_MAP,
  10589. .doit = nl80211_set_qos_map,
  10590. .policy = nl80211_policy,
  10591. .flags = GENL_UNS_ADMIN_PERM,
  10592. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10593. NL80211_FLAG_NEED_RTNL,
  10594. },
  10595. {
  10596. .cmd = NL80211_CMD_ADD_TX_TS,
  10597. .doit = nl80211_add_tx_ts,
  10598. .policy = nl80211_policy,
  10599. .flags = GENL_UNS_ADMIN_PERM,
  10600. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10601. NL80211_FLAG_NEED_RTNL,
  10602. },
  10603. {
  10604. .cmd = NL80211_CMD_DEL_TX_TS,
  10605. .doit = nl80211_del_tx_ts,
  10606. .policy = nl80211_policy,
  10607. .flags = GENL_UNS_ADMIN_PERM,
  10608. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10609. NL80211_FLAG_NEED_RTNL,
  10610. },
  10611. {
  10612. .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
  10613. .doit = nl80211_tdls_channel_switch,
  10614. .policy = nl80211_policy,
  10615. .flags = GENL_UNS_ADMIN_PERM,
  10616. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10617. NL80211_FLAG_NEED_RTNL,
  10618. },
  10619. {
  10620. .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
  10621. .doit = nl80211_tdls_cancel_channel_switch,
  10622. .policy = nl80211_policy,
  10623. .flags = GENL_UNS_ADMIN_PERM,
  10624. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10625. NL80211_FLAG_NEED_RTNL,
  10626. },
  10627. };
  10628. /* notification functions */
  10629. void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
  10630. enum nl80211_commands cmd)
  10631. {
  10632. struct sk_buff *msg;
  10633. struct nl80211_dump_wiphy_state state = {};
  10634. WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
  10635. cmd != NL80211_CMD_DEL_WIPHY);
  10636. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10637. if (!msg)
  10638. return;
  10639. if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
  10640. nlmsg_free(msg);
  10641. return;
  10642. }
  10643. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10644. NL80211_MCGRP_CONFIG, GFP_KERNEL);
  10645. }
  10646. void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
  10647. struct wireless_dev *wdev,
  10648. enum nl80211_commands cmd)
  10649. {
  10650. struct sk_buff *msg;
  10651. WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
  10652. cmd != NL80211_CMD_DEL_INTERFACE);
  10653. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10654. if (!msg)
  10655. return;
  10656. if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
  10657. cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
  10658. nlmsg_free(msg);
  10659. return;
  10660. }
  10661. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10662. NL80211_MCGRP_CONFIG, GFP_KERNEL);
  10663. }
  10664. static int nl80211_add_scan_req(struct sk_buff *msg,
  10665. struct cfg80211_registered_device *rdev)
  10666. {
  10667. struct cfg80211_scan_request *req = rdev->scan_req;
  10668. struct nlattr *nest;
  10669. int i;
  10670. if (WARN_ON(!req))
  10671. return 0;
  10672. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
  10673. if (!nest)
  10674. goto nla_put_failure;
  10675. for (i = 0; i < req->n_ssids; i++) {
  10676. if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
  10677. goto nla_put_failure;
  10678. }
  10679. nla_nest_end(msg, nest);
  10680. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  10681. if (!nest)
  10682. goto nla_put_failure;
  10683. for (i = 0; i < req->n_channels; i++) {
  10684. if (nla_put_u32(msg, i, req->channels[i]->center_freq))
  10685. goto nla_put_failure;
  10686. }
  10687. nla_nest_end(msg, nest);
  10688. if (req->ie &&
  10689. nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
  10690. goto nla_put_failure;
  10691. if (req->flags &&
  10692. nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
  10693. goto nla_put_failure;
  10694. if (req->info.scan_start_tsf &&
  10695. (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
  10696. req->info.scan_start_tsf, NL80211_BSS_PAD) ||
  10697. nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
  10698. req->info.tsf_bssid)))
  10699. goto nla_put_failure;
  10700. return 0;
  10701. nla_put_failure:
  10702. return -ENOBUFS;
  10703. }
  10704. static int nl80211_send_scan_msg(struct sk_buff *msg,
  10705. struct cfg80211_registered_device *rdev,
  10706. struct wireless_dev *wdev,
  10707. u32 portid, u32 seq, int flags,
  10708. u32 cmd)
  10709. {
  10710. void *hdr;
  10711. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  10712. if (!hdr)
  10713. return -1;
  10714. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10715. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  10716. wdev->netdev->ifindex)) ||
  10717. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  10718. NL80211_ATTR_PAD))
  10719. goto nla_put_failure;
  10720. /* ignore errors and send incomplete event anyway */
  10721. nl80211_add_scan_req(msg, rdev);
  10722. genlmsg_end(msg, hdr);
  10723. return 0;
  10724. nla_put_failure:
  10725. genlmsg_cancel(msg, hdr);
  10726. return -EMSGSIZE;
  10727. }
  10728. static int
  10729. nl80211_send_sched_scan_msg(struct sk_buff *msg,
  10730. struct cfg80211_registered_device *rdev,
  10731. struct net_device *netdev,
  10732. u32 portid, u32 seq, int flags, u32 cmd)
  10733. {
  10734. void *hdr;
  10735. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  10736. if (!hdr)
  10737. return -1;
  10738. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10739. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  10740. goto nla_put_failure;
  10741. genlmsg_end(msg, hdr);
  10742. return 0;
  10743. nla_put_failure:
  10744. genlmsg_cancel(msg, hdr);
  10745. return -EMSGSIZE;
  10746. }
  10747. void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
  10748. struct wireless_dev *wdev)
  10749. {
  10750. struct sk_buff *msg;
  10751. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10752. if (!msg)
  10753. return;
  10754. if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
  10755. NL80211_CMD_TRIGGER_SCAN) < 0) {
  10756. nlmsg_free(msg);
  10757. return;
  10758. }
  10759. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10760. NL80211_MCGRP_SCAN, GFP_KERNEL);
  10761. }
  10762. struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
  10763. struct wireless_dev *wdev, bool aborted)
  10764. {
  10765. struct sk_buff *msg;
  10766. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10767. if (!msg)
  10768. return NULL;
  10769. if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
  10770. aborted ? NL80211_CMD_SCAN_ABORTED :
  10771. NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
  10772. nlmsg_free(msg);
  10773. return NULL;
  10774. }
  10775. return msg;
  10776. }
  10777. void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
  10778. struct sk_buff *msg)
  10779. {
  10780. if (!msg)
  10781. return;
  10782. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10783. NL80211_MCGRP_SCAN, GFP_KERNEL);
  10784. }
  10785. void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
  10786. struct net_device *netdev)
  10787. {
  10788. struct sk_buff *msg;
  10789. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10790. if (!msg)
  10791. return;
  10792. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
  10793. NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
  10794. nlmsg_free(msg);
  10795. return;
  10796. }
  10797. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10798. NL80211_MCGRP_SCAN, GFP_KERNEL);
  10799. }
  10800. void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
  10801. struct net_device *netdev, u32 cmd)
  10802. {
  10803. struct sk_buff *msg;
  10804. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10805. if (!msg)
  10806. return;
  10807. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
  10808. nlmsg_free(msg);
  10809. return;
  10810. }
  10811. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10812. NL80211_MCGRP_SCAN, GFP_KERNEL);
  10813. }
  10814. static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
  10815. struct regulatory_request *request)
  10816. {
  10817. /* Userspace can always count this one always being set */
  10818. if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
  10819. goto nla_put_failure;
  10820. if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
  10821. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  10822. NL80211_REGDOM_TYPE_WORLD))
  10823. goto nla_put_failure;
  10824. } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
  10825. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  10826. NL80211_REGDOM_TYPE_CUSTOM_WORLD))
  10827. goto nla_put_failure;
  10828. } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
  10829. request->intersect) {
  10830. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  10831. NL80211_REGDOM_TYPE_INTERSECTION))
  10832. goto nla_put_failure;
  10833. } else {
  10834. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  10835. NL80211_REGDOM_TYPE_COUNTRY) ||
  10836. nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
  10837. request->alpha2))
  10838. goto nla_put_failure;
  10839. }
  10840. if (request->wiphy_idx != WIPHY_IDX_INVALID) {
  10841. struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
  10842. if (wiphy &&
  10843. nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
  10844. goto nla_put_failure;
  10845. if (wiphy &&
  10846. wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  10847. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  10848. goto nla_put_failure;
  10849. }
  10850. return true;
  10851. nla_put_failure:
  10852. return false;
  10853. }
  10854. /*
  10855. * This can happen on global regulatory changes or device specific settings
  10856. * based on custom regulatory domains.
  10857. */
  10858. void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
  10859. struct regulatory_request *request)
  10860. {
  10861. struct sk_buff *msg;
  10862. void *hdr;
  10863. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10864. if (!msg)
  10865. return;
  10866. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
  10867. if (!hdr) {
  10868. nlmsg_free(msg);
  10869. return;
  10870. }
  10871. if (nl80211_reg_change_event_fill(msg, request) == false)
  10872. goto nla_put_failure;
  10873. genlmsg_end(msg, hdr);
  10874. rcu_read_lock();
  10875. genlmsg_multicast_allns(&nl80211_fam, msg, 0,
  10876. NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
  10877. rcu_read_unlock();
  10878. return;
  10879. nla_put_failure:
  10880. genlmsg_cancel(msg, hdr);
  10881. nlmsg_free(msg);
  10882. }
  10883. static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
  10884. struct net_device *netdev,
  10885. const u8 *buf, size_t len,
  10886. enum nl80211_commands cmd, gfp_t gfp,
  10887. int uapsd_queues)
  10888. {
  10889. struct sk_buff *msg;
  10890. void *hdr;
  10891. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10892. if (!msg)
  10893. return;
  10894. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  10895. if (!hdr) {
  10896. nlmsg_free(msg);
  10897. return;
  10898. }
  10899. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10900. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  10901. nla_put(msg, NL80211_ATTR_FRAME, len, buf))
  10902. goto nla_put_failure;
  10903. if (uapsd_queues >= 0) {
  10904. struct nlattr *nla_wmm =
  10905. nla_nest_start(msg, NL80211_ATTR_STA_WME);
  10906. if (!nla_wmm)
  10907. goto nla_put_failure;
  10908. if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
  10909. uapsd_queues))
  10910. goto nla_put_failure;
  10911. nla_nest_end(msg, nla_wmm);
  10912. }
  10913. genlmsg_end(msg, hdr);
  10914. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10915. NL80211_MCGRP_MLME, gfp);
  10916. return;
  10917. nla_put_failure:
  10918. genlmsg_cancel(msg, hdr);
  10919. nlmsg_free(msg);
  10920. }
  10921. void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
  10922. struct net_device *netdev, const u8 *buf,
  10923. size_t len, gfp_t gfp)
  10924. {
  10925. nl80211_send_mlme_event(rdev, netdev, buf, len,
  10926. NL80211_CMD_AUTHENTICATE, gfp, -1);
  10927. }
  10928. void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
  10929. struct net_device *netdev, const u8 *buf,
  10930. size_t len, gfp_t gfp, int uapsd_queues)
  10931. {
  10932. nl80211_send_mlme_event(rdev, netdev, buf, len,
  10933. NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
  10934. }
  10935. void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
  10936. struct net_device *netdev, const u8 *buf,
  10937. size_t len, gfp_t gfp)
  10938. {
  10939. nl80211_send_mlme_event(rdev, netdev, buf, len,
  10940. NL80211_CMD_DEAUTHENTICATE, gfp, -1);
  10941. }
  10942. void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
  10943. struct net_device *netdev, const u8 *buf,
  10944. size_t len, gfp_t gfp)
  10945. {
  10946. nl80211_send_mlme_event(rdev, netdev, buf, len,
  10947. NL80211_CMD_DISASSOCIATE, gfp, -1);
  10948. }
  10949. void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
  10950. size_t len)
  10951. {
  10952. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10953. struct wiphy *wiphy = wdev->wiphy;
  10954. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  10955. const struct ieee80211_mgmt *mgmt = (void *)buf;
  10956. u32 cmd;
  10957. if (WARN_ON(len < 2))
  10958. return;
  10959. if (ieee80211_is_deauth(mgmt->frame_control))
  10960. cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
  10961. else
  10962. cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
  10963. trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
  10964. nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
  10965. }
  10966. EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
  10967. static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
  10968. struct net_device *netdev, int cmd,
  10969. const u8 *addr, gfp_t gfp)
  10970. {
  10971. struct sk_buff *msg;
  10972. void *hdr;
  10973. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  10974. if (!msg)
  10975. return;
  10976. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  10977. if (!hdr) {
  10978. nlmsg_free(msg);
  10979. return;
  10980. }
  10981. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  10982. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  10983. nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
  10984. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  10985. goto nla_put_failure;
  10986. genlmsg_end(msg, hdr);
  10987. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10988. NL80211_MCGRP_MLME, gfp);
  10989. return;
  10990. nla_put_failure:
  10991. genlmsg_cancel(msg, hdr);
  10992. nlmsg_free(msg);
  10993. }
  10994. void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
  10995. struct net_device *netdev, const u8 *addr,
  10996. gfp_t gfp)
  10997. {
  10998. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
  10999. addr, gfp);
  11000. }
  11001. void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
  11002. struct net_device *netdev, const u8 *addr,
  11003. gfp_t gfp)
  11004. {
  11005. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
  11006. addr, gfp);
  11007. }
  11008. void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
  11009. struct net_device *netdev, const u8 *bssid,
  11010. const u8 *req_ie, size_t req_ie_len,
  11011. const u8 *resp_ie, size_t resp_ie_len,
  11012. int status, gfp_t gfp)
  11013. {
  11014. struct sk_buff *msg;
  11015. void *hdr;
  11016. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11017. if (!msg)
  11018. return;
  11019. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
  11020. if (!hdr) {
  11021. nlmsg_free(msg);
  11022. return;
  11023. }
  11024. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11025. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11026. (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
  11027. nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
  11028. status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
  11029. status) ||
  11030. (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) ||
  11031. (req_ie &&
  11032. nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
  11033. (resp_ie &&
  11034. nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
  11035. goto nla_put_failure;
  11036. genlmsg_end(msg, hdr);
  11037. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11038. NL80211_MCGRP_MLME, gfp);
  11039. return;
  11040. nla_put_failure:
  11041. genlmsg_cancel(msg, hdr);
  11042. nlmsg_free(msg);
  11043. }
  11044. void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
  11045. struct net_device *netdev, const u8 *bssid,
  11046. const u8 *req_ie, size_t req_ie_len,
  11047. const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
  11048. {
  11049. struct sk_buff *msg;
  11050. void *hdr;
  11051. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11052. if (!msg)
  11053. return;
  11054. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
  11055. if (!hdr) {
  11056. nlmsg_free(msg);
  11057. return;
  11058. }
  11059. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11060. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11061. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
  11062. (req_ie &&
  11063. nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
  11064. (resp_ie &&
  11065. nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
  11066. goto nla_put_failure;
  11067. genlmsg_end(msg, hdr);
  11068. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11069. NL80211_MCGRP_MLME, gfp);
  11070. return;
  11071. nla_put_failure:
  11072. genlmsg_cancel(msg, hdr);
  11073. nlmsg_free(msg);
  11074. }
  11075. void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
  11076. struct net_device *netdev, u16 reason,
  11077. const u8 *ie, size_t ie_len, bool from_ap)
  11078. {
  11079. struct sk_buff *msg;
  11080. void *hdr;
  11081. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  11082. if (!msg)
  11083. return;
  11084. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
  11085. if (!hdr) {
  11086. nlmsg_free(msg);
  11087. return;
  11088. }
  11089. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11090. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11091. (from_ap && reason &&
  11092. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
  11093. (from_ap &&
  11094. nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
  11095. (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
  11096. goto nla_put_failure;
  11097. genlmsg_end(msg, hdr);
  11098. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11099. NL80211_MCGRP_MLME, GFP_KERNEL);
  11100. return;
  11101. nla_put_failure:
  11102. genlmsg_cancel(msg, hdr);
  11103. nlmsg_free(msg);
  11104. }
  11105. void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
  11106. struct net_device *netdev, const u8 *bssid,
  11107. gfp_t gfp)
  11108. {
  11109. struct sk_buff *msg;
  11110. void *hdr;
  11111. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11112. if (!msg)
  11113. return;
  11114. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
  11115. if (!hdr) {
  11116. nlmsg_free(msg);
  11117. return;
  11118. }
  11119. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11120. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11121. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
  11122. goto nla_put_failure;
  11123. genlmsg_end(msg, hdr);
  11124. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11125. NL80211_MCGRP_MLME, gfp);
  11126. return;
  11127. nla_put_failure:
  11128. genlmsg_cancel(msg, hdr);
  11129. nlmsg_free(msg);
  11130. }
  11131. void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
  11132. const u8* ie, u8 ie_len, gfp_t gfp)
  11133. {
  11134. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11135. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11136. struct sk_buff *msg;
  11137. void *hdr;
  11138. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
  11139. return;
  11140. trace_cfg80211_notify_new_peer_candidate(dev, addr);
  11141. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11142. if (!msg)
  11143. return;
  11144. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
  11145. if (!hdr) {
  11146. nlmsg_free(msg);
  11147. return;
  11148. }
  11149. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11150. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11151. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  11152. (ie_len && ie &&
  11153. nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
  11154. goto nla_put_failure;
  11155. genlmsg_end(msg, hdr);
  11156. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11157. NL80211_MCGRP_MLME, gfp);
  11158. return;
  11159. nla_put_failure:
  11160. genlmsg_cancel(msg, hdr);
  11161. nlmsg_free(msg);
  11162. }
  11163. EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
  11164. void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
  11165. struct net_device *netdev, const u8 *addr,
  11166. enum nl80211_key_type key_type, int key_id,
  11167. const u8 *tsc, gfp_t gfp)
  11168. {
  11169. struct sk_buff *msg;
  11170. void *hdr;
  11171. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11172. if (!msg)
  11173. return;
  11174. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
  11175. if (!hdr) {
  11176. nlmsg_free(msg);
  11177. return;
  11178. }
  11179. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11180. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11181. (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
  11182. nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
  11183. (key_id != -1 &&
  11184. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
  11185. (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
  11186. goto nla_put_failure;
  11187. genlmsg_end(msg, hdr);
  11188. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11189. NL80211_MCGRP_MLME, gfp);
  11190. return;
  11191. nla_put_failure:
  11192. genlmsg_cancel(msg, hdr);
  11193. nlmsg_free(msg);
  11194. }
  11195. void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
  11196. struct ieee80211_channel *channel_before,
  11197. struct ieee80211_channel *channel_after)
  11198. {
  11199. struct sk_buff *msg;
  11200. void *hdr;
  11201. struct nlattr *nl_freq;
  11202. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  11203. if (!msg)
  11204. return;
  11205. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
  11206. if (!hdr) {
  11207. nlmsg_free(msg);
  11208. return;
  11209. }
  11210. /*
  11211. * Since we are applying the beacon hint to a wiphy we know its
  11212. * wiphy_idx is valid
  11213. */
  11214. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  11215. goto nla_put_failure;
  11216. /* Before */
  11217. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
  11218. if (!nl_freq)
  11219. goto nla_put_failure;
  11220. if (nl80211_msg_put_channel(msg, channel_before, false))
  11221. goto nla_put_failure;
  11222. nla_nest_end(msg, nl_freq);
  11223. /* After */
  11224. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
  11225. if (!nl_freq)
  11226. goto nla_put_failure;
  11227. if (nl80211_msg_put_channel(msg, channel_after, false))
  11228. goto nla_put_failure;
  11229. nla_nest_end(msg, nl_freq);
  11230. genlmsg_end(msg, hdr);
  11231. rcu_read_lock();
  11232. genlmsg_multicast_allns(&nl80211_fam, msg, 0,
  11233. NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
  11234. rcu_read_unlock();
  11235. return;
  11236. nla_put_failure:
  11237. genlmsg_cancel(msg, hdr);
  11238. nlmsg_free(msg);
  11239. }
  11240. static void nl80211_send_remain_on_chan_event(
  11241. int cmd, struct cfg80211_registered_device *rdev,
  11242. struct wireless_dev *wdev, u64 cookie,
  11243. struct ieee80211_channel *chan,
  11244. unsigned int duration, gfp_t gfp)
  11245. {
  11246. struct sk_buff *msg;
  11247. void *hdr;
  11248. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11249. if (!msg)
  11250. return;
  11251. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  11252. if (!hdr) {
  11253. nlmsg_free(msg);
  11254. return;
  11255. }
  11256. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11257. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11258. wdev->netdev->ifindex)) ||
  11259. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11260. NL80211_ATTR_PAD) ||
  11261. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
  11262. nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  11263. NL80211_CHAN_NO_HT) ||
  11264. nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  11265. NL80211_ATTR_PAD))
  11266. goto nla_put_failure;
  11267. if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
  11268. nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
  11269. goto nla_put_failure;
  11270. genlmsg_end(msg, hdr);
  11271. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11272. NL80211_MCGRP_MLME, gfp);
  11273. return;
  11274. nla_put_failure:
  11275. genlmsg_cancel(msg, hdr);
  11276. nlmsg_free(msg);
  11277. }
  11278. void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
  11279. struct ieee80211_channel *chan,
  11280. unsigned int duration, gfp_t gfp)
  11281. {
  11282. struct wiphy *wiphy = wdev->wiphy;
  11283. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11284. trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
  11285. nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
  11286. rdev, wdev, cookie, chan,
  11287. duration, gfp);
  11288. }
  11289. EXPORT_SYMBOL(cfg80211_ready_on_channel);
  11290. void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
  11291. struct ieee80211_channel *chan,
  11292. gfp_t gfp)
  11293. {
  11294. struct wiphy *wiphy = wdev->wiphy;
  11295. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11296. trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
  11297. nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  11298. rdev, wdev, cookie, chan, 0, gfp);
  11299. }
  11300. EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
  11301. void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
  11302. struct station_info *sinfo, gfp_t gfp)
  11303. {
  11304. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  11305. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11306. struct sk_buff *msg;
  11307. trace_cfg80211_new_sta(dev, mac_addr, sinfo);
  11308. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11309. if (!msg)
  11310. return;
  11311. if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
  11312. rdev, dev, mac_addr, sinfo) < 0) {
  11313. nlmsg_free(msg);
  11314. return;
  11315. }
  11316. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11317. NL80211_MCGRP_MLME, gfp);
  11318. }
  11319. EXPORT_SYMBOL(cfg80211_new_sta);
  11320. void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
  11321. struct station_info *sinfo, gfp_t gfp)
  11322. {
  11323. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  11324. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11325. struct sk_buff *msg;
  11326. struct station_info empty_sinfo = {};
  11327. if (!sinfo)
  11328. sinfo = &empty_sinfo;
  11329. trace_cfg80211_del_sta(dev, mac_addr);
  11330. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11331. if (!msg)
  11332. return;
  11333. if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
  11334. rdev, dev, mac_addr, sinfo) < 0) {
  11335. nlmsg_free(msg);
  11336. return;
  11337. }
  11338. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11339. NL80211_MCGRP_MLME, gfp);
  11340. }
  11341. EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
  11342. void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
  11343. enum nl80211_connect_failed_reason reason,
  11344. gfp_t gfp)
  11345. {
  11346. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  11347. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11348. struct sk_buff *msg;
  11349. void *hdr;
  11350. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  11351. if (!msg)
  11352. return;
  11353. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
  11354. if (!hdr) {
  11355. nlmsg_free(msg);
  11356. return;
  11357. }
  11358. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11359. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
  11360. nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
  11361. goto nla_put_failure;
  11362. genlmsg_end(msg, hdr);
  11363. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11364. NL80211_MCGRP_MLME, gfp);
  11365. return;
  11366. nla_put_failure:
  11367. genlmsg_cancel(msg, hdr);
  11368. nlmsg_free(msg);
  11369. }
  11370. EXPORT_SYMBOL(cfg80211_conn_failed);
  11371. static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
  11372. const u8 *addr, gfp_t gfp)
  11373. {
  11374. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11375. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11376. struct sk_buff *msg;
  11377. void *hdr;
  11378. u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
  11379. if (!nlportid)
  11380. return false;
  11381. msg = nlmsg_new(100, gfp);
  11382. if (!msg)
  11383. return true;
  11384. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  11385. if (!hdr) {
  11386. nlmsg_free(msg);
  11387. return true;
  11388. }
  11389. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11390. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11391. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  11392. goto nla_put_failure;
  11393. genlmsg_end(msg, hdr);
  11394. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  11395. return true;
  11396. nla_put_failure:
  11397. genlmsg_cancel(msg, hdr);
  11398. nlmsg_free(msg);
  11399. return true;
  11400. }
  11401. bool cfg80211_rx_spurious_frame(struct net_device *dev,
  11402. const u8 *addr, gfp_t gfp)
  11403. {
  11404. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11405. bool ret;
  11406. trace_cfg80211_rx_spurious_frame(dev, addr);
  11407. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  11408. wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
  11409. trace_cfg80211_return_bool(false);
  11410. return false;
  11411. }
  11412. ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
  11413. addr, gfp);
  11414. trace_cfg80211_return_bool(ret);
  11415. return ret;
  11416. }
  11417. EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
  11418. bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
  11419. const u8 *addr, gfp_t gfp)
  11420. {
  11421. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11422. bool ret;
  11423. trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
  11424. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  11425. wdev->iftype != NL80211_IFTYPE_P2P_GO &&
  11426. wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
  11427. trace_cfg80211_return_bool(false);
  11428. return false;
  11429. }
  11430. ret = __nl80211_unexpected_frame(dev,
  11431. NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
  11432. addr, gfp);
  11433. trace_cfg80211_return_bool(ret);
  11434. return ret;
  11435. }
  11436. EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
  11437. int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
  11438. struct wireless_dev *wdev, u32 nlportid,
  11439. int freq, int sig_dbm,
  11440. const u8 *buf, size_t len, u32 flags, gfp_t gfp)
  11441. {
  11442. struct net_device *netdev = wdev->netdev;
  11443. struct sk_buff *msg;
  11444. void *hdr;
  11445. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11446. if (!msg)
  11447. return -ENOMEM;
  11448. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  11449. if (!hdr) {
  11450. nlmsg_free(msg);
  11451. return -ENOMEM;
  11452. }
  11453. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11454. (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11455. netdev->ifindex)) ||
  11456. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11457. NL80211_ATTR_PAD) ||
  11458. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
  11459. (sig_dbm &&
  11460. nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
  11461. nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
  11462. (flags &&
  11463. nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
  11464. goto nla_put_failure;
  11465. genlmsg_end(msg, hdr);
  11466. return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  11467. nla_put_failure:
  11468. genlmsg_cancel(msg, hdr);
  11469. nlmsg_free(msg);
  11470. return -ENOBUFS;
  11471. }
  11472. void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
  11473. const u8 *buf, size_t len, bool ack, gfp_t gfp)
  11474. {
  11475. struct wiphy *wiphy = wdev->wiphy;
  11476. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11477. struct net_device *netdev = wdev->netdev;
  11478. struct sk_buff *msg;
  11479. void *hdr;
  11480. trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
  11481. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11482. if (!msg)
  11483. return;
  11484. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
  11485. if (!hdr) {
  11486. nlmsg_free(msg);
  11487. return;
  11488. }
  11489. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11490. (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11491. netdev->ifindex)) ||
  11492. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11493. NL80211_ATTR_PAD) ||
  11494. nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
  11495. nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  11496. NL80211_ATTR_PAD) ||
  11497. (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
  11498. goto nla_put_failure;
  11499. genlmsg_end(msg, hdr);
  11500. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11501. NL80211_MCGRP_MLME, gfp);
  11502. return;
  11503. nla_put_failure:
  11504. genlmsg_cancel(msg, hdr);
  11505. nlmsg_free(msg);
  11506. }
  11507. EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
  11508. static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
  11509. const char *mac, gfp_t gfp)
  11510. {
  11511. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11512. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11513. struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11514. void **cb;
  11515. if (!msg)
  11516. return NULL;
  11517. cb = (void **)msg->cb;
  11518. cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
  11519. if (!cb[0]) {
  11520. nlmsg_free(msg);
  11521. return NULL;
  11522. }
  11523. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11524. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
  11525. goto nla_put_failure;
  11526. if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
  11527. goto nla_put_failure;
  11528. cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
  11529. if (!cb[1])
  11530. goto nla_put_failure;
  11531. cb[2] = rdev;
  11532. return msg;
  11533. nla_put_failure:
  11534. nlmsg_free(msg);
  11535. return NULL;
  11536. }
  11537. static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
  11538. {
  11539. void **cb = (void **)msg->cb;
  11540. struct cfg80211_registered_device *rdev = cb[2];
  11541. nla_nest_end(msg, cb[1]);
  11542. genlmsg_end(msg, cb[0]);
  11543. memset(msg->cb, 0, sizeof(msg->cb));
  11544. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11545. NL80211_MCGRP_MLME, gfp);
  11546. }
  11547. void cfg80211_cqm_rssi_notify(struct net_device *dev,
  11548. enum nl80211_cqm_rssi_threshold_event rssi_event,
  11549. gfp_t gfp)
  11550. {
  11551. struct sk_buff *msg;
  11552. trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
  11553. if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
  11554. rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
  11555. return;
  11556. msg = cfg80211_prepare_cqm(dev, NULL, gfp);
  11557. if (!msg)
  11558. return;
  11559. if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
  11560. rssi_event))
  11561. goto nla_put_failure;
  11562. cfg80211_send_cqm(msg, gfp);
  11563. return;
  11564. nla_put_failure:
  11565. nlmsg_free(msg);
  11566. }
  11567. EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
  11568. void cfg80211_cqm_txe_notify(struct net_device *dev,
  11569. const u8 *peer, u32 num_packets,
  11570. u32 rate, u32 intvl, gfp_t gfp)
  11571. {
  11572. struct sk_buff *msg;
  11573. msg = cfg80211_prepare_cqm(dev, peer, gfp);
  11574. if (!msg)
  11575. return;
  11576. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
  11577. goto nla_put_failure;
  11578. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
  11579. goto nla_put_failure;
  11580. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
  11581. goto nla_put_failure;
  11582. cfg80211_send_cqm(msg, gfp);
  11583. return;
  11584. nla_put_failure:
  11585. nlmsg_free(msg);
  11586. }
  11587. EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
  11588. void cfg80211_cqm_pktloss_notify(struct net_device *dev,
  11589. const u8 *peer, u32 num_packets, gfp_t gfp)
  11590. {
  11591. struct sk_buff *msg;
  11592. trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
  11593. msg = cfg80211_prepare_cqm(dev, peer, gfp);
  11594. if (!msg)
  11595. return;
  11596. if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
  11597. goto nla_put_failure;
  11598. cfg80211_send_cqm(msg, gfp);
  11599. return;
  11600. nla_put_failure:
  11601. nlmsg_free(msg);
  11602. }
  11603. EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
  11604. void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
  11605. {
  11606. struct sk_buff *msg;
  11607. msg = cfg80211_prepare_cqm(dev, NULL, gfp);
  11608. if (!msg)
  11609. return;
  11610. if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
  11611. goto nla_put_failure;
  11612. cfg80211_send_cqm(msg, gfp);
  11613. return;
  11614. nla_put_failure:
  11615. nlmsg_free(msg);
  11616. }
  11617. EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
  11618. static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
  11619. struct net_device *netdev, const u8 *bssid,
  11620. const u8 *replay_ctr, gfp_t gfp)
  11621. {
  11622. struct sk_buff *msg;
  11623. struct nlattr *rekey_attr;
  11624. void *hdr;
  11625. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11626. if (!msg)
  11627. return;
  11628. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
  11629. if (!hdr) {
  11630. nlmsg_free(msg);
  11631. return;
  11632. }
  11633. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11634. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11635. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
  11636. goto nla_put_failure;
  11637. rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
  11638. if (!rekey_attr)
  11639. goto nla_put_failure;
  11640. if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
  11641. NL80211_REPLAY_CTR_LEN, replay_ctr))
  11642. goto nla_put_failure;
  11643. nla_nest_end(msg, rekey_attr);
  11644. genlmsg_end(msg, hdr);
  11645. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11646. NL80211_MCGRP_MLME, gfp);
  11647. return;
  11648. nla_put_failure:
  11649. genlmsg_cancel(msg, hdr);
  11650. nlmsg_free(msg);
  11651. }
  11652. void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
  11653. const u8 *replay_ctr, gfp_t gfp)
  11654. {
  11655. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11656. struct wiphy *wiphy = wdev->wiphy;
  11657. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11658. trace_cfg80211_gtk_rekey_notify(dev, bssid);
  11659. nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
  11660. }
  11661. EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
  11662. static void
  11663. nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
  11664. struct net_device *netdev, int index,
  11665. const u8 *bssid, bool preauth, gfp_t gfp)
  11666. {
  11667. struct sk_buff *msg;
  11668. struct nlattr *attr;
  11669. void *hdr;
  11670. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11671. if (!msg)
  11672. return;
  11673. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
  11674. if (!hdr) {
  11675. nlmsg_free(msg);
  11676. return;
  11677. }
  11678. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11679. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  11680. goto nla_put_failure;
  11681. attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
  11682. if (!attr)
  11683. goto nla_put_failure;
  11684. if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
  11685. nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
  11686. (preauth &&
  11687. nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
  11688. goto nla_put_failure;
  11689. nla_nest_end(msg, attr);
  11690. genlmsg_end(msg, hdr);
  11691. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11692. NL80211_MCGRP_MLME, gfp);
  11693. return;
  11694. nla_put_failure:
  11695. genlmsg_cancel(msg, hdr);
  11696. nlmsg_free(msg);
  11697. }
  11698. void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
  11699. const u8 *bssid, bool preauth, gfp_t gfp)
  11700. {
  11701. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11702. struct wiphy *wiphy = wdev->wiphy;
  11703. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11704. trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
  11705. nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
  11706. }
  11707. EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
  11708. static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
  11709. struct net_device *netdev,
  11710. struct cfg80211_chan_def *chandef,
  11711. gfp_t gfp,
  11712. enum nl80211_commands notif,
  11713. u8 count)
  11714. {
  11715. struct sk_buff *msg;
  11716. void *hdr;
  11717. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11718. if (!msg)
  11719. return;
  11720. hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
  11721. if (!hdr) {
  11722. nlmsg_free(msg);
  11723. return;
  11724. }
  11725. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  11726. goto nla_put_failure;
  11727. if (nl80211_send_chandef(msg, chandef))
  11728. goto nla_put_failure;
  11729. if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
  11730. (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
  11731. goto nla_put_failure;
  11732. genlmsg_end(msg, hdr);
  11733. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11734. NL80211_MCGRP_MLME, gfp);
  11735. return;
  11736. nla_put_failure:
  11737. genlmsg_cancel(msg, hdr);
  11738. nlmsg_free(msg);
  11739. }
  11740. void cfg80211_ch_switch_notify(struct net_device *dev,
  11741. struct cfg80211_chan_def *chandef)
  11742. {
  11743. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11744. struct wiphy *wiphy = wdev->wiphy;
  11745. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11746. ASSERT_WDEV_LOCK(wdev);
  11747. trace_cfg80211_ch_switch_notify(dev, chandef);
  11748. wdev->chandef = *chandef;
  11749. wdev->preset_chandef = *chandef;
  11750. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
  11751. NL80211_CMD_CH_SWITCH_NOTIFY, 0);
  11752. }
  11753. EXPORT_SYMBOL(cfg80211_ch_switch_notify);
  11754. void cfg80211_ch_switch_started_notify(struct net_device *dev,
  11755. struct cfg80211_chan_def *chandef,
  11756. u8 count)
  11757. {
  11758. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11759. struct wiphy *wiphy = wdev->wiphy;
  11760. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11761. trace_cfg80211_ch_switch_started_notify(dev, chandef);
  11762. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
  11763. NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
  11764. }
  11765. EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
  11766. void
  11767. nl80211_radar_notify(struct cfg80211_registered_device *rdev,
  11768. const struct cfg80211_chan_def *chandef,
  11769. enum nl80211_radar_event event,
  11770. struct net_device *netdev, gfp_t gfp)
  11771. {
  11772. struct sk_buff *msg;
  11773. void *hdr;
  11774. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11775. if (!msg)
  11776. return;
  11777. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
  11778. if (!hdr) {
  11779. nlmsg_free(msg);
  11780. return;
  11781. }
  11782. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  11783. goto nla_put_failure;
  11784. /* NOP and radar events don't need a netdev parameter */
  11785. if (netdev) {
  11786. struct wireless_dev *wdev = netdev->ieee80211_ptr;
  11787. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11788. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11789. NL80211_ATTR_PAD))
  11790. goto nla_put_failure;
  11791. }
  11792. if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
  11793. goto nla_put_failure;
  11794. if (nl80211_send_chandef(msg, chandef))
  11795. goto nla_put_failure;
  11796. genlmsg_end(msg, hdr);
  11797. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11798. NL80211_MCGRP_MLME, gfp);
  11799. return;
  11800. nla_put_failure:
  11801. genlmsg_cancel(msg, hdr);
  11802. nlmsg_free(msg);
  11803. }
  11804. void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  11805. u64 cookie, bool acked, gfp_t gfp)
  11806. {
  11807. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11808. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11809. struct sk_buff *msg;
  11810. void *hdr;
  11811. trace_cfg80211_probe_status(dev, addr, cookie, acked);
  11812. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11813. if (!msg)
  11814. return;
  11815. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
  11816. if (!hdr) {
  11817. nlmsg_free(msg);
  11818. return;
  11819. }
  11820. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11821. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11822. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  11823. nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  11824. NL80211_ATTR_PAD) ||
  11825. (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
  11826. goto nla_put_failure;
  11827. genlmsg_end(msg, hdr);
  11828. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11829. NL80211_MCGRP_MLME, gfp);
  11830. return;
  11831. nla_put_failure:
  11832. genlmsg_cancel(msg, hdr);
  11833. nlmsg_free(msg);
  11834. }
  11835. EXPORT_SYMBOL(cfg80211_probe_status);
  11836. void cfg80211_report_obss_beacon(struct wiphy *wiphy,
  11837. const u8 *frame, size_t len,
  11838. int freq, int sig_dbm)
  11839. {
  11840. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11841. struct sk_buff *msg;
  11842. void *hdr;
  11843. struct cfg80211_beacon_registration *reg;
  11844. trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
  11845. spin_lock_bh(&rdev->beacon_registrations_lock);
  11846. list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  11847. msg = nlmsg_new(len + 100, GFP_ATOMIC);
  11848. if (!msg) {
  11849. spin_unlock_bh(&rdev->beacon_registrations_lock);
  11850. return;
  11851. }
  11852. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  11853. if (!hdr)
  11854. goto nla_put_failure;
  11855. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11856. (freq &&
  11857. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
  11858. (sig_dbm &&
  11859. nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
  11860. nla_put(msg, NL80211_ATTR_FRAME, len, frame))
  11861. goto nla_put_failure;
  11862. genlmsg_end(msg, hdr);
  11863. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
  11864. }
  11865. spin_unlock_bh(&rdev->beacon_registrations_lock);
  11866. return;
  11867. nla_put_failure:
  11868. spin_unlock_bh(&rdev->beacon_registrations_lock);
  11869. if (hdr)
  11870. genlmsg_cancel(msg, hdr);
  11871. nlmsg_free(msg);
  11872. }
  11873. EXPORT_SYMBOL(cfg80211_report_obss_beacon);
  11874. #ifdef CONFIG_PM
  11875. static int cfg80211_net_detect_results(struct sk_buff *msg,
  11876. struct cfg80211_wowlan_wakeup *wakeup)
  11877. {
  11878. struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
  11879. struct nlattr *nl_results, *nl_match, *nl_freqs;
  11880. int i, j;
  11881. nl_results = nla_nest_start(
  11882. msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
  11883. if (!nl_results)
  11884. return -EMSGSIZE;
  11885. for (i = 0; i < nd->n_matches; i++) {
  11886. struct cfg80211_wowlan_nd_match *match = nd->matches[i];
  11887. nl_match = nla_nest_start(msg, i);
  11888. if (!nl_match)
  11889. break;
  11890. /* The SSID attribute is optional in nl80211, but for
  11891. * simplicity reasons it's always present in the
  11892. * cfg80211 structure. If a driver can't pass the
  11893. * SSID, that needs to be changed. A zero length SSID
  11894. * is still a valid SSID (wildcard), so it cannot be
  11895. * used for this purpose.
  11896. */
  11897. if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
  11898. match->ssid.ssid)) {
  11899. nla_nest_cancel(msg, nl_match);
  11900. goto out;
  11901. }
  11902. if (match->n_channels) {
  11903. nl_freqs = nla_nest_start(
  11904. msg, NL80211_ATTR_SCAN_FREQUENCIES);
  11905. if (!nl_freqs) {
  11906. nla_nest_cancel(msg, nl_match);
  11907. goto out;
  11908. }
  11909. for (j = 0; j < match->n_channels; j++) {
  11910. if (nla_put_u32(msg, j, match->channels[j])) {
  11911. nla_nest_cancel(msg, nl_freqs);
  11912. nla_nest_cancel(msg, nl_match);
  11913. goto out;
  11914. }
  11915. }
  11916. nla_nest_end(msg, nl_freqs);
  11917. }
  11918. nla_nest_end(msg, nl_match);
  11919. }
  11920. out:
  11921. nla_nest_end(msg, nl_results);
  11922. return 0;
  11923. }
  11924. void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
  11925. struct cfg80211_wowlan_wakeup *wakeup,
  11926. gfp_t gfp)
  11927. {
  11928. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11929. struct sk_buff *msg;
  11930. void *hdr;
  11931. int size = 200;
  11932. trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
  11933. if (wakeup)
  11934. size += wakeup->packet_present_len;
  11935. msg = nlmsg_new(size, gfp);
  11936. if (!msg)
  11937. return;
  11938. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
  11939. if (!hdr)
  11940. goto free_msg;
  11941. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11942. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11943. NL80211_ATTR_PAD))
  11944. goto free_msg;
  11945. if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11946. wdev->netdev->ifindex))
  11947. goto free_msg;
  11948. if (wakeup) {
  11949. struct nlattr *reasons;
  11950. reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  11951. if (!reasons)
  11952. goto free_msg;
  11953. if (wakeup->disconnect &&
  11954. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
  11955. goto free_msg;
  11956. if (wakeup->magic_pkt &&
  11957. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
  11958. goto free_msg;
  11959. if (wakeup->gtk_rekey_failure &&
  11960. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
  11961. goto free_msg;
  11962. if (wakeup->eap_identity_req &&
  11963. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
  11964. goto free_msg;
  11965. if (wakeup->four_way_handshake &&
  11966. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
  11967. goto free_msg;
  11968. if (wakeup->rfkill_release &&
  11969. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
  11970. goto free_msg;
  11971. if (wakeup->pattern_idx >= 0 &&
  11972. nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  11973. wakeup->pattern_idx))
  11974. goto free_msg;
  11975. if (wakeup->tcp_match &&
  11976. nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
  11977. goto free_msg;
  11978. if (wakeup->tcp_connlost &&
  11979. nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
  11980. goto free_msg;
  11981. if (wakeup->tcp_nomoretokens &&
  11982. nla_put_flag(msg,
  11983. NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
  11984. goto free_msg;
  11985. if (wakeup->packet) {
  11986. u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
  11987. u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
  11988. if (!wakeup->packet_80211) {
  11989. pkt_attr =
  11990. NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
  11991. len_attr =
  11992. NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
  11993. }
  11994. if (wakeup->packet_len &&
  11995. nla_put_u32(msg, len_attr, wakeup->packet_len))
  11996. goto free_msg;
  11997. if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
  11998. wakeup->packet))
  11999. goto free_msg;
  12000. }
  12001. if (wakeup->net_detect &&
  12002. cfg80211_net_detect_results(msg, wakeup))
  12003. goto free_msg;
  12004. nla_nest_end(msg, reasons);
  12005. }
  12006. genlmsg_end(msg, hdr);
  12007. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12008. NL80211_MCGRP_MLME, gfp);
  12009. return;
  12010. free_msg:
  12011. nlmsg_free(msg);
  12012. }
  12013. EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
  12014. #endif
  12015. void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
  12016. enum nl80211_tdls_operation oper,
  12017. u16 reason_code, gfp_t gfp)
  12018. {
  12019. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12020. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  12021. struct sk_buff *msg;
  12022. void *hdr;
  12023. trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
  12024. reason_code);
  12025. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12026. if (!msg)
  12027. return;
  12028. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
  12029. if (!hdr) {
  12030. nlmsg_free(msg);
  12031. return;
  12032. }
  12033. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12034. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  12035. nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
  12036. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
  12037. (reason_code > 0 &&
  12038. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
  12039. goto nla_put_failure;
  12040. genlmsg_end(msg, hdr);
  12041. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12042. NL80211_MCGRP_MLME, gfp);
  12043. return;
  12044. nla_put_failure:
  12045. genlmsg_cancel(msg, hdr);
  12046. nlmsg_free(msg);
  12047. }
  12048. EXPORT_SYMBOL(cfg80211_tdls_oper_request);
  12049. static int nl80211_netlink_notify(struct notifier_block * nb,
  12050. unsigned long state,
  12051. void *_notify)
  12052. {
  12053. struct netlink_notify *notify = _notify;
  12054. struct cfg80211_registered_device *rdev;
  12055. struct wireless_dev *wdev;
  12056. struct cfg80211_beacon_registration *reg, *tmp;
  12057. if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
  12058. return NOTIFY_DONE;
  12059. rcu_read_lock();
  12060. list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
  12061. bool schedule_destroy_work = false;
  12062. struct cfg80211_sched_scan_request *sched_scan_req =
  12063. rcu_dereference(rdev->sched_scan_req);
  12064. if (sched_scan_req && notify->portid &&
  12065. sched_scan_req->owner_nlportid == notify->portid) {
  12066. sched_scan_req->owner_nlportid = 0;
  12067. if (rdev->ops->sched_scan_stop &&
  12068. rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  12069. schedule_work(&rdev->sched_scan_stop_wk);
  12070. }
  12071. list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
  12072. cfg80211_mlme_unregister_socket(wdev, notify->portid);
  12073. if (wdev->owner_nlportid == notify->portid)
  12074. schedule_destroy_work = true;
  12075. }
  12076. spin_lock_bh(&rdev->beacon_registrations_lock);
  12077. list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
  12078. list) {
  12079. if (reg->nlportid == notify->portid) {
  12080. list_del(&reg->list);
  12081. kfree(reg);
  12082. break;
  12083. }
  12084. }
  12085. spin_unlock_bh(&rdev->beacon_registrations_lock);
  12086. if (schedule_destroy_work) {
  12087. struct cfg80211_iface_destroy *destroy;
  12088. destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
  12089. if (destroy) {
  12090. destroy->nlportid = notify->portid;
  12091. spin_lock(&rdev->destroy_list_lock);
  12092. list_add(&destroy->list, &rdev->destroy_list);
  12093. spin_unlock(&rdev->destroy_list_lock);
  12094. schedule_work(&rdev->destroy_work);
  12095. }
  12096. }
  12097. }
  12098. rcu_read_unlock();
  12099. /*
  12100. * It is possible that the user space process that is controlling the
  12101. * indoor setting disappeared, so notify the regulatory core.
  12102. */
  12103. regulatory_netlink_notify(notify->portid);
  12104. return NOTIFY_OK;
  12105. }
  12106. static struct notifier_block nl80211_netlink_notifier = {
  12107. .notifier_call = nl80211_netlink_notify,
  12108. };
  12109. void cfg80211_ft_event(struct net_device *netdev,
  12110. struct cfg80211_ft_event_params *ft_event)
  12111. {
  12112. struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
  12113. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12114. struct sk_buff *msg;
  12115. void *hdr;
  12116. trace_cfg80211_ft_event(wiphy, netdev, ft_event);
  12117. if (!ft_event->target_ap)
  12118. return;
  12119. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  12120. if (!msg)
  12121. return;
  12122. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
  12123. if (!hdr)
  12124. goto out;
  12125. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12126. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  12127. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
  12128. goto out;
  12129. if (ft_event->ies &&
  12130. nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
  12131. goto out;
  12132. if (ft_event->ric_ies &&
  12133. nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
  12134. ft_event->ric_ies))
  12135. goto out;
  12136. genlmsg_end(msg, hdr);
  12137. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12138. NL80211_MCGRP_MLME, GFP_KERNEL);
  12139. return;
  12140. out:
  12141. nlmsg_free(msg);
  12142. }
  12143. EXPORT_SYMBOL(cfg80211_ft_event);
  12144. void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
  12145. {
  12146. struct cfg80211_registered_device *rdev;
  12147. struct sk_buff *msg;
  12148. void *hdr;
  12149. u32 nlportid;
  12150. rdev = wiphy_to_rdev(wdev->wiphy);
  12151. if (!rdev->crit_proto_nlportid)
  12152. return;
  12153. nlportid = rdev->crit_proto_nlportid;
  12154. rdev->crit_proto_nlportid = 0;
  12155. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12156. if (!msg)
  12157. return;
  12158. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
  12159. if (!hdr)
  12160. goto nla_put_failure;
  12161. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12162. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  12163. NL80211_ATTR_PAD))
  12164. goto nla_put_failure;
  12165. genlmsg_end(msg, hdr);
  12166. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  12167. return;
  12168. nla_put_failure:
  12169. if (hdr)
  12170. genlmsg_cancel(msg, hdr);
  12171. nlmsg_free(msg);
  12172. }
  12173. EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
  12174. void nl80211_send_ap_stopped(struct wireless_dev *wdev)
  12175. {
  12176. struct wiphy *wiphy = wdev->wiphy;
  12177. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12178. struct sk_buff *msg;
  12179. void *hdr;
  12180. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  12181. if (!msg)
  12182. return;
  12183. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
  12184. if (!hdr)
  12185. goto out;
  12186. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12187. nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
  12188. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  12189. NL80211_ATTR_PAD))
  12190. goto out;
  12191. genlmsg_end(msg, hdr);
  12192. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
  12193. NL80211_MCGRP_MLME, GFP_KERNEL);
  12194. return;
  12195. out:
  12196. nlmsg_free(msg);
  12197. }
  12198. /* initialisation/exit functions */
  12199. int nl80211_init(void)
  12200. {
  12201. int err;
  12202. err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
  12203. nl80211_mcgrps);
  12204. if (err)
  12205. return err;
  12206. err = netlink_register_notifier(&nl80211_netlink_notifier);
  12207. if (err)
  12208. goto err_out;
  12209. return 0;
  12210. err_out:
  12211. genl_unregister_family(&nl80211_fam);
  12212. return err;
  12213. }
  12214. void nl80211_exit(void)
  12215. {
  12216. netlink_unregister_notifier(&nl80211_netlink_notifier);
  12217. genl_unregister_family(&nl80211_fam);
  12218. }