nl80211.c 398 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089
  1. /*
  2. * This is the new netlink-based wireless configuration interface.
  3. *
  4. * Copyright 2006-2010 Johannes Berg <[email protected]>
  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. static int validate_beacon_head(const struct nlattr *attr)
  183. {
  184. const u8 *data = nla_data(attr);
  185. unsigned int len = nla_len(attr);
  186. const struct element *elem;
  187. const struct ieee80211_mgmt *mgmt = (void *)data;
  188. unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
  189. u.beacon.variable);
  190. if (len < fixedlen)
  191. goto err;
  192. if (ieee80211_hdrlen(mgmt->frame_control) !=
  193. offsetof(struct ieee80211_mgmt, u.beacon))
  194. goto err;
  195. data += fixedlen;
  196. len -= fixedlen;
  197. for_each_element(elem, data, len) {
  198. /* nothing */
  199. }
  200. if (for_each_element_completed(elem, data, len))
  201. return 0;
  202. err:
  203. return -EINVAL;
  204. }
  205. /* policy for the attributes */
  206. static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
  207. [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
  208. [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
  209. .len = 20-1 },
  210. [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
  211. [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
  212. [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
  213. [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
  214. [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
  215. [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
  216. [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
  217. [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
  218. [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
  219. [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
  220. [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
  221. [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
  222. [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
  223. [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
  224. [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
  225. [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
  226. [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
  227. [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
  228. [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
  229. .len = WLAN_MAX_KEY_LEN },
  230. [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
  231. [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
  232. [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
  233. [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  234. [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
  235. [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
  236. [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
  237. [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
  238. .len = IEEE80211_MAX_DATA_LEN },
  239. [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
  240. .len = IEEE80211_MAX_DATA_LEN },
  241. [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
  242. [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
  243. [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
  244. [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
  245. .len = NL80211_MAX_SUPP_RATES },
  246. [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
  247. [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
  248. [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
  249. [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
  250. .len = IEEE80211_MAX_MESH_ID_LEN },
  251. [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_BINARY,
  252. .len = ETH_ALEN },
  253. [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
  254. [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
  255. [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
  256. [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
  257. [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
  258. [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
  259. .len = NL80211_MAX_SUPP_RATES },
  260. [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
  261. [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
  262. [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
  263. [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
  264. [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
  265. [NL80211_ATTR_IE] = { .type = NLA_BINARY,
  266. .len = IEEE80211_MAX_DATA_LEN },
  267. [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
  268. [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
  269. [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
  270. .len = IEEE80211_MAX_SSID_LEN },
  271. [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
  272. [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
  273. [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
  274. [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
  275. [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
  276. [NL80211_ATTR_STA_FLAGS2] = {
  277. .len = sizeof(struct nl80211_sta_flag_update),
  278. },
  279. [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
  280. [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
  281. [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
  282. [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
  283. [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
  284. [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
  285. [NL80211_ATTR_PID] = { .type = NLA_U32 },
  286. [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
  287. [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN },
  288. [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
  289. [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
  290. [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
  291. [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
  292. .len = IEEE80211_MAX_DATA_LEN },
  293. [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
  294. [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
  295. [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
  296. [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
  297. [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
  298. [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
  299. [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
  300. [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
  301. [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
  302. [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
  303. [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
  304. [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
  305. [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  306. [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
  307. [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
  308. [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
  309. [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
  310. [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
  311. [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
  312. [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
  313. .len = IEEE80211_MAX_DATA_LEN },
  314. [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
  315. .len = IEEE80211_MAX_DATA_LEN },
  316. [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
  317. [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
  318. [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
  319. [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
  320. [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
  321. [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
  322. [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
  323. [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
  324. [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
  325. [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
  326. [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
  327. .len = IEEE80211_MAX_DATA_LEN },
  328. [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
  329. [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
  330. [NL80211_ATTR_HT_CAPABILITY_MASK] = {
  331. .len = NL80211_HT_CAPABILITY_LEN
  332. },
  333. [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
  334. [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
  335. [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
  336. [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
  337. [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
  338. [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
  339. [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
  340. [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
  341. [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
  342. [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
  343. [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 },
  344. [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
  345. [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
  346. [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
  347. [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
  348. [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
  349. [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
  350. [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
  351. .len = NL80211_VHT_CAPABILITY_LEN,
  352. },
  353. [NL80211_ATTR_MDID] = { .type = NLA_U16 },
  354. [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
  355. .len = IEEE80211_MAX_DATA_LEN },
  356. [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
  357. [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
  358. [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
  359. [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
  360. [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
  361. [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
  362. [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
  363. [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
  364. [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
  365. [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
  366. [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
  367. [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
  368. [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
  369. [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
  370. .len = IEEE80211_QOS_MAP_LEN_MAX },
  371. [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
  372. [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
  373. [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
  374. [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
  375. [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
  376. [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
  377. [NL80211_ATTR_TSID] = { .type = NLA_U8 },
  378. [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
  379. [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
  380. [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
  381. [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
  382. [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
  383. [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
  384. [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
  385. [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
  386. [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
  387. [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
  388. [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 },
  389. [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
  390. .len = VHT_MUMIMO_GROUPS_DATA_LEN
  391. },
  392. [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN },
  393. [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 },
  394. [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 },
  395. [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
  396. [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
  397. .len = FILS_MAX_KEK_LEN },
  398. [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN },
  399. [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
  400. [NL80211_ATTR_BSSID] = { .len = ETH_ALEN },
  401. [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
  402. [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
  403. .len = sizeof(struct nl80211_bss_select_rssi_adjust)
  404. },
  405. [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
  406. [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
  407. .len = FILS_ERP_MAX_USERNAME_LEN },
  408. [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
  409. .len = FILS_ERP_MAX_REALM_LEN },
  410. [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
  411. [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
  412. .len = FILS_ERP_MAX_RRK_LEN },
  413. [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 },
  414. [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
  415. [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
  416. };
  417. /* policy for the key attributes */
  418. static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
  419. [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
  420. [NL80211_KEY_IDX] = { .type = NLA_U8 },
  421. [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
  422. [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
  423. [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
  424. [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
  425. [NL80211_KEY_TYPE] = { .type = NLA_U32 },
  426. [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
  427. };
  428. /* policy for the key default flags */
  429. static const struct nla_policy
  430. nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
  431. [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
  432. [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
  433. };
  434. /* policy for WoWLAN attributes */
  435. static const struct nla_policy
  436. nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
  437. [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
  438. [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
  439. [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
  440. [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
  441. [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
  442. [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
  443. [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
  444. [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
  445. [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
  446. [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
  447. };
  448. static const struct nla_policy
  449. nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
  450. [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
  451. [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
  452. [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
  453. [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
  454. [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
  455. [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
  456. [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
  457. .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
  458. },
  459. [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
  460. .len = sizeof(struct nl80211_wowlan_tcp_data_token)
  461. },
  462. [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
  463. [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
  464. [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
  465. };
  466. /* policy for coalesce rule attributes */
  467. static const struct nla_policy
  468. nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
  469. [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
  470. [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
  471. [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
  472. };
  473. /* policy for GTK rekey offload attributes */
  474. static const struct nla_policy
  475. nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
  476. [NL80211_REKEY_DATA_KEK] = { .type = NLA_BINARY,
  477. .len = FILS_MAX_KEK_LEN },
  478. [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
  479. [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
  480. };
  481. static const struct nla_policy
  482. nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
  483. [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
  484. .len = IEEE80211_MAX_SSID_LEN },
  485. [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
  486. };
  487. static const struct nla_policy
  488. nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
  489. [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
  490. [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
  491. };
  492. static const struct nla_policy
  493. nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
  494. [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
  495. [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
  496. [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
  497. .len = sizeof(struct nl80211_bss_select_rssi_adjust)
  498. },
  499. };
  500. /* policy for NAN function attributes */
  501. static const struct nla_policy
  502. nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
  503. [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
  504. [NL80211_NAN_FUNC_SERVICE_ID] = {
  505. .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
  506. [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
  507. [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
  508. [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
  509. [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
  510. [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
  511. [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN },
  512. [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
  513. [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
  514. [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
  515. .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
  516. [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
  517. [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
  518. [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
  519. [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
  520. [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
  521. };
  522. /* policy for Service Response Filter attributes */
  523. static const struct nla_policy
  524. nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
  525. [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
  526. [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
  527. .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
  528. [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
  529. [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
  530. };
  531. /* policy for packet pattern attributes */
  532. static const struct nla_policy
  533. nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
  534. [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
  535. [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
  536. [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
  537. };
  538. static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
  539. struct netlink_callback *cb,
  540. struct cfg80211_registered_device **rdev,
  541. struct wireless_dev **wdev)
  542. {
  543. int err;
  544. if (!cb->args[0]) {
  545. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  546. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  547. nl80211_policy);
  548. if (err)
  549. return err;
  550. *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
  551. nl80211_fam.attrbuf);
  552. if (IS_ERR(*wdev))
  553. return PTR_ERR(*wdev);
  554. *rdev = wiphy_to_rdev((*wdev)->wiphy);
  555. /* 0 is the first index - add 1 to parse only once */
  556. cb->args[0] = (*rdev)->wiphy_idx + 1;
  557. cb->args[1] = (*wdev)->identifier;
  558. } else {
  559. /* subtract the 1 again here */
  560. struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
  561. struct wireless_dev *tmp;
  562. if (!wiphy)
  563. return -ENODEV;
  564. *rdev = wiphy_to_rdev(wiphy);
  565. *wdev = NULL;
  566. list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
  567. if (tmp->identifier == cb->args[1]) {
  568. *wdev = tmp;
  569. break;
  570. }
  571. }
  572. if (!*wdev)
  573. return -ENODEV;
  574. }
  575. return 0;
  576. }
  577. /* IE validation */
  578. static bool is_valid_ie_attr(const struct nlattr *attr)
  579. {
  580. const u8 *pos;
  581. int len;
  582. if (!attr)
  583. return true;
  584. pos = nla_data(attr);
  585. len = nla_len(attr);
  586. while (len) {
  587. u8 elemlen;
  588. if (len < 2)
  589. return false;
  590. len -= 2;
  591. elemlen = pos[1];
  592. if (elemlen > len)
  593. return false;
  594. len -= elemlen;
  595. pos += 2 + elemlen;
  596. }
  597. return true;
  598. }
  599. /* message building helper */
  600. static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
  601. int flags, u8 cmd)
  602. {
  603. /* since there is no private header just add the generic one */
  604. return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
  605. }
  606. static int nl80211_msg_put_channel(struct sk_buff *msg,
  607. struct ieee80211_channel *chan,
  608. bool large)
  609. {
  610. /* Some channels must be completely excluded from the
  611. * list to protect old user-space tools from breaking
  612. */
  613. if (!large && chan->flags &
  614. (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
  615. return 0;
  616. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
  617. chan->center_freq))
  618. goto nla_put_failure;
  619. if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
  620. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
  621. goto nla_put_failure;
  622. if (chan->flags & IEEE80211_CHAN_NO_IR) {
  623. if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
  624. goto nla_put_failure;
  625. if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
  626. goto nla_put_failure;
  627. }
  628. if (chan->flags & IEEE80211_CHAN_RADAR) {
  629. if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
  630. goto nla_put_failure;
  631. if (large) {
  632. u32 time;
  633. time = elapsed_jiffies_msecs(chan->dfs_state_entered);
  634. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
  635. chan->dfs_state))
  636. goto nla_put_failure;
  637. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
  638. time))
  639. goto nla_put_failure;
  640. if (nla_put_u32(msg,
  641. NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
  642. chan->dfs_cac_ms))
  643. goto nla_put_failure;
  644. }
  645. }
  646. if (large) {
  647. if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
  648. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
  649. goto nla_put_failure;
  650. if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
  651. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
  652. goto nla_put_failure;
  653. if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
  654. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
  655. goto nla_put_failure;
  656. if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
  657. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
  658. goto nla_put_failure;
  659. if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
  660. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
  661. goto nla_put_failure;
  662. if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
  663. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
  664. goto nla_put_failure;
  665. if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
  666. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
  667. goto nla_put_failure;
  668. if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
  669. nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
  670. goto nla_put_failure;
  671. }
  672. if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
  673. DBM_TO_MBM(chan->max_power)))
  674. goto nla_put_failure;
  675. return 0;
  676. nla_put_failure:
  677. return -ENOBUFS;
  678. }
  679. /* netlink command implementations */
  680. struct key_parse {
  681. struct key_params p;
  682. int idx;
  683. int type;
  684. bool def, defmgmt;
  685. bool def_uni, def_multi;
  686. };
  687. static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
  688. {
  689. struct nlattr *tb[NL80211_KEY_MAX + 1];
  690. int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
  691. nl80211_key_policy);
  692. if (err)
  693. return err;
  694. k->def = !!tb[NL80211_KEY_DEFAULT];
  695. k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
  696. if (k->def) {
  697. k->def_uni = true;
  698. k->def_multi = true;
  699. }
  700. if (k->defmgmt)
  701. k->def_multi = true;
  702. if (tb[NL80211_KEY_IDX])
  703. k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
  704. if (tb[NL80211_KEY_DATA]) {
  705. k->p.key = nla_data(tb[NL80211_KEY_DATA]);
  706. k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
  707. }
  708. if (tb[NL80211_KEY_SEQ]) {
  709. k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
  710. k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
  711. }
  712. if (tb[NL80211_KEY_CIPHER])
  713. k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
  714. if (tb[NL80211_KEY_TYPE]) {
  715. k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
  716. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  717. return -EINVAL;
  718. }
  719. if (tb[NL80211_KEY_DEFAULT_TYPES]) {
  720. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  721. err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  722. tb[NL80211_KEY_DEFAULT_TYPES],
  723. nl80211_key_default_policy);
  724. if (err)
  725. return err;
  726. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  727. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  728. }
  729. return 0;
  730. }
  731. static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
  732. {
  733. if (info->attrs[NL80211_ATTR_KEY_DATA]) {
  734. k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
  735. k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
  736. }
  737. if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
  738. k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
  739. k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
  740. }
  741. if (info->attrs[NL80211_ATTR_KEY_IDX])
  742. k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  743. if (info->attrs[NL80211_ATTR_KEY_CIPHER])
  744. k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
  745. k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
  746. k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
  747. if (k->def) {
  748. k->def_uni = true;
  749. k->def_multi = true;
  750. }
  751. if (k->defmgmt)
  752. k->def_multi = true;
  753. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  754. k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  755. if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
  756. return -EINVAL;
  757. }
  758. if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
  759. struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
  760. int err = nla_parse_nested(
  761. kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
  762. info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
  763. nl80211_key_default_policy);
  764. if (err)
  765. return err;
  766. k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
  767. k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
  768. }
  769. return 0;
  770. }
  771. static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
  772. {
  773. int err;
  774. memset(k, 0, sizeof(*k));
  775. k->idx = -1;
  776. k->type = -1;
  777. if (info->attrs[NL80211_ATTR_KEY])
  778. err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
  779. else
  780. err = nl80211_parse_key_old(info, k);
  781. if (err)
  782. return err;
  783. if (k->def && k->defmgmt)
  784. return -EINVAL;
  785. if (k->defmgmt) {
  786. if (k->def_uni || !k->def_multi)
  787. return -EINVAL;
  788. }
  789. if (k->idx != -1) {
  790. if (k->defmgmt) {
  791. if (k->idx < 4 || k->idx > 5)
  792. return -EINVAL;
  793. } else if (k->def) {
  794. if (k->idx < 0 || k->idx > 3)
  795. return -EINVAL;
  796. } else {
  797. if (k->idx < 0 || k->idx > 5)
  798. return -EINVAL;
  799. }
  800. }
  801. return 0;
  802. }
  803. static struct cfg80211_cached_keys *
  804. nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
  805. struct nlattr *keys, bool *no_ht)
  806. {
  807. struct key_parse parse;
  808. struct nlattr *key;
  809. struct cfg80211_cached_keys *result;
  810. int rem, err, def = 0;
  811. bool have_key = false;
  812. nla_for_each_nested(key, keys, rem) {
  813. have_key = true;
  814. break;
  815. }
  816. if (!have_key)
  817. return NULL;
  818. result = kzalloc(sizeof(*result), GFP_KERNEL);
  819. if (!result)
  820. return ERR_PTR(-ENOMEM);
  821. result->def = -1;
  822. nla_for_each_nested(key, keys, rem) {
  823. memset(&parse, 0, sizeof(parse));
  824. parse.idx = -1;
  825. err = nl80211_parse_key_new(key, &parse);
  826. if (err)
  827. goto error;
  828. err = -EINVAL;
  829. if (!parse.p.key)
  830. goto error;
  831. if (parse.idx < 0 || parse.idx > 3)
  832. goto error;
  833. if (parse.def) {
  834. if (def)
  835. goto error;
  836. def = 1;
  837. result->def = parse.idx;
  838. if (!parse.def_uni || !parse.def_multi)
  839. goto error;
  840. } else if (parse.defmgmt)
  841. goto error;
  842. err = cfg80211_validate_key_settings(rdev, &parse.p,
  843. parse.idx, false, NULL);
  844. if (err)
  845. goto error;
  846. if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  847. parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
  848. err = -EINVAL;
  849. goto error;
  850. }
  851. result->params[parse.idx].cipher = parse.p.cipher;
  852. result->params[parse.idx].key_len = parse.p.key_len;
  853. result->params[parse.idx].key = result->data[parse.idx];
  854. memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
  855. /* must be WEP key if we got here */
  856. if (no_ht)
  857. *no_ht = true;
  858. }
  859. if (result->def < 0) {
  860. err = -EINVAL;
  861. goto error;
  862. }
  863. return result;
  864. error:
  865. kfree(result);
  866. return ERR_PTR(err);
  867. }
  868. static int nl80211_key_allowed(struct wireless_dev *wdev)
  869. {
  870. ASSERT_WDEV_LOCK(wdev);
  871. switch (wdev->iftype) {
  872. case NL80211_IFTYPE_AP:
  873. case NL80211_IFTYPE_AP_VLAN:
  874. case NL80211_IFTYPE_P2P_GO:
  875. case NL80211_IFTYPE_MESH_POINT:
  876. break;
  877. case NL80211_IFTYPE_ADHOC:
  878. case NL80211_IFTYPE_STATION:
  879. case NL80211_IFTYPE_P2P_CLIENT:
  880. if (!wdev->current_bss)
  881. return -ENOLINK;
  882. break;
  883. case NL80211_IFTYPE_UNSPECIFIED:
  884. case NL80211_IFTYPE_OCB:
  885. case NL80211_IFTYPE_MONITOR:
  886. case NL80211_IFTYPE_NAN:
  887. case NL80211_IFTYPE_P2P_DEVICE:
  888. case NL80211_IFTYPE_WDS:
  889. case NUM_NL80211_IFTYPES:
  890. return -EINVAL;
  891. }
  892. return 0;
  893. }
  894. static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
  895. struct nlattr *tb)
  896. {
  897. struct ieee80211_channel *chan;
  898. if (tb == NULL)
  899. return NULL;
  900. chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
  901. if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
  902. return NULL;
  903. return chan;
  904. }
  905. static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
  906. {
  907. struct nlattr *nl_modes = nla_nest_start(msg, attr);
  908. int i;
  909. if (!nl_modes)
  910. goto nla_put_failure;
  911. i = 0;
  912. while (ifmodes) {
  913. if ((ifmodes & 1) && nla_put_flag(msg, i))
  914. goto nla_put_failure;
  915. ifmodes >>= 1;
  916. i++;
  917. }
  918. nla_nest_end(msg, nl_modes);
  919. return 0;
  920. nla_put_failure:
  921. return -ENOBUFS;
  922. }
  923. static int nl80211_put_iface_combinations(struct wiphy *wiphy,
  924. struct sk_buff *msg,
  925. bool large)
  926. {
  927. struct nlattr *nl_combis;
  928. int i, j;
  929. nl_combis = nla_nest_start(msg,
  930. NL80211_ATTR_INTERFACE_COMBINATIONS);
  931. if (!nl_combis)
  932. goto nla_put_failure;
  933. for (i = 0; i < wiphy->n_iface_combinations; i++) {
  934. const struct ieee80211_iface_combination *c;
  935. struct nlattr *nl_combi, *nl_limits;
  936. c = &wiphy->iface_combinations[i];
  937. nl_combi = nla_nest_start(msg, i + 1);
  938. if (!nl_combi)
  939. goto nla_put_failure;
  940. nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
  941. if (!nl_limits)
  942. goto nla_put_failure;
  943. for (j = 0; j < c->n_limits; j++) {
  944. struct nlattr *nl_limit;
  945. nl_limit = nla_nest_start(msg, j + 1);
  946. if (!nl_limit)
  947. goto nla_put_failure;
  948. if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
  949. c->limits[j].max))
  950. goto nla_put_failure;
  951. if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
  952. c->limits[j].types))
  953. goto nla_put_failure;
  954. nla_nest_end(msg, nl_limit);
  955. }
  956. nla_nest_end(msg, nl_limits);
  957. if (c->beacon_int_infra_match &&
  958. nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
  959. goto nla_put_failure;
  960. if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
  961. c->num_different_channels) ||
  962. nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
  963. c->max_interfaces))
  964. goto nla_put_failure;
  965. if (large &&
  966. (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
  967. c->radar_detect_widths) ||
  968. nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
  969. c->radar_detect_regions)))
  970. goto nla_put_failure;
  971. if (c->beacon_int_min_gcd &&
  972. nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
  973. c->beacon_int_min_gcd))
  974. goto nla_put_failure;
  975. nla_nest_end(msg, nl_combi);
  976. }
  977. nla_nest_end(msg, nl_combis);
  978. return 0;
  979. nla_put_failure:
  980. return -ENOBUFS;
  981. }
  982. #ifdef CONFIG_PM
  983. static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
  984. struct sk_buff *msg)
  985. {
  986. const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
  987. struct nlattr *nl_tcp;
  988. if (!tcp)
  989. return 0;
  990. nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
  991. if (!nl_tcp)
  992. return -ENOBUFS;
  993. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  994. tcp->data_payload_max))
  995. return -ENOBUFS;
  996. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  997. tcp->data_payload_max))
  998. return -ENOBUFS;
  999. if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
  1000. return -ENOBUFS;
  1001. if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  1002. sizeof(*tcp->tok), tcp->tok))
  1003. return -ENOBUFS;
  1004. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
  1005. tcp->data_interval_max))
  1006. return -ENOBUFS;
  1007. if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  1008. tcp->wake_payload_max))
  1009. return -ENOBUFS;
  1010. nla_nest_end(msg, nl_tcp);
  1011. return 0;
  1012. }
  1013. static int nl80211_send_wowlan(struct sk_buff *msg,
  1014. struct cfg80211_registered_device *rdev,
  1015. bool large)
  1016. {
  1017. struct nlattr *nl_wowlan;
  1018. if (!rdev->wiphy.wowlan)
  1019. return 0;
  1020. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
  1021. if (!nl_wowlan)
  1022. return -ENOBUFS;
  1023. if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
  1024. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  1025. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
  1026. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  1027. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
  1028. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  1029. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
  1030. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
  1031. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
  1032. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  1033. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
  1034. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  1035. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
  1036. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  1037. ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
  1038. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
  1039. return -ENOBUFS;
  1040. if (rdev->wiphy.wowlan->n_patterns) {
  1041. struct nl80211_pattern_support pat = {
  1042. .max_patterns = rdev->wiphy.wowlan->n_patterns,
  1043. .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
  1044. .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
  1045. .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
  1046. };
  1047. if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  1048. sizeof(pat), &pat))
  1049. return -ENOBUFS;
  1050. }
  1051. if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
  1052. nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
  1053. rdev->wiphy.wowlan->max_nd_match_sets))
  1054. return -ENOBUFS;
  1055. if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
  1056. return -ENOBUFS;
  1057. nla_nest_end(msg, nl_wowlan);
  1058. return 0;
  1059. }
  1060. #endif
  1061. static int nl80211_send_coalesce(struct sk_buff *msg,
  1062. struct cfg80211_registered_device *rdev)
  1063. {
  1064. struct nl80211_coalesce_rule_support rule;
  1065. if (!rdev->wiphy.coalesce)
  1066. return 0;
  1067. rule.max_rules = rdev->wiphy.coalesce->n_rules;
  1068. rule.max_delay = rdev->wiphy.coalesce->max_delay;
  1069. rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
  1070. rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
  1071. rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
  1072. rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
  1073. if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
  1074. return -ENOBUFS;
  1075. return 0;
  1076. }
  1077. static int nl80211_send_band_rateinfo(struct sk_buff *msg,
  1078. struct ieee80211_supported_band *sband)
  1079. {
  1080. struct nlattr *nl_rates, *nl_rate;
  1081. struct ieee80211_rate *rate;
  1082. int i;
  1083. /* add HT info */
  1084. if (sband->ht_cap.ht_supported &&
  1085. (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
  1086. sizeof(sband->ht_cap.mcs),
  1087. &sband->ht_cap.mcs) ||
  1088. nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
  1089. sband->ht_cap.cap) ||
  1090. nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
  1091. sband->ht_cap.ampdu_factor) ||
  1092. nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
  1093. sband->ht_cap.ampdu_density)))
  1094. return -ENOBUFS;
  1095. /* add VHT info */
  1096. if (sband->vht_cap.vht_supported &&
  1097. (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
  1098. sizeof(sband->vht_cap.vht_mcs),
  1099. &sband->vht_cap.vht_mcs) ||
  1100. nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
  1101. sband->vht_cap.cap)))
  1102. return -ENOBUFS;
  1103. /* add bitrates */
  1104. nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
  1105. if (!nl_rates)
  1106. return -ENOBUFS;
  1107. for (i = 0; i < sband->n_bitrates; i++) {
  1108. nl_rate = nla_nest_start(msg, i);
  1109. if (!nl_rate)
  1110. return -ENOBUFS;
  1111. rate = &sband->bitrates[i];
  1112. if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
  1113. rate->bitrate))
  1114. return -ENOBUFS;
  1115. if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
  1116. nla_put_flag(msg,
  1117. NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
  1118. return -ENOBUFS;
  1119. nla_nest_end(msg, nl_rate);
  1120. }
  1121. nla_nest_end(msg, nl_rates);
  1122. return 0;
  1123. }
  1124. static int
  1125. nl80211_send_mgmt_stypes(struct sk_buff *msg,
  1126. const struct ieee80211_txrx_stypes *mgmt_stypes)
  1127. {
  1128. u16 stypes;
  1129. struct nlattr *nl_ftypes, *nl_ifs;
  1130. enum nl80211_iftype ift;
  1131. int i;
  1132. if (!mgmt_stypes)
  1133. return 0;
  1134. nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
  1135. if (!nl_ifs)
  1136. return -ENOBUFS;
  1137. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  1138. nl_ftypes = nla_nest_start(msg, ift);
  1139. if (!nl_ftypes)
  1140. return -ENOBUFS;
  1141. i = 0;
  1142. stypes = mgmt_stypes[ift].tx;
  1143. while (stypes) {
  1144. if ((stypes & 1) &&
  1145. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
  1146. (i << 4) | IEEE80211_FTYPE_MGMT))
  1147. return -ENOBUFS;
  1148. stypes >>= 1;
  1149. i++;
  1150. }
  1151. nla_nest_end(msg, nl_ftypes);
  1152. }
  1153. nla_nest_end(msg, nl_ifs);
  1154. nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
  1155. if (!nl_ifs)
  1156. return -ENOBUFS;
  1157. for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
  1158. nl_ftypes = nla_nest_start(msg, ift);
  1159. if (!nl_ftypes)
  1160. return -ENOBUFS;
  1161. i = 0;
  1162. stypes = mgmt_stypes[ift].rx;
  1163. while (stypes) {
  1164. if ((stypes & 1) &&
  1165. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
  1166. (i << 4) | IEEE80211_FTYPE_MGMT))
  1167. return -ENOBUFS;
  1168. stypes >>= 1;
  1169. i++;
  1170. }
  1171. nla_nest_end(msg, nl_ftypes);
  1172. }
  1173. nla_nest_end(msg, nl_ifs);
  1174. return 0;
  1175. }
  1176. struct nl80211_dump_wiphy_state {
  1177. s64 filter_wiphy;
  1178. long start;
  1179. long split_start, band_start, chan_start, capa_start;
  1180. bool split;
  1181. };
  1182. static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
  1183. enum nl80211_commands cmd,
  1184. struct sk_buff *msg, u32 portid, u32 seq,
  1185. int flags, struct nl80211_dump_wiphy_state *state)
  1186. {
  1187. void *hdr;
  1188. struct nlattr *nl_bands, *nl_band;
  1189. struct nlattr *nl_freqs, *nl_freq;
  1190. struct nlattr *nl_cmds;
  1191. enum nl80211_band band;
  1192. struct ieee80211_channel *chan;
  1193. int i;
  1194. const struct ieee80211_txrx_stypes *mgmt_stypes =
  1195. rdev->wiphy.mgmt_stypes;
  1196. u32 features;
  1197. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  1198. if (!hdr)
  1199. return -ENOBUFS;
  1200. if (WARN_ON(!state))
  1201. return -EINVAL;
  1202. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  1203. nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
  1204. wiphy_name(&rdev->wiphy)) ||
  1205. nla_put_u32(msg, NL80211_ATTR_GENERATION,
  1206. cfg80211_rdev_list_generation))
  1207. goto nla_put_failure;
  1208. if (cmd != NL80211_CMD_NEW_WIPHY)
  1209. goto finish;
  1210. switch (state->split_start) {
  1211. case 0:
  1212. if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
  1213. rdev->wiphy.retry_short) ||
  1214. nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
  1215. rdev->wiphy.retry_long) ||
  1216. nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
  1217. rdev->wiphy.frag_threshold) ||
  1218. nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
  1219. rdev->wiphy.rts_threshold) ||
  1220. nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
  1221. rdev->wiphy.coverage_class) ||
  1222. nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
  1223. rdev->wiphy.max_scan_ssids) ||
  1224. nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
  1225. rdev->wiphy.max_sched_scan_ssids) ||
  1226. nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
  1227. rdev->wiphy.max_scan_ie_len) ||
  1228. nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
  1229. rdev->wiphy.max_sched_scan_ie_len) ||
  1230. nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
  1231. rdev->wiphy.max_match_sets) ||
  1232. nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
  1233. rdev->wiphy.max_sched_scan_plans) ||
  1234. nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
  1235. rdev->wiphy.max_sched_scan_plan_interval) ||
  1236. nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
  1237. rdev->wiphy.max_sched_scan_plan_iterations))
  1238. goto nla_put_failure;
  1239. if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
  1240. nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
  1241. goto nla_put_failure;
  1242. if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
  1243. nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
  1244. goto nla_put_failure;
  1245. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
  1246. nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
  1247. goto nla_put_failure;
  1248. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
  1249. nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
  1250. goto nla_put_failure;
  1251. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  1252. nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
  1253. goto nla_put_failure;
  1254. if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
  1255. nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
  1256. goto nla_put_failure;
  1257. state->split_start++;
  1258. if (state->split)
  1259. break;
  1260. case 1:
  1261. if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
  1262. sizeof(u32) * rdev->wiphy.n_cipher_suites,
  1263. rdev->wiphy.cipher_suites))
  1264. goto nla_put_failure;
  1265. if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
  1266. rdev->wiphy.max_num_pmkids))
  1267. goto nla_put_failure;
  1268. if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  1269. nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
  1270. goto nla_put_failure;
  1271. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
  1272. rdev->wiphy.available_antennas_tx) ||
  1273. nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
  1274. rdev->wiphy.available_antennas_rx))
  1275. goto nla_put_failure;
  1276. if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
  1277. nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
  1278. rdev->wiphy.probe_resp_offload))
  1279. goto nla_put_failure;
  1280. if ((rdev->wiphy.available_antennas_tx ||
  1281. rdev->wiphy.available_antennas_rx) &&
  1282. rdev->ops->get_antenna) {
  1283. u32 tx_ant = 0, rx_ant = 0;
  1284. int res;
  1285. res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
  1286. if (!res) {
  1287. if (nla_put_u32(msg,
  1288. NL80211_ATTR_WIPHY_ANTENNA_TX,
  1289. tx_ant) ||
  1290. nla_put_u32(msg,
  1291. NL80211_ATTR_WIPHY_ANTENNA_RX,
  1292. rx_ant))
  1293. goto nla_put_failure;
  1294. }
  1295. }
  1296. state->split_start++;
  1297. if (state->split)
  1298. break;
  1299. case 2:
  1300. if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
  1301. rdev->wiphy.interface_modes))
  1302. goto nla_put_failure;
  1303. state->split_start++;
  1304. if (state->split)
  1305. break;
  1306. case 3:
  1307. nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
  1308. if (!nl_bands)
  1309. goto nla_put_failure;
  1310. for (band = state->band_start;
  1311. band < NUM_NL80211_BANDS; band++) {
  1312. struct ieee80211_supported_band *sband;
  1313. sband = rdev->wiphy.bands[band];
  1314. if (!sband)
  1315. continue;
  1316. nl_band = nla_nest_start(msg, band);
  1317. if (!nl_band)
  1318. goto nla_put_failure;
  1319. switch (state->chan_start) {
  1320. case 0:
  1321. if (nl80211_send_band_rateinfo(msg, sband))
  1322. goto nla_put_failure;
  1323. state->chan_start++;
  1324. if (state->split)
  1325. break;
  1326. default:
  1327. /* add frequencies */
  1328. nl_freqs = nla_nest_start(
  1329. msg, NL80211_BAND_ATTR_FREQS);
  1330. if (!nl_freqs)
  1331. goto nla_put_failure;
  1332. for (i = state->chan_start - 1;
  1333. i < sband->n_channels;
  1334. i++) {
  1335. nl_freq = nla_nest_start(msg, i);
  1336. if (!nl_freq)
  1337. goto nla_put_failure;
  1338. chan = &sband->channels[i];
  1339. if (nl80211_msg_put_channel(
  1340. msg, chan,
  1341. state->split))
  1342. goto nla_put_failure;
  1343. nla_nest_end(msg, nl_freq);
  1344. if (state->split)
  1345. break;
  1346. }
  1347. if (i < sband->n_channels)
  1348. state->chan_start = i + 2;
  1349. else
  1350. state->chan_start = 0;
  1351. nla_nest_end(msg, nl_freqs);
  1352. }
  1353. nla_nest_end(msg, nl_band);
  1354. if (state->split) {
  1355. /* start again here */
  1356. if (state->chan_start)
  1357. band--;
  1358. break;
  1359. }
  1360. }
  1361. nla_nest_end(msg, nl_bands);
  1362. if (band < NUM_NL80211_BANDS)
  1363. state->band_start = band + 1;
  1364. else
  1365. state->band_start = 0;
  1366. /* if bands & channels are done, continue outside */
  1367. if (state->band_start == 0 && state->chan_start == 0)
  1368. state->split_start++;
  1369. if (state->split)
  1370. break;
  1371. case 4:
  1372. nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
  1373. if (!nl_cmds)
  1374. goto nla_put_failure;
  1375. i = 0;
  1376. #define CMD(op, n) \
  1377. do { \
  1378. if (rdev->ops->op) { \
  1379. i++; \
  1380. if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
  1381. goto nla_put_failure; \
  1382. } \
  1383. } while (0)
  1384. CMD(add_virtual_intf, NEW_INTERFACE);
  1385. CMD(change_virtual_intf, SET_INTERFACE);
  1386. CMD(add_key, NEW_KEY);
  1387. CMD(start_ap, START_AP);
  1388. CMD(add_station, NEW_STATION);
  1389. CMD(add_mpath, NEW_MPATH);
  1390. CMD(update_mesh_config, SET_MESH_CONFIG);
  1391. CMD(change_bss, SET_BSS);
  1392. CMD(auth, AUTHENTICATE);
  1393. CMD(assoc, ASSOCIATE);
  1394. CMD(deauth, DEAUTHENTICATE);
  1395. CMD(disassoc, DISASSOCIATE);
  1396. CMD(join_ibss, JOIN_IBSS);
  1397. CMD(join_mesh, JOIN_MESH);
  1398. CMD(set_pmksa, SET_PMKSA);
  1399. CMD(del_pmksa, DEL_PMKSA);
  1400. CMD(flush_pmksa, FLUSH_PMKSA);
  1401. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
  1402. CMD(remain_on_channel, REMAIN_ON_CHANNEL);
  1403. CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
  1404. CMD(mgmt_tx, FRAME);
  1405. CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
  1406. if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
  1407. i++;
  1408. if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
  1409. goto nla_put_failure;
  1410. }
  1411. if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
  1412. rdev->ops->join_mesh) {
  1413. i++;
  1414. if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
  1415. goto nla_put_failure;
  1416. }
  1417. CMD(set_wds_peer, SET_WDS_PEER);
  1418. if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
  1419. CMD(tdls_mgmt, TDLS_MGMT);
  1420. CMD(tdls_oper, TDLS_OPER);
  1421. }
  1422. if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  1423. CMD(sched_scan_start, START_SCHED_SCAN);
  1424. CMD(probe_client, PROBE_CLIENT);
  1425. CMD(set_noack_map, SET_NOACK_MAP);
  1426. if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
  1427. i++;
  1428. if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
  1429. goto nla_put_failure;
  1430. }
  1431. CMD(start_p2p_device, START_P2P_DEVICE);
  1432. CMD(set_mcast_rate, SET_MCAST_RATE);
  1433. #ifdef CONFIG_NL80211_TESTMODE
  1434. CMD(testmode_cmd, TESTMODE);
  1435. #endif
  1436. if (state->split) {
  1437. CMD(crit_proto_start, CRIT_PROTOCOL_START);
  1438. CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
  1439. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
  1440. CMD(channel_switch, CHANNEL_SWITCH);
  1441. CMD(set_qos_map, SET_QOS_MAP);
  1442. if (rdev->wiphy.features &
  1443. NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
  1444. CMD(add_tx_ts, ADD_TX_TS);
  1445. CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
  1446. CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
  1447. }
  1448. /* add into the if now */
  1449. #undef CMD
  1450. if (rdev->ops->connect || rdev->ops->auth) {
  1451. i++;
  1452. if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
  1453. goto nla_put_failure;
  1454. }
  1455. if (rdev->ops->disconnect || rdev->ops->deauth) {
  1456. i++;
  1457. if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
  1458. goto nla_put_failure;
  1459. }
  1460. nla_nest_end(msg, nl_cmds);
  1461. state->split_start++;
  1462. if (state->split)
  1463. break;
  1464. case 5:
  1465. if (rdev->ops->remain_on_channel &&
  1466. (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
  1467. nla_put_u32(msg,
  1468. NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
  1469. rdev->wiphy.max_remain_on_channel_duration))
  1470. goto nla_put_failure;
  1471. if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
  1472. nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
  1473. goto nla_put_failure;
  1474. if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
  1475. goto nla_put_failure;
  1476. state->split_start++;
  1477. if (state->split)
  1478. break;
  1479. case 6:
  1480. #ifdef CONFIG_PM
  1481. if (nl80211_send_wowlan(msg, rdev, state->split))
  1482. goto nla_put_failure;
  1483. state->split_start++;
  1484. if (state->split)
  1485. break;
  1486. #else
  1487. state->split_start++;
  1488. #endif
  1489. case 7:
  1490. if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
  1491. rdev->wiphy.software_iftypes))
  1492. goto nla_put_failure;
  1493. if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
  1494. state->split))
  1495. goto nla_put_failure;
  1496. state->split_start++;
  1497. if (state->split)
  1498. break;
  1499. case 8:
  1500. if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
  1501. nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
  1502. rdev->wiphy.ap_sme_capa))
  1503. goto nla_put_failure;
  1504. features = rdev->wiphy.features;
  1505. /*
  1506. * We can only add the per-channel limit information if the
  1507. * dump is split, otherwise it makes it too big. Therefore
  1508. * only advertise it in that case.
  1509. */
  1510. if (state->split)
  1511. features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
  1512. if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
  1513. goto nla_put_failure;
  1514. if (rdev->wiphy.ht_capa_mod_mask &&
  1515. nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
  1516. sizeof(*rdev->wiphy.ht_capa_mod_mask),
  1517. rdev->wiphy.ht_capa_mod_mask))
  1518. goto nla_put_failure;
  1519. if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
  1520. rdev->wiphy.max_acl_mac_addrs &&
  1521. nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
  1522. rdev->wiphy.max_acl_mac_addrs))
  1523. goto nla_put_failure;
  1524. /*
  1525. * Any information below this point is only available to
  1526. * applications that can deal with it being split. This
  1527. * helps ensure that newly added capabilities don't break
  1528. * older tools by overrunning their buffers.
  1529. *
  1530. * We still increment split_start so that in the split
  1531. * case we'll continue with more data in the next round,
  1532. * but break unconditionally so unsplit data stops here.
  1533. */
  1534. state->split_start++;
  1535. break;
  1536. case 9:
  1537. if (rdev->wiphy.extended_capabilities &&
  1538. (nla_put(msg, NL80211_ATTR_EXT_CAPA,
  1539. rdev->wiphy.extended_capabilities_len,
  1540. rdev->wiphy.extended_capabilities) ||
  1541. nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
  1542. rdev->wiphy.extended_capabilities_len,
  1543. rdev->wiphy.extended_capabilities_mask)))
  1544. goto nla_put_failure;
  1545. if (rdev->wiphy.vht_capa_mod_mask &&
  1546. nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
  1547. sizeof(*rdev->wiphy.vht_capa_mod_mask),
  1548. rdev->wiphy.vht_capa_mod_mask))
  1549. goto nla_put_failure;
  1550. state->split_start++;
  1551. break;
  1552. case 10:
  1553. if (nl80211_send_coalesce(msg, rdev))
  1554. goto nla_put_failure;
  1555. if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
  1556. (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
  1557. nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
  1558. goto nla_put_failure;
  1559. if (rdev->wiphy.max_ap_assoc_sta &&
  1560. nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
  1561. rdev->wiphy.max_ap_assoc_sta))
  1562. goto nla_put_failure;
  1563. state->split_start++;
  1564. break;
  1565. case 11:
  1566. if (rdev->wiphy.n_vendor_commands) {
  1567. const struct nl80211_vendor_cmd_info *info;
  1568. struct nlattr *nested;
  1569. nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
  1570. if (!nested)
  1571. goto nla_put_failure;
  1572. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  1573. info = &rdev->wiphy.vendor_commands[i].info;
  1574. if (nla_put(msg, i + 1, sizeof(*info), info))
  1575. goto nla_put_failure;
  1576. }
  1577. nla_nest_end(msg, nested);
  1578. }
  1579. if (rdev->wiphy.n_vendor_events) {
  1580. const struct nl80211_vendor_cmd_info *info;
  1581. struct nlattr *nested;
  1582. nested = nla_nest_start(msg,
  1583. NL80211_ATTR_VENDOR_EVENTS);
  1584. if (!nested)
  1585. goto nla_put_failure;
  1586. for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
  1587. info = &rdev->wiphy.vendor_events[i];
  1588. if (nla_put(msg, i + 1, sizeof(*info), info))
  1589. goto nla_put_failure;
  1590. }
  1591. nla_nest_end(msg, nested);
  1592. }
  1593. state->split_start++;
  1594. break;
  1595. case 12:
  1596. if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
  1597. nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
  1598. rdev->wiphy.max_num_csa_counters))
  1599. goto nla_put_failure;
  1600. if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  1601. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  1602. goto nla_put_failure;
  1603. if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
  1604. sizeof(rdev->wiphy.ext_features),
  1605. rdev->wiphy.ext_features))
  1606. goto nla_put_failure;
  1607. if (rdev->wiphy.bss_select_support) {
  1608. struct nlattr *nested;
  1609. u32 bss_select_support = rdev->wiphy.bss_select_support;
  1610. nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT);
  1611. if (!nested)
  1612. goto nla_put_failure;
  1613. i = 0;
  1614. while (bss_select_support) {
  1615. if ((bss_select_support & 1) &&
  1616. nla_put_flag(msg, i))
  1617. goto nla_put_failure;
  1618. i++;
  1619. bss_select_support >>= 1;
  1620. }
  1621. nla_nest_end(msg, nested);
  1622. }
  1623. state->split_start++;
  1624. break;
  1625. case 13:
  1626. if (rdev->wiphy.num_iftype_ext_capab &&
  1627. rdev->wiphy.iftype_ext_capab) {
  1628. struct nlattr *nested_ext_capab, *nested;
  1629. nested = nla_nest_start(msg,
  1630. NL80211_ATTR_IFTYPE_EXT_CAPA);
  1631. if (!nested)
  1632. goto nla_put_failure;
  1633. for (i = state->capa_start;
  1634. i < rdev->wiphy.num_iftype_ext_capab; i++) {
  1635. const struct wiphy_iftype_ext_capab *capab;
  1636. capab = &rdev->wiphy.iftype_ext_capab[i];
  1637. nested_ext_capab = nla_nest_start(msg, i);
  1638. if (!nested_ext_capab ||
  1639. nla_put_u32(msg, NL80211_ATTR_IFTYPE,
  1640. capab->iftype) ||
  1641. nla_put(msg, NL80211_ATTR_EXT_CAPA,
  1642. capab->extended_capabilities_len,
  1643. capab->extended_capabilities) ||
  1644. nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
  1645. capab->extended_capabilities_len,
  1646. capab->extended_capabilities_mask))
  1647. goto nla_put_failure;
  1648. nla_nest_end(msg, nested_ext_capab);
  1649. if (state->split)
  1650. break;
  1651. }
  1652. nla_nest_end(msg, nested);
  1653. if (i < rdev->wiphy.num_iftype_ext_capab) {
  1654. state->capa_start = i + 1;
  1655. break;
  1656. }
  1657. }
  1658. /* done */
  1659. state->split_start = 0;
  1660. break;
  1661. }
  1662. finish:
  1663. genlmsg_end(msg, hdr);
  1664. return 0;
  1665. nla_put_failure:
  1666. genlmsg_cancel(msg, hdr);
  1667. return -EMSGSIZE;
  1668. }
  1669. static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
  1670. struct netlink_callback *cb,
  1671. struct nl80211_dump_wiphy_state *state)
  1672. {
  1673. struct nlattr **tb = nl80211_fam.attrbuf;
  1674. int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  1675. tb, nl80211_fam.maxattr, nl80211_policy);
  1676. /* ignore parse errors for backward compatibility */
  1677. if (ret)
  1678. return 0;
  1679. state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
  1680. if (tb[NL80211_ATTR_WIPHY])
  1681. state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
  1682. if (tb[NL80211_ATTR_WDEV])
  1683. state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
  1684. if (tb[NL80211_ATTR_IFINDEX]) {
  1685. struct net_device *netdev;
  1686. struct cfg80211_registered_device *rdev;
  1687. int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
  1688. netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
  1689. if (!netdev)
  1690. return -ENODEV;
  1691. if (netdev->ieee80211_ptr) {
  1692. rdev = wiphy_to_rdev(
  1693. netdev->ieee80211_ptr->wiphy);
  1694. state->filter_wiphy = rdev->wiphy_idx;
  1695. }
  1696. }
  1697. return 0;
  1698. }
  1699. static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
  1700. {
  1701. int idx = 0, ret;
  1702. struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
  1703. struct cfg80211_registered_device *rdev;
  1704. rtnl_lock();
  1705. if (!state) {
  1706. state = kzalloc(sizeof(*state), GFP_KERNEL);
  1707. if (!state) {
  1708. rtnl_unlock();
  1709. return -ENOMEM;
  1710. }
  1711. state->filter_wiphy = -1;
  1712. ret = nl80211_dump_wiphy_parse(skb, cb, state);
  1713. if (ret) {
  1714. kfree(state);
  1715. rtnl_unlock();
  1716. return ret;
  1717. }
  1718. cb->args[0] = (long)state;
  1719. }
  1720. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  1721. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  1722. continue;
  1723. if (++idx <= state->start)
  1724. continue;
  1725. if (state->filter_wiphy != -1 &&
  1726. state->filter_wiphy != rdev->wiphy_idx)
  1727. continue;
  1728. /* attempt to fit multiple wiphy data chunks into the skb */
  1729. do {
  1730. ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
  1731. skb,
  1732. NETLINK_CB(cb->skb).portid,
  1733. cb->nlh->nlmsg_seq,
  1734. NLM_F_MULTI, state);
  1735. if (ret < 0) {
  1736. /*
  1737. * If sending the wiphy data didn't fit (ENOBUFS
  1738. * or EMSGSIZE returned), this SKB is still
  1739. * empty (so it's not too big because another
  1740. * wiphy dataset is already in the skb) and
  1741. * we've not tried to adjust the dump allocation
  1742. * yet ... then adjust the alloc size to be
  1743. * bigger, and return 1 but with the empty skb.
  1744. * This results in an empty message being RX'ed
  1745. * in userspace, but that is ignored.
  1746. *
  1747. * We can then retry with the larger buffer.
  1748. */
  1749. if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
  1750. !skb->len && !state->split &&
  1751. cb->min_dump_alloc < 4096) {
  1752. cb->min_dump_alloc = 4096;
  1753. state->split_start = 0;
  1754. rtnl_unlock();
  1755. return 1;
  1756. }
  1757. idx--;
  1758. break;
  1759. }
  1760. } while (state->split_start > 0);
  1761. break;
  1762. }
  1763. rtnl_unlock();
  1764. state->start = idx;
  1765. return skb->len;
  1766. }
  1767. static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
  1768. {
  1769. kfree((void *)cb->args[0]);
  1770. return 0;
  1771. }
  1772. static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
  1773. {
  1774. struct sk_buff *msg;
  1775. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1776. struct nl80211_dump_wiphy_state state = {};
  1777. msg = nlmsg_new(4096, GFP_KERNEL);
  1778. if (!msg)
  1779. return -ENOMEM;
  1780. if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
  1781. info->snd_portid, info->snd_seq, 0,
  1782. &state) < 0) {
  1783. nlmsg_free(msg);
  1784. return -ENOBUFS;
  1785. }
  1786. return genlmsg_reply(msg, info);
  1787. }
  1788. static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
  1789. [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
  1790. [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
  1791. [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
  1792. [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
  1793. [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
  1794. };
  1795. static int parse_txq_params(struct nlattr *tb[],
  1796. struct ieee80211_txq_params *txq_params)
  1797. {
  1798. u8 ac;
  1799. if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
  1800. !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
  1801. !tb[NL80211_TXQ_ATTR_AIFS])
  1802. return -EINVAL;
  1803. ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
  1804. txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
  1805. txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
  1806. txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
  1807. txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
  1808. if (ac >= NL80211_NUM_ACS)
  1809. return -EINVAL;
  1810. txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
  1811. return 0;
  1812. }
  1813. static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
  1814. {
  1815. /*
  1816. * You can only set the channel explicitly for WDS interfaces,
  1817. * all others have their channel managed via their respective
  1818. * "establish a connection" command (connect, join, ...)
  1819. *
  1820. * For AP/GO and mesh mode, the channel can be set with the
  1821. * channel userspace API, but is only stored and passed to the
  1822. * low-level driver when the AP starts or the mesh is joined.
  1823. * This is for backward compatibility, userspace can also give
  1824. * the channel in the start-ap or join-mesh commands instead.
  1825. *
  1826. * Monitors are special as they are normally slaved to
  1827. * whatever else is going on, so they have their own special
  1828. * operation to set the monitor channel if possible.
  1829. */
  1830. return !wdev ||
  1831. wdev->iftype == NL80211_IFTYPE_AP ||
  1832. wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
  1833. wdev->iftype == NL80211_IFTYPE_MONITOR ||
  1834. wdev->iftype == NL80211_IFTYPE_P2P_GO;
  1835. }
  1836. static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
  1837. struct genl_info *info,
  1838. struct cfg80211_chan_def *chandef)
  1839. {
  1840. u32 control_freq;
  1841. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  1842. return -EINVAL;
  1843. control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  1844. memset(chandef, 0, sizeof(*chandef));
  1845. chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
  1846. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  1847. chandef->center_freq1 = control_freq;
  1848. chandef->center_freq2 = 0;
  1849. /* Primary channel not allowed */
  1850. if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
  1851. return -EINVAL;
  1852. if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
  1853. enum nl80211_channel_type chantype;
  1854. chantype = nla_get_u32(
  1855. info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
  1856. switch (chantype) {
  1857. case NL80211_CHAN_NO_HT:
  1858. case NL80211_CHAN_HT20:
  1859. case NL80211_CHAN_HT40PLUS:
  1860. case NL80211_CHAN_HT40MINUS:
  1861. cfg80211_chandef_create(chandef, chandef->chan,
  1862. chantype);
  1863. break;
  1864. default:
  1865. return -EINVAL;
  1866. }
  1867. } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
  1868. chandef->width =
  1869. nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
  1870. if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
  1871. chandef->center_freq1 =
  1872. nla_get_u32(
  1873. info->attrs[NL80211_ATTR_CENTER_FREQ1]);
  1874. if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
  1875. chandef->center_freq2 =
  1876. nla_get_u32(
  1877. info->attrs[NL80211_ATTR_CENTER_FREQ2]);
  1878. }
  1879. if (!cfg80211_chandef_valid(chandef))
  1880. return -EINVAL;
  1881. if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
  1882. IEEE80211_CHAN_DISABLED))
  1883. return -EINVAL;
  1884. if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
  1885. chandef->width == NL80211_CHAN_WIDTH_10) &&
  1886. !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
  1887. return -EINVAL;
  1888. return 0;
  1889. }
  1890. static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
  1891. struct net_device *dev,
  1892. struct genl_info *info)
  1893. {
  1894. struct cfg80211_chan_def chandef;
  1895. int result;
  1896. enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
  1897. struct wireless_dev *wdev = NULL;
  1898. if (dev)
  1899. wdev = dev->ieee80211_ptr;
  1900. if (!nl80211_can_set_dev_channel(wdev))
  1901. return -EOPNOTSUPP;
  1902. if (wdev)
  1903. iftype = wdev->iftype;
  1904. result = nl80211_parse_chandef(rdev, info, &chandef);
  1905. if (result)
  1906. return result;
  1907. switch (iftype) {
  1908. case NL80211_IFTYPE_AP:
  1909. case NL80211_IFTYPE_P2P_GO:
  1910. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
  1911. iftype)) {
  1912. result = -EINVAL;
  1913. break;
  1914. }
  1915. if (wdev->beacon_interval) {
  1916. if (!dev || !rdev->ops->set_ap_chanwidth ||
  1917. !(rdev->wiphy.features &
  1918. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
  1919. result = -EBUSY;
  1920. break;
  1921. }
  1922. /* Only allow dynamic channel width changes */
  1923. if (chandef.chan != wdev->preset_chandef.chan) {
  1924. result = -EBUSY;
  1925. break;
  1926. }
  1927. result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
  1928. if (result)
  1929. break;
  1930. }
  1931. wdev->preset_chandef = chandef;
  1932. result = 0;
  1933. break;
  1934. case NL80211_IFTYPE_MESH_POINT:
  1935. result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
  1936. break;
  1937. case NL80211_IFTYPE_MONITOR:
  1938. result = cfg80211_set_monitor_channel(rdev, &chandef);
  1939. break;
  1940. default:
  1941. result = -EINVAL;
  1942. }
  1943. return result;
  1944. }
  1945. static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
  1946. {
  1947. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1948. struct net_device *netdev = info->user_ptr[1];
  1949. return __nl80211_set_channel(rdev, netdev, info);
  1950. }
  1951. static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
  1952. {
  1953. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  1954. struct net_device *dev = info->user_ptr[1];
  1955. struct wireless_dev *wdev = dev->ieee80211_ptr;
  1956. const u8 *bssid;
  1957. if (!info->attrs[NL80211_ATTR_MAC])
  1958. return -EINVAL;
  1959. if (netif_running(dev))
  1960. return -EBUSY;
  1961. if (!rdev->ops->set_wds_peer)
  1962. return -EOPNOTSUPP;
  1963. if (wdev->iftype != NL80211_IFTYPE_WDS)
  1964. return -EOPNOTSUPP;
  1965. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  1966. return rdev_set_wds_peer(rdev, dev, bssid);
  1967. }
  1968. static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
  1969. {
  1970. struct cfg80211_registered_device *rdev;
  1971. struct net_device *netdev = NULL;
  1972. struct wireless_dev *wdev;
  1973. int result = 0, rem_txq_params = 0;
  1974. struct nlattr *nl_txq_params;
  1975. u32 changed;
  1976. u8 retry_short = 0, retry_long = 0;
  1977. u32 frag_threshold = 0, rts_threshold = 0;
  1978. u8 coverage_class = 0;
  1979. ASSERT_RTNL();
  1980. /*
  1981. * Try to find the wiphy and netdev. Normally this
  1982. * function shouldn't need the netdev, but this is
  1983. * done for backward compatibility -- previously
  1984. * setting the channel was done per wiphy, but now
  1985. * it is per netdev. Previous userland like hostapd
  1986. * also passed a netdev to set_wiphy, so that it is
  1987. * possible to let that go to the right netdev!
  1988. */
  1989. if (info->attrs[NL80211_ATTR_IFINDEX]) {
  1990. int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
  1991. netdev = __dev_get_by_index(genl_info_net(info), ifindex);
  1992. if (netdev && netdev->ieee80211_ptr)
  1993. rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
  1994. else
  1995. netdev = NULL;
  1996. }
  1997. if (!netdev) {
  1998. rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
  1999. info->attrs);
  2000. if (IS_ERR(rdev))
  2001. return PTR_ERR(rdev);
  2002. wdev = NULL;
  2003. netdev = NULL;
  2004. result = 0;
  2005. } else
  2006. wdev = netdev->ieee80211_ptr;
  2007. /*
  2008. * end workaround code, by now the rdev is available
  2009. * and locked, and wdev may or may not be NULL.
  2010. */
  2011. if (info->attrs[NL80211_ATTR_WIPHY_NAME])
  2012. result = cfg80211_dev_rename(
  2013. rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
  2014. if (result)
  2015. return result;
  2016. if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
  2017. struct ieee80211_txq_params txq_params;
  2018. struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
  2019. if (!rdev->ops->set_txq_params)
  2020. return -EOPNOTSUPP;
  2021. if (!netdev)
  2022. return -EINVAL;
  2023. if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2024. netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2025. return -EINVAL;
  2026. if (!netif_running(netdev))
  2027. return -ENETDOWN;
  2028. nla_for_each_nested(nl_txq_params,
  2029. info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
  2030. rem_txq_params) {
  2031. result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
  2032. nla_data(nl_txq_params),
  2033. nla_len(nl_txq_params),
  2034. txq_params_policy);
  2035. if (result)
  2036. return result;
  2037. result = parse_txq_params(tb, &txq_params);
  2038. if (result)
  2039. return result;
  2040. result = rdev_set_txq_params(rdev, netdev,
  2041. &txq_params);
  2042. if (result)
  2043. return result;
  2044. }
  2045. }
  2046. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  2047. result = __nl80211_set_channel(
  2048. rdev,
  2049. nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
  2050. info);
  2051. if (result)
  2052. return result;
  2053. }
  2054. if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
  2055. struct wireless_dev *txp_wdev = wdev;
  2056. enum nl80211_tx_power_setting type;
  2057. int idx, mbm = 0;
  2058. if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
  2059. txp_wdev = NULL;
  2060. if (!rdev->ops->set_tx_power)
  2061. return -EOPNOTSUPP;
  2062. idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
  2063. type = nla_get_u32(info->attrs[idx]);
  2064. if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
  2065. (type != NL80211_TX_POWER_AUTOMATIC))
  2066. return -EINVAL;
  2067. if (type != NL80211_TX_POWER_AUTOMATIC) {
  2068. idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
  2069. mbm = nla_get_u32(info->attrs[idx]);
  2070. }
  2071. result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
  2072. if (result)
  2073. return result;
  2074. }
  2075. if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
  2076. info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
  2077. u32 tx_ant, rx_ant;
  2078. if ((!rdev->wiphy.available_antennas_tx &&
  2079. !rdev->wiphy.available_antennas_rx) ||
  2080. !rdev->ops->set_antenna)
  2081. return -EOPNOTSUPP;
  2082. tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
  2083. rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
  2084. /* reject antenna configurations which don't match the
  2085. * available antenna masks, except for the "all" mask */
  2086. if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
  2087. (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
  2088. return -EINVAL;
  2089. tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
  2090. rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
  2091. result = rdev_set_antenna(rdev, tx_ant, rx_ant);
  2092. if (result)
  2093. return result;
  2094. }
  2095. changed = 0;
  2096. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
  2097. retry_short = nla_get_u8(
  2098. info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
  2099. if (retry_short == 0)
  2100. return -EINVAL;
  2101. changed |= WIPHY_PARAM_RETRY_SHORT;
  2102. }
  2103. if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
  2104. retry_long = nla_get_u8(
  2105. info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
  2106. if (retry_long == 0)
  2107. return -EINVAL;
  2108. changed |= WIPHY_PARAM_RETRY_LONG;
  2109. }
  2110. if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
  2111. frag_threshold = nla_get_u32(
  2112. info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
  2113. if (frag_threshold < 256)
  2114. return -EINVAL;
  2115. if (frag_threshold != (u32) -1) {
  2116. /*
  2117. * Fragments (apart from the last one) are required to
  2118. * have even length. Make the fragmentation code
  2119. * simpler by stripping LSB should someone try to use
  2120. * odd threshold value.
  2121. */
  2122. frag_threshold &= ~0x1;
  2123. }
  2124. changed |= WIPHY_PARAM_FRAG_THRESHOLD;
  2125. }
  2126. if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
  2127. rts_threshold = nla_get_u32(
  2128. info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
  2129. changed |= WIPHY_PARAM_RTS_THRESHOLD;
  2130. }
  2131. if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
  2132. if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
  2133. return -EINVAL;
  2134. coverage_class = nla_get_u8(
  2135. info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
  2136. changed |= WIPHY_PARAM_COVERAGE_CLASS;
  2137. }
  2138. if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
  2139. if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
  2140. return -EOPNOTSUPP;
  2141. changed |= WIPHY_PARAM_DYN_ACK;
  2142. }
  2143. if (changed) {
  2144. u8 old_retry_short, old_retry_long;
  2145. u32 old_frag_threshold, old_rts_threshold;
  2146. u8 old_coverage_class;
  2147. if (!rdev->ops->set_wiphy_params)
  2148. return -EOPNOTSUPP;
  2149. old_retry_short = rdev->wiphy.retry_short;
  2150. old_retry_long = rdev->wiphy.retry_long;
  2151. old_frag_threshold = rdev->wiphy.frag_threshold;
  2152. old_rts_threshold = rdev->wiphy.rts_threshold;
  2153. old_coverage_class = rdev->wiphy.coverage_class;
  2154. if (changed & WIPHY_PARAM_RETRY_SHORT)
  2155. rdev->wiphy.retry_short = retry_short;
  2156. if (changed & WIPHY_PARAM_RETRY_LONG)
  2157. rdev->wiphy.retry_long = retry_long;
  2158. if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
  2159. rdev->wiphy.frag_threshold = frag_threshold;
  2160. if (changed & WIPHY_PARAM_RTS_THRESHOLD)
  2161. rdev->wiphy.rts_threshold = rts_threshold;
  2162. if (changed & WIPHY_PARAM_COVERAGE_CLASS)
  2163. rdev->wiphy.coverage_class = coverage_class;
  2164. result = rdev_set_wiphy_params(rdev, changed);
  2165. if (result) {
  2166. rdev->wiphy.retry_short = old_retry_short;
  2167. rdev->wiphy.retry_long = old_retry_long;
  2168. rdev->wiphy.frag_threshold = old_frag_threshold;
  2169. rdev->wiphy.rts_threshold = old_rts_threshold;
  2170. rdev->wiphy.coverage_class = old_coverage_class;
  2171. return result;
  2172. }
  2173. }
  2174. return 0;
  2175. }
  2176. static inline u64 wdev_id(struct wireless_dev *wdev)
  2177. {
  2178. return (u64)wdev->identifier |
  2179. ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
  2180. }
  2181. static int nl80211_send_chandef(struct sk_buff *msg,
  2182. const struct cfg80211_chan_def *chandef)
  2183. {
  2184. if (WARN_ON(!cfg80211_chandef_valid(chandef)))
  2185. return -EINVAL;
  2186. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
  2187. chandef->chan->center_freq))
  2188. return -ENOBUFS;
  2189. switch (chandef->width) {
  2190. case NL80211_CHAN_WIDTH_20_NOHT:
  2191. case NL80211_CHAN_WIDTH_20:
  2192. case NL80211_CHAN_WIDTH_40:
  2193. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  2194. cfg80211_get_chandef_type(chandef)))
  2195. return -ENOBUFS;
  2196. break;
  2197. default:
  2198. break;
  2199. }
  2200. if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
  2201. return -ENOBUFS;
  2202. if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
  2203. return -ENOBUFS;
  2204. if (chandef->center_freq2 &&
  2205. nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
  2206. return -ENOBUFS;
  2207. return 0;
  2208. }
  2209. static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
  2210. struct cfg80211_registered_device *rdev,
  2211. struct wireless_dev *wdev, bool removal)
  2212. {
  2213. struct net_device *dev = wdev->netdev;
  2214. u8 cmd = NL80211_CMD_NEW_INTERFACE;
  2215. void *hdr;
  2216. if (removal)
  2217. cmd = NL80211_CMD_DEL_INTERFACE;
  2218. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  2219. if (!hdr)
  2220. return -1;
  2221. if (dev &&
  2222. (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  2223. nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
  2224. goto nla_put_failure;
  2225. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  2226. nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
  2227. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  2228. NL80211_ATTR_PAD) ||
  2229. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
  2230. nla_put_u32(msg, NL80211_ATTR_GENERATION,
  2231. rdev->devlist_generation ^
  2232. (cfg80211_rdev_list_generation << 2)))
  2233. goto nla_put_failure;
  2234. if (rdev->ops->get_channel) {
  2235. int ret;
  2236. struct cfg80211_chan_def chandef = {};
  2237. ret = rdev_get_channel(rdev, wdev, &chandef);
  2238. if (ret == 0) {
  2239. if (nl80211_send_chandef(msg, &chandef))
  2240. goto nla_put_failure;
  2241. }
  2242. }
  2243. if (rdev->ops->get_tx_power) {
  2244. int dbm, ret;
  2245. ret = rdev_get_tx_power(rdev, wdev, &dbm);
  2246. if (ret == 0 &&
  2247. nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
  2248. DBM_TO_MBM(dbm)))
  2249. goto nla_put_failure;
  2250. }
  2251. if (wdev->ssid_len) {
  2252. if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
  2253. goto nla_put_failure;
  2254. }
  2255. genlmsg_end(msg, hdr);
  2256. return 0;
  2257. nla_put_failure:
  2258. genlmsg_cancel(msg, hdr);
  2259. return -EMSGSIZE;
  2260. }
  2261. static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
  2262. {
  2263. int wp_idx = 0;
  2264. int if_idx = 0;
  2265. int wp_start = cb->args[0];
  2266. int if_start = cb->args[1];
  2267. int filter_wiphy = -1;
  2268. struct cfg80211_registered_device *rdev;
  2269. struct wireless_dev *wdev;
  2270. int ret;
  2271. rtnl_lock();
  2272. if (!cb->args[2]) {
  2273. struct nl80211_dump_wiphy_state state = {
  2274. .filter_wiphy = -1,
  2275. };
  2276. ret = nl80211_dump_wiphy_parse(skb, cb, &state);
  2277. if (ret)
  2278. goto out_unlock;
  2279. filter_wiphy = state.filter_wiphy;
  2280. /*
  2281. * if filtering, set cb->args[2] to +1 since 0 is the default
  2282. * value needed to determine that parsing is necessary.
  2283. */
  2284. if (filter_wiphy >= 0)
  2285. cb->args[2] = filter_wiphy + 1;
  2286. else
  2287. cb->args[2] = -1;
  2288. } else if (cb->args[2] > 0) {
  2289. filter_wiphy = cb->args[2] - 1;
  2290. }
  2291. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  2292. if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
  2293. continue;
  2294. if (wp_idx < wp_start) {
  2295. wp_idx++;
  2296. continue;
  2297. }
  2298. if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
  2299. continue;
  2300. if_idx = 0;
  2301. list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
  2302. if (if_idx < if_start) {
  2303. if_idx++;
  2304. continue;
  2305. }
  2306. if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
  2307. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  2308. rdev, wdev, false) < 0) {
  2309. goto out;
  2310. }
  2311. if_idx++;
  2312. }
  2313. wp_idx++;
  2314. }
  2315. out:
  2316. cb->args[0] = wp_idx;
  2317. cb->args[1] = if_idx;
  2318. ret = skb->len;
  2319. out_unlock:
  2320. rtnl_unlock();
  2321. return ret;
  2322. }
  2323. static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
  2324. {
  2325. struct sk_buff *msg;
  2326. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2327. struct wireless_dev *wdev = info->user_ptr[1];
  2328. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2329. if (!msg)
  2330. return -ENOMEM;
  2331. if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
  2332. rdev, wdev, false) < 0) {
  2333. nlmsg_free(msg);
  2334. return -ENOBUFS;
  2335. }
  2336. return genlmsg_reply(msg, info);
  2337. }
  2338. static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
  2339. [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
  2340. [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
  2341. [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
  2342. [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
  2343. [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
  2344. [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
  2345. };
  2346. static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
  2347. {
  2348. struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
  2349. int flag;
  2350. *mntrflags = 0;
  2351. if (!nla)
  2352. return -EINVAL;
  2353. if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
  2354. nla, mntr_flags_policy))
  2355. return -EINVAL;
  2356. for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
  2357. if (flags[flag])
  2358. *mntrflags |= (1<<flag);
  2359. return 0;
  2360. }
  2361. static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
  2362. struct net_device *netdev, u8 use_4addr,
  2363. enum nl80211_iftype iftype)
  2364. {
  2365. if (!use_4addr) {
  2366. if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
  2367. return -EBUSY;
  2368. return 0;
  2369. }
  2370. switch (iftype) {
  2371. case NL80211_IFTYPE_AP_VLAN:
  2372. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
  2373. return 0;
  2374. break;
  2375. case NL80211_IFTYPE_STATION:
  2376. if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
  2377. return 0;
  2378. break;
  2379. default:
  2380. break;
  2381. }
  2382. return -EOPNOTSUPP;
  2383. }
  2384. static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
  2385. {
  2386. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2387. struct vif_params params;
  2388. int err;
  2389. enum nl80211_iftype otype, ntype;
  2390. struct net_device *dev = info->user_ptr[1];
  2391. u32 _flags, *flags = NULL;
  2392. bool change = false;
  2393. memset(&params, 0, sizeof(params));
  2394. otype = ntype = dev->ieee80211_ptr->iftype;
  2395. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  2396. ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  2397. if (otype != ntype)
  2398. change = true;
  2399. if (ntype > NL80211_IFTYPE_MAX)
  2400. return -EINVAL;
  2401. }
  2402. if (info->attrs[NL80211_ATTR_MESH_ID]) {
  2403. struct wireless_dev *wdev = dev->ieee80211_ptr;
  2404. if (ntype != NL80211_IFTYPE_MESH_POINT)
  2405. return -EINVAL;
  2406. if (netif_running(dev))
  2407. return -EBUSY;
  2408. wdev_lock(wdev);
  2409. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  2410. IEEE80211_MAX_MESH_ID_LEN);
  2411. wdev->mesh_id_up_len =
  2412. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  2413. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  2414. wdev->mesh_id_up_len);
  2415. wdev_unlock(wdev);
  2416. }
  2417. if (info->attrs[NL80211_ATTR_4ADDR]) {
  2418. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  2419. change = true;
  2420. err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
  2421. if (err)
  2422. return err;
  2423. } else {
  2424. params.use_4addr = -1;
  2425. }
  2426. if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
  2427. if (ntype != NL80211_IFTYPE_MONITOR)
  2428. return -EINVAL;
  2429. err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
  2430. &_flags);
  2431. if (err)
  2432. return err;
  2433. flags = &_flags;
  2434. change = true;
  2435. }
  2436. if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
  2437. const u8 *mumimo_groups;
  2438. u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
  2439. if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
  2440. return -EOPNOTSUPP;
  2441. mumimo_groups =
  2442. nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
  2443. /* bits 0 and 63 are reserved and must be zero */
  2444. if ((mumimo_groups[0] & BIT(7)) ||
  2445. (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0)))
  2446. return -EINVAL;
  2447. memcpy(params.vht_mumimo_groups, mumimo_groups,
  2448. VHT_MUMIMO_GROUPS_DATA_LEN);
  2449. change = true;
  2450. }
  2451. if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
  2452. u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
  2453. if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
  2454. return -EOPNOTSUPP;
  2455. nla_memcpy(params.macaddr,
  2456. info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR],
  2457. ETH_ALEN);
  2458. change = true;
  2459. }
  2460. if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
  2461. !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
  2462. return -EOPNOTSUPP;
  2463. if (change)
  2464. err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
  2465. else
  2466. err = 0;
  2467. if (!err && params.use_4addr != -1)
  2468. dev->ieee80211_ptr->use_4addr = params.use_4addr;
  2469. return err;
  2470. }
  2471. static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
  2472. {
  2473. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2474. struct vif_params params;
  2475. struct wireless_dev *wdev;
  2476. struct sk_buff *msg;
  2477. int err;
  2478. enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
  2479. u32 flags;
  2480. /* to avoid failing a new interface creation due to pending removal */
  2481. cfg80211_destroy_ifaces(rdev);
  2482. memset(&params, 0, sizeof(params));
  2483. if (!info->attrs[NL80211_ATTR_IFNAME])
  2484. return -EINVAL;
  2485. if (info->attrs[NL80211_ATTR_IFTYPE]) {
  2486. type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
  2487. if (type > NL80211_IFTYPE_MAX)
  2488. return -EINVAL;
  2489. }
  2490. if (!rdev->ops->add_virtual_intf ||
  2491. !(rdev->wiphy.interface_modes & (1 << type)))
  2492. return -EOPNOTSUPP;
  2493. if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
  2494. rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
  2495. info->attrs[NL80211_ATTR_MAC]) {
  2496. nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
  2497. ETH_ALEN);
  2498. if (!is_valid_ether_addr(params.macaddr))
  2499. return -EADDRNOTAVAIL;
  2500. }
  2501. if (info->attrs[NL80211_ATTR_4ADDR]) {
  2502. params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
  2503. err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
  2504. if (err)
  2505. return err;
  2506. }
  2507. err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
  2508. info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
  2509. &flags);
  2510. if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
  2511. !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
  2512. return -EOPNOTSUPP;
  2513. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2514. if (!msg)
  2515. return -ENOMEM;
  2516. wdev = rdev_add_virtual_intf(rdev,
  2517. nla_data(info->attrs[NL80211_ATTR_IFNAME]),
  2518. NET_NAME_USER, type, err ? NULL : &flags,
  2519. &params);
  2520. if (WARN_ON(!wdev)) {
  2521. nlmsg_free(msg);
  2522. return -EPROTO;
  2523. } else if (IS_ERR(wdev)) {
  2524. nlmsg_free(msg);
  2525. return PTR_ERR(wdev);
  2526. }
  2527. if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
  2528. wdev->owner_nlportid = info->snd_portid;
  2529. switch (type) {
  2530. case NL80211_IFTYPE_MESH_POINT:
  2531. if (!info->attrs[NL80211_ATTR_MESH_ID])
  2532. break;
  2533. wdev_lock(wdev);
  2534. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
  2535. IEEE80211_MAX_MESH_ID_LEN);
  2536. wdev->mesh_id_up_len =
  2537. nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  2538. memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
  2539. wdev->mesh_id_up_len);
  2540. wdev_unlock(wdev);
  2541. break;
  2542. case NL80211_IFTYPE_NAN:
  2543. case NL80211_IFTYPE_P2P_DEVICE:
  2544. /*
  2545. * P2P Device and NAN do not have a netdev, so don't go
  2546. * through the netdev notifier and must be added here
  2547. */
  2548. mutex_init(&wdev->mtx);
  2549. INIT_LIST_HEAD(&wdev->event_list);
  2550. spin_lock_init(&wdev->event_lock);
  2551. INIT_LIST_HEAD(&wdev->mgmt_registrations);
  2552. spin_lock_init(&wdev->mgmt_registrations_lock);
  2553. wdev->identifier = ++rdev->wdev_id;
  2554. list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
  2555. rdev->devlist_generation++;
  2556. break;
  2557. default:
  2558. break;
  2559. }
  2560. if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
  2561. rdev, wdev, false) < 0) {
  2562. nlmsg_free(msg);
  2563. return -ENOBUFS;
  2564. }
  2565. /*
  2566. * For wdevs which have no associated netdev object (e.g. of type
  2567. * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
  2568. * For all other types, the event will be generated from the
  2569. * netdev notifier
  2570. */
  2571. if (!wdev->netdev)
  2572. nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
  2573. return genlmsg_reply(msg, info);
  2574. }
  2575. static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
  2576. {
  2577. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2578. struct wireless_dev *wdev = info->user_ptr[1];
  2579. if (!rdev->ops->del_virtual_intf)
  2580. return -EOPNOTSUPP;
  2581. /*
  2582. * If we remove a wireless device without a netdev then clear
  2583. * user_ptr[1] so that nl80211_post_doit won't dereference it
  2584. * to check if it needs to do dev_put(). Otherwise it crashes
  2585. * since the wdev has been freed, unlike with a netdev where
  2586. * we need the dev_put() for the netdev to really be freed.
  2587. */
  2588. if (!wdev->netdev)
  2589. info->user_ptr[1] = NULL;
  2590. return rdev_del_virtual_intf(rdev, wdev);
  2591. }
  2592. static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
  2593. {
  2594. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2595. struct net_device *dev = info->user_ptr[1];
  2596. u16 noack_map;
  2597. if (!info->attrs[NL80211_ATTR_NOACK_MAP])
  2598. return -EINVAL;
  2599. if (!rdev->ops->set_noack_map)
  2600. return -EOPNOTSUPP;
  2601. noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
  2602. return rdev_set_noack_map(rdev, dev, noack_map);
  2603. }
  2604. struct get_key_cookie {
  2605. struct sk_buff *msg;
  2606. int error;
  2607. int idx;
  2608. };
  2609. static void get_key_callback(void *c, struct key_params *params)
  2610. {
  2611. struct nlattr *key;
  2612. struct get_key_cookie *cookie = c;
  2613. if ((params->key &&
  2614. nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
  2615. params->key_len, params->key)) ||
  2616. (params->seq &&
  2617. nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
  2618. params->seq_len, params->seq)) ||
  2619. (params->cipher &&
  2620. nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
  2621. params->cipher)))
  2622. goto nla_put_failure;
  2623. key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
  2624. if (!key)
  2625. goto nla_put_failure;
  2626. if ((params->key &&
  2627. nla_put(cookie->msg, NL80211_KEY_DATA,
  2628. params->key_len, params->key)) ||
  2629. (params->seq &&
  2630. nla_put(cookie->msg, NL80211_KEY_SEQ,
  2631. params->seq_len, params->seq)) ||
  2632. (params->cipher &&
  2633. nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
  2634. params->cipher)))
  2635. goto nla_put_failure;
  2636. if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
  2637. goto nla_put_failure;
  2638. nla_nest_end(cookie->msg, key);
  2639. return;
  2640. nla_put_failure:
  2641. cookie->error = 1;
  2642. }
  2643. static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
  2644. {
  2645. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2646. int err;
  2647. struct net_device *dev = info->user_ptr[1];
  2648. u8 key_idx = 0;
  2649. const u8 *mac_addr = NULL;
  2650. bool pairwise;
  2651. struct get_key_cookie cookie = {
  2652. .error = 0,
  2653. };
  2654. void *hdr;
  2655. struct sk_buff *msg;
  2656. if (info->attrs[NL80211_ATTR_KEY_IDX])
  2657. key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
  2658. if (key_idx > 5)
  2659. return -EINVAL;
  2660. if (info->attrs[NL80211_ATTR_MAC])
  2661. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2662. pairwise = !!mac_addr;
  2663. if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
  2664. u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
  2665. if (kt >= NUM_NL80211_KEYTYPES)
  2666. return -EINVAL;
  2667. if (kt != NL80211_KEYTYPE_GROUP &&
  2668. kt != NL80211_KEYTYPE_PAIRWISE)
  2669. return -EINVAL;
  2670. pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
  2671. }
  2672. if (!rdev->ops->get_key)
  2673. return -EOPNOTSUPP;
  2674. if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  2675. return -ENOENT;
  2676. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  2677. if (!msg)
  2678. return -ENOMEM;
  2679. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  2680. NL80211_CMD_NEW_KEY);
  2681. if (!hdr)
  2682. goto nla_put_failure;
  2683. cookie.msg = msg;
  2684. cookie.idx = key_idx;
  2685. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  2686. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
  2687. goto nla_put_failure;
  2688. if (mac_addr &&
  2689. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
  2690. goto nla_put_failure;
  2691. err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
  2692. get_key_callback);
  2693. if (err)
  2694. goto free_msg;
  2695. if (cookie.error)
  2696. goto nla_put_failure;
  2697. genlmsg_end(msg, hdr);
  2698. return genlmsg_reply(msg, info);
  2699. nla_put_failure:
  2700. err = -ENOBUFS;
  2701. free_msg:
  2702. nlmsg_free(msg);
  2703. return err;
  2704. }
  2705. static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
  2706. {
  2707. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2708. struct key_parse key;
  2709. int err;
  2710. struct net_device *dev = info->user_ptr[1];
  2711. err = nl80211_parse_key(info, &key);
  2712. if (err)
  2713. return err;
  2714. if (key.idx < 0)
  2715. return -EINVAL;
  2716. /* only support setting default key */
  2717. if (!key.def && !key.defmgmt)
  2718. return -EINVAL;
  2719. wdev_lock(dev->ieee80211_ptr);
  2720. if (key.def) {
  2721. if (!rdev->ops->set_default_key) {
  2722. err = -EOPNOTSUPP;
  2723. goto out;
  2724. }
  2725. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2726. if (err)
  2727. goto out;
  2728. err = rdev_set_default_key(rdev, dev, key.idx,
  2729. key.def_uni, key.def_multi);
  2730. if (err)
  2731. goto out;
  2732. #ifdef CONFIG_CFG80211_WEXT
  2733. dev->ieee80211_ptr->wext.default_key = key.idx;
  2734. #endif
  2735. } else {
  2736. if (key.def_uni || !key.def_multi) {
  2737. err = -EINVAL;
  2738. goto out;
  2739. }
  2740. if (!rdev->ops->set_default_mgmt_key) {
  2741. err = -EOPNOTSUPP;
  2742. goto out;
  2743. }
  2744. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2745. if (err)
  2746. goto out;
  2747. err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
  2748. if (err)
  2749. goto out;
  2750. #ifdef CONFIG_CFG80211_WEXT
  2751. dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
  2752. #endif
  2753. }
  2754. out:
  2755. wdev_unlock(dev->ieee80211_ptr);
  2756. return err;
  2757. }
  2758. static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
  2759. {
  2760. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2761. int err;
  2762. struct net_device *dev = info->user_ptr[1];
  2763. struct key_parse key;
  2764. const u8 *mac_addr = NULL;
  2765. err = nl80211_parse_key(info, &key);
  2766. if (err)
  2767. return err;
  2768. if (!key.p.key)
  2769. return -EINVAL;
  2770. if (info->attrs[NL80211_ATTR_MAC])
  2771. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2772. if (key.type == -1) {
  2773. if (mac_addr)
  2774. key.type = NL80211_KEYTYPE_PAIRWISE;
  2775. else
  2776. key.type = NL80211_KEYTYPE_GROUP;
  2777. }
  2778. /* for now */
  2779. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  2780. key.type != NL80211_KEYTYPE_GROUP)
  2781. return -EINVAL;
  2782. if (!rdev->ops->add_key)
  2783. return -EOPNOTSUPP;
  2784. if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
  2785. key.type == NL80211_KEYTYPE_PAIRWISE,
  2786. mac_addr))
  2787. return -EINVAL;
  2788. wdev_lock(dev->ieee80211_ptr);
  2789. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2790. if (!err)
  2791. err = rdev_add_key(rdev, dev, key.idx,
  2792. key.type == NL80211_KEYTYPE_PAIRWISE,
  2793. mac_addr, &key.p);
  2794. wdev_unlock(dev->ieee80211_ptr);
  2795. return err;
  2796. }
  2797. static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
  2798. {
  2799. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2800. int err;
  2801. struct net_device *dev = info->user_ptr[1];
  2802. u8 *mac_addr = NULL;
  2803. struct key_parse key;
  2804. err = nl80211_parse_key(info, &key);
  2805. if (err)
  2806. return err;
  2807. if (info->attrs[NL80211_ATTR_MAC])
  2808. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  2809. if (key.type == -1) {
  2810. if (mac_addr)
  2811. key.type = NL80211_KEYTYPE_PAIRWISE;
  2812. else
  2813. key.type = NL80211_KEYTYPE_GROUP;
  2814. }
  2815. /* for now */
  2816. if (key.type != NL80211_KEYTYPE_PAIRWISE &&
  2817. key.type != NL80211_KEYTYPE_GROUP)
  2818. return -EINVAL;
  2819. if (!rdev->ops->del_key)
  2820. return -EOPNOTSUPP;
  2821. wdev_lock(dev->ieee80211_ptr);
  2822. err = nl80211_key_allowed(dev->ieee80211_ptr);
  2823. if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
  2824. !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
  2825. err = -ENOENT;
  2826. if (!err)
  2827. err = rdev_del_key(rdev, dev, key.idx,
  2828. key.type == NL80211_KEYTYPE_PAIRWISE,
  2829. mac_addr);
  2830. #ifdef CONFIG_CFG80211_WEXT
  2831. if (!err) {
  2832. if (key.idx == dev->ieee80211_ptr->wext.default_key)
  2833. dev->ieee80211_ptr->wext.default_key = -1;
  2834. else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
  2835. dev->ieee80211_ptr->wext.default_mgmt_key = -1;
  2836. }
  2837. #endif
  2838. wdev_unlock(dev->ieee80211_ptr);
  2839. return err;
  2840. }
  2841. /* This function returns an error or the number of nested attributes */
  2842. static int validate_acl_mac_addrs(struct nlattr *nl_attr)
  2843. {
  2844. struct nlattr *attr;
  2845. int n_entries = 0, tmp;
  2846. nla_for_each_nested(attr, nl_attr, tmp) {
  2847. if (nla_len(attr) != ETH_ALEN)
  2848. return -EINVAL;
  2849. n_entries++;
  2850. }
  2851. return n_entries;
  2852. }
  2853. /*
  2854. * This function parses ACL information and allocates memory for ACL data.
  2855. * On successful return, the calling function is responsible to free the
  2856. * ACL buffer returned by this function.
  2857. */
  2858. static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
  2859. struct genl_info *info)
  2860. {
  2861. enum nl80211_acl_policy acl_policy;
  2862. struct nlattr *attr;
  2863. struct cfg80211_acl_data *acl;
  2864. int i = 0, n_entries, tmp;
  2865. if (!wiphy->max_acl_mac_addrs)
  2866. return ERR_PTR(-EOPNOTSUPP);
  2867. if (!info->attrs[NL80211_ATTR_ACL_POLICY])
  2868. return ERR_PTR(-EINVAL);
  2869. acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
  2870. if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
  2871. acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
  2872. return ERR_PTR(-EINVAL);
  2873. if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
  2874. return ERR_PTR(-EINVAL);
  2875. n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
  2876. if (n_entries < 0)
  2877. return ERR_PTR(n_entries);
  2878. if (n_entries > wiphy->max_acl_mac_addrs)
  2879. return ERR_PTR(-ENOTSUPP);
  2880. acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
  2881. GFP_KERNEL);
  2882. if (!acl)
  2883. return ERR_PTR(-ENOMEM);
  2884. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
  2885. memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
  2886. i++;
  2887. }
  2888. acl->n_acl_entries = n_entries;
  2889. acl->acl_policy = acl_policy;
  2890. return acl;
  2891. }
  2892. static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
  2893. {
  2894. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  2895. struct net_device *dev = info->user_ptr[1];
  2896. struct cfg80211_acl_data *acl;
  2897. int err;
  2898. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  2899. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  2900. return -EOPNOTSUPP;
  2901. if (!dev->ieee80211_ptr->beacon_interval)
  2902. return -EINVAL;
  2903. acl = parse_acl_data(&rdev->wiphy, info);
  2904. if (IS_ERR(acl))
  2905. return PTR_ERR(acl);
  2906. err = rdev_set_mac_acl(rdev, dev, acl);
  2907. kfree(acl);
  2908. return err;
  2909. }
  2910. static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
  2911. u8 *rates, u8 rates_len)
  2912. {
  2913. u8 i;
  2914. u32 mask = 0;
  2915. for (i = 0; i < rates_len; i++) {
  2916. int rate = (rates[i] & 0x7f) * 5;
  2917. int ridx;
  2918. for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
  2919. struct ieee80211_rate *srate =
  2920. &sband->bitrates[ridx];
  2921. if (rate == srate->bitrate) {
  2922. mask |= 1 << ridx;
  2923. break;
  2924. }
  2925. }
  2926. if (ridx == sband->n_bitrates)
  2927. return 0; /* rate not found */
  2928. }
  2929. return mask;
  2930. }
  2931. static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
  2932. u8 *rates, u8 rates_len,
  2933. u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
  2934. {
  2935. u8 i;
  2936. memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
  2937. for (i = 0; i < rates_len; i++) {
  2938. int ridx, rbit;
  2939. ridx = rates[i] / 8;
  2940. rbit = BIT(rates[i] % 8);
  2941. /* check validity */
  2942. if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
  2943. return false;
  2944. /* check availability */
  2945. ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
  2946. if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
  2947. mcs[ridx] |= rbit;
  2948. else
  2949. return false;
  2950. }
  2951. return true;
  2952. }
  2953. static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
  2954. {
  2955. u16 mcs_mask = 0;
  2956. switch (vht_mcs_map) {
  2957. case IEEE80211_VHT_MCS_NOT_SUPPORTED:
  2958. break;
  2959. case IEEE80211_VHT_MCS_SUPPORT_0_7:
  2960. mcs_mask = 0x00FF;
  2961. break;
  2962. case IEEE80211_VHT_MCS_SUPPORT_0_8:
  2963. mcs_mask = 0x01FF;
  2964. break;
  2965. case IEEE80211_VHT_MCS_SUPPORT_0_9:
  2966. mcs_mask = 0x03FF;
  2967. break;
  2968. default:
  2969. break;
  2970. }
  2971. return mcs_mask;
  2972. }
  2973. static void vht_build_mcs_mask(u16 vht_mcs_map,
  2974. u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
  2975. {
  2976. u8 nss;
  2977. for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
  2978. vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
  2979. vht_mcs_map >>= 2;
  2980. }
  2981. }
  2982. static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
  2983. struct nl80211_txrate_vht *txrate,
  2984. u16 mcs[NL80211_VHT_NSS_MAX])
  2985. {
  2986. u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  2987. u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
  2988. u8 i;
  2989. if (!sband->vht_cap.vht_supported)
  2990. return false;
  2991. memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
  2992. /* Build vht_mcs_mask from VHT capabilities */
  2993. vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
  2994. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  2995. if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
  2996. mcs[i] = txrate->mcs[i];
  2997. else
  2998. return false;
  2999. }
  3000. return true;
  3001. }
  3002. static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
  3003. [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
  3004. .len = NL80211_MAX_SUPP_RATES },
  3005. [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
  3006. .len = NL80211_MAX_SUPP_HT_RATES },
  3007. [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
  3008. [NL80211_TXRATE_GI] = { .type = NLA_U8 },
  3009. };
  3010. static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
  3011. struct cfg80211_bitrate_mask *mask)
  3012. {
  3013. struct nlattr *tb[NL80211_TXRATE_MAX + 1];
  3014. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3015. int rem, i;
  3016. struct nlattr *tx_rates;
  3017. struct ieee80211_supported_band *sband;
  3018. u16 vht_tx_mcs_map;
  3019. memset(mask, 0, sizeof(*mask));
  3020. /* Default to all rates enabled */
  3021. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  3022. sband = rdev->wiphy.bands[i];
  3023. if (!sband)
  3024. continue;
  3025. mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
  3026. memcpy(mask->control[i].ht_mcs,
  3027. sband->ht_cap.mcs.rx_mask,
  3028. sizeof(mask->control[i].ht_mcs));
  3029. if (!sband->vht_cap.vht_supported)
  3030. continue;
  3031. vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
  3032. vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
  3033. }
  3034. /* if no rates are given set it back to the defaults */
  3035. if (!info->attrs[NL80211_ATTR_TX_RATES])
  3036. goto out;
  3037. /* The nested attribute uses enum nl80211_band as the index. This maps
  3038. * directly to the enum nl80211_band values used in cfg80211.
  3039. */
  3040. BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
  3041. nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
  3042. enum nl80211_band band = nla_type(tx_rates);
  3043. int err;
  3044. if (band < 0 || band >= NUM_NL80211_BANDS)
  3045. return -EINVAL;
  3046. sband = rdev->wiphy.bands[band];
  3047. if (sband == NULL)
  3048. return -EINVAL;
  3049. err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
  3050. nla_len(tx_rates), nl80211_txattr_policy);
  3051. if (err)
  3052. return err;
  3053. if (tb[NL80211_TXRATE_LEGACY]) {
  3054. mask->control[band].legacy = rateset_to_mask(
  3055. sband,
  3056. nla_data(tb[NL80211_TXRATE_LEGACY]),
  3057. nla_len(tb[NL80211_TXRATE_LEGACY]));
  3058. if ((mask->control[band].legacy == 0) &&
  3059. nla_len(tb[NL80211_TXRATE_LEGACY]))
  3060. return -EINVAL;
  3061. }
  3062. if (tb[NL80211_TXRATE_HT]) {
  3063. if (!ht_rateset_to_mask(
  3064. sband,
  3065. nla_data(tb[NL80211_TXRATE_HT]),
  3066. nla_len(tb[NL80211_TXRATE_HT]),
  3067. mask->control[band].ht_mcs))
  3068. return -EINVAL;
  3069. }
  3070. if (tb[NL80211_TXRATE_VHT]) {
  3071. if (!vht_set_mcs_mask(
  3072. sband,
  3073. nla_data(tb[NL80211_TXRATE_VHT]),
  3074. mask->control[band].vht_mcs))
  3075. return -EINVAL;
  3076. }
  3077. if (tb[NL80211_TXRATE_GI]) {
  3078. mask->control[band].gi =
  3079. nla_get_u8(tb[NL80211_TXRATE_GI]);
  3080. if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
  3081. return -EINVAL;
  3082. }
  3083. if (mask->control[band].legacy == 0) {
  3084. /* don't allow empty legacy rates if HT or VHT
  3085. * are not even supported.
  3086. */
  3087. if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
  3088. rdev->wiphy.bands[band]->vht_cap.vht_supported))
  3089. return -EINVAL;
  3090. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
  3091. if (mask->control[band].ht_mcs[i])
  3092. goto out;
  3093. for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
  3094. if (mask->control[band].vht_mcs[i])
  3095. goto out;
  3096. /* legacy and mcs rates may not be both empty */
  3097. return -EINVAL;
  3098. }
  3099. }
  3100. out:
  3101. return 0;
  3102. }
  3103. static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
  3104. enum nl80211_band band,
  3105. struct cfg80211_bitrate_mask *beacon_rate)
  3106. {
  3107. u32 count_ht, count_vht, i;
  3108. u32 rate = beacon_rate->control[band].legacy;
  3109. /* Allow only one rate */
  3110. if (hweight32(rate) > 1)
  3111. return -EINVAL;
  3112. count_ht = 0;
  3113. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  3114. if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
  3115. return -EINVAL;
  3116. } else if (beacon_rate->control[band].ht_mcs[i]) {
  3117. count_ht++;
  3118. if (count_ht > 1)
  3119. return -EINVAL;
  3120. }
  3121. if (count_ht && rate)
  3122. return -EINVAL;
  3123. }
  3124. count_vht = 0;
  3125. for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
  3126. if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
  3127. return -EINVAL;
  3128. } else if (beacon_rate->control[band].vht_mcs[i]) {
  3129. count_vht++;
  3130. if (count_vht > 1)
  3131. return -EINVAL;
  3132. }
  3133. if (count_vht && rate)
  3134. return -EINVAL;
  3135. }
  3136. if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
  3137. return -EINVAL;
  3138. if (rate &&
  3139. !wiphy_ext_feature_isset(&rdev->wiphy,
  3140. NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
  3141. return -EINVAL;
  3142. if (count_ht &&
  3143. !wiphy_ext_feature_isset(&rdev->wiphy,
  3144. NL80211_EXT_FEATURE_BEACON_RATE_HT))
  3145. return -EINVAL;
  3146. if (count_vht &&
  3147. !wiphy_ext_feature_isset(&rdev->wiphy,
  3148. NL80211_EXT_FEATURE_BEACON_RATE_VHT))
  3149. return -EINVAL;
  3150. return 0;
  3151. }
  3152. static int nl80211_parse_beacon(struct nlattr *attrs[],
  3153. struct cfg80211_beacon_data *bcn)
  3154. {
  3155. bool haveinfo = false;
  3156. if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
  3157. !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
  3158. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
  3159. !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
  3160. return -EINVAL;
  3161. memset(bcn, 0, sizeof(*bcn));
  3162. if (attrs[NL80211_ATTR_BEACON_HEAD]) {
  3163. int ret = validate_beacon_head(attrs[NL80211_ATTR_BEACON_HEAD]);
  3164. if (ret)
  3165. return ret;
  3166. bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
  3167. bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
  3168. if (!bcn->head_len)
  3169. return -EINVAL;
  3170. haveinfo = true;
  3171. }
  3172. if (attrs[NL80211_ATTR_BEACON_TAIL]) {
  3173. bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
  3174. bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
  3175. haveinfo = true;
  3176. }
  3177. if (!haveinfo)
  3178. return -EINVAL;
  3179. if (attrs[NL80211_ATTR_IE]) {
  3180. bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
  3181. bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
  3182. }
  3183. if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
  3184. bcn->proberesp_ies =
  3185. nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  3186. bcn->proberesp_ies_len =
  3187. nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
  3188. }
  3189. if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
  3190. bcn->assocresp_ies =
  3191. nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  3192. bcn->assocresp_ies_len =
  3193. nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
  3194. }
  3195. if (attrs[NL80211_ATTR_PROBE_RESP]) {
  3196. bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
  3197. bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
  3198. }
  3199. return 0;
  3200. }
  3201. static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
  3202. struct cfg80211_ap_settings *params)
  3203. {
  3204. struct wireless_dev *wdev;
  3205. bool ret = false;
  3206. list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
  3207. if (wdev->iftype != NL80211_IFTYPE_AP &&
  3208. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  3209. continue;
  3210. if (!wdev->preset_chandef.chan)
  3211. continue;
  3212. params->chandef = wdev->preset_chandef;
  3213. ret = true;
  3214. break;
  3215. }
  3216. return ret;
  3217. }
  3218. static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
  3219. enum nl80211_auth_type auth_type,
  3220. enum nl80211_commands cmd)
  3221. {
  3222. if (auth_type > NL80211_AUTHTYPE_MAX)
  3223. return false;
  3224. switch (cmd) {
  3225. case NL80211_CMD_AUTHENTICATE:
  3226. if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
  3227. auth_type == NL80211_AUTHTYPE_SAE)
  3228. return false;
  3229. if (!wiphy_ext_feature_isset(&rdev->wiphy,
  3230. NL80211_EXT_FEATURE_FILS_STA) &&
  3231. (auth_type == NL80211_AUTHTYPE_FILS_SK ||
  3232. auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
  3233. auth_type == NL80211_AUTHTYPE_FILS_PK))
  3234. return false;
  3235. return true;
  3236. case NL80211_CMD_CONNECT:
  3237. if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
  3238. auth_type == NL80211_AUTHTYPE_SAE)
  3239. return false;
  3240. /* FILS with SK PFS or PK not supported yet */
  3241. if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
  3242. auth_type == NL80211_AUTHTYPE_FILS_PK)
  3243. return false;
  3244. if (!wiphy_ext_feature_isset(
  3245. &rdev->wiphy,
  3246. NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
  3247. auth_type == NL80211_AUTHTYPE_FILS_SK)
  3248. return false;
  3249. return true;
  3250. case NL80211_CMD_START_AP:
  3251. /* SAE not supported yet */
  3252. if (auth_type == NL80211_AUTHTYPE_SAE)
  3253. return false;
  3254. /* FILS not supported yet */
  3255. if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
  3256. auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
  3257. auth_type == NL80211_AUTHTYPE_FILS_PK)
  3258. return false;
  3259. return true;
  3260. default:
  3261. return false;
  3262. }
  3263. }
  3264. static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
  3265. {
  3266. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3267. struct net_device *dev = info->user_ptr[1];
  3268. struct wireless_dev *wdev = dev->ieee80211_ptr;
  3269. struct cfg80211_ap_settings params;
  3270. int err;
  3271. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3272. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3273. return -EOPNOTSUPP;
  3274. if (!rdev->ops->start_ap)
  3275. return -EOPNOTSUPP;
  3276. if (wdev->beacon_interval)
  3277. return -EALREADY;
  3278. memset(&params, 0, sizeof(params));
  3279. /* these are required for START_AP */
  3280. if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
  3281. !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
  3282. !info->attrs[NL80211_ATTR_BEACON_HEAD])
  3283. return -EINVAL;
  3284. err = nl80211_parse_beacon(info->attrs, &params.beacon);
  3285. if (err)
  3286. return err;
  3287. params.beacon_interval =
  3288. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  3289. params.dtim_period =
  3290. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  3291. err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
  3292. params.beacon_interval);
  3293. if (err)
  3294. return err;
  3295. /*
  3296. * In theory, some of these attributes should be required here
  3297. * but since they were not used when the command was originally
  3298. * added, keep them optional for old user space programs to let
  3299. * them continue to work with drivers that do not need the
  3300. * additional information -- drivers must check!
  3301. */
  3302. if (info->attrs[NL80211_ATTR_SSID]) {
  3303. params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  3304. params.ssid_len =
  3305. nla_len(info->attrs[NL80211_ATTR_SSID]);
  3306. if (params.ssid_len == 0 ||
  3307. params.ssid_len > IEEE80211_MAX_SSID_LEN)
  3308. return -EINVAL;
  3309. }
  3310. if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
  3311. params.hidden_ssid = nla_get_u32(
  3312. info->attrs[NL80211_ATTR_HIDDEN_SSID]);
  3313. if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
  3314. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
  3315. params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
  3316. return -EINVAL;
  3317. }
  3318. params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  3319. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  3320. params.auth_type = nla_get_u32(
  3321. info->attrs[NL80211_ATTR_AUTH_TYPE]);
  3322. if (!nl80211_valid_auth_type(rdev, params.auth_type,
  3323. NL80211_CMD_START_AP))
  3324. return -EINVAL;
  3325. } else
  3326. params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  3327. err = nl80211_crypto_settings(rdev, info, &params.crypto,
  3328. NL80211_MAX_NR_CIPHER_SUITES);
  3329. if (err)
  3330. return err;
  3331. if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
  3332. if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
  3333. return -EOPNOTSUPP;
  3334. params.inactivity_timeout = nla_get_u16(
  3335. info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
  3336. }
  3337. if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
  3338. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3339. return -EINVAL;
  3340. params.p2p_ctwindow =
  3341. nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
  3342. if (params.p2p_ctwindow > 127)
  3343. return -EINVAL;
  3344. if (params.p2p_ctwindow != 0 &&
  3345. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
  3346. return -EINVAL;
  3347. }
  3348. if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
  3349. u8 tmp;
  3350. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3351. return -EINVAL;
  3352. tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
  3353. if (tmp > 1)
  3354. return -EINVAL;
  3355. params.p2p_opp_ps = tmp;
  3356. if (params.p2p_opp_ps != 0 &&
  3357. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
  3358. return -EINVAL;
  3359. }
  3360. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  3361. err = nl80211_parse_chandef(rdev, info, &params.chandef);
  3362. if (err)
  3363. return err;
  3364. } else if (wdev->preset_chandef.chan) {
  3365. params.chandef = wdev->preset_chandef;
  3366. } else if (!nl80211_get_ap_channel(rdev, &params))
  3367. return -EINVAL;
  3368. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
  3369. wdev->iftype))
  3370. return -EINVAL;
  3371. if (info->attrs[NL80211_ATTR_TX_RATES]) {
  3372. err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
  3373. if (err)
  3374. return err;
  3375. err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
  3376. &params.beacon_rate);
  3377. if (err)
  3378. return err;
  3379. }
  3380. if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
  3381. params.smps_mode =
  3382. nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
  3383. switch (params.smps_mode) {
  3384. case NL80211_SMPS_OFF:
  3385. break;
  3386. case NL80211_SMPS_STATIC:
  3387. if (!(rdev->wiphy.features &
  3388. NL80211_FEATURE_STATIC_SMPS))
  3389. return -EINVAL;
  3390. break;
  3391. case NL80211_SMPS_DYNAMIC:
  3392. if (!(rdev->wiphy.features &
  3393. NL80211_FEATURE_DYNAMIC_SMPS))
  3394. return -EINVAL;
  3395. break;
  3396. default:
  3397. return -EINVAL;
  3398. }
  3399. } else {
  3400. params.smps_mode = NL80211_SMPS_OFF;
  3401. }
  3402. params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
  3403. if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
  3404. return -EOPNOTSUPP;
  3405. if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
  3406. params.acl = parse_acl_data(&rdev->wiphy, info);
  3407. if (IS_ERR(params.acl))
  3408. return PTR_ERR(params.acl);
  3409. }
  3410. wdev_lock(wdev);
  3411. err = rdev_start_ap(rdev, dev, &params);
  3412. if (!err) {
  3413. wdev->preset_chandef = params.chandef;
  3414. wdev->beacon_interval = params.beacon_interval;
  3415. wdev->chandef = params.chandef;
  3416. wdev->ssid_len = params.ssid_len;
  3417. memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
  3418. }
  3419. wdev_unlock(wdev);
  3420. kfree(params.acl);
  3421. return err;
  3422. }
  3423. static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
  3424. {
  3425. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3426. struct net_device *dev = info->user_ptr[1];
  3427. struct wireless_dev *wdev = dev->ieee80211_ptr;
  3428. struct cfg80211_beacon_data params;
  3429. int err;
  3430. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3431. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  3432. return -EOPNOTSUPP;
  3433. if (!rdev->ops->change_beacon)
  3434. return -EOPNOTSUPP;
  3435. if (!wdev->beacon_interval)
  3436. return -EINVAL;
  3437. err = nl80211_parse_beacon(info->attrs, &params);
  3438. if (err)
  3439. return err;
  3440. wdev_lock(wdev);
  3441. err = rdev_change_beacon(rdev, dev, &params);
  3442. wdev_unlock(wdev);
  3443. return err;
  3444. }
  3445. static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
  3446. {
  3447. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3448. struct net_device *dev = info->user_ptr[1];
  3449. return cfg80211_stop_ap(rdev, dev, false);
  3450. }
  3451. static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
  3452. [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
  3453. [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
  3454. [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
  3455. [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
  3456. [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
  3457. [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
  3458. };
  3459. static int parse_station_flags(struct genl_info *info,
  3460. enum nl80211_iftype iftype,
  3461. struct station_parameters *params)
  3462. {
  3463. struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
  3464. struct nlattr *nla;
  3465. int flag;
  3466. /*
  3467. * Try parsing the new attribute first so userspace
  3468. * can specify both for older kernels.
  3469. */
  3470. nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
  3471. if (nla) {
  3472. struct nl80211_sta_flag_update *sta_flags;
  3473. sta_flags = nla_data(nla);
  3474. params->sta_flags_mask = sta_flags->mask;
  3475. params->sta_flags_set = sta_flags->set;
  3476. params->sta_flags_set &= params->sta_flags_mask;
  3477. if ((params->sta_flags_mask |
  3478. params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
  3479. return -EINVAL;
  3480. return 0;
  3481. }
  3482. /* if present, parse the old attribute */
  3483. nla = info->attrs[NL80211_ATTR_STA_FLAGS];
  3484. if (!nla)
  3485. return 0;
  3486. if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
  3487. nla, sta_flags_policy))
  3488. return -EINVAL;
  3489. /*
  3490. * Only allow certain flags for interface types so that
  3491. * other attributes are silently ignored. Remember that
  3492. * this is backward compatibility code with old userspace
  3493. * and shouldn't be hit in other cases anyway.
  3494. */
  3495. switch (iftype) {
  3496. case NL80211_IFTYPE_AP:
  3497. case NL80211_IFTYPE_AP_VLAN:
  3498. case NL80211_IFTYPE_P2P_GO:
  3499. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3500. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  3501. BIT(NL80211_STA_FLAG_WME) |
  3502. BIT(NL80211_STA_FLAG_MFP);
  3503. break;
  3504. case NL80211_IFTYPE_P2P_CLIENT:
  3505. case NL80211_IFTYPE_STATION:
  3506. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3507. BIT(NL80211_STA_FLAG_TDLS_PEER);
  3508. break;
  3509. case NL80211_IFTYPE_MESH_POINT:
  3510. params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3511. BIT(NL80211_STA_FLAG_MFP) |
  3512. BIT(NL80211_STA_FLAG_AUTHORIZED);
  3513. break;
  3514. default:
  3515. return -EINVAL;
  3516. }
  3517. for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
  3518. if (flags[flag]) {
  3519. params->sta_flags_set |= (1<<flag);
  3520. /* no longer support new API additions in old API */
  3521. if (flag > NL80211_STA_FLAG_MAX_OLD_API)
  3522. return -EINVAL;
  3523. }
  3524. }
  3525. return 0;
  3526. }
  3527. static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
  3528. int attr)
  3529. {
  3530. struct nlattr *rate;
  3531. u32 bitrate;
  3532. u16 bitrate_compat;
  3533. enum nl80211_rate_info rate_flg;
  3534. rate = nla_nest_start(msg, attr);
  3535. if (!rate)
  3536. return false;
  3537. /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
  3538. bitrate = cfg80211_calculate_bitrate(info);
  3539. /* report 16-bit bitrate only if we can */
  3540. bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
  3541. if (bitrate > 0 &&
  3542. nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
  3543. return false;
  3544. if (bitrate_compat > 0 &&
  3545. nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
  3546. return false;
  3547. switch (info->bw) {
  3548. case RATE_INFO_BW_5:
  3549. rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
  3550. break;
  3551. case RATE_INFO_BW_10:
  3552. rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
  3553. break;
  3554. default:
  3555. WARN_ON(1);
  3556. /* fall through */
  3557. case RATE_INFO_BW_20:
  3558. rate_flg = 0;
  3559. break;
  3560. case RATE_INFO_BW_40:
  3561. rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
  3562. break;
  3563. case RATE_INFO_BW_80:
  3564. rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
  3565. break;
  3566. case RATE_INFO_BW_160:
  3567. rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
  3568. break;
  3569. }
  3570. if (rate_flg && nla_put_flag(msg, rate_flg))
  3571. return false;
  3572. if (info->flags & RATE_INFO_FLAGS_MCS) {
  3573. if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
  3574. return false;
  3575. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  3576. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  3577. return false;
  3578. } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
  3579. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
  3580. return false;
  3581. if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
  3582. return false;
  3583. if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
  3584. nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
  3585. return false;
  3586. }
  3587. nla_nest_end(msg, rate);
  3588. return true;
  3589. }
  3590. static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
  3591. int id)
  3592. {
  3593. void *attr;
  3594. int i = 0;
  3595. if (!mask)
  3596. return true;
  3597. attr = nla_nest_start(msg, id);
  3598. if (!attr)
  3599. return false;
  3600. for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
  3601. if (!(mask & BIT(i)))
  3602. continue;
  3603. if (nla_put_u8(msg, i, signal[i]))
  3604. return false;
  3605. }
  3606. nla_nest_end(msg, attr);
  3607. return true;
  3608. }
  3609. static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
  3610. u32 seq, int flags,
  3611. struct cfg80211_registered_device *rdev,
  3612. struct net_device *dev,
  3613. const u8 *mac_addr, struct station_info *sinfo)
  3614. {
  3615. void *hdr;
  3616. struct nlattr *sinfoattr, *bss_param;
  3617. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  3618. if (!hdr)
  3619. return -1;
  3620. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  3621. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
  3622. nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
  3623. goto nla_put_failure;
  3624. sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
  3625. if (!sinfoattr)
  3626. goto nla_put_failure;
  3627. #define PUT_SINFO(attr, memb, type) do { \
  3628. BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
  3629. if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
  3630. nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
  3631. sinfo->memb)) \
  3632. goto nla_put_failure; \
  3633. } while (0)
  3634. #define PUT_SINFO_U64(attr, memb) do { \
  3635. if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
  3636. nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
  3637. sinfo->memb, NL80211_STA_INFO_PAD)) \
  3638. goto nla_put_failure; \
  3639. } while (0)
  3640. PUT_SINFO(CONNECTED_TIME, connected_time, u32);
  3641. PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
  3642. if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
  3643. BIT(NL80211_STA_INFO_RX_BYTES64)) &&
  3644. nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
  3645. (u32)sinfo->rx_bytes))
  3646. goto nla_put_failure;
  3647. if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
  3648. BIT(NL80211_STA_INFO_TX_BYTES64)) &&
  3649. nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
  3650. (u32)sinfo->tx_bytes))
  3651. goto nla_put_failure;
  3652. PUT_SINFO_U64(RX_BYTES64, rx_bytes);
  3653. PUT_SINFO_U64(TX_BYTES64, tx_bytes);
  3654. PUT_SINFO(LLID, llid, u16);
  3655. PUT_SINFO(PLID, plid, u16);
  3656. PUT_SINFO(PLINK_STATE, plink_state, u8);
  3657. PUT_SINFO_U64(RX_DURATION, rx_duration);
  3658. switch (rdev->wiphy.signal_type) {
  3659. case CFG80211_SIGNAL_TYPE_MBM:
  3660. PUT_SINFO(SIGNAL, signal, u8);
  3661. PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
  3662. break;
  3663. default:
  3664. break;
  3665. }
  3666. if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
  3667. if (!nl80211_put_signal(msg, sinfo->chains,
  3668. sinfo->chain_signal,
  3669. NL80211_STA_INFO_CHAIN_SIGNAL))
  3670. goto nla_put_failure;
  3671. }
  3672. if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
  3673. if (!nl80211_put_signal(msg, sinfo->chains,
  3674. sinfo->chain_signal_avg,
  3675. NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
  3676. goto nla_put_failure;
  3677. }
  3678. if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
  3679. if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
  3680. NL80211_STA_INFO_TX_BITRATE))
  3681. goto nla_put_failure;
  3682. }
  3683. if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
  3684. if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
  3685. NL80211_STA_INFO_RX_BITRATE))
  3686. goto nla_put_failure;
  3687. }
  3688. PUT_SINFO(RX_PACKETS, rx_packets, u32);
  3689. PUT_SINFO(TX_PACKETS, tx_packets, u32);
  3690. PUT_SINFO(TX_RETRIES, tx_retries, u32);
  3691. PUT_SINFO(TX_FAILED, tx_failed, u32);
  3692. PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
  3693. PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
  3694. PUT_SINFO(LOCAL_PM, local_pm, u32);
  3695. PUT_SINFO(PEER_PM, peer_pm, u32);
  3696. PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
  3697. if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
  3698. bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
  3699. if (!bss_param)
  3700. goto nla_put_failure;
  3701. if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
  3702. nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
  3703. ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
  3704. nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
  3705. ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
  3706. nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
  3707. nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
  3708. sinfo->bss_param.dtim_period) ||
  3709. nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
  3710. sinfo->bss_param.beacon_interval))
  3711. goto nla_put_failure;
  3712. nla_nest_end(msg, bss_param);
  3713. }
  3714. if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
  3715. nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
  3716. sizeof(struct nl80211_sta_flag_update),
  3717. &sinfo->sta_flags))
  3718. goto nla_put_failure;
  3719. PUT_SINFO_U64(T_OFFSET, t_offset);
  3720. PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
  3721. PUT_SINFO_U64(BEACON_RX, rx_beacon);
  3722. PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
  3723. #undef PUT_SINFO
  3724. #undef PUT_SINFO_U64
  3725. if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
  3726. struct nlattr *tidsattr;
  3727. int tid;
  3728. tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
  3729. if (!tidsattr)
  3730. goto nla_put_failure;
  3731. for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
  3732. struct cfg80211_tid_stats *tidstats;
  3733. struct nlattr *tidattr;
  3734. tidstats = &sinfo->pertid[tid];
  3735. if (!tidstats->filled)
  3736. continue;
  3737. tidattr = nla_nest_start(msg, tid + 1);
  3738. if (!tidattr)
  3739. goto nla_put_failure;
  3740. #define PUT_TIDVAL_U64(attr, memb) do { \
  3741. if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
  3742. nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
  3743. tidstats->memb, NL80211_TID_STATS_PAD)) \
  3744. goto nla_put_failure; \
  3745. } while (0)
  3746. PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
  3747. PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
  3748. PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
  3749. PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
  3750. #undef PUT_TIDVAL_U64
  3751. nla_nest_end(msg, tidattr);
  3752. }
  3753. nla_nest_end(msg, tidsattr);
  3754. }
  3755. nla_nest_end(msg, sinfoattr);
  3756. if (sinfo->assoc_req_ies_len &&
  3757. nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
  3758. sinfo->assoc_req_ies))
  3759. goto nla_put_failure;
  3760. genlmsg_end(msg, hdr);
  3761. return 0;
  3762. nla_put_failure:
  3763. genlmsg_cancel(msg, hdr);
  3764. return -EMSGSIZE;
  3765. }
  3766. static int nl80211_dump_station(struct sk_buff *skb,
  3767. struct netlink_callback *cb)
  3768. {
  3769. struct station_info sinfo;
  3770. struct cfg80211_registered_device *rdev;
  3771. struct wireless_dev *wdev;
  3772. u8 mac_addr[ETH_ALEN];
  3773. int sta_idx = cb->args[2];
  3774. int err;
  3775. rtnl_lock();
  3776. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  3777. if (err)
  3778. goto out_err;
  3779. if (!wdev->netdev) {
  3780. err = -EINVAL;
  3781. goto out_err;
  3782. }
  3783. if (!rdev->ops->dump_station) {
  3784. err = -EOPNOTSUPP;
  3785. goto out_err;
  3786. }
  3787. while (1) {
  3788. memset(&sinfo, 0, sizeof(sinfo));
  3789. err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
  3790. mac_addr, &sinfo);
  3791. if (err == -ENOENT)
  3792. break;
  3793. if (err)
  3794. goto out_err;
  3795. if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
  3796. NETLINK_CB(cb->skb).portid,
  3797. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  3798. rdev, wdev->netdev, mac_addr,
  3799. &sinfo) < 0)
  3800. goto out;
  3801. sta_idx++;
  3802. }
  3803. out:
  3804. cb->args[2] = sta_idx;
  3805. err = skb->len;
  3806. out_err:
  3807. rtnl_unlock();
  3808. return err;
  3809. }
  3810. static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
  3811. {
  3812. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  3813. struct net_device *dev = info->user_ptr[1];
  3814. struct station_info sinfo;
  3815. struct sk_buff *msg;
  3816. u8 *mac_addr = NULL;
  3817. int err;
  3818. memset(&sinfo, 0, sizeof(sinfo));
  3819. if (!info->attrs[NL80211_ATTR_MAC])
  3820. return -EINVAL;
  3821. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  3822. if (!rdev->ops->get_station)
  3823. return -EOPNOTSUPP;
  3824. err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
  3825. if (err)
  3826. return err;
  3827. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  3828. if (!msg)
  3829. return -ENOMEM;
  3830. if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
  3831. info->snd_portid, info->snd_seq, 0,
  3832. rdev, dev, mac_addr, &sinfo) < 0) {
  3833. nlmsg_free(msg);
  3834. return -ENOBUFS;
  3835. }
  3836. return genlmsg_reply(msg, info);
  3837. }
  3838. int cfg80211_check_station_change(struct wiphy *wiphy,
  3839. struct station_parameters *params,
  3840. enum cfg80211_station_type statype)
  3841. {
  3842. if (params->listen_interval != -1 &&
  3843. statype != CFG80211_STA_AP_CLIENT_UNASSOC)
  3844. return -EINVAL;
  3845. if (params->support_p2p_ps != -1 &&
  3846. statype != CFG80211_STA_AP_CLIENT_UNASSOC)
  3847. return -EINVAL;
  3848. if (params->aid &&
  3849. !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  3850. statype != CFG80211_STA_AP_CLIENT_UNASSOC)
  3851. return -EINVAL;
  3852. /* When you run into this, adjust the code below for the new flag */
  3853. BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
  3854. switch (statype) {
  3855. case CFG80211_STA_MESH_PEER_KERNEL:
  3856. case CFG80211_STA_MESH_PEER_USER:
  3857. /*
  3858. * No ignoring the TDLS flag here -- the userspace mesh
  3859. * code doesn't have the bug of including TDLS in the
  3860. * mask everywhere.
  3861. */
  3862. if (params->sta_flags_mask &
  3863. ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3864. BIT(NL80211_STA_FLAG_MFP) |
  3865. BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3866. return -EINVAL;
  3867. break;
  3868. case CFG80211_STA_TDLS_PEER_SETUP:
  3869. case CFG80211_STA_TDLS_PEER_ACTIVE:
  3870. if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  3871. return -EINVAL;
  3872. /* ignore since it can't change */
  3873. params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3874. break;
  3875. default:
  3876. /* disallow mesh-specific things */
  3877. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
  3878. return -EINVAL;
  3879. if (params->local_pm)
  3880. return -EINVAL;
  3881. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  3882. return -EINVAL;
  3883. }
  3884. if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
  3885. statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
  3886. /* TDLS can't be set, ... */
  3887. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  3888. return -EINVAL;
  3889. /*
  3890. * ... but don't bother the driver with it. This works around
  3891. * a hostapd/wpa_supplicant issue -- it always includes the
  3892. * TLDS_PEER flag in the mask even for AP mode.
  3893. */
  3894. params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  3895. }
  3896. if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
  3897. statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
  3898. /* reject other things that can't change */
  3899. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
  3900. return -EINVAL;
  3901. if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
  3902. return -EINVAL;
  3903. if (params->supported_rates)
  3904. return -EINVAL;
  3905. if (params->ext_capab || params->ht_capa || params->vht_capa)
  3906. return -EINVAL;
  3907. }
  3908. if (statype != CFG80211_STA_AP_CLIENT &&
  3909. statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
  3910. if (params->vlan)
  3911. return -EINVAL;
  3912. }
  3913. switch (statype) {
  3914. case CFG80211_STA_AP_MLME_CLIENT:
  3915. /* Use this only for authorizing/unauthorizing a station */
  3916. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3917. return -EOPNOTSUPP;
  3918. break;
  3919. case CFG80211_STA_AP_CLIENT:
  3920. case CFG80211_STA_AP_CLIENT_UNASSOC:
  3921. /* accept only the listed bits */
  3922. if (params->sta_flags_mask &
  3923. ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3924. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3925. BIT(NL80211_STA_FLAG_ASSOCIATED) |
  3926. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  3927. BIT(NL80211_STA_FLAG_WME) |
  3928. BIT(NL80211_STA_FLAG_MFP)))
  3929. return -EINVAL;
  3930. /* but authenticated/associated only if driver handles it */
  3931. if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
  3932. params->sta_flags_mask &
  3933. (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  3934. BIT(NL80211_STA_FLAG_ASSOCIATED)))
  3935. return -EINVAL;
  3936. break;
  3937. case CFG80211_STA_IBSS:
  3938. case CFG80211_STA_AP_STA:
  3939. /* reject any changes other than AUTHORIZED */
  3940. if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
  3941. return -EINVAL;
  3942. break;
  3943. case CFG80211_STA_TDLS_PEER_SETUP:
  3944. /* reject any changes other than AUTHORIZED or WME */
  3945. if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
  3946. BIT(NL80211_STA_FLAG_WME)))
  3947. return -EINVAL;
  3948. /* force (at least) rates when authorizing */
  3949. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
  3950. !params->supported_rates)
  3951. return -EINVAL;
  3952. break;
  3953. case CFG80211_STA_TDLS_PEER_ACTIVE:
  3954. /* reject any changes */
  3955. return -EINVAL;
  3956. case CFG80211_STA_MESH_PEER_KERNEL:
  3957. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  3958. return -EINVAL;
  3959. break;
  3960. case CFG80211_STA_MESH_PEER_USER:
  3961. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
  3962. params->plink_action != NL80211_PLINK_ACTION_BLOCK)
  3963. return -EINVAL;
  3964. break;
  3965. }
  3966. return 0;
  3967. }
  3968. EXPORT_SYMBOL(cfg80211_check_station_change);
  3969. /*
  3970. * Get vlan interface making sure it is running and on the right wiphy.
  3971. */
  3972. static struct net_device *get_vlan(struct genl_info *info,
  3973. struct cfg80211_registered_device *rdev)
  3974. {
  3975. struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
  3976. struct net_device *v;
  3977. int ret;
  3978. if (!vlanattr)
  3979. return NULL;
  3980. v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
  3981. if (!v)
  3982. return ERR_PTR(-ENODEV);
  3983. if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
  3984. ret = -EINVAL;
  3985. goto error;
  3986. }
  3987. if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  3988. v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  3989. v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
  3990. ret = -EINVAL;
  3991. goto error;
  3992. }
  3993. if (!netif_running(v)) {
  3994. ret = -ENETDOWN;
  3995. goto error;
  3996. }
  3997. return v;
  3998. error:
  3999. dev_put(v);
  4000. return ERR_PTR(ret);
  4001. }
  4002. static const struct nla_policy
  4003. nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
  4004. [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
  4005. [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
  4006. };
  4007. static int nl80211_parse_sta_wme(struct genl_info *info,
  4008. struct station_parameters *params)
  4009. {
  4010. struct nlattr *tb[NL80211_STA_WME_MAX + 1];
  4011. struct nlattr *nla;
  4012. int err;
  4013. /* parse WME attributes if present */
  4014. if (!info->attrs[NL80211_ATTR_STA_WME])
  4015. return 0;
  4016. nla = info->attrs[NL80211_ATTR_STA_WME];
  4017. err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
  4018. nl80211_sta_wme_policy);
  4019. if (err)
  4020. return err;
  4021. if (tb[NL80211_STA_WME_UAPSD_QUEUES])
  4022. params->uapsd_queues = nla_get_u8(
  4023. tb[NL80211_STA_WME_UAPSD_QUEUES]);
  4024. if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  4025. return -EINVAL;
  4026. if (tb[NL80211_STA_WME_MAX_SP])
  4027. params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
  4028. if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  4029. return -EINVAL;
  4030. params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
  4031. return 0;
  4032. }
  4033. static int nl80211_parse_sta_channel_info(struct genl_info *info,
  4034. struct station_parameters *params)
  4035. {
  4036. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
  4037. params->supported_channels =
  4038. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  4039. params->supported_channels_len =
  4040. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
  4041. /*
  4042. * Need to include at least one (first channel, number of
  4043. * channels) tuple for each subband, and must have proper
  4044. * tuples for the rest of the data as well.
  4045. */
  4046. if (params->supported_channels_len < 2)
  4047. return -EINVAL;
  4048. if (params->supported_channels_len % 2)
  4049. return -EINVAL;
  4050. }
  4051. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
  4052. params->supported_oper_classes =
  4053. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  4054. params->supported_oper_classes_len =
  4055. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
  4056. /*
  4057. * The value of the Length field of the Supported Operating
  4058. * Classes element is between 2 and 253.
  4059. */
  4060. if (params->supported_oper_classes_len < 2 ||
  4061. params->supported_oper_classes_len > 253)
  4062. return -EINVAL;
  4063. }
  4064. return 0;
  4065. }
  4066. static int nl80211_set_station_tdls(struct genl_info *info,
  4067. struct station_parameters *params)
  4068. {
  4069. int err;
  4070. /* Dummy STA entry gets updated once the peer capabilities are known */
  4071. if (info->attrs[NL80211_ATTR_PEER_AID])
  4072. params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  4073. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  4074. params->ht_capa =
  4075. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  4076. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  4077. params->vht_capa =
  4078. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  4079. err = nl80211_parse_sta_channel_info(info, params);
  4080. if (err)
  4081. return err;
  4082. return nl80211_parse_sta_wme(info, params);
  4083. }
  4084. static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
  4085. {
  4086. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4087. struct net_device *dev = info->user_ptr[1];
  4088. struct station_parameters params;
  4089. u8 *mac_addr;
  4090. int err;
  4091. memset(&params, 0, sizeof(params));
  4092. if (!rdev->ops->change_station)
  4093. return -EOPNOTSUPP;
  4094. /*
  4095. * AID and listen_interval properties can be set only for unassociated
  4096. * station. Include these parameters here and will check them in
  4097. * cfg80211_check_station_change().
  4098. */
  4099. if (info->attrs[NL80211_ATTR_STA_AID])
  4100. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
  4101. if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  4102. params.listen_interval =
  4103. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  4104. else
  4105. params.listen_interval = -1;
  4106. if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
  4107. u8 tmp;
  4108. tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
  4109. if (tmp >= NUM_NL80211_P2P_PS_STATUS)
  4110. return -EINVAL;
  4111. params.support_p2p_ps = tmp;
  4112. } else {
  4113. params.support_p2p_ps = -1;
  4114. }
  4115. if (!info->attrs[NL80211_ATTR_MAC])
  4116. return -EINVAL;
  4117. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4118. if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
  4119. params.supported_rates =
  4120. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4121. params.supported_rates_len =
  4122. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4123. }
  4124. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  4125. params.capability =
  4126. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  4127. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  4128. }
  4129. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  4130. params.ext_capab =
  4131. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4132. params.ext_capab_len =
  4133. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4134. }
  4135. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  4136. return -EINVAL;
  4137. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
  4138. params.plink_action =
  4139. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  4140. if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
  4141. return -EINVAL;
  4142. }
  4143. if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
  4144. params.plink_state =
  4145. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
  4146. if (params.plink_state >= NUM_NL80211_PLINK_STATES)
  4147. return -EINVAL;
  4148. if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) {
  4149. params.peer_aid = nla_get_u16(
  4150. info->attrs[NL80211_ATTR_MESH_PEER_AID]);
  4151. if (params.peer_aid > IEEE80211_MAX_AID)
  4152. return -EINVAL;
  4153. }
  4154. params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
  4155. }
  4156. if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
  4157. enum nl80211_mesh_power_mode pm = nla_get_u32(
  4158. info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
  4159. if (pm <= NL80211_MESH_POWER_UNKNOWN ||
  4160. pm > NL80211_MESH_POWER_MAX)
  4161. return -EINVAL;
  4162. params.local_pm = pm;
  4163. }
  4164. /* Include parameters for TDLS peer (will check later) */
  4165. err = nl80211_set_station_tdls(info, &params);
  4166. if (err)
  4167. return err;
  4168. params.vlan = get_vlan(info, rdev);
  4169. if (IS_ERR(params.vlan))
  4170. return PTR_ERR(params.vlan);
  4171. switch (dev->ieee80211_ptr->iftype) {
  4172. case NL80211_IFTYPE_AP:
  4173. case NL80211_IFTYPE_AP_VLAN:
  4174. case NL80211_IFTYPE_P2P_GO:
  4175. case NL80211_IFTYPE_P2P_CLIENT:
  4176. case NL80211_IFTYPE_STATION:
  4177. case NL80211_IFTYPE_ADHOC:
  4178. case NL80211_IFTYPE_MESH_POINT:
  4179. break;
  4180. default:
  4181. err = -EOPNOTSUPP;
  4182. goto out_put_vlan;
  4183. }
  4184. /* driver will call cfg80211_check_station_change() */
  4185. err = rdev_change_station(rdev, dev, mac_addr, &params);
  4186. out_put_vlan:
  4187. if (params.vlan)
  4188. dev_put(params.vlan);
  4189. return err;
  4190. }
  4191. static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
  4192. {
  4193. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4194. int err;
  4195. struct net_device *dev = info->user_ptr[1];
  4196. struct station_parameters params;
  4197. u8 *mac_addr = NULL;
  4198. u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  4199. BIT(NL80211_STA_FLAG_ASSOCIATED);
  4200. memset(&params, 0, sizeof(params));
  4201. if (!rdev->ops->add_station)
  4202. return -EOPNOTSUPP;
  4203. if (!info->attrs[NL80211_ATTR_MAC])
  4204. return -EINVAL;
  4205. if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
  4206. return -EINVAL;
  4207. if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
  4208. return -EINVAL;
  4209. if (!info->attrs[NL80211_ATTR_STA_AID] &&
  4210. !info->attrs[NL80211_ATTR_PEER_AID])
  4211. return -EINVAL;
  4212. mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4213. params.supported_rates =
  4214. nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4215. params.supported_rates_len =
  4216. nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
  4217. params.listen_interval =
  4218. nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
  4219. if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
  4220. u8 tmp;
  4221. tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
  4222. if (tmp >= NUM_NL80211_P2P_PS_STATUS)
  4223. return -EINVAL;
  4224. params.support_p2p_ps = tmp;
  4225. } else {
  4226. /*
  4227. * if not specified, assume it's supported for P2P GO interface,
  4228. * and is NOT supported for AP interface
  4229. */
  4230. params.support_p2p_ps =
  4231. dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
  4232. }
  4233. if (info->attrs[NL80211_ATTR_PEER_AID])
  4234. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
  4235. else
  4236. params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
  4237. if (!params.aid || params.aid > IEEE80211_MAX_AID)
  4238. return -EINVAL;
  4239. if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
  4240. params.capability =
  4241. nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
  4242. params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
  4243. }
  4244. if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
  4245. params.ext_capab =
  4246. nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4247. params.ext_capab_len =
  4248. nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
  4249. }
  4250. if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
  4251. params.ht_capa =
  4252. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
  4253. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
  4254. params.vht_capa =
  4255. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
  4256. if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
  4257. params.opmode_notif_used = true;
  4258. params.opmode_notif =
  4259. nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
  4260. }
  4261. if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
  4262. params.plink_action =
  4263. nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
  4264. if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
  4265. return -EINVAL;
  4266. }
  4267. err = nl80211_parse_sta_channel_info(info, &params);
  4268. if (err)
  4269. return err;
  4270. err = nl80211_parse_sta_wme(info, &params);
  4271. if (err)
  4272. return err;
  4273. if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
  4274. return -EINVAL;
  4275. /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
  4276. * as userspace might just pass through the capabilities from the IEs
  4277. * directly, rather than enforcing this restriction and returning an
  4278. * error in this case.
  4279. */
  4280. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
  4281. params.ht_capa = NULL;
  4282. params.vht_capa = NULL;
  4283. }
  4284. /* When you run into this, adjust the code below for the new flag */
  4285. BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
  4286. switch (dev->ieee80211_ptr->iftype) {
  4287. case NL80211_IFTYPE_AP:
  4288. case NL80211_IFTYPE_AP_VLAN:
  4289. case NL80211_IFTYPE_P2P_GO:
  4290. /* ignore WME attributes if iface/sta is not capable */
  4291. if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
  4292. !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
  4293. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  4294. /* TDLS peers cannot be added */
  4295. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  4296. info->attrs[NL80211_ATTR_PEER_AID])
  4297. return -EINVAL;
  4298. /* but don't bother the driver with it */
  4299. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
  4300. /* allow authenticated/associated only if driver handles it */
  4301. if (!(rdev->wiphy.features &
  4302. NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
  4303. params.sta_flags_mask & auth_assoc)
  4304. return -EINVAL;
  4305. /* Older userspace, or userspace wanting to be compatible with
  4306. * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
  4307. * and assoc flags in the mask, but assumes the station will be
  4308. * added as associated anyway since this was the required driver
  4309. * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
  4310. * introduced.
  4311. * In order to not bother drivers with this quirk in the API
  4312. * set the flags in both the mask and set for new stations in
  4313. * this case.
  4314. */
  4315. if (!(params.sta_flags_mask & auth_assoc)) {
  4316. params.sta_flags_mask |= auth_assoc;
  4317. params.sta_flags_set |= auth_assoc;
  4318. }
  4319. /* must be last in here for error handling */
  4320. params.vlan = get_vlan(info, rdev);
  4321. if (IS_ERR(params.vlan))
  4322. return PTR_ERR(params.vlan);
  4323. break;
  4324. case NL80211_IFTYPE_MESH_POINT:
  4325. /* ignore uAPSD data */
  4326. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  4327. /* associated is disallowed */
  4328. if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
  4329. return -EINVAL;
  4330. /* TDLS peers cannot be added */
  4331. if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
  4332. info->attrs[NL80211_ATTR_PEER_AID])
  4333. return -EINVAL;
  4334. break;
  4335. case NL80211_IFTYPE_STATION:
  4336. case NL80211_IFTYPE_P2P_CLIENT:
  4337. /* ignore uAPSD data */
  4338. params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
  4339. /* these are disallowed */
  4340. if (params.sta_flags_mask &
  4341. (BIT(NL80211_STA_FLAG_ASSOCIATED) |
  4342. BIT(NL80211_STA_FLAG_AUTHENTICATED)))
  4343. return -EINVAL;
  4344. /* Only TDLS peers can be added */
  4345. if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
  4346. return -EINVAL;
  4347. /* Can only add if TDLS ... */
  4348. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
  4349. return -EOPNOTSUPP;
  4350. /* ... with external setup is supported */
  4351. if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
  4352. return -EOPNOTSUPP;
  4353. /*
  4354. * Older wpa_supplicant versions always mark the TDLS peer
  4355. * as authorized, but it shouldn't yet be.
  4356. */
  4357. params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
  4358. break;
  4359. default:
  4360. return -EOPNOTSUPP;
  4361. }
  4362. /* be aware of params.vlan when changing code here */
  4363. err = rdev_add_station(rdev, dev, mac_addr, &params);
  4364. if (params.vlan)
  4365. dev_put(params.vlan);
  4366. return err;
  4367. }
  4368. static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
  4369. {
  4370. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4371. struct net_device *dev = info->user_ptr[1];
  4372. struct station_del_parameters params;
  4373. memset(&params, 0, sizeof(params));
  4374. if (info->attrs[NL80211_ATTR_MAC])
  4375. params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4376. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  4377. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
  4378. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  4379. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4380. return -EINVAL;
  4381. if (!rdev->ops->del_station)
  4382. return -EOPNOTSUPP;
  4383. if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
  4384. params.subtype =
  4385. nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
  4386. if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
  4387. params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
  4388. return -EINVAL;
  4389. } else {
  4390. /* Default to Deauthentication frame */
  4391. params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
  4392. }
  4393. if (info->attrs[NL80211_ATTR_REASON_CODE]) {
  4394. params.reason_code =
  4395. nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  4396. if (params.reason_code == 0)
  4397. return -EINVAL; /* 0 is reserved */
  4398. } else {
  4399. /* Default to reason code 2 */
  4400. params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
  4401. }
  4402. return rdev_del_station(rdev, dev, &params);
  4403. }
  4404. static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
  4405. int flags, struct net_device *dev,
  4406. u8 *dst, u8 *next_hop,
  4407. struct mpath_info *pinfo)
  4408. {
  4409. void *hdr;
  4410. struct nlattr *pinfoattr;
  4411. hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
  4412. if (!hdr)
  4413. return -1;
  4414. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  4415. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
  4416. nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
  4417. nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
  4418. goto nla_put_failure;
  4419. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
  4420. if (!pinfoattr)
  4421. goto nla_put_failure;
  4422. if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
  4423. nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
  4424. pinfo->frame_qlen))
  4425. goto nla_put_failure;
  4426. if (((pinfo->filled & MPATH_INFO_SN) &&
  4427. nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
  4428. ((pinfo->filled & MPATH_INFO_METRIC) &&
  4429. nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
  4430. pinfo->metric)) ||
  4431. ((pinfo->filled & MPATH_INFO_EXPTIME) &&
  4432. nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
  4433. pinfo->exptime)) ||
  4434. ((pinfo->filled & MPATH_INFO_FLAGS) &&
  4435. nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
  4436. pinfo->flags)) ||
  4437. ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
  4438. nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
  4439. pinfo->discovery_timeout)) ||
  4440. ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
  4441. nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
  4442. pinfo->discovery_retries)))
  4443. goto nla_put_failure;
  4444. nla_nest_end(msg, pinfoattr);
  4445. genlmsg_end(msg, hdr);
  4446. return 0;
  4447. nla_put_failure:
  4448. genlmsg_cancel(msg, hdr);
  4449. return -EMSGSIZE;
  4450. }
  4451. static int nl80211_dump_mpath(struct sk_buff *skb,
  4452. struct netlink_callback *cb)
  4453. {
  4454. struct mpath_info pinfo;
  4455. struct cfg80211_registered_device *rdev;
  4456. struct wireless_dev *wdev;
  4457. u8 dst[ETH_ALEN];
  4458. u8 next_hop[ETH_ALEN];
  4459. int path_idx = cb->args[2];
  4460. int err;
  4461. rtnl_lock();
  4462. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  4463. if (err)
  4464. goto out_err;
  4465. if (!rdev->ops->dump_mpath) {
  4466. err = -EOPNOTSUPP;
  4467. goto out_err;
  4468. }
  4469. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
  4470. err = -EOPNOTSUPP;
  4471. goto out_err;
  4472. }
  4473. while (1) {
  4474. err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
  4475. next_hop, &pinfo);
  4476. if (err == -ENOENT)
  4477. break;
  4478. if (err)
  4479. goto out_err;
  4480. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
  4481. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4482. wdev->netdev, dst, next_hop,
  4483. &pinfo) < 0)
  4484. goto out;
  4485. path_idx++;
  4486. }
  4487. out:
  4488. cb->args[2] = path_idx;
  4489. err = skb->len;
  4490. out_err:
  4491. rtnl_unlock();
  4492. return err;
  4493. }
  4494. static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
  4495. {
  4496. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4497. int err;
  4498. struct net_device *dev = info->user_ptr[1];
  4499. struct mpath_info pinfo;
  4500. struct sk_buff *msg;
  4501. u8 *dst = NULL;
  4502. u8 next_hop[ETH_ALEN];
  4503. memset(&pinfo, 0, sizeof(pinfo));
  4504. if (!info->attrs[NL80211_ATTR_MAC])
  4505. return -EINVAL;
  4506. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4507. if (!rdev->ops->get_mpath)
  4508. return -EOPNOTSUPP;
  4509. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4510. return -EOPNOTSUPP;
  4511. err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
  4512. if (err)
  4513. return err;
  4514. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4515. if (!msg)
  4516. return -ENOMEM;
  4517. if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
  4518. dev, dst, next_hop, &pinfo) < 0) {
  4519. nlmsg_free(msg);
  4520. return -ENOBUFS;
  4521. }
  4522. return genlmsg_reply(msg, info);
  4523. }
  4524. static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
  4525. {
  4526. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4527. struct net_device *dev = info->user_ptr[1];
  4528. u8 *dst = NULL;
  4529. u8 *next_hop = NULL;
  4530. if (!info->attrs[NL80211_ATTR_MAC])
  4531. return -EINVAL;
  4532. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  4533. return -EINVAL;
  4534. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4535. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  4536. if (!rdev->ops->change_mpath)
  4537. return -EOPNOTSUPP;
  4538. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4539. return -EOPNOTSUPP;
  4540. return rdev_change_mpath(rdev, dev, dst, next_hop);
  4541. }
  4542. static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
  4543. {
  4544. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4545. struct net_device *dev = info->user_ptr[1];
  4546. u8 *dst = NULL;
  4547. u8 *next_hop = NULL;
  4548. if (!info->attrs[NL80211_ATTR_MAC])
  4549. return -EINVAL;
  4550. if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
  4551. return -EINVAL;
  4552. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4553. next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
  4554. if (!rdev->ops->add_mpath)
  4555. return -EOPNOTSUPP;
  4556. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4557. return -EOPNOTSUPP;
  4558. return rdev_add_mpath(rdev, dev, dst, next_hop);
  4559. }
  4560. static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
  4561. {
  4562. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4563. struct net_device *dev = info->user_ptr[1];
  4564. u8 *dst = NULL;
  4565. if (info->attrs[NL80211_ATTR_MAC])
  4566. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4567. if (!rdev->ops->del_mpath)
  4568. return -EOPNOTSUPP;
  4569. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4570. return -EOPNOTSUPP;
  4571. return rdev_del_mpath(rdev, dev, dst);
  4572. }
  4573. static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
  4574. {
  4575. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4576. int err;
  4577. struct net_device *dev = info->user_ptr[1];
  4578. struct mpath_info pinfo;
  4579. struct sk_buff *msg;
  4580. u8 *dst = NULL;
  4581. u8 mpp[ETH_ALEN];
  4582. memset(&pinfo, 0, sizeof(pinfo));
  4583. if (!info->attrs[NL80211_ATTR_MAC])
  4584. return -EINVAL;
  4585. dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
  4586. if (!rdev->ops->get_mpp)
  4587. return -EOPNOTSUPP;
  4588. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  4589. return -EOPNOTSUPP;
  4590. err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
  4591. if (err)
  4592. return err;
  4593. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4594. if (!msg)
  4595. return -ENOMEM;
  4596. if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
  4597. dev, dst, mpp, &pinfo) < 0) {
  4598. nlmsg_free(msg);
  4599. return -ENOBUFS;
  4600. }
  4601. return genlmsg_reply(msg, info);
  4602. }
  4603. static int nl80211_dump_mpp(struct sk_buff *skb,
  4604. struct netlink_callback *cb)
  4605. {
  4606. struct mpath_info pinfo;
  4607. struct cfg80211_registered_device *rdev;
  4608. struct wireless_dev *wdev;
  4609. u8 dst[ETH_ALEN];
  4610. u8 mpp[ETH_ALEN];
  4611. int path_idx = cb->args[2];
  4612. int err;
  4613. rtnl_lock();
  4614. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  4615. if (err)
  4616. goto out_err;
  4617. if (!rdev->ops->dump_mpp) {
  4618. err = -EOPNOTSUPP;
  4619. goto out_err;
  4620. }
  4621. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
  4622. err = -EOPNOTSUPP;
  4623. goto out_err;
  4624. }
  4625. while (1) {
  4626. err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
  4627. mpp, &pinfo);
  4628. if (err == -ENOENT)
  4629. break;
  4630. if (err)
  4631. goto out_err;
  4632. if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
  4633. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  4634. wdev->netdev, dst, mpp,
  4635. &pinfo) < 0)
  4636. goto out;
  4637. path_idx++;
  4638. }
  4639. out:
  4640. cb->args[2] = path_idx;
  4641. err = skb->len;
  4642. out_err:
  4643. rtnl_unlock();
  4644. return err;
  4645. }
  4646. static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
  4647. {
  4648. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4649. struct net_device *dev = info->user_ptr[1];
  4650. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4651. struct bss_parameters params;
  4652. int err;
  4653. memset(&params, 0, sizeof(params));
  4654. /* default to not changing parameters */
  4655. params.use_cts_prot = -1;
  4656. params.use_short_preamble = -1;
  4657. params.use_short_slot_time = -1;
  4658. params.ap_isolate = -1;
  4659. params.ht_opmode = -1;
  4660. params.p2p_ctwindow = -1;
  4661. params.p2p_opp_ps = -1;
  4662. if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
  4663. params.use_cts_prot =
  4664. nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
  4665. if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
  4666. params.use_short_preamble =
  4667. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
  4668. if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
  4669. params.use_short_slot_time =
  4670. nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
  4671. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  4672. params.basic_rates =
  4673. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4674. params.basic_rates_len =
  4675. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  4676. }
  4677. if (info->attrs[NL80211_ATTR_AP_ISOLATE])
  4678. params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
  4679. if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
  4680. params.ht_opmode =
  4681. nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
  4682. if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
  4683. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4684. return -EINVAL;
  4685. params.p2p_ctwindow =
  4686. nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
  4687. if (params.p2p_ctwindow < 0)
  4688. return -EINVAL;
  4689. if (params.p2p_ctwindow != 0 &&
  4690. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
  4691. return -EINVAL;
  4692. }
  4693. if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
  4694. u8 tmp;
  4695. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4696. return -EINVAL;
  4697. tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
  4698. if (tmp > 1)
  4699. return -EINVAL;
  4700. params.p2p_opp_ps = tmp;
  4701. if (params.p2p_opp_ps &&
  4702. !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
  4703. return -EINVAL;
  4704. }
  4705. if (!rdev->ops->change_bss)
  4706. return -EOPNOTSUPP;
  4707. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
  4708. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
  4709. return -EOPNOTSUPP;
  4710. wdev_lock(wdev);
  4711. err = rdev_change_bss(rdev, dev, &params);
  4712. wdev_unlock(wdev);
  4713. return err;
  4714. }
  4715. static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
  4716. {
  4717. char *data = NULL;
  4718. bool is_indoor;
  4719. enum nl80211_user_reg_hint_type user_reg_hint_type;
  4720. u32 owner_nlportid;
  4721. /*
  4722. * You should only get this when cfg80211 hasn't yet initialized
  4723. * completely when built-in to the kernel right between the time
  4724. * window between nl80211_init() and regulatory_init(), if that is
  4725. * even possible.
  4726. */
  4727. if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
  4728. return -EINPROGRESS;
  4729. if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
  4730. user_reg_hint_type =
  4731. nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
  4732. else
  4733. user_reg_hint_type = NL80211_USER_REG_HINT_USER;
  4734. switch (user_reg_hint_type) {
  4735. case NL80211_USER_REG_HINT_USER:
  4736. case NL80211_USER_REG_HINT_CELL_BASE:
  4737. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  4738. return -EINVAL;
  4739. data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  4740. return regulatory_hint_user(data, user_reg_hint_type);
  4741. case NL80211_USER_REG_HINT_INDOOR:
  4742. if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
  4743. owner_nlportid = info->snd_portid;
  4744. is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
  4745. } else {
  4746. owner_nlportid = 0;
  4747. is_indoor = true;
  4748. }
  4749. return regulatory_hint_indoor(is_indoor, owner_nlportid);
  4750. default:
  4751. return -EINVAL;
  4752. }
  4753. }
  4754. static int nl80211_get_mesh_config(struct sk_buff *skb,
  4755. struct genl_info *info)
  4756. {
  4757. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  4758. struct net_device *dev = info->user_ptr[1];
  4759. struct wireless_dev *wdev = dev->ieee80211_ptr;
  4760. struct mesh_config cur_params;
  4761. int err = 0;
  4762. void *hdr;
  4763. struct nlattr *pinfoattr;
  4764. struct sk_buff *msg;
  4765. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  4766. return -EOPNOTSUPP;
  4767. if (!rdev->ops->get_mesh_config)
  4768. return -EOPNOTSUPP;
  4769. wdev_lock(wdev);
  4770. /* If not connected, get default parameters */
  4771. if (!wdev->mesh_id_len)
  4772. memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
  4773. else
  4774. err = rdev_get_mesh_config(rdev, dev, &cur_params);
  4775. wdev_unlock(wdev);
  4776. if (err)
  4777. return err;
  4778. /* Draw up a netlink message to send back */
  4779. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  4780. if (!msg)
  4781. return -ENOMEM;
  4782. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  4783. NL80211_CMD_GET_MESH_CONFIG);
  4784. if (!hdr)
  4785. goto out;
  4786. pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
  4787. if (!pinfoattr)
  4788. goto nla_put_failure;
  4789. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  4790. nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
  4791. cur_params.dot11MeshRetryTimeout) ||
  4792. nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  4793. cur_params.dot11MeshConfirmTimeout) ||
  4794. nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
  4795. cur_params.dot11MeshHoldingTimeout) ||
  4796. nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
  4797. cur_params.dot11MeshMaxPeerLinks) ||
  4798. nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
  4799. cur_params.dot11MeshMaxRetries) ||
  4800. nla_put_u8(msg, NL80211_MESHCONF_TTL,
  4801. cur_params.dot11MeshTTL) ||
  4802. nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
  4803. cur_params.element_ttl) ||
  4804. nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  4805. cur_params.auto_open_plinks) ||
  4806. nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
  4807. cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
  4808. nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  4809. cur_params.dot11MeshHWMPmaxPREQretries) ||
  4810. nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
  4811. cur_params.path_refresh_time) ||
  4812. nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  4813. cur_params.min_discovery_timeout) ||
  4814. nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  4815. cur_params.dot11MeshHWMPactivePathTimeout) ||
  4816. nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  4817. cur_params.dot11MeshHWMPpreqMinInterval) ||
  4818. nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  4819. cur_params.dot11MeshHWMPperrMinInterval) ||
  4820. nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  4821. cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
  4822. nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
  4823. cur_params.dot11MeshHWMPRootMode) ||
  4824. nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  4825. cur_params.dot11MeshHWMPRannInterval) ||
  4826. nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  4827. cur_params.dot11MeshGateAnnouncementProtocol) ||
  4828. nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
  4829. cur_params.dot11MeshForwarding) ||
  4830. nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
  4831. cur_params.rssi_threshold) ||
  4832. nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
  4833. cur_params.ht_opmode) ||
  4834. nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  4835. cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
  4836. nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  4837. cur_params.dot11MeshHWMProotInterval) ||
  4838. nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
  4839. cur_params.dot11MeshHWMPconfirmationInterval) ||
  4840. nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
  4841. cur_params.power_mode) ||
  4842. nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
  4843. cur_params.dot11MeshAwakeWindowDuration) ||
  4844. nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
  4845. cur_params.plink_timeout))
  4846. goto nla_put_failure;
  4847. nla_nest_end(msg, pinfoattr);
  4848. genlmsg_end(msg, hdr);
  4849. return genlmsg_reply(msg, info);
  4850. nla_put_failure:
  4851. genlmsg_cancel(msg, hdr);
  4852. out:
  4853. nlmsg_free(msg);
  4854. return -ENOBUFS;
  4855. }
  4856. static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
  4857. [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
  4858. [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
  4859. [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
  4860. [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
  4861. [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
  4862. [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
  4863. [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
  4864. [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
  4865. [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
  4866. [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
  4867. [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
  4868. [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
  4869. [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
  4870. [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
  4871. [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
  4872. [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
  4873. [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
  4874. [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
  4875. [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
  4876. [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
  4877. [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
  4878. [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
  4879. [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
  4880. [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
  4881. [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
  4882. [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
  4883. [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
  4884. [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
  4885. };
  4886. static const struct nla_policy
  4887. nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
  4888. [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
  4889. [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
  4890. [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
  4891. [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
  4892. [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
  4893. [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
  4894. [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
  4895. .len = IEEE80211_MAX_DATA_LEN },
  4896. [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
  4897. };
  4898. static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out)
  4899. {
  4900. u8 val = nla_get_u8(nla);
  4901. if (val < min || val > max)
  4902. return -EINVAL;
  4903. *out = val;
  4904. return 0;
  4905. }
  4906. static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out)
  4907. {
  4908. u8 val = nla_get_u8(nla);
  4909. if (val < min || val > max)
  4910. return -EINVAL;
  4911. *out = val;
  4912. return 0;
  4913. }
  4914. static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out)
  4915. {
  4916. u16 val = nla_get_u16(nla);
  4917. if (val < min || val > max)
  4918. return -EINVAL;
  4919. *out = val;
  4920. return 0;
  4921. }
  4922. static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out)
  4923. {
  4924. u32 val = nla_get_u32(nla);
  4925. if (val < min || val > max)
  4926. return -EINVAL;
  4927. *out = val;
  4928. return 0;
  4929. }
  4930. static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out)
  4931. {
  4932. s32 val = nla_get_s32(nla);
  4933. if (val < min || val > max)
  4934. return -EINVAL;
  4935. *out = val;
  4936. return 0;
  4937. }
  4938. static int nl80211_check_power_mode(const struct nlattr *nla,
  4939. enum nl80211_mesh_power_mode min,
  4940. enum nl80211_mesh_power_mode max,
  4941. enum nl80211_mesh_power_mode *out)
  4942. {
  4943. u32 val = nla_get_u32(nla);
  4944. if (val < min || val > max)
  4945. return -EINVAL;
  4946. *out = val;
  4947. return 0;
  4948. }
  4949. static int nl80211_parse_mesh_config(struct genl_info *info,
  4950. struct mesh_config *cfg,
  4951. u32 *mask_out)
  4952. {
  4953. struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
  4954. u32 mask = 0;
  4955. u16 ht_opmode;
  4956. #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
  4957. do { \
  4958. if (tb[attr]) { \
  4959. if (fn(tb[attr], min, max, &cfg->param)) \
  4960. return -EINVAL; \
  4961. mask |= (1 << (attr - 1)); \
  4962. } \
  4963. } while (0)
  4964. if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
  4965. return -EINVAL;
  4966. if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
  4967. info->attrs[NL80211_ATTR_MESH_CONFIG],
  4968. nl80211_meshconf_params_policy))
  4969. return -EINVAL;
  4970. /* This makes sure that there aren't more than 32 mesh config
  4971. * parameters (otherwise our bitfield scheme would not work.) */
  4972. BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
  4973. /* Fill in the params struct */
  4974. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
  4975. mask, NL80211_MESHCONF_RETRY_TIMEOUT,
  4976. nl80211_check_u16);
  4977. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
  4978. mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
  4979. nl80211_check_u16);
  4980. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
  4981. mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
  4982. nl80211_check_u16);
  4983. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
  4984. mask, NL80211_MESHCONF_MAX_PEER_LINKS,
  4985. nl80211_check_u16);
  4986. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
  4987. mask, NL80211_MESHCONF_MAX_RETRIES,
  4988. nl80211_check_u8);
  4989. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
  4990. mask, NL80211_MESHCONF_TTL, nl80211_check_u8);
  4991. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
  4992. mask, NL80211_MESHCONF_ELEMENT_TTL,
  4993. nl80211_check_u8);
  4994. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
  4995. mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
  4996. nl80211_check_bool);
  4997. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
  4998. 1, 255, mask,
  4999. NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
  5000. nl80211_check_u32);
  5001. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
  5002. mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
  5003. nl80211_check_u8);
  5004. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
  5005. mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
  5006. nl80211_check_u32);
  5007. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
  5008. mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
  5009. nl80211_check_u16);
  5010. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
  5011. 1, 65535, mask,
  5012. NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
  5013. nl80211_check_u32);
  5014. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
  5015. 1, 65535, mask,
  5016. NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
  5017. nl80211_check_u16);
  5018. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
  5019. 1, 65535, mask,
  5020. NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
  5021. nl80211_check_u16);
  5022. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  5023. dot11MeshHWMPnetDiameterTraversalTime,
  5024. 1, 65535, mask,
  5025. NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  5026. nl80211_check_u16);
  5027. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
  5028. mask, NL80211_MESHCONF_HWMP_ROOTMODE,
  5029. nl80211_check_u8);
  5030. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
  5031. mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
  5032. nl80211_check_u16);
  5033. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  5034. dot11MeshGateAnnouncementProtocol, 0, 1,
  5035. mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
  5036. nl80211_check_bool);
  5037. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
  5038. mask, NL80211_MESHCONF_FORWARDING,
  5039. nl80211_check_bool);
  5040. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
  5041. mask, NL80211_MESHCONF_RSSI_THRESHOLD,
  5042. nl80211_check_s32);
  5043. /*
  5044. * Check HT operation mode based on
  5045. * IEEE 802.11-2016 9.4.2.57 HT Operation element.
  5046. */
  5047. if (tb[NL80211_MESHCONF_HT_OPMODE]) {
  5048. ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
  5049. if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
  5050. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
  5051. IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
  5052. return -EINVAL;
  5053. /* NON_HT_STA bit is reserved, but some programs set it */
  5054. ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
  5055. cfg->ht_opmode = ht_opmode;
  5056. mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
  5057. }
  5058. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
  5059. 1, 65535, mask,
  5060. NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
  5061. nl80211_check_u32);
  5062. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
  5063. mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
  5064. nl80211_check_u16);
  5065. FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
  5066. dot11MeshHWMPconfirmationInterval,
  5067. 1, 65535, mask,
  5068. NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
  5069. nl80211_check_u16);
  5070. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
  5071. NL80211_MESH_POWER_ACTIVE,
  5072. NL80211_MESH_POWER_MAX,
  5073. mask, NL80211_MESHCONF_POWER_MODE,
  5074. nl80211_check_power_mode);
  5075. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
  5076. 0, 65535, mask,
  5077. NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16);
  5078. FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
  5079. mask, NL80211_MESHCONF_PLINK_TIMEOUT,
  5080. nl80211_check_u32);
  5081. if (mask_out)
  5082. *mask_out = mask;
  5083. return 0;
  5084. #undef FILL_IN_MESH_PARAM_IF_SET
  5085. }
  5086. static int nl80211_parse_mesh_setup(struct genl_info *info,
  5087. struct mesh_setup *setup)
  5088. {
  5089. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5090. struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
  5091. if (!info->attrs[NL80211_ATTR_MESH_SETUP])
  5092. return -EINVAL;
  5093. if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
  5094. info->attrs[NL80211_ATTR_MESH_SETUP],
  5095. nl80211_mesh_setup_params_policy))
  5096. return -EINVAL;
  5097. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
  5098. setup->sync_method =
  5099. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
  5100. IEEE80211_SYNC_METHOD_VENDOR :
  5101. IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
  5102. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
  5103. setup->path_sel_proto =
  5104. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
  5105. IEEE80211_PATH_PROTOCOL_VENDOR :
  5106. IEEE80211_PATH_PROTOCOL_HWMP;
  5107. if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
  5108. setup->path_metric =
  5109. (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
  5110. IEEE80211_PATH_METRIC_VENDOR :
  5111. IEEE80211_PATH_METRIC_AIRTIME;
  5112. if (tb[NL80211_MESH_SETUP_IE]) {
  5113. struct nlattr *ieattr =
  5114. tb[NL80211_MESH_SETUP_IE];
  5115. if (!is_valid_ie_attr(ieattr))
  5116. return -EINVAL;
  5117. setup->ie = nla_data(ieattr);
  5118. setup->ie_len = nla_len(ieattr);
  5119. }
  5120. if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
  5121. !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
  5122. return -EINVAL;
  5123. setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
  5124. setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
  5125. setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
  5126. if (setup->is_secure)
  5127. setup->user_mpm = true;
  5128. if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
  5129. if (!setup->user_mpm)
  5130. return -EINVAL;
  5131. setup->auth_id =
  5132. nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
  5133. }
  5134. return 0;
  5135. }
  5136. static int nl80211_update_mesh_config(struct sk_buff *skb,
  5137. struct genl_info *info)
  5138. {
  5139. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5140. struct net_device *dev = info->user_ptr[1];
  5141. struct wireless_dev *wdev = dev->ieee80211_ptr;
  5142. struct mesh_config cfg;
  5143. u32 mask;
  5144. int err;
  5145. if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
  5146. return -EOPNOTSUPP;
  5147. if (!rdev->ops->update_mesh_config)
  5148. return -EOPNOTSUPP;
  5149. err = nl80211_parse_mesh_config(info, &cfg, &mask);
  5150. if (err)
  5151. return err;
  5152. wdev_lock(wdev);
  5153. if (!wdev->mesh_id_len)
  5154. err = -ENOLINK;
  5155. if (!err)
  5156. err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
  5157. wdev_unlock(wdev);
  5158. return err;
  5159. }
  5160. static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
  5161. struct sk_buff *msg)
  5162. {
  5163. struct nlattr *nl_reg_rules;
  5164. unsigned int i;
  5165. if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
  5166. (regdom->dfs_region &&
  5167. nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
  5168. goto nla_put_failure;
  5169. nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
  5170. if (!nl_reg_rules)
  5171. goto nla_put_failure;
  5172. for (i = 0; i < regdom->n_reg_rules; i++) {
  5173. struct nlattr *nl_reg_rule;
  5174. const struct ieee80211_reg_rule *reg_rule;
  5175. const struct ieee80211_freq_range *freq_range;
  5176. const struct ieee80211_power_rule *power_rule;
  5177. unsigned int max_bandwidth_khz;
  5178. reg_rule = &regdom->reg_rules[i];
  5179. freq_range = &reg_rule->freq_range;
  5180. power_rule = &reg_rule->power_rule;
  5181. nl_reg_rule = nla_nest_start(msg, i);
  5182. if (!nl_reg_rule)
  5183. goto nla_put_failure;
  5184. max_bandwidth_khz = freq_range->max_bandwidth_khz;
  5185. if (!max_bandwidth_khz)
  5186. max_bandwidth_khz = reg_get_max_bandwidth(regdom,
  5187. reg_rule);
  5188. if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
  5189. reg_rule->flags) ||
  5190. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
  5191. freq_range->start_freq_khz) ||
  5192. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
  5193. freq_range->end_freq_khz) ||
  5194. nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
  5195. max_bandwidth_khz) ||
  5196. nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
  5197. power_rule->max_antenna_gain) ||
  5198. nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
  5199. power_rule->max_eirp) ||
  5200. nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
  5201. reg_rule->dfs_cac_ms))
  5202. goto nla_put_failure;
  5203. nla_nest_end(msg, nl_reg_rule);
  5204. }
  5205. nla_nest_end(msg, nl_reg_rules);
  5206. return 0;
  5207. nla_put_failure:
  5208. return -EMSGSIZE;
  5209. }
  5210. static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
  5211. {
  5212. const struct ieee80211_regdomain *regdom = NULL;
  5213. struct cfg80211_registered_device *rdev;
  5214. struct wiphy *wiphy = NULL;
  5215. struct sk_buff *msg;
  5216. void *hdr;
  5217. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  5218. if (!msg)
  5219. return -ENOBUFS;
  5220. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  5221. NL80211_CMD_GET_REG);
  5222. if (!hdr)
  5223. goto put_failure;
  5224. if (info->attrs[NL80211_ATTR_WIPHY]) {
  5225. bool self_managed;
  5226. rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
  5227. if (IS_ERR(rdev)) {
  5228. nlmsg_free(msg);
  5229. return PTR_ERR(rdev);
  5230. }
  5231. wiphy = &rdev->wiphy;
  5232. self_managed = wiphy->regulatory_flags &
  5233. REGULATORY_WIPHY_SELF_MANAGED;
  5234. regdom = get_wiphy_regdom(wiphy);
  5235. /* a self-managed-reg device must have a private regdom */
  5236. if (WARN_ON(!regdom && self_managed)) {
  5237. nlmsg_free(msg);
  5238. return -EINVAL;
  5239. }
  5240. if (regdom &&
  5241. nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  5242. goto nla_put_failure;
  5243. }
  5244. if (!wiphy && reg_last_request_cell_base() &&
  5245. nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
  5246. NL80211_USER_REG_HINT_CELL_BASE))
  5247. goto nla_put_failure;
  5248. rcu_read_lock();
  5249. if (!regdom)
  5250. regdom = rcu_dereference(cfg80211_regdomain);
  5251. if (nl80211_put_regdom(regdom, msg))
  5252. goto nla_put_failure_rcu;
  5253. rcu_read_unlock();
  5254. genlmsg_end(msg, hdr);
  5255. return genlmsg_reply(msg, info);
  5256. nla_put_failure_rcu:
  5257. rcu_read_unlock();
  5258. nla_put_failure:
  5259. genlmsg_cancel(msg, hdr);
  5260. put_failure:
  5261. nlmsg_free(msg);
  5262. return -EMSGSIZE;
  5263. }
  5264. static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
  5265. u32 seq, int flags, struct wiphy *wiphy,
  5266. const struct ieee80211_regdomain *regdom)
  5267. {
  5268. void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
  5269. NL80211_CMD_GET_REG);
  5270. if (!hdr)
  5271. return -1;
  5272. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  5273. if (nl80211_put_regdom(regdom, msg))
  5274. goto nla_put_failure;
  5275. if (!wiphy && reg_last_request_cell_base() &&
  5276. nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
  5277. NL80211_USER_REG_HINT_CELL_BASE))
  5278. goto nla_put_failure;
  5279. if (wiphy &&
  5280. nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  5281. goto nla_put_failure;
  5282. if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  5283. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  5284. goto nla_put_failure;
  5285. genlmsg_end(msg, hdr);
  5286. return 0;
  5287. nla_put_failure:
  5288. genlmsg_cancel(msg, hdr);
  5289. return -EMSGSIZE;
  5290. }
  5291. static int nl80211_get_reg_dump(struct sk_buff *skb,
  5292. struct netlink_callback *cb)
  5293. {
  5294. const struct ieee80211_regdomain *regdom = NULL;
  5295. struct cfg80211_registered_device *rdev;
  5296. int err, reg_idx, start = cb->args[2];
  5297. rtnl_lock();
  5298. if (cfg80211_regdomain && start == 0) {
  5299. err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
  5300. NLM_F_MULTI, NULL,
  5301. rtnl_dereference(cfg80211_regdomain));
  5302. if (err < 0)
  5303. goto out_err;
  5304. }
  5305. /* the global regdom is idx 0 */
  5306. reg_idx = 1;
  5307. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  5308. regdom = get_wiphy_regdom(&rdev->wiphy);
  5309. if (!regdom)
  5310. continue;
  5311. if (++reg_idx <= start)
  5312. continue;
  5313. err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
  5314. NLM_F_MULTI, &rdev->wiphy, regdom);
  5315. if (err < 0) {
  5316. reg_idx--;
  5317. break;
  5318. }
  5319. }
  5320. cb->args[2] = reg_idx;
  5321. err = skb->len;
  5322. out_err:
  5323. rtnl_unlock();
  5324. return err;
  5325. }
  5326. #ifdef CONFIG_CFG80211_CRDA_SUPPORT
  5327. static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
  5328. [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
  5329. [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
  5330. [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
  5331. [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
  5332. [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
  5333. [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
  5334. [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
  5335. };
  5336. static int parse_reg_rule(struct nlattr *tb[],
  5337. struct ieee80211_reg_rule *reg_rule)
  5338. {
  5339. struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
  5340. struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
  5341. if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
  5342. return -EINVAL;
  5343. if (!tb[NL80211_ATTR_FREQ_RANGE_START])
  5344. return -EINVAL;
  5345. if (!tb[NL80211_ATTR_FREQ_RANGE_END])
  5346. return -EINVAL;
  5347. if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
  5348. return -EINVAL;
  5349. if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
  5350. return -EINVAL;
  5351. reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
  5352. freq_range->start_freq_khz =
  5353. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
  5354. freq_range->end_freq_khz =
  5355. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
  5356. freq_range->max_bandwidth_khz =
  5357. nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
  5358. power_rule->max_eirp =
  5359. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
  5360. if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
  5361. power_rule->max_antenna_gain =
  5362. nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
  5363. if (tb[NL80211_ATTR_DFS_CAC_TIME])
  5364. reg_rule->dfs_cac_ms =
  5365. nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
  5366. return 0;
  5367. }
  5368. static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
  5369. {
  5370. struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
  5371. struct nlattr *nl_reg_rule;
  5372. char *alpha2;
  5373. int rem_reg_rules, r;
  5374. u32 num_rules = 0, rule_idx = 0, size_of_regd;
  5375. enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
  5376. struct ieee80211_regdomain *rd;
  5377. if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
  5378. return -EINVAL;
  5379. if (!info->attrs[NL80211_ATTR_REG_RULES])
  5380. return -EINVAL;
  5381. alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
  5382. if (info->attrs[NL80211_ATTR_DFS_REGION])
  5383. dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
  5384. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  5385. rem_reg_rules) {
  5386. num_rules++;
  5387. if (num_rules > NL80211_MAX_SUPP_REG_RULES)
  5388. return -EINVAL;
  5389. }
  5390. if (!reg_is_valid_request(alpha2))
  5391. return -EINVAL;
  5392. size_of_regd = sizeof(struct ieee80211_regdomain) +
  5393. num_rules * sizeof(struct ieee80211_reg_rule);
  5394. rd = kzalloc(size_of_regd, GFP_KERNEL);
  5395. if (!rd)
  5396. return -ENOMEM;
  5397. rd->n_reg_rules = num_rules;
  5398. rd->alpha2[0] = alpha2[0];
  5399. rd->alpha2[1] = alpha2[1];
  5400. /*
  5401. * Disable DFS master mode if the DFS region was
  5402. * not supported or known on this kernel.
  5403. */
  5404. if (reg_supported_dfs_region(dfs_region))
  5405. rd->dfs_region = dfs_region;
  5406. nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
  5407. rem_reg_rules) {
  5408. r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
  5409. nla_data(nl_reg_rule), nla_len(nl_reg_rule),
  5410. reg_rule_policy);
  5411. if (r)
  5412. goto bad_reg;
  5413. r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
  5414. if (r)
  5415. goto bad_reg;
  5416. rule_idx++;
  5417. if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
  5418. r = -EINVAL;
  5419. goto bad_reg;
  5420. }
  5421. }
  5422. /* set_regdom takes ownership of rd */
  5423. return set_regdom(rd, REGD_SOURCE_CRDA);
  5424. bad_reg:
  5425. kfree(rd);
  5426. return r;
  5427. }
  5428. #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
  5429. static int validate_scan_freqs(struct nlattr *freqs)
  5430. {
  5431. struct nlattr *attr1, *attr2;
  5432. int n_channels = 0, tmp1, tmp2;
  5433. nla_for_each_nested(attr1, freqs, tmp1)
  5434. if (nla_len(attr1) != sizeof(u32))
  5435. return 0;
  5436. nla_for_each_nested(attr1, freqs, tmp1) {
  5437. n_channels++;
  5438. /*
  5439. * Some hardware has a limited channel list for
  5440. * scanning, and it is pretty much nonsensical
  5441. * to scan for a channel twice, so disallow that
  5442. * and don't require drivers to check that the
  5443. * channel list they get isn't longer than what
  5444. * they can scan, as long as they can scan all
  5445. * the channels they registered at once.
  5446. */
  5447. nla_for_each_nested(attr2, freqs, tmp2)
  5448. if (attr1 != attr2 &&
  5449. nla_get_u32(attr1) == nla_get_u32(attr2))
  5450. return 0;
  5451. }
  5452. return n_channels;
  5453. }
  5454. static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
  5455. {
  5456. return b < NUM_NL80211_BANDS && wiphy->bands[b];
  5457. }
  5458. static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
  5459. struct cfg80211_bss_selection *bss_select)
  5460. {
  5461. struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
  5462. struct nlattr *nest;
  5463. int err;
  5464. bool found = false;
  5465. int i;
  5466. /* only process one nested attribute */
  5467. nest = nla_data(nla);
  5468. if (!nla_ok(nest, nla_len(nest)))
  5469. return -EINVAL;
  5470. err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest),
  5471. nla_len(nest), nl80211_bss_select_policy);
  5472. if (err)
  5473. return err;
  5474. /* only one attribute may be given */
  5475. for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
  5476. if (attr[i]) {
  5477. if (found)
  5478. return -EINVAL;
  5479. found = true;
  5480. }
  5481. }
  5482. bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
  5483. if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
  5484. bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
  5485. if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
  5486. bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
  5487. bss_select->param.band_pref =
  5488. nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
  5489. if (!is_band_valid(wiphy, bss_select->param.band_pref))
  5490. return -EINVAL;
  5491. }
  5492. if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
  5493. struct nl80211_bss_select_rssi_adjust *adj_param;
  5494. adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
  5495. bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
  5496. bss_select->param.adjust.band = adj_param->band;
  5497. bss_select->param.adjust.delta = adj_param->delta;
  5498. if (!is_band_valid(wiphy, bss_select->param.adjust.band))
  5499. return -EINVAL;
  5500. }
  5501. /* user-space did not provide behaviour attribute */
  5502. if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
  5503. return -EINVAL;
  5504. if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
  5505. return -EINVAL;
  5506. return 0;
  5507. }
  5508. static int nl80211_parse_random_mac(struct nlattr **attrs,
  5509. u8 *mac_addr, u8 *mac_addr_mask)
  5510. {
  5511. int i;
  5512. if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
  5513. eth_zero_addr(mac_addr);
  5514. eth_zero_addr(mac_addr_mask);
  5515. mac_addr[0] = 0x2;
  5516. mac_addr_mask[0] = 0x3;
  5517. return 0;
  5518. }
  5519. /* need both or none */
  5520. if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
  5521. return -EINVAL;
  5522. memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
  5523. memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
  5524. /* don't allow or configure an mcast address */
  5525. if (!is_multicast_ether_addr(mac_addr_mask) ||
  5526. is_multicast_ether_addr(mac_addr))
  5527. return -EINVAL;
  5528. /*
  5529. * allow users to pass a MAC address that has bits set outside
  5530. * of the mask, but don't bother drivers with having to deal
  5531. * with such bits
  5532. */
  5533. for (i = 0; i < ETH_ALEN; i++)
  5534. mac_addr[i] &= mac_addr_mask[i];
  5535. return 0;
  5536. }
  5537. static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
  5538. {
  5539. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5540. struct wireless_dev *wdev = info->user_ptr[1];
  5541. struct cfg80211_scan_request *request;
  5542. struct nlattr *attr;
  5543. struct wiphy *wiphy;
  5544. int err, tmp, n_ssids = 0, n_channels, i;
  5545. size_t ie_len;
  5546. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  5547. return -EINVAL;
  5548. wiphy = &rdev->wiphy;
  5549. if (wdev->iftype == NL80211_IFTYPE_NAN)
  5550. return -EOPNOTSUPP;
  5551. if (!rdev->ops->scan)
  5552. return -EOPNOTSUPP;
  5553. if (rdev->scan_req || rdev->scan_msg) {
  5554. err = -EBUSY;
  5555. goto unlock;
  5556. }
  5557. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5558. n_channels = validate_scan_freqs(
  5559. info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  5560. if (!n_channels) {
  5561. err = -EINVAL;
  5562. goto unlock;
  5563. }
  5564. } else {
  5565. n_channels = ieee80211_get_num_supported_channels(wiphy);
  5566. }
  5567. if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
  5568. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
  5569. n_ssids++;
  5570. if (n_ssids > wiphy->max_scan_ssids) {
  5571. err = -EINVAL;
  5572. goto unlock;
  5573. }
  5574. if (info->attrs[NL80211_ATTR_IE])
  5575. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5576. else
  5577. ie_len = 0;
  5578. if (ie_len > wiphy->max_scan_ie_len) {
  5579. err = -EINVAL;
  5580. goto unlock;
  5581. }
  5582. request = kzalloc(sizeof(*request)
  5583. + sizeof(*request->ssids) * n_ssids
  5584. + sizeof(*request->channels) * n_channels
  5585. + ie_len, GFP_KERNEL);
  5586. if (!request) {
  5587. err = -ENOMEM;
  5588. goto unlock;
  5589. }
  5590. if (n_ssids)
  5591. request->ssids = (void *)&request->channels[n_channels];
  5592. request->n_ssids = n_ssids;
  5593. if (ie_len) {
  5594. if (n_ssids)
  5595. request->ie = (void *)(request->ssids + n_ssids);
  5596. else
  5597. request->ie = (void *)(request->channels + n_channels);
  5598. }
  5599. i = 0;
  5600. if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5601. /* user specified, bail out if channel not found */
  5602. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
  5603. struct ieee80211_channel *chan;
  5604. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  5605. if (!chan) {
  5606. err = -EINVAL;
  5607. goto out_free;
  5608. }
  5609. /* ignore disabled channels */
  5610. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5611. continue;
  5612. request->channels[i] = chan;
  5613. i++;
  5614. }
  5615. } else {
  5616. enum nl80211_band band;
  5617. /* all channels */
  5618. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  5619. int j;
  5620. if (!wiphy->bands[band])
  5621. continue;
  5622. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  5623. struct ieee80211_channel *chan;
  5624. chan = &wiphy->bands[band]->channels[j];
  5625. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5626. continue;
  5627. request->channels[i] = chan;
  5628. i++;
  5629. }
  5630. }
  5631. }
  5632. if (!i) {
  5633. err = -EINVAL;
  5634. goto out_free;
  5635. }
  5636. request->n_channels = i;
  5637. i = 0;
  5638. if (n_ssids) {
  5639. nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
  5640. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  5641. err = -EINVAL;
  5642. goto out_free;
  5643. }
  5644. request->ssids[i].ssid_len = nla_len(attr);
  5645. memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
  5646. i++;
  5647. }
  5648. }
  5649. if (info->attrs[NL80211_ATTR_IE]) {
  5650. request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  5651. memcpy((void *)request->ie,
  5652. nla_data(info->attrs[NL80211_ATTR_IE]),
  5653. request->ie_len);
  5654. }
  5655. for (i = 0; i < NUM_NL80211_BANDS; i++)
  5656. if (wiphy->bands[i])
  5657. request->rates[i] =
  5658. (1 << wiphy->bands[i]->n_bitrates) - 1;
  5659. if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
  5660. nla_for_each_nested(attr,
  5661. info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
  5662. tmp) {
  5663. enum nl80211_band band = nla_type(attr);
  5664. if (band < 0 || band >= NUM_NL80211_BANDS) {
  5665. err = -EINVAL;
  5666. goto out_free;
  5667. }
  5668. if (!wiphy->bands[band])
  5669. continue;
  5670. err = ieee80211_get_ratemask(wiphy->bands[band],
  5671. nla_data(attr),
  5672. nla_len(attr),
  5673. &request->rates[band]);
  5674. if (err)
  5675. goto out_free;
  5676. }
  5677. }
  5678. if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
  5679. if (!wiphy_ext_feature_isset(wiphy,
  5680. NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
  5681. err = -EOPNOTSUPP;
  5682. goto out_free;
  5683. }
  5684. request->duration =
  5685. nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
  5686. request->duration_mandatory =
  5687. nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
  5688. }
  5689. if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
  5690. request->flags = nla_get_u32(
  5691. info->attrs[NL80211_ATTR_SCAN_FLAGS]);
  5692. if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  5693. !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
  5694. ((request->flags & NL80211_SCAN_FLAG_LOW_SPAN) &&
  5695. !wiphy_ext_feature_isset(wiphy,
  5696. NL80211_EXT_FEATURE_LOW_SPAN_SCAN)) ||
  5697. ((request->flags & NL80211_SCAN_FLAG_LOW_POWER) &&
  5698. !wiphy_ext_feature_isset(wiphy,
  5699. NL80211_EXT_FEATURE_LOW_POWER_SCAN)) ||
  5700. ((request->flags & NL80211_SCAN_FLAG_HIGH_ACCURACY) &&
  5701. !wiphy_ext_feature_isset(wiphy,
  5702. NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN))) {
  5703. err = -EOPNOTSUPP;
  5704. goto out_free;
  5705. }
  5706. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  5707. if (!(wiphy->features &
  5708. NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
  5709. err = -EOPNOTSUPP;
  5710. goto out_free;
  5711. }
  5712. if (wdev->current_bss) {
  5713. err = -EOPNOTSUPP;
  5714. goto out_free;
  5715. }
  5716. err = nl80211_parse_random_mac(info->attrs,
  5717. request->mac_addr,
  5718. request->mac_addr_mask);
  5719. if (err)
  5720. goto out_free;
  5721. }
  5722. }
  5723. request->no_cck =
  5724. nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  5725. /* Initial implementation used NL80211_ATTR_MAC to set the specific
  5726. * BSSID to scan for. This was problematic because that same attribute
  5727. * was already used for another purpose (local random MAC address). The
  5728. * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
  5729. * compatibility with older userspace components, also use the
  5730. * NL80211_ATTR_MAC value here if it can be determined to be used for
  5731. * the specific BSSID use case instead of the random MAC address
  5732. * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
  5733. */
  5734. if (info->attrs[NL80211_ATTR_BSSID])
  5735. memcpy(request->bssid,
  5736. nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
  5737. else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
  5738. info->attrs[NL80211_ATTR_MAC])
  5739. memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
  5740. ETH_ALEN);
  5741. else
  5742. eth_broadcast_addr(request->bssid);
  5743. request->wdev = wdev;
  5744. request->wiphy = &rdev->wiphy;
  5745. request->scan_start = jiffies;
  5746. rdev->scan_req = request;
  5747. err = rdev_scan(rdev, request);
  5748. if (!err) {
  5749. nl80211_send_scan_start(rdev, wdev);
  5750. if (wdev->netdev)
  5751. dev_hold(wdev->netdev);
  5752. } else {
  5753. out_free:
  5754. rdev->scan_req = NULL;
  5755. kfree(request);
  5756. }
  5757. unlock:
  5758. return err;
  5759. }
  5760. static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
  5761. {
  5762. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  5763. struct wireless_dev *wdev = info->user_ptr[1];
  5764. if (!rdev->ops->abort_scan)
  5765. return -EOPNOTSUPP;
  5766. if (rdev->scan_msg)
  5767. return 0;
  5768. if (!rdev->scan_req)
  5769. return -ENOENT;
  5770. rdev_abort_scan(rdev, wdev);
  5771. return 0;
  5772. }
  5773. static int
  5774. nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
  5775. struct cfg80211_sched_scan_request *request,
  5776. struct nlattr **attrs)
  5777. {
  5778. int tmp, err, i = 0;
  5779. struct nlattr *attr;
  5780. if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
  5781. u32 interval;
  5782. /*
  5783. * If scan plans are not specified,
  5784. * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
  5785. * case one scan plan will be set with the specified scan
  5786. * interval and infinite number of iterations.
  5787. */
  5788. if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5789. return -EINVAL;
  5790. interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
  5791. if (!interval)
  5792. return -EINVAL;
  5793. request->scan_plans[0].interval =
  5794. DIV_ROUND_UP(interval, MSEC_PER_SEC);
  5795. if (!request->scan_plans[0].interval)
  5796. return -EINVAL;
  5797. if (request->scan_plans[0].interval >
  5798. wiphy->max_sched_scan_plan_interval)
  5799. request->scan_plans[0].interval =
  5800. wiphy->max_sched_scan_plan_interval;
  5801. return 0;
  5802. }
  5803. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
  5804. struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
  5805. if (WARN_ON(i >= n_plans))
  5806. return -EINVAL;
  5807. err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
  5808. nla_data(attr), nla_len(attr),
  5809. nl80211_plan_policy);
  5810. if (err)
  5811. return err;
  5812. if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
  5813. return -EINVAL;
  5814. request->scan_plans[i].interval =
  5815. nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
  5816. if (!request->scan_plans[i].interval ||
  5817. request->scan_plans[i].interval >
  5818. wiphy->max_sched_scan_plan_interval)
  5819. return -EINVAL;
  5820. if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
  5821. request->scan_plans[i].iterations =
  5822. nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
  5823. if (!request->scan_plans[i].iterations ||
  5824. (request->scan_plans[i].iterations >
  5825. wiphy->max_sched_scan_plan_iterations))
  5826. return -EINVAL;
  5827. } else if (i < n_plans - 1) {
  5828. /*
  5829. * All scan plans but the last one must specify
  5830. * a finite number of iterations
  5831. */
  5832. return -EINVAL;
  5833. }
  5834. i++;
  5835. }
  5836. /*
  5837. * The last scan plan must not specify the number of
  5838. * iterations, it is supposed to run infinitely
  5839. */
  5840. if (request->scan_plans[n_plans - 1].iterations)
  5841. return -EINVAL;
  5842. return 0;
  5843. }
  5844. static struct cfg80211_sched_scan_request *
  5845. nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
  5846. struct nlattr **attrs)
  5847. {
  5848. struct cfg80211_sched_scan_request *request;
  5849. struct nlattr *attr;
  5850. int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
  5851. enum nl80211_band band;
  5852. size_t ie_len;
  5853. struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
  5854. s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
  5855. if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
  5856. return ERR_PTR(-EINVAL);
  5857. if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5858. n_channels = validate_scan_freqs(
  5859. attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
  5860. if (!n_channels)
  5861. return ERR_PTR(-EINVAL);
  5862. } else {
  5863. n_channels = ieee80211_get_num_supported_channels(wiphy);
  5864. }
  5865. if (attrs[NL80211_ATTR_SCAN_SSIDS])
  5866. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
  5867. tmp)
  5868. n_ssids++;
  5869. if (n_ssids > wiphy->max_sched_scan_ssids)
  5870. return ERR_PTR(-EINVAL);
  5871. /*
  5872. * First, count the number of 'real' matchsets. Due to an issue with
  5873. * the old implementation, matchsets containing only the RSSI attribute
  5874. * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
  5875. * RSSI for all matchsets, rather than their own matchset for reporting
  5876. * all APs with a strong RSSI. This is needed to be compatible with
  5877. * older userspace that treated a matchset with only the RSSI as the
  5878. * global RSSI for all other matchsets - if there are other matchsets.
  5879. */
  5880. if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  5881. nla_for_each_nested(attr,
  5882. attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  5883. tmp) {
  5884. struct nlattr *rssi;
  5885. err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  5886. nla_data(attr), nla_len(attr),
  5887. nl80211_match_policy);
  5888. if (err)
  5889. return ERR_PTR(err);
  5890. /* add other standalone attributes here */
  5891. if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
  5892. n_match_sets++;
  5893. continue;
  5894. }
  5895. rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
  5896. if (rssi)
  5897. default_match_rssi = nla_get_s32(rssi);
  5898. }
  5899. }
  5900. /* However, if there's no other matchset, add the RSSI one */
  5901. if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
  5902. n_match_sets = 1;
  5903. if (n_match_sets > wiphy->max_match_sets)
  5904. return ERR_PTR(-EINVAL);
  5905. if (attrs[NL80211_ATTR_IE])
  5906. ie_len = nla_len(attrs[NL80211_ATTR_IE]);
  5907. else
  5908. ie_len = 0;
  5909. if (ie_len > wiphy->max_sched_scan_ie_len)
  5910. return ERR_PTR(-EINVAL);
  5911. if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
  5912. /*
  5913. * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
  5914. * each scan plan already specifies its own interval
  5915. */
  5916. if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5917. return ERR_PTR(-EINVAL);
  5918. nla_for_each_nested(attr,
  5919. attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
  5920. n_plans++;
  5921. } else {
  5922. /*
  5923. * The scan interval attribute is kept for backward
  5924. * compatibility. If no scan plans are specified and sched scan
  5925. * interval is specified, one scan plan will be set with this
  5926. * scan interval and infinite number of iterations.
  5927. */
  5928. if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
  5929. return ERR_PTR(-EINVAL);
  5930. n_plans = 1;
  5931. }
  5932. if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
  5933. return ERR_PTR(-EINVAL);
  5934. if (!wiphy_ext_feature_isset(
  5935. wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
  5936. (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
  5937. attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
  5938. return ERR_PTR(-EINVAL);
  5939. request = kzalloc(sizeof(*request)
  5940. + sizeof(*request->ssids) * n_ssids
  5941. + sizeof(*request->match_sets) * n_match_sets
  5942. + sizeof(*request->scan_plans) * n_plans
  5943. + sizeof(*request->channels) * n_channels
  5944. + ie_len, GFP_KERNEL);
  5945. if (!request)
  5946. return ERR_PTR(-ENOMEM);
  5947. if (n_ssids)
  5948. request->ssids = (void *)&request->channels[n_channels];
  5949. request->n_ssids = n_ssids;
  5950. if (ie_len) {
  5951. if (n_ssids)
  5952. request->ie = (void *)(request->ssids + n_ssids);
  5953. else
  5954. request->ie = (void *)(request->channels + n_channels);
  5955. }
  5956. if (n_match_sets) {
  5957. if (request->ie)
  5958. request->match_sets = (void *)(request->ie + ie_len);
  5959. else if (n_ssids)
  5960. request->match_sets =
  5961. (void *)(request->ssids + n_ssids);
  5962. else
  5963. request->match_sets =
  5964. (void *)(request->channels + n_channels);
  5965. }
  5966. request->n_match_sets = n_match_sets;
  5967. if (n_match_sets)
  5968. request->scan_plans = (void *)(request->match_sets +
  5969. n_match_sets);
  5970. else if (request->ie)
  5971. request->scan_plans = (void *)(request->ie + ie_len);
  5972. else if (n_ssids)
  5973. request->scan_plans = (void *)(request->ssids + n_ssids);
  5974. else
  5975. request->scan_plans = (void *)(request->channels + n_channels);
  5976. request->n_scan_plans = n_plans;
  5977. i = 0;
  5978. if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
  5979. /* user specified, bail out if channel not found */
  5980. nla_for_each_nested(attr,
  5981. attrs[NL80211_ATTR_SCAN_FREQUENCIES],
  5982. tmp) {
  5983. struct ieee80211_channel *chan;
  5984. chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
  5985. if (!chan) {
  5986. err = -EINVAL;
  5987. goto out_free;
  5988. }
  5989. /* ignore disabled channels */
  5990. if (chan->flags & IEEE80211_CHAN_DISABLED)
  5991. continue;
  5992. request->channels[i] = chan;
  5993. i++;
  5994. }
  5995. } else {
  5996. /* all channels */
  5997. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  5998. int j;
  5999. if (!wiphy->bands[band])
  6000. continue;
  6001. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  6002. struct ieee80211_channel *chan;
  6003. chan = &wiphy->bands[band]->channels[j];
  6004. if (chan->flags & IEEE80211_CHAN_DISABLED)
  6005. continue;
  6006. request->channels[i] = chan;
  6007. i++;
  6008. }
  6009. }
  6010. }
  6011. if (!i) {
  6012. err = -EINVAL;
  6013. goto out_free;
  6014. }
  6015. request->n_channels = i;
  6016. i = 0;
  6017. if (n_ssids) {
  6018. nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
  6019. tmp) {
  6020. if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
  6021. err = -EINVAL;
  6022. goto out_free;
  6023. }
  6024. request->ssids[i].ssid_len = nla_len(attr);
  6025. memcpy(request->ssids[i].ssid, nla_data(attr),
  6026. nla_len(attr));
  6027. i++;
  6028. }
  6029. }
  6030. i = 0;
  6031. if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
  6032. nla_for_each_nested(attr,
  6033. attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
  6034. tmp) {
  6035. struct nlattr *ssid, *rssi;
  6036. err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
  6037. nla_data(attr), nla_len(attr),
  6038. nl80211_match_policy);
  6039. if (err)
  6040. goto out_free;
  6041. ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
  6042. if (ssid) {
  6043. if (WARN_ON(i >= n_match_sets)) {
  6044. /* this indicates a programming error,
  6045. * the loop above should have verified
  6046. * things properly
  6047. */
  6048. err = -EINVAL;
  6049. goto out_free;
  6050. }
  6051. if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
  6052. err = -EINVAL;
  6053. goto out_free;
  6054. }
  6055. memcpy(request->match_sets[i].ssid.ssid,
  6056. nla_data(ssid), nla_len(ssid));
  6057. request->match_sets[i].ssid.ssid_len =
  6058. nla_len(ssid);
  6059. /* special attribute - old implementation w/a */
  6060. request->match_sets[i].rssi_thold =
  6061. default_match_rssi;
  6062. rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
  6063. if (rssi)
  6064. request->match_sets[i].rssi_thold =
  6065. nla_get_s32(rssi);
  6066. }
  6067. i++;
  6068. }
  6069. /* there was no other matchset, so the RSSI one is alone */
  6070. if (i == 0 && n_match_sets)
  6071. request->match_sets[0].rssi_thold = default_match_rssi;
  6072. request->min_rssi_thold = INT_MAX;
  6073. for (i = 0; i < n_match_sets; i++)
  6074. request->min_rssi_thold =
  6075. min(request->match_sets[i].rssi_thold,
  6076. request->min_rssi_thold);
  6077. } else {
  6078. request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
  6079. }
  6080. if (ie_len) {
  6081. request->ie_len = ie_len;
  6082. memcpy((void *)request->ie,
  6083. nla_data(attrs[NL80211_ATTR_IE]),
  6084. request->ie_len);
  6085. }
  6086. if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
  6087. request->flags = nla_get_u32(
  6088. attrs[NL80211_ATTR_SCAN_FLAGS]);
  6089. if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
  6090. !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
  6091. err = -EOPNOTSUPP;
  6092. goto out_free;
  6093. }
  6094. if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
  6095. u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
  6096. if (!wdev) /* must be net-detect */
  6097. flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
  6098. if (!(wiphy->features & flg)) {
  6099. err = -EOPNOTSUPP;
  6100. goto out_free;
  6101. }
  6102. if (wdev && wdev->current_bss) {
  6103. err = -EOPNOTSUPP;
  6104. goto out_free;
  6105. }
  6106. err = nl80211_parse_random_mac(attrs, request->mac_addr,
  6107. request->mac_addr_mask);
  6108. if (err)
  6109. goto out_free;
  6110. }
  6111. }
  6112. if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
  6113. request->delay =
  6114. nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
  6115. if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
  6116. request->relative_rssi = nla_get_s8(
  6117. attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
  6118. request->relative_rssi_set = true;
  6119. }
  6120. if (request->relative_rssi_set &&
  6121. attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
  6122. struct nl80211_bss_select_rssi_adjust *rssi_adjust;
  6123. rssi_adjust = nla_data(
  6124. attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
  6125. request->rssi_adjust.band = rssi_adjust->band;
  6126. request->rssi_adjust.delta = rssi_adjust->delta;
  6127. if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
  6128. err = -EINVAL;
  6129. goto out_free;
  6130. }
  6131. }
  6132. err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
  6133. if (err)
  6134. goto out_free;
  6135. request->scan_start = jiffies;
  6136. return request;
  6137. out_free:
  6138. kfree(request);
  6139. return ERR_PTR(err);
  6140. }
  6141. static int nl80211_start_sched_scan(struct sk_buff *skb,
  6142. struct genl_info *info)
  6143. {
  6144. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6145. struct net_device *dev = info->user_ptr[1];
  6146. struct wireless_dev *wdev = dev->ieee80211_ptr;
  6147. struct cfg80211_sched_scan_request *sched_scan_req;
  6148. int err;
  6149. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  6150. !rdev->ops->sched_scan_start)
  6151. return -EOPNOTSUPP;
  6152. if (rdev->sched_scan_req)
  6153. return -EINPROGRESS;
  6154. sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
  6155. info->attrs);
  6156. err = PTR_ERR_OR_ZERO(sched_scan_req);
  6157. if (err)
  6158. goto out_err;
  6159. err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
  6160. if (err)
  6161. goto out_free;
  6162. sched_scan_req->dev = dev;
  6163. sched_scan_req->wiphy = &rdev->wiphy;
  6164. if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
  6165. sched_scan_req->owner_nlportid = info->snd_portid;
  6166. rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
  6167. nl80211_send_sched_scan(rdev, dev,
  6168. NL80211_CMD_START_SCHED_SCAN);
  6169. return 0;
  6170. out_free:
  6171. kfree(sched_scan_req);
  6172. out_err:
  6173. return err;
  6174. }
  6175. static int nl80211_stop_sched_scan(struct sk_buff *skb,
  6176. struct genl_info *info)
  6177. {
  6178. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6179. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
  6180. !rdev->ops->sched_scan_stop)
  6181. return -EOPNOTSUPP;
  6182. return __cfg80211_stop_sched_scan(rdev, false);
  6183. }
  6184. static int nl80211_start_radar_detection(struct sk_buff *skb,
  6185. struct genl_info *info)
  6186. {
  6187. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6188. struct net_device *dev = info->user_ptr[1];
  6189. struct wireless_dev *wdev = dev->ieee80211_ptr;
  6190. struct cfg80211_chan_def chandef;
  6191. enum nl80211_dfs_regions dfs_region;
  6192. unsigned int cac_time_ms;
  6193. int err;
  6194. dfs_region = reg_get_dfs_region(wdev->wiphy);
  6195. if (dfs_region == NL80211_DFS_UNSET)
  6196. return -EINVAL;
  6197. err = nl80211_parse_chandef(rdev, info, &chandef);
  6198. if (err)
  6199. return err;
  6200. if (netif_carrier_ok(dev))
  6201. return -EBUSY;
  6202. if (rdev->wiphy.flags & WIPHY_FLAG_DFS_OFFLOAD)
  6203. return -EOPNOTSUPP;
  6204. if (wdev->cac_started)
  6205. return -EBUSY;
  6206. err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
  6207. wdev->iftype);
  6208. if (err < 0)
  6209. return err;
  6210. if (err == 0)
  6211. return -EINVAL;
  6212. if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
  6213. return -EINVAL;
  6214. if (!rdev->ops->start_radar_detection)
  6215. return -EOPNOTSUPP;
  6216. cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
  6217. if (WARN_ON(!cac_time_ms))
  6218. cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
  6219. err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
  6220. if (!err) {
  6221. wdev->chandef = chandef;
  6222. wdev->cac_started = true;
  6223. wdev->cac_start_time = jiffies;
  6224. wdev->cac_time_ms = cac_time_ms;
  6225. }
  6226. return err;
  6227. }
  6228. static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
  6229. {
  6230. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6231. struct net_device *dev = info->user_ptr[1];
  6232. struct wireless_dev *wdev = dev->ieee80211_ptr;
  6233. struct cfg80211_csa_settings params;
  6234. /* csa_attrs is defined static to avoid waste of stack size - this
  6235. * function is called under RTNL lock, so this should not be a problem.
  6236. */
  6237. static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
  6238. int err;
  6239. bool need_new_beacon = false;
  6240. int len, i;
  6241. u32 cs_count;
  6242. if (!rdev->ops->channel_switch ||
  6243. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
  6244. return -EOPNOTSUPP;
  6245. switch (dev->ieee80211_ptr->iftype) {
  6246. case NL80211_IFTYPE_AP:
  6247. case NL80211_IFTYPE_P2P_GO:
  6248. need_new_beacon = true;
  6249. /* useless if AP is not running */
  6250. if (!wdev->beacon_interval)
  6251. return -ENOTCONN;
  6252. break;
  6253. case NL80211_IFTYPE_ADHOC:
  6254. if (!wdev->ssid_len)
  6255. return -ENOTCONN;
  6256. break;
  6257. case NL80211_IFTYPE_MESH_POINT:
  6258. if (!wdev->mesh_id_len)
  6259. return -ENOTCONN;
  6260. break;
  6261. default:
  6262. return -EOPNOTSUPP;
  6263. }
  6264. memset(&params, 0, sizeof(params));
  6265. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  6266. !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
  6267. return -EINVAL;
  6268. /* only important for AP, IBSS and mesh create IEs internally */
  6269. if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
  6270. return -EINVAL;
  6271. /* Even though the attribute is u32, the specification says
  6272. * u8, so let's make sure we don't overflow.
  6273. */
  6274. cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
  6275. if (cs_count > 255)
  6276. return -EINVAL;
  6277. params.count = cs_count;
  6278. if (!need_new_beacon)
  6279. goto skip_beacons;
  6280. err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
  6281. if (err)
  6282. return err;
  6283. err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
  6284. info->attrs[NL80211_ATTR_CSA_IES],
  6285. nl80211_policy);
  6286. if (err)
  6287. return err;
  6288. err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
  6289. if (err)
  6290. return err;
  6291. if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
  6292. return -EINVAL;
  6293. len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
  6294. if (!len || (len % sizeof(u16)))
  6295. return -EINVAL;
  6296. params.n_counter_offsets_beacon = len / sizeof(u16);
  6297. if (rdev->wiphy.max_num_csa_counters &&
  6298. (params.n_counter_offsets_beacon >
  6299. rdev->wiphy.max_num_csa_counters))
  6300. return -EINVAL;
  6301. params.counter_offsets_beacon =
  6302. nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
  6303. /* sanity checks - counters should fit and be the same */
  6304. for (i = 0; i < params.n_counter_offsets_beacon; i++) {
  6305. u16 offset = params.counter_offsets_beacon[i];
  6306. if (offset >= params.beacon_csa.tail_len)
  6307. return -EINVAL;
  6308. if (params.beacon_csa.tail[offset] != params.count)
  6309. return -EINVAL;
  6310. }
  6311. if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
  6312. len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
  6313. if (!len || (len % sizeof(u16)))
  6314. return -EINVAL;
  6315. params.n_counter_offsets_presp = len / sizeof(u16);
  6316. if (rdev->wiphy.max_num_csa_counters &&
  6317. (params.n_counter_offsets_presp >
  6318. rdev->wiphy.max_num_csa_counters))
  6319. return -EINVAL;
  6320. params.counter_offsets_presp =
  6321. nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
  6322. /* sanity checks - counters should fit and be the same */
  6323. for (i = 0; i < params.n_counter_offsets_presp; i++) {
  6324. u16 offset = params.counter_offsets_presp[i];
  6325. if (offset >= params.beacon_csa.probe_resp_len)
  6326. return -EINVAL;
  6327. if (params.beacon_csa.probe_resp[offset] !=
  6328. params.count)
  6329. return -EINVAL;
  6330. }
  6331. }
  6332. skip_beacons:
  6333. err = nl80211_parse_chandef(rdev, info, &params.chandef);
  6334. if (err)
  6335. return err;
  6336. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
  6337. wdev->iftype))
  6338. return -EINVAL;
  6339. err = cfg80211_chandef_dfs_required(wdev->wiphy,
  6340. &params.chandef,
  6341. wdev->iftype);
  6342. if (err < 0)
  6343. return err;
  6344. if (err > 0)
  6345. params.radar_required = true;
  6346. if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
  6347. params.block_tx = true;
  6348. wdev_lock(wdev);
  6349. err = rdev_channel_switch(rdev, dev, &params);
  6350. wdev_unlock(wdev);
  6351. return err;
  6352. }
  6353. static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
  6354. u32 seq, int flags,
  6355. struct cfg80211_registered_device *rdev,
  6356. struct wireless_dev *wdev,
  6357. struct cfg80211_internal_bss *intbss)
  6358. {
  6359. struct cfg80211_bss *res = &intbss->pub;
  6360. const struct cfg80211_bss_ies *ies;
  6361. void *hdr;
  6362. struct nlattr *bss;
  6363. ASSERT_WDEV_LOCK(wdev);
  6364. hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
  6365. NL80211_CMD_NEW_SCAN_RESULTS);
  6366. if (!hdr)
  6367. return -1;
  6368. genl_dump_check_consistent(cb, hdr, &nl80211_fam);
  6369. if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
  6370. goto nla_put_failure;
  6371. if (wdev->netdev &&
  6372. nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
  6373. goto nla_put_failure;
  6374. if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  6375. NL80211_ATTR_PAD))
  6376. goto nla_put_failure;
  6377. bss = nla_nest_start(msg, NL80211_ATTR_BSS);
  6378. if (!bss)
  6379. goto nla_put_failure;
  6380. if ((!is_zero_ether_addr(res->bssid) &&
  6381. nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
  6382. goto nla_put_failure;
  6383. rcu_read_lock();
  6384. /* indicate whether we have probe response data or not */
  6385. if (rcu_access_pointer(res->proberesp_ies) &&
  6386. nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
  6387. goto fail_unlock_rcu;
  6388. /* this pointer prefers to be pointed to probe response data
  6389. * but is always valid
  6390. */
  6391. ies = rcu_dereference(res->ies);
  6392. if (ies) {
  6393. if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
  6394. NL80211_BSS_PAD))
  6395. goto fail_unlock_rcu;
  6396. if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
  6397. ies->len, ies->data))
  6398. goto fail_unlock_rcu;
  6399. }
  6400. /* and this pointer is always (unless driver didn't know) beacon data */
  6401. ies = rcu_dereference(res->beacon_ies);
  6402. if (ies && ies->from_beacon) {
  6403. if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
  6404. NL80211_BSS_PAD))
  6405. goto fail_unlock_rcu;
  6406. if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
  6407. ies->len, ies->data))
  6408. goto fail_unlock_rcu;
  6409. }
  6410. rcu_read_unlock();
  6411. if (res->beacon_interval &&
  6412. nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
  6413. goto nla_put_failure;
  6414. if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
  6415. nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
  6416. nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
  6417. nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
  6418. jiffies_to_msecs(jiffies - intbss->ts)))
  6419. goto nla_put_failure;
  6420. if (intbss->parent_tsf &&
  6421. (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
  6422. intbss->parent_tsf, NL80211_BSS_PAD) ||
  6423. nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
  6424. intbss->parent_bssid)))
  6425. goto nla_put_failure;
  6426. if (intbss->ts_boottime &&
  6427. nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
  6428. intbss->ts_boottime, NL80211_BSS_PAD))
  6429. goto nla_put_failure;
  6430. if (!nl80211_put_signal(msg, intbss->pub.chains,
  6431. intbss->pub.chain_signal,
  6432. NL80211_BSS_CHAIN_SIGNAL))
  6433. goto nla_put_failure;
  6434. switch (rdev->wiphy.signal_type) {
  6435. case CFG80211_SIGNAL_TYPE_MBM:
  6436. if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
  6437. goto nla_put_failure;
  6438. break;
  6439. case CFG80211_SIGNAL_TYPE_UNSPEC:
  6440. if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
  6441. goto nla_put_failure;
  6442. break;
  6443. default:
  6444. break;
  6445. }
  6446. switch (wdev->iftype) {
  6447. case NL80211_IFTYPE_P2P_CLIENT:
  6448. case NL80211_IFTYPE_STATION:
  6449. if (intbss == wdev->current_bss &&
  6450. nla_put_u32(msg, NL80211_BSS_STATUS,
  6451. NL80211_BSS_STATUS_ASSOCIATED))
  6452. goto nla_put_failure;
  6453. break;
  6454. case NL80211_IFTYPE_ADHOC:
  6455. if (intbss == wdev->current_bss &&
  6456. nla_put_u32(msg, NL80211_BSS_STATUS,
  6457. NL80211_BSS_STATUS_IBSS_JOINED))
  6458. goto nla_put_failure;
  6459. break;
  6460. default:
  6461. break;
  6462. }
  6463. nla_nest_end(msg, bss);
  6464. genlmsg_end(msg, hdr);
  6465. return 0;
  6466. fail_unlock_rcu:
  6467. rcu_read_unlock();
  6468. nla_put_failure:
  6469. genlmsg_cancel(msg, hdr);
  6470. return -EMSGSIZE;
  6471. }
  6472. static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
  6473. {
  6474. struct cfg80211_registered_device *rdev;
  6475. struct cfg80211_internal_bss *scan;
  6476. struct wireless_dev *wdev;
  6477. int start = cb->args[2], idx = 0;
  6478. int err;
  6479. rtnl_lock();
  6480. err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  6481. if (err) {
  6482. rtnl_unlock();
  6483. return err;
  6484. }
  6485. wdev_lock(wdev);
  6486. spin_lock_bh(&rdev->bss_lock);
  6487. cfg80211_bss_expire(rdev);
  6488. cb->seq = rdev->bss_generation;
  6489. list_for_each_entry(scan, &rdev->bss_list, list) {
  6490. if (++idx <= start)
  6491. continue;
  6492. if (nl80211_send_bss(skb, cb,
  6493. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  6494. rdev, wdev, scan) < 0) {
  6495. idx--;
  6496. break;
  6497. }
  6498. }
  6499. spin_unlock_bh(&rdev->bss_lock);
  6500. wdev_unlock(wdev);
  6501. cb->args[2] = idx;
  6502. rtnl_unlock();
  6503. return skb->len;
  6504. }
  6505. static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
  6506. int flags, struct net_device *dev,
  6507. bool allow_radio_stats,
  6508. struct survey_info *survey)
  6509. {
  6510. void *hdr;
  6511. struct nlattr *infoattr;
  6512. /* skip radio stats if userspace didn't request them */
  6513. if (!survey->channel && !allow_radio_stats)
  6514. return 0;
  6515. hdr = nl80211hdr_put(msg, portid, seq, flags,
  6516. NL80211_CMD_NEW_SURVEY_RESULTS);
  6517. if (!hdr)
  6518. return -ENOMEM;
  6519. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
  6520. goto nla_put_failure;
  6521. infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
  6522. if (!infoattr)
  6523. goto nla_put_failure;
  6524. if (survey->channel &&
  6525. nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
  6526. survey->channel->center_freq))
  6527. goto nla_put_failure;
  6528. if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
  6529. nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
  6530. goto nla_put_failure;
  6531. if ((survey->filled & SURVEY_INFO_IN_USE) &&
  6532. nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
  6533. goto nla_put_failure;
  6534. if ((survey->filled & SURVEY_INFO_TIME) &&
  6535. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
  6536. survey->time, NL80211_SURVEY_INFO_PAD))
  6537. goto nla_put_failure;
  6538. if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
  6539. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
  6540. survey->time_busy, NL80211_SURVEY_INFO_PAD))
  6541. goto nla_put_failure;
  6542. if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
  6543. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
  6544. survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
  6545. goto nla_put_failure;
  6546. if ((survey->filled & SURVEY_INFO_TIME_RX) &&
  6547. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
  6548. survey->time_rx, NL80211_SURVEY_INFO_PAD))
  6549. goto nla_put_failure;
  6550. if ((survey->filled & SURVEY_INFO_TIME_TX) &&
  6551. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
  6552. survey->time_tx, NL80211_SURVEY_INFO_PAD))
  6553. goto nla_put_failure;
  6554. if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
  6555. nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
  6556. survey->time_scan, NL80211_SURVEY_INFO_PAD))
  6557. goto nla_put_failure;
  6558. nla_nest_end(msg, infoattr);
  6559. genlmsg_end(msg, hdr);
  6560. return 0;
  6561. nla_put_failure:
  6562. genlmsg_cancel(msg, hdr);
  6563. return -EMSGSIZE;
  6564. }
  6565. static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
  6566. {
  6567. struct survey_info survey;
  6568. struct cfg80211_registered_device *rdev;
  6569. struct wireless_dev *wdev;
  6570. int survey_idx = cb->args[2];
  6571. int res;
  6572. bool radio_stats;
  6573. rtnl_lock();
  6574. res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
  6575. if (res)
  6576. goto out_err;
  6577. /* prepare_wdev_dump parsed the attributes */
  6578. radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
  6579. if (!wdev->netdev) {
  6580. res = -EINVAL;
  6581. goto out_err;
  6582. }
  6583. if (!rdev->ops->dump_survey) {
  6584. res = -EOPNOTSUPP;
  6585. goto out_err;
  6586. }
  6587. while (1) {
  6588. res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
  6589. if (res == -ENOENT)
  6590. break;
  6591. if (res)
  6592. goto out_err;
  6593. /* don't send disabled channels, but do send non-channel data */
  6594. if (survey.channel &&
  6595. survey.channel->flags & IEEE80211_CHAN_DISABLED) {
  6596. survey_idx++;
  6597. continue;
  6598. }
  6599. if (nl80211_send_survey(skb,
  6600. NETLINK_CB(cb->skb).portid,
  6601. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  6602. wdev->netdev, radio_stats, &survey) < 0)
  6603. goto out;
  6604. survey_idx++;
  6605. }
  6606. out:
  6607. cb->args[2] = survey_idx;
  6608. res = skb->len;
  6609. out_err:
  6610. rtnl_unlock();
  6611. return res;
  6612. }
  6613. static bool nl80211_valid_wpa_versions(u32 wpa_versions)
  6614. {
  6615. return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
  6616. NL80211_WPA_VERSION_2));
  6617. }
  6618. static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
  6619. {
  6620. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6621. struct net_device *dev = info->user_ptr[1];
  6622. struct ieee80211_channel *chan;
  6623. const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
  6624. int err, ssid_len, ie_len = 0, auth_data_len = 0;
  6625. enum nl80211_auth_type auth_type;
  6626. struct key_parse key;
  6627. bool local_state_change;
  6628. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6629. return -EINVAL;
  6630. if (!info->attrs[NL80211_ATTR_MAC])
  6631. return -EINVAL;
  6632. if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
  6633. return -EINVAL;
  6634. if (!info->attrs[NL80211_ATTR_SSID])
  6635. return -EINVAL;
  6636. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  6637. return -EINVAL;
  6638. err = nl80211_parse_key(info, &key);
  6639. if (err)
  6640. return err;
  6641. if (key.idx >= 0) {
  6642. if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
  6643. return -EINVAL;
  6644. if (!key.p.key || !key.p.key_len)
  6645. return -EINVAL;
  6646. if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
  6647. key.p.key_len != WLAN_KEY_LEN_WEP40) &&
  6648. (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
  6649. key.p.key_len != WLAN_KEY_LEN_WEP104))
  6650. return -EINVAL;
  6651. if (key.idx > 3)
  6652. return -EINVAL;
  6653. } else {
  6654. key.p.key_len = 0;
  6655. key.p.key = NULL;
  6656. }
  6657. if (key.idx >= 0) {
  6658. int i;
  6659. bool ok = false;
  6660. for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
  6661. if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
  6662. ok = true;
  6663. break;
  6664. }
  6665. }
  6666. if (!ok)
  6667. return -EINVAL;
  6668. }
  6669. if (!rdev->ops->auth)
  6670. return -EOPNOTSUPP;
  6671. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6672. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6673. return -EOPNOTSUPP;
  6674. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6675. chan = nl80211_get_valid_chan(&rdev->wiphy,
  6676. info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  6677. if (!chan)
  6678. return -EINVAL;
  6679. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6680. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6681. if (info->attrs[NL80211_ATTR_IE]) {
  6682. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6683. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6684. }
  6685. auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  6686. if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
  6687. return -EINVAL;
  6688. if ((auth_type == NL80211_AUTHTYPE_SAE ||
  6689. auth_type == NL80211_AUTHTYPE_FILS_SK ||
  6690. auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
  6691. auth_type == NL80211_AUTHTYPE_FILS_PK) &&
  6692. !info->attrs[NL80211_ATTR_AUTH_DATA])
  6693. return -EINVAL;
  6694. if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
  6695. if (auth_type != NL80211_AUTHTYPE_SAE &&
  6696. auth_type != NL80211_AUTHTYPE_FILS_SK &&
  6697. auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
  6698. auth_type != NL80211_AUTHTYPE_FILS_PK)
  6699. return -EINVAL;
  6700. auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
  6701. auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
  6702. /* need to include at least Auth Transaction and Status Code */
  6703. if (auth_data_len < 4)
  6704. return -EINVAL;
  6705. }
  6706. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6707. /*
  6708. * Since we no longer track auth state, ignore
  6709. * requests to only change local state.
  6710. */
  6711. if (local_state_change)
  6712. return 0;
  6713. wdev_lock(dev->ieee80211_ptr);
  6714. err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
  6715. ssid, ssid_len, ie, ie_len,
  6716. key.p.key, key.p.key_len, key.idx,
  6717. auth_data, auth_data_len);
  6718. wdev_unlock(dev->ieee80211_ptr);
  6719. return err;
  6720. }
  6721. static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
  6722. struct genl_info *info,
  6723. struct cfg80211_crypto_settings *settings,
  6724. int cipher_limit)
  6725. {
  6726. memset(settings, 0, sizeof(*settings));
  6727. settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
  6728. if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
  6729. u16 proto;
  6730. proto = nla_get_u16(
  6731. info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
  6732. settings->control_port_ethertype = cpu_to_be16(proto);
  6733. if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
  6734. proto != ETH_P_PAE)
  6735. return -EINVAL;
  6736. if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
  6737. settings->control_port_no_encrypt = true;
  6738. } else
  6739. settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
  6740. if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
  6741. void *data;
  6742. int len, i;
  6743. data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  6744. len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
  6745. settings->n_ciphers_pairwise = len / sizeof(u32);
  6746. if (len % sizeof(u32))
  6747. return -EINVAL;
  6748. if (settings->n_ciphers_pairwise > cipher_limit)
  6749. return -EINVAL;
  6750. memcpy(settings->ciphers_pairwise, data, len);
  6751. for (i = 0; i < settings->n_ciphers_pairwise; i++)
  6752. if (!cfg80211_supported_cipher_suite(
  6753. &rdev->wiphy,
  6754. settings->ciphers_pairwise[i]))
  6755. return -EINVAL;
  6756. }
  6757. if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
  6758. settings->cipher_group =
  6759. nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
  6760. if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
  6761. settings->cipher_group))
  6762. return -EINVAL;
  6763. }
  6764. if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
  6765. settings->wpa_versions =
  6766. nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
  6767. if (!nl80211_valid_wpa_versions(settings->wpa_versions))
  6768. return -EINVAL;
  6769. }
  6770. if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
  6771. void *data;
  6772. int len;
  6773. data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
  6774. len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
  6775. settings->n_akm_suites = len / sizeof(u32);
  6776. if (len % sizeof(u32))
  6777. return -EINVAL;
  6778. if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
  6779. return -EINVAL;
  6780. memcpy(settings->akm_suites, data, len);
  6781. }
  6782. return 0;
  6783. }
  6784. static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
  6785. {
  6786. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6787. struct net_device *dev = info->user_ptr[1];
  6788. struct ieee80211_channel *chan;
  6789. struct cfg80211_assoc_request req = {};
  6790. const u8 *bssid, *ssid;
  6791. int err, ssid_len = 0;
  6792. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6793. return -EINVAL;
  6794. if (!info->attrs[NL80211_ATTR_MAC] ||
  6795. !info->attrs[NL80211_ATTR_SSID] ||
  6796. !info->attrs[NL80211_ATTR_WIPHY_FREQ])
  6797. return -EINVAL;
  6798. if (!rdev->ops->assoc)
  6799. return -EOPNOTSUPP;
  6800. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6801. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6802. return -EOPNOTSUPP;
  6803. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6804. chan = nl80211_get_valid_chan(&rdev->wiphy,
  6805. info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  6806. if (!chan)
  6807. return -EINVAL;
  6808. ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  6809. ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  6810. if (info->attrs[NL80211_ATTR_IE]) {
  6811. req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6812. req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6813. }
  6814. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  6815. enum nl80211_mfp mfp =
  6816. nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  6817. if (mfp == NL80211_MFP_REQUIRED)
  6818. req.use_mfp = true;
  6819. else if (mfp != NL80211_MFP_NO)
  6820. return -EINVAL;
  6821. }
  6822. if (info->attrs[NL80211_ATTR_PREV_BSSID])
  6823. req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
  6824. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  6825. req.flags |= ASSOC_REQ_DISABLE_HT;
  6826. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6827. memcpy(&req.ht_capa_mask,
  6828. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  6829. sizeof(req.ht_capa_mask));
  6830. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  6831. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  6832. return -EINVAL;
  6833. memcpy(&req.ht_capa,
  6834. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  6835. sizeof(req.ht_capa));
  6836. }
  6837. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
  6838. req.flags |= ASSOC_REQ_DISABLE_VHT;
  6839. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  6840. memcpy(&req.vht_capa_mask,
  6841. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
  6842. sizeof(req.vht_capa_mask));
  6843. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
  6844. if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  6845. return -EINVAL;
  6846. memcpy(&req.vht_capa,
  6847. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
  6848. sizeof(req.vht_capa));
  6849. }
  6850. if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
  6851. if (!((rdev->wiphy.features &
  6852. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
  6853. (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
  6854. !wiphy_ext_feature_isset(&rdev->wiphy,
  6855. NL80211_EXT_FEATURE_RRM))
  6856. return -EINVAL;
  6857. req.flags |= ASSOC_REQ_USE_RRM;
  6858. }
  6859. if (info->attrs[NL80211_ATTR_FILS_KEK]) {
  6860. req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
  6861. req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
  6862. if (!info->attrs[NL80211_ATTR_FILS_NONCES])
  6863. return -EINVAL;
  6864. req.fils_nonces =
  6865. nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
  6866. }
  6867. err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
  6868. if (!err) {
  6869. wdev_lock(dev->ieee80211_ptr);
  6870. err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
  6871. ssid, ssid_len, &req);
  6872. if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
  6873. dev->ieee80211_ptr->conn_owner_nlportid =
  6874. info->snd_portid;
  6875. memcpy(dev->ieee80211_ptr->disconnect_bssid,
  6876. bssid, ETH_ALEN);
  6877. }
  6878. wdev_unlock(dev->ieee80211_ptr);
  6879. }
  6880. return err;
  6881. }
  6882. static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
  6883. {
  6884. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6885. struct net_device *dev = info->user_ptr[1];
  6886. const u8 *ie = NULL, *bssid;
  6887. int ie_len = 0, err;
  6888. u16 reason_code;
  6889. bool local_state_change;
  6890. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6891. return -EINVAL;
  6892. if (!info->attrs[NL80211_ATTR_MAC])
  6893. return -EINVAL;
  6894. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  6895. return -EINVAL;
  6896. if (!rdev->ops->deauth)
  6897. return -EOPNOTSUPP;
  6898. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6899. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6900. return -EOPNOTSUPP;
  6901. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6902. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  6903. if (reason_code == 0) {
  6904. /* Reason Code 0 is reserved */
  6905. return -EINVAL;
  6906. }
  6907. if (info->attrs[NL80211_ATTR_IE]) {
  6908. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6909. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6910. }
  6911. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6912. wdev_lock(dev->ieee80211_ptr);
  6913. err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
  6914. local_state_change);
  6915. wdev_unlock(dev->ieee80211_ptr);
  6916. return err;
  6917. }
  6918. static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
  6919. {
  6920. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6921. struct net_device *dev = info->user_ptr[1];
  6922. const u8 *ie = NULL, *bssid;
  6923. int ie_len = 0, err;
  6924. u16 reason_code;
  6925. bool local_state_change;
  6926. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6927. return -EINVAL;
  6928. if (!info->attrs[NL80211_ATTR_MAC])
  6929. return -EINVAL;
  6930. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  6931. return -EINVAL;
  6932. if (!rdev->ops->disassoc)
  6933. return -EOPNOTSUPP;
  6934. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  6935. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  6936. return -EOPNOTSUPP;
  6937. bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  6938. reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  6939. if (reason_code == 0) {
  6940. /* Reason Code 0 is reserved */
  6941. return -EINVAL;
  6942. }
  6943. if (info->attrs[NL80211_ATTR_IE]) {
  6944. ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  6945. ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  6946. }
  6947. local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
  6948. wdev_lock(dev->ieee80211_ptr);
  6949. err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
  6950. local_state_change);
  6951. wdev_unlock(dev->ieee80211_ptr);
  6952. return err;
  6953. }
  6954. static bool
  6955. nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
  6956. int mcast_rate[NUM_NL80211_BANDS],
  6957. int rateval)
  6958. {
  6959. struct wiphy *wiphy = &rdev->wiphy;
  6960. bool found = false;
  6961. int band, i;
  6962. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  6963. struct ieee80211_supported_band *sband;
  6964. sband = wiphy->bands[band];
  6965. if (!sband)
  6966. continue;
  6967. for (i = 0; i < sband->n_bitrates; i++) {
  6968. if (sband->bitrates[i].bitrate == rateval) {
  6969. mcast_rate[band] = i + 1;
  6970. found = true;
  6971. break;
  6972. }
  6973. }
  6974. }
  6975. return found;
  6976. }
  6977. static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
  6978. {
  6979. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  6980. struct net_device *dev = info->user_ptr[1];
  6981. struct cfg80211_ibss_params ibss;
  6982. struct wiphy *wiphy;
  6983. struct cfg80211_cached_keys *connkeys = NULL;
  6984. int err;
  6985. memset(&ibss, 0, sizeof(ibss));
  6986. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  6987. return -EINVAL;
  6988. if (!info->attrs[NL80211_ATTR_SSID] ||
  6989. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  6990. return -EINVAL;
  6991. ibss.beacon_interval = 100;
  6992. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
  6993. ibss.beacon_interval =
  6994. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  6995. err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
  6996. ibss.beacon_interval);
  6997. if (err)
  6998. return err;
  6999. if (!rdev->ops->join_ibss)
  7000. return -EOPNOTSUPP;
  7001. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  7002. return -EOPNOTSUPP;
  7003. wiphy = &rdev->wiphy;
  7004. if (info->attrs[NL80211_ATTR_MAC]) {
  7005. ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7006. if (!is_valid_ether_addr(ibss.bssid))
  7007. return -EINVAL;
  7008. }
  7009. ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  7010. ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  7011. if (info->attrs[NL80211_ATTR_IE]) {
  7012. ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  7013. ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  7014. }
  7015. err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
  7016. if (err)
  7017. return err;
  7018. if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
  7019. NL80211_IFTYPE_ADHOC))
  7020. return -EINVAL;
  7021. switch (ibss.chandef.width) {
  7022. case NL80211_CHAN_WIDTH_5:
  7023. case NL80211_CHAN_WIDTH_10:
  7024. case NL80211_CHAN_WIDTH_20_NOHT:
  7025. break;
  7026. case NL80211_CHAN_WIDTH_20:
  7027. case NL80211_CHAN_WIDTH_40:
  7028. if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
  7029. return -EINVAL;
  7030. break;
  7031. case NL80211_CHAN_WIDTH_80:
  7032. case NL80211_CHAN_WIDTH_80P80:
  7033. case NL80211_CHAN_WIDTH_160:
  7034. if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
  7035. return -EINVAL;
  7036. if (!wiphy_ext_feature_isset(&rdev->wiphy,
  7037. NL80211_EXT_FEATURE_VHT_IBSS))
  7038. return -EINVAL;
  7039. break;
  7040. default:
  7041. return -EINVAL;
  7042. }
  7043. ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
  7044. ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
  7045. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  7046. u8 *rates =
  7047. nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  7048. int n_rates =
  7049. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  7050. struct ieee80211_supported_band *sband =
  7051. wiphy->bands[ibss.chandef.chan->band];
  7052. err = ieee80211_get_ratemask(sband, rates, n_rates,
  7053. &ibss.basic_rates);
  7054. if (err)
  7055. return err;
  7056. }
  7057. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  7058. memcpy(&ibss.ht_capa_mask,
  7059. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  7060. sizeof(ibss.ht_capa_mask));
  7061. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  7062. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  7063. return -EINVAL;
  7064. memcpy(&ibss.ht_capa,
  7065. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  7066. sizeof(ibss.ht_capa));
  7067. }
  7068. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  7069. !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
  7070. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  7071. return -EINVAL;
  7072. if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  7073. bool no_ht = false;
  7074. connkeys = nl80211_parse_connkeys(rdev,
  7075. info->attrs[NL80211_ATTR_KEYS],
  7076. &no_ht);
  7077. if (IS_ERR(connkeys))
  7078. return PTR_ERR(connkeys);
  7079. if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
  7080. no_ht) {
  7081. kzfree(connkeys);
  7082. return -EINVAL;
  7083. }
  7084. }
  7085. ibss.control_port =
  7086. nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
  7087. ibss.userspace_handles_dfs =
  7088. nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
  7089. err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
  7090. if (err)
  7091. kzfree(connkeys);
  7092. return err;
  7093. }
  7094. static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
  7095. {
  7096. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7097. struct net_device *dev = info->user_ptr[1];
  7098. if (!rdev->ops->leave_ibss)
  7099. return -EOPNOTSUPP;
  7100. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
  7101. return -EOPNOTSUPP;
  7102. return cfg80211_leave_ibss(rdev, dev, false);
  7103. }
  7104. static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
  7105. {
  7106. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7107. struct net_device *dev = info->user_ptr[1];
  7108. int mcast_rate[NUM_NL80211_BANDS];
  7109. u32 nla_rate;
  7110. int err;
  7111. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
  7112. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
  7113. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
  7114. return -EOPNOTSUPP;
  7115. if (!rdev->ops->set_mcast_rate)
  7116. return -EOPNOTSUPP;
  7117. memset(mcast_rate, 0, sizeof(mcast_rate));
  7118. if (!info->attrs[NL80211_ATTR_MCAST_RATE])
  7119. return -EINVAL;
  7120. nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
  7121. if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
  7122. return -EINVAL;
  7123. err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
  7124. return err;
  7125. }
  7126. static struct sk_buff *
  7127. __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
  7128. struct wireless_dev *wdev, int approxlen,
  7129. u32 portid, u32 seq, enum nl80211_commands cmd,
  7130. enum nl80211_attrs attr,
  7131. const struct nl80211_vendor_cmd_info *info,
  7132. gfp_t gfp)
  7133. {
  7134. struct sk_buff *skb;
  7135. void *hdr;
  7136. struct nlattr *data;
  7137. skb = nlmsg_new(approxlen + 100, gfp);
  7138. if (!skb)
  7139. return NULL;
  7140. hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
  7141. if (!hdr) {
  7142. kfree_skb(skb);
  7143. return NULL;
  7144. }
  7145. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  7146. goto nla_put_failure;
  7147. if (info) {
  7148. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
  7149. info->vendor_id))
  7150. goto nla_put_failure;
  7151. if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
  7152. info->subcmd))
  7153. goto nla_put_failure;
  7154. }
  7155. if (wdev) {
  7156. if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
  7157. wdev_id(wdev), NL80211_ATTR_PAD))
  7158. goto nla_put_failure;
  7159. if (wdev->netdev &&
  7160. nla_put_u32(skb, NL80211_ATTR_IFINDEX,
  7161. wdev->netdev->ifindex))
  7162. goto nla_put_failure;
  7163. }
  7164. data = nla_nest_start(skb, attr);
  7165. if (!data)
  7166. goto nla_put_failure;
  7167. ((void **)skb->cb)[0] = rdev;
  7168. ((void **)skb->cb)[1] = hdr;
  7169. ((void **)skb->cb)[2] = data;
  7170. return skb;
  7171. nla_put_failure:
  7172. kfree_skb(skb);
  7173. return NULL;
  7174. }
  7175. struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
  7176. struct wireless_dev *wdev,
  7177. enum nl80211_commands cmd,
  7178. enum nl80211_attrs attr,
  7179. int vendor_event_idx,
  7180. int approxlen, gfp_t gfp)
  7181. {
  7182. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  7183. const struct nl80211_vendor_cmd_info *info;
  7184. switch (cmd) {
  7185. case NL80211_CMD_TESTMODE:
  7186. if (WARN_ON(vendor_event_idx != -1))
  7187. return NULL;
  7188. info = NULL;
  7189. break;
  7190. case NL80211_CMD_VENDOR:
  7191. if (WARN_ON(vendor_event_idx < 0 ||
  7192. vendor_event_idx >= wiphy->n_vendor_events))
  7193. return NULL;
  7194. info = &wiphy->vendor_events[vendor_event_idx];
  7195. break;
  7196. default:
  7197. WARN_ON(1);
  7198. return NULL;
  7199. }
  7200. return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
  7201. cmd, attr, info, gfp);
  7202. }
  7203. EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
  7204. void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
  7205. {
  7206. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  7207. void *hdr = ((void **)skb->cb)[1];
  7208. struct nlattr *data = ((void **)skb->cb)[2];
  7209. enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
  7210. /* clear CB data for netlink core to own from now on */
  7211. memset(skb->cb, 0, sizeof(skb->cb));
  7212. nla_nest_end(skb, data);
  7213. genlmsg_end(skb, hdr);
  7214. if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
  7215. mcgrp = NL80211_MCGRP_VENDOR;
  7216. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
  7217. mcgrp, gfp);
  7218. }
  7219. EXPORT_SYMBOL(__cfg80211_send_event_skb);
  7220. #ifdef CONFIG_NL80211_TESTMODE
  7221. static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
  7222. {
  7223. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7224. struct wireless_dev *wdev =
  7225. __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
  7226. int err;
  7227. if (!rdev->ops->testmode_cmd)
  7228. return -EOPNOTSUPP;
  7229. if (IS_ERR(wdev)) {
  7230. err = PTR_ERR(wdev);
  7231. if (err != -EINVAL)
  7232. return err;
  7233. wdev = NULL;
  7234. } else if (wdev->wiphy != &rdev->wiphy) {
  7235. return -EINVAL;
  7236. }
  7237. if (!info->attrs[NL80211_ATTR_TESTDATA])
  7238. return -EINVAL;
  7239. rdev->cur_cmd_info = info;
  7240. err = rdev_testmode_cmd(rdev, wdev,
  7241. nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
  7242. nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
  7243. rdev->cur_cmd_info = NULL;
  7244. return err;
  7245. }
  7246. static int nl80211_testmode_dump(struct sk_buff *skb,
  7247. struct netlink_callback *cb)
  7248. {
  7249. struct cfg80211_registered_device *rdev;
  7250. int err;
  7251. long phy_idx;
  7252. void *data = NULL;
  7253. int data_len = 0;
  7254. rtnl_lock();
  7255. if (cb->args[0]) {
  7256. /*
  7257. * 0 is a valid index, but not valid for args[0],
  7258. * so we need to offset by 1.
  7259. */
  7260. phy_idx = cb->args[0] - 1;
  7261. } else {
  7262. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  7263. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  7264. nl80211_policy);
  7265. if (err)
  7266. goto out_err;
  7267. rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
  7268. nl80211_fam.attrbuf);
  7269. if (IS_ERR(rdev)) {
  7270. err = PTR_ERR(rdev);
  7271. goto out_err;
  7272. }
  7273. phy_idx = rdev->wiphy_idx;
  7274. rdev = NULL;
  7275. if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
  7276. cb->args[1] =
  7277. (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
  7278. }
  7279. if (cb->args[1]) {
  7280. data = nla_data((void *)cb->args[1]);
  7281. data_len = nla_len((void *)cb->args[1]);
  7282. }
  7283. rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
  7284. if (!rdev) {
  7285. err = -ENOENT;
  7286. goto out_err;
  7287. }
  7288. if (!rdev->ops->testmode_dump) {
  7289. err = -EOPNOTSUPP;
  7290. goto out_err;
  7291. }
  7292. while (1) {
  7293. void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
  7294. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  7295. NL80211_CMD_TESTMODE);
  7296. struct nlattr *tmdata;
  7297. if (!hdr)
  7298. break;
  7299. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
  7300. genlmsg_cancel(skb, hdr);
  7301. break;
  7302. }
  7303. tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
  7304. if (!tmdata) {
  7305. genlmsg_cancel(skb, hdr);
  7306. break;
  7307. }
  7308. err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
  7309. nla_nest_end(skb, tmdata);
  7310. if (err == -ENOBUFS || err == -ENOENT) {
  7311. genlmsg_cancel(skb, hdr);
  7312. break;
  7313. } else if (err) {
  7314. genlmsg_cancel(skb, hdr);
  7315. goto out_err;
  7316. }
  7317. genlmsg_end(skb, hdr);
  7318. }
  7319. err = skb->len;
  7320. /* see above */
  7321. cb->args[0] = phy_idx + 1;
  7322. out_err:
  7323. rtnl_unlock();
  7324. return err;
  7325. }
  7326. #endif
  7327. static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
  7328. {
  7329. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7330. struct net_device *dev = info->user_ptr[1];
  7331. struct cfg80211_connect_params connect;
  7332. struct wiphy *wiphy;
  7333. struct cfg80211_cached_keys *connkeys = NULL;
  7334. int err;
  7335. memset(&connect, 0, sizeof(connect));
  7336. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  7337. return -EINVAL;
  7338. if (!info->attrs[NL80211_ATTR_SSID] ||
  7339. !nla_len(info->attrs[NL80211_ATTR_SSID]))
  7340. return -EINVAL;
  7341. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  7342. connect.auth_type =
  7343. nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  7344. if (!nl80211_valid_auth_type(rdev, connect.auth_type,
  7345. NL80211_CMD_CONNECT))
  7346. return -EINVAL;
  7347. } else
  7348. connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  7349. connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
  7350. err = nl80211_crypto_settings(rdev, info, &connect.crypto,
  7351. NL80211_MAX_NR_CIPHER_SUITES);
  7352. if (err)
  7353. return err;
  7354. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7355. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7356. return -EOPNOTSUPP;
  7357. wiphy = &rdev->wiphy;
  7358. connect.bg_scan_period = -1;
  7359. if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
  7360. (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
  7361. connect.bg_scan_period =
  7362. nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
  7363. }
  7364. if (info->attrs[NL80211_ATTR_MAC])
  7365. connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7366. else if (info->attrs[NL80211_ATTR_MAC_HINT])
  7367. connect.bssid_hint =
  7368. nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
  7369. connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  7370. connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  7371. if (info->attrs[NL80211_ATTR_IE]) {
  7372. connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  7373. connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  7374. }
  7375. if (info->attrs[NL80211_ATTR_USE_MFP]) {
  7376. connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
  7377. if (connect.mfp != NL80211_MFP_REQUIRED &&
  7378. connect.mfp != NL80211_MFP_NO)
  7379. return -EINVAL;
  7380. } else {
  7381. connect.mfp = NL80211_MFP_NO;
  7382. }
  7383. if (info->attrs[NL80211_ATTR_PREV_BSSID])
  7384. connect.prev_bssid =
  7385. nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
  7386. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7387. connect.channel = nl80211_get_valid_chan(
  7388. wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
  7389. if (!connect.channel)
  7390. return -EINVAL;
  7391. } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
  7392. connect.channel_hint = nl80211_get_valid_chan(
  7393. wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
  7394. if (!connect.channel_hint)
  7395. return -EINVAL;
  7396. }
  7397. if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
  7398. connkeys = nl80211_parse_connkeys(rdev,
  7399. info->attrs[NL80211_ATTR_KEYS], NULL);
  7400. if (IS_ERR(connkeys))
  7401. return PTR_ERR(connkeys);
  7402. }
  7403. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
  7404. connect.flags |= ASSOC_REQ_DISABLE_HT;
  7405. if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
  7406. memcpy(&connect.ht_capa_mask,
  7407. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
  7408. sizeof(connect.ht_capa_mask));
  7409. if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
  7410. if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
  7411. kzfree(connkeys);
  7412. return -EINVAL;
  7413. }
  7414. memcpy(&connect.ht_capa,
  7415. nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
  7416. sizeof(connect.ht_capa));
  7417. }
  7418. if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
  7419. connect.flags |= ASSOC_REQ_DISABLE_VHT;
  7420. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
  7421. memcpy(&connect.vht_capa_mask,
  7422. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
  7423. sizeof(connect.vht_capa_mask));
  7424. if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
  7425. if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
  7426. kzfree(connkeys);
  7427. return -EINVAL;
  7428. }
  7429. memcpy(&connect.vht_capa,
  7430. nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
  7431. sizeof(connect.vht_capa));
  7432. }
  7433. if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
  7434. if (!((rdev->wiphy.features &
  7435. NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
  7436. (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
  7437. !wiphy_ext_feature_isset(&rdev->wiphy,
  7438. NL80211_EXT_FEATURE_RRM)) {
  7439. kzfree(connkeys);
  7440. return -EINVAL;
  7441. }
  7442. connect.flags |= ASSOC_REQ_USE_RRM;
  7443. }
  7444. connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
  7445. if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
  7446. kzfree(connkeys);
  7447. return -EOPNOTSUPP;
  7448. }
  7449. if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
  7450. /* bss selection makes no sense if bssid is set */
  7451. if (connect.bssid) {
  7452. kzfree(connkeys);
  7453. return -EINVAL;
  7454. }
  7455. err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
  7456. wiphy, &connect.bss_select);
  7457. if (err) {
  7458. kzfree(connkeys);
  7459. return err;
  7460. }
  7461. }
  7462. if (wiphy_ext_feature_isset(&rdev->wiphy,
  7463. NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
  7464. info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
  7465. info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
  7466. info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
  7467. info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
  7468. connect.fils_erp_username =
  7469. nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
  7470. connect.fils_erp_username_len =
  7471. nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
  7472. connect.fils_erp_realm =
  7473. nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
  7474. connect.fils_erp_realm_len =
  7475. nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
  7476. connect.fils_erp_next_seq_num =
  7477. nla_get_u16(
  7478. info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
  7479. connect.fils_erp_rrk =
  7480. nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
  7481. connect.fils_erp_rrk_len =
  7482. nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
  7483. } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
  7484. info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
  7485. info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
  7486. info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
  7487. kzfree(connkeys);
  7488. return -EINVAL;
  7489. }
  7490. if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
  7491. if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
  7492. return -EINVAL;
  7493. }
  7494. connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
  7495. }
  7496. wdev_lock(dev->ieee80211_ptr);
  7497. err = cfg80211_connect(rdev, dev, &connect, connkeys,
  7498. connect.prev_bssid);
  7499. if (err)
  7500. kzfree(connkeys);
  7501. if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
  7502. dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
  7503. if (connect.bssid)
  7504. memcpy(dev->ieee80211_ptr->disconnect_bssid,
  7505. connect.bssid, ETH_ALEN);
  7506. else
  7507. memset(dev->ieee80211_ptr->disconnect_bssid,
  7508. 0, ETH_ALEN);
  7509. }
  7510. wdev_unlock(dev->ieee80211_ptr);
  7511. return err;
  7512. }
  7513. static int nl80211_update_connect_params(struct sk_buff *skb,
  7514. struct genl_info *info)
  7515. {
  7516. struct cfg80211_connect_params connect = {};
  7517. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7518. struct net_device *dev = info->user_ptr[1];
  7519. struct wireless_dev *wdev = dev->ieee80211_ptr;
  7520. u32 changed = 0;
  7521. int ret;
  7522. if (!rdev->ops->update_connect_params)
  7523. return -EOPNOTSUPP;
  7524. if (info->attrs[NL80211_ATTR_IE]) {
  7525. if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  7526. return -EINVAL;
  7527. connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  7528. connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  7529. changed |= UPDATE_ASSOC_IES;
  7530. }
  7531. if (wiphy_ext_feature_isset(&rdev->wiphy,
  7532. NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
  7533. info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
  7534. info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
  7535. info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
  7536. info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
  7537. connect.fils_erp_username =
  7538. nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
  7539. connect.fils_erp_username_len =
  7540. nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
  7541. connect.fils_erp_realm =
  7542. nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
  7543. connect.fils_erp_realm_len =
  7544. nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
  7545. connect.fils_erp_next_seq_num =
  7546. nla_get_u16(
  7547. info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
  7548. connect.fils_erp_rrk =
  7549. nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
  7550. connect.fils_erp_rrk_len =
  7551. nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
  7552. changed |= UPDATE_FILS_ERP_INFO;
  7553. } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
  7554. info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
  7555. info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
  7556. info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
  7557. return -EINVAL;
  7558. }
  7559. if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
  7560. u32 auth_type =
  7561. nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
  7562. if (!nl80211_valid_auth_type(rdev, auth_type,
  7563. NL80211_CMD_CONNECT))
  7564. return -EINVAL;
  7565. connect.auth_type = auth_type;
  7566. changed |= UPDATE_AUTH_TYPE;
  7567. }
  7568. wdev_lock(dev->ieee80211_ptr);
  7569. if (!wdev->current_bss)
  7570. ret = -ENOLINK;
  7571. else
  7572. ret = rdev_update_connect_params(rdev, dev, &connect, changed);
  7573. wdev_unlock(dev->ieee80211_ptr);
  7574. return ret;
  7575. }
  7576. static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
  7577. {
  7578. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7579. struct net_device *dev = info->user_ptr[1];
  7580. u16 reason;
  7581. int ret;
  7582. if (!info->attrs[NL80211_ATTR_REASON_CODE])
  7583. reason = WLAN_REASON_DEAUTH_LEAVING;
  7584. else
  7585. reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
  7586. if (reason == 0)
  7587. return -EINVAL;
  7588. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7589. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7590. return -EOPNOTSUPP;
  7591. wdev_lock(dev->ieee80211_ptr);
  7592. ret = cfg80211_disconnect(rdev, dev, reason, true);
  7593. wdev_unlock(dev->ieee80211_ptr);
  7594. return ret;
  7595. }
  7596. static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
  7597. {
  7598. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7599. struct net *net;
  7600. int err;
  7601. if (info->attrs[NL80211_ATTR_PID]) {
  7602. u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
  7603. net = get_net_ns_by_pid(pid);
  7604. } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
  7605. u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
  7606. net = get_net_ns_by_fd(fd);
  7607. } else {
  7608. return -EINVAL;
  7609. }
  7610. if (IS_ERR(net))
  7611. return PTR_ERR(net);
  7612. err = 0;
  7613. /* check if anything to do */
  7614. if (!net_eq(wiphy_net(&rdev->wiphy), net))
  7615. err = cfg80211_switch_netns(rdev, net);
  7616. put_net(net);
  7617. return err;
  7618. }
  7619. static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
  7620. {
  7621. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7622. int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
  7623. struct cfg80211_pmksa *pmksa) = NULL;
  7624. struct net_device *dev = info->user_ptr[1];
  7625. struct cfg80211_pmksa pmksa;
  7626. memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
  7627. if (!info->attrs[NL80211_ATTR_PMKID])
  7628. return -EINVAL;
  7629. pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
  7630. if (info->attrs[NL80211_ATTR_MAC]) {
  7631. pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7632. } else if (info->attrs[NL80211_ATTR_SSID] &&
  7633. info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
  7634. (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
  7635. info->attrs[NL80211_ATTR_PMK])) {
  7636. pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
  7637. pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  7638. pmksa.cache_id =
  7639. nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
  7640. } else {
  7641. return -EINVAL;
  7642. }
  7643. if (info->attrs[NL80211_ATTR_PMK]) {
  7644. pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
  7645. pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
  7646. }
  7647. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7648. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7649. return -EOPNOTSUPP;
  7650. switch (info->genlhdr->cmd) {
  7651. case NL80211_CMD_SET_PMKSA:
  7652. rdev_ops = rdev->ops->set_pmksa;
  7653. break;
  7654. case NL80211_CMD_DEL_PMKSA:
  7655. rdev_ops = rdev->ops->del_pmksa;
  7656. break;
  7657. default:
  7658. WARN_ON(1);
  7659. break;
  7660. }
  7661. if (!rdev_ops)
  7662. return -EOPNOTSUPP;
  7663. return rdev_ops(&rdev->wiphy, dev, &pmksa);
  7664. }
  7665. static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
  7666. {
  7667. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7668. struct net_device *dev = info->user_ptr[1];
  7669. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
  7670. dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
  7671. return -EOPNOTSUPP;
  7672. if (!rdev->ops->flush_pmksa)
  7673. return -EOPNOTSUPP;
  7674. return rdev_flush_pmksa(rdev, dev);
  7675. }
  7676. static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
  7677. {
  7678. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7679. struct net_device *dev = info->user_ptr[1];
  7680. u8 action_code, dialog_token;
  7681. u32 peer_capability = 0;
  7682. u16 status_code;
  7683. u8 *peer;
  7684. bool initiator;
  7685. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  7686. !rdev->ops->tdls_mgmt)
  7687. return -EOPNOTSUPP;
  7688. if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
  7689. !info->attrs[NL80211_ATTR_STATUS_CODE] ||
  7690. !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
  7691. !info->attrs[NL80211_ATTR_IE] ||
  7692. !info->attrs[NL80211_ATTR_MAC])
  7693. return -EINVAL;
  7694. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7695. action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
  7696. status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
  7697. dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
  7698. initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
  7699. if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
  7700. peer_capability =
  7701. nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
  7702. return rdev_tdls_mgmt(rdev, dev, peer, action_code,
  7703. dialog_token, status_code, peer_capability,
  7704. initiator,
  7705. nla_data(info->attrs[NL80211_ATTR_IE]),
  7706. nla_len(info->attrs[NL80211_ATTR_IE]));
  7707. }
  7708. static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
  7709. {
  7710. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7711. struct net_device *dev = info->user_ptr[1];
  7712. enum nl80211_tdls_operation operation;
  7713. u8 *peer;
  7714. if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
  7715. !rdev->ops->tdls_oper)
  7716. return -EOPNOTSUPP;
  7717. if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
  7718. !info->attrs[NL80211_ATTR_MAC])
  7719. return -EINVAL;
  7720. operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
  7721. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  7722. return rdev_tdls_oper(rdev, dev, peer, operation);
  7723. }
  7724. static int nl80211_remain_on_channel(struct sk_buff *skb,
  7725. struct genl_info *info)
  7726. {
  7727. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7728. struct wireless_dev *wdev = info->user_ptr[1];
  7729. struct cfg80211_chan_def chandef;
  7730. struct sk_buff *msg;
  7731. void *hdr;
  7732. u64 cookie;
  7733. u32 duration;
  7734. int err;
  7735. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
  7736. !info->attrs[NL80211_ATTR_DURATION])
  7737. return -EINVAL;
  7738. duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  7739. if (!rdev->ops->remain_on_channel ||
  7740. !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
  7741. return -EOPNOTSUPP;
  7742. /*
  7743. * We should be on that channel for at least a minimum amount of
  7744. * time (10ms) but no longer than the driver supports.
  7745. */
  7746. if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
  7747. duration > rdev->wiphy.max_remain_on_channel_duration)
  7748. return -EINVAL;
  7749. err = nl80211_parse_chandef(rdev, info, &chandef);
  7750. if (err)
  7751. return err;
  7752. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7753. if (!msg)
  7754. return -ENOMEM;
  7755. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7756. NL80211_CMD_REMAIN_ON_CHANNEL);
  7757. if (!hdr) {
  7758. err = -ENOBUFS;
  7759. goto free_msg;
  7760. }
  7761. err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
  7762. duration, &cookie);
  7763. if (err)
  7764. goto free_msg;
  7765. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  7766. NL80211_ATTR_PAD))
  7767. goto nla_put_failure;
  7768. genlmsg_end(msg, hdr);
  7769. return genlmsg_reply(msg, info);
  7770. nla_put_failure:
  7771. err = -ENOBUFS;
  7772. free_msg:
  7773. nlmsg_free(msg);
  7774. return err;
  7775. }
  7776. static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
  7777. struct genl_info *info)
  7778. {
  7779. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7780. struct wireless_dev *wdev = info->user_ptr[1];
  7781. u64 cookie;
  7782. if (!info->attrs[NL80211_ATTR_COOKIE])
  7783. return -EINVAL;
  7784. if (!rdev->ops->cancel_remain_on_channel)
  7785. return -EOPNOTSUPP;
  7786. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  7787. return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
  7788. }
  7789. static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
  7790. struct genl_info *info)
  7791. {
  7792. struct cfg80211_bitrate_mask mask;
  7793. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7794. struct net_device *dev = info->user_ptr[1];
  7795. int err;
  7796. if (!rdev->ops->set_bitrate_mask)
  7797. return -EOPNOTSUPP;
  7798. err = nl80211_parse_tx_bitrate_mask(info, &mask);
  7799. if (err)
  7800. return err;
  7801. return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
  7802. }
  7803. static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
  7804. {
  7805. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7806. struct wireless_dev *wdev = info->user_ptr[1];
  7807. u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
  7808. if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
  7809. return -EINVAL;
  7810. if (info->attrs[NL80211_ATTR_FRAME_TYPE])
  7811. frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
  7812. switch (wdev->iftype) {
  7813. case NL80211_IFTYPE_STATION:
  7814. case NL80211_IFTYPE_ADHOC:
  7815. case NL80211_IFTYPE_P2P_CLIENT:
  7816. case NL80211_IFTYPE_AP:
  7817. case NL80211_IFTYPE_AP_VLAN:
  7818. case NL80211_IFTYPE_MESH_POINT:
  7819. case NL80211_IFTYPE_P2P_GO:
  7820. case NL80211_IFTYPE_P2P_DEVICE:
  7821. break;
  7822. case NL80211_IFTYPE_NAN:
  7823. default:
  7824. return -EOPNOTSUPP;
  7825. }
  7826. /* not much point in registering if we can't reply */
  7827. if (!rdev->ops->mgmt_tx)
  7828. return -EOPNOTSUPP;
  7829. return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
  7830. nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
  7831. nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
  7832. }
  7833. static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
  7834. {
  7835. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7836. struct wireless_dev *wdev = info->user_ptr[1];
  7837. struct cfg80211_chan_def chandef;
  7838. int err;
  7839. void *hdr = NULL;
  7840. u64 cookie;
  7841. struct sk_buff *msg = NULL;
  7842. struct cfg80211_mgmt_tx_params params = {
  7843. .dont_wait_for_ack =
  7844. info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
  7845. };
  7846. if (!info->attrs[NL80211_ATTR_FRAME])
  7847. return -EINVAL;
  7848. if (!rdev->ops->mgmt_tx)
  7849. return -EOPNOTSUPP;
  7850. switch (wdev->iftype) {
  7851. case NL80211_IFTYPE_P2P_DEVICE:
  7852. if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
  7853. return -EINVAL;
  7854. case NL80211_IFTYPE_STATION:
  7855. case NL80211_IFTYPE_ADHOC:
  7856. case NL80211_IFTYPE_P2P_CLIENT:
  7857. case NL80211_IFTYPE_AP:
  7858. case NL80211_IFTYPE_AP_VLAN:
  7859. case NL80211_IFTYPE_MESH_POINT:
  7860. case NL80211_IFTYPE_P2P_GO:
  7861. break;
  7862. case NL80211_IFTYPE_NAN:
  7863. default:
  7864. return -EOPNOTSUPP;
  7865. }
  7866. if (info->attrs[NL80211_ATTR_DURATION]) {
  7867. if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  7868. return -EINVAL;
  7869. params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
  7870. /*
  7871. * We should wait on the channel for at least a minimum amount
  7872. * of time (10ms) but no longer than the driver supports.
  7873. */
  7874. if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
  7875. params.wait > rdev->wiphy.max_remain_on_channel_duration)
  7876. return -EINVAL;
  7877. }
  7878. params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
  7879. if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
  7880. return -EINVAL;
  7881. params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
  7882. /* get the channel if any has been specified, otherwise pass NULL to
  7883. * the driver. The latter will use the current one
  7884. */
  7885. chandef.chan = NULL;
  7886. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  7887. err = nl80211_parse_chandef(rdev, info, &chandef);
  7888. if (err)
  7889. return err;
  7890. }
  7891. if (!chandef.chan && params.offchan)
  7892. return -EINVAL;
  7893. params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
  7894. params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
  7895. if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
  7896. int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
  7897. int i;
  7898. if (len % sizeof(u16))
  7899. return -EINVAL;
  7900. params.n_csa_offsets = len / sizeof(u16);
  7901. params.csa_offsets =
  7902. nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
  7903. /* check that all the offsets fit the frame */
  7904. for (i = 0; i < params.n_csa_offsets; i++) {
  7905. if (params.csa_offsets[i] >= params.len)
  7906. return -EINVAL;
  7907. }
  7908. }
  7909. if (!params.dont_wait_for_ack) {
  7910. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  7911. if (!msg)
  7912. return -ENOMEM;
  7913. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  7914. NL80211_CMD_FRAME);
  7915. if (!hdr) {
  7916. err = -ENOBUFS;
  7917. goto free_msg;
  7918. }
  7919. }
  7920. params.chan = chandef.chan;
  7921. err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
  7922. if (err)
  7923. goto free_msg;
  7924. if (msg) {
  7925. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  7926. NL80211_ATTR_PAD))
  7927. goto nla_put_failure;
  7928. genlmsg_end(msg, hdr);
  7929. return genlmsg_reply(msg, info);
  7930. }
  7931. return 0;
  7932. nla_put_failure:
  7933. err = -ENOBUFS;
  7934. free_msg:
  7935. nlmsg_free(msg);
  7936. return err;
  7937. }
  7938. static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
  7939. {
  7940. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7941. struct wireless_dev *wdev = info->user_ptr[1];
  7942. u64 cookie;
  7943. if (!info->attrs[NL80211_ATTR_COOKIE])
  7944. return -EINVAL;
  7945. if (!rdev->ops->mgmt_tx_cancel_wait)
  7946. return -EOPNOTSUPP;
  7947. switch (wdev->iftype) {
  7948. case NL80211_IFTYPE_STATION:
  7949. case NL80211_IFTYPE_ADHOC:
  7950. case NL80211_IFTYPE_P2P_CLIENT:
  7951. case NL80211_IFTYPE_AP:
  7952. case NL80211_IFTYPE_AP_VLAN:
  7953. case NL80211_IFTYPE_P2P_GO:
  7954. case NL80211_IFTYPE_P2P_DEVICE:
  7955. break;
  7956. case NL80211_IFTYPE_NAN:
  7957. default:
  7958. return -EOPNOTSUPP;
  7959. }
  7960. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  7961. return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
  7962. }
  7963. static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
  7964. {
  7965. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7966. struct wireless_dev *wdev;
  7967. struct net_device *dev = info->user_ptr[1];
  7968. u8 ps_state;
  7969. bool state;
  7970. int err;
  7971. if (!info->attrs[NL80211_ATTR_PS_STATE])
  7972. return -EINVAL;
  7973. ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
  7974. if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
  7975. return -EINVAL;
  7976. wdev = dev->ieee80211_ptr;
  7977. if (!rdev->ops->set_power_mgmt)
  7978. return -EOPNOTSUPP;
  7979. state = (ps_state == NL80211_PS_ENABLED) ? true : false;
  7980. if (state == wdev->ps)
  7981. return 0;
  7982. err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
  7983. if (!err)
  7984. wdev->ps = state;
  7985. return err;
  7986. }
  7987. static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
  7988. {
  7989. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  7990. enum nl80211_ps_state ps_state;
  7991. struct wireless_dev *wdev;
  7992. struct net_device *dev = info->user_ptr[1];
  7993. struct sk_buff *msg;
  7994. void *hdr;
  7995. int err;
  7996. wdev = dev->ieee80211_ptr;
  7997. if (!rdev->ops->set_power_mgmt)
  7998. return -EOPNOTSUPP;
  7999. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  8000. if (!msg)
  8001. return -ENOMEM;
  8002. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8003. NL80211_CMD_GET_POWER_SAVE);
  8004. if (!hdr) {
  8005. err = -ENOBUFS;
  8006. goto free_msg;
  8007. }
  8008. if (wdev->ps)
  8009. ps_state = NL80211_PS_ENABLED;
  8010. else
  8011. ps_state = NL80211_PS_DISABLED;
  8012. if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
  8013. goto nla_put_failure;
  8014. genlmsg_end(msg, hdr);
  8015. return genlmsg_reply(msg, info);
  8016. nla_put_failure:
  8017. err = -ENOBUFS;
  8018. free_msg:
  8019. nlmsg_free(msg);
  8020. return err;
  8021. }
  8022. static const struct nla_policy
  8023. nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
  8024. [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
  8025. [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
  8026. [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
  8027. [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
  8028. [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
  8029. [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
  8030. };
  8031. static int nl80211_set_cqm_txe(struct genl_info *info,
  8032. u32 rate, u32 pkts, u32 intvl)
  8033. {
  8034. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8035. struct net_device *dev = info->user_ptr[1];
  8036. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8037. if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
  8038. return -EINVAL;
  8039. if (!rdev->ops->set_cqm_txe_config)
  8040. return -EOPNOTSUPP;
  8041. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  8042. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  8043. return -EOPNOTSUPP;
  8044. return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
  8045. }
  8046. static int nl80211_set_cqm_rssi(struct genl_info *info,
  8047. s32 threshold, u32 hysteresis)
  8048. {
  8049. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8050. struct net_device *dev = info->user_ptr[1];
  8051. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8052. if (threshold > 0)
  8053. return -EINVAL;
  8054. /* disabling - hysteresis should also be zero then */
  8055. if (threshold == 0)
  8056. hysteresis = 0;
  8057. if (!rdev->ops->set_cqm_rssi_config)
  8058. return -EOPNOTSUPP;
  8059. if (wdev->iftype != NL80211_IFTYPE_STATION &&
  8060. wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  8061. return -EOPNOTSUPP;
  8062. return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
  8063. }
  8064. static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
  8065. {
  8066. struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
  8067. struct nlattr *cqm;
  8068. int err;
  8069. cqm = info->attrs[NL80211_ATTR_CQM];
  8070. if (!cqm)
  8071. return -EINVAL;
  8072. err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
  8073. nl80211_attr_cqm_policy);
  8074. if (err)
  8075. return err;
  8076. if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
  8077. attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
  8078. s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
  8079. u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
  8080. return nl80211_set_cqm_rssi(info, threshold, hysteresis);
  8081. }
  8082. if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
  8083. attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
  8084. attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
  8085. u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
  8086. u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
  8087. u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
  8088. return nl80211_set_cqm_txe(info, rate, pkts, intvl);
  8089. }
  8090. return -EINVAL;
  8091. }
  8092. static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
  8093. {
  8094. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8095. struct net_device *dev = info->user_ptr[1];
  8096. struct ocb_setup setup = {};
  8097. int err;
  8098. err = nl80211_parse_chandef(rdev, info, &setup.chandef);
  8099. if (err)
  8100. return err;
  8101. return cfg80211_join_ocb(rdev, dev, &setup);
  8102. }
  8103. static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
  8104. {
  8105. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8106. struct net_device *dev = info->user_ptr[1];
  8107. return cfg80211_leave_ocb(rdev, dev);
  8108. }
  8109. static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
  8110. {
  8111. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8112. struct net_device *dev = info->user_ptr[1];
  8113. struct mesh_config cfg;
  8114. struct mesh_setup setup;
  8115. int err;
  8116. /* start with default */
  8117. memcpy(&cfg, &default_mesh_config, sizeof(cfg));
  8118. memcpy(&setup, &default_mesh_setup, sizeof(setup));
  8119. if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
  8120. /* and parse parameters if given */
  8121. err = nl80211_parse_mesh_config(info, &cfg, NULL);
  8122. if (err)
  8123. return err;
  8124. }
  8125. if (!info->attrs[NL80211_ATTR_MESH_ID] ||
  8126. !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
  8127. return -EINVAL;
  8128. setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
  8129. setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
  8130. if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
  8131. !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
  8132. nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
  8133. return -EINVAL;
  8134. if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
  8135. setup.beacon_interval =
  8136. nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
  8137. err = cfg80211_validate_beacon_int(rdev,
  8138. NL80211_IFTYPE_MESH_POINT,
  8139. setup.beacon_interval);
  8140. if (err)
  8141. return err;
  8142. }
  8143. if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
  8144. setup.dtim_period =
  8145. nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
  8146. if (setup.dtim_period < 1 || setup.dtim_period > 100)
  8147. return -EINVAL;
  8148. }
  8149. if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
  8150. /* parse additional setup parameters if given */
  8151. err = nl80211_parse_mesh_setup(info, &setup);
  8152. if (err)
  8153. return err;
  8154. }
  8155. if (setup.user_mpm)
  8156. cfg.auto_open_plinks = false;
  8157. if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
  8158. err = nl80211_parse_chandef(rdev, info, &setup.chandef);
  8159. if (err)
  8160. return err;
  8161. } else {
  8162. /* cfg80211_join_mesh() will sort it out */
  8163. setup.chandef.chan = NULL;
  8164. }
  8165. if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
  8166. u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  8167. int n_rates =
  8168. nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
  8169. struct ieee80211_supported_band *sband;
  8170. if (!setup.chandef.chan)
  8171. return -EINVAL;
  8172. sband = rdev->wiphy.bands[setup.chandef.chan->band];
  8173. err = ieee80211_get_ratemask(sband, rates, n_rates,
  8174. &setup.basic_rates);
  8175. if (err)
  8176. return err;
  8177. }
  8178. if (info->attrs[NL80211_ATTR_TX_RATES]) {
  8179. err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
  8180. if (err)
  8181. return err;
  8182. if (!setup.chandef.chan)
  8183. return -EINVAL;
  8184. err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
  8185. &setup.beacon_rate);
  8186. if (err)
  8187. return err;
  8188. }
  8189. return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
  8190. }
  8191. static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
  8192. {
  8193. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8194. struct net_device *dev = info->user_ptr[1];
  8195. return cfg80211_leave_mesh(rdev, dev);
  8196. }
  8197. #ifdef CONFIG_PM
  8198. static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
  8199. struct cfg80211_registered_device *rdev)
  8200. {
  8201. struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
  8202. struct nlattr *nl_pats, *nl_pat;
  8203. int i, pat_len;
  8204. if (!wowlan->n_patterns)
  8205. return 0;
  8206. nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
  8207. if (!nl_pats)
  8208. return -ENOBUFS;
  8209. for (i = 0; i < wowlan->n_patterns; i++) {
  8210. nl_pat = nla_nest_start(msg, i + 1);
  8211. if (!nl_pat)
  8212. return -ENOBUFS;
  8213. pat_len = wowlan->patterns[i].pattern_len;
  8214. if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
  8215. wowlan->patterns[i].mask) ||
  8216. nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
  8217. wowlan->patterns[i].pattern) ||
  8218. nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
  8219. wowlan->patterns[i].pkt_offset))
  8220. return -ENOBUFS;
  8221. nla_nest_end(msg, nl_pat);
  8222. }
  8223. nla_nest_end(msg, nl_pats);
  8224. return 0;
  8225. }
  8226. static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
  8227. struct cfg80211_wowlan_tcp *tcp)
  8228. {
  8229. struct nlattr *nl_tcp;
  8230. if (!tcp)
  8231. return 0;
  8232. nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
  8233. if (!nl_tcp)
  8234. return -ENOBUFS;
  8235. if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
  8236. nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
  8237. nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
  8238. nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
  8239. nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
  8240. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
  8241. tcp->payload_len, tcp->payload) ||
  8242. nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
  8243. tcp->data_interval) ||
  8244. nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
  8245. tcp->wake_len, tcp->wake_data) ||
  8246. nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
  8247. DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
  8248. return -ENOBUFS;
  8249. if (tcp->payload_seq.len &&
  8250. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
  8251. sizeof(tcp->payload_seq), &tcp->payload_seq))
  8252. return -ENOBUFS;
  8253. if (tcp->payload_tok.len &&
  8254. nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
  8255. sizeof(tcp->payload_tok) + tcp->tokens_size,
  8256. &tcp->payload_tok))
  8257. return -ENOBUFS;
  8258. nla_nest_end(msg, nl_tcp);
  8259. return 0;
  8260. }
  8261. static int nl80211_send_wowlan_nd(struct sk_buff *msg,
  8262. struct cfg80211_sched_scan_request *req)
  8263. {
  8264. struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
  8265. int i;
  8266. if (!req)
  8267. return 0;
  8268. nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
  8269. if (!nd)
  8270. return -ENOBUFS;
  8271. if (req->n_scan_plans == 1 &&
  8272. nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
  8273. req->scan_plans[0].interval * 1000))
  8274. return -ENOBUFS;
  8275. if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
  8276. return -ENOBUFS;
  8277. if (req->relative_rssi_set) {
  8278. struct nl80211_bss_select_rssi_adjust rssi_adjust;
  8279. if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
  8280. req->relative_rssi))
  8281. return -ENOBUFS;
  8282. rssi_adjust.band = req->rssi_adjust.band;
  8283. rssi_adjust.delta = req->rssi_adjust.delta;
  8284. if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
  8285. sizeof(rssi_adjust), &rssi_adjust))
  8286. return -ENOBUFS;
  8287. }
  8288. freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  8289. if (!freqs)
  8290. return -ENOBUFS;
  8291. for (i = 0; i < req->n_channels; i++) {
  8292. if (nla_put_u32(msg, i, req->channels[i]->center_freq))
  8293. return -ENOBUFS;
  8294. }
  8295. nla_nest_end(msg, freqs);
  8296. if (req->n_match_sets) {
  8297. matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
  8298. if (!matches)
  8299. return -ENOBUFS;
  8300. for (i = 0; i < req->n_match_sets; i++) {
  8301. match = nla_nest_start(msg, i);
  8302. if (!match)
  8303. return -ENOBUFS;
  8304. if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
  8305. req->match_sets[i].ssid.ssid_len,
  8306. req->match_sets[i].ssid.ssid))
  8307. return -ENOBUFS;
  8308. nla_nest_end(msg, match);
  8309. }
  8310. nla_nest_end(msg, matches);
  8311. }
  8312. scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
  8313. if (!scan_plans)
  8314. return -ENOBUFS;
  8315. for (i = 0; i < req->n_scan_plans; i++) {
  8316. scan_plan = nla_nest_start(msg, i + 1);
  8317. if (!scan_plan)
  8318. return -ENOBUFS;
  8319. if (!scan_plan ||
  8320. nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
  8321. req->scan_plans[i].interval) ||
  8322. (req->scan_plans[i].iterations &&
  8323. nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
  8324. req->scan_plans[i].iterations)))
  8325. return -ENOBUFS;
  8326. nla_nest_end(msg, scan_plan);
  8327. }
  8328. nla_nest_end(msg, scan_plans);
  8329. nla_nest_end(msg, nd);
  8330. return 0;
  8331. }
  8332. static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
  8333. {
  8334. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8335. struct sk_buff *msg;
  8336. void *hdr;
  8337. u32 size = NLMSG_DEFAULT_SIZE;
  8338. if (!rdev->wiphy.wowlan)
  8339. return -EOPNOTSUPP;
  8340. if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
  8341. /* adjust size to have room for all the data */
  8342. size += rdev->wiphy.wowlan_config->tcp->tokens_size +
  8343. rdev->wiphy.wowlan_config->tcp->payload_len +
  8344. rdev->wiphy.wowlan_config->tcp->wake_len +
  8345. rdev->wiphy.wowlan_config->tcp->wake_len / 8;
  8346. }
  8347. msg = nlmsg_new(size, GFP_KERNEL);
  8348. if (!msg)
  8349. return -ENOMEM;
  8350. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8351. NL80211_CMD_GET_WOWLAN);
  8352. if (!hdr)
  8353. goto nla_put_failure;
  8354. if (rdev->wiphy.wowlan_config) {
  8355. struct nlattr *nl_wowlan;
  8356. nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  8357. if (!nl_wowlan)
  8358. goto nla_put_failure;
  8359. if ((rdev->wiphy.wowlan_config->any &&
  8360. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  8361. (rdev->wiphy.wowlan_config->disconnect &&
  8362. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  8363. (rdev->wiphy.wowlan_config->magic_pkt &&
  8364. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  8365. (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
  8366. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  8367. (rdev->wiphy.wowlan_config->eap_identity_req &&
  8368. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  8369. (rdev->wiphy.wowlan_config->four_way_handshake &&
  8370. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  8371. (rdev->wiphy.wowlan_config->rfkill_release &&
  8372. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
  8373. goto nla_put_failure;
  8374. if (nl80211_send_wowlan_patterns(msg, rdev))
  8375. goto nla_put_failure;
  8376. if (nl80211_send_wowlan_tcp(msg,
  8377. rdev->wiphy.wowlan_config->tcp))
  8378. goto nla_put_failure;
  8379. if (nl80211_send_wowlan_nd(
  8380. msg,
  8381. rdev->wiphy.wowlan_config->nd_config))
  8382. goto nla_put_failure;
  8383. nla_nest_end(msg, nl_wowlan);
  8384. }
  8385. genlmsg_end(msg, hdr);
  8386. return genlmsg_reply(msg, info);
  8387. nla_put_failure:
  8388. nlmsg_free(msg);
  8389. return -ENOBUFS;
  8390. }
  8391. static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
  8392. struct nlattr *attr,
  8393. struct cfg80211_wowlan *trig)
  8394. {
  8395. struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
  8396. struct cfg80211_wowlan_tcp *cfg;
  8397. struct nl80211_wowlan_tcp_data_token *tok = NULL;
  8398. struct nl80211_wowlan_tcp_data_seq *seq = NULL;
  8399. u32 size;
  8400. u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
  8401. int err, port;
  8402. if (!rdev->wiphy.wowlan->tcp)
  8403. return -EINVAL;
  8404. err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
  8405. nla_data(attr), nla_len(attr),
  8406. nl80211_wowlan_tcp_policy);
  8407. if (err)
  8408. return err;
  8409. if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
  8410. !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
  8411. !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
  8412. !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
  8413. !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
  8414. !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
  8415. !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
  8416. !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
  8417. return -EINVAL;
  8418. data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
  8419. if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
  8420. return -EINVAL;
  8421. if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
  8422. rdev->wiphy.wowlan->tcp->data_interval_max ||
  8423. nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
  8424. return -EINVAL;
  8425. wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
  8426. if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
  8427. return -EINVAL;
  8428. wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
  8429. if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
  8430. return -EINVAL;
  8431. if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
  8432. u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
  8433. tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
  8434. tokens_size = tokln - sizeof(*tok);
  8435. if (!tok->len || tokens_size % tok->len)
  8436. return -EINVAL;
  8437. if (!rdev->wiphy.wowlan->tcp->tok)
  8438. return -EINVAL;
  8439. if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
  8440. return -EINVAL;
  8441. if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
  8442. return -EINVAL;
  8443. if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
  8444. return -EINVAL;
  8445. if (tok->offset + tok->len > data_size)
  8446. return -EINVAL;
  8447. }
  8448. if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
  8449. seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
  8450. if (!rdev->wiphy.wowlan->tcp->seq)
  8451. return -EINVAL;
  8452. if (seq->len == 0 || seq->len > 4)
  8453. return -EINVAL;
  8454. if (seq->len + seq->offset > data_size)
  8455. return -EINVAL;
  8456. }
  8457. size = sizeof(*cfg);
  8458. size += data_size;
  8459. size += wake_size + wake_mask_size;
  8460. size += tokens_size;
  8461. cfg = kzalloc(size, GFP_KERNEL);
  8462. if (!cfg)
  8463. return -ENOMEM;
  8464. cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
  8465. cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
  8466. memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
  8467. ETH_ALEN);
  8468. if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
  8469. port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
  8470. else
  8471. port = 0;
  8472. #ifdef CONFIG_INET
  8473. /* allocate a socket and port for it and use it */
  8474. err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
  8475. IPPROTO_TCP, &cfg->sock, 1);
  8476. if (err) {
  8477. kfree(cfg);
  8478. return err;
  8479. }
  8480. if (inet_csk_get_port(cfg->sock->sk, port)) {
  8481. sock_release(cfg->sock);
  8482. kfree(cfg);
  8483. return -EADDRINUSE;
  8484. }
  8485. cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
  8486. #else
  8487. if (!port) {
  8488. kfree(cfg);
  8489. return -EINVAL;
  8490. }
  8491. cfg->src_port = port;
  8492. #endif
  8493. cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
  8494. cfg->payload_len = data_size;
  8495. cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
  8496. memcpy((void *)cfg->payload,
  8497. nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
  8498. data_size);
  8499. if (seq)
  8500. cfg->payload_seq = *seq;
  8501. cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
  8502. cfg->wake_len = wake_size;
  8503. cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
  8504. memcpy((void *)cfg->wake_data,
  8505. nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
  8506. wake_size);
  8507. cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
  8508. data_size + wake_size;
  8509. memcpy((void *)cfg->wake_mask,
  8510. nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
  8511. wake_mask_size);
  8512. if (tok) {
  8513. cfg->tokens_size = tokens_size;
  8514. memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
  8515. }
  8516. trig->tcp = cfg;
  8517. return 0;
  8518. }
  8519. static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
  8520. const struct wiphy_wowlan_support *wowlan,
  8521. struct nlattr *attr,
  8522. struct cfg80211_wowlan *trig)
  8523. {
  8524. struct nlattr **tb;
  8525. int err;
  8526. tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
  8527. if (!tb)
  8528. return -ENOMEM;
  8529. if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
  8530. err = -EOPNOTSUPP;
  8531. goto out;
  8532. }
  8533. err = nla_parse(tb, NL80211_ATTR_MAX,
  8534. nla_data(attr), nla_len(attr),
  8535. nl80211_policy);
  8536. if (err)
  8537. goto out;
  8538. trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
  8539. err = PTR_ERR_OR_ZERO(trig->nd_config);
  8540. if (err)
  8541. trig->nd_config = NULL;
  8542. out:
  8543. kfree(tb);
  8544. return err;
  8545. }
  8546. static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
  8547. {
  8548. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8549. struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
  8550. struct cfg80211_wowlan new_triggers = {};
  8551. struct cfg80211_wowlan *ntrig;
  8552. const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
  8553. int err, i;
  8554. bool prev_enabled = rdev->wiphy.wowlan_config;
  8555. bool regular = false;
  8556. if (!wowlan)
  8557. return -EOPNOTSUPP;
  8558. if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
  8559. cfg80211_rdev_free_wowlan(rdev);
  8560. rdev->wiphy.wowlan_config = NULL;
  8561. goto set_wakeup;
  8562. }
  8563. err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
  8564. nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  8565. nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
  8566. nl80211_wowlan_policy);
  8567. if (err)
  8568. return err;
  8569. if (tb[NL80211_WOWLAN_TRIG_ANY]) {
  8570. if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
  8571. return -EINVAL;
  8572. new_triggers.any = true;
  8573. }
  8574. if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
  8575. if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
  8576. return -EINVAL;
  8577. new_triggers.disconnect = true;
  8578. regular = true;
  8579. }
  8580. if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
  8581. if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
  8582. return -EINVAL;
  8583. new_triggers.magic_pkt = true;
  8584. regular = true;
  8585. }
  8586. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
  8587. return -EINVAL;
  8588. if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
  8589. if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
  8590. return -EINVAL;
  8591. new_triggers.gtk_rekey_failure = true;
  8592. regular = true;
  8593. }
  8594. if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
  8595. if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
  8596. return -EINVAL;
  8597. new_triggers.eap_identity_req = true;
  8598. regular = true;
  8599. }
  8600. if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
  8601. if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
  8602. return -EINVAL;
  8603. new_triggers.four_way_handshake = true;
  8604. regular = true;
  8605. }
  8606. if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
  8607. if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
  8608. return -EINVAL;
  8609. new_triggers.rfkill_release = true;
  8610. regular = true;
  8611. }
  8612. if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
  8613. struct nlattr *pat;
  8614. int n_patterns = 0;
  8615. int rem, pat_len, mask_len, pkt_offset;
  8616. struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
  8617. regular = true;
  8618. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  8619. rem)
  8620. n_patterns++;
  8621. if (n_patterns > wowlan->n_patterns)
  8622. return -EINVAL;
  8623. new_triggers.patterns = kcalloc(n_patterns,
  8624. sizeof(new_triggers.patterns[0]),
  8625. GFP_KERNEL);
  8626. if (!new_triggers.patterns)
  8627. return -ENOMEM;
  8628. new_triggers.n_patterns = n_patterns;
  8629. i = 0;
  8630. nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
  8631. rem) {
  8632. u8 *mask_pat;
  8633. nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
  8634. nla_len(pat), nl80211_packet_pattern_policy);
  8635. err = -EINVAL;
  8636. if (!pat_tb[NL80211_PKTPAT_MASK] ||
  8637. !pat_tb[NL80211_PKTPAT_PATTERN])
  8638. goto error;
  8639. pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
  8640. mask_len = DIV_ROUND_UP(pat_len, 8);
  8641. if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
  8642. goto error;
  8643. if (pat_len > wowlan->pattern_max_len ||
  8644. pat_len < wowlan->pattern_min_len)
  8645. goto error;
  8646. if (!pat_tb[NL80211_PKTPAT_OFFSET])
  8647. pkt_offset = 0;
  8648. else
  8649. pkt_offset = nla_get_u32(
  8650. pat_tb[NL80211_PKTPAT_OFFSET]);
  8651. if (pkt_offset > wowlan->max_pkt_offset)
  8652. goto error;
  8653. new_triggers.patterns[i].pkt_offset = pkt_offset;
  8654. mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
  8655. if (!mask_pat) {
  8656. err = -ENOMEM;
  8657. goto error;
  8658. }
  8659. new_triggers.patterns[i].mask = mask_pat;
  8660. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
  8661. mask_len);
  8662. mask_pat += mask_len;
  8663. new_triggers.patterns[i].pattern = mask_pat;
  8664. new_triggers.patterns[i].pattern_len = pat_len;
  8665. memcpy(mask_pat,
  8666. nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
  8667. pat_len);
  8668. i++;
  8669. }
  8670. }
  8671. if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
  8672. regular = true;
  8673. err = nl80211_parse_wowlan_tcp(
  8674. rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
  8675. &new_triggers);
  8676. if (err)
  8677. goto error;
  8678. }
  8679. if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
  8680. regular = true;
  8681. err = nl80211_parse_wowlan_nd(
  8682. rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
  8683. &new_triggers);
  8684. if (err)
  8685. goto error;
  8686. }
  8687. /* The 'any' trigger means the device continues operating more or less
  8688. * as in its normal operation mode and wakes up the host on most of the
  8689. * normal interrupts (like packet RX, ...)
  8690. * It therefore makes little sense to combine with the more constrained
  8691. * wakeup trigger modes.
  8692. */
  8693. if (new_triggers.any && regular) {
  8694. err = -EINVAL;
  8695. goto error;
  8696. }
  8697. ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
  8698. if (!ntrig) {
  8699. err = -ENOMEM;
  8700. goto error;
  8701. }
  8702. cfg80211_rdev_free_wowlan(rdev);
  8703. rdev->wiphy.wowlan_config = ntrig;
  8704. set_wakeup:
  8705. if (rdev->ops->set_wakeup &&
  8706. prev_enabled != !!rdev->wiphy.wowlan_config)
  8707. rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
  8708. return 0;
  8709. error:
  8710. for (i = 0; i < new_triggers.n_patterns; i++)
  8711. kfree(new_triggers.patterns[i].mask);
  8712. kfree(new_triggers.patterns);
  8713. if (new_triggers.tcp && new_triggers.tcp->sock)
  8714. sock_release(new_triggers.tcp->sock);
  8715. kfree(new_triggers.tcp);
  8716. kfree(new_triggers.nd_config);
  8717. return err;
  8718. }
  8719. #endif
  8720. static int nl80211_send_coalesce_rules(struct sk_buff *msg,
  8721. struct cfg80211_registered_device *rdev)
  8722. {
  8723. struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
  8724. int i, j, pat_len;
  8725. struct cfg80211_coalesce_rules *rule;
  8726. if (!rdev->coalesce->n_rules)
  8727. return 0;
  8728. nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
  8729. if (!nl_rules)
  8730. return -ENOBUFS;
  8731. for (i = 0; i < rdev->coalesce->n_rules; i++) {
  8732. nl_rule = nla_nest_start(msg, i + 1);
  8733. if (!nl_rule)
  8734. return -ENOBUFS;
  8735. rule = &rdev->coalesce->rules[i];
  8736. if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
  8737. rule->delay))
  8738. return -ENOBUFS;
  8739. if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
  8740. rule->condition))
  8741. return -ENOBUFS;
  8742. nl_pats = nla_nest_start(msg,
  8743. NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
  8744. if (!nl_pats)
  8745. return -ENOBUFS;
  8746. for (j = 0; j < rule->n_patterns; j++) {
  8747. nl_pat = nla_nest_start(msg, j + 1);
  8748. if (!nl_pat)
  8749. return -ENOBUFS;
  8750. pat_len = rule->patterns[j].pattern_len;
  8751. if (nla_put(msg, NL80211_PKTPAT_MASK,
  8752. DIV_ROUND_UP(pat_len, 8),
  8753. rule->patterns[j].mask) ||
  8754. nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
  8755. rule->patterns[j].pattern) ||
  8756. nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
  8757. rule->patterns[j].pkt_offset))
  8758. return -ENOBUFS;
  8759. nla_nest_end(msg, nl_pat);
  8760. }
  8761. nla_nest_end(msg, nl_pats);
  8762. nla_nest_end(msg, nl_rule);
  8763. }
  8764. nla_nest_end(msg, nl_rules);
  8765. return 0;
  8766. }
  8767. static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
  8768. {
  8769. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8770. struct sk_buff *msg;
  8771. void *hdr;
  8772. if (!rdev->wiphy.coalesce)
  8773. return -EOPNOTSUPP;
  8774. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  8775. if (!msg)
  8776. return -ENOMEM;
  8777. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  8778. NL80211_CMD_GET_COALESCE);
  8779. if (!hdr)
  8780. goto nla_put_failure;
  8781. if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
  8782. goto nla_put_failure;
  8783. genlmsg_end(msg, hdr);
  8784. return genlmsg_reply(msg, info);
  8785. nla_put_failure:
  8786. nlmsg_free(msg);
  8787. return -ENOBUFS;
  8788. }
  8789. void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
  8790. {
  8791. struct cfg80211_coalesce *coalesce = rdev->coalesce;
  8792. int i, j;
  8793. struct cfg80211_coalesce_rules *rule;
  8794. if (!coalesce)
  8795. return;
  8796. for (i = 0; i < coalesce->n_rules; i++) {
  8797. rule = &coalesce->rules[i];
  8798. for (j = 0; j < rule->n_patterns; j++)
  8799. kfree(rule->patterns[j].mask);
  8800. kfree(rule->patterns);
  8801. }
  8802. kfree(coalesce->rules);
  8803. kfree(coalesce);
  8804. rdev->coalesce = NULL;
  8805. }
  8806. static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
  8807. struct nlattr *rule,
  8808. struct cfg80211_coalesce_rules *new_rule)
  8809. {
  8810. int err, i;
  8811. const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
  8812. struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
  8813. int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
  8814. struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
  8815. err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
  8816. nla_len(rule), nl80211_coalesce_policy);
  8817. if (err)
  8818. return err;
  8819. if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
  8820. new_rule->delay =
  8821. nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
  8822. if (new_rule->delay > coalesce->max_delay)
  8823. return -EINVAL;
  8824. if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
  8825. new_rule->condition =
  8826. nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
  8827. if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
  8828. new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
  8829. return -EINVAL;
  8830. if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
  8831. return -EINVAL;
  8832. nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
  8833. rem)
  8834. n_patterns++;
  8835. if (n_patterns > coalesce->n_patterns)
  8836. return -EINVAL;
  8837. new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
  8838. GFP_KERNEL);
  8839. if (!new_rule->patterns)
  8840. return -ENOMEM;
  8841. new_rule->n_patterns = n_patterns;
  8842. i = 0;
  8843. nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
  8844. rem) {
  8845. u8 *mask_pat;
  8846. nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
  8847. nla_len(pat), nl80211_packet_pattern_policy);
  8848. if (!pat_tb[NL80211_PKTPAT_MASK] ||
  8849. !pat_tb[NL80211_PKTPAT_PATTERN])
  8850. return -EINVAL;
  8851. pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
  8852. mask_len = DIV_ROUND_UP(pat_len, 8);
  8853. if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
  8854. return -EINVAL;
  8855. if (pat_len > coalesce->pattern_max_len ||
  8856. pat_len < coalesce->pattern_min_len)
  8857. return -EINVAL;
  8858. if (!pat_tb[NL80211_PKTPAT_OFFSET])
  8859. pkt_offset = 0;
  8860. else
  8861. pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
  8862. if (pkt_offset > coalesce->max_pkt_offset)
  8863. return -EINVAL;
  8864. new_rule->patterns[i].pkt_offset = pkt_offset;
  8865. mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
  8866. if (!mask_pat)
  8867. return -ENOMEM;
  8868. new_rule->patterns[i].mask = mask_pat;
  8869. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
  8870. mask_len);
  8871. mask_pat += mask_len;
  8872. new_rule->patterns[i].pattern = mask_pat;
  8873. new_rule->patterns[i].pattern_len = pat_len;
  8874. memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
  8875. pat_len);
  8876. i++;
  8877. }
  8878. return 0;
  8879. }
  8880. static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
  8881. {
  8882. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8883. const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
  8884. struct cfg80211_coalesce new_coalesce = {};
  8885. struct cfg80211_coalesce *n_coalesce;
  8886. int err, rem_rule, n_rules = 0, i, j;
  8887. struct nlattr *rule;
  8888. struct cfg80211_coalesce_rules *tmp_rule;
  8889. if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
  8890. return -EOPNOTSUPP;
  8891. if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
  8892. cfg80211_rdev_free_coalesce(rdev);
  8893. rdev_set_coalesce(rdev, NULL);
  8894. return 0;
  8895. }
  8896. nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
  8897. rem_rule)
  8898. n_rules++;
  8899. if (n_rules > coalesce->n_rules)
  8900. return -EINVAL;
  8901. new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
  8902. GFP_KERNEL);
  8903. if (!new_coalesce.rules)
  8904. return -ENOMEM;
  8905. new_coalesce.n_rules = n_rules;
  8906. i = 0;
  8907. nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
  8908. rem_rule) {
  8909. err = nl80211_parse_coalesce_rule(rdev, rule,
  8910. &new_coalesce.rules[i]);
  8911. if (err)
  8912. goto error;
  8913. i++;
  8914. }
  8915. err = rdev_set_coalesce(rdev, &new_coalesce);
  8916. if (err)
  8917. goto error;
  8918. n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
  8919. if (!n_coalesce) {
  8920. err = -ENOMEM;
  8921. goto error;
  8922. }
  8923. cfg80211_rdev_free_coalesce(rdev);
  8924. rdev->coalesce = n_coalesce;
  8925. return 0;
  8926. error:
  8927. for (i = 0; i < new_coalesce.n_rules; i++) {
  8928. tmp_rule = &new_coalesce.rules[i];
  8929. for (j = 0; j < tmp_rule->n_patterns; j++)
  8930. kfree(tmp_rule->patterns[j].mask);
  8931. kfree(tmp_rule->patterns);
  8932. }
  8933. kfree(new_coalesce.rules);
  8934. return err;
  8935. }
  8936. static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
  8937. {
  8938. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  8939. struct net_device *dev = info->user_ptr[1];
  8940. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8941. struct nlattr *tb[NUM_NL80211_REKEY_DATA];
  8942. struct cfg80211_gtk_rekey_data rekey_data;
  8943. int err;
  8944. if (!info->attrs[NL80211_ATTR_REKEY_DATA])
  8945. return -EINVAL;
  8946. err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
  8947. nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
  8948. nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
  8949. nl80211_rekey_policy);
  8950. if (err)
  8951. return err;
  8952. if (!tb[NL80211_REKEY_DATA_KEK] || !tb[NL80211_REKEY_DATA_REPLAY_CTR] ||
  8953. (!wiphy_ext_feature_isset(&rdev->wiphy,
  8954. NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
  8955. !wiphy_ext_feature_isset(&rdev->wiphy,
  8956. NL80211_EXT_FEATURE_FILS_STA) &&
  8957. !tb[NL80211_REKEY_DATA_KCK]))
  8958. return -EINVAL;
  8959. if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
  8960. return -ERANGE;
  8961. if (nla_len(tb[NL80211_REKEY_DATA_KEK]) < NL80211_KEK_LEN)
  8962. return -ERANGE;
  8963. if (tb[NL80211_REKEY_DATA_KCK] &&
  8964. nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
  8965. return -ERANGE;
  8966. memset(&rekey_data, 0, sizeof(rekey_data));
  8967. rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
  8968. rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
  8969. if (tb[NL80211_REKEY_DATA_KCK])
  8970. rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
  8971. rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
  8972. wdev_lock(wdev);
  8973. if (!wdev->current_bss) {
  8974. err = -ENOTCONN;
  8975. goto out;
  8976. }
  8977. if (!rdev->ops->set_rekey_data) {
  8978. err = -EOPNOTSUPP;
  8979. goto out;
  8980. }
  8981. err = rdev_set_rekey_data(rdev, dev, &rekey_data);
  8982. out:
  8983. wdev_unlock(wdev);
  8984. return err;
  8985. }
  8986. static int nl80211_register_unexpected_frame(struct sk_buff *skb,
  8987. struct genl_info *info)
  8988. {
  8989. struct net_device *dev = info->user_ptr[1];
  8990. struct wireless_dev *wdev = dev->ieee80211_ptr;
  8991. if (wdev->iftype != NL80211_IFTYPE_AP &&
  8992. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  8993. return -EINVAL;
  8994. if (wdev->ap_unexpected_nlportid)
  8995. return -EBUSY;
  8996. wdev->ap_unexpected_nlportid = info->snd_portid;
  8997. return 0;
  8998. }
  8999. static int nl80211_probe_client(struct sk_buff *skb,
  9000. struct genl_info *info)
  9001. {
  9002. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9003. struct net_device *dev = info->user_ptr[1];
  9004. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9005. struct sk_buff *msg;
  9006. void *hdr;
  9007. const u8 *addr;
  9008. u64 cookie;
  9009. int err;
  9010. if (wdev->iftype != NL80211_IFTYPE_AP &&
  9011. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  9012. return -EOPNOTSUPP;
  9013. if (!info->attrs[NL80211_ATTR_MAC])
  9014. return -EINVAL;
  9015. if (!rdev->ops->probe_client)
  9016. return -EOPNOTSUPP;
  9017. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9018. if (!msg)
  9019. return -ENOMEM;
  9020. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  9021. NL80211_CMD_PROBE_CLIENT);
  9022. if (!hdr) {
  9023. err = -ENOBUFS;
  9024. goto free_msg;
  9025. }
  9026. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9027. err = rdev_probe_client(rdev, dev, addr, &cookie);
  9028. if (err)
  9029. goto free_msg;
  9030. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  9031. NL80211_ATTR_PAD))
  9032. goto nla_put_failure;
  9033. genlmsg_end(msg, hdr);
  9034. return genlmsg_reply(msg, info);
  9035. nla_put_failure:
  9036. err = -ENOBUFS;
  9037. free_msg:
  9038. nlmsg_free(msg);
  9039. return err;
  9040. }
  9041. static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
  9042. {
  9043. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9044. struct cfg80211_beacon_registration *reg, *nreg;
  9045. int rv;
  9046. if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
  9047. return -EOPNOTSUPP;
  9048. nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
  9049. if (!nreg)
  9050. return -ENOMEM;
  9051. /* First, check if already registered. */
  9052. spin_lock_bh(&rdev->beacon_registrations_lock);
  9053. list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  9054. if (reg->nlportid == info->snd_portid) {
  9055. rv = -EALREADY;
  9056. goto out_err;
  9057. }
  9058. }
  9059. /* Add it to the list */
  9060. nreg->nlportid = info->snd_portid;
  9061. list_add(&nreg->list, &rdev->beacon_registrations);
  9062. spin_unlock_bh(&rdev->beacon_registrations_lock);
  9063. return 0;
  9064. out_err:
  9065. spin_unlock_bh(&rdev->beacon_registrations_lock);
  9066. kfree(nreg);
  9067. return rv;
  9068. }
  9069. static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
  9070. {
  9071. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9072. struct wireless_dev *wdev = info->user_ptr[1];
  9073. int err;
  9074. if (!rdev->ops->start_p2p_device)
  9075. return -EOPNOTSUPP;
  9076. if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  9077. return -EOPNOTSUPP;
  9078. if (wdev->p2p_started)
  9079. return 0;
  9080. if (rfkill_blocked(rdev->rfkill))
  9081. return -ERFKILL;
  9082. err = rdev_start_p2p_device(rdev, wdev);
  9083. if (err)
  9084. return err;
  9085. wdev->p2p_started = true;
  9086. rdev->opencount++;
  9087. return 0;
  9088. }
  9089. static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
  9090. {
  9091. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9092. struct wireless_dev *wdev = info->user_ptr[1];
  9093. if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
  9094. return -EOPNOTSUPP;
  9095. if (!rdev->ops->stop_p2p_device)
  9096. return -EOPNOTSUPP;
  9097. cfg80211_stop_p2p_device(rdev, wdev);
  9098. return 0;
  9099. }
  9100. static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
  9101. {
  9102. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9103. struct wireless_dev *wdev = info->user_ptr[1];
  9104. struct cfg80211_nan_conf conf = {};
  9105. int err;
  9106. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9107. return -EOPNOTSUPP;
  9108. if (wdev->nan_started)
  9109. return -EEXIST;
  9110. if (rfkill_blocked(rdev->rfkill))
  9111. return -ERFKILL;
  9112. if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
  9113. return -EINVAL;
  9114. if (!info->attrs[NL80211_ATTR_NAN_DUAL])
  9115. return -EINVAL;
  9116. conf.master_pref =
  9117. nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
  9118. if (!conf.master_pref)
  9119. return -EINVAL;
  9120. conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
  9121. err = rdev_start_nan(rdev, wdev, &conf);
  9122. if (err)
  9123. return err;
  9124. wdev->nan_started = true;
  9125. rdev->opencount++;
  9126. return 0;
  9127. }
  9128. static int nl80211_stop_nan(struct sk_buff *skb, 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. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9133. return -EOPNOTSUPP;
  9134. cfg80211_stop_nan(rdev, wdev);
  9135. return 0;
  9136. }
  9137. static int validate_nan_filter(struct nlattr *filter_attr)
  9138. {
  9139. struct nlattr *attr;
  9140. int len = 0, n_entries = 0, rem;
  9141. nla_for_each_nested(attr, filter_attr, rem) {
  9142. len += nla_len(attr);
  9143. n_entries++;
  9144. }
  9145. if (len >= U8_MAX)
  9146. return -EINVAL;
  9147. return n_entries;
  9148. }
  9149. static int handle_nan_filter(struct nlattr *attr_filter,
  9150. struct cfg80211_nan_func *func,
  9151. bool tx)
  9152. {
  9153. struct nlattr *attr;
  9154. int n_entries, rem, i;
  9155. struct cfg80211_nan_func_filter *filter;
  9156. n_entries = validate_nan_filter(attr_filter);
  9157. if (n_entries < 0)
  9158. return n_entries;
  9159. BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
  9160. filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
  9161. if (!filter)
  9162. return -ENOMEM;
  9163. i = 0;
  9164. nla_for_each_nested(attr, attr_filter, rem) {
  9165. filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
  9166. GFP_KERNEL);
  9167. filter[i].len = nla_len(attr);
  9168. i++;
  9169. }
  9170. if (tx) {
  9171. func->num_tx_filters = n_entries;
  9172. func->tx_filters = filter;
  9173. } else {
  9174. func->num_rx_filters = n_entries;
  9175. func->rx_filters = filter;
  9176. }
  9177. return 0;
  9178. }
  9179. static int nl80211_nan_add_func(struct sk_buff *skb,
  9180. struct genl_info *info)
  9181. {
  9182. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9183. struct wireless_dev *wdev = info->user_ptr[1];
  9184. struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
  9185. struct cfg80211_nan_func *func;
  9186. struct sk_buff *msg = NULL;
  9187. void *hdr = NULL;
  9188. int err = 0;
  9189. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9190. return -EOPNOTSUPP;
  9191. if (!wdev->nan_started)
  9192. return -ENOTCONN;
  9193. if (!info->attrs[NL80211_ATTR_NAN_FUNC])
  9194. return -EINVAL;
  9195. if (wdev->owner_nlportid &&
  9196. wdev->owner_nlportid != info->snd_portid)
  9197. return -ENOTCONN;
  9198. err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX,
  9199. nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]),
  9200. nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]),
  9201. nl80211_nan_func_policy);
  9202. if (err)
  9203. return err;
  9204. func = kzalloc(sizeof(*func), GFP_KERNEL);
  9205. if (!func)
  9206. return -ENOMEM;
  9207. func->cookie = wdev->wiphy->cookie_counter++;
  9208. if (!tb[NL80211_NAN_FUNC_TYPE] ||
  9209. nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
  9210. err = -EINVAL;
  9211. goto out;
  9212. }
  9213. func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
  9214. if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
  9215. err = -EINVAL;
  9216. goto out;
  9217. }
  9218. memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
  9219. sizeof(func->service_id));
  9220. func->close_range =
  9221. nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
  9222. if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
  9223. func->serv_spec_info_len =
  9224. nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
  9225. func->serv_spec_info =
  9226. kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
  9227. func->serv_spec_info_len,
  9228. GFP_KERNEL);
  9229. if (!func->serv_spec_info) {
  9230. err = -ENOMEM;
  9231. goto out;
  9232. }
  9233. }
  9234. if (tb[NL80211_NAN_FUNC_TTL])
  9235. func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
  9236. switch (func->type) {
  9237. case NL80211_NAN_FUNC_PUBLISH:
  9238. if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
  9239. err = -EINVAL;
  9240. goto out;
  9241. }
  9242. func->publish_type =
  9243. nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
  9244. func->publish_bcast =
  9245. nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
  9246. if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
  9247. func->publish_bcast) {
  9248. err = -EINVAL;
  9249. goto out;
  9250. }
  9251. break;
  9252. case NL80211_NAN_FUNC_SUBSCRIBE:
  9253. func->subscribe_active =
  9254. nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
  9255. break;
  9256. case NL80211_NAN_FUNC_FOLLOW_UP:
  9257. if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
  9258. !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
  9259. !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
  9260. err = -EINVAL;
  9261. goto out;
  9262. }
  9263. func->followup_id =
  9264. nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
  9265. func->followup_reqid =
  9266. nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
  9267. memcpy(func->followup_dest.addr,
  9268. nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
  9269. sizeof(func->followup_dest.addr));
  9270. if (func->ttl) {
  9271. err = -EINVAL;
  9272. goto out;
  9273. }
  9274. break;
  9275. default:
  9276. err = -EINVAL;
  9277. goto out;
  9278. }
  9279. if (tb[NL80211_NAN_FUNC_SRF]) {
  9280. struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
  9281. err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX,
  9282. nla_data(tb[NL80211_NAN_FUNC_SRF]),
  9283. nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL);
  9284. if (err)
  9285. goto out;
  9286. func->srf_include =
  9287. nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
  9288. if (srf_tb[NL80211_NAN_SRF_BF]) {
  9289. if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
  9290. !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
  9291. err = -EINVAL;
  9292. goto out;
  9293. }
  9294. func->srf_bf_len =
  9295. nla_len(srf_tb[NL80211_NAN_SRF_BF]);
  9296. func->srf_bf =
  9297. kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
  9298. func->srf_bf_len, GFP_KERNEL);
  9299. if (!func->srf_bf) {
  9300. err = -ENOMEM;
  9301. goto out;
  9302. }
  9303. func->srf_bf_idx =
  9304. nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
  9305. } else {
  9306. struct nlattr *attr, *mac_attr =
  9307. srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
  9308. int n_entries, rem, i = 0;
  9309. if (!mac_attr) {
  9310. err = -EINVAL;
  9311. goto out;
  9312. }
  9313. n_entries = validate_acl_mac_addrs(mac_attr);
  9314. if (n_entries <= 0) {
  9315. err = -EINVAL;
  9316. goto out;
  9317. }
  9318. func->srf_num_macs = n_entries;
  9319. func->srf_macs =
  9320. kzalloc(sizeof(*func->srf_macs) * n_entries,
  9321. GFP_KERNEL);
  9322. if (!func->srf_macs) {
  9323. err = -ENOMEM;
  9324. goto out;
  9325. }
  9326. nla_for_each_nested(attr, mac_attr, rem)
  9327. memcpy(func->srf_macs[i++].addr, nla_data(attr),
  9328. sizeof(*func->srf_macs));
  9329. }
  9330. }
  9331. if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
  9332. err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
  9333. func, true);
  9334. if (err)
  9335. goto out;
  9336. }
  9337. if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
  9338. err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
  9339. func, false);
  9340. if (err)
  9341. goto out;
  9342. }
  9343. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9344. if (!msg) {
  9345. err = -ENOMEM;
  9346. goto out;
  9347. }
  9348. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  9349. NL80211_CMD_ADD_NAN_FUNCTION);
  9350. /* This can't really happen - we just allocated 4KB */
  9351. if (WARN_ON(!hdr)) {
  9352. err = -ENOMEM;
  9353. goto out;
  9354. }
  9355. err = rdev_add_nan_func(rdev, wdev, func);
  9356. out:
  9357. if (err < 0) {
  9358. cfg80211_free_nan_func(func);
  9359. nlmsg_free(msg);
  9360. return err;
  9361. }
  9362. /* propagate the instance id and cookie to userspace */
  9363. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
  9364. NL80211_ATTR_PAD))
  9365. goto nla_put_failure;
  9366. func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
  9367. if (!func_attr)
  9368. goto nla_put_failure;
  9369. if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
  9370. func->instance_id))
  9371. goto nla_put_failure;
  9372. nla_nest_end(msg, func_attr);
  9373. genlmsg_end(msg, hdr);
  9374. return genlmsg_reply(msg, info);
  9375. nla_put_failure:
  9376. nlmsg_free(msg);
  9377. return -ENOBUFS;
  9378. }
  9379. static int nl80211_nan_del_func(struct sk_buff *skb,
  9380. struct genl_info *info)
  9381. {
  9382. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9383. struct wireless_dev *wdev = info->user_ptr[1];
  9384. u64 cookie;
  9385. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9386. return -EOPNOTSUPP;
  9387. if (!wdev->nan_started)
  9388. return -ENOTCONN;
  9389. if (!info->attrs[NL80211_ATTR_COOKIE])
  9390. return -EINVAL;
  9391. if (wdev->owner_nlportid &&
  9392. wdev->owner_nlportid != info->snd_portid)
  9393. return -ENOTCONN;
  9394. cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
  9395. rdev_del_nan_func(rdev, wdev, cookie);
  9396. return 0;
  9397. }
  9398. static int nl80211_nan_change_config(struct sk_buff *skb,
  9399. struct genl_info *info)
  9400. {
  9401. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9402. struct wireless_dev *wdev = info->user_ptr[1];
  9403. struct cfg80211_nan_conf conf = {};
  9404. u32 changed = 0;
  9405. if (wdev->iftype != NL80211_IFTYPE_NAN)
  9406. return -EOPNOTSUPP;
  9407. if (!wdev->nan_started)
  9408. return -ENOTCONN;
  9409. if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
  9410. conf.master_pref =
  9411. nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
  9412. if (conf.master_pref <= 1 || conf.master_pref == 255)
  9413. return -EINVAL;
  9414. changed |= CFG80211_NAN_CONF_CHANGED_PREF;
  9415. }
  9416. if (info->attrs[NL80211_ATTR_NAN_DUAL]) {
  9417. conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]);
  9418. changed |= CFG80211_NAN_CONF_CHANGED_DUAL;
  9419. }
  9420. if (!changed)
  9421. return -EINVAL;
  9422. return rdev_nan_change_conf(rdev, wdev, &conf, changed);
  9423. }
  9424. void cfg80211_nan_match(struct wireless_dev *wdev,
  9425. struct cfg80211_nan_match_params *match, gfp_t gfp)
  9426. {
  9427. struct wiphy *wiphy = wdev->wiphy;
  9428. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9429. struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
  9430. struct sk_buff *msg;
  9431. void *hdr;
  9432. if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
  9433. return;
  9434. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9435. if (!msg)
  9436. return;
  9437. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
  9438. if (!hdr) {
  9439. nlmsg_free(msg);
  9440. return;
  9441. }
  9442. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9443. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  9444. wdev->netdev->ifindex)) ||
  9445. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  9446. NL80211_ATTR_PAD))
  9447. goto nla_put_failure;
  9448. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
  9449. NL80211_ATTR_PAD) ||
  9450. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
  9451. goto nla_put_failure;
  9452. match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH);
  9453. if (!match_attr)
  9454. goto nla_put_failure;
  9455. local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL);
  9456. if (!local_func_attr)
  9457. goto nla_put_failure;
  9458. if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
  9459. goto nla_put_failure;
  9460. nla_nest_end(msg, local_func_attr);
  9461. peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER);
  9462. if (!peer_func_attr)
  9463. goto nla_put_failure;
  9464. if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
  9465. nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
  9466. goto nla_put_failure;
  9467. if (match->info && match->info_len &&
  9468. nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
  9469. match->info))
  9470. goto nla_put_failure;
  9471. nla_nest_end(msg, peer_func_attr);
  9472. nla_nest_end(msg, match_attr);
  9473. genlmsg_end(msg, hdr);
  9474. if (!wdev->owner_nlportid)
  9475. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
  9476. msg, 0, NL80211_MCGRP_NAN, gfp);
  9477. else
  9478. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
  9479. wdev->owner_nlportid);
  9480. return;
  9481. nla_put_failure:
  9482. nlmsg_free(msg);
  9483. }
  9484. EXPORT_SYMBOL(cfg80211_nan_match);
  9485. void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
  9486. u8 inst_id,
  9487. enum nl80211_nan_func_term_reason reason,
  9488. u64 cookie, gfp_t gfp)
  9489. {
  9490. struct wiphy *wiphy = wdev->wiphy;
  9491. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9492. struct sk_buff *msg;
  9493. struct nlattr *func_attr;
  9494. void *hdr;
  9495. if (WARN_ON(!inst_id))
  9496. return;
  9497. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  9498. if (!msg)
  9499. return;
  9500. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
  9501. if (!hdr) {
  9502. nlmsg_free(msg);
  9503. return;
  9504. }
  9505. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9506. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  9507. wdev->netdev->ifindex)) ||
  9508. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  9509. NL80211_ATTR_PAD))
  9510. goto nla_put_failure;
  9511. if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  9512. NL80211_ATTR_PAD))
  9513. goto nla_put_failure;
  9514. func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC);
  9515. if (!func_attr)
  9516. goto nla_put_failure;
  9517. if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
  9518. nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
  9519. goto nla_put_failure;
  9520. nla_nest_end(msg, func_attr);
  9521. genlmsg_end(msg, hdr);
  9522. if (!wdev->owner_nlportid)
  9523. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
  9524. msg, 0, NL80211_MCGRP_NAN, gfp);
  9525. else
  9526. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
  9527. wdev->owner_nlportid);
  9528. return;
  9529. nla_put_failure:
  9530. nlmsg_free(msg);
  9531. }
  9532. EXPORT_SYMBOL(cfg80211_nan_func_terminated);
  9533. static int nl80211_get_protocol_features(struct sk_buff *skb,
  9534. struct genl_info *info)
  9535. {
  9536. void *hdr;
  9537. struct sk_buff *msg;
  9538. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  9539. if (!msg)
  9540. return -ENOMEM;
  9541. hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
  9542. NL80211_CMD_GET_PROTOCOL_FEATURES);
  9543. if (!hdr)
  9544. goto nla_put_failure;
  9545. if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
  9546. NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
  9547. goto nla_put_failure;
  9548. genlmsg_end(msg, hdr);
  9549. return genlmsg_reply(msg, info);
  9550. nla_put_failure:
  9551. kfree_skb(msg);
  9552. return -ENOBUFS;
  9553. }
  9554. static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
  9555. {
  9556. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9557. struct cfg80211_update_ft_ies_params ft_params;
  9558. struct net_device *dev = info->user_ptr[1];
  9559. if (!rdev->ops->update_ft_ies)
  9560. return -EOPNOTSUPP;
  9561. if (!info->attrs[NL80211_ATTR_MDID] ||
  9562. !info->attrs[NL80211_ATTR_IE] ||
  9563. !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
  9564. return -EINVAL;
  9565. memset(&ft_params, 0, sizeof(ft_params));
  9566. ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
  9567. ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
  9568. ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
  9569. return rdev_update_ft_ies(rdev, dev, &ft_params);
  9570. }
  9571. static int nl80211_crit_protocol_start(struct sk_buff *skb,
  9572. struct genl_info *info)
  9573. {
  9574. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9575. struct wireless_dev *wdev = info->user_ptr[1];
  9576. enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
  9577. u16 duration;
  9578. int ret;
  9579. if (!rdev->ops->crit_proto_start)
  9580. return -EOPNOTSUPP;
  9581. if (WARN_ON(!rdev->ops->crit_proto_stop))
  9582. return -EINVAL;
  9583. if (rdev->crit_proto_nlportid)
  9584. return -EBUSY;
  9585. /* determine protocol if provided */
  9586. if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
  9587. proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
  9588. if (proto >= NUM_NL80211_CRIT_PROTO)
  9589. return -EINVAL;
  9590. /* timeout must be provided */
  9591. if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
  9592. return -EINVAL;
  9593. duration =
  9594. nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
  9595. if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
  9596. return -ERANGE;
  9597. ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
  9598. if (!ret)
  9599. rdev->crit_proto_nlportid = info->snd_portid;
  9600. return ret;
  9601. }
  9602. static int nl80211_crit_protocol_stop(struct sk_buff *skb,
  9603. struct genl_info *info)
  9604. {
  9605. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9606. struct wireless_dev *wdev = info->user_ptr[1];
  9607. if (!rdev->ops->crit_proto_stop)
  9608. return -EOPNOTSUPP;
  9609. if (rdev->crit_proto_nlportid) {
  9610. rdev->crit_proto_nlportid = 0;
  9611. rdev_crit_proto_stop(rdev, wdev);
  9612. }
  9613. return 0;
  9614. }
  9615. static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
  9616. {
  9617. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9618. struct wireless_dev *wdev =
  9619. __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
  9620. int i, err;
  9621. u32 vid, subcmd;
  9622. if (!rdev->wiphy.vendor_commands)
  9623. return -EOPNOTSUPP;
  9624. if (IS_ERR(wdev)) {
  9625. err = PTR_ERR(wdev);
  9626. if (err != -EINVAL)
  9627. return err;
  9628. wdev = NULL;
  9629. } else if (wdev->wiphy != &rdev->wiphy) {
  9630. return -EINVAL;
  9631. }
  9632. if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
  9633. !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
  9634. return -EINVAL;
  9635. vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
  9636. subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
  9637. for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
  9638. const struct wiphy_vendor_command *vcmd;
  9639. void *data = NULL;
  9640. int len = 0;
  9641. vcmd = &rdev->wiphy.vendor_commands[i];
  9642. if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
  9643. continue;
  9644. if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
  9645. WIPHY_VENDOR_CMD_NEED_NETDEV)) {
  9646. if (!wdev)
  9647. return -EINVAL;
  9648. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
  9649. !wdev->netdev)
  9650. return -EINVAL;
  9651. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
  9652. if (wdev->netdev &&
  9653. !netif_running(wdev->netdev))
  9654. return -ENETDOWN;
  9655. if (!wdev->netdev && !wdev->p2p_started)
  9656. return -ENETDOWN;
  9657. }
  9658. if (!vcmd->doit)
  9659. return -EOPNOTSUPP;
  9660. } else {
  9661. wdev = NULL;
  9662. }
  9663. if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
  9664. data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  9665. len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
  9666. }
  9667. rdev->cur_cmd_info = info;
  9668. err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
  9669. data, len);
  9670. rdev->cur_cmd_info = NULL;
  9671. return err;
  9672. }
  9673. return -EOPNOTSUPP;
  9674. }
  9675. static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
  9676. struct netlink_callback *cb,
  9677. struct cfg80211_registered_device **rdev,
  9678. struct wireless_dev **wdev)
  9679. {
  9680. u32 vid, subcmd;
  9681. unsigned int i;
  9682. int vcmd_idx = -1;
  9683. int err;
  9684. void *data = NULL;
  9685. unsigned int data_len = 0;
  9686. if (cb->args[0]) {
  9687. /* subtract the 1 again here */
  9688. struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
  9689. struct wireless_dev *tmp;
  9690. if (!wiphy)
  9691. return -ENODEV;
  9692. *rdev = wiphy_to_rdev(wiphy);
  9693. *wdev = NULL;
  9694. if (cb->args[1]) {
  9695. list_for_each_entry(tmp, &wiphy->wdev_list, list) {
  9696. if (tmp->identifier == cb->args[1] - 1) {
  9697. *wdev = tmp;
  9698. break;
  9699. }
  9700. }
  9701. }
  9702. /* keep rtnl locked in successful case */
  9703. return 0;
  9704. }
  9705. err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
  9706. nl80211_fam.attrbuf, nl80211_fam.maxattr,
  9707. nl80211_policy);
  9708. if (err)
  9709. return err;
  9710. if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
  9711. !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD])
  9712. return -EINVAL;
  9713. *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
  9714. nl80211_fam.attrbuf);
  9715. if (IS_ERR(*wdev))
  9716. *wdev = NULL;
  9717. *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
  9718. nl80211_fam.attrbuf);
  9719. if (IS_ERR(*rdev))
  9720. return PTR_ERR(*rdev);
  9721. vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
  9722. subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
  9723. for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
  9724. const struct wiphy_vendor_command *vcmd;
  9725. vcmd = &(*rdev)->wiphy.vendor_commands[i];
  9726. if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
  9727. continue;
  9728. if (!vcmd->dumpit)
  9729. return -EOPNOTSUPP;
  9730. vcmd_idx = i;
  9731. break;
  9732. }
  9733. if (vcmd_idx < 0)
  9734. return -EOPNOTSUPP;
  9735. if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
  9736. data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
  9737. data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
  9738. }
  9739. /* 0 is the first index - add 1 to parse only once */
  9740. cb->args[0] = (*rdev)->wiphy_idx + 1;
  9741. /* add 1 to know if it was NULL */
  9742. cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
  9743. cb->args[2] = vcmd_idx;
  9744. cb->args[3] = (unsigned long)data;
  9745. cb->args[4] = data_len;
  9746. /* keep rtnl locked in successful case */
  9747. return 0;
  9748. }
  9749. static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
  9750. struct netlink_callback *cb)
  9751. {
  9752. struct cfg80211_registered_device *rdev;
  9753. struct wireless_dev *wdev;
  9754. unsigned int vcmd_idx;
  9755. const struct wiphy_vendor_command *vcmd;
  9756. void *data;
  9757. int data_len;
  9758. int err;
  9759. struct nlattr *vendor_data;
  9760. rtnl_lock();
  9761. err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
  9762. if (err)
  9763. goto out;
  9764. vcmd_idx = cb->args[2];
  9765. data = (void *)cb->args[3];
  9766. data_len = cb->args[4];
  9767. vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
  9768. if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
  9769. WIPHY_VENDOR_CMD_NEED_NETDEV)) {
  9770. if (!wdev) {
  9771. err = -EINVAL;
  9772. goto out;
  9773. }
  9774. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
  9775. !wdev->netdev) {
  9776. err = -EINVAL;
  9777. goto out;
  9778. }
  9779. if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
  9780. if (wdev->netdev &&
  9781. !netif_running(wdev->netdev)) {
  9782. err = -ENETDOWN;
  9783. goto out;
  9784. }
  9785. if (!wdev->netdev && !wdev->p2p_started) {
  9786. err = -ENETDOWN;
  9787. goto out;
  9788. }
  9789. }
  9790. }
  9791. while (1) {
  9792. void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
  9793. cb->nlh->nlmsg_seq, NLM_F_MULTI,
  9794. NL80211_CMD_VENDOR);
  9795. if (!hdr)
  9796. break;
  9797. if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  9798. (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
  9799. wdev_id(wdev),
  9800. NL80211_ATTR_PAD))) {
  9801. genlmsg_cancel(skb, hdr);
  9802. break;
  9803. }
  9804. vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
  9805. if (!vendor_data) {
  9806. genlmsg_cancel(skb, hdr);
  9807. break;
  9808. }
  9809. err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
  9810. (unsigned long *)&cb->args[5]);
  9811. nla_nest_end(skb, vendor_data);
  9812. if (err == -ENOBUFS || err == -ENOENT) {
  9813. genlmsg_cancel(skb, hdr);
  9814. break;
  9815. } else if (err) {
  9816. genlmsg_cancel(skb, hdr);
  9817. goto out;
  9818. }
  9819. genlmsg_end(skb, hdr);
  9820. }
  9821. err = skb->len;
  9822. out:
  9823. rtnl_unlock();
  9824. return err;
  9825. }
  9826. struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
  9827. enum nl80211_commands cmd,
  9828. enum nl80211_attrs attr,
  9829. int approxlen)
  9830. {
  9831. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  9832. if (WARN_ON(!rdev->cur_cmd_info))
  9833. return NULL;
  9834. return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
  9835. rdev->cur_cmd_info->snd_portid,
  9836. rdev->cur_cmd_info->snd_seq,
  9837. cmd, attr, NULL, GFP_KERNEL);
  9838. }
  9839. EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
  9840. int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
  9841. {
  9842. struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
  9843. void *hdr = ((void **)skb->cb)[1];
  9844. struct nlattr *data = ((void **)skb->cb)[2];
  9845. /* clear CB data for netlink core to own from now on */
  9846. memset(skb->cb, 0, sizeof(skb->cb));
  9847. if (WARN_ON(!rdev->cur_cmd_info)) {
  9848. kfree_skb(skb);
  9849. return -EINVAL;
  9850. }
  9851. nla_nest_end(skb, data);
  9852. genlmsg_end(skb, hdr);
  9853. return genlmsg_reply(skb, rdev->cur_cmd_info);
  9854. }
  9855. EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
  9856. static int nl80211_set_qos_map(struct sk_buff *skb,
  9857. struct genl_info *info)
  9858. {
  9859. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9860. struct cfg80211_qos_map *qos_map = NULL;
  9861. struct net_device *dev = info->user_ptr[1];
  9862. u8 *pos, len, num_des, des_len, des;
  9863. int ret;
  9864. if (!rdev->ops->set_qos_map)
  9865. return -EOPNOTSUPP;
  9866. if (info->attrs[NL80211_ATTR_QOS_MAP]) {
  9867. pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
  9868. len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
  9869. if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
  9870. len > IEEE80211_QOS_MAP_LEN_MAX)
  9871. return -EINVAL;
  9872. qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
  9873. if (!qos_map)
  9874. return -ENOMEM;
  9875. num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
  9876. if (num_des) {
  9877. des_len = num_des *
  9878. sizeof(struct cfg80211_dscp_exception);
  9879. memcpy(qos_map->dscp_exception, pos, des_len);
  9880. qos_map->num_des = num_des;
  9881. for (des = 0; des < num_des; des++) {
  9882. if (qos_map->dscp_exception[des].up > 7) {
  9883. kfree(qos_map);
  9884. return -EINVAL;
  9885. }
  9886. }
  9887. pos += des_len;
  9888. }
  9889. memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
  9890. }
  9891. wdev_lock(dev->ieee80211_ptr);
  9892. ret = nl80211_key_allowed(dev->ieee80211_ptr);
  9893. if (!ret)
  9894. ret = rdev_set_qos_map(rdev, dev, qos_map);
  9895. wdev_unlock(dev->ieee80211_ptr);
  9896. kfree(qos_map);
  9897. return ret;
  9898. }
  9899. static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
  9900. {
  9901. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9902. struct net_device *dev = info->user_ptr[1];
  9903. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9904. const u8 *peer;
  9905. u8 tsid, up;
  9906. u16 admitted_time = 0;
  9907. int err;
  9908. if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
  9909. return -EOPNOTSUPP;
  9910. if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
  9911. !info->attrs[NL80211_ATTR_USER_PRIO])
  9912. return -EINVAL;
  9913. tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
  9914. if (tsid >= IEEE80211_NUM_TIDS)
  9915. return -EINVAL;
  9916. up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
  9917. if (up >= IEEE80211_NUM_UPS)
  9918. return -EINVAL;
  9919. /* WMM uses TIDs 0-7 even for TSPEC */
  9920. if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
  9921. /* TODO: handle 802.11 TSPEC/admission control
  9922. * need more attributes for that (e.g. BA session requirement);
  9923. * change the WMM adminssion test above to allow both then
  9924. */
  9925. return -EINVAL;
  9926. }
  9927. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9928. if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
  9929. admitted_time =
  9930. nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
  9931. if (!admitted_time)
  9932. return -EINVAL;
  9933. }
  9934. wdev_lock(wdev);
  9935. switch (wdev->iftype) {
  9936. case NL80211_IFTYPE_STATION:
  9937. case NL80211_IFTYPE_P2P_CLIENT:
  9938. if (wdev->current_bss)
  9939. break;
  9940. err = -ENOTCONN;
  9941. goto out;
  9942. default:
  9943. err = -EOPNOTSUPP;
  9944. goto out;
  9945. }
  9946. err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
  9947. out:
  9948. wdev_unlock(wdev);
  9949. return err;
  9950. }
  9951. static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
  9952. {
  9953. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9954. struct net_device *dev = info->user_ptr[1];
  9955. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9956. const u8 *peer;
  9957. u8 tsid;
  9958. int err;
  9959. if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
  9960. return -EINVAL;
  9961. tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
  9962. peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
  9963. wdev_lock(wdev);
  9964. err = rdev_del_tx_ts(rdev, dev, tsid, peer);
  9965. wdev_unlock(wdev);
  9966. return err;
  9967. }
  9968. static int nl80211_tdls_channel_switch(struct sk_buff *skb,
  9969. struct genl_info *info)
  9970. {
  9971. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  9972. struct net_device *dev = info->user_ptr[1];
  9973. struct wireless_dev *wdev = dev->ieee80211_ptr;
  9974. struct cfg80211_chan_def chandef = {};
  9975. const u8 *addr;
  9976. u8 oper_class;
  9977. int err;
  9978. if (!rdev->ops->tdls_channel_switch ||
  9979. !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
  9980. return -EOPNOTSUPP;
  9981. switch (dev->ieee80211_ptr->iftype) {
  9982. case NL80211_IFTYPE_STATION:
  9983. case NL80211_IFTYPE_P2P_CLIENT:
  9984. break;
  9985. default:
  9986. return -EOPNOTSUPP;
  9987. }
  9988. if (!info->attrs[NL80211_ATTR_MAC] ||
  9989. !info->attrs[NL80211_ATTR_OPER_CLASS])
  9990. return -EINVAL;
  9991. err = nl80211_parse_chandef(rdev, info, &chandef);
  9992. if (err)
  9993. return err;
  9994. /*
  9995. * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
  9996. * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
  9997. * specification is not defined for them.
  9998. */
  9999. if (chandef.chan->band == NL80211_BAND_2GHZ &&
  10000. chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
  10001. chandef.width != NL80211_CHAN_WIDTH_20)
  10002. return -EINVAL;
  10003. /* we will be active on the TDLS link */
  10004. if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
  10005. wdev->iftype))
  10006. return -EINVAL;
  10007. /* don't allow switching to DFS channels */
  10008. if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
  10009. return -EINVAL;
  10010. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  10011. oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
  10012. wdev_lock(wdev);
  10013. err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
  10014. wdev_unlock(wdev);
  10015. return err;
  10016. }
  10017. static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
  10018. struct genl_info *info)
  10019. {
  10020. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  10021. struct net_device *dev = info->user_ptr[1];
  10022. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10023. const u8 *addr;
  10024. if (!rdev->ops->tdls_channel_switch ||
  10025. !rdev->ops->tdls_cancel_channel_switch ||
  10026. !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
  10027. return -EOPNOTSUPP;
  10028. switch (dev->ieee80211_ptr->iftype) {
  10029. case NL80211_IFTYPE_STATION:
  10030. case NL80211_IFTYPE_P2P_CLIENT:
  10031. break;
  10032. default:
  10033. return -EOPNOTSUPP;
  10034. }
  10035. if (!info->attrs[NL80211_ATTR_MAC])
  10036. return -EINVAL;
  10037. addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
  10038. wdev_lock(wdev);
  10039. rdev_tdls_cancel_channel_switch(rdev, dev, addr);
  10040. wdev_unlock(wdev);
  10041. return 0;
  10042. }
  10043. static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
  10044. struct genl_info *info)
  10045. {
  10046. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  10047. struct net_device *dev = info->user_ptr[1];
  10048. struct wireless_dev *wdev = dev->ieee80211_ptr;
  10049. const struct nlattr *nla;
  10050. bool enabled;
  10051. if (netif_running(dev))
  10052. return -EBUSY;
  10053. if (!rdev->ops->set_multicast_to_unicast)
  10054. return -EOPNOTSUPP;
  10055. if (wdev->iftype != NL80211_IFTYPE_AP &&
  10056. wdev->iftype != NL80211_IFTYPE_P2P_GO)
  10057. return -EOPNOTSUPP;
  10058. nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
  10059. enabled = nla_get_flag(nla);
  10060. return rdev_set_multicast_to_unicast(rdev, dev, enabled);
  10061. }
  10062. static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
  10063. {
  10064. struct cfg80211_registered_device *rdev = info->user_ptr[0];
  10065. struct net_device *dev = info->user_ptr[1];
  10066. struct cfg80211_external_auth_params params;
  10067. if (!rdev->ops->external_auth)
  10068. return -EOPNOTSUPP;
  10069. if (!info->attrs[NL80211_ATTR_SSID])
  10070. return -EINVAL;
  10071. if (!info->attrs[NL80211_ATTR_BSSID])
  10072. return -EINVAL;
  10073. if (!info->attrs[NL80211_ATTR_STATUS_CODE])
  10074. return -EINVAL;
  10075. memset(&params, 0, sizeof(params));
  10076. params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
  10077. if (params.ssid.ssid_len == 0 ||
  10078. params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
  10079. return -EINVAL;
  10080. memcpy(params.ssid.ssid, nla_data(info->attrs[NL80211_ATTR_SSID]),
  10081. params.ssid.ssid_len);
  10082. memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
  10083. ETH_ALEN);
  10084. params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
  10085. return rdev_external_auth(rdev, dev, &params);
  10086. }
  10087. #define NL80211_FLAG_NEED_WIPHY 0x01
  10088. #define NL80211_FLAG_NEED_NETDEV 0x02
  10089. #define NL80211_FLAG_NEED_RTNL 0x04
  10090. #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
  10091. #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
  10092. NL80211_FLAG_CHECK_NETDEV_UP)
  10093. #define NL80211_FLAG_NEED_WDEV 0x10
  10094. /* If a netdev is associated, it must be UP, P2P must be started */
  10095. #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
  10096. NL80211_FLAG_CHECK_NETDEV_UP)
  10097. #define NL80211_FLAG_CLEAR_SKB 0x20
  10098. static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
  10099. struct genl_info *info)
  10100. {
  10101. struct cfg80211_registered_device *rdev;
  10102. struct wireless_dev *wdev;
  10103. struct net_device *dev;
  10104. bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
  10105. if (rtnl)
  10106. rtnl_lock();
  10107. if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
  10108. rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
  10109. if (IS_ERR(rdev)) {
  10110. if (rtnl)
  10111. rtnl_unlock();
  10112. return PTR_ERR(rdev);
  10113. }
  10114. info->user_ptr[0] = rdev;
  10115. } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
  10116. ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
  10117. ASSERT_RTNL();
  10118. wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
  10119. info->attrs);
  10120. if (IS_ERR(wdev)) {
  10121. if (rtnl)
  10122. rtnl_unlock();
  10123. return PTR_ERR(wdev);
  10124. }
  10125. dev = wdev->netdev;
  10126. rdev = wiphy_to_rdev(wdev->wiphy);
  10127. if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
  10128. if (!dev) {
  10129. if (rtnl)
  10130. rtnl_unlock();
  10131. return -EINVAL;
  10132. }
  10133. info->user_ptr[1] = dev;
  10134. } else {
  10135. info->user_ptr[1] = wdev;
  10136. }
  10137. if (dev) {
  10138. if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
  10139. !netif_running(dev)) {
  10140. if (rtnl)
  10141. rtnl_unlock();
  10142. return -ENETDOWN;
  10143. }
  10144. dev_hold(dev);
  10145. } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
  10146. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE &&
  10147. !wdev->p2p_started) {
  10148. if (rtnl)
  10149. rtnl_unlock();
  10150. return -ENETDOWN;
  10151. }
  10152. if (wdev->iftype == NL80211_IFTYPE_NAN &&
  10153. !wdev->nan_started) {
  10154. if (rtnl)
  10155. rtnl_unlock();
  10156. return -ENETDOWN;
  10157. }
  10158. }
  10159. info->user_ptr[0] = rdev;
  10160. }
  10161. return 0;
  10162. }
  10163. static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
  10164. struct genl_info *info)
  10165. {
  10166. if (info->user_ptr[1]) {
  10167. if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
  10168. struct wireless_dev *wdev = info->user_ptr[1];
  10169. if (wdev->netdev)
  10170. dev_put(wdev->netdev);
  10171. } else {
  10172. dev_put(info->user_ptr[1]);
  10173. }
  10174. }
  10175. if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
  10176. rtnl_unlock();
  10177. /* If needed, clear the netlink message payload from the SKB
  10178. * as it might contain key data that shouldn't stick around on
  10179. * the heap after the SKB is freed. The netlink message header
  10180. * is still needed for further processing, so leave it intact.
  10181. */
  10182. if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
  10183. struct nlmsghdr *nlh = nlmsg_hdr(skb);
  10184. memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
  10185. }
  10186. }
  10187. static const struct genl_ops nl80211_ops[] = {
  10188. {
  10189. .cmd = NL80211_CMD_GET_WIPHY,
  10190. .doit = nl80211_get_wiphy,
  10191. .dumpit = nl80211_dump_wiphy,
  10192. .done = nl80211_dump_wiphy_done,
  10193. .policy = nl80211_policy,
  10194. /* can be retrieved by unprivileged users */
  10195. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10196. NL80211_FLAG_NEED_RTNL,
  10197. },
  10198. {
  10199. .cmd = NL80211_CMD_SET_WIPHY,
  10200. .doit = nl80211_set_wiphy,
  10201. .policy = nl80211_policy,
  10202. .flags = GENL_UNS_ADMIN_PERM,
  10203. .internal_flags = NL80211_FLAG_NEED_RTNL,
  10204. },
  10205. {
  10206. .cmd = NL80211_CMD_GET_INTERFACE,
  10207. .doit = nl80211_get_interface,
  10208. .dumpit = nl80211_dump_interface,
  10209. .policy = nl80211_policy,
  10210. /* can be retrieved by unprivileged users */
  10211. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10212. NL80211_FLAG_NEED_RTNL,
  10213. },
  10214. {
  10215. .cmd = NL80211_CMD_SET_INTERFACE,
  10216. .doit = nl80211_set_interface,
  10217. .policy = nl80211_policy,
  10218. .flags = GENL_UNS_ADMIN_PERM,
  10219. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10220. NL80211_FLAG_NEED_RTNL,
  10221. },
  10222. {
  10223. .cmd = NL80211_CMD_NEW_INTERFACE,
  10224. .doit = nl80211_new_interface,
  10225. .policy = nl80211_policy,
  10226. .flags = GENL_UNS_ADMIN_PERM,
  10227. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10228. NL80211_FLAG_NEED_RTNL,
  10229. },
  10230. {
  10231. .cmd = NL80211_CMD_DEL_INTERFACE,
  10232. .doit = nl80211_del_interface,
  10233. .policy = nl80211_policy,
  10234. .flags = GENL_UNS_ADMIN_PERM,
  10235. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10236. NL80211_FLAG_NEED_RTNL,
  10237. },
  10238. {
  10239. .cmd = NL80211_CMD_GET_KEY,
  10240. .doit = nl80211_get_key,
  10241. .policy = nl80211_policy,
  10242. .flags = GENL_UNS_ADMIN_PERM,
  10243. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10244. NL80211_FLAG_NEED_RTNL,
  10245. },
  10246. {
  10247. .cmd = NL80211_CMD_SET_KEY,
  10248. .doit = nl80211_set_key,
  10249. .policy = nl80211_policy,
  10250. .flags = GENL_UNS_ADMIN_PERM,
  10251. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10252. NL80211_FLAG_NEED_RTNL |
  10253. NL80211_FLAG_CLEAR_SKB,
  10254. },
  10255. {
  10256. .cmd = NL80211_CMD_NEW_KEY,
  10257. .doit = nl80211_new_key,
  10258. .policy = nl80211_policy,
  10259. .flags = GENL_UNS_ADMIN_PERM,
  10260. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10261. NL80211_FLAG_NEED_RTNL |
  10262. NL80211_FLAG_CLEAR_SKB,
  10263. },
  10264. {
  10265. .cmd = NL80211_CMD_DEL_KEY,
  10266. .doit = nl80211_del_key,
  10267. .policy = nl80211_policy,
  10268. .flags = GENL_UNS_ADMIN_PERM,
  10269. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10270. NL80211_FLAG_NEED_RTNL,
  10271. },
  10272. {
  10273. .cmd = NL80211_CMD_SET_BEACON,
  10274. .policy = nl80211_policy,
  10275. .flags = GENL_UNS_ADMIN_PERM,
  10276. .doit = nl80211_set_beacon,
  10277. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10278. NL80211_FLAG_NEED_RTNL,
  10279. },
  10280. {
  10281. .cmd = NL80211_CMD_START_AP,
  10282. .policy = nl80211_policy,
  10283. .flags = GENL_UNS_ADMIN_PERM,
  10284. .doit = nl80211_start_ap,
  10285. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10286. NL80211_FLAG_NEED_RTNL,
  10287. },
  10288. {
  10289. .cmd = NL80211_CMD_STOP_AP,
  10290. .policy = nl80211_policy,
  10291. .flags = GENL_UNS_ADMIN_PERM,
  10292. .doit = nl80211_stop_ap,
  10293. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10294. NL80211_FLAG_NEED_RTNL,
  10295. },
  10296. {
  10297. .cmd = NL80211_CMD_GET_STATION,
  10298. .doit = nl80211_get_station,
  10299. .dumpit = nl80211_dump_station,
  10300. .policy = nl80211_policy,
  10301. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10302. NL80211_FLAG_NEED_RTNL,
  10303. },
  10304. {
  10305. .cmd = NL80211_CMD_SET_STATION,
  10306. .doit = nl80211_set_station,
  10307. .policy = nl80211_policy,
  10308. .flags = GENL_UNS_ADMIN_PERM,
  10309. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10310. NL80211_FLAG_NEED_RTNL,
  10311. },
  10312. {
  10313. .cmd = NL80211_CMD_NEW_STATION,
  10314. .doit = nl80211_new_station,
  10315. .policy = nl80211_policy,
  10316. .flags = GENL_UNS_ADMIN_PERM,
  10317. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10318. NL80211_FLAG_NEED_RTNL,
  10319. },
  10320. {
  10321. .cmd = NL80211_CMD_DEL_STATION,
  10322. .doit = nl80211_del_station,
  10323. .policy = nl80211_policy,
  10324. .flags = GENL_UNS_ADMIN_PERM,
  10325. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10326. NL80211_FLAG_NEED_RTNL,
  10327. },
  10328. {
  10329. .cmd = NL80211_CMD_GET_MPATH,
  10330. .doit = nl80211_get_mpath,
  10331. .dumpit = nl80211_dump_mpath,
  10332. .policy = nl80211_policy,
  10333. .flags = GENL_UNS_ADMIN_PERM,
  10334. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10335. NL80211_FLAG_NEED_RTNL,
  10336. },
  10337. {
  10338. .cmd = NL80211_CMD_GET_MPP,
  10339. .doit = nl80211_get_mpp,
  10340. .dumpit = nl80211_dump_mpp,
  10341. .policy = nl80211_policy,
  10342. .flags = GENL_UNS_ADMIN_PERM,
  10343. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10344. NL80211_FLAG_NEED_RTNL,
  10345. },
  10346. {
  10347. .cmd = NL80211_CMD_SET_MPATH,
  10348. .doit = nl80211_set_mpath,
  10349. .policy = nl80211_policy,
  10350. .flags = GENL_UNS_ADMIN_PERM,
  10351. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10352. NL80211_FLAG_NEED_RTNL,
  10353. },
  10354. {
  10355. .cmd = NL80211_CMD_NEW_MPATH,
  10356. .doit = nl80211_new_mpath,
  10357. .policy = nl80211_policy,
  10358. .flags = GENL_UNS_ADMIN_PERM,
  10359. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10360. NL80211_FLAG_NEED_RTNL,
  10361. },
  10362. {
  10363. .cmd = NL80211_CMD_DEL_MPATH,
  10364. .doit = nl80211_del_mpath,
  10365. .policy = nl80211_policy,
  10366. .flags = GENL_UNS_ADMIN_PERM,
  10367. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10368. NL80211_FLAG_NEED_RTNL,
  10369. },
  10370. {
  10371. .cmd = NL80211_CMD_SET_BSS,
  10372. .doit = nl80211_set_bss,
  10373. .policy = nl80211_policy,
  10374. .flags = GENL_UNS_ADMIN_PERM,
  10375. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10376. NL80211_FLAG_NEED_RTNL,
  10377. },
  10378. {
  10379. .cmd = NL80211_CMD_GET_REG,
  10380. .doit = nl80211_get_reg_do,
  10381. .dumpit = nl80211_get_reg_dump,
  10382. .policy = nl80211_policy,
  10383. .internal_flags = NL80211_FLAG_NEED_RTNL,
  10384. /* can be retrieved by unprivileged users */
  10385. },
  10386. #ifdef CONFIG_CFG80211_CRDA_SUPPORT
  10387. {
  10388. .cmd = NL80211_CMD_SET_REG,
  10389. .doit = nl80211_set_reg,
  10390. .policy = nl80211_policy,
  10391. .flags = GENL_ADMIN_PERM,
  10392. .internal_flags = NL80211_FLAG_NEED_RTNL,
  10393. },
  10394. #endif
  10395. {
  10396. .cmd = NL80211_CMD_REQ_SET_REG,
  10397. .doit = nl80211_req_set_reg,
  10398. .policy = nl80211_policy,
  10399. .flags = GENL_ADMIN_PERM,
  10400. },
  10401. {
  10402. .cmd = NL80211_CMD_GET_MESH_CONFIG,
  10403. .doit = nl80211_get_mesh_config,
  10404. .policy = nl80211_policy,
  10405. /* can be retrieved by unprivileged users */
  10406. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10407. NL80211_FLAG_NEED_RTNL,
  10408. },
  10409. {
  10410. .cmd = NL80211_CMD_SET_MESH_CONFIG,
  10411. .doit = nl80211_update_mesh_config,
  10412. .policy = nl80211_policy,
  10413. .flags = GENL_UNS_ADMIN_PERM,
  10414. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10415. NL80211_FLAG_NEED_RTNL,
  10416. },
  10417. {
  10418. .cmd = NL80211_CMD_TRIGGER_SCAN,
  10419. .doit = nl80211_trigger_scan,
  10420. .policy = nl80211_policy,
  10421. .flags = GENL_UNS_ADMIN_PERM,
  10422. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10423. NL80211_FLAG_NEED_RTNL,
  10424. },
  10425. {
  10426. .cmd = NL80211_CMD_ABORT_SCAN,
  10427. .doit = nl80211_abort_scan,
  10428. .policy = nl80211_policy,
  10429. .flags = GENL_UNS_ADMIN_PERM,
  10430. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10431. NL80211_FLAG_NEED_RTNL,
  10432. },
  10433. {
  10434. .cmd = NL80211_CMD_GET_SCAN,
  10435. .policy = nl80211_policy,
  10436. .dumpit = nl80211_dump_scan,
  10437. },
  10438. {
  10439. .cmd = NL80211_CMD_START_SCHED_SCAN,
  10440. .doit = nl80211_start_sched_scan,
  10441. .policy = nl80211_policy,
  10442. .flags = GENL_UNS_ADMIN_PERM,
  10443. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10444. NL80211_FLAG_NEED_RTNL,
  10445. },
  10446. {
  10447. .cmd = NL80211_CMD_STOP_SCHED_SCAN,
  10448. .doit = nl80211_stop_sched_scan,
  10449. .policy = nl80211_policy,
  10450. .flags = GENL_UNS_ADMIN_PERM,
  10451. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10452. NL80211_FLAG_NEED_RTNL,
  10453. },
  10454. {
  10455. .cmd = NL80211_CMD_AUTHENTICATE,
  10456. .doit = nl80211_authenticate,
  10457. .policy = nl80211_policy,
  10458. .flags = GENL_UNS_ADMIN_PERM,
  10459. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10460. NL80211_FLAG_NEED_RTNL |
  10461. NL80211_FLAG_CLEAR_SKB,
  10462. },
  10463. {
  10464. .cmd = NL80211_CMD_ASSOCIATE,
  10465. .doit = nl80211_associate,
  10466. .policy = nl80211_policy,
  10467. .flags = GENL_UNS_ADMIN_PERM,
  10468. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10469. NL80211_FLAG_NEED_RTNL |
  10470. NL80211_FLAG_CLEAR_SKB,
  10471. },
  10472. {
  10473. .cmd = NL80211_CMD_DEAUTHENTICATE,
  10474. .doit = nl80211_deauthenticate,
  10475. .policy = nl80211_policy,
  10476. .flags = GENL_UNS_ADMIN_PERM,
  10477. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10478. NL80211_FLAG_NEED_RTNL,
  10479. },
  10480. {
  10481. .cmd = NL80211_CMD_DISASSOCIATE,
  10482. .doit = nl80211_disassociate,
  10483. .policy = nl80211_policy,
  10484. .flags = GENL_UNS_ADMIN_PERM,
  10485. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10486. NL80211_FLAG_NEED_RTNL,
  10487. },
  10488. {
  10489. .cmd = NL80211_CMD_JOIN_IBSS,
  10490. .doit = nl80211_join_ibss,
  10491. .policy = nl80211_policy,
  10492. .flags = GENL_UNS_ADMIN_PERM,
  10493. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10494. NL80211_FLAG_NEED_RTNL,
  10495. },
  10496. {
  10497. .cmd = NL80211_CMD_LEAVE_IBSS,
  10498. .doit = nl80211_leave_ibss,
  10499. .policy = nl80211_policy,
  10500. .flags = GENL_UNS_ADMIN_PERM,
  10501. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10502. NL80211_FLAG_NEED_RTNL,
  10503. },
  10504. #ifdef CONFIG_NL80211_TESTMODE
  10505. {
  10506. .cmd = NL80211_CMD_TESTMODE,
  10507. .doit = nl80211_testmode_do,
  10508. .dumpit = nl80211_testmode_dump,
  10509. .policy = nl80211_policy,
  10510. .flags = GENL_UNS_ADMIN_PERM,
  10511. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10512. NL80211_FLAG_NEED_RTNL,
  10513. },
  10514. #endif
  10515. {
  10516. .cmd = NL80211_CMD_CONNECT,
  10517. .doit = nl80211_connect,
  10518. .policy = nl80211_policy,
  10519. .flags = GENL_UNS_ADMIN_PERM,
  10520. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10521. NL80211_FLAG_NEED_RTNL |
  10522. NL80211_FLAG_CLEAR_SKB,
  10523. },
  10524. {
  10525. .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
  10526. .doit = nl80211_update_connect_params,
  10527. .policy = nl80211_policy,
  10528. .flags = GENL_ADMIN_PERM,
  10529. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10530. NL80211_FLAG_NEED_RTNL |
  10531. NL80211_FLAG_CLEAR_SKB,
  10532. },
  10533. {
  10534. .cmd = NL80211_CMD_DISCONNECT,
  10535. .doit = nl80211_disconnect,
  10536. .policy = nl80211_policy,
  10537. .flags = GENL_UNS_ADMIN_PERM,
  10538. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10539. NL80211_FLAG_NEED_RTNL,
  10540. },
  10541. {
  10542. .cmd = NL80211_CMD_SET_WIPHY_NETNS,
  10543. .doit = nl80211_wiphy_netns,
  10544. .policy = nl80211_policy,
  10545. .flags = GENL_UNS_ADMIN_PERM,
  10546. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10547. NL80211_FLAG_NEED_RTNL,
  10548. },
  10549. {
  10550. .cmd = NL80211_CMD_GET_SURVEY,
  10551. .policy = nl80211_policy,
  10552. .dumpit = nl80211_dump_survey,
  10553. },
  10554. {
  10555. .cmd = NL80211_CMD_SET_PMKSA,
  10556. .doit = nl80211_setdel_pmksa,
  10557. .policy = nl80211_policy,
  10558. .flags = GENL_UNS_ADMIN_PERM,
  10559. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10560. NL80211_FLAG_NEED_RTNL |
  10561. NL80211_FLAG_CLEAR_SKB,
  10562. },
  10563. {
  10564. .cmd = NL80211_CMD_DEL_PMKSA,
  10565. .doit = nl80211_setdel_pmksa,
  10566. .policy = nl80211_policy,
  10567. .flags = GENL_UNS_ADMIN_PERM,
  10568. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10569. NL80211_FLAG_NEED_RTNL,
  10570. },
  10571. {
  10572. .cmd = NL80211_CMD_FLUSH_PMKSA,
  10573. .doit = nl80211_flush_pmksa,
  10574. .policy = nl80211_policy,
  10575. .flags = GENL_UNS_ADMIN_PERM,
  10576. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10577. NL80211_FLAG_NEED_RTNL,
  10578. },
  10579. {
  10580. .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
  10581. .doit = nl80211_remain_on_channel,
  10582. .policy = nl80211_policy,
  10583. .flags = GENL_UNS_ADMIN_PERM,
  10584. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10585. NL80211_FLAG_NEED_RTNL,
  10586. },
  10587. {
  10588. .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  10589. .doit = nl80211_cancel_remain_on_channel,
  10590. .policy = nl80211_policy,
  10591. .flags = GENL_UNS_ADMIN_PERM,
  10592. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10593. NL80211_FLAG_NEED_RTNL,
  10594. },
  10595. {
  10596. .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
  10597. .doit = nl80211_set_tx_bitrate_mask,
  10598. .policy = nl80211_policy,
  10599. .flags = GENL_UNS_ADMIN_PERM,
  10600. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10601. NL80211_FLAG_NEED_RTNL,
  10602. },
  10603. {
  10604. .cmd = NL80211_CMD_REGISTER_FRAME,
  10605. .doit = nl80211_register_mgmt,
  10606. .policy = nl80211_policy,
  10607. .flags = GENL_UNS_ADMIN_PERM,
  10608. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10609. NL80211_FLAG_NEED_RTNL,
  10610. },
  10611. {
  10612. .cmd = NL80211_CMD_FRAME,
  10613. .doit = nl80211_tx_mgmt,
  10614. .policy = nl80211_policy,
  10615. .flags = GENL_UNS_ADMIN_PERM,
  10616. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10617. NL80211_FLAG_NEED_RTNL,
  10618. },
  10619. {
  10620. .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
  10621. .doit = nl80211_tx_mgmt_cancel_wait,
  10622. .policy = nl80211_policy,
  10623. .flags = GENL_UNS_ADMIN_PERM,
  10624. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10625. NL80211_FLAG_NEED_RTNL,
  10626. },
  10627. {
  10628. .cmd = NL80211_CMD_SET_POWER_SAVE,
  10629. .doit = nl80211_set_power_save,
  10630. .policy = nl80211_policy,
  10631. .flags = GENL_UNS_ADMIN_PERM,
  10632. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10633. NL80211_FLAG_NEED_RTNL,
  10634. },
  10635. {
  10636. .cmd = NL80211_CMD_GET_POWER_SAVE,
  10637. .doit = nl80211_get_power_save,
  10638. .policy = nl80211_policy,
  10639. /* can be retrieved by unprivileged users */
  10640. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10641. NL80211_FLAG_NEED_RTNL,
  10642. },
  10643. {
  10644. .cmd = NL80211_CMD_SET_CQM,
  10645. .doit = nl80211_set_cqm,
  10646. .policy = nl80211_policy,
  10647. .flags = GENL_UNS_ADMIN_PERM,
  10648. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10649. NL80211_FLAG_NEED_RTNL,
  10650. },
  10651. {
  10652. .cmd = NL80211_CMD_SET_CHANNEL,
  10653. .doit = nl80211_set_channel,
  10654. .policy = nl80211_policy,
  10655. .flags = GENL_UNS_ADMIN_PERM,
  10656. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10657. NL80211_FLAG_NEED_RTNL,
  10658. },
  10659. {
  10660. .cmd = NL80211_CMD_SET_WDS_PEER,
  10661. .doit = nl80211_set_wds_peer,
  10662. .policy = nl80211_policy,
  10663. .flags = GENL_UNS_ADMIN_PERM,
  10664. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10665. NL80211_FLAG_NEED_RTNL,
  10666. },
  10667. {
  10668. .cmd = NL80211_CMD_JOIN_MESH,
  10669. .doit = nl80211_join_mesh,
  10670. .policy = nl80211_policy,
  10671. .flags = GENL_UNS_ADMIN_PERM,
  10672. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10673. NL80211_FLAG_NEED_RTNL,
  10674. },
  10675. {
  10676. .cmd = NL80211_CMD_LEAVE_MESH,
  10677. .doit = nl80211_leave_mesh,
  10678. .policy = nl80211_policy,
  10679. .flags = GENL_UNS_ADMIN_PERM,
  10680. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10681. NL80211_FLAG_NEED_RTNL,
  10682. },
  10683. {
  10684. .cmd = NL80211_CMD_JOIN_OCB,
  10685. .doit = nl80211_join_ocb,
  10686. .policy = nl80211_policy,
  10687. .flags = GENL_UNS_ADMIN_PERM,
  10688. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10689. NL80211_FLAG_NEED_RTNL,
  10690. },
  10691. {
  10692. .cmd = NL80211_CMD_LEAVE_OCB,
  10693. .doit = nl80211_leave_ocb,
  10694. .policy = nl80211_policy,
  10695. .flags = GENL_UNS_ADMIN_PERM,
  10696. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10697. NL80211_FLAG_NEED_RTNL,
  10698. },
  10699. #ifdef CONFIG_PM
  10700. {
  10701. .cmd = NL80211_CMD_GET_WOWLAN,
  10702. .doit = nl80211_get_wowlan,
  10703. .policy = nl80211_policy,
  10704. /* can be retrieved by unprivileged users */
  10705. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10706. NL80211_FLAG_NEED_RTNL,
  10707. },
  10708. {
  10709. .cmd = NL80211_CMD_SET_WOWLAN,
  10710. .doit = nl80211_set_wowlan,
  10711. .policy = nl80211_policy,
  10712. .flags = GENL_UNS_ADMIN_PERM,
  10713. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10714. NL80211_FLAG_NEED_RTNL,
  10715. },
  10716. #endif
  10717. {
  10718. .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
  10719. .doit = nl80211_set_rekey_data,
  10720. .policy = nl80211_policy,
  10721. .flags = GENL_UNS_ADMIN_PERM,
  10722. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10723. NL80211_FLAG_NEED_RTNL |
  10724. NL80211_FLAG_CLEAR_SKB,
  10725. },
  10726. {
  10727. .cmd = NL80211_CMD_TDLS_MGMT,
  10728. .doit = nl80211_tdls_mgmt,
  10729. .policy = nl80211_policy,
  10730. .flags = GENL_UNS_ADMIN_PERM,
  10731. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10732. NL80211_FLAG_NEED_RTNL,
  10733. },
  10734. {
  10735. .cmd = NL80211_CMD_TDLS_OPER,
  10736. .doit = nl80211_tdls_oper,
  10737. .policy = nl80211_policy,
  10738. .flags = GENL_UNS_ADMIN_PERM,
  10739. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10740. NL80211_FLAG_NEED_RTNL,
  10741. },
  10742. {
  10743. .cmd = NL80211_CMD_UNEXPECTED_FRAME,
  10744. .doit = nl80211_register_unexpected_frame,
  10745. .policy = nl80211_policy,
  10746. .flags = GENL_UNS_ADMIN_PERM,
  10747. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10748. NL80211_FLAG_NEED_RTNL,
  10749. },
  10750. {
  10751. .cmd = NL80211_CMD_PROBE_CLIENT,
  10752. .doit = nl80211_probe_client,
  10753. .policy = nl80211_policy,
  10754. .flags = GENL_UNS_ADMIN_PERM,
  10755. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10756. NL80211_FLAG_NEED_RTNL,
  10757. },
  10758. {
  10759. .cmd = NL80211_CMD_REGISTER_BEACONS,
  10760. .doit = nl80211_register_beacons,
  10761. .policy = nl80211_policy,
  10762. .flags = GENL_UNS_ADMIN_PERM,
  10763. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10764. NL80211_FLAG_NEED_RTNL,
  10765. },
  10766. {
  10767. .cmd = NL80211_CMD_SET_NOACK_MAP,
  10768. .doit = nl80211_set_noack_map,
  10769. .policy = nl80211_policy,
  10770. .flags = GENL_UNS_ADMIN_PERM,
  10771. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10772. NL80211_FLAG_NEED_RTNL,
  10773. },
  10774. {
  10775. .cmd = NL80211_CMD_START_P2P_DEVICE,
  10776. .doit = nl80211_start_p2p_device,
  10777. .policy = nl80211_policy,
  10778. .flags = GENL_UNS_ADMIN_PERM,
  10779. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10780. NL80211_FLAG_NEED_RTNL,
  10781. },
  10782. {
  10783. .cmd = NL80211_CMD_STOP_P2P_DEVICE,
  10784. .doit = nl80211_stop_p2p_device,
  10785. .policy = nl80211_policy,
  10786. .flags = GENL_UNS_ADMIN_PERM,
  10787. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10788. NL80211_FLAG_NEED_RTNL,
  10789. },
  10790. {
  10791. .cmd = NL80211_CMD_START_NAN,
  10792. .doit = nl80211_start_nan,
  10793. .policy = nl80211_policy,
  10794. .flags = GENL_ADMIN_PERM,
  10795. .internal_flags = NL80211_FLAG_NEED_WDEV |
  10796. NL80211_FLAG_NEED_RTNL,
  10797. },
  10798. {
  10799. .cmd = NL80211_CMD_STOP_NAN,
  10800. .doit = nl80211_stop_nan,
  10801. .policy = nl80211_policy,
  10802. .flags = GENL_ADMIN_PERM,
  10803. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10804. NL80211_FLAG_NEED_RTNL,
  10805. },
  10806. {
  10807. .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
  10808. .doit = nl80211_nan_add_func,
  10809. .policy = nl80211_policy,
  10810. .flags = GENL_ADMIN_PERM,
  10811. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10812. NL80211_FLAG_NEED_RTNL,
  10813. },
  10814. {
  10815. .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
  10816. .doit = nl80211_nan_del_func,
  10817. .policy = nl80211_policy,
  10818. .flags = GENL_ADMIN_PERM,
  10819. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10820. NL80211_FLAG_NEED_RTNL,
  10821. },
  10822. {
  10823. .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
  10824. .doit = nl80211_nan_change_config,
  10825. .policy = nl80211_policy,
  10826. .flags = GENL_ADMIN_PERM,
  10827. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10828. NL80211_FLAG_NEED_RTNL,
  10829. },
  10830. {
  10831. .cmd = NL80211_CMD_SET_MCAST_RATE,
  10832. .doit = nl80211_set_mcast_rate,
  10833. .policy = nl80211_policy,
  10834. .flags = GENL_UNS_ADMIN_PERM,
  10835. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10836. NL80211_FLAG_NEED_RTNL,
  10837. },
  10838. {
  10839. .cmd = NL80211_CMD_SET_MAC_ACL,
  10840. .doit = nl80211_set_mac_acl,
  10841. .policy = nl80211_policy,
  10842. .flags = GENL_UNS_ADMIN_PERM,
  10843. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10844. NL80211_FLAG_NEED_RTNL,
  10845. },
  10846. {
  10847. .cmd = NL80211_CMD_RADAR_DETECT,
  10848. .doit = nl80211_start_radar_detection,
  10849. .policy = nl80211_policy,
  10850. .flags = GENL_UNS_ADMIN_PERM,
  10851. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10852. NL80211_FLAG_NEED_RTNL,
  10853. },
  10854. {
  10855. .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
  10856. .doit = nl80211_get_protocol_features,
  10857. .policy = nl80211_policy,
  10858. },
  10859. {
  10860. .cmd = NL80211_CMD_UPDATE_FT_IES,
  10861. .doit = nl80211_update_ft_ies,
  10862. .policy = nl80211_policy,
  10863. .flags = GENL_UNS_ADMIN_PERM,
  10864. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10865. NL80211_FLAG_NEED_RTNL,
  10866. },
  10867. {
  10868. .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
  10869. .doit = nl80211_crit_protocol_start,
  10870. .policy = nl80211_policy,
  10871. .flags = GENL_UNS_ADMIN_PERM,
  10872. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10873. NL80211_FLAG_NEED_RTNL,
  10874. },
  10875. {
  10876. .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
  10877. .doit = nl80211_crit_protocol_stop,
  10878. .policy = nl80211_policy,
  10879. .flags = GENL_UNS_ADMIN_PERM,
  10880. .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
  10881. NL80211_FLAG_NEED_RTNL,
  10882. },
  10883. {
  10884. .cmd = NL80211_CMD_GET_COALESCE,
  10885. .doit = nl80211_get_coalesce,
  10886. .policy = nl80211_policy,
  10887. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10888. NL80211_FLAG_NEED_RTNL,
  10889. },
  10890. {
  10891. .cmd = NL80211_CMD_SET_COALESCE,
  10892. .doit = nl80211_set_coalesce,
  10893. .policy = nl80211_policy,
  10894. .flags = GENL_UNS_ADMIN_PERM,
  10895. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10896. NL80211_FLAG_NEED_RTNL,
  10897. },
  10898. {
  10899. .cmd = NL80211_CMD_CHANNEL_SWITCH,
  10900. .doit = nl80211_channel_switch,
  10901. .policy = nl80211_policy,
  10902. .flags = GENL_UNS_ADMIN_PERM,
  10903. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10904. NL80211_FLAG_NEED_RTNL,
  10905. },
  10906. {
  10907. .cmd = NL80211_CMD_VENDOR,
  10908. .doit = nl80211_vendor_cmd,
  10909. .dumpit = nl80211_vendor_cmd_dump,
  10910. .policy = nl80211_policy,
  10911. .flags = GENL_UNS_ADMIN_PERM,
  10912. .internal_flags = NL80211_FLAG_NEED_WIPHY |
  10913. NL80211_FLAG_NEED_RTNL |
  10914. NL80211_FLAG_CLEAR_SKB,
  10915. },
  10916. {
  10917. .cmd = NL80211_CMD_SET_QOS_MAP,
  10918. .doit = nl80211_set_qos_map,
  10919. .policy = nl80211_policy,
  10920. .flags = GENL_UNS_ADMIN_PERM,
  10921. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10922. NL80211_FLAG_NEED_RTNL,
  10923. },
  10924. {
  10925. .cmd = NL80211_CMD_ADD_TX_TS,
  10926. .doit = nl80211_add_tx_ts,
  10927. .policy = nl80211_policy,
  10928. .flags = GENL_UNS_ADMIN_PERM,
  10929. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10930. NL80211_FLAG_NEED_RTNL,
  10931. },
  10932. {
  10933. .cmd = NL80211_CMD_DEL_TX_TS,
  10934. .doit = nl80211_del_tx_ts,
  10935. .policy = nl80211_policy,
  10936. .flags = GENL_UNS_ADMIN_PERM,
  10937. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10938. NL80211_FLAG_NEED_RTNL,
  10939. },
  10940. {
  10941. .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
  10942. .doit = nl80211_tdls_channel_switch,
  10943. .policy = nl80211_policy,
  10944. .flags = GENL_UNS_ADMIN_PERM,
  10945. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10946. NL80211_FLAG_NEED_RTNL,
  10947. },
  10948. {
  10949. .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
  10950. .doit = nl80211_tdls_cancel_channel_switch,
  10951. .policy = nl80211_policy,
  10952. .flags = GENL_UNS_ADMIN_PERM,
  10953. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10954. NL80211_FLAG_NEED_RTNL,
  10955. },
  10956. {
  10957. .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
  10958. .doit = nl80211_set_multicast_to_unicast,
  10959. .policy = nl80211_policy,
  10960. .flags = GENL_UNS_ADMIN_PERM,
  10961. .internal_flags = NL80211_FLAG_NEED_NETDEV |
  10962. NL80211_FLAG_NEED_RTNL,
  10963. },
  10964. {
  10965. .cmd = NL80211_CMD_EXTERNAL_AUTH,
  10966. .doit = nl80211_external_auth,
  10967. .policy = nl80211_policy,
  10968. .flags = GENL_ADMIN_PERM,
  10969. .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
  10970. NL80211_FLAG_NEED_RTNL,
  10971. },
  10972. };
  10973. /* notification functions */
  10974. void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
  10975. enum nl80211_commands cmd)
  10976. {
  10977. struct sk_buff *msg;
  10978. struct nl80211_dump_wiphy_state state = {};
  10979. WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
  10980. cmd != NL80211_CMD_DEL_WIPHY);
  10981. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10982. if (!msg)
  10983. return;
  10984. if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
  10985. nlmsg_free(msg);
  10986. return;
  10987. }
  10988. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  10989. NL80211_MCGRP_CONFIG, GFP_KERNEL);
  10990. }
  10991. void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
  10992. struct wireless_dev *wdev,
  10993. enum nl80211_commands cmd)
  10994. {
  10995. struct sk_buff *msg;
  10996. WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
  10997. cmd != NL80211_CMD_DEL_INTERFACE);
  10998. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  10999. if (!msg)
  11000. return;
  11001. if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
  11002. cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
  11003. nlmsg_free(msg);
  11004. return;
  11005. }
  11006. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11007. NL80211_MCGRP_CONFIG, GFP_KERNEL);
  11008. }
  11009. static int nl80211_add_scan_req(struct sk_buff *msg,
  11010. struct cfg80211_registered_device *rdev)
  11011. {
  11012. struct cfg80211_scan_request *req = rdev->scan_req;
  11013. struct nlattr *nest;
  11014. int i;
  11015. if (WARN_ON(!req))
  11016. return 0;
  11017. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
  11018. if (!nest)
  11019. goto nla_put_failure;
  11020. for (i = 0; i < req->n_ssids; i++) {
  11021. if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
  11022. goto nla_put_failure;
  11023. }
  11024. nla_nest_end(msg, nest);
  11025. nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
  11026. if (!nest)
  11027. goto nla_put_failure;
  11028. for (i = 0; i < req->n_channels; i++) {
  11029. if (nla_put_u32(msg, i, req->channels[i]->center_freq))
  11030. goto nla_put_failure;
  11031. }
  11032. nla_nest_end(msg, nest);
  11033. if (req->ie &&
  11034. nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
  11035. goto nla_put_failure;
  11036. if (req->flags &&
  11037. nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
  11038. goto nla_put_failure;
  11039. if (req->info.scan_start_tsf &&
  11040. (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
  11041. req->info.scan_start_tsf, NL80211_BSS_PAD) ||
  11042. nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
  11043. req->info.tsf_bssid)))
  11044. goto nla_put_failure;
  11045. return 0;
  11046. nla_put_failure:
  11047. return -ENOBUFS;
  11048. }
  11049. static int nl80211_send_scan_msg(struct sk_buff *msg,
  11050. struct cfg80211_registered_device *rdev,
  11051. struct wireless_dev *wdev,
  11052. u32 portid, u32 seq, int flags,
  11053. u32 cmd)
  11054. {
  11055. void *hdr;
  11056. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  11057. if (!hdr)
  11058. return -1;
  11059. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11060. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11061. wdev->netdev->ifindex)) ||
  11062. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11063. NL80211_ATTR_PAD))
  11064. goto nla_put_failure;
  11065. /* ignore errors and send incomplete event anyway */
  11066. nl80211_add_scan_req(msg, rdev);
  11067. genlmsg_end(msg, hdr);
  11068. return 0;
  11069. nla_put_failure:
  11070. genlmsg_cancel(msg, hdr);
  11071. return -EMSGSIZE;
  11072. }
  11073. static int
  11074. nl80211_send_sched_scan_msg(struct sk_buff *msg,
  11075. struct cfg80211_registered_device *rdev,
  11076. struct net_device *netdev,
  11077. u32 portid, u32 seq, int flags, u32 cmd)
  11078. {
  11079. void *hdr;
  11080. hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
  11081. if (!hdr)
  11082. return -1;
  11083. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11084. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  11085. goto nla_put_failure;
  11086. genlmsg_end(msg, hdr);
  11087. return 0;
  11088. nla_put_failure:
  11089. genlmsg_cancel(msg, hdr);
  11090. return -EMSGSIZE;
  11091. }
  11092. void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
  11093. struct wireless_dev *wdev)
  11094. {
  11095. struct sk_buff *msg;
  11096. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  11097. if (!msg)
  11098. return;
  11099. if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
  11100. NL80211_CMD_TRIGGER_SCAN) < 0) {
  11101. nlmsg_free(msg);
  11102. return;
  11103. }
  11104. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11105. NL80211_MCGRP_SCAN, GFP_KERNEL);
  11106. }
  11107. struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
  11108. struct wireless_dev *wdev, bool aborted)
  11109. {
  11110. struct sk_buff *msg;
  11111. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  11112. if (!msg)
  11113. return NULL;
  11114. if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
  11115. aborted ? NL80211_CMD_SCAN_ABORTED :
  11116. NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
  11117. nlmsg_free(msg);
  11118. return NULL;
  11119. }
  11120. return msg;
  11121. }
  11122. void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
  11123. struct sk_buff *msg)
  11124. {
  11125. if (!msg)
  11126. return;
  11127. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11128. NL80211_MCGRP_SCAN, GFP_KERNEL);
  11129. }
  11130. void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
  11131. struct net_device *netdev)
  11132. {
  11133. struct sk_buff *msg;
  11134. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  11135. if (!msg)
  11136. return;
  11137. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
  11138. NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
  11139. nlmsg_free(msg);
  11140. return;
  11141. }
  11142. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11143. NL80211_MCGRP_SCAN, GFP_KERNEL);
  11144. }
  11145. void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
  11146. struct net_device *netdev, u32 cmd)
  11147. {
  11148. struct sk_buff *msg;
  11149. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  11150. if (!msg)
  11151. return;
  11152. if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
  11153. nlmsg_free(msg);
  11154. return;
  11155. }
  11156. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11157. NL80211_MCGRP_SCAN, GFP_KERNEL);
  11158. }
  11159. static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
  11160. struct regulatory_request *request)
  11161. {
  11162. /* Userspace can always count this one always being set */
  11163. if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
  11164. goto nla_put_failure;
  11165. if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
  11166. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  11167. NL80211_REGDOM_TYPE_WORLD))
  11168. goto nla_put_failure;
  11169. } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
  11170. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  11171. NL80211_REGDOM_TYPE_CUSTOM_WORLD))
  11172. goto nla_put_failure;
  11173. } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
  11174. request->intersect) {
  11175. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  11176. NL80211_REGDOM_TYPE_INTERSECTION))
  11177. goto nla_put_failure;
  11178. } else {
  11179. if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
  11180. NL80211_REGDOM_TYPE_COUNTRY) ||
  11181. nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
  11182. request->alpha2))
  11183. goto nla_put_failure;
  11184. }
  11185. if (request->wiphy_idx != WIPHY_IDX_INVALID) {
  11186. struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
  11187. if (wiphy &&
  11188. nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
  11189. goto nla_put_failure;
  11190. if (wiphy &&
  11191. wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
  11192. nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
  11193. goto nla_put_failure;
  11194. }
  11195. return true;
  11196. nla_put_failure:
  11197. return false;
  11198. }
  11199. /*
  11200. * This can happen on global regulatory changes or device specific settings
  11201. * based on custom regulatory domains.
  11202. */
  11203. void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
  11204. struct regulatory_request *request)
  11205. {
  11206. struct sk_buff *msg;
  11207. void *hdr;
  11208. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  11209. if (!msg)
  11210. return;
  11211. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
  11212. if (!hdr) {
  11213. nlmsg_free(msg);
  11214. return;
  11215. }
  11216. if (nl80211_reg_change_event_fill(msg, request) == false)
  11217. goto nla_put_failure;
  11218. genlmsg_end(msg, hdr);
  11219. rcu_read_lock();
  11220. genlmsg_multicast_allns(&nl80211_fam, msg, 0,
  11221. NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
  11222. rcu_read_unlock();
  11223. return;
  11224. nla_put_failure:
  11225. genlmsg_cancel(msg, hdr);
  11226. nlmsg_free(msg);
  11227. }
  11228. static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
  11229. struct net_device *netdev,
  11230. const u8 *buf, size_t len,
  11231. enum nl80211_commands cmd, gfp_t gfp,
  11232. int uapsd_queues)
  11233. {
  11234. struct sk_buff *msg;
  11235. void *hdr;
  11236. msg = nlmsg_new(100 + len, gfp);
  11237. if (!msg)
  11238. return;
  11239. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  11240. if (!hdr) {
  11241. nlmsg_free(msg);
  11242. return;
  11243. }
  11244. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11245. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11246. nla_put(msg, NL80211_ATTR_FRAME, len, buf))
  11247. goto nla_put_failure;
  11248. if (uapsd_queues >= 0) {
  11249. struct nlattr *nla_wmm =
  11250. nla_nest_start(msg, NL80211_ATTR_STA_WME);
  11251. if (!nla_wmm)
  11252. goto nla_put_failure;
  11253. if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
  11254. uapsd_queues))
  11255. goto nla_put_failure;
  11256. nla_nest_end(msg, nla_wmm);
  11257. }
  11258. genlmsg_end(msg, hdr);
  11259. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11260. NL80211_MCGRP_MLME, gfp);
  11261. return;
  11262. nla_put_failure:
  11263. genlmsg_cancel(msg, hdr);
  11264. nlmsg_free(msg);
  11265. }
  11266. void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
  11267. struct net_device *netdev, const u8 *buf,
  11268. size_t len, gfp_t gfp)
  11269. {
  11270. nl80211_send_mlme_event(rdev, netdev, buf, len,
  11271. NL80211_CMD_AUTHENTICATE, gfp, -1);
  11272. }
  11273. void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
  11274. struct net_device *netdev, const u8 *buf,
  11275. size_t len, gfp_t gfp, int uapsd_queues)
  11276. {
  11277. nl80211_send_mlme_event(rdev, netdev, buf, len,
  11278. NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
  11279. }
  11280. void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
  11281. struct net_device *netdev, const u8 *buf,
  11282. size_t len, gfp_t gfp)
  11283. {
  11284. nl80211_send_mlme_event(rdev, netdev, buf, len,
  11285. NL80211_CMD_DEAUTHENTICATE, gfp, -1);
  11286. }
  11287. void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
  11288. struct net_device *netdev, const u8 *buf,
  11289. size_t len, gfp_t gfp)
  11290. {
  11291. nl80211_send_mlme_event(rdev, netdev, buf, len,
  11292. NL80211_CMD_DISASSOCIATE, gfp, -1);
  11293. }
  11294. void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
  11295. size_t len)
  11296. {
  11297. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11298. struct wiphy *wiphy = wdev->wiphy;
  11299. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11300. const struct ieee80211_mgmt *mgmt = (void *)buf;
  11301. u32 cmd;
  11302. if (WARN_ON(len < 2))
  11303. return;
  11304. if (ieee80211_is_deauth(mgmt->frame_control))
  11305. cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
  11306. else
  11307. cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
  11308. trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
  11309. nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
  11310. }
  11311. EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
  11312. static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
  11313. struct net_device *netdev, int cmd,
  11314. const u8 *addr, gfp_t gfp)
  11315. {
  11316. struct sk_buff *msg;
  11317. void *hdr;
  11318. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11319. if (!msg)
  11320. return;
  11321. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  11322. if (!hdr) {
  11323. nlmsg_free(msg);
  11324. return;
  11325. }
  11326. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11327. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11328. nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
  11329. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  11330. goto nla_put_failure;
  11331. genlmsg_end(msg, hdr);
  11332. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11333. NL80211_MCGRP_MLME, gfp);
  11334. return;
  11335. nla_put_failure:
  11336. genlmsg_cancel(msg, hdr);
  11337. nlmsg_free(msg);
  11338. }
  11339. void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
  11340. struct net_device *netdev, const u8 *addr,
  11341. gfp_t gfp)
  11342. {
  11343. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
  11344. addr, gfp);
  11345. }
  11346. void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
  11347. struct net_device *netdev, const u8 *addr,
  11348. gfp_t gfp)
  11349. {
  11350. nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
  11351. addr, gfp);
  11352. }
  11353. void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
  11354. struct net_device *netdev,
  11355. struct cfg80211_connect_resp_params *cr,
  11356. gfp_t gfp)
  11357. {
  11358. struct sk_buff *msg;
  11359. void *hdr;
  11360. msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
  11361. cr->fils_kek_len + cr->pmk_len +
  11362. (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp);
  11363. if (!msg)
  11364. return;
  11365. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
  11366. if (!hdr) {
  11367. nlmsg_free(msg);
  11368. return;
  11369. }
  11370. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11371. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11372. (cr->bssid &&
  11373. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
  11374. nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
  11375. cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
  11376. cr->status) ||
  11377. (cr->status < 0 &&
  11378. (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
  11379. nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
  11380. cr->timeout_reason))) ||
  11381. (cr->req_ie &&
  11382. nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
  11383. (cr->resp_ie &&
  11384. nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
  11385. cr->resp_ie)) ||
  11386. (cr->update_erp_next_seq_num &&
  11387. nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
  11388. cr->fils_erp_next_seq_num)) ||
  11389. (cr->status == WLAN_STATUS_SUCCESS &&
  11390. ((cr->fils_kek &&
  11391. nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len,
  11392. cr->fils_kek)) ||
  11393. (cr->pmk &&
  11394. nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) ||
  11395. (cr->pmkid &&
  11396. nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid)))))
  11397. goto nla_put_failure;
  11398. genlmsg_end(msg, hdr);
  11399. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11400. NL80211_MCGRP_MLME, gfp);
  11401. return;
  11402. nla_put_failure:
  11403. genlmsg_cancel(msg, hdr);
  11404. nlmsg_free(msg);
  11405. }
  11406. void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
  11407. struct net_device *netdev,
  11408. struct cfg80211_roam_info *info, gfp_t gfp)
  11409. {
  11410. struct sk_buff *msg;
  11411. void *hdr;
  11412. const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
  11413. msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp);
  11414. if (!msg)
  11415. return;
  11416. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
  11417. if (!hdr) {
  11418. nlmsg_free(msg);
  11419. return;
  11420. }
  11421. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11422. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11423. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
  11424. (info->req_ie &&
  11425. nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
  11426. info->req_ie)) ||
  11427. (info->resp_ie &&
  11428. nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
  11429. info->resp_ie)) ||
  11430. (info->authorized &&
  11431. nla_put_flag(msg, NL80211_ATTR_PORT_AUTHORIZED)))
  11432. goto nla_put_failure;
  11433. genlmsg_end(msg, hdr);
  11434. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11435. NL80211_MCGRP_MLME, gfp);
  11436. return;
  11437. nla_put_failure:
  11438. genlmsg_cancel(msg, hdr);
  11439. nlmsg_free(msg);
  11440. }
  11441. void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
  11442. struct net_device *netdev, u16 reason,
  11443. const u8 *ie, size_t ie_len, bool from_ap)
  11444. {
  11445. struct sk_buff *msg;
  11446. void *hdr;
  11447. msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
  11448. if (!msg)
  11449. return;
  11450. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
  11451. if (!hdr) {
  11452. nlmsg_free(msg);
  11453. return;
  11454. }
  11455. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11456. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11457. (from_ap && reason &&
  11458. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
  11459. (from_ap &&
  11460. nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
  11461. (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
  11462. goto nla_put_failure;
  11463. genlmsg_end(msg, hdr);
  11464. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11465. NL80211_MCGRP_MLME, GFP_KERNEL);
  11466. return;
  11467. nla_put_failure:
  11468. genlmsg_cancel(msg, hdr);
  11469. nlmsg_free(msg);
  11470. }
  11471. void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
  11472. struct net_device *netdev, const u8 *bssid,
  11473. gfp_t gfp)
  11474. {
  11475. struct sk_buff *msg;
  11476. void *hdr;
  11477. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11478. if (!msg)
  11479. return;
  11480. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
  11481. if (!hdr) {
  11482. nlmsg_free(msg);
  11483. return;
  11484. }
  11485. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11486. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11487. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
  11488. goto nla_put_failure;
  11489. genlmsg_end(msg, hdr);
  11490. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11491. NL80211_MCGRP_MLME, gfp);
  11492. return;
  11493. nla_put_failure:
  11494. genlmsg_cancel(msg, hdr);
  11495. nlmsg_free(msg);
  11496. }
  11497. void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
  11498. const u8* ie, u8 ie_len, gfp_t gfp)
  11499. {
  11500. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11501. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11502. struct sk_buff *msg;
  11503. void *hdr;
  11504. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
  11505. return;
  11506. trace_cfg80211_notify_new_peer_candidate(dev, addr);
  11507. msg = nlmsg_new(100 + ie_len, gfp);
  11508. if (!msg)
  11509. return;
  11510. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
  11511. if (!hdr) {
  11512. nlmsg_free(msg);
  11513. return;
  11514. }
  11515. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11516. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11517. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  11518. (ie_len && ie &&
  11519. nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
  11520. goto nla_put_failure;
  11521. genlmsg_end(msg, hdr);
  11522. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11523. NL80211_MCGRP_MLME, gfp);
  11524. return;
  11525. nla_put_failure:
  11526. genlmsg_cancel(msg, hdr);
  11527. nlmsg_free(msg);
  11528. }
  11529. EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
  11530. void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
  11531. struct net_device *netdev, const u8 *addr,
  11532. enum nl80211_key_type key_type, int key_id,
  11533. const u8 *tsc, gfp_t gfp)
  11534. {
  11535. struct sk_buff *msg;
  11536. void *hdr;
  11537. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11538. if (!msg)
  11539. return;
  11540. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
  11541. if (!hdr) {
  11542. nlmsg_free(msg);
  11543. return;
  11544. }
  11545. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11546. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  11547. (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
  11548. nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
  11549. (key_id != -1 &&
  11550. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
  11551. (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
  11552. goto nla_put_failure;
  11553. genlmsg_end(msg, hdr);
  11554. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11555. NL80211_MCGRP_MLME, gfp);
  11556. return;
  11557. nla_put_failure:
  11558. genlmsg_cancel(msg, hdr);
  11559. nlmsg_free(msg);
  11560. }
  11561. void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
  11562. struct ieee80211_channel *channel_before,
  11563. struct ieee80211_channel *channel_after)
  11564. {
  11565. struct sk_buff *msg;
  11566. void *hdr;
  11567. struct nlattr *nl_freq;
  11568. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  11569. if (!msg)
  11570. return;
  11571. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
  11572. if (!hdr) {
  11573. nlmsg_free(msg);
  11574. return;
  11575. }
  11576. /*
  11577. * Since we are applying the beacon hint to a wiphy we know its
  11578. * wiphy_idx is valid
  11579. */
  11580. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
  11581. goto nla_put_failure;
  11582. /* Before */
  11583. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
  11584. if (!nl_freq)
  11585. goto nla_put_failure;
  11586. if (nl80211_msg_put_channel(msg, channel_before, false))
  11587. goto nla_put_failure;
  11588. nla_nest_end(msg, nl_freq);
  11589. /* After */
  11590. nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
  11591. if (!nl_freq)
  11592. goto nla_put_failure;
  11593. if (nl80211_msg_put_channel(msg, channel_after, false))
  11594. goto nla_put_failure;
  11595. nla_nest_end(msg, nl_freq);
  11596. genlmsg_end(msg, hdr);
  11597. rcu_read_lock();
  11598. genlmsg_multicast_allns(&nl80211_fam, msg, 0,
  11599. NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
  11600. rcu_read_unlock();
  11601. return;
  11602. nla_put_failure:
  11603. genlmsg_cancel(msg, hdr);
  11604. nlmsg_free(msg);
  11605. }
  11606. static void nl80211_send_remain_on_chan_event(
  11607. int cmd, struct cfg80211_registered_device *rdev,
  11608. struct wireless_dev *wdev, u64 cookie,
  11609. struct ieee80211_channel *chan,
  11610. unsigned int duration, gfp_t gfp)
  11611. {
  11612. struct sk_buff *msg;
  11613. void *hdr;
  11614. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11615. if (!msg)
  11616. return;
  11617. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  11618. if (!hdr) {
  11619. nlmsg_free(msg);
  11620. return;
  11621. }
  11622. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11623. (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11624. wdev->netdev->ifindex)) ||
  11625. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11626. NL80211_ATTR_PAD) ||
  11627. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
  11628. nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
  11629. NL80211_CHAN_NO_HT) ||
  11630. nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  11631. NL80211_ATTR_PAD))
  11632. goto nla_put_failure;
  11633. if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
  11634. nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
  11635. goto nla_put_failure;
  11636. genlmsg_end(msg, hdr);
  11637. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11638. NL80211_MCGRP_MLME, gfp);
  11639. return;
  11640. nla_put_failure:
  11641. genlmsg_cancel(msg, hdr);
  11642. nlmsg_free(msg);
  11643. }
  11644. void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
  11645. struct ieee80211_channel *chan,
  11646. unsigned int duration, gfp_t gfp)
  11647. {
  11648. struct wiphy *wiphy = wdev->wiphy;
  11649. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11650. trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
  11651. nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
  11652. rdev, wdev, cookie, chan,
  11653. duration, gfp);
  11654. }
  11655. EXPORT_SYMBOL(cfg80211_ready_on_channel);
  11656. void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
  11657. struct ieee80211_channel *chan,
  11658. gfp_t gfp)
  11659. {
  11660. struct wiphy *wiphy = wdev->wiphy;
  11661. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11662. trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
  11663. nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
  11664. rdev, wdev, cookie, chan, 0, gfp);
  11665. }
  11666. EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
  11667. void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
  11668. struct station_info *sinfo, gfp_t gfp)
  11669. {
  11670. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  11671. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11672. struct sk_buff *msg;
  11673. trace_cfg80211_new_sta(dev, mac_addr, sinfo);
  11674. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11675. if (!msg)
  11676. return;
  11677. if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
  11678. rdev, dev, mac_addr, sinfo) < 0) {
  11679. nlmsg_free(msg);
  11680. return;
  11681. }
  11682. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11683. NL80211_MCGRP_MLME, gfp);
  11684. }
  11685. EXPORT_SYMBOL(cfg80211_new_sta);
  11686. void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
  11687. struct station_info *sinfo, gfp_t gfp)
  11688. {
  11689. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  11690. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11691. struct sk_buff *msg;
  11692. struct station_info empty_sinfo = {};
  11693. if (!sinfo)
  11694. sinfo = &empty_sinfo;
  11695. trace_cfg80211_del_sta(dev, mac_addr);
  11696. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11697. if (!msg)
  11698. return;
  11699. if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
  11700. rdev, dev, mac_addr, sinfo) < 0) {
  11701. nlmsg_free(msg);
  11702. return;
  11703. }
  11704. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11705. NL80211_MCGRP_MLME, gfp);
  11706. }
  11707. EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
  11708. void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
  11709. enum nl80211_connect_failed_reason reason,
  11710. gfp_t gfp)
  11711. {
  11712. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  11713. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11714. struct sk_buff *msg;
  11715. void *hdr;
  11716. msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
  11717. if (!msg)
  11718. return;
  11719. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
  11720. if (!hdr) {
  11721. nlmsg_free(msg);
  11722. return;
  11723. }
  11724. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11725. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
  11726. nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
  11727. goto nla_put_failure;
  11728. genlmsg_end(msg, hdr);
  11729. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11730. NL80211_MCGRP_MLME, gfp);
  11731. return;
  11732. nla_put_failure:
  11733. genlmsg_cancel(msg, hdr);
  11734. nlmsg_free(msg);
  11735. }
  11736. EXPORT_SYMBOL(cfg80211_conn_failed);
  11737. static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
  11738. const u8 *addr, gfp_t gfp)
  11739. {
  11740. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11741. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11742. struct sk_buff *msg;
  11743. void *hdr;
  11744. u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
  11745. if (!nlportid)
  11746. return false;
  11747. msg = nlmsg_new(100, gfp);
  11748. if (!msg)
  11749. return true;
  11750. hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
  11751. if (!hdr) {
  11752. nlmsg_free(msg);
  11753. return true;
  11754. }
  11755. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11756. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  11757. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  11758. goto nla_put_failure;
  11759. genlmsg_end(msg, hdr);
  11760. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  11761. return true;
  11762. nla_put_failure:
  11763. genlmsg_cancel(msg, hdr);
  11764. nlmsg_free(msg);
  11765. return true;
  11766. }
  11767. bool cfg80211_rx_spurious_frame(struct net_device *dev,
  11768. const u8 *addr, gfp_t gfp)
  11769. {
  11770. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11771. bool ret;
  11772. trace_cfg80211_rx_spurious_frame(dev, addr);
  11773. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  11774. wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
  11775. trace_cfg80211_return_bool(false);
  11776. return false;
  11777. }
  11778. ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
  11779. addr, gfp);
  11780. trace_cfg80211_return_bool(ret);
  11781. return ret;
  11782. }
  11783. EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
  11784. bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
  11785. const u8 *addr, gfp_t gfp)
  11786. {
  11787. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11788. bool ret;
  11789. trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
  11790. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
  11791. wdev->iftype != NL80211_IFTYPE_P2P_GO &&
  11792. wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
  11793. trace_cfg80211_return_bool(false);
  11794. return false;
  11795. }
  11796. ret = __nl80211_unexpected_frame(dev,
  11797. NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
  11798. addr, gfp);
  11799. trace_cfg80211_return_bool(ret);
  11800. return ret;
  11801. }
  11802. EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
  11803. int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
  11804. struct wireless_dev *wdev, u32 nlportid,
  11805. int freq, int sig_dbm,
  11806. const u8 *buf, size_t len, u32 flags, gfp_t gfp)
  11807. {
  11808. struct net_device *netdev = wdev->netdev;
  11809. struct sk_buff *msg;
  11810. void *hdr;
  11811. msg = nlmsg_new(100 + len, gfp);
  11812. if (!msg)
  11813. return -ENOMEM;
  11814. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  11815. if (!hdr) {
  11816. nlmsg_free(msg);
  11817. return -ENOMEM;
  11818. }
  11819. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11820. (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11821. netdev->ifindex)) ||
  11822. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11823. NL80211_ATTR_PAD) ||
  11824. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
  11825. (sig_dbm &&
  11826. nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
  11827. nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
  11828. (flags &&
  11829. nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
  11830. goto nla_put_failure;
  11831. genlmsg_end(msg, hdr);
  11832. return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  11833. nla_put_failure:
  11834. genlmsg_cancel(msg, hdr);
  11835. nlmsg_free(msg);
  11836. return -ENOBUFS;
  11837. }
  11838. void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
  11839. const u8 *buf, size_t len, bool ack, gfp_t gfp)
  11840. {
  11841. struct wiphy *wiphy = wdev->wiphy;
  11842. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  11843. struct net_device *netdev = wdev->netdev;
  11844. struct sk_buff *msg;
  11845. void *hdr;
  11846. trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
  11847. msg = nlmsg_new(100 + len, gfp);
  11848. if (!msg)
  11849. return;
  11850. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
  11851. if (!hdr) {
  11852. nlmsg_free(msg);
  11853. return;
  11854. }
  11855. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11856. (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  11857. netdev->ifindex)) ||
  11858. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  11859. NL80211_ATTR_PAD) ||
  11860. nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
  11861. nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  11862. NL80211_ATTR_PAD) ||
  11863. (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
  11864. goto nla_put_failure;
  11865. genlmsg_end(msg, hdr);
  11866. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11867. NL80211_MCGRP_MLME, gfp);
  11868. return;
  11869. nla_put_failure:
  11870. genlmsg_cancel(msg, hdr);
  11871. nlmsg_free(msg);
  11872. }
  11873. EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
  11874. static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
  11875. const char *mac, gfp_t gfp)
  11876. {
  11877. struct wireless_dev *wdev = dev->ieee80211_ptr;
  11878. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  11879. struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11880. void **cb;
  11881. if (!msg)
  11882. return NULL;
  11883. cb = (void **)msg->cb;
  11884. cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
  11885. if (!cb[0]) {
  11886. nlmsg_free(msg);
  11887. return NULL;
  11888. }
  11889. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  11890. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
  11891. goto nla_put_failure;
  11892. if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
  11893. goto nla_put_failure;
  11894. cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
  11895. if (!cb[1])
  11896. goto nla_put_failure;
  11897. cb[2] = rdev;
  11898. return msg;
  11899. nla_put_failure:
  11900. nlmsg_free(msg);
  11901. return NULL;
  11902. }
  11903. static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
  11904. {
  11905. void **cb = (void **)msg->cb;
  11906. struct cfg80211_registered_device *rdev = cb[2];
  11907. nla_nest_end(msg, cb[1]);
  11908. genlmsg_end(msg, cb[0]);
  11909. memset(msg->cb, 0, sizeof(msg->cb));
  11910. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  11911. NL80211_MCGRP_MLME, gfp);
  11912. }
  11913. void cfg80211_cqm_rssi_notify(struct net_device *dev,
  11914. enum nl80211_cqm_rssi_threshold_event rssi_event,
  11915. gfp_t gfp)
  11916. {
  11917. struct sk_buff *msg;
  11918. trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
  11919. if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
  11920. rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
  11921. return;
  11922. msg = cfg80211_prepare_cqm(dev, NULL, gfp);
  11923. if (!msg)
  11924. return;
  11925. if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
  11926. rssi_event))
  11927. goto nla_put_failure;
  11928. cfg80211_send_cqm(msg, gfp);
  11929. return;
  11930. nla_put_failure:
  11931. nlmsg_free(msg);
  11932. }
  11933. EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
  11934. void cfg80211_cqm_txe_notify(struct net_device *dev,
  11935. const u8 *peer, u32 num_packets,
  11936. u32 rate, u32 intvl, gfp_t gfp)
  11937. {
  11938. struct sk_buff *msg;
  11939. msg = cfg80211_prepare_cqm(dev, peer, gfp);
  11940. if (!msg)
  11941. return;
  11942. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
  11943. goto nla_put_failure;
  11944. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
  11945. goto nla_put_failure;
  11946. if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
  11947. goto nla_put_failure;
  11948. cfg80211_send_cqm(msg, gfp);
  11949. return;
  11950. nla_put_failure:
  11951. nlmsg_free(msg);
  11952. }
  11953. EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
  11954. void cfg80211_cqm_pktloss_notify(struct net_device *dev,
  11955. const u8 *peer, u32 num_packets, gfp_t gfp)
  11956. {
  11957. struct sk_buff *msg;
  11958. trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
  11959. msg = cfg80211_prepare_cqm(dev, peer, gfp);
  11960. if (!msg)
  11961. return;
  11962. if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
  11963. goto nla_put_failure;
  11964. cfg80211_send_cqm(msg, gfp);
  11965. return;
  11966. nla_put_failure:
  11967. nlmsg_free(msg);
  11968. }
  11969. EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
  11970. void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
  11971. {
  11972. struct sk_buff *msg;
  11973. msg = cfg80211_prepare_cqm(dev, NULL, gfp);
  11974. if (!msg)
  11975. return;
  11976. if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
  11977. goto nla_put_failure;
  11978. cfg80211_send_cqm(msg, gfp);
  11979. return;
  11980. nla_put_failure:
  11981. nlmsg_free(msg);
  11982. }
  11983. EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
  11984. static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
  11985. struct net_device *netdev, const u8 *bssid,
  11986. const u8 *replay_ctr, gfp_t gfp)
  11987. {
  11988. struct sk_buff *msg;
  11989. struct nlattr *rekey_attr;
  11990. void *hdr;
  11991. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  11992. if (!msg)
  11993. return;
  11994. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
  11995. if (!hdr) {
  11996. nlmsg_free(msg);
  11997. return;
  11998. }
  11999. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12000. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  12001. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
  12002. goto nla_put_failure;
  12003. rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
  12004. if (!rekey_attr)
  12005. goto nla_put_failure;
  12006. if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
  12007. NL80211_REPLAY_CTR_LEN, replay_ctr))
  12008. goto nla_put_failure;
  12009. nla_nest_end(msg, rekey_attr);
  12010. genlmsg_end(msg, hdr);
  12011. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12012. NL80211_MCGRP_MLME, gfp);
  12013. return;
  12014. nla_put_failure:
  12015. genlmsg_cancel(msg, hdr);
  12016. nlmsg_free(msg);
  12017. }
  12018. void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
  12019. const u8 *replay_ctr, gfp_t gfp)
  12020. {
  12021. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12022. struct wiphy *wiphy = wdev->wiphy;
  12023. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12024. trace_cfg80211_gtk_rekey_notify(dev, bssid);
  12025. nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
  12026. }
  12027. EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
  12028. static void
  12029. nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
  12030. struct net_device *netdev, int index,
  12031. const u8 *bssid, bool preauth, gfp_t gfp)
  12032. {
  12033. struct sk_buff *msg;
  12034. struct nlattr *attr;
  12035. void *hdr;
  12036. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12037. if (!msg)
  12038. return;
  12039. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
  12040. if (!hdr) {
  12041. nlmsg_free(msg);
  12042. return;
  12043. }
  12044. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12045. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  12046. goto nla_put_failure;
  12047. attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
  12048. if (!attr)
  12049. goto nla_put_failure;
  12050. if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
  12051. nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
  12052. (preauth &&
  12053. nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
  12054. goto nla_put_failure;
  12055. nla_nest_end(msg, attr);
  12056. genlmsg_end(msg, hdr);
  12057. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12058. NL80211_MCGRP_MLME, gfp);
  12059. return;
  12060. nla_put_failure:
  12061. genlmsg_cancel(msg, hdr);
  12062. nlmsg_free(msg);
  12063. }
  12064. void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
  12065. const u8 *bssid, bool preauth, gfp_t gfp)
  12066. {
  12067. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12068. struct wiphy *wiphy = wdev->wiphy;
  12069. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12070. trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
  12071. nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
  12072. }
  12073. EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
  12074. static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
  12075. struct net_device *netdev,
  12076. struct cfg80211_chan_def *chandef,
  12077. gfp_t gfp,
  12078. enum nl80211_commands notif,
  12079. u8 count)
  12080. {
  12081. struct sk_buff *msg;
  12082. void *hdr;
  12083. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12084. if (!msg)
  12085. return;
  12086. hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
  12087. if (!hdr) {
  12088. nlmsg_free(msg);
  12089. return;
  12090. }
  12091. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
  12092. goto nla_put_failure;
  12093. if (nl80211_send_chandef(msg, chandef))
  12094. goto nla_put_failure;
  12095. if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
  12096. (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
  12097. goto nla_put_failure;
  12098. genlmsg_end(msg, hdr);
  12099. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12100. NL80211_MCGRP_MLME, gfp);
  12101. return;
  12102. nla_put_failure:
  12103. genlmsg_cancel(msg, hdr);
  12104. nlmsg_free(msg);
  12105. }
  12106. void cfg80211_ch_switch_notify(struct net_device *dev,
  12107. struct cfg80211_chan_def *chandef)
  12108. {
  12109. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12110. struct wiphy *wiphy = wdev->wiphy;
  12111. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12112. ASSERT_WDEV_LOCK(wdev);
  12113. trace_cfg80211_ch_switch_notify(dev, chandef);
  12114. wdev->chandef = *chandef;
  12115. wdev->preset_chandef = *chandef;
  12116. if (wdev->iftype == NL80211_IFTYPE_STATION &&
  12117. !WARN_ON(!wdev->current_bss))
  12118. wdev->current_bss->pub.channel = chandef->chan;
  12119. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
  12120. NL80211_CMD_CH_SWITCH_NOTIFY, 0);
  12121. }
  12122. EXPORT_SYMBOL(cfg80211_ch_switch_notify);
  12123. void cfg80211_ch_switch_started_notify(struct net_device *dev,
  12124. struct cfg80211_chan_def *chandef,
  12125. u8 count)
  12126. {
  12127. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12128. struct wiphy *wiphy = wdev->wiphy;
  12129. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12130. trace_cfg80211_ch_switch_started_notify(dev, chandef);
  12131. nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
  12132. NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
  12133. }
  12134. EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
  12135. void
  12136. nl80211_radar_notify(struct cfg80211_registered_device *rdev,
  12137. const struct cfg80211_chan_def *chandef,
  12138. enum nl80211_radar_event event,
  12139. struct net_device *netdev, gfp_t gfp)
  12140. {
  12141. struct sk_buff *msg;
  12142. void *hdr;
  12143. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12144. if (!msg)
  12145. return;
  12146. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
  12147. if (!hdr) {
  12148. nlmsg_free(msg);
  12149. return;
  12150. }
  12151. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
  12152. goto nla_put_failure;
  12153. /* NOP and radar events don't need a netdev parameter */
  12154. if (netdev) {
  12155. struct wireless_dev *wdev = netdev->ieee80211_ptr;
  12156. if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  12157. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  12158. NL80211_ATTR_PAD))
  12159. goto nla_put_failure;
  12160. }
  12161. if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
  12162. goto nla_put_failure;
  12163. if (nl80211_send_chandef(msg, chandef))
  12164. goto nla_put_failure;
  12165. genlmsg_end(msg, hdr);
  12166. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12167. NL80211_MCGRP_MLME, gfp);
  12168. return;
  12169. nla_put_failure:
  12170. genlmsg_cancel(msg, hdr);
  12171. nlmsg_free(msg);
  12172. }
  12173. void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  12174. u64 cookie, bool acked, gfp_t gfp)
  12175. {
  12176. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12177. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  12178. struct sk_buff *msg;
  12179. void *hdr;
  12180. trace_cfg80211_probe_status(dev, addr, cookie, acked);
  12181. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12182. if (!msg)
  12183. return;
  12184. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
  12185. if (!hdr) {
  12186. nlmsg_free(msg);
  12187. return;
  12188. }
  12189. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12190. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  12191. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  12192. nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
  12193. NL80211_ATTR_PAD) ||
  12194. (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
  12195. goto nla_put_failure;
  12196. genlmsg_end(msg, hdr);
  12197. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12198. NL80211_MCGRP_MLME, gfp);
  12199. return;
  12200. nla_put_failure:
  12201. genlmsg_cancel(msg, hdr);
  12202. nlmsg_free(msg);
  12203. }
  12204. EXPORT_SYMBOL(cfg80211_probe_status);
  12205. void cfg80211_report_obss_beacon(struct wiphy *wiphy,
  12206. const u8 *frame, size_t len,
  12207. int freq, int sig_dbm)
  12208. {
  12209. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12210. struct sk_buff *msg;
  12211. void *hdr;
  12212. struct cfg80211_beacon_registration *reg;
  12213. trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
  12214. spin_lock_bh(&rdev->beacon_registrations_lock);
  12215. list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  12216. msg = nlmsg_new(len + 100, GFP_ATOMIC);
  12217. if (!msg) {
  12218. spin_unlock_bh(&rdev->beacon_registrations_lock);
  12219. return;
  12220. }
  12221. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
  12222. if (!hdr)
  12223. goto nla_put_failure;
  12224. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12225. (freq &&
  12226. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
  12227. (sig_dbm &&
  12228. nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
  12229. nla_put(msg, NL80211_ATTR_FRAME, len, frame))
  12230. goto nla_put_failure;
  12231. genlmsg_end(msg, hdr);
  12232. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
  12233. }
  12234. spin_unlock_bh(&rdev->beacon_registrations_lock);
  12235. return;
  12236. nla_put_failure:
  12237. spin_unlock_bh(&rdev->beacon_registrations_lock);
  12238. if (hdr)
  12239. genlmsg_cancel(msg, hdr);
  12240. nlmsg_free(msg);
  12241. }
  12242. EXPORT_SYMBOL(cfg80211_report_obss_beacon);
  12243. #ifdef CONFIG_PM
  12244. static int cfg80211_net_detect_results(struct sk_buff *msg,
  12245. struct cfg80211_wowlan_wakeup *wakeup)
  12246. {
  12247. struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
  12248. struct nlattr *nl_results, *nl_match, *nl_freqs;
  12249. int i, j;
  12250. nl_results = nla_nest_start(
  12251. msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
  12252. if (!nl_results)
  12253. return -EMSGSIZE;
  12254. for (i = 0; i < nd->n_matches; i++) {
  12255. struct cfg80211_wowlan_nd_match *match = nd->matches[i];
  12256. nl_match = nla_nest_start(msg, i);
  12257. if (!nl_match)
  12258. break;
  12259. /* The SSID attribute is optional in nl80211, but for
  12260. * simplicity reasons it's always present in the
  12261. * cfg80211 structure. If a driver can't pass the
  12262. * SSID, that needs to be changed. A zero length SSID
  12263. * is still a valid SSID (wildcard), so it cannot be
  12264. * used for this purpose.
  12265. */
  12266. if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
  12267. match->ssid.ssid)) {
  12268. nla_nest_cancel(msg, nl_match);
  12269. goto out;
  12270. }
  12271. if (match->n_channels) {
  12272. nl_freqs = nla_nest_start(
  12273. msg, NL80211_ATTR_SCAN_FREQUENCIES);
  12274. if (!nl_freqs) {
  12275. nla_nest_cancel(msg, nl_match);
  12276. goto out;
  12277. }
  12278. for (j = 0; j < match->n_channels; j++) {
  12279. if (nla_put_u32(msg, j, match->channels[j])) {
  12280. nla_nest_cancel(msg, nl_freqs);
  12281. nla_nest_cancel(msg, nl_match);
  12282. goto out;
  12283. }
  12284. }
  12285. nla_nest_end(msg, nl_freqs);
  12286. }
  12287. nla_nest_end(msg, nl_match);
  12288. }
  12289. out:
  12290. nla_nest_end(msg, nl_results);
  12291. return 0;
  12292. }
  12293. void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
  12294. struct cfg80211_wowlan_wakeup *wakeup,
  12295. gfp_t gfp)
  12296. {
  12297. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  12298. struct sk_buff *msg;
  12299. void *hdr;
  12300. int size = 200;
  12301. trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
  12302. if (wakeup)
  12303. size += wakeup->packet_present_len;
  12304. msg = nlmsg_new(size, gfp);
  12305. if (!msg)
  12306. return;
  12307. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
  12308. if (!hdr)
  12309. goto free_msg;
  12310. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12311. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  12312. NL80211_ATTR_PAD))
  12313. goto free_msg;
  12314. if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
  12315. wdev->netdev->ifindex))
  12316. goto free_msg;
  12317. if (wakeup) {
  12318. struct nlattr *reasons;
  12319. reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
  12320. if (!reasons)
  12321. goto free_msg;
  12322. if (wakeup->disconnect &&
  12323. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
  12324. goto free_msg;
  12325. if (wakeup->magic_pkt &&
  12326. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
  12327. goto free_msg;
  12328. if (wakeup->gtk_rekey_failure &&
  12329. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
  12330. goto free_msg;
  12331. if (wakeup->eap_identity_req &&
  12332. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
  12333. goto free_msg;
  12334. if (wakeup->four_way_handshake &&
  12335. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
  12336. goto free_msg;
  12337. if (wakeup->rfkill_release &&
  12338. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
  12339. goto free_msg;
  12340. if (wakeup->pattern_idx >= 0 &&
  12341. nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
  12342. wakeup->pattern_idx))
  12343. goto free_msg;
  12344. if (wakeup->tcp_match &&
  12345. nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
  12346. goto free_msg;
  12347. if (wakeup->tcp_connlost &&
  12348. nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
  12349. goto free_msg;
  12350. if (wakeup->tcp_nomoretokens &&
  12351. nla_put_flag(msg,
  12352. NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
  12353. goto free_msg;
  12354. if (wakeup->packet) {
  12355. u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
  12356. u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
  12357. if (!wakeup->packet_80211) {
  12358. pkt_attr =
  12359. NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
  12360. len_attr =
  12361. NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
  12362. }
  12363. if (wakeup->packet_len &&
  12364. nla_put_u32(msg, len_attr, wakeup->packet_len))
  12365. goto free_msg;
  12366. if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
  12367. wakeup->packet))
  12368. goto free_msg;
  12369. }
  12370. if (wakeup->net_detect &&
  12371. cfg80211_net_detect_results(msg, wakeup))
  12372. goto free_msg;
  12373. nla_nest_end(msg, reasons);
  12374. }
  12375. genlmsg_end(msg, hdr);
  12376. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12377. NL80211_MCGRP_MLME, gfp);
  12378. return;
  12379. free_msg:
  12380. nlmsg_free(msg);
  12381. }
  12382. EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
  12383. #endif
  12384. void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
  12385. enum nl80211_tdls_operation oper,
  12386. u16 reason_code, gfp_t gfp)
  12387. {
  12388. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12389. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  12390. struct sk_buff *msg;
  12391. void *hdr;
  12392. trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
  12393. reason_code);
  12394. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12395. if (!msg)
  12396. return;
  12397. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
  12398. if (!hdr) {
  12399. nlmsg_free(msg);
  12400. return;
  12401. }
  12402. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12403. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  12404. nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
  12405. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
  12406. (reason_code > 0 &&
  12407. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
  12408. goto nla_put_failure;
  12409. genlmsg_end(msg, hdr);
  12410. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12411. NL80211_MCGRP_MLME, gfp);
  12412. return;
  12413. nla_put_failure:
  12414. genlmsg_cancel(msg, hdr);
  12415. nlmsg_free(msg);
  12416. }
  12417. EXPORT_SYMBOL(cfg80211_tdls_oper_request);
  12418. static int nl80211_netlink_notify(struct notifier_block * nb,
  12419. unsigned long state,
  12420. void *_notify)
  12421. {
  12422. struct netlink_notify *notify = _notify;
  12423. struct cfg80211_registered_device *rdev;
  12424. struct wireless_dev *wdev;
  12425. struct cfg80211_beacon_registration *reg, *tmp;
  12426. if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
  12427. return NOTIFY_DONE;
  12428. rcu_read_lock();
  12429. list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
  12430. bool schedule_destroy_work = false;
  12431. struct cfg80211_sched_scan_request *sched_scan_req =
  12432. rcu_dereference(rdev->sched_scan_req);
  12433. if (sched_scan_req && notify->portid &&
  12434. sched_scan_req->owner_nlportid == notify->portid) {
  12435. sched_scan_req->owner_nlportid = 0;
  12436. if (rdev->ops->sched_scan_stop &&
  12437. rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
  12438. schedule_work(&rdev->sched_scan_stop_wk);
  12439. }
  12440. list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
  12441. cfg80211_mlme_unregister_socket(wdev, notify->portid);
  12442. if (wdev->owner_nlportid == notify->portid)
  12443. schedule_destroy_work = true;
  12444. else if (wdev->conn_owner_nlportid == notify->portid)
  12445. schedule_work(&wdev->disconnect_wk);
  12446. }
  12447. spin_lock_bh(&rdev->beacon_registrations_lock);
  12448. list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
  12449. list) {
  12450. if (reg->nlportid == notify->portid) {
  12451. list_del(&reg->list);
  12452. kfree(reg);
  12453. break;
  12454. }
  12455. }
  12456. spin_unlock_bh(&rdev->beacon_registrations_lock);
  12457. if (schedule_destroy_work) {
  12458. struct cfg80211_iface_destroy *destroy;
  12459. destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
  12460. if (destroy) {
  12461. destroy->nlportid = notify->portid;
  12462. spin_lock(&rdev->destroy_list_lock);
  12463. list_add(&destroy->list, &rdev->destroy_list);
  12464. spin_unlock(&rdev->destroy_list_lock);
  12465. schedule_work(&rdev->destroy_work);
  12466. }
  12467. }
  12468. }
  12469. rcu_read_unlock();
  12470. /*
  12471. * It is possible that the user space process that is controlling the
  12472. * indoor setting disappeared, so notify the regulatory core.
  12473. */
  12474. regulatory_netlink_notify(notify->portid);
  12475. return NOTIFY_OK;
  12476. }
  12477. static struct notifier_block nl80211_netlink_notifier = {
  12478. .notifier_call = nl80211_netlink_notify,
  12479. };
  12480. void cfg80211_ft_event(struct net_device *netdev,
  12481. struct cfg80211_ft_event_params *ft_event)
  12482. {
  12483. struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
  12484. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12485. struct sk_buff *msg;
  12486. void *hdr;
  12487. trace_cfg80211_ft_event(wiphy, netdev, ft_event);
  12488. if (!ft_event->target_ap)
  12489. return;
  12490. msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
  12491. GFP_KERNEL);
  12492. if (!msg)
  12493. return;
  12494. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
  12495. if (!hdr)
  12496. goto out;
  12497. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12498. nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
  12499. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
  12500. goto out;
  12501. if (ft_event->ies &&
  12502. nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
  12503. goto out;
  12504. if (ft_event->ric_ies &&
  12505. nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
  12506. ft_event->ric_ies))
  12507. goto out;
  12508. genlmsg_end(msg, hdr);
  12509. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
  12510. NL80211_MCGRP_MLME, GFP_KERNEL);
  12511. return;
  12512. out:
  12513. nlmsg_free(msg);
  12514. }
  12515. EXPORT_SYMBOL(cfg80211_ft_event);
  12516. void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
  12517. {
  12518. struct cfg80211_registered_device *rdev;
  12519. struct sk_buff *msg;
  12520. void *hdr;
  12521. u32 nlportid;
  12522. rdev = wiphy_to_rdev(wdev->wiphy);
  12523. if (!rdev->crit_proto_nlportid)
  12524. return;
  12525. nlportid = rdev->crit_proto_nlportid;
  12526. rdev->crit_proto_nlportid = 0;
  12527. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12528. if (!msg)
  12529. return;
  12530. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
  12531. if (!hdr)
  12532. goto nla_put_failure;
  12533. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12534. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  12535. NL80211_ATTR_PAD))
  12536. goto nla_put_failure;
  12537. genlmsg_end(msg, hdr);
  12538. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
  12539. return;
  12540. nla_put_failure:
  12541. if (hdr)
  12542. genlmsg_cancel(msg, hdr);
  12543. nlmsg_free(msg);
  12544. }
  12545. EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
  12546. void cfg80211_ap_stopped(struct net_device *netdev, gfp_t gfp)
  12547. {
  12548. struct wireless_dev *wdev = netdev->ieee80211_ptr;
  12549. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  12550. nl80211_send_mlme_event(rdev, netdev, NULL, 0,
  12551. NL80211_CMD_STOP_AP, gfp, -1);
  12552. }
  12553. EXPORT_SYMBOL(cfg80211_ap_stopped);
  12554. void nl80211_send_ap_stopped(struct wireless_dev *wdev)
  12555. {
  12556. struct wiphy *wiphy = wdev->wiphy;
  12557. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  12558. struct sk_buff *msg;
  12559. void *hdr;
  12560. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  12561. if (!msg)
  12562. return;
  12563. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
  12564. if (!hdr)
  12565. goto out;
  12566. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12567. nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
  12568. nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
  12569. NL80211_ATTR_PAD))
  12570. goto out;
  12571. genlmsg_end(msg, hdr);
  12572. genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
  12573. NL80211_MCGRP_MLME, GFP_KERNEL);
  12574. return;
  12575. out:
  12576. nlmsg_free(msg);
  12577. }
  12578. int cfg80211_external_auth_request(struct net_device *dev,
  12579. struct cfg80211_external_auth_params *params,
  12580. gfp_t gfp)
  12581. {
  12582. struct wireless_dev *wdev = dev->ieee80211_ptr;
  12583. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  12584. struct sk_buff *msg;
  12585. void *hdr;
  12586. if (!wdev->conn_owner_nlportid)
  12587. return -EINVAL;
  12588. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
  12589. if (!msg)
  12590. return -ENOMEM;
  12591. hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
  12592. if (!hdr)
  12593. goto nla_put_failure;
  12594. if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
  12595. nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
  12596. nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
  12597. nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
  12598. params->action) ||
  12599. nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
  12600. nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
  12601. params->ssid.ssid))
  12602. goto nla_put_failure;
  12603. genlmsg_end(msg, hdr);
  12604. genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
  12605. wdev->conn_owner_nlportid);
  12606. return 0;
  12607. nla_put_failure:
  12608. nlmsg_free(msg);
  12609. return -ENOBUFS;
  12610. }
  12611. EXPORT_SYMBOL(cfg80211_external_auth_request);
  12612. /* initialisation/exit functions */
  12613. int nl80211_init(void)
  12614. {
  12615. int err;
  12616. err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
  12617. nl80211_mcgrps);
  12618. if (err)
  12619. return err;
  12620. err = netlink_register_notifier(&nl80211_netlink_notifier);
  12621. if (err)
  12622. goto err_out;
  12623. return 0;
  12624. err_out:
  12625. genl_unregister_family(&nl80211_fam);
  12626. return err;
  12627. }
  12628. void nl80211_exit(void)
  12629. {
  12630. netlink_unregister_notifier(&nl80211_netlink_notifier);
  12631. genl_unregister_family(&nl80211_fam);
  12632. }