cfg.c 133 KB

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