cfg.c 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * mac80211 configuration hooks for cfg80211
  4. *
  5. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  6. * Copyright 2013-2015 Intel Mobile Communications GmbH
  7. * Copyright (C) 2015-2017 Intel Deutschland GmbH
  8. * Copyright (C) 2018-2024 Intel Corporation
  9. */
  10. #include <linux/ieee80211.h>
  11. #include <linux/nl80211.h>
  12. #include <linux/rtnetlink.h>
  13. #include <linux/slab.h>
  14. #include <net/net_namespace.h>
  15. #include <linux/rcupdate.h>
  16. #include <linux/fips.h>
  17. #include <linux/if_ether.h>
  18. #include <net/cfg80211.h>
  19. #include "ieee80211_i.h"
  20. #include "driver-ops.h"
  21. #include "rate.h"
  22. #include "mesh.h"
  23. #include "wme.h"
  24. static struct ieee80211_link_data *
  25. ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id,
  26. bool require_valid)
  27. {
  28. struct ieee80211_link_data *link;
  29. if (link_id < 0) {
  30. /*
  31. * For keys, if sdata is not an MLD, we might not use
  32. * the return value at all (if it's not a pairwise key),
  33. * so in that case (require_valid==false) don't error.
  34. */
  35. if (require_valid && ieee80211_vif_is_mld(&sdata->vif))
  36. return ERR_PTR(-EINVAL);
  37. return &sdata->deflink;
  38. }
  39. link = sdata_dereference(sdata->link[link_id], sdata);
  40. if (!link)
  41. return ERR_PTR(-ENOLINK);
  42. return link;
  43. }
  44. static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
  45. struct vif_params *params)
  46. {
  47. bool mu_mimo_groups = false;
  48. bool mu_mimo_follow = false;
  49. if (params->vht_mumimo_groups) {
  50. u64 membership;
  51. BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
  52. memcpy(sdata->vif.bss_conf.mu_group.membership,
  53. params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
  54. memcpy(sdata->vif.bss_conf.mu_group.position,
  55. params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
  56. WLAN_USER_POSITION_LEN);
  57. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  58. BSS_CHANGED_MU_GROUPS);
  59. /* don't care about endianness - just check for 0 */
  60. memcpy(&membership, params->vht_mumimo_groups,
  61. WLAN_MEMBERSHIP_LEN);
  62. mu_mimo_groups = membership != 0;
  63. }
  64. if (params->vht_mumimo_follow_addr) {
  65. mu_mimo_follow =
  66. is_valid_ether_addr(params->vht_mumimo_follow_addr);
  67. ether_addr_copy(sdata->u.mntr.mu_follow_addr,
  68. params->vht_mumimo_follow_addr);
  69. }
  70. sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
  71. }
  72. static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
  73. struct vif_params *params)
  74. {
  75. struct ieee80211_local *local = sdata->local;
  76. struct ieee80211_sub_if_data *monitor_sdata;
  77. /* check flags first */
  78. if (params->flags && ieee80211_sdata_running(sdata)) {
  79. u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
  80. /*
  81. * Prohibit MONITOR_FLAG_COOK_FRAMES and
  82. * MONITOR_FLAG_ACTIVE to be changed while the
  83. * interface is up.
  84. * Else we would need to add a lot of cruft
  85. * to update everything:
  86. * cooked_mntrs, monitor and all fif_* counters
  87. * reconfigure hardware
  88. */
  89. if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
  90. return -EBUSY;
  91. }
  92. /* also validate MU-MIMO change */
  93. monitor_sdata = wiphy_dereference(local->hw.wiphy,
  94. local->monitor_sdata);
  95. if (!monitor_sdata &&
  96. (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
  97. return -EOPNOTSUPP;
  98. /* apply all changes now - no failures allowed */
  99. if (monitor_sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
  100. ieee80211_set_mu_mimo_follow(monitor_sdata, params);
  101. if (params->flags) {
  102. if (ieee80211_sdata_running(sdata)) {
  103. ieee80211_adjust_monitor_flags(sdata, -1);
  104. sdata->u.mntr.flags = params->flags;
  105. ieee80211_adjust_monitor_flags(sdata, 1);
  106. ieee80211_configure_filter(local);
  107. } else {
  108. /*
  109. * Because the interface is down, ieee80211_do_stop
  110. * and ieee80211_do_open take care of "everything"
  111. * mentioned in the comment above.
  112. */
  113. sdata->u.mntr.flags = params->flags;
  114. }
  115. }
  116. return 0;
  117. }
  118. static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
  119. struct cfg80211_mbssid_config params,
  120. struct ieee80211_bss_conf *link_conf)
  121. {
  122. struct ieee80211_sub_if_data *tx_sdata;
  123. sdata->vif.mbssid_tx_vif = NULL;
  124. link_conf->bssid_index = 0;
  125. link_conf->nontransmitted = false;
  126. link_conf->ema_ap = false;
  127. link_conf->bssid_indicator = 0;
  128. if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
  129. return -EINVAL;
  130. tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
  131. if (!tx_sdata)
  132. return -EINVAL;
  133. if (tx_sdata == sdata) {
  134. sdata->vif.mbssid_tx_vif = &sdata->vif;
  135. } else {
  136. sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
  137. link_conf->nontransmitted = true;
  138. link_conf->bssid_index = params.index;
  139. }
  140. if (params.ema)
  141. link_conf->ema_ap = true;
  142. return 0;
  143. }
  144. static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
  145. const char *name,
  146. unsigned char name_assign_type,
  147. enum nl80211_iftype type,
  148. struct vif_params *params)
  149. {
  150. struct ieee80211_local *local = wiphy_priv(wiphy);
  151. struct wireless_dev *wdev;
  152. struct ieee80211_sub_if_data *sdata;
  153. int err;
  154. err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
  155. if (err)
  156. return ERR_PTR(err);
  157. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  158. if (type == NL80211_IFTYPE_MONITOR) {
  159. err = ieee80211_set_mon_options(sdata, params);
  160. if (err) {
  161. ieee80211_if_remove(sdata);
  162. return NULL;
  163. }
  164. }
  165. return wdev;
  166. }
  167. static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
  168. {
  169. ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
  170. return 0;
  171. }
  172. static int ieee80211_change_iface(struct wiphy *wiphy,
  173. struct net_device *dev,
  174. enum nl80211_iftype type,
  175. struct vif_params *params)
  176. {
  177. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  178. struct ieee80211_local *local = sdata->local;
  179. struct sta_info *sta;
  180. int ret;
  181. lockdep_assert_wiphy(local->hw.wiphy);
  182. ret = ieee80211_if_change_type(sdata, type);
  183. if (ret)
  184. return ret;
  185. if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
  186. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  187. ieee80211_check_fast_rx_iface(sdata);
  188. } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
  189. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  190. if (params->use_4addr == ifmgd->use_4addr)
  191. return 0;
  192. /* FIXME: no support for 4-addr MLO yet */
  193. if (ieee80211_vif_is_mld(&sdata->vif))
  194. return -EOPNOTSUPP;
  195. sdata->u.mgd.use_4addr = params->use_4addr;
  196. if (!ifmgd->associated)
  197. return 0;
  198. sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
  199. if (sta)
  200. drv_sta_set_4addr(local, sdata, &sta->sta,
  201. params->use_4addr);
  202. if (params->use_4addr)
  203. ieee80211_send_4addr_nullfunc(local, sdata);
  204. }
  205. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  206. ret = ieee80211_set_mon_options(sdata, params);
  207. if (ret)
  208. return ret;
  209. }
  210. return 0;
  211. }
  212. static int ieee80211_start_p2p_device(struct wiphy *wiphy,
  213. struct wireless_dev *wdev)
  214. {
  215. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  216. int ret;
  217. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  218. ret = ieee80211_check_combinations(sdata, NULL, 0, 0, -1);
  219. if (ret < 0)
  220. return ret;
  221. return ieee80211_do_open(wdev, true);
  222. }
  223. static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
  224. struct wireless_dev *wdev)
  225. {
  226. ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
  227. }
  228. static int ieee80211_start_nan(struct wiphy *wiphy,
  229. struct wireless_dev *wdev,
  230. struct cfg80211_nan_conf *conf)
  231. {
  232. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  233. int ret;
  234. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  235. ret = ieee80211_check_combinations(sdata, NULL, 0, 0, -1);
  236. if (ret < 0)
  237. return ret;
  238. ret = ieee80211_do_open(wdev, true);
  239. if (ret)
  240. return ret;
  241. ret = drv_start_nan(sdata->local, sdata, conf);
  242. if (ret)
  243. ieee80211_sdata_stop(sdata);
  244. sdata->u.nan.conf = *conf;
  245. return ret;
  246. }
  247. static void ieee80211_stop_nan(struct wiphy *wiphy,
  248. struct wireless_dev *wdev)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  251. drv_stop_nan(sdata->local, sdata);
  252. ieee80211_sdata_stop(sdata);
  253. }
  254. static int ieee80211_nan_change_conf(struct wiphy *wiphy,
  255. struct wireless_dev *wdev,
  256. struct cfg80211_nan_conf *conf,
  257. u32 changes)
  258. {
  259. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  260. struct cfg80211_nan_conf new_conf;
  261. int ret = 0;
  262. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  263. return -EOPNOTSUPP;
  264. if (!ieee80211_sdata_running(sdata))
  265. return -ENETDOWN;
  266. new_conf = sdata->u.nan.conf;
  267. if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
  268. new_conf.master_pref = conf->master_pref;
  269. if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
  270. new_conf.bands = conf->bands;
  271. ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
  272. if (!ret)
  273. sdata->u.nan.conf = new_conf;
  274. return ret;
  275. }
  276. static int ieee80211_add_nan_func(struct wiphy *wiphy,
  277. struct wireless_dev *wdev,
  278. struct cfg80211_nan_func *nan_func)
  279. {
  280. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  281. int ret;
  282. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  283. return -EOPNOTSUPP;
  284. if (!ieee80211_sdata_running(sdata))
  285. return -ENETDOWN;
  286. spin_lock_bh(&sdata->u.nan.func_lock);
  287. ret = idr_alloc(&sdata->u.nan.function_inst_ids,
  288. nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
  289. GFP_ATOMIC);
  290. spin_unlock_bh(&sdata->u.nan.func_lock);
  291. if (ret < 0)
  292. return ret;
  293. nan_func->instance_id = ret;
  294. WARN_ON(nan_func->instance_id == 0);
  295. ret = drv_add_nan_func(sdata->local, sdata, nan_func);
  296. if (ret) {
  297. spin_lock_bh(&sdata->u.nan.func_lock);
  298. idr_remove(&sdata->u.nan.function_inst_ids,
  299. nan_func->instance_id);
  300. spin_unlock_bh(&sdata->u.nan.func_lock);
  301. }
  302. return ret;
  303. }
  304. static struct cfg80211_nan_func *
  305. ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
  306. u64 cookie)
  307. {
  308. struct cfg80211_nan_func *func;
  309. int id;
  310. lockdep_assert_held(&sdata->u.nan.func_lock);
  311. idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
  312. if (func->cookie == cookie)
  313. return func;
  314. }
  315. return NULL;
  316. }
  317. static void ieee80211_del_nan_func(struct wiphy *wiphy,
  318. struct wireless_dev *wdev, u64 cookie)
  319. {
  320. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  321. struct cfg80211_nan_func *func;
  322. u8 instance_id = 0;
  323. if (sdata->vif.type != NL80211_IFTYPE_NAN ||
  324. !ieee80211_sdata_running(sdata))
  325. return;
  326. spin_lock_bh(&sdata->u.nan.func_lock);
  327. func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
  328. if (func)
  329. instance_id = func->instance_id;
  330. spin_unlock_bh(&sdata->u.nan.func_lock);
  331. if (instance_id)
  332. drv_del_nan_func(sdata->local, sdata, instance_id);
  333. }
  334. static int ieee80211_set_noack_map(struct wiphy *wiphy,
  335. struct net_device *dev,
  336. u16 noack_map)
  337. {
  338. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  339. sdata->noack_map = noack_map;
  340. ieee80211_check_fast_xmit_iface(sdata);
  341. return 0;
  342. }
  343. static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
  344. const u8 *mac_addr, u8 key_idx)
  345. {
  346. struct ieee80211_local *local = sdata->local;
  347. struct ieee80211_key *key;
  348. struct sta_info *sta;
  349. int ret = -EINVAL;
  350. if (!wiphy_ext_feature_isset(local->hw.wiphy,
  351. NL80211_EXT_FEATURE_EXT_KEY_ID))
  352. return -EINVAL;
  353. sta = sta_info_get_bss(sdata, mac_addr);
  354. if (!sta)
  355. return -EINVAL;
  356. if (sta->ptk_idx == key_idx)
  357. return 0;
  358. key = wiphy_dereference(local->hw.wiphy, sta->ptk[key_idx]);
  359. if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
  360. ret = ieee80211_set_tx_key(key);
  361. return ret;
  362. }
  363. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  364. int link_id, u8 key_idx, bool pairwise,
  365. const u8 *mac_addr, struct key_params *params)
  366. {
  367. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  368. struct ieee80211_link_data *link =
  369. ieee80211_link_or_deflink(sdata, link_id, false);
  370. struct ieee80211_local *local = sdata->local;
  371. struct sta_info *sta = NULL;
  372. struct ieee80211_key *key;
  373. int err;
  374. lockdep_assert_wiphy(local->hw.wiphy);
  375. if (!ieee80211_sdata_running(sdata))
  376. return -ENETDOWN;
  377. if (IS_ERR(link))
  378. return PTR_ERR(link);
  379. if (pairwise && params->mode == NL80211_KEY_SET_TX)
  380. return ieee80211_set_tx(sdata, mac_addr, key_idx);
  381. /* reject WEP and TKIP keys if WEP failed to initialize */
  382. switch (params->cipher) {
  383. case WLAN_CIPHER_SUITE_WEP40:
  384. case WLAN_CIPHER_SUITE_TKIP:
  385. case WLAN_CIPHER_SUITE_WEP104:
  386. if (link_id >= 0)
  387. return -EINVAL;
  388. if (WARN_ON_ONCE(fips_enabled))
  389. return -EINVAL;
  390. break;
  391. default:
  392. break;
  393. }
  394. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  395. params->key, params->seq_len, params->seq);
  396. if (IS_ERR(key))
  397. return PTR_ERR(key);
  398. key->conf.link_id = link_id;
  399. if (pairwise)
  400. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  401. if (params->mode == NL80211_KEY_NO_TX)
  402. key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
  403. if (mac_addr) {
  404. sta = sta_info_get_bss(sdata, mac_addr);
  405. /*
  406. * The ASSOC test makes sure the driver is ready to
  407. * receive the key. When wpa_supplicant has roamed
  408. * using FT, it attempts to set the key before
  409. * association has completed, this rejects that attempt
  410. * so it will set the key again after association.
  411. *
  412. * TODO: accept the key if we have a station entry and
  413. * add it to the device after the station.
  414. */
  415. if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  416. ieee80211_key_free_unused(key);
  417. return -ENOENT;
  418. }
  419. }
  420. switch (sdata->vif.type) {
  421. case NL80211_IFTYPE_STATION:
  422. if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
  423. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  424. break;
  425. case NL80211_IFTYPE_AP:
  426. case NL80211_IFTYPE_AP_VLAN:
  427. /* Keys without a station are used for TX only */
  428. if (sta && test_sta_flag(sta, WLAN_STA_MFP))
  429. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  430. break;
  431. case NL80211_IFTYPE_ADHOC:
  432. /* no MFP (yet) */
  433. break;
  434. case NL80211_IFTYPE_MESH_POINT:
  435. #ifdef CONFIG_MAC80211_MESH
  436. if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
  437. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  438. break;
  439. #endif
  440. case NL80211_IFTYPE_WDS:
  441. case NL80211_IFTYPE_MONITOR:
  442. case NL80211_IFTYPE_P2P_DEVICE:
  443. case NL80211_IFTYPE_NAN:
  444. case NL80211_IFTYPE_UNSPECIFIED:
  445. case NUM_NL80211_IFTYPES:
  446. case NL80211_IFTYPE_P2P_CLIENT:
  447. case NL80211_IFTYPE_P2P_GO:
  448. case NL80211_IFTYPE_OCB:
  449. /* shouldn't happen */
  450. WARN_ON_ONCE(1);
  451. break;
  452. }
  453. err = ieee80211_key_link(key, link, sta);
  454. /* KRACK protection, shouldn't happen but just silently accept key */
  455. if (err == -EALREADY)
  456. err = 0;
  457. return err;
  458. }
  459. static struct ieee80211_key *
  460. ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
  461. u8 key_idx, bool pairwise, const u8 *mac_addr)
  462. {
  463. struct ieee80211_local *local __maybe_unused = sdata->local;
  464. struct ieee80211_link_data *link = &sdata->deflink;
  465. struct ieee80211_key *key;
  466. if (link_id >= 0) {
  467. link = sdata_dereference(sdata->link[link_id], sdata);
  468. if (!link)
  469. return NULL;
  470. }
  471. if (mac_addr) {
  472. struct sta_info *sta;
  473. struct link_sta_info *link_sta;
  474. sta = sta_info_get_bss(sdata, mac_addr);
  475. if (!sta)
  476. return NULL;
  477. if (link_id >= 0) {
  478. link_sta = rcu_dereference_check(sta->link[link_id],
  479. lockdep_is_held(&local->hw.wiphy->mtx));
  480. if (!link_sta)
  481. return NULL;
  482. } else {
  483. link_sta = &sta->deflink;
  484. }
  485. if (pairwise && key_idx < NUM_DEFAULT_KEYS)
  486. return wiphy_dereference(local->hw.wiphy,
  487. sta->ptk[key_idx]);
  488. if (!pairwise &&
  489. key_idx < NUM_DEFAULT_KEYS +
  490. NUM_DEFAULT_MGMT_KEYS +
  491. NUM_DEFAULT_BEACON_KEYS)
  492. return wiphy_dereference(local->hw.wiphy,
  493. link_sta->gtk[key_idx]);
  494. return NULL;
  495. }
  496. if (pairwise && key_idx < NUM_DEFAULT_KEYS)
  497. return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]);
  498. key = wiphy_dereference(local->hw.wiphy, link->gtk[key_idx]);
  499. if (key)
  500. return key;
  501. /* or maybe it was a WEP key */
  502. if (key_idx < NUM_DEFAULT_KEYS)
  503. return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]);
  504. return NULL;
  505. }
  506. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  507. int link_id, u8 key_idx, bool pairwise,
  508. const u8 *mac_addr)
  509. {
  510. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  511. struct ieee80211_local *local = sdata->local;
  512. struct ieee80211_key *key;
  513. lockdep_assert_wiphy(local->hw.wiphy);
  514. key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
  515. if (!key)
  516. return -ENOENT;
  517. ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
  518. return 0;
  519. }
  520. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  521. int link_id, u8 key_idx, bool pairwise,
  522. const u8 *mac_addr, void *cookie,
  523. void (*callback)(void *cookie,
  524. struct key_params *params))
  525. {
  526. struct ieee80211_sub_if_data *sdata;
  527. u8 seq[6] = {0};
  528. struct key_params params;
  529. struct ieee80211_key *key;
  530. u64 pn64;
  531. u32 iv32;
  532. u16 iv16;
  533. int err = -ENOENT;
  534. struct ieee80211_key_seq kseq = {};
  535. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  536. rcu_read_lock();
  537. key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
  538. if (!key)
  539. goto out;
  540. memset(&params, 0, sizeof(params));
  541. params.cipher = key->conf.cipher;
  542. switch (key->conf.cipher) {
  543. case WLAN_CIPHER_SUITE_TKIP:
  544. pn64 = atomic64_read(&key->conf.tx_pn);
  545. iv32 = TKIP_PN_TO_IV32(pn64);
  546. iv16 = TKIP_PN_TO_IV16(pn64);
  547. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  548. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  549. drv_get_key_seq(sdata->local, key, &kseq);
  550. iv32 = kseq.tkip.iv32;
  551. iv16 = kseq.tkip.iv16;
  552. }
  553. seq[0] = iv16 & 0xff;
  554. seq[1] = (iv16 >> 8) & 0xff;
  555. seq[2] = iv32 & 0xff;
  556. seq[3] = (iv32 >> 8) & 0xff;
  557. seq[4] = (iv32 >> 16) & 0xff;
  558. seq[5] = (iv32 >> 24) & 0xff;
  559. params.seq = seq;
  560. params.seq_len = 6;
  561. break;
  562. case WLAN_CIPHER_SUITE_CCMP:
  563. case WLAN_CIPHER_SUITE_CCMP_256:
  564. case WLAN_CIPHER_SUITE_AES_CMAC:
  565. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  566. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  567. offsetof(typeof(kseq), aes_cmac));
  568. fallthrough;
  569. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  570. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  571. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  572. offsetof(typeof(kseq), aes_gmac));
  573. fallthrough;
  574. case WLAN_CIPHER_SUITE_GCMP:
  575. case WLAN_CIPHER_SUITE_GCMP_256:
  576. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  577. offsetof(typeof(kseq), gcmp));
  578. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  579. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  580. drv_get_key_seq(sdata->local, key, &kseq);
  581. memcpy(seq, kseq.ccmp.pn, 6);
  582. } else {
  583. pn64 = atomic64_read(&key->conf.tx_pn);
  584. seq[0] = pn64;
  585. seq[1] = pn64 >> 8;
  586. seq[2] = pn64 >> 16;
  587. seq[3] = pn64 >> 24;
  588. seq[4] = pn64 >> 32;
  589. seq[5] = pn64 >> 40;
  590. }
  591. params.seq = seq;
  592. params.seq_len = 6;
  593. break;
  594. default:
  595. if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  596. break;
  597. if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
  598. break;
  599. drv_get_key_seq(sdata->local, key, &kseq);
  600. params.seq = kseq.hw.seq;
  601. params.seq_len = kseq.hw.seq_len;
  602. break;
  603. }
  604. callback(cookie, &params);
  605. err = 0;
  606. out:
  607. rcu_read_unlock();
  608. return err;
  609. }
  610. static int ieee80211_config_default_key(struct wiphy *wiphy,
  611. struct net_device *dev,
  612. int link_id, u8 key_idx, bool uni,
  613. bool multi)
  614. {
  615. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  616. struct ieee80211_link_data *link =
  617. ieee80211_link_or_deflink(sdata, link_id, false);
  618. if (IS_ERR(link))
  619. return PTR_ERR(link);
  620. ieee80211_set_default_key(link, key_idx, uni, multi);
  621. return 0;
  622. }
  623. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  624. struct net_device *dev,
  625. int link_id, u8 key_idx)
  626. {
  627. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  628. struct ieee80211_link_data *link =
  629. ieee80211_link_or_deflink(sdata, link_id, true);
  630. if (IS_ERR(link))
  631. return PTR_ERR(link);
  632. ieee80211_set_default_mgmt_key(link, key_idx);
  633. return 0;
  634. }
  635. static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
  636. struct net_device *dev,
  637. int link_id, u8 key_idx)
  638. {
  639. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  640. struct ieee80211_link_data *link =
  641. ieee80211_link_or_deflink(sdata, link_id, true);
  642. if (IS_ERR(link))
  643. return PTR_ERR(link);
  644. ieee80211_set_default_beacon_key(link, key_idx);
  645. return 0;
  646. }
  647. void sta_set_rate_info_tx(struct sta_info *sta,
  648. const struct ieee80211_tx_rate *rate,
  649. struct rate_info *rinfo)
  650. {
  651. rinfo->flags = 0;
  652. if (rate->flags & IEEE80211_TX_RC_MCS) {
  653. rinfo->flags |= RATE_INFO_FLAGS_MCS;
  654. rinfo->mcs = rate->idx;
  655. } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
  656. rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
  657. rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
  658. rinfo->nss = ieee80211_rate_get_vht_nss(rate);
  659. } else {
  660. struct ieee80211_supported_band *sband;
  661. sband = ieee80211_get_sband(sta->sdata);
  662. WARN_ON_ONCE(sband && !sband->bitrates);
  663. if (sband && sband->bitrates)
  664. rinfo->legacy = sband->bitrates[rate->idx].bitrate;
  665. }
  666. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  667. rinfo->bw = RATE_INFO_BW_40;
  668. else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  669. rinfo->bw = RATE_INFO_BW_80;
  670. else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  671. rinfo->bw = RATE_INFO_BW_160;
  672. else
  673. rinfo->bw = RATE_INFO_BW_20;
  674. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  675. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  676. }
  677. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  678. int idx, u8 *mac, struct station_info *sinfo)
  679. {
  680. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  681. struct ieee80211_local *local = sdata->local;
  682. struct sta_info *sta;
  683. int ret = -ENOENT;
  684. lockdep_assert_wiphy(local->hw.wiphy);
  685. sta = sta_info_get_by_idx(sdata, idx);
  686. if (sta) {
  687. ret = 0;
  688. memcpy(mac, sta->sta.addr, ETH_ALEN);
  689. sta_set_sinfo(sta, sinfo, true);
  690. }
  691. return ret;
  692. }
  693. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  694. int idx, struct survey_info *survey)
  695. {
  696. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  697. return drv_get_survey(local, idx, survey);
  698. }
  699. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  700. const u8 *mac, struct station_info *sinfo)
  701. {
  702. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  703. struct ieee80211_local *local = sdata->local;
  704. struct sta_info *sta;
  705. int ret = -ENOENT;
  706. lockdep_assert_wiphy(local->hw.wiphy);
  707. sta = sta_info_get_bss(sdata, mac);
  708. if (sta) {
  709. ret = 0;
  710. sta_set_sinfo(sta, sinfo, true);
  711. }
  712. return ret;
  713. }
  714. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  715. struct cfg80211_chan_def *chandef)
  716. {
  717. struct ieee80211_local *local = wiphy_priv(wiphy);
  718. struct ieee80211_sub_if_data *sdata;
  719. struct ieee80211_chan_req chanreq = { .oper = *chandef };
  720. int ret;
  721. lockdep_assert_wiphy(local->hw.wiphy);
  722. if (cfg80211_chandef_identical(&local->monitor_chanreq.oper,
  723. &chanreq.oper))
  724. return 0;
  725. sdata = wiphy_dereference(local->hw.wiphy,
  726. local->monitor_sdata);
  727. if (!sdata)
  728. goto done;
  729. if (cfg80211_chandef_identical(&sdata->vif.bss_conf.chanreq.oper,
  730. &chanreq.oper))
  731. return 0;
  732. ieee80211_link_release_channel(&sdata->deflink);
  733. ret = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
  734. IEEE80211_CHANCTX_EXCLUSIVE);
  735. if (ret)
  736. return ret;
  737. done:
  738. local->monitor_chanreq = chanreq;
  739. return 0;
  740. }
  741. static int
  742. ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  743. const u8 *resp, size_t resp_len,
  744. const struct ieee80211_csa_settings *csa,
  745. const struct ieee80211_color_change_settings *cca,
  746. struct ieee80211_link_data *link)
  747. {
  748. struct probe_resp *new, *old;
  749. if (!resp || !resp_len)
  750. return 1;
  751. old = sdata_dereference(link->u.ap.probe_resp, sdata);
  752. new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
  753. if (!new)
  754. return -ENOMEM;
  755. new->len = resp_len;
  756. memcpy(new->data, resp, resp_len);
  757. if (csa)
  758. memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
  759. csa->n_counter_offsets_presp *
  760. sizeof(new->cntdwn_counter_offsets[0]));
  761. else if (cca)
  762. new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
  763. rcu_assign_pointer(link->u.ap.probe_resp, new);
  764. if (old)
  765. kfree_rcu(old, rcu_head);
  766. return 0;
  767. }
  768. static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
  769. struct cfg80211_fils_discovery *params,
  770. struct ieee80211_link_data *link,
  771. struct ieee80211_bss_conf *link_conf,
  772. u64 *changed)
  773. {
  774. struct fils_discovery_data *new, *old = NULL;
  775. struct ieee80211_fils_discovery *fd;
  776. if (!params->update)
  777. return 0;
  778. fd = &link_conf->fils_discovery;
  779. fd->min_interval = params->min_interval;
  780. fd->max_interval = params->max_interval;
  781. old = sdata_dereference(link->u.ap.fils_discovery, sdata);
  782. if (old)
  783. kfree_rcu(old, rcu_head);
  784. if (params->tmpl && params->tmpl_len) {
  785. new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
  786. if (!new)
  787. return -ENOMEM;
  788. new->len = params->tmpl_len;
  789. memcpy(new->data, params->tmpl, params->tmpl_len);
  790. rcu_assign_pointer(link->u.ap.fils_discovery, new);
  791. } else {
  792. RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
  793. }
  794. *changed |= BSS_CHANGED_FILS_DISCOVERY;
  795. return 0;
  796. }
  797. static int
  798. ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
  799. struct cfg80211_unsol_bcast_probe_resp *params,
  800. struct ieee80211_link_data *link,
  801. struct ieee80211_bss_conf *link_conf,
  802. u64 *changed)
  803. {
  804. struct unsol_bcast_probe_resp_data *new, *old = NULL;
  805. if (!params->update)
  806. return 0;
  807. link_conf->unsol_bcast_probe_resp_interval = params->interval;
  808. old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
  809. if (old)
  810. kfree_rcu(old, rcu_head);
  811. if (params->tmpl && params->tmpl_len) {
  812. new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
  813. if (!new)
  814. return -ENOMEM;
  815. new->len = params->tmpl_len;
  816. memcpy(new->data, params->tmpl, params->tmpl_len);
  817. rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
  818. } else {
  819. RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
  820. }
  821. *changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
  822. return 0;
  823. }
  824. static int ieee80211_set_ftm_responder_params(
  825. struct ieee80211_sub_if_data *sdata,
  826. const u8 *lci, size_t lci_len,
  827. const u8 *civicloc, size_t civicloc_len,
  828. struct ieee80211_bss_conf *link_conf)
  829. {
  830. struct ieee80211_ftm_responder_params *new, *old;
  831. u8 *pos;
  832. int len;
  833. if (!lci_len && !civicloc_len)
  834. return 0;
  835. old = link_conf->ftmr_params;
  836. len = lci_len + civicloc_len;
  837. new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
  838. if (!new)
  839. return -ENOMEM;
  840. pos = (u8 *)(new + 1);
  841. if (lci_len) {
  842. new->lci_len = lci_len;
  843. new->lci = pos;
  844. memcpy(pos, lci, lci_len);
  845. pos += lci_len;
  846. }
  847. if (civicloc_len) {
  848. new->civicloc_len = civicloc_len;
  849. new->civicloc = pos;
  850. memcpy(pos, civicloc, civicloc_len);
  851. pos += civicloc_len;
  852. }
  853. link_conf->ftmr_params = new;
  854. kfree(old);
  855. return 0;
  856. }
  857. static int
  858. ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
  859. struct cfg80211_mbssid_elems *src)
  860. {
  861. int i, offset = 0;
  862. dst->cnt = src->cnt;
  863. for (i = 0; i < src->cnt; i++) {
  864. memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
  865. dst->elem[i].len = src->elem[i].len;
  866. dst->elem[i].data = pos + offset;
  867. offset += dst->elem[i].len;
  868. }
  869. return offset;
  870. }
  871. static int
  872. ieee80211_copy_rnr_beacon(u8 *pos, struct cfg80211_rnr_elems *dst,
  873. struct cfg80211_rnr_elems *src)
  874. {
  875. int i, offset = 0;
  876. for (i = 0; i < src->cnt; i++) {
  877. memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
  878. dst->elem[i].len = src->elem[i].len;
  879. dst->elem[i].data = pos + offset;
  880. offset += dst->elem[i].len;
  881. }
  882. dst->cnt = src->cnt;
  883. return offset;
  884. }
  885. static int
  886. ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  887. struct ieee80211_link_data *link,
  888. struct cfg80211_beacon_data *params,
  889. const struct ieee80211_csa_settings *csa,
  890. const struct ieee80211_color_change_settings *cca,
  891. u64 *changed)
  892. {
  893. struct cfg80211_mbssid_elems *mbssid = NULL;
  894. struct cfg80211_rnr_elems *rnr = NULL;
  895. struct beacon_data *new, *old;
  896. int new_head_len, new_tail_len;
  897. int size, err;
  898. u64 _changed = BSS_CHANGED_BEACON;
  899. struct ieee80211_bss_conf *link_conf = link->conf;
  900. old = sdata_dereference(link->u.ap.beacon, sdata);
  901. /* Need to have a beacon head if we don't have one yet */
  902. if (!params->head && !old)
  903. return -EINVAL;
  904. /* new or old head? */
  905. if (params->head)
  906. new_head_len = params->head_len;
  907. else
  908. new_head_len = old->head_len;
  909. /* new or old tail? */
  910. if (params->tail || !old)
  911. /* params->tail_len will be zero for !params->tail */
  912. new_tail_len = params->tail_len;
  913. else
  914. new_tail_len = old->tail_len;
  915. size = sizeof(*new) + new_head_len + new_tail_len;
  916. /* new or old multiple BSSID elements? */
  917. if (params->mbssid_ies) {
  918. mbssid = params->mbssid_ies;
  919. size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
  920. if (params->rnr_ies) {
  921. rnr = params->rnr_ies;
  922. size += struct_size(new->rnr_ies, elem, rnr->cnt);
  923. }
  924. size += ieee80211_get_mbssid_beacon_len(mbssid, rnr,
  925. mbssid->cnt);
  926. } else if (old && old->mbssid_ies) {
  927. mbssid = old->mbssid_ies;
  928. size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
  929. if (old && old->rnr_ies) {
  930. rnr = old->rnr_ies;
  931. size += struct_size(new->rnr_ies, elem, rnr->cnt);
  932. }
  933. size += ieee80211_get_mbssid_beacon_len(mbssid, rnr,
  934. mbssid->cnt);
  935. }
  936. new = kzalloc(size, GFP_KERNEL);
  937. if (!new)
  938. return -ENOMEM;
  939. /* start filling the new info now */
  940. /*
  941. * pointers go into the block we allocated,
  942. * memory is | beacon_data | head | tail | mbssid_ies | rnr_ies
  943. */
  944. new->head = ((u8 *) new) + sizeof(*new);
  945. new->tail = new->head + new_head_len;
  946. new->head_len = new_head_len;
  947. new->tail_len = new_tail_len;
  948. /* copy in optional mbssid_ies */
  949. if (mbssid) {
  950. u8 *pos = new->tail + new->tail_len;
  951. new->mbssid_ies = (void *)pos;
  952. pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
  953. pos += ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies,
  954. mbssid);
  955. if (rnr) {
  956. new->rnr_ies = (void *)pos;
  957. pos += struct_size(new->rnr_ies, elem, rnr->cnt);
  958. ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr);
  959. }
  960. /* update bssid_indicator */
  961. link_conf->bssid_indicator =
  962. ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
  963. }
  964. if (csa) {
  965. new->cntdwn_current_counter = csa->count;
  966. memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
  967. csa->n_counter_offsets_beacon *
  968. sizeof(new->cntdwn_counter_offsets[0]));
  969. } else if (cca) {
  970. new->cntdwn_current_counter = cca->count;
  971. new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
  972. }
  973. /* copy in head */
  974. if (params->head)
  975. memcpy(new->head, params->head, new_head_len);
  976. else
  977. memcpy(new->head, old->head, new_head_len);
  978. /* copy in optional tail */
  979. if (params->tail)
  980. memcpy(new->tail, params->tail, new_tail_len);
  981. else
  982. if (old)
  983. memcpy(new->tail, old->tail, new_tail_len);
  984. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  985. params->probe_resp_len, csa, cca, link);
  986. if (err < 0) {
  987. kfree(new);
  988. return err;
  989. }
  990. if (err == 0)
  991. _changed |= BSS_CHANGED_AP_PROBE_RESP;
  992. if (params->ftm_responder != -1) {
  993. link_conf->ftm_responder = params->ftm_responder;
  994. err = ieee80211_set_ftm_responder_params(sdata,
  995. params->lci,
  996. params->lci_len,
  997. params->civicloc,
  998. params->civicloc_len,
  999. link_conf);
  1000. if (err < 0) {
  1001. kfree(new);
  1002. return err;
  1003. }
  1004. _changed |= BSS_CHANGED_FTM_RESPONDER;
  1005. }
  1006. rcu_assign_pointer(link->u.ap.beacon, new);
  1007. sdata->u.ap.active = true;
  1008. if (old)
  1009. kfree_rcu(old, rcu_head);
  1010. *changed |= _changed;
  1011. return 0;
  1012. }
  1013. static u8 ieee80211_num_beaconing_links(struct ieee80211_sub_if_data *sdata)
  1014. {
  1015. struct ieee80211_link_data *link;
  1016. u8 link_id, num = 0;
  1017. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  1018. sdata->vif.type != NL80211_IFTYPE_P2P_GO)
  1019. return num;
  1020. if (!sdata->vif.valid_links)
  1021. return num;
  1022. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  1023. link = sdata_dereference(sdata->link[link_id], sdata);
  1024. if (!link)
  1025. continue;
  1026. if (sdata_dereference(link->u.ap.beacon, sdata))
  1027. num++;
  1028. }
  1029. return num;
  1030. }
  1031. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  1032. struct cfg80211_ap_settings *params)
  1033. {
  1034. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1035. struct ieee80211_local *local = sdata->local;
  1036. struct beacon_data *old;
  1037. struct ieee80211_sub_if_data *vlan;
  1038. u64 changed = BSS_CHANGED_BEACON_INT |
  1039. BSS_CHANGED_BEACON_ENABLED |
  1040. BSS_CHANGED_BEACON |
  1041. BSS_CHANGED_P2P_PS |
  1042. BSS_CHANGED_TXPOWER |
  1043. BSS_CHANGED_TWT;
  1044. int i, err;
  1045. int prev_beacon_int;
  1046. unsigned int link_id = params->beacon.link_id;
  1047. struct ieee80211_link_data *link;
  1048. struct ieee80211_bss_conf *link_conf;
  1049. struct ieee80211_chan_req chanreq = { .oper = params->chandef };
  1050. lockdep_assert_wiphy(local->hw.wiphy);
  1051. link = sdata_dereference(sdata->link[link_id], sdata);
  1052. if (!link)
  1053. return -ENOLINK;
  1054. link_conf = link->conf;
  1055. old = sdata_dereference(link->u.ap.beacon, sdata);
  1056. if (old)
  1057. return -EALREADY;
  1058. if (params->smps_mode != NL80211_SMPS_OFF)
  1059. return -EOPNOTSUPP;
  1060. link->smps_mode = IEEE80211_SMPS_OFF;
  1061. link->needed_rx_chains = sdata->local->rx_chains;
  1062. prev_beacon_int = link_conf->beacon_int;
  1063. link_conf->beacon_int = params->beacon_interval;
  1064. if (params->ht_cap)
  1065. link_conf->ht_ldpc =
  1066. params->ht_cap->cap_info &
  1067. cpu_to_le16(IEEE80211_HT_CAP_LDPC_CODING);
  1068. if (params->vht_cap) {
  1069. link_conf->vht_ldpc =
  1070. params->vht_cap->vht_cap_info &
  1071. cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC);
  1072. link_conf->vht_su_beamformer =
  1073. params->vht_cap->vht_cap_info &
  1074. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
  1075. link_conf->vht_su_beamformee =
  1076. params->vht_cap->vht_cap_info &
  1077. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
  1078. link_conf->vht_mu_beamformer =
  1079. params->vht_cap->vht_cap_info &
  1080. cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
  1081. link_conf->vht_mu_beamformee =
  1082. params->vht_cap->vht_cap_info &
  1083. cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
  1084. }
  1085. if (params->he_cap && params->he_oper) {
  1086. link_conf->he_support = true;
  1087. link_conf->htc_trig_based_pkt_ext =
  1088. le32_get_bits(params->he_oper->he_oper_params,
  1089. IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
  1090. link_conf->frame_time_rts_th =
  1091. le32_get_bits(params->he_oper->he_oper_params,
  1092. IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
  1093. changed |= BSS_CHANGED_HE_OBSS_PD;
  1094. if (params->beacon.he_bss_color.enabled)
  1095. changed |= BSS_CHANGED_HE_BSS_COLOR;
  1096. }
  1097. if (params->he_cap) {
  1098. link_conf->he_ldpc =
  1099. params->he_cap->phy_cap_info[1] &
  1100. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
  1101. link_conf->he_su_beamformer =
  1102. params->he_cap->phy_cap_info[3] &
  1103. IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
  1104. link_conf->he_su_beamformee =
  1105. params->he_cap->phy_cap_info[4] &
  1106. IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE;
  1107. link_conf->he_mu_beamformer =
  1108. params->he_cap->phy_cap_info[4] &
  1109. IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
  1110. link_conf->he_full_ul_mumimo =
  1111. params->he_cap->phy_cap_info[2] &
  1112. IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO;
  1113. }
  1114. if (params->eht_cap) {
  1115. if (!link_conf->he_support)
  1116. return -EOPNOTSUPP;
  1117. link_conf->eht_support = true;
  1118. link_conf->eht_su_beamformer =
  1119. params->eht_cap->fixed.phy_cap_info[0] &
  1120. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER;
  1121. link_conf->eht_su_beamformee =
  1122. params->eht_cap->fixed.phy_cap_info[0] &
  1123. IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
  1124. link_conf->eht_mu_beamformer =
  1125. params->eht_cap->fixed.phy_cap_info[7] &
  1126. (IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
  1127. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
  1128. IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ);
  1129. link_conf->eht_80mhz_full_bw_ul_mumimo =
  1130. params->eht_cap->fixed.phy_cap_info[7] &
  1131. (IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
  1132. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
  1133. IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ);
  1134. } else {
  1135. link_conf->eht_su_beamformer = false;
  1136. link_conf->eht_su_beamformee = false;
  1137. link_conf->eht_mu_beamformer = false;
  1138. }
  1139. if (sdata->vif.type == NL80211_IFTYPE_AP &&
  1140. params->mbssid_config.tx_wdev) {
  1141. err = ieee80211_set_ap_mbssid_options(sdata,
  1142. params->mbssid_config,
  1143. link_conf);
  1144. if (err)
  1145. return err;
  1146. }
  1147. err = ieee80211_link_use_channel(link, &chanreq,
  1148. IEEE80211_CHANCTX_SHARED);
  1149. if (!err)
  1150. ieee80211_link_copy_chanctx_to_vlans(link, false);
  1151. if (err) {
  1152. link_conf->beacon_int = prev_beacon_int;
  1153. return err;
  1154. }
  1155. /*
  1156. * Apply control port protocol, this allows us to
  1157. * not encrypt dynamic WEP control frames.
  1158. */
  1159. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  1160. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  1161. sdata->control_port_over_nl80211 =
  1162. params->crypto.control_port_over_nl80211;
  1163. sdata->control_port_no_preauth =
  1164. params->crypto.control_port_no_preauth;
  1165. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  1166. vlan->control_port_protocol =
  1167. params->crypto.control_port_ethertype;
  1168. vlan->control_port_no_encrypt =
  1169. params->crypto.control_port_no_encrypt;
  1170. vlan->control_port_over_nl80211 =
  1171. params->crypto.control_port_over_nl80211;
  1172. vlan->control_port_no_preauth =
  1173. params->crypto.control_port_no_preauth;
  1174. }
  1175. link_conf->dtim_period = params->dtim_period;
  1176. link_conf->enable_beacon = true;
  1177. link_conf->allow_p2p_go_ps = sdata->vif.p2p;
  1178. link_conf->twt_responder = params->twt_responder;
  1179. link_conf->he_obss_pd = params->he_obss_pd;
  1180. link_conf->he_bss_color = params->beacon.he_bss_color;
  1181. sdata->vif.cfg.s1g = params->chandef.chan->band ==
  1182. NL80211_BAND_S1GHZ;
  1183. sdata->vif.cfg.ssid_len = params->ssid_len;
  1184. if (params->ssid_len)
  1185. memcpy(sdata->vif.cfg.ssid, params->ssid,
  1186. params->ssid_len);
  1187. link_conf->hidden_ssid =
  1188. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  1189. memset(&link_conf->p2p_noa_attr, 0,
  1190. sizeof(link_conf->p2p_noa_attr));
  1191. link_conf->p2p_noa_attr.oppps_ctwindow =
  1192. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1193. if (params->p2p_opp_ps)
  1194. link_conf->p2p_noa_attr.oppps_ctwindow |=
  1195. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1196. sdata->beacon_rate_set = false;
  1197. if (wiphy_ext_feature_isset(local->hw.wiphy,
  1198. NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
  1199. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  1200. sdata->beacon_rateidx_mask[i] =
  1201. params->beacon_rate.control[i].legacy;
  1202. if (sdata->beacon_rateidx_mask[i])
  1203. sdata->beacon_rate_set = true;
  1204. }
  1205. }
  1206. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
  1207. link_conf->beacon_tx_rate = params->beacon_rate;
  1208. err = ieee80211_assign_beacon(sdata, link, &params->beacon, NULL, NULL,
  1209. &changed);
  1210. if (err < 0)
  1211. goto error;
  1212. err = ieee80211_set_fils_discovery(sdata, &params->fils_discovery,
  1213. link, link_conf, &changed);
  1214. if (err < 0)
  1215. goto error;
  1216. err = ieee80211_set_unsol_bcast_probe_resp(sdata,
  1217. &params->unsol_bcast_probe_resp,
  1218. link, link_conf, &changed);
  1219. if (err < 0)
  1220. goto error;
  1221. err = drv_start_ap(sdata->local, sdata, link_conf);
  1222. if (err) {
  1223. old = sdata_dereference(link->u.ap.beacon, sdata);
  1224. if (old)
  1225. kfree_rcu(old, rcu_head);
  1226. RCU_INIT_POINTER(link->u.ap.beacon, NULL);
  1227. if (ieee80211_num_beaconing_links(sdata) == 0)
  1228. sdata->u.ap.active = false;
  1229. goto error;
  1230. }
  1231. ieee80211_recalc_dtim(local, sdata);
  1232. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
  1233. ieee80211_link_info_change_notify(sdata, link, changed);
  1234. if (ieee80211_num_beaconing_links(sdata) <= 1)
  1235. netif_carrier_on(dev);
  1236. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  1237. netif_carrier_on(vlan->dev);
  1238. return 0;
  1239. error:
  1240. ieee80211_link_release_channel(link);
  1241. return err;
  1242. }
  1243. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  1244. struct cfg80211_ap_update *params)
  1245. {
  1246. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1247. struct ieee80211_link_data *link;
  1248. struct cfg80211_beacon_data *beacon = &params->beacon;
  1249. struct beacon_data *old;
  1250. int err;
  1251. struct ieee80211_bss_conf *link_conf;
  1252. u64 changed = 0;
  1253. lockdep_assert_wiphy(wiphy);
  1254. link = sdata_dereference(sdata->link[beacon->link_id], sdata);
  1255. if (!link)
  1256. return -ENOLINK;
  1257. link_conf = link->conf;
  1258. /* don't allow changing the beacon while a countdown is in place - offset
  1259. * of channel switch counter may change
  1260. */
  1261. if (link_conf->csa_active || link_conf->color_change_active)
  1262. return -EBUSY;
  1263. old = sdata_dereference(link->u.ap.beacon, sdata);
  1264. if (!old)
  1265. return -ENOENT;
  1266. err = ieee80211_assign_beacon(sdata, link, beacon, NULL, NULL,
  1267. &changed);
  1268. if (err < 0)
  1269. return err;
  1270. err = ieee80211_set_fils_discovery(sdata, &params->fils_discovery,
  1271. link, link_conf, &changed);
  1272. if (err < 0)
  1273. return err;
  1274. err = ieee80211_set_unsol_bcast_probe_resp(sdata,
  1275. &params->unsol_bcast_probe_resp,
  1276. link, link_conf, &changed);
  1277. if (err < 0)
  1278. return err;
  1279. if (beacon->he_bss_color_valid &&
  1280. beacon->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
  1281. link_conf->he_bss_color.enabled = beacon->he_bss_color.enabled;
  1282. changed |= BSS_CHANGED_HE_BSS_COLOR;
  1283. }
  1284. ieee80211_link_info_change_notify(sdata, link, changed);
  1285. return 0;
  1286. }
  1287. static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
  1288. {
  1289. if (!link->u.ap.next_beacon)
  1290. return;
  1291. kfree(link->u.ap.next_beacon->mbssid_ies);
  1292. kfree(link->u.ap.next_beacon->rnr_ies);
  1293. kfree(link->u.ap.next_beacon);
  1294. link->u.ap.next_beacon = NULL;
  1295. }
  1296. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
  1297. unsigned int link_id)
  1298. {
  1299. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1300. struct ieee80211_sub_if_data *vlan;
  1301. struct ieee80211_local *local = sdata->local;
  1302. struct beacon_data *old_beacon;
  1303. struct probe_resp *old_probe_resp;
  1304. struct fils_discovery_data *old_fils_discovery;
  1305. struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
  1306. struct cfg80211_chan_def chandef;
  1307. struct ieee80211_link_data *link =
  1308. sdata_dereference(sdata->link[link_id], sdata);
  1309. struct ieee80211_bss_conf *link_conf = link->conf;
  1310. LIST_HEAD(keys);
  1311. lockdep_assert_wiphy(local->hw.wiphy);
  1312. old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
  1313. if (!old_beacon)
  1314. return -ENOENT;
  1315. old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
  1316. sdata);
  1317. old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
  1318. sdata);
  1319. old_unsol_bcast_probe_resp =
  1320. sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
  1321. sdata);
  1322. /* abort any running channel switch or color change */
  1323. link_conf->csa_active = false;
  1324. link_conf->color_change_active = false;
  1325. ieee80211_vif_unblock_queues_csa(sdata);
  1326. ieee80211_free_next_beacon(link);
  1327. /* turn off carrier for this interface and dependent VLANs */
  1328. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  1329. netif_carrier_off(vlan->dev);
  1330. if (ieee80211_num_beaconing_links(sdata) <= 1) {
  1331. netif_carrier_off(dev);
  1332. sdata->u.ap.active = false;
  1333. }
  1334. /* remove beacon and probe response */
  1335. RCU_INIT_POINTER(link->u.ap.beacon, NULL);
  1336. RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
  1337. RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
  1338. RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
  1339. kfree_rcu(old_beacon, rcu_head);
  1340. if (old_probe_resp)
  1341. kfree_rcu(old_probe_resp, rcu_head);
  1342. if (old_fils_discovery)
  1343. kfree_rcu(old_fils_discovery, rcu_head);
  1344. if (old_unsol_bcast_probe_resp)
  1345. kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
  1346. kfree(link_conf->ftmr_params);
  1347. link_conf->ftmr_params = NULL;
  1348. sdata->vif.mbssid_tx_vif = NULL;
  1349. link_conf->bssid_index = 0;
  1350. link_conf->nontransmitted = false;
  1351. link_conf->ema_ap = false;
  1352. link_conf->bssid_indicator = 0;
  1353. __sta_info_flush(sdata, true, link_id);
  1354. ieee80211_remove_link_keys(link, &keys);
  1355. if (!list_empty(&keys)) {
  1356. synchronize_net();
  1357. ieee80211_free_key_list(local, &keys);
  1358. }
  1359. link_conf->enable_beacon = false;
  1360. sdata->beacon_rate_set = false;
  1361. sdata->vif.cfg.ssid_len = 0;
  1362. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  1363. ieee80211_link_info_change_notify(sdata, link,
  1364. BSS_CHANGED_BEACON_ENABLED);
  1365. if (sdata->wdev.links[link_id].cac_started) {
  1366. chandef = link_conf->chanreq.oper;
  1367. wiphy_delayed_work_cancel(wiphy, &link->dfs_cac_timer_work);
  1368. cfg80211_cac_event(sdata->dev, &chandef,
  1369. NL80211_RADAR_CAC_ABORTED,
  1370. GFP_KERNEL, link_id);
  1371. }
  1372. drv_stop_ap(sdata->local, sdata, link_conf);
  1373. /* free all potentially still buffered bcast frames */
  1374. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  1375. ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
  1376. ieee80211_link_copy_chanctx_to_vlans(link, true);
  1377. ieee80211_link_release_channel(link);
  1378. return 0;
  1379. }
  1380. static int sta_apply_auth_flags(struct ieee80211_local *local,
  1381. struct sta_info *sta,
  1382. u32 mask, u32 set)
  1383. {
  1384. int ret;
  1385. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  1386. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  1387. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  1388. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  1389. if (ret)
  1390. return ret;
  1391. }
  1392. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  1393. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  1394. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  1395. /*
  1396. * When peer becomes associated, init rate control as
  1397. * well. Some drivers require rate control initialized
  1398. * before drv_sta_state() is called.
  1399. */
  1400. if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  1401. rate_control_rate_init(sta);
  1402. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  1403. if (ret)
  1404. return ret;
  1405. }
  1406. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1407. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  1408. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  1409. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1410. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  1411. else
  1412. ret = 0;
  1413. if (ret)
  1414. return ret;
  1415. }
  1416. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  1417. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  1418. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  1419. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  1420. if (ret)
  1421. return ret;
  1422. }
  1423. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  1424. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  1425. test_sta_flag(sta, WLAN_STA_AUTH)) {
  1426. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  1427. if (ret)
  1428. return ret;
  1429. }
  1430. return 0;
  1431. }
  1432. static void sta_apply_mesh_params(struct ieee80211_local *local,
  1433. struct sta_info *sta,
  1434. struct station_parameters *params)
  1435. {
  1436. #ifdef CONFIG_MAC80211_MESH
  1437. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1438. u64 changed = 0;
  1439. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  1440. switch (params->plink_state) {
  1441. case NL80211_PLINK_ESTAB:
  1442. if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
  1443. changed = mesh_plink_inc_estab_count(sdata);
  1444. sta->mesh->plink_state = params->plink_state;
  1445. sta->mesh->aid = params->peer_aid;
  1446. ieee80211_mps_sta_status_update(sta);
  1447. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1448. sdata->u.mesh.mshcfg.power_mode);
  1449. ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
  1450. /* init at low value */
  1451. ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
  1452. break;
  1453. case NL80211_PLINK_LISTEN:
  1454. case NL80211_PLINK_BLOCKED:
  1455. case NL80211_PLINK_OPN_SNT:
  1456. case NL80211_PLINK_OPN_RCVD:
  1457. case NL80211_PLINK_CNF_RCVD:
  1458. case NL80211_PLINK_HOLDING:
  1459. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  1460. changed = mesh_plink_dec_estab_count(sdata);
  1461. sta->mesh->plink_state = params->plink_state;
  1462. ieee80211_mps_sta_status_update(sta);
  1463. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1464. NL80211_MESH_POWER_UNKNOWN);
  1465. break;
  1466. default:
  1467. /* nothing */
  1468. break;
  1469. }
  1470. }
  1471. switch (params->plink_action) {
  1472. case NL80211_PLINK_ACTION_NO_ACTION:
  1473. /* nothing */
  1474. break;
  1475. case NL80211_PLINK_ACTION_OPEN:
  1476. changed |= mesh_plink_open(sta);
  1477. break;
  1478. case NL80211_PLINK_ACTION_BLOCK:
  1479. changed |= mesh_plink_block(sta);
  1480. break;
  1481. }
  1482. if (params->local_pm)
  1483. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1484. params->local_pm);
  1485. ieee80211_mbss_info_change_notify(sdata, changed);
  1486. #endif
  1487. }
  1488. enum sta_link_apply_mode {
  1489. STA_LINK_MODE_NEW,
  1490. STA_LINK_MODE_STA_MODIFY,
  1491. STA_LINK_MODE_LINK_MODIFY,
  1492. };
  1493. static int sta_link_apply_parameters(struct ieee80211_local *local,
  1494. struct sta_info *sta,
  1495. enum sta_link_apply_mode mode,
  1496. struct link_station_parameters *params)
  1497. {
  1498. struct ieee80211_supported_band *sband;
  1499. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1500. u32 link_id = params->link_id < 0 ? 0 : params->link_id;
  1501. struct ieee80211_link_data *link =
  1502. sdata_dereference(sdata->link[link_id], sdata);
  1503. struct link_sta_info *link_sta =
  1504. rcu_dereference_protected(sta->link[link_id],
  1505. lockdep_is_held(&local->hw.wiphy->mtx));
  1506. bool changes = params->link_mac ||
  1507. params->txpwr_set ||
  1508. params->supported_rates_len ||
  1509. params->ht_capa ||
  1510. params->vht_capa ||
  1511. params->he_capa ||
  1512. params->eht_capa ||
  1513. params->opmode_notif_used;
  1514. switch (mode) {
  1515. case STA_LINK_MODE_NEW:
  1516. if (!params->link_mac)
  1517. return -EINVAL;
  1518. break;
  1519. case STA_LINK_MODE_LINK_MODIFY:
  1520. break;
  1521. case STA_LINK_MODE_STA_MODIFY:
  1522. if (params->link_id >= 0)
  1523. break;
  1524. if (!changes)
  1525. return 0;
  1526. break;
  1527. }
  1528. if (!link || !link_sta)
  1529. return -EINVAL;
  1530. sband = ieee80211_get_link_sband(link);
  1531. if (!sband)
  1532. return -EINVAL;
  1533. if (params->link_mac) {
  1534. if (mode == STA_LINK_MODE_NEW) {
  1535. memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
  1536. memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
  1537. } else if (!ether_addr_equal(link_sta->addr,
  1538. params->link_mac)) {
  1539. return -EINVAL;
  1540. }
  1541. }
  1542. if (params->txpwr_set) {
  1543. int ret;
  1544. link_sta->pub->txpwr.type = params->txpwr.type;
  1545. if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
  1546. link_sta->pub->txpwr.power = params->txpwr.power;
  1547. ret = drv_sta_set_txpwr(local, sdata, sta);
  1548. if (ret)
  1549. return ret;
  1550. }
  1551. if (params->supported_rates &&
  1552. params->supported_rates_len) {
  1553. ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
  1554. sband, params->supported_rates,
  1555. params->supported_rates_len,
  1556. &link_sta->pub->supp_rates[sband->band]);
  1557. }
  1558. if (params->ht_capa)
  1559. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1560. params->ht_capa, link_sta);
  1561. /* VHT can override some HT caps such as the A-MSDU max length */
  1562. if (params->vht_capa)
  1563. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1564. params->vht_capa, NULL,
  1565. link_sta);
  1566. if (params->he_capa)
  1567. ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
  1568. (void *)params->he_capa,
  1569. params->he_capa_len,
  1570. (void *)params->he_6ghz_capa,
  1571. link_sta);
  1572. if (params->he_capa && params->eht_capa)
  1573. ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
  1574. (u8 *)params->he_capa,
  1575. params->he_capa_len,
  1576. params->eht_capa,
  1577. params->eht_capa_len,
  1578. link_sta);
  1579. ieee80211_sta_init_nss(link_sta);
  1580. if (params->opmode_notif_used) {
  1581. /* returned value is only needed for rc update, but the
  1582. * rc isn't initialized here yet, so ignore it
  1583. */
  1584. __ieee80211_vht_handle_opmode(sdata, link_sta,
  1585. params->opmode_notif,
  1586. sband->band);
  1587. }
  1588. return 0;
  1589. }
  1590. static int sta_apply_parameters(struct ieee80211_local *local,
  1591. struct sta_info *sta,
  1592. struct station_parameters *params)
  1593. {
  1594. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1595. u32 mask, set;
  1596. int ret = 0;
  1597. mask = params->sta_flags_mask;
  1598. set = params->sta_flags_set;
  1599. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1600. /*
  1601. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1602. * API but must follow AUTHENTICATED for driver state.
  1603. */
  1604. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1605. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1606. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1607. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1608. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1609. /*
  1610. * TDLS -- everything follows authorized, but
  1611. * only becoming authorized is possible, not
  1612. * going back
  1613. */
  1614. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1615. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1616. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1617. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1618. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1619. }
  1620. }
  1621. if (mask & BIT(NL80211_STA_FLAG_WME) &&
  1622. local->hw.queues >= IEEE80211_NUM_ACS)
  1623. sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
  1624. /* auth flags will be set later for TDLS,
  1625. * and for unassociated stations that move to associated */
  1626. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1627. !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  1628. (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
  1629. ret = sta_apply_auth_flags(local, sta, mask, set);
  1630. if (ret)
  1631. return ret;
  1632. }
  1633. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1634. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1635. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1636. else
  1637. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1638. }
  1639. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1640. sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
  1641. if (set & BIT(NL80211_STA_FLAG_MFP))
  1642. set_sta_flag(sta, WLAN_STA_MFP);
  1643. else
  1644. clear_sta_flag(sta, WLAN_STA_MFP);
  1645. }
  1646. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1647. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1648. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1649. else
  1650. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1651. }
  1652. if (mask & BIT(NL80211_STA_FLAG_SPP_AMSDU))
  1653. sta->sta.spp_amsdu = set & BIT(NL80211_STA_FLAG_SPP_AMSDU);
  1654. /* mark TDLS channel switch support, if the AP allows it */
  1655. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1656. !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
  1657. params->ext_capab_len >= 4 &&
  1658. params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
  1659. set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
  1660. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1661. !sdata->u.mgd.tdls_wider_bw_prohibited &&
  1662. ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
  1663. params->ext_capab_len >= 8 &&
  1664. params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
  1665. set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
  1666. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1667. sta->sta.uapsd_queues = params->uapsd_queues;
  1668. sta->sta.max_sp = params->max_sp;
  1669. }
  1670. ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
  1671. params->ext_capab_len);
  1672. /*
  1673. * cfg80211 validates this (1-2007) and allows setting the AID
  1674. * only when creating a new station entry
  1675. */
  1676. if (params->aid)
  1677. sta->sta.aid = params->aid;
  1678. /*
  1679. * Some of the following updates would be racy if called on an
  1680. * existing station, via ieee80211_change_station(). However,
  1681. * all such changes are rejected by cfg80211 except for updates
  1682. * changing the supported rates on an existing but not yet used
  1683. * TDLS peer.
  1684. */
  1685. if (params->listen_interval >= 0)
  1686. sta->listen_interval = params->listen_interval;
  1687. ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_STA_MODIFY,
  1688. &params->link_sta_params);
  1689. if (ret)
  1690. return ret;
  1691. if (params->support_p2p_ps >= 0)
  1692. sta->sta.support_p2p_ps = params->support_p2p_ps;
  1693. if (ieee80211_vif_is_mesh(&sdata->vif))
  1694. sta_apply_mesh_params(local, sta, params);
  1695. if (params->airtime_weight)
  1696. sta->airtime_weight = params->airtime_weight;
  1697. /* set the STA state after all sta info from usermode has been set */
  1698. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
  1699. set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
  1700. ret = sta_apply_auth_flags(local, sta, mask, set);
  1701. if (ret)
  1702. return ret;
  1703. }
  1704. /* Mark the STA as MLO if MLD MAC address is available */
  1705. if (params->link_sta_params.mld_mac)
  1706. sta->sta.mlo = true;
  1707. return 0;
  1708. }
  1709. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1710. const u8 *mac,
  1711. struct station_parameters *params)
  1712. {
  1713. struct ieee80211_local *local = wiphy_priv(wiphy);
  1714. struct sta_info *sta;
  1715. struct ieee80211_sub_if_data *sdata;
  1716. int err;
  1717. lockdep_assert_wiphy(local->hw.wiphy);
  1718. if (params->vlan) {
  1719. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1720. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1721. sdata->vif.type != NL80211_IFTYPE_AP)
  1722. return -EINVAL;
  1723. } else
  1724. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1725. if (ether_addr_equal(mac, sdata->vif.addr))
  1726. return -EINVAL;
  1727. if (!is_valid_ether_addr(mac))
  1728. return -EINVAL;
  1729. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
  1730. sdata->vif.type == NL80211_IFTYPE_STATION &&
  1731. !sdata->u.mgd.associated)
  1732. return -EINVAL;
  1733. /*
  1734. * If we have a link ID, it can be a non-MLO station on an AP MLD,
  1735. * but we need to have a link_mac in that case as well, so use the
  1736. * STA's MAC address in that case.
  1737. */
  1738. if (params->link_sta_params.link_id >= 0)
  1739. sta = sta_info_alloc_with_link(sdata, mac,
  1740. params->link_sta_params.link_id,
  1741. params->link_sta_params.link_mac ?: mac,
  1742. GFP_KERNEL);
  1743. else
  1744. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1745. if (!sta)
  1746. return -ENOMEM;
  1747. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1748. sta->sta.tdls = true;
  1749. /* Though the mutex is not needed here (since the station is not
  1750. * visible yet), sta_apply_parameters (and inner functions) require
  1751. * the mutex due to other paths.
  1752. */
  1753. err = sta_apply_parameters(local, sta, params);
  1754. if (err) {
  1755. sta_info_free(local, sta);
  1756. return err;
  1757. }
  1758. /*
  1759. * for TDLS and for unassociated station, rate control should be
  1760. * initialized only when rates are known and station is marked
  1761. * authorized/associated
  1762. */
  1763. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1764. test_sta_flag(sta, WLAN_STA_ASSOC))
  1765. rate_control_rate_init(sta);
  1766. return sta_info_insert(sta);
  1767. }
  1768. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1769. struct station_del_parameters *params)
  1770. {
  1771. struct ieee80211_sub_if_data *sdata;
  1772. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1773. if (params->mac)
  1774. return sta_info_destroy_addr_bss(sdata, params->mac);
  1775. sta_info_flush(sdata, params->link_id);
  1776. return 0;
  1777. }
  1778. static int ieee80211_change_station(struct wiphy *wiphy,
  1779. struct net_device *dev, const u8 *mac,
  1780. struct station_parameters *params)
  1781. {
  1782. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1783. struct ieee80211_local *local = wiphy_priv(wiphy);
  1784. struct sta_info *sta;
  1785. struct ieee80211_sub_if_data *vlansdata;
  1786. enum cfg80211_station_type statype;
  1787. int err;
  1788. lockdep_assert_wiphy(local->hw.wiphy);
  1789. sta = sta_info_get_bss(sdata, mac);
  1790. if (!sta)
  1791. return -ENOENT;
  1792. switch (sdata->vif.type) {
  1793. case NL80211_IFTYPE_MESH_POINT:
  1794. if (sdata->u.mesh.user_mpm)
  1795. statype = CFG80211_STA_MESH_PEER_USER;
  1796. else
  1797. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1798. break;
  1799. case NL80211_IFTYPE_ADHOC:
  1800. statype = CFG80211_STA_IBSS;
  1801. break;
  1802. case NL80211_IFTYPE_STATION:
  1803. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1804. statype = CFG80211_STA_AP_STA;
  1805. break;
  1806. }
  1807. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1808. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1809. else
  1810. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1811. break;
  1812. case NL80211_IFTYPE_AP:
  1813. case NL80211_IFTYPE_AP_VLAN:
  1814. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1815. statype = CFG80211_STA_AP_CLIENT;
  1816. else
  1817. statype = CFG80211_STA_AP_CLIENT_UNASSOC;
  1818. break;
  1819. default:
  1820. return -EOPNOTSUPP;
  1821. }
  1822. err = cfg80211_check_station_change(wiphy, params, statype);
  1823. if (err)
  1824. return err;
  1825. if (params->vlan && params->vlan != sta->sdata->dev) {
  1826. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1827. if (params->vlan->ieee80211_ptr->use_4addr) {
  1828. if (vlansdata->u.vlan.sta)
  1829. return -EBUSY;
  1830. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1831. __ieee80211_check_fast_rx_iface(vlansdata);
  1832. drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
  1833. }
  1834. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1835. sta->sdata->u.vlan.sta)
  1836. RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
  1837. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1838. ieee80211_vif_dec_num_mcast(sta->sdata);
  1839. sta->sdata = vlansdata;
  1840. ieee80211_check_fast_rx(sta);
  1841. ieee80211_check_fast_xmit(sta);
  1842. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
  1843. ieee80211_vif_inc_num_mcast(sta->sdata);
  1844. cfg80211_send_layer2_update(sta->sdata->dev,
  1845. sta->sta.addr);
  1846. }
  1847. }
  1848. err = sta_apply_parameters(local, sta, params);
  1849. if (err)
  1850. return err;
  1851. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1852. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1853. ieee80211_recalc_ps(local);
  1854. ieee80211_recalc_ps_vif(sdata);
  1855. }
  1856. return 0;
  1857. }
  1858. #ifdef CONFIG_MAC80211_MESH
  1859. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1860. const u8 *dst, const u8 *next_hop)
  1861. {
  1862. struct ieee80211_sub_if_data *sdata;
  1863. struct mesh_path *mpath;
  1864. struct sta_info *sta;
  1865. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1866. rcu_read_lock();
  1867. sta = sta_info_get(sdata, next_hop);
  1868. if (!sta) {
  1869. rcu_read_unlock();
  1870. return -ENOENT;
  1871. }
  1872. mpath = mesh_path_add(sdata, dst);
  1873. if (IS_ERR(mpath)) {
  1874. rcu_read_unlock();
  1875. return PTR_ERR(mpath);
  1876. }
  1877. mesh_path_fix_nexthop(mpath, sta);
  1878. rcu_read_unlock();
  1879. return 0;
  1880. }
  1881. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1882. const u8 *dst)
  1883. {
  1884. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1885. if (dst)
  1886. return mesh_path_del(sdata, dst);
  1887. mesh_path_flush_by_iface(sdata);
  1888. return 0;
  1889. }
  1890. static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
  1891. const u8 *dst, const u8 *next_hop)
  1892. {
  1893. struct ieee80211_sub_if_data *sdata;
  1894. struct mesh_path *mpath;
  1895. struct sta_info *sta;
  1896. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1897. rcu_read_lock();
  1898. sta = sta_info_get(sdata, next_hop);
  1899. if (!sta) {
  1900. rcu_read_unlock();
  1901. return -ENOENT;
  1902. }
  1903. mpath = mesh_path_lookup(sdata, dst);
  1904. if (!mpath) {
  1905. rcu_read_unlock();
  1906. return -ENOENT;
  1907. }
  1908. mesh_path_fix_nexthop(mpath, sta);
  1909. rcu_read_unlock();
  1910. return 0;
  1911. }
  1912. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1913. struct mpath_info *pinfo)
  1914. {
  1915. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1916. if (next_hop_sta)
  1917. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1918. else
  1919. eth_zero_addr(next_hop);
  1920. memset(pinfo, 0, sizeof(*pinfo));
  1921. pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
  1922. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1923. MPATH_INFO_SN |
  1924. MPATH_INFO_METRIC |
  1925. MPATH_INFO_EXPTIME |
  1926. MPATH_INFO_DISCOVERY_TIMEOUT |
  1927. MPATH_INFO_DISCOVERY_RETRIES |
  1928. MPATH_INFO_FLAGS |
  1929. MPATH_INFO_HOP_COUNT |
  1930. MPATH_INFO_PATH_CHANGE;
  1931. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1932. pinfo->sn = mpath->sn;
  1933. pinfo->metric = mpath->metric;
  1934. if (time_before(jiffies, mpath->exp_time))
  1935. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1936. pinfo->discovery_timeout =
  1937. jiffies_to_msecs(mpath->discovery_timeout);
  1938. pinfo->discovery_retries = mpath->discovery_retries;
  1939. if (mpath->flags & MESH_PATH_ACTIVE)
  1940. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1941. if (mpath->flags & MESH_PATH_RESOLVING)
  1942. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1943. if (mpath->flags & MESH_PATH_SN_VALID)
  1944. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1945. if (mpath->flags & MESH_PATH_FIXED)
  1946. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1947. if (mpath->flags & MESH_PATH_RESOLVED)
  1948. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1949. pinfo->hop_count = mpath->hop_count;
  1950. pinfo->path_change_count = mpath->path_change_count;
  1951. }
  1952. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1953. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1954. {
  1955. struct ieee80211_sub_if_data *sdata;
  1956. struct mesh_path *mpath;
  1957. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1958. rcu_read_lock();
  1959. mpath = mesh_path_lookup(sdata, dst);
  1960. if (!mpath) {
  1961. rcu_read_unlock();
  1962. return -ENOENT;
  1963. }
  1964. memcpy(dst, mpath->dst, ETH_ALEN);
  1965. mpath_set_pinfo(mpath, next_hop, pinfo);
  1966. rcu_read_unlock();
  1967. return 0;
  1968. }
  1969. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1970. int idx, u8 *dst, u8 *next_hop,
  1971. struct mpath_info *pinfo)
  1972. {
  1973. struct ieee80211_sub_if_data *sdata;
  1974. struct mesh_path *mpath;
  1975. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1976. rcu_read_lock();
  1977. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1978. if (!mpath) {
  1979. rcu_read_unlock();
  1980. return -ENOENT;
  1981. }
  1982. memcpy(dst, mpath->dst, ETH_ALEN);
  1983. mpath_set_pinfo(mpath, next_hop, pinfo);
  1984. rcu_read_unlock();
  1985. return 0;
  1986. }
  1987. static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
  1988. struct mpath_info *pinfo)
  1989. {
  1990. memset(pinfo, 0, sizeof(*pinfo));
  1991. memcpy(mpp, mpath->mpp, ETH_ALEN);
  1992. pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
  1993. }
  1994. static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
  1995. u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  1996. {
  1997. struct ieee80211_sub_if_data *sdata;
  1998. struct mesh_path *mpath;
  1999. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2000. rcu_read_lock();
  2001. mpath = mpp_path_lookup(sdata, dst);
  2002. if (!mpath) {
  2003. rcu_read_unlock();
  2004. return -ENOENT;
  2005. }
  2006. memcpy(dst, mpath->dst, ETH_ALEN);
  2007. mpp_set_pinfo(mpath, mpp, pinfo);
  2008. rcu_read_unlock();
  2009. return 0;
  2010. }
  2011. static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
  2012. int idx, u8 *dst, u8 *mpp,
  2013. struct mpath_info *pinfo)
  2014. {
  2015. struct ieee80211_sub_if_data *sdata;
  2016. struct mesh_path *mpath;
  2017. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2018. rcu_read_lock();
  2019. mpath = mpp_path_lookup_by_idx(sdata, idx);
  2020. if (!mpath) {
  2021. rcu_read_unlock();
  2022. return -ENOENT;
  2023. }
  2024. memcpy(dst, mpath->dst, ETH_ALEN);
  2025. mpp_set_pinfo(mpath, mpp, pinfo);
  2026. rcu_read_unlock();
  2027. return 0;
  2028. }
  2029. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  2030. struct net_device *dev,
  2031. struct mesh_config *conf)
  2032. {
  2033. struct ieee80211_sub_if_data *sdata;
  2034. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2035. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  2036. return 0;
  2037. }
  2038. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  2039. {
  2040. return (mask >> (parm-1)) & 0x1;
  2041. }
  2042. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  2043. const struct mesh_setup *setup)
  2044. {
  2045. u8 *new_ie;
  2046. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  2047. struct ieee80211_sub_if_data, u.mesh);
  2048. int i;
  2049. /* allocate information elements */
  2050. new_ie = NULL;
  2051. if (setup->ie_len) {
  2052. new_ie = kmemdup(setup->ie, setup->ie_len,
  2053. GFP_KERNEL);
  2054. if (!new_ie)
  2055. return -ENOMEM;
  2056. }
  2057. ifmsh->ie_len = setup->ie_len;
  2058. ifmsh->ie = new_ie;
  2059. /* now copy the rest of the setup parameters */
  2060. ifmsh->mesh_id_len = setup->mesh_id_len;
  2061. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  2062. ifmsh->mesh_sp_id = setup->sync_method;
  2063. ifmsh->mesh_pp_id = setup->path_sel_proto;
  2064. ifmsh->mesh_pm_id = setup->path_metric;
  2065. ifmsh->user_mpm = setup->user_mpm;
  2066. ifmsh->mesh_auth_id = setup->auth_id;
  2067. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  2068. ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
  2069. if (setup->is_authenticated)
  2070. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  2071. if (setup->is_secure)
  2072. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  2073. /* mcast rate setting in Mesh Node */
  2074. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  2075. sizeof(setup->mcast_rate));
  2076. sdata->vif.bss_conf.basic_rates = setup->basic_rates;
  2077. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  2078. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  2079. sdata->beacon_rate_set = false;
  2080. if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
  2081. NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
  2082. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  2083. sdata->beacon_rateidx_mask[i] =
  2084. setup->beacon_rate.control[i].legacy;
  2085. if (sdata->beacon_rateidx_mask[i])
  2086. sdata->beacon_rate_set = true;
  2087. }
  2088. }
  2089. return 0;
  2090. }
  2091. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  2092. struct net_device *dev, u32 mask,
  2093. const struct mesh_config *nconf)
  2094. {
  2095. struct mesh_config *conf;
  2096. struct ieee80211_sub_if_data *sdata;
  2097. struct ieee80211_if_mesh *ifmsh;
  2098. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2099. ifmsh = &sdata->u.mesh;
  2100. /* Set the config options which we are interested in setting */
  2101. conf = &(sdata->u.mesh.mshcfg);
  2102. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  2103. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  2104. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  2105. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  2106. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  2107. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  2108. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  2109. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  2110. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  2111. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  2112. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  2113. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  2114. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  2115. conf->element_ttl = nconf->element_ttl;
  2116. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  2117. if (ifmsh->user_mpm)
  2118. return -EBUSY;
  2119. conf->auto_open_plinks = nconf->auto_open_plinks;
  2120. }
  2121. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  2122. conf->dot11MeshNbrOffsetMaxNeighbor =
  2123. nconf->dot11MeshNbrOffsetMaxNeighbor;
  2124. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  2125. conf->dot11MeshHWMPmaxPREQretries =
  2126. nconf->dot11MeshHWMPmaxPREQretries;
  2127. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  2128. conf->path_refresh_time = nconf->path_refresh_time;
  2129. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  2130. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  2131. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  2132. conf->dot11MeshHWMPactivePathTimeout =
  2133. nconf->dot11MeshHWMPactivePathTimeout;
  2134. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  2135. conf->dot11MeshHWMPpreqMinInterval =
  2136. nconf->dot11MeshHWMPpreqMinInterval;
  2137. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  2138. conf->dot11MeshHWMPperrMinInterval =
  2139. nconf->dot11MeshHWMPperrMinInterval;
  2140. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  2141. mask))
  2142. conf->dot11MeshHWMPnetDiameterTraversalTime =
  2143. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  2144. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  2145. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  2146. ieee80211_mesh_root_setup(ifmsh);
  2147. }
  2148. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  2149. /* our current gate announcement implementation rides on root
  2150. * announcements, so require this ifmsh to also be a root node
  2151. * */
  2152. if (nconf->dot11MeshGateAnnouncementProtocol &&
  2153. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  2154. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  2155. ieee80211_mesh_root_setup(ifmsh);
  2156. }
  2157. conf->dot11MeshGateAnnouncementProtocol =
  2158. nconf->dot11MeshGateAnnouncementProtocol;
  2159. }
  2160. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  2161. conf->dot11MeshHWMPRannInterval =
  2162. nconf->dot11MeshHWMPRannInterval;
  2163. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  2164. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  2165. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  2166. /* our RSSI threshold implementation is supported only for
  2167. * devices that report signal in dBm.
  2168. */
  2169. if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
  2170. return -EOPNOTSUPP;
  2171. conf->rssi_threshold = nconf->rssi_threshold;
  2172. }
  2173. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  2174. conf->ht_opmode = nconf->ht_opmode;
  2175. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  2176. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  2177. BSS_CHANGED_HT);
  2178. }
  2179. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  2180. conf->dot11MeshHWMPactivePathToRootTimeout =
  2181. nconf->dot11MeshHWMPactivePathToRootTimeout;
  2182. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  2183. conf->dot11MeshHWMProotInterval =
  2184. nconf->dot11MeshHWMProotInterval;
  2185. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  2186. conf->dot11MeshHWMPconfirmationInterval =
  2187. nconf->dot11MeshHWMPconfirmationInterval;
  2188. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  2189. conf->power_mode = nconf->power_mode;
  2190. ieee80211_mps_local_status_update(sdata);
  2191. }
  2192. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  2193. conf->dot11MeshAwakeWindowDuration =
  2194. nconf->dot11MeshAwakeWindowDuration;
  2195. if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
  2196. conf->plink_timeout = nconf->plink_timeout;
  2197. if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
  2198. conf->dot11MeshConnectedToMeshGate =
  2199. nconf->dot11MeshConnectedToMeshGate;
  2200. if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
  2201. conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
  2202. if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
  2203. conf->dot11MeshConnectedToAuthServer =
  2204. nconf->dot11MeshConnectedToAuthServer;
  2205. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  2206. return 0;
  2207. }
  2208. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  2209. const struct mesh_config *conf,
  2210. const struct mesh_setup *setup)
  2211. {
  2212. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2213. struct ieee80211_chan_req chanreq = { .oper = setup->chandef };
  2214. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2215. int err;
  2216. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  2217. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  2218. err = copy_mesh_setup(ifmsh, setup);
  2219. if (err)
  2220. return err;
  2221. sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
  2222. /* can mesh use other SMPS modes? */
  2223. sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
  2224. sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
  2225. err = ieee80211_link_use_channel(&sdata->deflink, &chanreq,
  2226. IEEE80211_CHANCTX_SHARED);
  2227. if (err)
  2228. return err;
  2229. return ieee80211_start_mesh(sdata);
  2230. }
  2231. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  2232. {
  2233. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2234. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  2235. ieee80211_stop_mesh(sdata);
  2236. ieee80211_link_release_channel(&sdata->deflink);
  2237. kfree(sdata->u.mesh.ie);
  2238. return 0;
  2239. }
  2240. #endif
  2241. static int ieee80211_change_bss(struct wiphy *wiphy,
  2242. struct net_device *dev,
  2243. struct bss_parameters *params)
  2244. {
  2245. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2246. struct ieee80211_link_data *link;
  2247. struct ieee80211_supported_band *sband;
  2248. u64 changed = 0;
  2249. link = ieee80211_link_or_deflink(sdata, params->link_id, true);
  2250. if (IS_ERR(link))
  2251. return PTR_ERR(link);
  2252. if (!sdata_dereference(link->u.ap.beacon, sdata))
  2253. return -ENOENT;
  2254. sband = ieee80211_get_link_sband(link);
  2255. if (!sband)
  2256. return -EINVAL;
  2257. if (params->basic_rates) {
  2258. if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width,
  2259. wiphy->bands[sband->band],
  2260. params->basic_rates,
  2261. params->basic_rates_len,
  2262. &link->conf->basic_rates))
  2263. return -EINVAL;
  2264. changed |= BSS_CHANGED_BASIC_RATES;
  2265. ieee80211_check_rate_mask(link);
  2266. }
  2267. if (params->use_cts_prot >= 0) {
  2268. link->conf->use_cts_prot = params->use_cts_prot;
  2269. changed |= BSS_CHANGED_ERP_CTS_PROT;
  2270. }
  2271. if (params->use_short_preamble >= 0) {
  2272. link->conf->use_short_preamble = params->use_short_preamble;
  2273. changed |= BSS_CHANGED_ERP_PREAMBLE;
  2274. }
  2275. if (!link->conf->use_short_slot &&
  2276. (sband->band == NL80211_BAND_5GHZ ||
  2277. sband->band == NL80211_BAND_6GHZ)) {
  2278. link->conf->use_short_slot = true;
  2279. changed |= BSS_CHANGED_ERP_SLOT;
  2280. }
  2281. if (params->use_short_slot_time >= 0) {
  2282. link->conf->use_short_slot = params->use_short_slot_time;
  2283. changed |= BSS_CHANGED_ERP_SLOT;
  2284. }
  2285. if (params->ap_isolate >= 0) {
  2286. if (params->ap_isolate)
  2287. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  2288. else
  2289. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  2290. ieee80211_check_fast_rx_iface(sdata);
  2291. }
  2292. if (params->ht_opmode >= 0) {
  2293. link->conf->ht_operation_mode = (u16)params->ht_opmode;
  2294. changed |= BSS_CHANGED_HT;
  2295. }
  2296. if (params->p2p_ctwindow >= 0) {
  2297. link->conf->p2p_noa_attr.oppps_ctwindow &=
  2298. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  2299. link->conf->p2p_noa_attr.oppps_ctwindow |=
  2300. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  2301. changed |= BSS_CHANGED_P2P_PS;
  2302. }
  2303. if (params->p2p_opp_ps > 0) {
  2304. link->conf->p2p_noa_attr.oppps_ctwindow |=
  2305. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  2306. changed |= BSS_CHANGED_P2P_PS;
  2307. } else if (params->p2p_opp_ps == 0) {
  2308. link->conf->p2p_noa_attr.oppps_ctwindow &=
  2309. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  2310. changed |= BSS_CHANGED_P2P_PS;
  2311. }
  2312. ieee80211_link_info_change_notify(sdata, link, changed);
  2313. return 0;
  2314. }
  2315. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  2316. struct net_device *dev,
  2317. struct ieee80211_txq_params *params)
  2318. {
  2319. struct ieee80211_local *local = wiphy_priv(wiphy);
  2320. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2321. struct ieee80211_link_data *link =
  2322. ieee80211_link_or_deflink(sdata, params->link_id, true);
  2323. struct ieee80211_tx_queue_params p;
  2324. if (!local->ops->conf_tx)
  2325. return -EOPNOTSUPP;
  2326. if (local->hw.queues < IEEE80211_NUM_ACS)
  2327. return -EOPNOTSUPP;
  2328. if (IS_ERR(link))
  2329. return PTR_ERR(link);
  2330. memset(&p, 0, sizeof(p));
  2331. p.aifs = params->aifs;
  2332. p.cw_max = params->cwmax;
  2333. p.cw_min = params->cwmin;
  2334. p.txop = params->txop;
  2335. /*
  2336. * Setting tx queue params disables u-apsd because it's only
  2337. * called in master mode.
  2338. */
  2339. p.uapsd = false;
  2340. ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
  2341. link->tx_conf[params->ac] = p;
  2342. if (drv_conf_tx(local, link, params->ac, &p)) {
  2343. wiphy_debug(local->hw.wiphy,
  2344. "failed to set TX queue parameters for AC %d\n",
  2345. params->ac);
  2346. return -EINVAL;
  2347. }
  2348. ieee80211_link_info_change_notify(sdata, link,
  2349. BSS_CHANGED_QOS);
  2350. return 0;
  2351. }
  2352. #ifdef CONFIG_PM
  2353. static int ieee80211_suspend(struct wiphy *wiphy,
  2354. struct cfg80211_wowlan *wowlan)
  2355. {
  2356. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  2357. }
  2358. static int ieee80211_resume(struct wiphy *wiphy)
  2359. {
  2360. return __ieee80211_resume(wiphy_priv(wiphy));
  2361. }
  2362. #else
  2363. #define ieee80211_suspend NULL
  2364. #define ieee80211_resume NULL
  2365. #endif
  2366. static int ieee80211_scan(struct wiphy *wiphy,
  2367. struct cfg80211_scan_request *req)
  2368. {
  2369. struct ieee80211_sub_if_data *sdata;
  2370. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  2371. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  2372. case NL80211_IFTYPE_STATION:
  2373. case NL80211_IFTYPE_ADHOC:
  2374. case NL80211_IFTYPE_MESH_POINT:
  2375. case NL80211_IFTYPE_P2P_CLIENT:
  2376. case NL80211_IFTYPE_P2P_DEVICE:
  2377. break;
  2378. case NL80211_IFTYPE_P2P_GO:
  2379. if (sdata->local->ops->hw_scan)
  2380. break;
  2381. /*
  2382. * FIXME: implement NoA while scanning in software,
  2383. * for now fall through to allow scanning only when
  2384. * beaconing hasn't been configured yet
  2385. */
  2386. fallthrough;
  2387. case NL80211_IFTYPE_AP:
  2388. /*
  2389. * If the scan has been forced (and the driver supports
  2390. * forcing), don't care about being beaconing already.
  2391. * This will create problems to the attached stations (e.g. all
  2392. * the frames sent while scanning on other channel will be
  2393. * lost)
  2394. */
  2395. if (sdata->deflink.u.ap.beacon &&
  2396. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  2397. !(req->flags & NL80211_SCAN_FLAG_AP)))
  2398. return -EOPNOTSUPP;
  2399. break;
  2400. case NL80211_IFTYPE_NAN:
  2401. default:
  2402. return -EOPNOTSUPP;
  2403. }
  2404. return ieee80211_request_scan(sdata, req);
  2405. }
  2406. static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
  2407. {
  2408. ieee80211_scan_cancel(wiphy_priv(wiphy));
  2409. }
  2410. static int
  2411. ieee80211_sched_scan_start(struct wiphy *wiphy,
  2412. struct net_device *dev,
  2413. struct cfg80211_sched_scan_request *req)
  2414. {
  2415. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2416. if (!sdata->local->ops->sched_scan_start)
  2417. return -EOPNOTSUPP;
  2418. return ieee80211_request_sched_scan_start(sdata, req);
  2419. }
  2420. static int
  2421. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
  2422. u64 reqid)
  2423. {
  2424. struct ieee80211_local *local = wiphy_priv(wiphy);
  2425. if (!local->ops->sched_scan_stop)
  2426. return -EOPNOTSUPP;
  2427. return ieee80211_request_sched_scan_stop(local);
  2428. }
  2429. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  2430. struct cfg80211_auth_request *req)
  2431. {
  2432. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  2433. }
  2434. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  2435. struct cfg80211_assoc_request *req)
  2436. {
  2437. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  2438. }
  2439. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  2440. struct cfg80211_deauth_request *req)
  2441. {
  2442. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  2443. }
  2444. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  2445. struct cfg80211_disassoc_request *req)
  2446. {
  2447. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  2448. }
  2449. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  2450. struct cfg80211_ibss_params *params)
  2451. {
  2452. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  2453. }
  2454. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  2455. {
  2456. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  2457. }
  2458. static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
  2459. struct ocb_setup *setup)
  2460. {
  2461. return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
  2462. }
  2463. static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
  2464. {
  2465. return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  2466. }
  2467. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  2468. int rate[NUM_NL80211_BANDS])
  2469. {
  2470. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2471. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  2472. sizeof(int) * NUM_NL80211_BANDS);
  2473. if (ieee80211_sdata_running(sdata))
  2474. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  2475. BSS_CHANGED_MCAST_RATE);
  2476. return 0;
  2477. }
  2478. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  2479. {
  2480. struct ieee80211_local *local = wiphy_priv(wiphy);
  2481. int err;
  2482. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  2483. ieee80211_check_fast_xmit_all(local);
  2484. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  2485. if (err) {
  2486. ieee80211_check_fast_xmit_all(local);
  2487. return err;
  2488. }
  2489. }
  2490. if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
  2491. (changed & WIPHY_PARAM_DYN_ACK)) {
  2492. s16 coverage_class;
  2493. coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
  2494. wiphy->coverage_class : -1;
  2495. err = drv_set_coverage_class(local, coverage_class);
  2496. if (err)
  2497. return err;
  2498. }
  2499. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  2500. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  2501. if (err)
  2502. return err;
  2503. }
  2504. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  2505. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  2506. return -EINVAL;
  2507. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  2508. }
  2509. if (changed & WIPHY_PARAM_RETRY_LONG) {
  2510. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  2511. return -EINVAL;
  2512. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  2513. }
  2514. if (changed &
  2515. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  2516. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  2517. if (changed & (WIPHY_PARAM_TXQ_LIMIT |
  2518. WIPHY_PARAM_TXQ_MEMORY_LIMIT |
  2519. WIPHY_PARAM_TXQ_QUANTUM))
  2520. ieee80211_txq_set_params(local);
  2521. return 0;
  2522. }
  2523. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  2524. struct wireless_dev *wdev,
  2525. enum nl80211_tx_power_setting type, int mbm)
  2526. {
  2527. struct ieee80211_local *local = wiphy_priv(wiphy);
  2528. struct ieee80211_sub_if_data *sdata;
  2529. enum nl80211_tx_power_setting txp_type = type;
  2530. bool update_txp_type = false;
  2531. bool has_monitor = false;
  2532. int old_power = local->user_power_level;
  2533. lockdep_assert_wiphy(local->hw.wiphy);
  2534. if (wdev) {
  2535. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2536. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2537. if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF))
  2538. return -EOPNOTSUPP;
  2539. sdata = wiphy_dereference(local->hw.wiphy,
  2540. local->monitor_sdata);
  2541. if (!sdata)
  2542. return -EOPNOTSUPP;
  2543. }
  2544. switch (type) {
  2545. case NL80211_TX_POWER_AUTOMATIC:
  2546. sdata->deflink.user_power_level =
  2547. IEEE80211_UNSET_POWER_LEVEL;
  2548. txp_type = NL80211_TX_POWER_LIMITED;
  2549. break;
  2550. case NL80211_TX_POWER_LIMITED:
  2551. case NL80211_TX_POWER_FIXED:
  2552. if (mbm < 0 || (mbm % 100))
  2553. return -EOPNOTSUPP;
  2554. sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
  2555. break;
  2556. }
  2557. if (txp_type != sdata->vif.bss_conf.txpower_type) {
  2558. update_txp_type = true;
  2559. sdata->vif.bss_conf.txpower_type = txp_type;
  2560. }
  2561. ieee80211_recalc_txpower(sdata, update_txp_type);
  2562. return 0;
  2563. }
  2564. switch (type) {
  2565. case NL80211_TX_POWER_AUTOMATIC:
  2566. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  2567. txp_type = NL80211_TX_POWER_LIMITED;
  2568. break;
  2569. case NL80211_TX_POWER_LIMITED:
  2570. case NL80211_TX_POWER_FIXED:
  2571. if (mbm < 0 || (mbm % 100))
  2572. return -EOPNOTSUPP;
  2573. local->user_power_level = MBM_TO_DBM(mbm);
  2574. break;
  2575. }
  2576. list_for_each_entry(sdata, &local->interfaces, list) {
  2577. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2578. has_monitor = true;
  2579. continue;
  2580. }
  2581. sdata->deflink.user_power_level = local->user_power_level;
  2582. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2583. update_txp_type = true;
  2584. sdata->vif.bss_conf.txpower_type = txp_type;
  2585. }
  2586. list_for_each_entry(sdata, &local->interfaces, list) {
  2587. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  2588. continue;
  2589. ieee80211_recalc_txpower(sdata, update_txp_type);
  2590. }
  2591. if (has_monitor) {
  2592. sdata = wiphy_dereference(local->hw.wiphy,
  2593. local->monitor_sdata);
  2594. if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) {
  2595. sdata->deflink.user_power_level = local->user_power_level;
  2596. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2597. update_txp_type = true;
  2598. sdata->vif.bss_conf.txpower_type = txp_type;
  2599. ieee80211_recalc_txpower(sdata, update_txp_type);
  2600. }
  2601. }
  2602. if (local->emulate_chanctx &&
  2603. (old_power != local->user_power_level))
  2604. ieee80211_hw_conf_chan(local);
  2605. return 0;
  2606. }
  2607. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  2608. struct wireless_dev *wdev,
  2609. int *dbm)
  2610. {
  2611. struct ieee80211_local *local = wiphy_priv(wiphy);
  2612. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2613. if (local->ops->get_txpower &&
  2614. (sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  2615. return drv_get_txpower(local, sdata, dbm);
  2616. if (local->emulate_chanctx)
  2617. *dbm = local->hw.conf.power_level;
  2618. else
  2619. *dbm = sdata->vif.bss_conf.txpower;
  2620. /* INT_MIN indicates no power level was set yet */
  2621. if (*dbm == INT_MIN)
  2622. return -EINVAL;
  2623. return 0;
  2624. }
  2625. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  2626. {
  2627. struct ieee80211_local *local = wiphy_priv(wiphy);
  2628. drv_rfkill_poll(local);
  2629. }
  2630. #ifdef CONFIG_NL80211_TESTMODE
  2631. static int ieee80211_testmode_cmd(struct wiphy *wiphy,
  2632. struct wireless_dev *wdev,
  2633. void *data, int len)
  2634. {
  2635. struct ieee80211_local *local = wiphy_priv(wiphy);
  2636. struct ieee80211_vif *vif = NULL;
  2637. if (!local->ops->testmode_cmd)
  2638. return -EOPNOTSUPP;
  2639. if (wdev) {
  2640. struct ieee80211_sub_if_data *sdata;
  2641. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2642. if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
  2643. vif = &sdata->vif;
  2644. }
  2645. return local->ops->testmode_cmd(&local->hw, vif, data, len);
  2646. }
  2647. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  2648. struct sk_buff *skb,
  2649. struct netlink_callback *cb,
  2650. void *data, int len)
  2651. {
  2652. struct ieee80211_local *local = wiphy_priv(wiphy);
  2653. if (!local->ops->testmode_dump)
  2654. return -EOPNOTSUPP;
  2655. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  2656. }
  2657. #endif
  2658. int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
  2659. struct ieee80211_link_data *link,
  2660. enum ieee80211_smps_mode smps_mode)
  2661. {
  2662. const u8 *ap;
  2663. enum ieee80211_smps_mode old_req;
  2664. int err;
  2665. struct sta_info *sta;
  2666. bool tdls_peer_found = false;
  2667. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  2668. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
  2669. return -EINVAL;
  2670. if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
  2671. return 0;
  2672. old_req = link->u.mgd.req_smps;
  2673. link->u.mgd.req_smps = smps_mode;
  2674. /* The driver indicated that EML is enabled for the interface, which
  2675. * implies that SMPS flows towards the AP should be stopped.
  2676. */
  2677. if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE)
  2678. return 0;
  2679. if (old_req == smps_mode &&
  2680. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  2681. return 0;
  2682. /*
  2683. * If not associated, or current association is not an HT
  2684. * association, there's no need to do anything, just store
  2685. * the new value until we associate.
  2686. */
  2687. if (!sdata->u.mgd.associated ||
  2688. link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT)
  2689. return 0;
  2690. ap = sdata->vif.cfg.ap_addr;
  2691. rcu_read_lock();
  2692. list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
  2693. if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
  2694. !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2695. continue;
  2696. tdls_peer_found = true;
  2697. break;
  2698. }
  2699. rcu_read_unlock();
  2700. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  2701. if (tdls_peer_found || !sdata->u.mgd.powersave)
  2702. smps_mode = IEEE80211_SMPS_OFF;
  2703. else
  2704. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2705. }
  2706. /* send SM PS frame to AP */
  2707. err = ieee80211_send_smps_action(sdata, smps_mode,
  2708. ap, ap,
  2709. ieee80211_vif_is_mld(&sdata->vif) ?
  2710. link->link_id : -1);
  2711. if (err)
  2712. link->u.mgd.req_smps = old_req;
  2713. else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
  2714. ieee80211_teardown_tdls_peers(link);
  2715. return err;
  2716. }
  2717. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2718. bool enabled, int timeout)
  2719. {
  2720. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2721. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2722. unsigned int link_id;
  2723. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2724. return -EOPNOTSUPP;
  2725. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
  2726. return -EOPNOTSUPP;
  2727. if (enabled == sdata->u.mgd.powersave &&
  2728. timeout == local->dynamic_ps_forced_timeout)
  2729. return 0;
  2730. sdata->u.mgd.powersave = enabled;
  2731. local->dynamic_ps_forced_timeout = timeout;
  2732. /* no change, but if automatic follow powersave */
  2733. for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
  2734. struct ieee80211_link_data *link;
  2735. link = sdata_dereference(sdata->link[link_id], sdata);
  2736. if (!link)
  2737. continue;
  2738. __ieee80211_request_smps_mgd(sdata, link,
  2739. link->u.mgd.req_smps);
  2740. }
  2741. if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  2742. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2743. ieee80211_recalc_ps(local);
  2744. ieee80211_recalc_ps_vif(sdata);
  2745. ieee80211_check_fast_rx_iface(sdata);
  2746. return 0;
  2747. }
  2748. static void ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data *sdata,
  2749. struct ieee80211_link_data *link,
  2750. s32 rssi_thold, u32 rssi_hyst,
  2751. s32 rssi_low, s32 rssi_high)
  2752. {
  2753. struct ieee80211_bss_conf *conf;
  2754. if (!link || !link->conf)
  2755. return;
  2756. conf = link->conf;
  2757. if (rssi_thold && rssi_hyst &&
  2758. rssi_thold == conf->cqm_rssi_thold &&
  2759. rssi_hyst == conf->cqm_rssi_hyst)
  2760. return;
  2761. conf->cqm_rssi_thold = rssi_thold;
  2762. conf->cqm_rssi_hyst = rssi_hyst;
  2763. conf->cqm_rssi_low = rssi_low;
  2764. conf->cqm_rssi_high = rssi_high;
  2765. link->u.mgd.last_cqm_event_signal = 0;
  2766. if (!ieee80211_vif_link_active(&sdata->vif, link->link_id))
  2767. return;
  2768. if (sdata->u.mgd.associated &&
  2769. (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
  2770. ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_CQM);
  2771. }
  2772. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  2773. struct net_device *dev,
  2774. s32 rssi_thold, u32 rssi_hyst)
  2775. {
  2776. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2777. struct ieee80211_vif *vif = &sdata->vif;
  2778. int link_id;
  2779. if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER &&
  2780. !(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
  2781. return -EOPNOTSUPP;
  2782. /* For MLD, handle CQM change on all the active links */
  2783. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  2784. struct ieee80211_link_data *link =
  2785. sdata_dereference(sdata->link[link_id], sdata);
  2786. ieee80211_set_cqm_rssi_link(sdata, link, rssi_thold, rssi_hyst,
  2787. 0, 0);
  2788. }
  2789. return 0;
  2790. }
  2791. static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
  2792. struct net_device *dev,
  2793. s32 rssi_low, s32 rssi_high)
  2794. {
  2795. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2796. struct ieee80211_vif *vif = &sdata->vif;
  2797. int link_id;
  2798. if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)
  2799. return -EOPNOTSUPP;
  2800. /* For MLD, handle CQM change on all the active links */
  2801. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  2802. struct ieee80211_link_data *link =
  2803. sdata_dereference(sdata->link[link_id], sdata);
  2804. ieee80211_set_cqm_rssi_link(sdata, link, 0, 0,
  2805. rssi_low, rssi_high);
  2806. }
  2807. return 0;
  2808. }
  2809. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  2810. struct net_device *dev,
  2811. unsigned int link_id,
  2812. const u8 *addr,
  2813. const struct cfg80211_bitrate_mask *mask)
  2814. {
  2815. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2816. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2817. int i, ret;
  2818. if (!ieee80211_sdata_running(sdata))
  2819. return -ENETDOWN;
  2820. /*
  2821. * If active validate the setting and reject it if it doesn't leave
  2822. * at least one basic rate usable, since we really have to be able
  2823. * to send something, and if we're an AP we have to be able to do
  2824. * so at a basic rate so that all clients can receive it.
  2825. */
  2826. if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
  2827. sdata->vif.bss_conf.chanreq.oper.chan) {
  2828. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  2829. enum nl80211_band band;
  2830. band = sdata->vif.bss_conf.chanreq.oper.chan->band;
  2831. if (!(mask->control[band].legacy & basic_rates))
  2832. return -EINVAL;
  2833. }
  2834. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
  2835. ret = drv_set_bitrate_mask(local, sdata, mask);
  2836. if (ret)
  2837. return ret;
  2838. }
  2839. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  2840. struct ieee80211_supported_band *sband = wiphy->bands[i];
  2841. int j;
  2842. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  2843. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
  2844. sizeof(mask->control[i].ht_mcs));
  2845. memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
  2846. mask->control[i].vht_mcs,
  2847. sizeof(mask->control[i].vht_mcs));
  2848. sdata->rc_has_mcs_mask[i] = false;
  2849. sdata->rc_has_vht_mcs_mask[i] = false;
  2850. if (!sband)
  2851. continue;
  2852. for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
  2853. if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
  2854. sdata->rc_has_mcs_mask[i] = true;
  2855. break;
  2856. }
  2857. }
  2858. for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
  2859. if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
  2860. sdata->rc_has_vht_mcs_mask[i] = true;
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. return 0;
  2866. }
  2867. static int ieee80211_start_radar_detection(struct wiphy *wiphy,
  2868. struct net_device *dev,
  2869. struct cfg80211_chan_def *chandef,
  2870. u32 cac_time_ms, int link_id)
  2871. {
  2872. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2873. struct ieee80211_chan_req chanreq = { .oper = *chandef };
  2874. struct ieee80211_local *local = sdata->local;
  2875. struct ieee80211_link_data *link_data;
  2876. int err;
  2877. lockdep_assert_wiphy(local->hw.wiphy);
  2878. if (!list_empty(&local->roc_list) || local->scanning)
  2879. return -EBUSY;
  2880. link_data = sdata_dereference(sdata->link[link_id], sdata);
  2881. if (!link_data)
  2882. return -ENOLINK;
  2883. /* whatever, but channel contexts should not complain about that one */
  2884. link_data->smps_mode = IEEE80211_SMPS_OFF;
  2885. link_data->needed_rx_chains = local->rx_chains;
  2886. err = ieee80211_link_use_channel(link_data, &chanreq,
  2887. IEEE80211_CHANCTX_SHARED);
  2888. if (err)
  2889. return err;
  2890. wiphy_delayed_work_queue(wiphy, &link_data->dfs_cac_timer_work,
  2891. msecs_to_jiffies(cac_time_ms));
  2892. return 0;
  2893. }
  2894. static void ieee80211_end_cac(struct wiphy *wiphy,
  2895. struct net_device *dev, unsigned int link_id)
  2896. {
  2897. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2898. struct ieee80211_local *local = sdata->local;
  2899. struct ieee80211_link_data *link_data;
  2900. lockdep_assert_wiphy(local->hw.wiphy);
  2901. list_for_each_entry(sdata, &local->interfaces, list) {
  2902. link_data = sdata_dereference(sdata->link[link_id], sdata);
  2903. if (!link_data)
  2904. continue;
  2905. wiphy_delayed_work_cancel(wiphy,
  2906. &link_data->dfs_cac_timer_work);
  2907. if (sdata->wdev.links[link_id].cac_started) {
  2908. ieee80211_link_release_channel(link_data);
  2909. sdata->wdev.links[link_id].cac_started = false;
  2910. }
  2911. }
  2912. }
  2913. static struct cfg80211_beacon_data *
  2914. cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
  2915. {
  2916. struct cfg80211_beacon_data *new_beacon;
  2917. u8 *pos;
  2918. int len;
  2919. len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
  2920. beacon->proberesp_ies_len + beacon->assocresp_ies_len +
  2921. beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
  2922. if (beacon->mbssid_ies)
  2923. len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
  2924. beacon->rnr_ies,
  2925. beacon->mbssid_ies->cnt);
  2926. new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
  2927. if (!new_beacon)
  2928. return NULL;
  2929. if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
  2930. new_beacon->mbssid_ies =
  2931. kzalloc(struct_size(new_beacon->mbssid_ies,
  2932. elem, beacon->mbssid_ies->cnt),
  2933. GFP_KERNEL);
  2934. if (!new_beacon->mbssid_ies) {
  2935. kfree(new_beacon);
  2936. return NULL;
  2937. }
  2938. if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
  2939. new_beacon->rnr_ies =
  2940. kzalloc(struct_size(new_beacon->rnr_ies,
  2941. elem, beacon->rnr_ies->cnt),
  2942. GFP_KERNEL);
  2943. if (!new_beacon->rnr_ies) {
  2944. kfree(new_beacon->mbssid_ies);
  2945. kfree(new_beacon);
  2946. return NULL;
  2947. }
  2948. }
  2949. }
  2950. pos = (u8 *)(new_beacon + 1);
  2951. if (beacon->head_len) {
  2952. new_beacon->head_len = beacon->head_len;
  2953. new_beacon->head = pos;
  2954. memcpy(pos, beacon->head, beacon->head_len);
  2955. pos += beacon->head_len;
  2956. }
  2957. if (beacon->tail_len) {
  2958. new_beacon->tail_len = beacon->tail_len;
  2959. new_beacon->tail = pos;
  2960. memcpy(pos, beacon->tail, beacon->tail_len);
  2961. pos += beacon->tail_len;
  2962. }
  2963. if (beacon->beacon_ies_len) {
  2964. new_beacon->beacon_ies_len = beacon->beacon_ies_len;
  2965. new_beacon->beacon_ies = pos;
  2966. memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
  2967. pos += beacon->beacon_ies_len;
  2968. }
  2969. if (beacon->proberesp_ies_len) {
  2970. new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
  2971. new_beacon->proberesp_ies = pos;
  2972. memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
  2973. pos += beacon->proberesp_ies_len;
  2974. }
  2975. if (beacon->assocresp_ies_len) {
  2976. new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
  2977. new_beacon->assocresp_ies = pos;
  2978. memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
  2979. pos += beacon->assocresp_ies_len;
  2980. }
  2981. if (beacon->probe_resp_len) {
  2982. new_beacon->probe_resp_len = beacon->probe_resp_len;
  2983. new_beacon->probe_resp = pos;
  2984. memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
  2985. pos += beacon->probe_resp_len;
  2986. }
  2987. if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
  2988. pos += ieee80211_copy_mbssid_beacon(pos,
  2989. new_beacon->mbssid_ies,
  2990. beacon->mbssid_ies);
  2991. if (beacon->rnr_ies && beacon->rnr_ies->cnt)
  2992. pos += ieee80211_copy_rnr_beacon(pos,
  2993. new_beacon->rnr_ies,
  2994. beacon->rnr_ies);
  2995. }
  2996. /* might copy -1, meaning no changes requested */
  2997. new_beacon->ftm_responder = beacon->ftm_responder;
  2998. if (beacon->lci) {
  2999. new_beacon->lci_len = beacon->lci_len;
  3000. new_beacon->lci = pos;
  3001. memcpy(pos, beacon->lci, beacon->lci_len);
  3002. pos += beacon->lci_len;
  3003. }
  3004. if (beacon->civicloc) {
  3005. new_beacon->civicloc_len = beacon->civicloc_len;
  3006. new_beacon->civicloc = pos;
  3007. memcpy(pos, beacon->civicloc, beacon->civicloc_len);
  3008. pos += beacon->civicloc_len;
  3009. }
  3010. return new_beacon;
  3011. }
  3012. void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id)
  3013. {
  3014. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3015. struct ieee80211_local *local = sdata->local;
  3016. struct ieee80211_link_data *link_data;
  3017. if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
  3018. return;
  3019. rcu_read_lock();
  3020. link_data = rcu_dereference(sdata->link[link_id]);
  3021. if (WARN_ON(!link_data)) {
  3022. rcu_read_unlock();
  3023. return;
  3024. }
  3025. /* TODO: MBSSID with MLO changes */
  3026. if (vif->mbssid_tx_vif == vif) {
  3027. /* Trigger ieee80211_csa_finish() on the non-transmitting
  3028. * interfaces when channel switch is received on
  3029. * transmitting interface
  3030. */
  3031. struct ieee80211_sub_if_data *iter;
  3032. list_for_each_entry_rcu(iter, &local->interfaces, list) {
  3033. if (!ieee80211_sdata_running(iter))
  3034. continue;
  3035. if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
  3036. continue;
  3037. wiphy_work_queue(iter->local->hw.wiphy,
  3038. &iter->deflink.csa.finalize_work);
  3039. }
  3040. }
  3041. wiphy_work_queue(local->hw.wiphy, &link_data->csa.finalize_work);
  3042. rcu_read_unlock();
  3043. }
  3044. EXPORT_SYMBOL(ieee80211_csa_finish);
  3045. void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif)
  3046. {
  3047. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3048. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3049. struct ieee80211_local *local = sdata->local;
  3050. sdata_info(sdata, "channel switch failed, disconnecting\n");
  3051. wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work);
  3052. }
  3053. EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
  3054. static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data,
  3055. u64 *changed)
  3056. {
  3057. struct ieee80211_sub_if_data *sdata = link_data->sdata;
  3058. int err;
  3059. switch (sdata->vif.type) {
  3060. case NL80211_IFTYPE_AP:
  3061. if (!link_data->u.ap.next_beacon)
  3062. return -EINVAL;
  3063. err = ieee80211_assign_beacon(sdata, link_data,
  3064. link_data->u.ap.next_beacon,
  3065. NULL, NULL, changed);
  3066. ieee80211_free_next_beacon(link_data);
  3067. if (err < 0)
  3068. return err;
  3069. break;
  3070. case NL80211_IFTYPE_ADHOC:
  3071. err = ieee80211_ibss_finish_csa(sdata, changed);
  3072. if (err < 0)
  3073. return err;
  3074. break;
  3075. #ifdef CONFIG_MAC80211_MESH
  3076. case NL80211_IFTYPE_MESH_POINT:
  3077. err = ieee80211_mesh_finish_csa(sdata, changed);
  3078. if (err < 0)
  3079. return err;
  3080. break;
  3081. #endif
  3082. default:
  3083. WARN_ON(1);
  3084. return -EINVAL;
  3085. }
  3086. return 0;
  3087. }
  3088. static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
  3089. {
  3090. struct ieee80211_sub_if_data *sdata = link_data->sdata;
  3091. struct ieee80211_local *local = sdata->local;
  3092. struct ieee80211_bss_conf *link_conf = link_data->conf;
  3093. u64 changed = 0;
  3094. int err;
  3095. lockdep_assert_wiphy(local->hw.wiphy);
  3096. /*
  3097. * using reservation isn't immediate as it may be deferred until later
  3098. * with multi-vif. once reservation is complete it will re-schedule the
  3099. * work with no reserved_chanctx so verify chandef to check if it
  3100. * completed successfully
  3101. */
  3102. if (link_data->reserved_chanctx) {
  3103. /*
  3104. * with multi-vif csa driver may call ieee80211_csa_finish()
  3105. * many times while waiting for other interfaces to use their
  3106. * reservations
  3107. */
  3108. if (link_data->reserved_ready)
  3109. return 0;
  3110. return ieee80211_link_use_reserved_context(link_data);
  3111. }
  3112. if (!cfg80211_chandef_identical(&link_conf->chanreq.oper,
  3113. &link_data->csa.chanreq.oper))
  3114. return -EINVAL;
  3115. link_conf->csa_active = false;
  3116. err = ieee80211_set_after_csa_beacon(link_data, &changed);
  3117. if (err)
  3118. return err;
  3119. ieee80211_link_info_change_notify(sdata, link_data, changed);
  3120. ieee80211_vif_unblock_queues_csa(sdata);
  3121. err = drv_post_channel_switch(link_data);
  3122. if (err)
  3123. return err;
  3124. cfg80211_ch_switch_notify(sdata->dev, &link_data->csa.chanreq.oper,
  3125. link_data->link_id);
  3126. return 0;
  3127. }
  3128. static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data)
  3129. {
  3130. struct ieee80211_sub_if_data *sdata = link_data->sdata;
  3131. if (__ieee80211_csa_finalize(link_data)) {
  3132. sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n",
  3133. link_data->link_id);
  3134. cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
  3135. GFP_KERNEL);
  3136. }
  3137. }
  3138. void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work)
  3139. {
  3140. struct ieee80211_link_data *link =
  3141. container_of(work, struct ieee80211_link_data, csa.finalize_work);
  3142. struct ieee80211_sub_if_data *sdata = link->sdata;
  3143. struct ieee80211_local *local = sdata->local;
  3144. lockdep_assert_wiphy(local->hw.wiphy);
  3145. /* AP might have been stopped while waiting for the lock. */
  3146. if (!link->conf->csa_active)
  3147. return;
  3148. if (!ieee80211_sdata_running(sdata))
  3149. return;
  3150. ieee80211_csa_finalize(link);
  3151. }
  3152. static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data,
  3153. struct cfg80211_csa_settings *params,
  3154. u64 *changed)
  3155. {
  3156. struct ieee80211_sub_if_data *sdata = link_data->sdata;
  3157. struct ieee80211_csa_settings csa = {};
  3158. int err;
  3159. switch (sdata->vif.type) {
  3160. case NL80211_IFTYPE_AP:
  3161. link_data->u.ap.next_beacon =
  3162. cfg80211_beacon_dup(&params->beacon_after);
  3163. if (!link_data->u.ap.next_beacon)
  3164. return -ENOMEM;
  3165. /*
  3166. * With a count of 0, we don't have to wait for any
  3167. * TBTT before switching, so complete the CSA
  3168. * immediately. In theory, with a count == 1 we
  3169. * should delay the switch until just before the next
  3170. * TBTT, but that would complicate things so we switch
  3171. * immediately too. If we would delay the switch
  3172. * until the next TBTT, we would have to set the probe
  3173. * response here.
  3174. *
  3175. * TODO: A channel switch with count <= 1 without
  3176. * sending a CSA action frame is kind of useless,
  3177. * because the clients won't know we're changing
  3178. * channels. The action frame must be implemented
  3179. * either here or in the userspace.
  3180. */
  3181. if (params->count <= 1)
  3182. break;
  3183. if ((params->n_counter_offsets_beacon >
  3184. IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
  3185. (params->n_counter_offsets_presp >
  3186. IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
  3187. ieee80211_free_next_beacon(link_data);
  3188. return -EINVAL;
  3189. }
  3190. csa.counter_offsets_beacon = params->counter_offsets_beacon;
  3191. csa.counter_offsets_presp = params->counter_offsets_presp;
  3192. csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
  3193. csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
  3194. csa.count = params->count;
  3195. err = ieee80211_assign_beacon(sdata, link_data,
  3196. &params->beacon_csa, &csa,
  3197. NULL, changed);
  3198. if (err < 0) {
  3199. ieee80211_free_next_beacon(link_data);
  3200. return err;
  3201. }
  3202. break;
  3203. case NL80211_IFTYPE_ADHOC:
  3204. if (!sdata->vif.cfg.ibss_joined)
  3205. return -EINVAL;
  3206. if (params->chandef.width != sdata->u.ibss.chandef.width)
  3207. return -EINVAL;
  3208. switch (params->chandef.width) {
  3209. case NL80211_CHAN_WIDTH_40:
  3210. if (cfg80211_get_chandef_type(&params->chandef) !=
  3211. cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
  3212. return -EINVAL;
  3213. break;
  3214. case NL80211_CHAN_WIDTH_5:
  3215. case NL80211_CHAN_WIDTH_10:
  3216. case NL80211_CHAN_WIDTH_20_NOHT:
  3217. case NL80211_CHAN_WIDTH_20:
  3218. break;
  3219. default:
  3220. return -EINVAL;
  3221. }
  3222. /* changes into another band are not supported */
  3223. if (sdata->u.ibss.chandef.chan->band !=
  3224. params->chandef.chan->band)
  3225. return -EINVAL;
  3226. /* see comments in the NL80211_IFTYPE_AP block */
  3227. if (params->count > 1) {
  3228. err = ieee80211_ibss_csa_beacon(sdata, params, changed);
  3229. if (err < 0)
  3230. return err;
  3231. }
  3232. ieee80211_send_action_csa(sdata, params);
  3233. break;
  3234. #ifdef CONFIG_MAC80211_MESH
  3235. case NL80211_IFTYPE_MESH_POINT: {
  3236. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  3237. /* changes into another band are not supported */
  3238. if (sdata->vif.bss_conf.chanreq.oper.chan->band !=
  3239. params->chandef.chan->band)
  3240. return -EINVAL;
  3241. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
  3242. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
  3243. if (!ifmsh->pre_value)
  3244. ifmsh->pre_value = 1;
  3245. else
  3246. ifmsh->pre_value++;
  3247. }
  3248. /* see comments in the NL80211_IFTYPE_AP block */
  3249. if (params->count > 1) {
  3250. err = ieee80211_mesh_csa_beacon(sdata, params, changed);
  3251. if (err < 0) {
  3252. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
  3253. return err;
  3254. }
  3255. }
  3256. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
  3257. ieee80211_send_action_csa(sdata, params);
  3258. break;
  3259. }
  3260. #endif
  3261. default:
  3262. return -EOPNOTSUPP;
  3263. }
  3264. return 0;
  3265. }
  3266. static void ieee80211_color_change_abort(struct ieee80211_link_data *link)
  3267. {
  3268. link->conf->color_change_active = false;
  3269. ieee80211_free_next_beacon(link);
  3270. cfg80211_color_change_aborted_notify(link->sdata->dev, link->link_id);
  3271. }
  3272. static int
  3273. __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  3274. struct cfg80211_csa_settings *params)
  3275. {
  3276. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3277. struct ieee80211_chan_req chanreq = { .oper = params->chandef };
  3278. struct ieee80211_local *local = sdata->local;
  3279. struct ieee80211_channel_switch ch_switch = {
  3280. .link_id = params->link_id,
  3281. };
  3282. struct ieee80211_chanctx_conf *conf;
  3283. struct ieee80211_chanctx *chanctx;
  3284. struct ieee80211_bss_conf *link_conf;
  3285. struct ieee80211_link_data *link_data;
  3286. u64 changed = 0;
  3287. u8 link_id = params->link_id;
  3288. int err;
  3289. lockdep_assert_wiphy(local->hw.wiphy);
  3290. if (!list_empty(&local->roc_list) || local->scanning)
  3291. return -EBUSY;
  3292. if (sdata->wdev.links[link_id].cac_started)
  3293. return -EBUSY;
  3294. if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
  3295. return -EINVAL;
  3296. link_data = wiphy_dereference(wiphy, sdata->link[link_id]);
  3297. if (!link_data)
  3298. return -ENOLINK;
  3299. link_conf = link_data->conf;
  3300. if (chanreq.oper.punctured && !link_conf->eht_support)
  3301. return -EINVAL;
  3302. /* don't allow another channel switch if one is already active. */
  3303. if (link_conf->csa_active)
  3304. return -EBUSY;
  3305. conf = wiphy_dereference(wiphy, link_conf->chanctx_conf);
  3306. if (!conf) {
  3307. err = -EBUSY;
  3308. goto out;
  3309. }
  3310. if (params->chandef.chan->freq_offset) {
  3311. /* this may work, but is untested */
  3312. err = -EOPNOTSUPP;
  3313. goto out;
  3314. }
  3315. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  3316. ch_switch.timestamp = 0;
  3317. ch_switch.device_timestamp = 0;
  3318. ch_switch.block_tx = params->block_tx;
  3319. ch_switch.chandef = chanreq.oper;
  3320. ch_switch.count = params->count;
  3321. err = drv_pre_channel_switch(sdata, &ch_switch);
  3322. if (err)
  3323. goto out;
  3324. err = ieee80211_link_reserve_chanctx(link_data, &chanreq,
  3325. chanctx->mode,
  3326. params->radar_required);
  3327. if (err)
  3328. goto out;
  3329. /* if reservation is invalid then this will fail */
  3330. err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0, -1);
  3331. if (err) {
  3332. ieee80211_link_unreserve_chanctx(link_data);
  3333. goto out;
  3334. }
  3335. /* if there is a color change in progress, abort it */
  3336. if (link_conf->color_change_active)
  3337. ieee80211_color_change_abort(link_data);
  3338. err = ieee80211_set_csa_beacon(link_data, params, &changed);
  3339. if (err) {
  3340. ieee80211_link_unreserve_chanctx(link_data);
  3341. goto out;
  3342. }
  3343. link_data->csa.chanreq = chanreq;
  3344. link_conf->csa_active = true;
  3345. if (params->block_tx)
  3346. ieee80211_vif_block_queues_csa(sdata);
  3347. cfg80211_ch_switch_started_notify(sdata->dev,
  3348. &link_data->csa.chanreq.oper, link_id,
  3349. params->count, params->block_tx);
  3350. if (changed) {
  3351. ieee80211_link_info_change_notify(sdata, link_data, changed);
  3352. drv_channel_switch_beacon(sdata, &link_data->csa.chanreq.oper);
  3353. } else {
  3354. /* if the beacon didn't change, we can finalize immediately */
  3355. ieee80211_csa_finalize(link_data);
  3356. }
  3357. out:
  3358. return err;
  3359. }
  3360. int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  3361. struct cfg80211_csa_settings *params)
  3362. {
  3363. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3364. struct ieee80211_local *local = sdata->local;
  3365. lockdep_assert_wiphy(local->hw.wiphy);
  3366. return __ieee80211_channel_switch(wiphy, dev, params);
  3367. }
  3368. u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
  3369. {
  3370. lockdep_assert_wiphy(local->hw.wiphy);
  3371. local->roc_cookie_counter++;
  3372. /* wow, you wrapped 64 bits ... more likely a bug */
  3373. if (WARN_ON(local->roc_cookie_counter == 0))
  3374. local->roc_cookie_counter++;
  3375. return local->roc_cookie_counter;
  3376. }
  3377. int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
  3378. u64 *cookie, gfp_t gfp)
  3379. {
  3380. unsigned long spin_flags;
  3381. struct sk_buff *ack_skb;
  3382. int id;
  3383. ack_skb = skb_copy(skb, gfp);
  3384. if (!ack_skb)
  3385. return -ENOMEM;
  3386. spin_lock_irqsave(&local->ack_status_lock, spin_flags);
  3387. id = idr_alloc(&local->ack_status_frames, ack_skb,
  3388. 1, 0x2000, GFP_ATOMIC);
  3389. spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
  3390. if (id < 0) {
  3391. kfree_skb(ack_skb);
  3392. return -ENOMEM;
  3393. }
  3394. IEEE80211_SKB_CB(skb)->status_data_idr = 1;
  3395. IEEE80211_SKB_CB(skb)->status_data = id;
  3396. *cookie = ieee80211_mgmt_tx_cookie(local);
  3397. IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
  3398. return 0;
  3399. }
  3400. static void
  3401. ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
  3402. struct wireless_dev *wdev,
  3403. struct mgmt_frame_regs *upd)
  3404. {
  3405. struct ieee80211_local *local = wiphy_priv(wiphy);
  3406. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  3407. u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
  3408. u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
  3409. bool global_change, intf_change;
  3410. global_change =
  3411. (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
  3412. (local->rx_mcast_action_reg !=
  3413. !!(upd->global_mcast_stypes & action_mask));
  3414. local->probe_req_reg = upd->global_stypes & preq_mask;
  3415. local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
  3416. intf_change = (sdata->vif.probe_req_reg !=
  3417. !!(upd->interface_stypes & preq_mask)) ||
  3418. (sdata->vif.rx_mcast_action_reg !=
  3419. !!(upd->interface_mcast_stypes & action_mask));
  3420. sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
  3421. sdata->vif.rx_mcast_action_reg =
  3422. upd->interface_mcast_stypes & action_mask;
  3423. if (!local->open_count)
  3424. return;
  3425. if (intf_change && ieee80211_sdata_running(sdata))
  3426. drv_config_iface_filter(local, sdata,
  3427. sdata->vif.probe_req_reg ?
  3428. FIF_PROBE_REQ : 0,
  3429. FIF_PROBE_REQ);
  3430. if (global_change)
  3431. ieee80211_configure_filter(local);
  3432. }
  3433. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  3434. {
  3435. struct ieee80211_local *local = wiphy_priv(wiphy);
  3436. int ret;
  3437. if (local->started)
  3438. return -EOPNOTSUPP;
  3439. ret = drv_set_antenna(local, tx_ant, rx_ant);
  3440. if (ret)
  3441. return ret;
  3442. local->rx_chains = hweight8(rx_ant);
  3443. return 0;
  3444. }
  3445. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  3446. {
  3447. struct ieee80211_local *local = wiphy_priv(wiphy);
  3448. return drv_get_antenna(local, tx_ant, rx_ant);
  3449. }
  3450. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  3451. struct net_device *dev,
  3452. struct cfg80211_gtk_rekey_data *data)
  3453. {
  3454. struct ieee80211_local *local = wiphy_priv(wiphy);
  3455. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3456. if (!local->ops->set_rekey_data)
  3457. return -EOPNOTSUPP;
  3458. drv_set_rekey_data(local, sdata, data);
  3459. return 0;
  3460. }
  3461. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  3462. const u8 *peer, u64 *cookie)
  3463. {
  3464. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3465. struct ieee80211_local *local = sdata->local;
  3466. struct ieee80211_qos_hdr *nullfunc;
  3467. struct sk_buff *skb;
  3468. int size = sizeof(*nullfunc);
  3469. __le16 fc;
  3470. bool qos;
  3471. struct ieee80211_tx_info *info;
  3472. struct sta_info *sta;
  3473. struct ieee80211_chanctx_conf *chanctx_conf;
  3474. enum nl80211_band band;
  3475. int ret;
  3476. /* the lock is needed to assign the cookie later */
  3477. lockdep_assert_wiphy(local->hw.wiphy);
  3478. rcu_read_lock();
  3479. sta = sta_info_get_bss(sdata, peer);
  3480. if (!sta) {
  3481. ret = -ENOLINK;
  3482. goto unlock;
  3483. }
  3484. qos = sta->sta.wme;
  3485. chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  3486. if (WARN_ON(!chanctx_conf)) {
  3487. ret = -EINVAL;
  3488. goto unlock;
  3489. }
  3490. band = chanctx_conf->def.chan->band;
  3491. if (qos) {
  3492. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  3493. IEEE80211_STYPE_QOS_NULLFUNC |
  3494. IEEE80211_FCTL_FROMDS);
  3495. } else {
  3496. size -= 2;
  3497. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  3498. IEEE80211_STYPE_NULLFUNC |
  3499. IEEE80211_FCTL_FROMDS);
  3500. }
  3501. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  3502. if (!skb) {
  3503. ret = -ENOMEM;
  3504. goto unlock;
  3505. }
  3506. skb->dev = dev;
  3507. skb_reserve(skb, local->hw.extra_tx_headroom);
  3508. nullfunc = skb_put(skb, size);
  3509. nullfunc->frame_control = fc;
  3510. nullfunc->duration_id = 0;
  3511. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  3512. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  3513. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  3514. nullfunc->seq_ctrl = 0;
  3515. info = IEEE80211_SKB_CB(skb);
  3516. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  3517. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  3518. info->band = band;
  3519. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  3520. skb->priority = 7;
  3521. if (qos)
  3522. nullfunc->qos_ctrl = cpu_to_le16(7);
  3523. ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
  3524. if (ret) {
  3525. kfree_skb(skb);
  3526. goto unlock;
  3527. }
  3528. local_bh_disable();
  3529. ieee80211_xmit(sdata, sta, skb);
  3530. local_bh_enable();
  3531. ret = 0;
  3532. unlock:
  3533. rcu_read_unlock();
  3534. return ret;
  3535. }
  3536. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  3537. struct wireless_dev *wdev,
  3538. unsigned int link_id,
  3539. struct cfg80211_chan_def *chandef)
  3540. {
  3541. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  3542. struct ieee80211_local *local = wiphy_priv(wiphy);
  3543. struct ieee80211_chanctx_conf *chanctx_conf;
  3544. struct ieee80211_link_data *link;
  3545. int ret = -ENODATA;
  3546. rcu_read_lock();
  3547. link = rcu_dereference(sdata->link[link_id]);
  3548. if (!link) {
  3549. ret = -ENOLINK;
  3550. goto out;
  3551. }
  3552. chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
  3553. if (chanctx_conf) {
  3554. *chandef = link->conf->chanreq.oper;
  3555. ret = 0;
  3556. } else if (local->open_count > 0 &&
  3557. local->open_count == local->monitors &&
  3558. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  3559. *chandef = local->monitor_chanreq.oper;
  3560. ret = 0;
  3561. }
  3562. out:
  3563. rcu_read_unlock();
  3564. return ret;
  3565. }
  3566. #ifdef CONFIG_PM
  3567. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  3568. {
  3569. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  3570. }
  3571. #endif
  3572. static int ieee80211_set_qos_map(struct wiphy *wiphy,
  3573. struct net_device *dev,
  3574. struct cfg80211_qos_map *qos_map)
  3575. {
  3576. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3577. struct mac80211_qos_map *new_qos_map, *old_qos_map;
  3578. if (qos_map) {
  3579. new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
  3580. if (!new_qos_map)
  3581. return -ENOMEM;
  3582. memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
  3583. } else {
  3584. /* A NULL qos_map was passed to disable QoS mapping */
  3585. new_qos_map = NULL;
  3586. }
  3587. old_qos_map = sdata_dereference(sdata->qos_map, sdata);
  3588. rcu_assign_pointer(sdata->qos_map, new_qos_map);
  3589. if (old_qos_map)
  3590. kfree_rcu(old_qos_map, rcu_head);
  3591. return 0;
  3592. }
  3593. static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
  3594. struct net_device *dev,
  3595. unsigned int link_id,
  3596. struct cfg80211_chan_def *chandef)
  3597. {
  3598. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3599. struct ieee80211_link_data *link;
  3600. struct ieee80211_chan_req chanreq = { .oper = *chandef };
  3601. int ret;
  3602. u64 changed = 0;
  3603. link = sdata_dereference(sdata->link[link_id], sdata);
  3604. ret = ieee80211_link_change_chanreq(link, &chanreq, &changed);
  3605. if (ret == 0)
  3606. ieee80211_link_info_change_notify(sdata, link, changed);
  3607. return ret;
  3608. }
  3609. static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  3610. u8 tsid, const u8 *peer, u8 up,
  3611. u16 admitted_time)
  3612. {
  3613. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3614. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3615. int ac = ieee802_1d_to_ac[up];
  3616. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3617. return -EOPNOTSUPP;
  3618. if (!(sdata->wmm_acm & BIT(up)))
  3619. return -EINVAL;
  3620. if (ifmgd->tx_tspec[ac].admitted_time)
  3621. return -EBUSY;
  3622. if (admitted_time) {
  3623. ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
  3624. ifmgd->tx_tspec[ac].tsid = tsid;
  3625. ifmgd->tx_tspec[ac].up = up;
  3626. }
  3627. return 0;
  3628. }
  3629. static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  3630. u8 tsid, const u8 *peer)
  3631. {
  3632. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3633. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3634. struct ieee80211_local *local = wiphy_priv(wiphy);
  3635. int ac;
  3636. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  3637. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  3638. /* skip unused entries */
  3639. if (!tx_tspec->admitted_time)
  3640. continue;
  3641. if (tx_tspec->tsid != tsid)
  3642. continue;
  3643. /* due to this new packets will be reassigned to non-ACM ACs */
  3644. tx_tspec->up = -1;
  3645. /* Make sure that all packets have been sent to avoid to
  3646. * restore the QoS params on packets that are still on the
  3647. * queues.
  3648. */
  3649. synchronize_net();
  3650. ieee80211_flush_queues(local, sdata, false);
  3651. /* restore the normal QoS parameters
  3652. * (unconditionally to avoid races)
  3653. */
  3654. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  3655. tx_tspec->downgraded = false;
  3656. ieee80211_sta_handle_tspec_ac_params(sdata);
  3657. /* finally clear all the data */
  3658. memset(tx_tspec, 0, sizeof(*tx_tspec));
  3659. return 0;
  3660. }
  3661. return -ENOENT;
  3662. }
  3663. void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
  3664. u8 inst_id,
  3665. enum nl80211_nan_func_term_reason reason,
  3666. gfp_t gfp)
  3667. {
  3668. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3669. struct cfg80211_nan_func *func;
  3670. u64 cookie;
  3671. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  3672. return;
  3673. spin_lock_bh(&sdata->u.nan.func_lock);
  3674. func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
  3675. if (WARN_ON(!func)) {
  3676. spin_unlock_bh(&sdata->u.nan.func_lock);
  3677. return;
  3678. }
  3679. cookie = func->cookie;
  3680. idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
  3681. spin_unlock_bh(&sdata->u.nan.func_lock);
  3682. cfg80211_free_nan_func(func);
  3683. cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
  3684. reason, cookie, gfp);
  3685. }
  3686. EXPORT_SYMBOL(ieee80211_nan_func_terminated);
  3687. void ieee80211_nan_func_match(struct ieee80211_vif *vif,
  3688. struct cfg80211_nan_match_params *match,
  3689. gfp_t gfp)
  3690. {
  3691. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3692. struct cfg80211_nan_func *func;
  3693. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  3694. return;
  3695. spin_lock_bh(&sdata->u.nan.func_lock);
  3696. func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
  3697. if (WARN_ON(!func)) {
  3698. spin_unlock_bh(&sdata->u.nan.func_lock);
  3699. return;
  3700. }
  3701. match->cookie = func->cookie;
  3702. spin_unlock_bh(&sdata->u.nan.func_lock);
  3703. cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
  3704. }
  3705. EXPORT_SYMBOL(ieee80211_nan_func_match);
  3706. static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
  3707. struct net_device *dev,
  3708. const bool enabled)
  3709. {
  3710. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3711. sdata->u.ap.multicast_to_unicast = enabled;
  3712. return 0;
  3713. }
  3714. void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
  3715. struct txq_info *txqi)
  3716. {
  3717. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
  3718. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
  3719. txqstats->backlog_bytes = txqi->tin.backlog_bytes;
  3720. }
  3721. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
  3722. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
  3723. txqstats->backlog_packets = txqi->tin.backlog_packets;
  3724. }
  3725. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
  3726. txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
  3727. txqstats->flows = txqi->tin.flows;
  3728. }
  3729. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
  3730. txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
  3731. txqstats->drops = txqi->cstats.drop_count;
  3732. }
  3733. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
  3734. txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
  3735. txqstats->ecn_marks = txqi->cstats.ecn_mark;
  3736. }
  3737. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
  3738. txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
  3739. txqstats->overlimit = txqi->tin.overlimit;
  3740. }
  3741. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
  3742. txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
  3743. txqstats->collisions = txqi->tin.collisions;
  3744. }
  3745. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
  3746. txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
  3747. txqstats->tx_bytes = txqi->tin.tx_bytes;
  3748. }
  3749. if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
  3750. txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
  3751. txqstats->tx_packets = txqi->tin.tx_packets;
  3752. }
  3753. }
  3754. static int ieee80211_get_txq_stats(struct wiphy *wiphy,
  3755. struct wireless_dev *wdev,
  3756. struct cfg80211_txq_stats *txqstats)
  3757. {
  3758. struct ieee80211_local *local = wiphy_priv(wiphy);
  3759. struct ieee80211_sub_if_data *sdata;
  3760. int ret = 0;
  3761. spin_lock_bh(&local->fq.lock);
  3762. rcu_read_lock();
  3763. if (wdev) {
  3764. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  3765. if (!sdata->vif.txq) {
  3766. ret = 1;
  3767. goto out;
  3768. }
  3769. ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
  3770. } else {
  3771. /* phy stats */
  3772. txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
  3773. BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
  3774. BIT(NL80211_TXQ_STATS_OVERLIMIT) |
  3775. BIT(NL80211_TXQ_STATS_OVERMEMORY) |
  3776. BIT(NL80211_TXQ_STATS_COLLISIONS) |
  3777. BIT(NL80211_TXQ_STATS_MAX_FLOWS);
  3778. txqstats->backlog_packets = local->fq.backlog;
  3779. txqstats->backlog_bytes = local->fq.memory_usage;
  3780. txqstats->overlimit = local->fq.overlimit;
  3781. txqstats->overmemory = local->fq.overmemory;
  3782. txqstats->collisions = local->fq.collisions;
  3783. txqstats->max_flows = local->fq.flows_cnt;
  3784. }
  3785. out:
  3786. rcu_read_unlock();
  3787. spin_unlock_bh(&local->fq.lock);
  3788. return ret;
  3789. }
  3790. static int
  3791. ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
  3792. struct net_device *dev,
  3793. struct cfg80211_ftm_responder_stats *ftm_stats)
  3794. {
  3795. struct ieee80211_local *local = wiphy_priv(wiphy);
  3796. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3797. return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
  3798. }
  3799. static int
  3800. ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
  3801. struct cfg80211_pmsr_request *request)
  3802. {
  3803. struct ieee80211_local *local = wiphy_priv(wiphy);
  3804. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
  3805. return drv_start_pmsr(local, sdata, request);
  3806. }
  3807. static void
  3808. ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
  3809. struct cfg80211_pmsr_request *request)
  3810. {
  3811. struct ieee80211_local *local = wiphy_priv(wiphy);
  3812. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
  3813. return drv_abort_pmsr(local, sdata, request);
  3814. }
  3815. static int ieee80211_set_tid_config(struct wiphy *wiphy,
  3816. struct net_device *dev,
  3817. struct cfg80211_tid_config *tid_conf)
  3818. {
  3819. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3820. struct sta_info *sta;
  3821. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3822. if (!sdata->local->ops->set_tid_config)
  3823. return -EOPNOTSUPP;
  3824. if (!tid_conf->peer)
  3825. return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
  3826. sta = sta_info_get_bss(sdata, tid_conf->peer);
  3827. if (!sta)
  3828. return -ENOENT;
  3829. return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
  3830. }
  3831. static int ieee80211_reset_tid_config(struct wiphy *wiphy,
  3832. struct net_device *dev,
  3833. const u8 *peer, u8 tids)
  3834. {
  3835. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  3836. struct sta_info *sta;
  3837. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3838. if (!sdata->local->ops->reset_tid_config)
  3839. return -EOPNOTSUPP;
  3840. if (!peer)
  3841. return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
  3842. sta = sta_info_get_bss(sdata, peer);
  3843. if (!sta)
  3844. return -ENOENT;
  3845. return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
  3846. }
  3847. static int ieee80211_set_sar_specs(struct wiphy *wiphy,
  3848. struct cfg80211_sar_specs *sar)
  3849. {
  3850. struct ieee80211_local *local = wiphy_priv(wiphy);
  3851. if (!local->ops->set_sar_specs)
  3852. return -EOPNOTSUPP;
  3853. return local->ops->set_sar_specs(&local->hw, sar);
  3854. }
  3855. static int
  3856. ieee80211_set_after_color_change_beacon(struct ieee80211_link_data *link,
  3857. u64 *changed)
  3858. {
  3859. struct ieee80211_sub_if_data *sdata = link->sdata;
  3860. switch (sdata->vif.type) {
  3861. case NL80211_IFTYPE_AP: {
  3862. int ret;
  3863. if (!link->u.ap.next_beacon)
  3864. return -EINVAL;
  3865. ret = ieee80211_assign_beacon(sdata, link,
  3866. link->u.ap.next_beacon,
  3867. NULL, NULL, changed);
  3868. ieee80211_free_next_beacon(link);
  3869. if (ret < 0)
  3870. return ret;
  3871. break;
  3872. }
  3873. default:
  3874. WARN_ON_ONCE(1);
  3875. return -EINVAL;
  3876. }
  3877. return 0;
  3878. }
  3879. static int
  3880. ieee80211_set_color_change_beacon(struct ieee80211_link_data *link,
  3881. struct cfg80211_color_change_settings *params,
  3882. u64 *changed)
  3883. {
  3884. struct ieee80211_sub_if_data *sdata = link->sdata;
  3885. struct ieee80211_color_change_settings color_change = {};
  3886. int err;
  3887. switch (sdata->vif.type) {
  3888. case NL80211_IFTYPE_AP:
  3889. link->u.ap.next_beacon =
  3890. cfg80211_beacon_dup(&params->beacon_next);
  3891. if (!link->u.ap.next_beacon)
  3892. return -ENOMEM;
  3893. if (params->count <= 1)
  3894. break;
  3895. color_change.counter_offset_beacon =
  3896. params->counter_offset_beacon;
  3897. color_change.counter_offset_presp =
  3898. params->counter_offset_presp;
  3899. color_change.count = params->count;
  3900. err = ieee80211_assign_beacon(sdata, link,
  3901. &params->beacon_color_change,
  3902. NULL, &color_change, changed);
  3903. if (err < 0) {
  3904. ieee80211_free_next_beacon(link);
  3905. return err;
  3906. }
  3907. break;
  3908. default:
  3909. return -EOPNOTSUPP;
  3910. }
  3911. return 0;
  3912. }
  3913. static void
  3914. ieee80211_color_change_bss_config_notify(struct ieee80211_link_data *link,
  3915. u8 color, int enable, u64 changed)
  3916. {
  3917. struct ieee80211_sub_if_data *sdata = link->sdata;
  3918. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3919. link->conf->he_bss_color.color = color;
  3920. link->conf->he_bss_color.enabled = enable;
  3921. changed |= BSS_CHANGED_HE_BSS_COLOR;
  3922. ieee80211_link_info_change_notify(sdata, link, changed);
  3923. if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
  3924. struct ieee80211_sub_if_data *child;
  3925. list_for_each_entry(child, &sdata->local->interfaces, list) {
  3926. if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
  3927. child->vif.bss_conf.he_bss_color.color = color;
  3928. child->vif.bss_conf.he_bss_color.enabled = enable;
  3929. ieee80211_link_info_change_notify(child,
  3930. &child->deflink,
  3931. BSS_CHANGED_HE_BSS_COLOR);
  3932. }
  3933. }
  3934. }
  3935. }
  3936. static int ieee80211_color_change_finalize(struct ieee80211_link_data *link)
  3937. {
  3938. struct ieee80211_sub_if_data *sdata = link->sdata;
  3939. struct ieee80211_local *local = sdata->local;
  3940. u64 changed = 0;
  3941. int err;
  3942. lockdep_assert_wiphy(local->hw.wiphy);
  3943. link->conf->color_change_active = false;
  3944. err = ieee80211_set_after_color_change_beacon(link, &changed);
  3945. if (err) {
  3946. cfg80211_color_change_aborted_notify(sdata->dev, link->link_id);
  3947. return err;
  3948. }
  3949. ieee80211_color_change_bss_config_notify(link,
  3950. link->conf->color_change_color,
  3951. 1, changed);
  3952. cfg80211_color_change_notify(sdata->dev, link->link_id);
  3953. return 0;
  3954. }
  3955. void ieee80211_color_change_finalize_work(struct wiphy *wiphy,
  3956. struct wiphy_work *work)
  3957. {
  3958. struct ieee80211_link_data *link =
  3959. container_of(work, struct ieee80211_link_data,
  3960. color_change_finalize_work);
  3961. struct ieee80211_sub_if_data *sdata = link->sdata;
  3962. struct ieee80211_bss_conf *link_conf = link->conf;
  3963. struct ieee80211_local *local = sdata->local;
  3964. lockdep_assert_wiphy(local->hw.wiphy);
  3965. /* AP might have been stopped while waiting for the lock. */
  3966. if (!link_conf->color_change_active)
  3967. return;
  3968. if (!ieee80211_sdata_running(sdata))
  3969. return;
  3970. ieee80211_color_change_finalize(link);
  3971. }
  3972. void ieee80211_color_collision_detection_work(struct wiphy *wiphy,
  3973. struct wiphy_work *work)
  3974. {
  3975. struct ieee80211_link_data *link =
  3976. container_of(work, struct ieee80211_link_data,
  3977. color_collision_detect_work.work);
  3978. struct ieee80211_sub_if_data *sdata = link->sdata;
  3979. cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap,
  3980. link->link_id);
  3981. }
  3982. void ieee80211_color_change_finish(struct ieee80211_vif *vif, u8 link_id)
  3983. {
  3984. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3985. struct ieee80211_link_data *link;
  3986. if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
  3987. return;
  3988. rcu_read_lock();
  3989. link = rcu_dereference(sdata->link[link_id]);
  3990. if (WARN_ON(!link)) {
  3991. rcu_read_unlock();
  3992. return;
  3993. }
  3994. wiphy_work_queue(sdata->local->hw.wiphy,
  3995. &link->color_change_finalize_work);
  3996. rcu_read_unlock();
  3997. }
  3998. EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
  3999. void
  4000. ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
  4001. u64 color_bitmap, u8 link_id)
  4002. {
  4003. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  4004. struct ieee80211_link_data *link;
  4005. if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
  4006. return;
  4007. rcu_read_lock();
  4008. link = rcu_dereference(sdata->link[link_id]);
  4009. if (WARN_ON(!link)) {
  4010. rcu_read_unlock();
  4011. return;
  4012. }
  4013. if (link->conf->color_change_active || link->conf->csa_active) {
  4014. rcu_read_unlock();
  4015. return;
  4016. }
  4017. if (wiphy_delayed_work_pending(sdata->local->hw.wiphy,
  4018. &link->color_collision_detect_work)) {
  4019. rcu_read_unlock();
  4020. return;
  4021. }
  4022. link->color_bitmap = color_bitmap;
  4023. /* queue the color collision detection event every 500 ms in order to
  4024. * avoid sending too much netlink messages to userspace.
  4025. */
  4026. wiphy_delayed_work_queue(sdata->local->hw.wiphy,
  4027. &link->color_collision_detect_work,
  4028. msecs_to_jiffies(500));
  4029. rcu_read_unlock();
  4030. }
  4031. EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify);
  4032. static int
  4033. ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
  4034. struct cfg80211_color_change_settings *params)
  4035. {
  4036. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  4037. struct ieee80211_local *local = sdata->local;
  4038. struct ieee80211_bss_conf *link_conf;
  4039. struct ieee80211_link_data *link;
  4040. u8 link_id = params->link_id;
  4041. u64 changed = 0;
  4042. int err;
  4043. lockdep_assert_wiphy(local->hw.wiphy);
  4044. if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS))
  4045. return -EINVAL;
  4046. link = wiphy_dereference(wiphy, sdata->link[link_id]);
  4047. if (!link)
  4048. return -ENOLINK;
  4049. link_conf = link->conf;
  4050. if (link_conf->nontransmitted)
  4051. return -EINVAL;
  4052. /* don't allow another color change if one is already active or if csa
  4053. * is active
  4054. */
  4055. if (link_conf->color_change_active || link_conf->csa_active) {
  4056. err = -EBUSY;
  4057. goto out;
  4058. }
  4059. err = ieee80211_set_color_change_beacon(link, params, &changed);
  4060. if (err)
  4061. goto out;
  4062. link_conf->color_change_active = true;
  4063. link_conf->color_change_color = params->color;
  4064. cfg80211_color_change_started_notify(sdata->dev, params->count, link_id);
  4065. if (changed)
  4066. ieee80211_color_change_bss_config_notify(link, 0, 0, changed);
  4067. else
  4068. /* if the beacon didn't change, we can finalize immediately */
  4069. ieee80211_color_change_finalize(link);
  4070. out:
  4071. return err;
  4072. }
  4073. static int
  4074. ieee80211_set_radar_background(struct wiphy *wiphy,
  4075. struct cfg80211_chan_def *chandef)
  4076. {
  4077. struct ieee80211_local *local = wiphy_priv(wiphy);
  4078. if (!local->ops->set_radar_background)
  4079. return -EOPNOTSUPP;
  4080. return local->ops->set_radar_background(&local->hw, chandef);
  4081. }
  4082. static int ieee80211_add_intf_link(struct wiphy *wiphy,
  4083. struct wireless_dev *wdev,
  4084. unsigned int link_id)
  4085. {
  4086. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  4087. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4088. if (wdev->use_4addr)
  4089. return -EOPNOTSUPP;
  4090. return ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
  4091. }
  4092. static void ieee80211_del_intf_link(struct wiphy *wiphy,
  4093. struct wireless_dev *wdev,
  4094. unsigned int link_id)
  4095. {
  4096. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  4097. u16 new_links = wdev->valid_links & ~BIT(link_id);
  4098. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4099. /* During the link teardown process, certain functions require the
  4100. * link_id to remain in the valid_links bitmap. Therefore, instead
  4101. * of removing the link_id from the bitmap, pass a masked value to
  4102. * simulate as if link_id does not exist anymore.
  4103. */
  4104. ieee80211_vif_set_links(sdata, new_links, 0);
  4105. }
  4106. static int
  4107. ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
  4108. struct link_station_parameters *params)
  4109. {
  4110. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  4111. struct ieee80211_local *local = wiphy_priv(wiphy);
  4112. struct sta_info *sta;
  4113. int ret;
  4114. lockdep_assert_wiphy(local->hw.wiphy);
  4115. sta = sta_info_get_bss(sdata, params->mld_mac);
  4116. if (!sta)
  4117. return -ENOENT;
  4118. if (!sta->sta.valid_links)
  4119. return -EINVAL;
  4120. if (sta->sta.valid_links & BIT(params->link_id))
  4121. return -EALREADY;
  4122. ret = ieee80211_sta_allocate_link(sta, params->link_id);
  4123. if (ret)
  4124. return ret;
  4125. ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_NEW, params);
  4126. if (ret) {
  4127. ieee80211_sta_free_link(sta, params->link_id);
  4128. return ret;
  4129. }
  4130. /* ieee80211_sta_activate_link frees the link upon failure */
  4131. return ieee80211_sta_activate_link(sta, params->link_id);
  4132. }
  4133. static int
  4134. ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
  4135. struct link_station_parameters *params)
  4136. {
  4137. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  4138. struct ieee80211_local *local = wiphy_priv(wiphy);
  4139. struct sta_info *sta;
  4140. lockdep_assert_wiphy(local->hw.wiphy);
  4141. sta = sta_info_get_bss(sdata, params->mld_mac);
  4142. if (!sta)
  4143. return -ENOENT;
  4144. if (!(sta->sta.valid_links & BIT(params->link_id)))
  4145. return -EINVAL;
  4146. return sta_link_apply_parameters(local, sta, STA_LINK_MODE_LINK_MODIFY,
  4147. params);
  4148. }
  4149. static int
  4150. ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
  4151. struct link_station_del_parameters *params)
  4152. {
  4153. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  4154. struct sta_info *sta;
  4155. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4156. sta = sta_info_get_bss(sdata, params->mld_mac);
  4157. if (!sta)
  4158. return -ENOENT;
  4159. if (!(sta->sta.valid_links & BIT(params->link_id)))
  4160. return -EINVAL;
  4161. /* must not create a STA without links */
  4162. if (sta->sta.valid_links == BIT(params->link_id))
  4163. return -EINVAL;
  4164. ieee80211_sta_remove_link(sta, params->link_id);
  4165. return 0;
  4166. }
  4167. static int ieee80211_set_hw_timestamp(struct wiphy *wiphy,
  4168. struct net_device *dev,
  4169. struct cfg80211_set_hw_timestamp *hwts)
  4170. {
  4171. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  4172. struct ieee80211_local *local = sdata->local;
  4173. if (!local->ops->set_hw_timestamp)
  4174. return -EOPNOTSUPP;
  4175. if (!check_sdata_in_driver(sdata))
  4176. return -EIO;
  4177. return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts);
  4178. }
  4179. static int
  4180. ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev,
  4181. struct cfg80211_ttlm_params *params)
  4182. {
  4183. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  4184. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4185. return ieee80211_req_neg_ttlm(sdata, params);
  4186. }
  4187. const struct cfg80211_ops mac80211_config_ops = {
  4188. .add_virtual_intf = ieee80211_add_iface,
  4189. .del_virtual_intf = ieee80211_del_iface,
  4190. .change_virtual_intf = ieee80211_change_iface,
  4191. .start_p2p_device = ieee80211_start_p2p_device,
  4192. .stop_p2p_device = ieee80211_stop_p2p_device,
  4193. .add_key = ieee80211_add_key,
  4194. .del_key = ieee80211_del_key,
  4195. .get_key = ieee80211_get_key,
  4196. .set_default_key = ieee80211_config_default_key,
  4197. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  4198. .set_default_beacon_key = ieee80211_config_default_beacon_key,
  4199. .start_ap = ieee80211_start_ap,
  4200. .change_beacon = ieee80211_change_beacon,
  4201. .stop_ap = ieee80211_stop_ap,
  4202. .add_station = ieee80211_add_station,
  4203. .del_station = ieee80211_del_station,
  4204. .change_station = ieee80211_change_station,
  4205. .get_station = ieee80211_get_station,
  4206. .dump_station = ieee80211_dump_station,
  4207. .dump_survey = ieee80211_dump_survey,
  4208. #ifdef CONFIG_MAC80211_MESH
  4209. .add_mpath = ieee80211_add_mpath,
  4210. .del_mpath = ieee80211_del_mpath,
  4211. .change_mpath = ieee80211_change_mpath,
  4212. .get_mpath = ieee80211_get_mpath,
  4213. .dump_mpath = ieee80211_dump_mpath,
  4214. .get_mpp = ieee80211_get_mpp,
  4215. .dump_mpp = ieee80211_dump_mpp,
  4216. .update_mesh_config = ieee80211_update_mesh_config,
  4217. .get_mesh_config = ieee80211_get_mesh_config,
  4218. .join_mesh = ieee80211_join_mesh,
  4219. .leave_mesh = ieee80211_leave_mesh,
  4220. #endif
  4221. .join_ocb = ieee80211_join_ocb,
  4222. .leave_ocb = ieee80211_leave_ocb,
  4223. .change_bss = ieee80211_change_bss,
  4224. .inform_bss = ieee80211_inform_bss,
  4225. .set_txq_params = ieee80211_set_txq_params,
  4226. .set_monitor_channel = ieee80211_set_monitor_channel,
  4227. .suspend = ieee80211_suspend,
  4228. .resume = ieee80211_resume,
  4229. .scan = ieee80211_scan,
  4230. .abort_scan = ieee80211_abort_scan,
  4231. .sched_scan_start = ieee80211_sched_scan_start,
  4232. .sched_scan_stop = ieee80211_sched_scan_stop,
  4233. .auth = ieee80211_auth,
  4234. .assoc = ieee80211_assoc,
  4235. .deauth = ieee80211_deauth,
  4236. .disassoc = ieee80211_disassoc,
  4237. .join_ibss = ieee80211_join_ibss,
  4238. .leave_ibss = ieee80211_leave_ibss,
  4239. .set_mcast_rate = ieee80211_set_mcast_rate,
  4240. .set_wiphy_params = ieee80211_set_wiphy_params,
  4241. .set_tx_power = ieee80211_set_tx_power,
  4242. .get_tx_power = ieee80211_get_tx_power,
  4243. .rfkill_poll = ieee80211_rfkill_poll,
  4244. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  4245. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  4246. .set_power_mgmt = ieee80211_set_power_mgmt,
  4247. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  4248. .remain_on_channel = ieee80211_remain_on_channel,
  4249. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  4250. .mgmt_tx = ieee80211_mgmt_tx,
  4251. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  4252. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  4253. .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
  4254. .update_mgmt_frame_registrations =
  4255. ieee80211_update_mgmt_frame_registrations,
  4256. .set_antenna = ieee80211_set_antenna,
  4257. .get_antenna = ieee80211_get_antenna,
  4258. .set_rekey_data = ieee80211_set_rekey_data,
  4259. .tdls_oper = ieee80211_tdls_oper,
  4260. .tdls_mgmt = ieee80211_tdls_mgmt,
  4261. .tdls_channel_switch = ieee80211_tdls_channel_switch,
  4262. .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
  4263. .probe_client = ieee80211_probe_client,
  4264. .set_noack_map = ieee80211_set_noack_map,
  4265. #ifdef CONFIG_PM
  4266. .set_wakeup = ieee80211_set_wakeup,
  4267. #endif
  4268. .get_channel = ieee80211_cfg_get_channel,
  4269. .start_radar_detection = ieee80211_start_radar_detection,
  4270. .end_cac = ieee80211_end_cac,
  4271. .channel_switch = ieee80211_channel_switch,
  4272. .set_qos_map = ieee80211_set_qos_map,
  4273. .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
  4274. .add_tx_ts = ieee80211_add_tx_ts,
  4275. .del_tx_ts = ieee80211_del_tx_ts,
  4276. .start_nan = ieee80211_start_nan,
  4277. .stop_nan = ieee80211_stop_nan,
  4278. .nan_change_conf = ieee80211_nan_change_conf,
  4279. .add_nan_func = ieee80211_add_nan_func,
  4280. .del_nan_func = ieee80211_del_nan_func,
  4281. .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
  4282. .tx_control_port = ieee80211_tx_control_port,
  4283. .get_txq_stats = ieee80211_get_txq_stats,
  4284. .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
  4285. .start_pmsr = ieee80211_start_pmsr,
  4286. .abort_pmsr = ieee80211_abort_pmsr,
  4287. .probe_mesh_link = ieee80211_probe_mesh_link,
  4288. .set_tid_config = ieee80211_set_tid_config,
  4289. .reset_tid_config = ieee80211_reset_tid_config,
  4290. .set_sar_specs = ieee80211_set_sar_specs,
  4291. .color_change = ieee80211_color_change,
  4292. .set_radar_background = ieee80211_set_radar_background,
  4293. .add_intf_link = ieee80211_add_intf_link,
  4294. .del_intf_link = ieee80211_del_intf_link,
  4295. .add_link_station = ieee80211_add_link_station,
  4296. .mod_link_station = ieee80211_mod_link_station,
  4297. .del_link_station = ieee80211_del_link_station,
  4298. .set_hw_timestamp = ieee80211_set_hw_timestamp,
  4299. .set_ttlm = ieee80211_set_ttlm,
  4300. .get_radio_mask = ieee80211_get_radio_mask,
  4301. };