cfg.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2015 Intel Mobile Communications GmbH
  6. * Copyright (C) 2015-2016 Intel Deutschland GmbH
  7. *
  8. * This file is GPLv2 as found in COPYING.
  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/if_ether.h>
  17. #include <net/cfg80211.h>
  18. #include "ieee80211_i.h"
  19. #include "driver-ops.h"
  20. #include "rate.h"
  21. #include "mesh.h"
  22. #include "wme.h"
  23. static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
  24. const char *name,
  25. unsigned char name_assign_type,
  26. enum nl80211_iftype type,
  27. u32 *flags,
  28. struct vif_params *params)
  29. {
  30. struct ieee80211_local *local = wiphy_priv(wiphy);
  31. struct wireless_dev *wdev;
  32. struct ieee80211_sub_if_data *sdata;
  33. int err;
  34. err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
  35. if (err)
  36. return ERR_PTR(err);
  37. if (type == NL80211_IFTYPE_MONITOR && flags) {
  38. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  39. sdata->u.mntr.flags = *flags;
  40. }
  41. return wdev;
  42. }
  43. static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
  44. {
  45. ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
  46. return 0;
  47. }
  48. static int ieee80211_change_iface(struct wiphy *wiphy,
  49. struct net_device *dev,
  50. enum nl80211_iftype type, u32 *flags,
  51. struct vif_params *params)
  52. {
  53. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  54. int ret;
  55. ret = ieee80211_if_change_type(sdata, type);
  56. if (ret)
  57. return ret;
  58. if (type == NL80211_IFTYPE_AP_VLAN &&
  59. params && params->use_4addr == 0) {
  60. RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
  61. ieee80211_check_fast_rx_iface(sdata);
  62. } else if (type == NL80211_IFTYPE_STATION &&
  63. params && params->use_4addr >= 0) {
  64. sdata->u.mgd.use_4addr = params->use_4addr;
  65. }
  66. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  67. struct ieee80211_local *local = sdata->local;
  68. struct ieee80211_sub_if_data *monitor_sdata;
  69. u32 mu_mntr_cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
  70. monitor_sdata = rtnl_dereference(local->monitor_sdata);
  71. if (monitor_sdata &&
  72. wiphy_ext_feature_isset(wiphy, mu_mntr_cap_flag)) {
  73. memcpy(monitor_sdata->vif.bss_conf.mu_group.membership,
  74. params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
  75. memcpy(monitor_sdata->vif.bss_conf.mu_group.position,
  76. params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
  77. WLAN_USER_POSITION_LEN);
  78. monitor_sdata->vif.mu_mimo_owner = true;
  79. ieee80211_bss_info_change_notify(monitor_sdata,
  80. BSS_CHANGED_MU_GROUPS);
  81. ether_addr_copy(monitor_sdata->u.mntr.mu_follow_addr,
  82. params->macaddr);
  83. }
  84. if (!flags)
  85. return 0;
  86. if (ieee80211_sdata_running(sdata)) {
  87. u32 mask = MONITOR_FLAG_COOK_FRAMES |
  88. MONITOR_FLAG_ACTIVE;
  89. /*
  90. * Prohibit MONITOR_FLAG_COOK_FRAMES and
  91. * MONITOR_FLAG_ACTIVE to be changed while the
  92. * interface is up.
  93. * Else we would need to add a lot of cruft
  94. * to update everything:
  95. * cooked_mntrs, monitor and all fif_* counters
  96. * reconfigure hardware
  97. */
  98. if ((*flags & mask) != (sdata->u.mntr.flags & mask))
  99. return -EBUSY;
  100. ieee80211_adjust_monitor_flags(sdata, -1);
  101. sdata->u.mntr.flags = *flags;
  102. ieee80211_adjust_monitor_flags(sdata, 1);
  103. ieee80211_configure_filter(local);
  104. } else {
  105. /*
  106. * Because the interface is down, ieee80211_do_stop
  107. * and ieee80211_do_open take care of "everything"
  108. * mentioned in the comment above.
  109. */
  110. sdata->u.mntr.flags = *flags;
  111. }
  112. }
  113. return 0;
  114. }
  115. static int ieee80211_start_p2p_device(struct wiphy *wiphy,
  116. struct wireless_dev *wdev)
  117. {
  118. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  119. int ret;
  120. mutex_lock(&sdata->local->chanctx_mtx);
  121. ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
  122. mutex_unlock(&sdata->local->chanctx_mtx);
  123. if (ret < 0)
  124. return ret;
  125. return ieee80211_do_open(wdev, true);
  126. }
  127. static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
  128. struct wireless_dev *wdev)
  129. {
  130. ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
  131. }
  132. static int ieee80211_start_nan(struct wiphy *wiphy,
  133. struct wireless_dev *wdev,
  134. struct cfg80211_nan_conf *conf)
  135. {
  136. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  137. int ret;
  138. mutex_lock(&sdata->local->chanctx_mtx);
  139. ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
  140. mutex_unlock(&sdata->local->chanctx_mtx);
  141. if (ret < 0)
  142. return ret;
  143. ret = ieee80211_do_open(wdev, true);
  144. if (ret)
  145. return ret;
  146. ret = drv_start_nan(sdata->local, sdata, conf);
  147. if (ret)
  148. ieee80211_sdata_stop(sdata);
  149. sdata->u.nan.conf = *conf;
  150. return ret;
  151. }
  152. static void ieee80211_stop_nan(struct wiphy *wiphy,
  153. struct wireless_dev *wdev)
  154. {
  155. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  156. drv_stop_nan(sdata->local, sdata);
  157. ieee80211_sdata_stop(sdata);
  158. }
  159. static int ieee80211_nan_change_conf(struct wiphy *wiphy,
  160. struct wireless_dev *wdev,
  161. struct cfg80211_nan_conf *conf,
  162. u32 changes)
  163. {
  164. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  165. struct cfg80211_nan_conf new_conf;
  166. int ret = 0;
  167. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  168. return -EOPNOTSUPP;
  169. if (!ieee80211_sdata_running(sdata))
  170. return -ENETDOWN;
  171. new_conf = sdata->u.nan.conf;
  172. if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
  173. new_conf.master_pref = conf->master_pref;
  174. if (changes & CFG80211_NAN_CONF_CHANGED_DUAL)
  175. new_conf.dual = conf->dual;
  176. ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
  177. if (!ret)
  178. sdata->u.nan.conf = new_conf;
  179. return ret;
  180. }
  181. static int ieee80211_add_nan_func(struct wiphy *wiphy,
  182. struct wireless_dev *wdev,
  183. struct cfg80211_nan_func *nan_func)
  184. {
  185. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  186. int ret;
  187. if (sdata->vif.type != NL80211_IFTYPE_NAN)
  188. return -EOPNOTSUPP;
  189. if (!ieee80211_sdata_running(sdata))
  190. return -ENETDOWN;
  191. spin_lock_bh(&sdata->u.nan.func_lock);
  192. ret = idr_alloc(&sdata->u.nan.function_inst_ids,
  193. nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
  194. GFP_ATOMIC);
  195. spin_unlock_bh(&sdata->u.nan.func_lock);
  196. if (ret < 0)
  197. return ret;
  198. nan_func->instance_id = ret;
  199. WARN_ON(nan_func->instance_id == 0);
  200. ret = drv_add_nan_func(sdata->local, sdata, nan_func);
  201. if (ret) {
  202. spin_lock_bh(&sdata->u.nan.func_lock);
  203. idr_remove(&sdata->u.nan.function_inst_ids,
  204. nan_func->instance_id);
  205. spin_unlock_bh(&sdata->u.nan.func_lock);
  206. }
  207. return ret;
  208. }
  209. static struct cfg80211_nan_func *
  210. ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
  211. u64 cookie)
  212. {
  213. struct cfg80211_nan_func *func;
  214. int id;
  215. lockdep_assert_held(&sdata->u.nan.func_lock);
  216. idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
  217. if (func->cookie == cookie)
  218. return func;
  219. }
  220. return NULL;
  221. }
  222. static void ieee80211_del_nan_func(struct wiphy *wiphy,
  223. struct wireless_dev *wdev, u64 cookie)
  224. {
  225. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  226. struct cfg80211_nan_func *func;
  227. u8 instance_id = 0;
  228. if (sdata->vif.type != NL80211_IFTYPE_NAN ||
  229. !ieee80211_sdata_running(sdata))
  230. return;
  231. spin_lock_bh(&sdata->u.nan.func_lock);
  232. func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
  233. if (func)
  234. instance_id = func->instance_id;
  235. spin_unlock_bh(&sdata->u.nan.func_lock);
  236. if (instance_id)
  237. drv_del_nan_func(sdata->local, sdata, instance_id);
  238. }
  239. static int ieee80211_set_noack_map(struct wiphy *wiphy,
  240. struct net_device *dev,
  241. u16 noack_map)
  242. {
  243. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  244. sdata->noack_map = noack_map;
  245. ieee80211_check_fast_xmit_iface(sdata);
  246. return 0;
  247. }
  248. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  249. u8 key_idx, bool pairwise, const u8 *mac_addr,
  250. struct key_params *params)
  251. {
  252. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  253. struct ieee80211_local *local = sdata->local;
  254. struct sta_info *sta = NULL;
  255. const struct ieee80211_cipher_scheme *cs = NULL;
  256. struct ieee80211_key *key;
  257. int err;
  258. if (!ieee80211_sdata_running(sdata))
  259. return -ENETDOWN;
  260. /* reject WEP and TKIP keys if WEP failed to initialize */
  261. switch (params->cipher) {
  262. case WLAN_CIPHER_SUITE_WEP40:
  263. case WLAN_CIPHER_SUITE_TKIP:
  264. case WLAN_CIPHER_SUITE_WEP104:
  265. if (IS_ERR(local->wep_tx_tfm))
  266. return -EINVAL;
  267. break;
  268. case WLAN_CIPHER_SUITE_CCMP:
  269. case WLAN_CIPHER_SUITE_CCMP_256:
  270. case WLAN_CIPHER_SUITE_AES_CMAC:
  271. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  272. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  273. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  274. case WLAN_CIPHER_SUITE_GCMP:
  275. case WLAN_CIPHER_SUITE_GCMP_256:
  276. break;
  277. default:
  278. cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
  279. break;
  280. }
  281. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  282. params->key, params->seq_len, params->seq,
  283. cs);
  284. if (IS_ERR(key))
  285. return PTR_ERR(key);
  286. if (pairwise)
  287. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  288. mutex_lock(&local->sta_mtx);
  289. if (mac_addr) {
  290. if (ieee80211_vif_is_mesh(&sdata->vif))
  291. sta = sta_info_get(sdata, mac_addr);
  292. else
  293. sta = sta_info_get_bss(sdata, mac_addr);
  294. /*
  295. * The ASSOC test makes sure the driver is ready to
  296. * receive the key. When wpa_supplicant has roamed
  297. * using FT, it attempts to set the key before
  298. * association has completed, this rejects that attempt
  299. * so it will set the key again after association.
  300. *
  301. * TODO: accept the key if we have a station entry and
  302. * add it to the device after the station.
  303. */
  304. if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  305. ieee80211_key_free_unused(key);
  306. err = -ENOENT;
  307. goto out_unlock;
  308. }
  309. }
  310. switch (sdata->vif.type) {
  311. case NL80211_IFTYPE_STATION:
  312. if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
  313. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  314. break;
  315. case NL80211_IFTYPE_AP:
  316. case NL80211_IFTYPE_AP_VLAN:
  317. /* Keys without a station are used for TX only */
  318. if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
  319. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  320. break;
  321. case NL80211_IFTYPE_ADHOC:
  322. /* no MFP (yet) */
  323. break;
  324. case NL80211_IFTYPE_MESH_POINT:
  325. #ifdef CONFIG_MAC80211_MESH
  326. if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
  327. key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
  328. break;
  329. #endif
  330. case NL80211_IFTYPE_WDS:
  331. case NL80211_IFTYPE_MONITOR:
  332. case NL80211_IFTYPE_P2P_DEVICE:
  333. case NL80211_IFTYPE_NAN:
  334. case NL80211_IFTYPE_UNSPECIFIED:
  335. case NUM_NL80211_IFTYPES:
  336. case NL80211_IFTYPE_P2P_CLIENT:
  337. case NL80211_IFTYPE_P2P_GO:
  338. case NL80211_IFTYPE_OCB:
  339. /* shouldn't happen */
  340. WARN_ON_ONCE(1);
  341. break;
  342. }
  343. if (sta)
  344. sta->cipher_scheme = cs;
  345. err = ieee80211_key_link(key, sdata, sta);
  346. out_unlock:
  347. mutex_unlock(&local->sta_mtx);
  348. return err;
  349. }
  350. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  351. u8 key_idx, bool pairwise, const u8 *mac_addr)
  352. {
  353. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  354. struct ieee80211_local *local = sdata->local;
  355. struct sta_info *sta;
  356. struct ieee80211_key *key = NULL;
  357. int ret;
  358. mutex_lock(&local->sta_mtx);
  359. mutex_lock(&local->key_mtx);
  360. if (mac_addr) {
  361. ret = -ENOENT;
  362. sta = sta_info_get_bss(sdata, mac_addr);
  363. if (!sta)
  364. goto out_unlock;
  365. if (pairwise)
  366. key = key_mtx_dereference(local, sta->ptk[key_idx]);
  367. else
  368. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  369. } else
  370. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  371. if (!key) {
  372. ret = -ENOENT;
  373. goto out_unlock;
  374. }
  375. ieee80211_key_free(key, true);
  376. ret = 0;
  377. out_unlock:
  378. mutex_unlock(&local->key_mtx);
  379. mutex_unlock(&local->sta_mtx);
  380. return ret;
  381. }
  382. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  383. u8 key_idx, bool pairwise, const u8 *mac_addr,
  384. void *cookie,
  385. void (*callback)(void *cookie,
  386. struct key_params *params))
  387. {
  388. struct ieee80211_sub_if_data *sdata;
  389. struct sta_info *sta = NULL;
  390. u8 seq[6] = {0};
  391. struct key_params params;
  392. struct ieee80211_key *key = NULL;
  393. u64 pn64;
  394. u32 iv32;
  395. u16 iv16;
  396. int err = -ENOENT;
  397. struct ieee80211_key_seq kseq = {};
  398. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  399. rcu_read_lock();
  400. if (mac_addr) {
  401. sta = sta_info_get_bss(sdata, mac_addr);
  402. if (!sta)
  403. goto out;
  404. if (pairwise && key_idx < NUM_DEFAULT_KEYS)
  405. key = rcu_dereference(sta->ptk[key_idx]);
  406. else if (!pairwise &&
  407. key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  408. key = rcu_dereference(sta->gtk[key_idx]);
  409. } else
  410. key = rcu_dereference(sdata->keys[key_idx]);
  411. if (!key)
  412. goto out;
  413. memset(&params, 0, sizeof(params));
  414. params.cipher = key->conf.cipher;
  415. switch (key->conf.cipher) {
  416. case WLAN_CIPHER_SUITE_TKIP:
  417. pn64 = atomic64_read(&key->conf.tx_pn);
  418. iv32 = TKIP_PN_TO_IV32(pn64);
  419. iv16 = TKIP_PN_TO_IV16(pn64);
  420. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  421. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  422. drv_get_key_seq(sdata->local, key, &kseq);
  423. iv32 = kseq.tkip.iv32;
  424. iv16 = kseq.tkip.iv16;
  425. }
  426. seq[0] = iv16 & 0xff;
  427. seq[1] = (iv16 >> 8) & 0xff;
  428. seq[2] = iv32 & 0xff;
  429. seq[3] = (iv32 >> 8) & 0xff;
  430. seq[4] = (iv32 >> 16) & 0xff;
  431. seq[5] = (iv32 >> 24) & 0xff;
  432. params.seq = seq;
  433. params.seq_len = 6;
  434. break;
  435. case WLAN_CIPHER_SUITE_CCMP:
  436. case WLAN_CIPHER_SUITE_CCMP_256:
  437. case WLAN_CIPHER_SUITE_AES_CMAC:
  438. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  439. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  440. offsetof(typeof(kseq), aes_cmac));
  441. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  442. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  443. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  444. offsetof(typeof(kseq), aes_gmac));
  445. case WLAN_CIPHER_SUITE_GCMP:
  446. case WLAN_CIPHER_SUITE_GCMP_256:
  447. BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
  448. offsetof(typeof(kseq), gcmp));
  449. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  450. !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
  451. drv_get_key_seq(sdata->local, key, &kseq);
  452. memcpy(seq, kseq.ccmp.pn, 6);
  453. } else {
  454. pn64 = atomic64_read(&key->conf.tx_pn);
  455. seq[0] = pn64;
  456. seq[1] = pn64 >> 8;
  457. seq[2] = pn64 >> 16;
  458. seq[3] = pn64 >> 24;
  459. seq[4] = pn64 >> 32;
  460. seq[5] = pn64 >> 40;
  461. }
  462. params.seq = seq;
  463. params.seq_len = 6;
  464. break;
  465. default:
  466. if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  467. break;
  468. if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
  469. break;
  470. drv_get_key_seq(sdata->local, key, &kseq);
  471. params.seq = kseq.hw.seq;
  472. params.seq_len = kseq.hw.seq_len;
  473. break;
  474. }
  475. params.key = key->conf.key;
  476. params.key_len = key->conf.keylen;
  477. callback(cookie, &params);
  478. err = 0;
  479. out:
  480. rcu_read_unlock();
  481. return err;
  482. }
  483. static int ieee80211_config_default_key(struct wiphy *wiphy,
  484. struct net_device *dev,
  485. u8 key_idx, bool uni,
  486. bool multi)
  487. {
  488. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  489. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  490. return 0;
  491. }
  492. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  493. struct net_device *dev,
  494. u8 key_idx)
  495. {
  496. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  497. ieee80211_set_default_mgmt_key(sdata, key_idx);
  498. return 0;
  499. }
  500. void sta_set_rate_info_tx(struct sta_info *sta,
  501. const struct ieee80211_tx_rate *rate,
  502. struct rate_info *rinfo)
  503. {
  504. rinfo->flags = 0;
  505. if (rate->flags & IEEE80211_TX_RC_MCS) {
  506. rinfo->flags |= RATE_INFO_FLAGS_MCS;
  507. rinfo->mcs = rate->idx;
  508. } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
  509. rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
  510. rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
  511. rinfo->nss = ieee80211_rate_get_vht_nss(rate);
  512. } else {
  513. struct ieee80211_supported_band *sband;
  514. int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
  515. u16 brate;
  516. sband = ieee80211_get_sband(sta->sdata);
  517. if (sband) {
  518. brate = sband->bitrates[rate->idx].bitrate;
  519. rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
  520. }
  521. }
  522. if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  523. rinfo->bw = RATE_INFO_BW_40;
  524. else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  525. rinfo->bw = RATE_INFO_BW_80;
  526. else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  527. rinfo->bw = RATE_INFO_BW_160;
  528. else
  529. rinfo->bw = RATE_INFO_BW_20;
  530. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  531. rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
  532. }
  533. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  534. int idx, u8 *mac, struct station_info *sinfo)
  535. {
  536. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  537. struct ieee80211_local *local = sdata->local;
  538. struct sta_info *sta;
  539. int ret = -ENOENT;
  540. mutex_lock(&local->sta_mtx);
  541. sta = sta_info_get_by_idx(sdata, idx);
  542. if (sta) {
  543. ret = 0;
  544. memcpy(mac, sta->sta.addr, ETH_ALEN);
  545. sta_set_sinfo(sta, sinfo);
  546. }
  547. mutex_unlock(&local->sta_mtx);
  548. return ret;
  549. }
  550. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  551. int idx, struct survey_info *survey)
  552. {
  553. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  554. return drv_get_survey(local, idx, survey);
  555. }
  556. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  557. const u8 *mac, struct station_info *sinfo)
  558. {
  559. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  560. struct ieee80211_local *local = sdata->local;
  561. struct sta_info *sta;
  562. int ret = -ENOENT;
  563. mutex_lock(&local->sta_mtx);
  564. sta = sta_info_get_bss(sdata, mac);
  565. if (sta) {
  566. ret = 0;
  567. sta_set_sinfo(sta, sinfo);
  568. }
  569. mutex_unlock(&local->sta_mtx);
  570. return ret;
  571. }
  572. static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
  573. struct cfg80211_chan_def *chandef)
  574. {
  575. struct ieee80211_local *local = wiphy_priv(wiphy);
  576. struct ieee80211_sub_if_data *sdata;
  577. int ret = 0;
  578. if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
  579. return 0;
  580. mutex_lock(&local->mtx);
  581. mutex_lock(&local->iflist_mtx);
  582. if (local->use_chanctx) {
  583. sdata = rcu_dereference_protected(
  584. local->monitor_sdata,
  585. lockdep_is_held(&local->iflist_mtx));
  586. if (sdata) {
  587. ieee80211_vif_release_channel(sdata);
  588. ret = ieee80211_vif_use_channel(sdata, chandef,
  589. IEEE80211_CHANCTX_EXCLUSIVE);
  590. }
  591. } else if (local->open_count == local->monitors) {
  592. local->_oper_chandef = *chandef;
  593. ieee80211_hw_config(local, 0);
  594. }
  595. if (ret == 0)
  596. local->monitor_chandef = *chandef;
  597. mutex_unlock(&local->iflist_mtx);
  598. mutex_unlock(&local->mtx);
  599. return ret;
  600. }
  601. static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
  602. const u8 *resp, size_t resp_len,
  603. const struct ieee80211_csa_settings *csa)
  604. {
  605. struct probe_resp *new, *old;
  606. if (!resp || !resp_len)
  607. return 1;
  608. old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  609. new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
  610. if (!new)
  611. return -ENOMEM;
  612. new->len = resp_len;
  613. memcpy(new->data, resp, resp_len);
  614. if (csa)
  615. memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
  616. csa->n_counter_offsets_presp *
  617. sizeof(new->csa_counter_offsets[0]));
  618. rcu_assign_pointer(sdata->u.ap.probe_resp, new);
  619. if (old)
  620. kfree_rcu(old, rcu_head);
  621. return 0;
  622. }
  623. static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
  624. struct cfg80211_beacon_data *params,
  625. const struct ieee80211_csa_settings *csa)
  626. {
  627. struct beacon_data *new, *old;
  628. int new_head_len, new_tail_len;
  629. int size, err;
  630. u32 changed = BSS_CHANGED_BEACON;
  631. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  632. /* Need to have a beacon head if we don't have one yet */
  633. if (!params->head && !old)
  634. return -EINVAL;
  635. /* new or old head? */
  636. if (params->head)
  637. new_head_len = params->head_len;
  638. else
  639. new_head_len = old->head_len;
  640. /* new or old tail? */
  641. if (params->tail || !old)
  642. /* params->tail_len will be zero for !params->tail */
  643. new_tail_len = params->tail_len;
  644. else
  645. new_tail_len = old->tail_len;
  646. size = sizeof(*new) + new_head_len + new_tail_len;
  647. new = kzalloc(size, GFP_KERNEL);
  648. if (!new)
  649. return -ENOMEM;
  650. /* start filling the new info now */
  651. /*
  652. * pointers go into the block we allocated,
  653. * memory is | beacon_data | head | tail |
  654. */
  655. new->head = ((u8 *) new) + sizeof(*new);
  656. new->tail = new->head + new_head_len;
  657. new->head_len = new_head_len;
  658. new->tail_len = new_tail_len;
  659. if (csa) {
  660. new->csa_current_counter = csa->count;
  661. memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
  662. csa->n_counter_offsets_beacon *
  663. sizeof(new->csa_counter_offsets[0]));
  664. }
  665. /* copy in head */
  666. if (params->head)
  667. memcpy(new->head, params->head, new_head_len);
  668. else
  669. memcpy(new->head, old->head, new_head_len);
  670. /* copy in optional tail */
  671. if (params->tail)
  672. memcpy(new->tail, params->tail, new_tail_len);
  673. else
  674. if (old)
  675. memcpy(new->tail, old->tail, new_tail_len);
  676. err = ieee80211_set_probe_resp(sdata, params->probe_resp,
  677. params->probe_resp_len, csa);
  678. if (err < 0)
  679. return err;
  680. if (err == 0)
  681. changed |= BSS_CHANGED_AP_PROBE_RESP;
  682. rcu_assign_pointer(sdata->u.ap.beacon, new);
  683. if (old)
  684. kfree_rcu(old, rcu_head);
  685. return changed;
  686. }
  687. static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
  688. struct cfg80211_ap_settings *params)
  689. {
  690. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  691. struct ieee80211_local *local = sdata->local;
  692. struct beacon_data *old;
  693. struct ieee80211_sub_if_data *vlan;
  694. u32 changed = BSS_CHANGED_BEACON_INT |
  695. BSS_CHANGED_BEACON_ENABLED |
  696. BSS_CHANGED_BEACON |
  697. BSS_CHANGED_SSID |
  698. BSS_CHANGED_P2P_PS |
  699. BSS_CHANGED_TXPOWER;
  700. int err;
  701. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  702. if (old)
  703. return -EALREADY;
  704. switch (params->smps_mode) {
  705. case NL80211_SMPS_OFF:
  706. sdata->smps_mode = IEEE80211_SMPS_OFF;
  707. break;
  708. case NL80211_SMPS_STATIC:
  709. sdata->smps_mode = IEEE80211_SMPS_STATIC;
  710. break;
  711. case NL80211_SMPS_DYNAMIC:
  712. sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
  713. break;
  714. default:
  715. return -EINVAL;
  716. }
  717. sdata->u.ap.req_smps = sdata->smps_mode;
  718. sdata->needed_rx_chains = sdata->local->rx_chains;
  719. mutex_lock(&local->mtx);
  720. err = ieee80211_vif_use_channel(sdata, &params->chandef,
  721. IEEE80211_CHANCTX_SHARED);
  722. if (!err)
  723. ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
  724. mutex_unlock(&local->mtx);
  725. if (err)
  726. return err;
  727. /*
  728. * Apply control port protocol, this allows us to
  729. * not encrypt dynamic WEP control frames.
  730. */
  731. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  732. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  733. sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
  734. &params->crypto,
  735. sdata->vif.type);
  736. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  737. vlan->control_port_protocol =
  738. params->crypto.control_port_ethertype;
  739. vlan->control_port_no_encrypt =
  740. params->crypto.control_port_no_encrypt;
  741. vlan->encrypt_headroom =
  742. ieee80211_cs_headroom(sdata->local,
  743. &params->crypto,
  744. vlan->vif.type);
  745. }
  746. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  747. sdata->vif.bss_conf.dtim_period = params->dtim_period;
  748. sdata->vif.bss_conf.enable_beacon = true;
  749. sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
  750. sdata->vif.bss_conf.ssid_len = params->ssid_len;
  751. if (params->ssid_len)
  752. memcpy(sdata->vif.bss_conf.ssid, params->ssid,
  753. params->ssid_len);
  754. sdata->vif.bss_conf.hidden_ssid =
  755. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  756. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  757. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  758. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
  759. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  760. if (params->p2p_opp_ps)
  761. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  762. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  763. err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
  764. if (err < 0) {
  765. ieee80211_vif_release_channel(sdata);
  766. return err;
  767. }
  768. changed |= err;
  769. err = drv_start_ap(sdata->local, sdata);
  770. if (err) {
  771. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  772. if (old)
  773. kfree_rcu(old, rcu_head);
  774. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  775. ieee80211_vif_release_channel(sdata);
  776. return err;
  777. }
  778. ieee80211_recalc_dtim(local, sdata);
  779. ieee80211_bss_info_change_notify(sdata, changed);
  780. netif_carrier_on(dev);
  781. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  782. netif_carrier_on(vlan->dev);
  783. return 0;
  784. }
  785. static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  786. struct cfg80211_beacon_data *params)
  787. {
  788. struct ieee80211_sub_if_data *sdata;
  789. struct beacon_data *old;
  790. int err;
  791. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  792. sdata_assert_lock(sdata);
  793. /* don't allow changing the beacon while CSA is in place - offset
  794. * of channel switch counter may change
  795. */
  796. if (sdata->vif.csa_active)
  797. return -EBUSY;
  798. old = sdata_dereference(sdata->u.ap.beacon, sdata);
  799. if (!old)
  800. return -ENOENT;
  801. err = ieee80211_assign_beacon(sdata, params, NULL);
  802. if (err < 0)
  803. return err;
  804. ieee80211_bss_info_change_notify(sdata, err);
  805. return 0;
  806. }
  807. static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  808. {
  809. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  810. struct ieee80211_sub_if_data *vlan;
  811. struct ieee80211_local *local = sdata->local;
  812. struct beacon_data *old_beacon;
  813. struct probe_resp *old_probe_resp;
  814. struct cfg80211_chan_def chandef;
  815. sdata_assert_lock(sdata);
  816. old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
  817. if (!old_beacon)
  818. return -ENOENT;
  819. old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
  820. /* abort any running channel switch */
  821. mutex_lock(&local->mtx);
  822. sdata->vif.csa_active = false;
  823. if (sdata->csa_block_tx) {
  824. ieee80211_wake_vif_queues(local, sdata,
  825. IEEE80211_QUEUE_STOP_REASON_CSA);
  826. sdata->csa_block_tx = false;
  827. }
  828. mutex_unlock(&local->mtx);
  829. kfree(sdata->u.ap.next_beacon);
  830. sdata->u.ap.next_beacon = NULL;
  831. /* turn off carrier for this interface and dependent VLANs */
  832. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
  833. netif_carrier_off(vlan->dev);
  834. netif_carrier_off(dev);
  835. /* remove beacon and probe response */
  836. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  837. RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
  838. kfree_rcu(old_beacon, rcu_head);
  839. if (old_probe_resp)
  840. kfree_rcu(old_probe_resp, rcu_head);
  841. sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
  842. __sta_info_flush(sdata, true);
  843. ieee80211_free_keys(sdata, true);
  844. sdata->vif.bss_conf.enable_beacon = false;
  845. sdata->vif.bss_conf.ssid_len = 0;
  846. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  847. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  848. if (sdata->wdev.cac_started) {
  849. chandef = sdata->vif.bss_conf.chandef;
  850. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  851. cfg80211_cac_event(sdata->dev, &chandef,
  852. NL80211_RADAR_CAC_ABORTED,
  853. GFP_KERNEL);
  854. }
  855. drv_stop_ap(sdata->local, sdata);
  856. /* free all potentially still buffered bcast frames */
  857. local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
  858. ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
  859. mutex_lock(&local->mtx);
  860. ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
  861. ieee80211_vif_release_channel(sdata);
  862. mutex_unlock(&local->mtx);
  863. return 0;
  864. }
  865. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  866. struct iapp_layer2_update {
  867. u8 da[ETH_ALEN]; /* broadcast */
  868. u8 sa[ETH_ALEN]; /* STA addr */
  869. __be16 len; /* 6 */
  870. u8 dsap; /* 0 */
  871. u8 ssap; /* 0 */
  872. u8 control;
  873. u8 xid_info[3];
  874. } __packed;
  875. static void ieee80211_send_layer2_update(struct sta_info *sta)
  876. {
  877. struct iapp_layer2_update *msg;
  878. struct sk_buff *skb;
  879. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  880. * bridge devices */
  881. skb = dev_alloc_skb(sizeof(*msg));
  882. if (!skb)
  883. return;
  884. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  885. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  886. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  887. eth_broadcast_addr(msg->da);
  888. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  889. msg->len = htons(6);
  890. msg->dsap = 0;
  891. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  892. msg->control = 0xaf; /* XID response lsb.1111F101.
  893. * F=0 (no poll command; unsolicited frame) */
  894. msg->xid_info[0] = 0x81; /* XID format identifier */
  895. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  896. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  897. skb->dev = sta->sdata->dev;
  898. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  899. memset(skb->cb, 0, sizeof(skb->cb));
  900. netif_rx_ni(skb);
  901. }
  902. static int sta_apply_auth_flags(struct ieee80211_local *local,
  903. struct sta_info *sta,
  904. u32 mask, u32 set)
  905. {
  906. int ret;
  907. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  908. set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  909. !test_sta_flag(sta, WLAN_STA_AUTH)) {
  910. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  911. if (ret)
  912. return ret;
  913. }
  914. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  915. set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  916. !test_sta_flag(sta, WLAN_STA_ASSOC)) {
  917. /*
  918. * When peer becomes associated, init rate control as
  919. * well. Some drivers require rate control initialized
  920. * before drv_sta_state() is called.
  921. */
  922. if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  923. rate_control_rate_init(sta);
  924. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  925. if (ret)
  926. return ret;
  927. }
  928. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  929. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  930. ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  931. else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  932. ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  933. else
  934. ret = 0;
  935. if (ret)
  936. return ret;
  937. }
  938. if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
  939. !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  940. test_sta_flag(sta, WLAN_STA_ASSOC)) {
  941. ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
  942. if (ret)
  943. return ret;
  944. }
  945. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
  946. !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
  947. test_sta_flag(sta, WLAN_STA_AUTH)) {
  948. ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
  949. if (ret)
  950. return ret;
  951. }
  952. return 0;
  953. }
  954. static void sta_apply_mesh_params(struct ieee80211_local *local,
  955. struct sta_info *sta,
  956. struct station_parameters *params)
  957. {
  958. #ifdef CONFIG_MAC80211_MESH
  959. struct ieee80211_sub_if_data *sdata = sta->sdata;
  960. u32 changed = 0;
  961. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
  962. switch (params->plink_state) {
  963. case NL80211_PLINK_ESTAB:
  964. if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
  965. changed = mesh_plink_inc_estab_count(sdata);
  966. sta->mesh->plink_state = params->plink_state;
  967. sta->mesh->aid = params->peer_aid;
  968. ieee80211_mps_sta_status_update(sta);
  969. changed |= ieee80211_mps_set_sta_local_pm(sta,
  970. sdata->u.mesh.mshcfg.power_mode);
  971. break;
  972. case NL80211_PLINK_LISTEN:
  973. case NL80211_PLINK_BLOCKED:
  974. case NL80211_PLINK_OPN_SNT:
  975. case NL80211_PLINK_OPN_RCVD:
  976. case NL80211_PLINK_CNF_RCVD:
  977. case NL80211_PLINK_HOLDING:
  978. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  979. changed = mesh_plink_dec_estab_count(sdata);
  980. sta->mesh->plink_state = params->plink_state;
  981. ieee80211_mps_sta_status_update(sta);
  982. changed |= ieee80211_mps_set_sta_local_pm(sta,
  983. NL80211_MESH_POWER_UNKNOWN);
  984. break;
  985. default:
  986. /* nothing */
  987. break;
  988. }
  989. }
  990. switch (params->plink_action) {
  991. case NL80211_PLINK_ACTION_NO_ACTION:
  992. /* nothing */
  993. break;
  994. case NL80211_PLINK_ACTION_OPEN:
  995. changed |= mesh_plink_open(sta);
  996. break;
  997. case NL80211_PLINK_ACTION_BLOCK:
  998. changed |= mesh_plink_block(sta);
  999. break;
  1000. }
  1001. if (params->local_pm)
  1002. changed |= ieee80211_mps_set_sta_local_pm(sta,
  1003. params->local_pm);
  1004. ieee80211_mbss_info_change_notify(sdata, changed);
  1005. #endif
  1006. }
  1007. static int sta_apply_parameters(struct ieee80211_local *local,
  1008. struct sta_info *sta,
  1009. struct station_parameters *params)
  1010. {
  1011. int ret = 0;
  1012. struct ieee80211_supported_band *sband;
  1013. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1014. u32 mask, set;
  1015. sband = ieee80211_get_sband(sdata);
  1016. if (!sband)
  1017. return -EINVAL;
  1018. mask = params->sta_flags_mask;
  1019. set = params->sta_flags_set;
  1020. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1021. /*
  1022. * In mesh mode, ASSOCIATED isn't part of the nl80211
  1023. * API but must follow AUTHENTICATED for driver state.
  1024. */
  1025. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1026. mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1027. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  1028. set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  1029. } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1030. /*
  1031. * TDLS -- everything follows authorized, but
  1032. * only becoming authorized is possible, not
  1033. * going back
  1034. */
  1035. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1036. set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1037. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1038. mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  1039. BIT(NL80211_STA_FLAG_ASSOCIATED);
  1040. }
  1041. }
  1042. if (mask & BIT(NL80211_STA_FLAG_WME) &&
  1043. local->hw.queues >= IEEE80211_NUM_ACS)
  1044. sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
  1045. /* auth flags will be set later for TDLS,
  1046. * and for unassociated stations that move to assocaited */
  1047. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1048. !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
  1049. (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
  1050. ret = sta_apply_auth_flags(local, sta, mask, set);
  1051. if (ret)
  1052. return ret;
  1053. }
  1054. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  1055. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  1056. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1057. else
  1058. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  1059. }
  1060. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  1061. sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
  1062. if (set & BIT(NL80211_STA_FLAG_MFP))
  1063. set_sta_flag(sta, WLAN_STA_MFP);
  1064. else
  1065. clear_sta_flag(sta, WLAN_STA_MFP);
  1066. }
  1067. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  1068. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1069. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1070. else
  1071. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1072. }
  1073. /* mark TDLS channel switch support, if the AP allows it */
  1074. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1075. !sdata->u.mgd.tdls_chan_switch_prohibited &&
  1076. params->ext_capab_len >= 4 &&
  1077. params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
  1078. set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
  1079. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1080. !sdata->u.mgd.tdls_wider_bw_prohibited &&
  1081. ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
  1082. params->ext_capab_len >= 8 &&
  1083. params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
  1084. set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
  1085. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  1086. sta->sta.uapsd_queues = params->uapsd_queues;
  1087. sta->sta.max_sp = params->max_sp;
  1088. }
  1089. /* The sender might not have sent the last bit, consider it to be 0 */
  1090. if (params->ext_capab_len >= 8) {
  1091. u8 val = (params->ext_capab[7] &
  1092. WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
  1093. /* we did get all the bits, take the MSB as well */
  1094. if (params->ext_capab_len >= 9) {
  1095. u8 val_msb = params->ext_capab[8] &
  1096. WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
  1097. val_msb <<= 1;
  1098. val |= val_msb;
  1099. }
  1100. switch (val) {
  1101. case 1:
  1102. sta->sta.max_amsdu_subframes = 32;
  1103. break;
  1104. case 2:
  1105. sta->sta.max_amsdu_subframes = 16;
  1106. break;
  1107. case 3:
  1108. sta->sta.max_amsdu_subframes = 8;
  1109. break;
  1110. default:
  1111. sta->sta.max_amsdu_subframes = 0;
  1112. }
  1113. }
  1114. /*
  1115. * cfg80211 validates this (1-2007) and allows setting the AID
  1116. * only when creating a new station entry
  1117. */
  1118. if (params->aid)
  1119. sta->sta.aid = params->aid;
  1120. /*
  1121. * Some of the following updates would be racy if called on an
  1122. * existing station, via ieee80211_change_station(). However,
  1123. * all such changes are rejected by cfg80211 except for updates
  1124. * changing the supported rates on an existing but not yet used
  1125. * TDLS peer.
  1126. */
  1127. if (params->listen_interval >= 0)
  1128. sta->listen_interval = params->listen_interval;
  1129. if (params->supported_rates) {
  1130. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1131. sband, params->supported_rates,
  1132. params->supported_rates_len,
  1133. &sta->sta.supp_rates[sband->band]);
  1134. }
  1135. if (params->ht_capa)
  1136. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  1137. params->ht_capa, sta);
  1138. /* VHT can override some HT caps such as the A-MSDU max length */
  1139. if (params->vht_capa)
  1140. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  1141. params->vht_capa, sta);
  1142. if (params->opmode_notif_used) {
  1143. /* returned value is only needed for rc update, but the
  1144. * rc isn't initialized here yet, so ignore it
  1145. */
  1146. __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
  1147. sband->band);
  1148. }
  1149. if (params->support_p2p_ps >= 0)
  1150. sta->sta.support_p2p_ps = params->support_p2p_ps;
  1151. if (ieee80211_vif_is_mesh(&sdata->vif))
  1152. sta_apply_mesh_params(local, sta, params);
  1153. /* set the STA state after all sta info from usermode has been set */
  1154. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
  1155. set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
  1156. ret = sta_apply_auth_flags(local, sta, mask, set);
  1157. if (ret)
  1158. return ret;
  1159. }
  1160. return 0;
  1161. }
  1162. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  1163. const u8 *mac,
  1164. struct station_parameters *params)
  1165. {
  1166. struct ieee80211_local *local = wiphy_priv(wiphy);
  1167. struct sta_info *sta;
  1168. struct ieee80211_sub_if_data *sdata;
  1169. int err;
  1170. int layer2_update;
  1171. if (params->vlan) {
  1172. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1173. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1174. sdata->vif.type != NL80211_IFTYPE_AP)
  1175. return -EINVAL;
  1176. } else
  1177. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1178. if (ether_addr_equal(mac, sdata->vif.addr))
  1179. return -EINVAL;
  1180. if (is_multicast_ether_addr(mac))
  1181. return -EINVAL;
  1182. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  1183. if (!sta)
  1184. return -ENOMEM;
  1185. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  1186. sta->sta.tdls = true;
  1187. err = sta_apply_parameters(local, sta, params);
  1188. if (err) {
  1189. sta_info_free(local, sta);
  1190. return err;
  1191. }
  1192. /*
  1193. * for TDLS and for unassociated station, rate control should be
  1194. * initialized only when rates are known and station is marked
  1195. * authorized/associated
  1196. */
  1197. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
  1198. test_sta_flag(sta, WLAN_STA_ASSOC))
  1199. rate_control_rate_init(sta);
  1200. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1201. sdata->vif.type == NL80211_IFTYPE_AP;
  1202. err = sta_info_insert_rcu(sta);
  1203. if (err) {
  1204. rcu_read_unlock();
  1205. return err;
  1206. }
  1207. if (layer2_update)
  1208. ieee80211_send_layer2_update(sta);
  1209. rcu_read_unlock();
  1210. return 0;
  1211. }
  1212. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  1213. struct station_del_parameters *params)
  1214. {
  1215. struct ieee80211_sub_if_data *sdata;
  1216. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1217. if (params->mac)
  1218. return sta_info_destroy_addr_bss(sdata, params->mac);
  1219. sta_info_flush(sdata);
  1220. return 0;
  1221. }
  1222. static int ieee80211_change_station(struct wiphy *wiphy,
  1223. struct net_device *dev, const u8 *mac,
  1224. struct station_parameters *params)
  1225. {
  1226. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1227. struct ieee80211_local *local = wiphy_priv(wiphy);
  1228. struct sta_info *sta;
  1229. struct ieee80211_sub_if_data *vlansdata;
  1230. enum cfg80211_station_type statype;
  1231. int err;
  1232. mutex_lock(&local->sta_mtx);
  1233. sta = sta_info_get_bss(sdata, mac);
  1234. if (!sta) {
  1235. err = -ENOENT;
  1236. goto out_err;
  1237. }
  1238. switch (sdata->vif.type) {
  1239. case NL80211_IFTYPE_MESH_POINT:
  1240. if (sdata->u.mesh.user_mpm)
  1241. statype = CFG80211_STA_MESH_PEER_USER;
  1242. else
  1243. statype = CFG80211_STA_MESH_PEER_KERNEL;
  1244. break;
  1245. case NL80211_IFTYPE_ADHOC:
  1246. statype = CFG80211_STA_IBSS;
  1247. break;
  1248. case NL80211_IFTYPE_STATION:
  1249. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  1250. statype = CFG80211_STA_AP_STA;
  1251. break;
  1252. }
  1253. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  1254. statype = CFG80211_STA_TDLS_PEER_ACTIVE;
  1255. else
  1256. statype = CFG80211_STA_TDLS_PEER_SETUP;
  1257. break;
  1258. case NL80211_IFTYPE_AP:
  1259. case NL80211_IFTYPE_AP_VLAN:
  1260. if (test_sta_flag(sta, WLAN_STA_ASSOC))
  1261. statype = CFG80211_STA_AP_CLIENT;
  1262. else
  1263. statype = CFG80211_STA_AP_CLIENT_UNASSOC;
  1264. break;
  1265. default:
  1266. err = -EOPNOTSUPP;
  1267. goto out_err;
  1268. }
  1269. err = cfg80211_check_station_change(wiphy, params, statype);
  1270. if (err)
  1271. goto out_err;
  1272. if (params->vlan && params->vlan != sta->sdata->dev) {
  1273. bool prev_4addr = false;
  1274. bool new_4addr = false;
  1275. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  1276. if (params->vlan->ieee80211_ptr->use_4addr) {
  1277. if (vlansdata->u.vlan.sta) {
  1278. err = -EBUSY;
  1279. goto out_err;
  1280. }
  1281. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  1282. new_4addr = true;
  1283. __ieee80211_check_fast_rx_iface(vlansdata);
  1284. }
  1285. if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1286. sta->sdata->u.vlan.sta) {
  1287. RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
  1288. prev_4addr = true;
  1289. }
  1290. sta->sdata = vlansdata;
  1291. ieee80211_check_fast_xmit(sta);
  1292. if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
  1293. prev_4addr != new_4addr) {
  1294. if (new_4addr)
  1295. atomic_dec(&sta->sdata->bss->num_mcast_sta);
  1296. else
  1297. atomic_inc(&sta->sdata->bss->num_mcast_sta);
  1298. }
  1299. ieee80211_send_layer2_update(sta);
  1300. }
  1301. err = sta_apply_parameters(local, sta, params);
  1302. if (err)
  1303. goto out_err;
  1304. mutex_unlock(&local->sta_mtx);
  1305. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1306. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1307. sta->known_smps_mode != sta->sdata->bss->req_smps &&
  1308. test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
  1309. sta_info_tx_streams(sta) != 1) {
  1310. ht_dbg(sta->sdata,
  1311. "%pM just authorized and MIMO capable - update SMPS\n",
  1312. sta->sta.addr);
  1313. ieee80211_send_smps_action(sta->sdata,
  1314. sta->sdata->bss->req_smps,
  1315. sta->sta.addr,
  1316. sta->sdata->vif.bss_conf.bssid);
  1317. }
  1318. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1319. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  1320. ieee80211_recalc_ps(local);
  1321. ieee80211_recalc_ps_vif(sdata);
  1322. }
  1323. return 0;
  1324. out_err:
  1325. mutex_unlock(&local->sta_mtx);
  1326. return err;
  1327. }
  1328. #ifdef CONFIG_MAC80211_MESH
  1329. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  1330. const u8 *dst, const u8 *next_hop)
  1331. {
  1332. struct ieee80211_sub_if_data *sdata;
  1333. struct mesh_path *mpath;
  1334. struct sta_info *sta;
  1335. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1336. rcu_read_lock();
  1337. sta = sta_info_get(sdata, next_hop);
  1338. if (!sta) {
  1339. rcu_read_unlock();
  1340. return -ENOENT;
  1341. }
  1342. mpath = mesh_path_add(sdata, dst);
  1343. if (IS_ERR(mpath)) {
  1344. rcu_read_unlock();
  1345. return PTR_ERR(mpath);
  1346. }
  1347. mesh_path_fix_nexthop(mpath, sta);
  1348. rcu_read_unlock();
  1349. return 0;
  1350. }
  1351. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  1352. const u8 *dst)
  1353. {
  1354. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1355. if (dst)
  1356. return mesh_path_del(sdata, dst);
  1357. mesh_path_flush_by_iface(sdata);
  1358. return 0;
  1359. }
  1360. static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
  1361. const u8 *dst, const u8 *next_hop)
  1362. {
  1363. struct ieee80211_sub_if_data *sdata;
  1364. struct mesh_path *mpath;
  1365. struct sta_info *sta;
  1366. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1367. rcu_read_lock();
  1368. sta = sta_info_get(sdata, next_hop);
  1369. if (!sta) {
  1370. rcu_read_unlock();
  1371. return -ENOENT;
  1372. }
  1373. mpath = mesh_path_lookup(sdata, dst);
  1374. if (!mpath) {
  1375. rcu_read_unlock();
  1376. return -ENOENT;
  1377. }
  1378. mesh_path_fix_nexthop(mpath, sta);
  1379. rcu_read_unlock();
  1380. return 0;
  1381. }
  1382. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  1383. struct mpath_info *pinfo)
  1384. {
  1385. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  1386. if (next_hop_sta)
  1387. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  1388. else
  1389. eth_zero_addr(next_hop);
  1390. memset(pinfo, 0, sizeof(*pinfo));
  1391. pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
  1392. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  1393. MPATH_INFO_SN |
  1394. MPATH_INFO_METRIC |
  1395. MPATH_INFO_EXPTIME |
  1396. MPATH_INFO_DISCOVERY_TIMEOUT |
  1397. MPATH_INFO_DISCOVERY_RETRIES |
  1398. MPATH_INFO_FLAGS;
  1399. pinfo->frame_qlen = mpath->frame_queue.qlen;
  1400. pinfo->sn = mpath->sn;
  1401. pinfo->metric = mpath->metric;
  1402. if (time_before(jiffies, mpath->exp_time))
  1403. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  1404. pinfo->discovery_timeout =
  1405. jiffies_to_msecs(mpath->discovery_timeout);
  1406. pinfo->discovery_retries = mpath->discovery_retries;
  1407. if (mpath->flags & MESH_PATH_ACTIVE)
  1408. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  1409. if (mpath->flags & MESH_PATH_RESOLVING)
  1410. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  1411. if (mpath->flags & MESH_PATH_SN_VALID)
  1412. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  1413. if (mpath->flags & MESH_PATH_FIXED)
  1414. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  1415. if (mpath->flags & MESH_PATH_RESOLVED)
  1416. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  1417. }
  1418. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  1419. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  1420. {
  1421. struct ieee80211_sub_if_data *sdata;
  1422. struct mesh_path *mpath;
  1423. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1424. rcu_read_lock();
  1425. mpath = mesh_path_lookup(sdata, dst);
  1426. if (!mpath) {
  1427. rcu_read_unlock();
  1428. return -ENOENT;
  1429. }
  1430. memcpy(dst, mpath->dst, ETH_ALEN);
  1431. mpath_set_pinfo(mpath, next_hop, pinfo);
  1432. rcu_read_unlock();
  1433. return 0;
  1434. }
  1435. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  1436. int idx, u8 *dst, u8 *next_hop,
  1437. struct mpath_info *pinfo)
  1438. {
  1439. struct ieee80211_sub_if_data *sdata;
  1440. struct mesh_path *mpath;
  1441. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1442. rcu_read_lock();
  1443. mpath = mesh_path_lookup_by_idx(sdata, idx);
  1444. if (!mpath) {
  1445. rcu_read_unlock();
  1446. return -ENOENT;
  1447. }
  1448. memcpy(dst, mpath->dst, ETH_ALEN);
  1449. mpath_set_pinfo(mpath, next_hop, pinfo);
  1450. rcu_read_unlock();
  1451. return 0;
  1452. }
  1453. static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
  1454. struct mpath_info *pinfo)
  1455. {
  1456. memset(pinfo, 0, sizeof(*pinfo));
  1457. memcpy(mpp, mpath->mpp, ETH_ALEN);
  1458. pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
  1459. }
  1460. static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
  1461. u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  1462. {
  1463. struct ieee80211_sub_if_data *sdata;
  1464. struct mesh_path *mpath;
  1465. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1466. rcu_read_lock();
  1467. mpath = mpp_path_lookup(sdata, dst);
  1468. if (!mpath) {
  1469. rcu_read_unlock();
  1470. return -ENOENT;
  1471. }
  1472. memcpy(dst, mpath->dst, ETH_ALEN);
  1473. mpp_set_pinfo(mpath, mpp, pinfo);
  1474. rcu_read_unlock();
  1475. return 0;
  1476. }
  1477. static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
  1478. int idx, u8 *dst, u8 *mpp,
  1479. struct mpath_info *pinfo)
  1480. {
  1481. struct ieee80211_sub_if_data *sdata;
  1482. struct mesh_path *mpath;
  1483. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1484. rcu_read_lock();
  1485. mpath = mpp_path_lookup_by_idx(sdata, idx);
  1486. if (!mpath) {
  1487. rcu_read_unlock();
  1488. return -ENOENT;
  1489. }
  1490. memcpy(dst, mpath->dst, ETH_ALEN);
  1491. mpp_set_pinfo(mpath, mpp, pinfo);
  1492. rcu_read_unlock();
  1493. return 0;
  1494. }
  1495. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  1496. struct net_device *dev,
  1497. struct mesh_config *conf)
  1498. {
  1499. struct ieee80211_sub_if_data *sdata;
  1500. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1501. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  1502. return 0;
  1503. }
  1504. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  1505. {
  1506. return (mask >> (parm-1)) & 0x1;
  1507. }
  1508. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  1509. const struct mesh_setup *setup)
  1510. {
  1511. u8 *new_ie;
  1512. const u8 *old_ie;
  1513. struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
  1514. struct ieee80211_sub_if_data, u.mesh);
  1515. /* allocate information elements */
  1516. new_ie = NULL;
  1517. old_ie = ifmsh->ie;
  1518. if (setup->ie_len) {
  1519. new_ie = kmemdup(setup->ie, setup->ie_len,
  1520. GFP_KERNEL);
  1521. if (!new_ie)
  1522. return -ENOMEM;
  1523. }
  1524. ifmsh->ie_len = setup->ie_len;
  1525. ifmsh->ie = new_ie;
  1526. kfree(old_ie);
  1527. /* now copy the rest of the setup parameters */
  1528. ifmsh->mesh_id_len = setup->mesh_id_len;
  1529. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  1530. ifmsh->mesh_sp_id = setup->sync_method;
  1531. ifmsh->mesh_pp_id = setup->path_sel_proto;
  1532. ifmsh->mesh_pm_id = setup->path_metric;
  1533. ifmsh->user_mpm = setup->user_mpm;
  1534. ifmsh->mesh_auth_id = setup->auth_id;
  1535. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  1536. if (setup->is_authenticated)
  1537. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  1538. if (setup->is_secure)
  1539. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  1540. /* mcast rate setting in Mesh Node */
  1541. memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
  1542. sizeof(setup->mcast_rate));
  1543. sdata->vif.bss_conf.basic_rates = setup->basic_rates;
  1544. sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
  1545. sdata->vif.bss_conf.dtim_period = setup->dtim_period;
  1546. return 0;
  1547. }
  1548. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  1549. struct net_device *dev, u32 mask,
  1550. const struct mesh_config *nconf)
  1551. {
  1552. struct mesh_config *conf;
  1553. struct ieee80211_sub_if_data *sdata;
  1554. struct ieee80211_if_mesh *ifmsh;
  1555. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1556. ifmsh = &sdata->u.mesh;
  1557. /* Set the config options which we are interested in setting */
  1558. conf = &(sdata->u.mesh.mshcfg);
  1559. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  1560. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  1561. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  1562. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  1563. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  1564. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  1565. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  1566. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  1567. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  1568. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  1569. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  1570. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  1571. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  1572. conf->element_ttl = nconf->element_ttl;
  1573. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
  1574. if (ifmsh->user_mpm)
  1575. return -EBUSY;
  1576. conf->auto_open_plinks = nconf->auto_open_plinks;
  1577. }
  1578. if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
  1579. conf->dot11MeshNbrOffsetMaxNeighbor =
  1580. nconf->dot11MeshNbrOffsetMaxNeighbor;
  1581. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  1582. conf->dot11MeshHWMPmaxPREQretries =
  1583. nconf->dot11MeshHWMPmaxPREQretries;
  1584. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1585. conf->path_refresh_time = nconf->path_refresh_time;
  1586. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1587. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1588. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1589. conf->dot11MeshHWMPactivePathTimeout =
  1590. nconf->dot11MeshHWMPactivePathTimeout;
  1591. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1592. conf->dot11MeshHWMPpreqMinInterval =
  1593. nconf->dot11MeshHWMPpreqMinInterval;
  1594. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  1595. conf->dot11MeshHWMPperrMinInterval =
  1596. nconf->dot11MeshHWMPperrMinInterval;
  1597. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1598. mask))
  1599. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1600. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1601. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1602. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1603. ieee80211_mesh_root_setup(ifmsh);
  1604. }
  1605. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1606. /* our current gate announcement implementation rides on root
  1607. * announcements, so require this ifmsh to also be a root node
  1608. * */
  1609. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1610. !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
  1611. conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
  1612. ieee80211_mesh_root_setup(ifmsh);
  1613. }
  1614. conf->dot11MeshGateAnnouncementProtocol =
  1615. nconf->dot11MeshGateAnnouncementProtocol;
  1616. }
  1617. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  1618. conf->dot11MeshHWMPRannInterval =
  1619. nconf->dot11MeshHWMPRannInterval;
  1620. if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  1621. conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
  1622. if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
  1623. /* our RSSI threshold implementation is supported only for
  1624. * devices that report signal in dBm.
  1625. */
  1626. if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
  1627. return -ENOTSUPP;
  1628. conf->rssi_threshold = nconf->rssi_threshold;
  1629. }
  1630. if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
  1631. conf->ht_opmode = nconf->ht_opmode;
  1632. sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
  1633. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1634. }
  1635. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  1636. conf->dot11MeshHWMPactivePathToRootTimeout =
  1637. nconf->dot11MeshHWMPactivePathToRootTimeout;
  1638. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  1639. conf->dot11MeshHWMProotInterval =
  1640. nconf->dot11MeshHWMProotInterval;
  1641. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  1642. conf->dot11MeshHWMPconfirmationInterval =
  1643. nconf->dot11MeshHWMPconfirmationInterval;
  1644. if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
  1645. conf->power_mode = nconf->power_mode;
  1646. ieee80211_mps_local_status_update(sdata);
  1647. }
  1648. if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
  1649. conf->dot11MeshAwakeWindowDuration =
  1650. nconf->dot11MeshAwakeWindowDuration;
  1651. if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
  1652. conf->plink_timeout = nconf->plink_timeout;
  1653. ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  1654. return 0;
  1655. }
  1656. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1657. const struct mesh_config *conf,
  1658. const struct mesh_setup *setup)
  1659. {
  1660. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1661. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1662. int err;
  1663. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1664. err = copy_mesh_setup(ifmsh, setup);
  1665. if (err)
  1666. return err;
  1667. /* can mesh use other SMPS modes? */
  1668. sdata->smps_mode = IEEE80211_SMPS_OFF;
  1669. sdata->needed_rx_chains = sdata->local->rx_chains;
  1670. mutex_lock(&sdata->local->mtx);
  1671. err = ieee80211_vif_use_channel(sdata, &setup->chandef,
  1672. IEEE80211_CHANCTX_SHARED);
  1673. mutex_unlock(&sdata->local->mtx);
  1674. if (err)
  1675. return err;
  1676. return ieee80211_start_mesh(sdata);
  1677. }
  1678. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1679. {
  1680. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1681. ieee80211_stop_mesh(sdata);
  1682. mutex_lock(&sdata->local->mtx);
  1683. ieee80211_vif_release_channel(sdata);
  1684. mutex_unlock(&sdata->local->mtx);
  1685. return 0;
  1686. }
  1687. #endif
  1688. static int ieee80211_change_bss(struct wiphy *wiphy,
  1689. struct net_device *dev,
  1690. struct bss_parameters *params)
  1691. {
  1692. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1693. struct ieee80211_supported_band *sband;
  1694. u32 changed = 0;
  1695. if (!sdata_dereference(sdata->u.ap.beacon, sdata))
  1696. return -ENOENT;
  1697. sband = ieee80211_get_sband(sdata);
  1698. if (!sband)
  1699. return -EINVAL;
  1700. if (params->use_cts_prot >= 0) {
  1701. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1702. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1703. }
  1704. if (params->use_short_preamble >= 0) {
  1705. sdata->vif.bss_conf.use_short_preamble =
  1706. params->use_short_preamble;
  1707. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1708. }
  1709. if (!sdata->vif.bss_conf.use_short_slot &&
  1710. sband->band == NL80211_BAND_5GHZ) {
  1711. sdata->vif.bss_conf.use_short_slot = true;
  1712. changed |= BSS_CHANGED_ERP_SLOT;
  1713. }
  1714. if (params->use_short_slot_time >= 0) {
  1715. sdata->vif.bss_conf.use_short_slot =
  1716. params->use_short_slot_time;
  1717. changed |= BSS_CHANGED_ERP_SLOT;
  1718. }
  1719. if (params->basic_rates) {
  1720. ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
  1721. wiphy->bands[sband->band],
  1722. params->basic_rates,
  1723. params->basic_rates_len,
  1724. &sdata->vif.bss_conf.basic_rates);
  1725. changed |= BSS_CHANGED_BASIC_RATES;
  1726. }
  1727. if (params->ap_isolate >= 0) {
  1728. if (params->ap_isolate)
  1729. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1730. else
  1731. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1732. ieee80211_check_fast_rx_iface(sdata);
  1733. }
  1734. if (params->ht_opmode >= 0) {
  1735. sdata->vif.bss_conf.ht_operation_mode =
  1736. (u16) params->ht_opmode;
  1737. changed |= BSS_CHANGED_HT;
  1738. }
  1739. if (params->p2p_ctwindow >= 0) {
  1740. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1741. ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1742. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1743. params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
  1744. changed |= BSS_CHANGED_P2P_PS;
  1745. }
  1746. if (params->p2p_opp_ps > 0) {
  1747. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
  1748. IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1749. changed |= BSS_CHANGED_P2P_PS;
  1750. } else if (params->p2p_opp_ps == 0) {
  1751. sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
  1752. ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
  1753. changed |= BSS_CHANGED_P2P_PS;
  1754. }
  1755. ieee80211_bss_info_change_notify(sdata, changed);
  1756. return 0;
  1757. }
  1758. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1759. struct net_device *dev,
  1760. struct ieee80211_txq_params *params)
  1761. {
  1762. struct ieee80211_local *local = wiphy_priv(wiphy);
  1763. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1764. struct ieee80211_tx_queue_params p;
  1765. if (!local->ops->conf_tx)
  1766. return -EOPNOTSUPP;
  1767. if (local->hw.queues < IEEE80211_NUM_ACS)
  1768. return -EOPNOTSUPP;
  1769. memset(&p, 0, sizeof(p));
  1770. p.aifs = params->aifs;
  1771. p.cw_max = params->cwmax;
  1772. p.cw_min = params->cwmin;
  1773. p.txop = params->txop;
  1774. /*
  1775. * Setting tx queue params disables u-apsd because it's only
  1776. * called in master mode.
  1777. */
  1778. p.uapsd = false;
  1779. sdata->tx_conf[params->ac] = p;
  1780. if (drv_conf_tx(local, sdata, params->ac, &p)) {
  1781. wiphy_debug(local->hw.wiphy,
  1782. "failed to set TX queue parameters for AC %d\n",
  1783. params->ac);
  1784. return -EINVAL;
  1785. }
  1786. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1787. return 0;
  1788. }
  1789. #ifdef CONFIG_PM
  1790. static int ieee80211_suspend(struct wiphy *wiphy,
  1791. struct cfg80211_wowlan *wowlan)
  1792. {
  1793. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1794. }
  1795. static int ieee80211_resume(struct wiphy *wiphy)
  1796. {
  1797. return __ieee80211_resume(wiphy_priv(wiphy));
  1798. }
  1799. #else
  1800. #define ieee80211_suspend NULL
  1801. #define ieee80211_resume NULL
  1802. #endif
  1803. static int ieee80211_scan(struct wiphy *wiphy,
  1804. struct cfg80211_scan_request *req)
  1805. {
  1806. struct ieee80211_sub_if_data *sdata;
  1807. sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
  1808. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1809. case NL80211_IFTYPE_STATION:
  1810. case NL80211_IFTYPE_ADHOC:
  1811. case NL80211_IFTYPE_MESH_POINT:
  1812. case NL80211_IFTYPE_P2P_CLIENT:
  1813. case NL80211_IFTYPE_P2P_DEVICE:
  1814. break;
  1815. case NL80211_IFTYPE_P2P_GO:
  1816. if (sdata->local->ops->hw_scan)
  1817. break;
  1818. /*
  1819. * FIXME: implement NoA while scanning in software,
  1820. * for now fall through to allow scanning only when
  1821. * beaconing hasn't been configured yet
  1822. */
  1823. case NL80211_IFTYPE_AP:
  1824. /*
  1825. * If the scan has been forced (and the driver supports
  1826. * forcing), don't care about being beaconing already.
  1827. * This will create problems to the attached stations (e.g. all
  1828. * the frames sent while scanning on other channel will be
  1829. * lost)
  1830. */
  1831. if (sdata->u.ap.beacon &&
  1832. (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
  1833. !(req->flags & NL80211_SCAN_FLAG_AP)))
  1834. return -EOPNOTSUPP;
  1835. break;
  1836. case NL80211_IFTYPE_NAN:
  1837. default:
  1838. return -EOPNOTSUPP;
  1839. }
  1840. return ieee80211_request_scan(sdata, req);
  1841. }
  1842. static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
  1843. {
  1844. ieee80211_scan_cancel(wiphy_priv(wiphy));
  1845. }
  1846. static int
  1847. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1848. struct net_device *dev,
  1849. struct cfg80211_sched_scan_request *req)
  1850. {
  1851. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1852. if (!sdata->local->ops->sched_scan_start)
  1853. return -EOPNOTSUPP;
  1854. return ieee80211_request_sched_scan_start(sdata, req);
  1855. }
  1856. static int
  1857. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1858. {
  1859. struct ieee80211_local *local = wiphy_priv(wiphy);
  1860. if (!local->ops->sched_scan_stop)
  1861. return -EOPNOTSUPP;
  1862. return ieee80211_request_sched_scan_stop(local);
  1863. }
  1864. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1865. struct cfg80211_auth_request *req)
  1866. {
  1867. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1868. }
  1869. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1870. struct cfg80211_assoc_request *req)
  1871. {
  1872. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1873. }
  1874. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1875. struct cfg80211_deauth_request *req)
  1876. {
  1877. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1878. }
  1879. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1880. struct cfg80211_disassoc_request *req)
  1881. {
  1882. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1883. }
  1884. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1885. struct cfg80211_ibss_params *params)
  1886. {
  1887. return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
  1888. }
  1889. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1890. {
  1891. return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1892. }
  1893. static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
  1894. struct ocb_setup *setup)
  1895. {
  1896. return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
  1897. }
  1898. static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
  1899. {
  1900. return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
  1901. }
  1902. static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
  1903. int rate[NUM_NL80211_BANDS])
  1904. {
  1905. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1906. memcpy(sdata->vif.bss_conf.mcast_rate, rate,
  1907. sizeof(int) * NUM_NL80211_BANDS);
  1908. return 0;
  1909. }
  1910. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1911. {
  1912. struct ieee80211_local *local = wiphy_priv(wiphy);
  1913. int err;
  1914. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1915. ieee80211_check_fast_xmit_all(local);
  1916. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1917. if (err) {
  1918. ieee80211_check_fast_xmit_all(local);
  1919. return err;
  1920. }
  1921. }
  1922. if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
  1923. (changed & WIPHY_PARAM_DYN_ACK)) {
  1924. s16 coverage_class;
  1925. coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
  1926. wiphy->coverage_class : -1;
  1927. err = drv_set_coverage_class(local, coverage_class);
  1928. if (err)
  1929. return err;
  1930. }
  1931. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1932. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1933. if (err)
  1934. return err;
  1935. }
  1936. if (changed & WIPHY_PARAM_RETRY_SHORT) {
  1937. if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
  1938. return -EINVAL;
  1939. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1940. }
  1941. if (changed & WIPHY_PARAM_RETRY_LONG) {
  1942. if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
  1943. return -EINVAL;
  1944. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1945. }
  1946. if (changed &
  1947. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1948. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1949. return 0;
  1950. }
  1951. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1952. struct wireless_dev *wdev,
  1953. enum nl80211_tx_power_setting type, int mbm)
  1954. {
  1955. struct ieee80211_local *local = wiphy_priv(wiphy);
  1956. struct ieee80211_sub_if_data *sdata;
  1957. enum nl80211_tx_power_setting txp_type = type;
  1958. bool update_txp_type = false;
  1959. bool has_monitor = false;
  1960. if (wdev) {
  1961. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  1962. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  1963. sdata = rtnl_dereference(local->monitor_sdata);
  1964. if (!sdata)
  1965. return -EOPNOTSUPP;
  1966. }
  1967. switch (type) {
  1968. case NL80211_TX_POWER_AUTOMATIC:
  1969. sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1970. txp_type = NL80211_TX_POWER_LIMITED;
  1971. break;
  1972. case NL80211_TX_POWER_LIMITED:
  1973. case NL80211_TX_POWER_FIXED:
  1974. if (mbm < 0 || (mbm % 100))
  1975. return -EOPNOTSUPP;
  1976. sdata->user_power_level = MBM_TO_DBM(mbm);
  1977. break;
  1978. }
  1979. if (txp_type != sdata->vif.bss_conf.txpower_type) {
  1980. update_txp_type = true;
  1981. sdata->vif.bss_conf.txpower_type = txp_type;
  1982. }
  1983. ieee80211_recalc_txpower(sdata, update_txp_type);
  1984. return 0;
  1985. }
  1986. switch (type) {
  1987. case NL80211_TX_POWER_AUTOMATIC:
  1988. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1989. txp_type = NL80211_TX_POWER_LIMITED;
  1990. break;
  1991. case NL80211_TX_POWER_LIMITED:
  1992. case NL80211_TX_POWER_FIXED:
  1993. if (mbm < 0 || (mbm % 100))
  1994. return -EOPNOTSUPP;
  1995. local->user_power_level = MBM_TO_DBM(mbm);
  1996. break;
  1997. }
  1998. mutex_lock(&local->iflist_mtx);
  1999. list_for_each_entry(sdata, &local->interfaces, list) {
  2000. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2001. has_monitor = true;
  2002. continue;
  2003. }
  2004. sdata->user_power_level = local->user_power_level;
  2005. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2006. update_txp_type = true;
  2007. sdata->vif.bss_conf.txpower_type = txp_type;
  2008. }
  2009. list_for_each_entry(sdata, &local->interfaces, list) {
  2010. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  2011. continue;
  2012. ieee80211_recalc_txpower(sdata, update_txp_type);
  2013. }
  2014. mutex_unlock(&local->iflist_mtx);
  2015. if (has_monitor) {
  2016. sdata = rtnl_dereference(local->monitor_sdata);
  2017. if (sdata) {
  2018. sdata->user_power_level = local->user_power_level;
  2019. if (txp_type != sdata->vif.bss_conf.txpower_type)
  2020. update_txp_type = true;
  2021. sdata->vif.bss_conf.txpower_type = txp_type;
  2022. ieee80211_recalc_txpower(sdata, update_txp_type);
  2023. }
  2024. }
  2025. return 0;
  2026. }
  2027. static int ieee80211_get_tx_power(struct wiphy *wiphy,
  2028. struct wireless_dev *wdev,
  2029. int *dbm)
  2030. {
  2031. struct ieee80211_local *local = wiphy_priv(wiphy);
  2032. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2033. if (local->ops->get_txpower)
  2034. return drv_get_txpower(local, sdata, dbm);
  2035. if (!local->use_chanctx)
  2036. *dbm = local->hw.conf.power_level;
  2037. else
  2038. *dbm = sdata->vif.bss_conf.txpower;
  2039. return 0;
  2040. }
  2041. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  2042. const u8 *addr)
  2043. {
  2044. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2045. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  2046. return 0;
  2047. }
  2048. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  2049. {
  2050. struct ieee80211_local *local = wiphy_priv(wiphy);
  2051. drv_rfkill_poll(local);
  2052. }
  2053. #ifdef CONFIG_NL80211_TESTMODE
  2054. static int ieee80211_testmode_cmd(struct wiphy *wiphy,
  2055. struct wireless_dev *wdev,
  2056. void *data, int len)
  2057. {
  2058. struct ieee80211_local *local = wiphy_priv(wiphy);
  2059. struct ieee80211_vif *vif = NULL;
  2060. if (!local->ops->testmode_cmd)
  2061. return -EOPNOTSUPP;
  2062. if (wdev) {
  2063. struct ieee80211_sub_if_data *sdata;
  2064. sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2065. if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
  2066. vif = &sdata->vif;
  2067. }
  2068. return local->ops->testmode_cmd(&local->hw, vif, data, len);
  2069. }
  2070. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  2071. struct sk_buff *skb,
  2072. struct netlink_callback *cb,
  2073. void *data, int len)
  2074. {
  2075. struct ieee80211_local *local = wiphy_priv(wiphy);
  2076. if (!local->ops->testmode_dump)
  2077. return -EOPNOTSUPP;
  2078. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  2079. }
  2080. #endif
  2081. int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
  2082. enum ieee80211_smps_mode smps_mode)
  2083. {
  2084. struct sta_info *sta;
  2085. enum ieee80211_smps_mode old_req;
  2086. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
  2087. return -EINVAL;
  2088. if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2089. return 0;
  2090. old_req = sdata->u.ap.req_smps;
  2091. sdata->u.ap.req_smps = smps_mode;
  2092. /* AUTOMATIC doesn't mean much for AP - don't allow it */
  2093. if (old_req == smps_mode ||
  2094. smps_mode == IEEE80211_SMPS_AUTOMATIC)
  2095. return 0;
  2096. /* If no associated stations, there's no need to do anything */
  2097. if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
  2098. sdata->smps_mode = smps_mode;
  2099. ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
  2100. return 0;
  2101. }
  2102. ht_dbg(sdata,
  2103. "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
  2104. smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
  2105. mutex_lock(&sdata->local->sta_mtx);
  2106. list_for_each_entry(sta, &sdata->local->sta_list, list) {
  2107. /*
  2108. * Only stations associated to our AP and
  2109. * associated VLANs
  2110. */
  2111. if (sta->sdata->bss != &sdata->u.ap)
  2112. continue;
  2113. /* This station doesn't support MIMO - skip it */
  2114. if (sta_info_tx_streams(sta) == 1)
  2115. continue;
  2116. /*
  2117. * Don't wake up a STA just to send the action frame
  2118. * unless we are getting more restrictive.
  2119. */
  2120. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  2121. !ieee80211_smps_is_restrictive(sta->known_smps_mode,
  2122. smps_mode)) {
  2123. ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
  2124. sta->sta.addr);
  2125. continue;
  2126. }
  2127. /*
  2128. * If the STA is not authorized, wait until it gets
  2129. * authorized and the action frame will be sent then.
  2130. */
  2131. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2132. continue;
  2133. ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
  2134. ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
  2135. sdata->vif.bss_conf.bssid);
  2136. }
  2137. mutex_unlock(&sdata->local->sta_mtx);
  2138. sdata->smps_mode = smps_mode;
  2139. ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
  2140. return 0;
  2141. }
  2142. int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
  2143. enum ieee80211_smps_mode smps_mode)
  2144. {
  2145. const u8 *ap;
  2146. enum ieee80211_smps_mode old_req;
  2147. int err;
  2148. struct sta_info *sta;
  2149. bool tdls_peer_found = false;
  2150. lockdep_assert_held(&sdata->wdev.mtx);
  2151. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
  2152. return -EINVAL;
  2153. old_req = sdata->u.mgd.req_smps;
  2154. sdata->u.mgd.req_smps = smps_mode;
  2155. if (old_req == smps_mode &&
  2156. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  2157. return 0;
  2158. /*
  2159. * If not associated, or current association is not an HT
  2160. * association, there's no need to do anything, just store
  2161. * the new value until we associate.
  2162. */
  2163. if (!sdata->u.mgd.associated ||
  2164. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  2165. return 0;
  2166. ap = sdata->u.mgd.associated->bssid;
  2167. rcu_read_lock();
  2168. list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
  2169. if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
  2170. !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2171. continue;
  2172. tdls_peer_found = true;
  2173. break;
  2174. }
  2175. rcu_read_unlock();
  2176. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  2177. if (tdls_peer_found || !sdata->u.mgd.powersave)
  2178. smps_mode = IEEE80211_SMPS_OFF;
  2179. else
  2180. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2181. }
  2182. /* send SM PS frame to AP */
  2183. err = ieee80211_send_smps_action(sdata, smps_mode,
  2184. ap, ap);
  2185. if (err)
  2186. sdata->u.mgd.req_smps = old_req;
  2187. else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
  2188. ieee80211_teardown_tdls_peers(sdata);
  2189. return err;
  2190. }
  2191. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  2192. bool enabled, int timeout)
  2193. {
  2194. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2195. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2196. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2197. return -EOPNOTSUPP;
  2198. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
  2199. return -EOPNOTSUPP;
  2200. if (enabled == sdata->u.mgd.powersave &&
  2201. timeout == local->dynamic_ps_forced_timeout)
  2202. return 0;
  2203. sdata->u.mgd.powersave = enabled;
  2204. local->dynamic_ps_forced_timeout = timeout;
  2205. /* no change, but if automatic follow powersave */
  2206. sdata_lock(sdata);
  2207. __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
  2208. sdata_unlock(sdata);
  2209. if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  2210. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2211. ieee80211_recalc_ps(local);
  2212. ieee80211_recalc_ps_vif(sdata);
  2213. return 0;
  2214. }
  2215. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  2216. struct net_device *dev,
  2217. s32 rssi_thold, u32 rssi_hyst)
  2218. {
  2219. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2220. struct ieee80211_vif *vif = &sdata->vif;
  2221. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  2222. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  2223. rssi_hyst == bss_conf->cqm_rssi_hyst)
  2224. return 0;
  2225. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
  2226. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
  2227. return -EOPNOTSUPP;
  2228. bss_conf->cqm_rssi_thold = rssi_thold;
  2229. bss_conf->cqm_rssi_hyst = rssi_hyst;
  2230. sdata->u.mgd.last_cqm_event_signal = 0;
  2231. /* tell the driver upon association, unless already associated */
  2232. if (sdata->u.mgd.associated &&
  2233. sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
  2234. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  2235. return 0;
  2236. }
  2237. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  2238. struct net_device *dev,
  2239. const u8 *addr,
  2240. const struct cfg80211_bitrate_mask *mask)
  2241. {
  2242. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2243. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  2244. int i, ret;
  2245. if (!ieee80211_sdata_running(sdata))
  2246. return -ENETDOWN;
  2247. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
  2248. ret = drv_set_bitrate_mask(local, sdata, mask);
  2249. if (ret)
  2250. return ret;
  2251. }
  2252. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  2253. struct ieee80211_supported_band *sband = wiphy->bands[i];
  2254. int j;
  2255. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  2256. memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
  2257. sizeof(mask->control[i].ht_mcs));
  2258. memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
  2259. mask->control[i].vht_mcs,
  2260. sizeof(mask->control[i].vht_mcs));
  2261. sdata->rc_has_mcs_mask[i] = false;
  2262. sdata->rc_has_vht_mcs_mask[i] = false;
  2263. if (!sband)
  2264. continue;
  2265. for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
  2266. if (~sdata->rc_rateidx_mcs_mask[i][j]) {
  2267. sdata->rc_has_mcs_mask[i] = true;
  2268. break;
  2269. }
  2270. }
  2271. for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
  2272. if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
  2273. sdata->rc_has_vht_mcs_mask[i] = true;
  2274. break;
  2275. }
  2276. }
  2277. }
  2278. return 0;
  2279. }
  2280. static int ieee80211_start_radar_detection(struct wiphy *wiphy,
  2281. struct net_device *dev,
  2282. struct cfg80211_chan_def *chandef,
  2283. u32 cac_time_ms)
  2284. {
  2285. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2286. struct ieee80211_local *local = sdata->local;
  2287. int err;
  2288. mutex_lock(&local->mtx);
  2289. if (!list_empty(&local->roc_list) || local->scanning) {
  2290. err = -EBUSY;
  2291. goto out_unlock;
  2292. }
  2293. /* whatever, but channel contexts should not complain about that one */
  2294. sdata->smps_mode = IEEE80211_SMPS_OFF;
  2295. sdata->needed_rx_chains = local->rx_chains;
  2296. err = ieee80211_vif_use_channel(sdata, chandef,
  2297. IEEE80211_CHANCTX_SHARED);
  2298. if (err)
  2299. goto out_unlock;
  2300. ieee80211_queue_delayed_work(&sdata->local->hw,
  2301. &sdata->dfs_cac_timer_work,
  2302. msecs_to_jiffies(cac_time_ms));
  2303. out_unlock:
  2304. mutex_unlock(&local->mtx);
  2305. return err;
  2306. }
  2307. static struct cfg80211_beacon_data *
  2308. cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
  2309. {
  2310. struct cfg80211_beacon_data *new_beacon;
  2311. u8 *pos;
  2312. int len;
  2313. len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
  2314. beacon->proberesp_ies_len + beacon->assocresp_ies_len +
  2315. beacon->probe_resp_len;
  2316. new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
  2317. if (!new_beacon)
  2318. return NULL;
  2319. pos = (u8 *)(new_beacon + 1);
  2320. if (beacon->head_len) {
  2321. new_beacon->head_len = beacon->head_len;
  2322. new_beacon->head = pos;
  2323. memcpy(pos, beacon->head, beacon->head_len);
  2324. pos += beacon->head_len;
  2325. }
  2326. if (beacon->tail_len) {
  2327. new_beacon->tail_len = beacon->tail_len;
  2328. new_beacon->tail = pos;
  2329. memcpy(pos, beacon->tail, beacon->tail_len);
  2330. pos += beacon->tail_len;
  2331. }
  2332. if (beacon->beacon_ies_len) {
  2333. new_beacon->beacon_ies_len = beacon->beacon_ies_len;
  2334. new_beacon->beacon_ies = pos;
  2335. memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
  2336. pos += beacon->beacon_ies_len;
  2337. }
  2338. if (beacon->proberesp_ies_len) {
  2339. new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
  2340. new_beacon->proberesp_ies = pos;
  2341. memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
  2342. pos += beacon->proberesp_ies_len;
  2343. }
  2344. if (beacon->assocresp_ies_len) {
  2345. new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
  2346. new_beacon->assocresp_ies = pos;
  2347. memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
  2348. pos += beacon->assocresp_ies_len;
  2349. }
  2350. if (beacon->probe_resp_len) {
  2351. new_beacon->probe_resp_len = beacon->probe_resp_len;
  2352. new_beacon->probe_resp = pos;
  2353. memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
  2354. pos += beacon->probe_resp_len;
  2355. }
  2356. return new_beacon;
  2357. }
  2358. void ieee80211_csa_finish(struct ieee80211_vif *vif)
  2359. {
  2360. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2361. ieee80211_queue_work(&sdata->local->hw,
  2362. &sdata->csa_finalize_work);
  2363. }
  2364. EXPORT_SYMBOL(ieee80211_csa_finish);
  2365. static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
  2366. u32 *changed)
  2367. {
  2368. int err;
  2369. switch (sdata->vif.type) {
  2370. case NL80211_IFTYPE_AP:
  2371. err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
  2372. NULL);
  2373. kfree(sdata->u.ap.next_beacon);
  2374. sdata->u.ap.next_beacon = NULL;
  2375. if (err < 0)
  2376. return err;
  2377. *changed |= err;
  2378. break;
  2379. case NL80211_IFTYPE_ADHOC:
  2380. err = ieee80211_ibss_finish_csa(sdata);
  2381. if (err < 0)
  2382. return err;
  2383. *changed |= err;
  2384. break;
  2385. #ifdef CONFIG_MAC80211_MESH
  2386. case NL80211_IFTYPE_MESH_POINT:
  2387. err = ieee80211_mesh_finish_csa(sdata);
  2388. if (err < 0)
  2389. return err;
  2390. *changed |= err;
  2391. break;
  2392. #endif
  2393. default:
  2394. WARN_ON(1);
  2395. return -EINVAL;
  2396. }
  2397. return 0;
  2398. }
  2399. static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
  2400. {
  2401. struct ieee80211_local *local = sdata->local;
  2402. u32 changed = 0;
  2403. int err;
  2404. sdata_assert_lock(sdata);
  2405. lockdep_assert_held(&local->mtx);
  2406. lockdep_assert_held(&local->chanctx_mtx);
  2407. /*
  2408. * using reservation isn't immediate as it may be deferred until later
  2409. * with multi-vif. once reservation is complete it will re-schedule the
  2410. * work with no reserved_chanctx so verify chandef to check if it
  2411. * completed successfully
  2412. */
  2413. if (sdata->reserved_chanctx) {
  2414. /*
  2415. * with multi-vif csa driver may call ieee80211_csa_finish()
  2416. * many times while waiting for other interfaces to use their
  2417. * reservations
  2418. */
  2419. if (sdata->reserved_ready)
  2420. return 0;
  2421. return ieee80211_vif_use_reserved_context(sdata);
  2422. }
  2423. if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
  2424. &sdata->csa_chandef))
  2425. return -EINVAL;
  2426. sdata->vif.csa_active = false;
  2427. err = ieee80211_set_after_csa_beacon(sdata, &changed);
  2428. if (err)
  2429. return err;
  2430. ieee80211_bss_info_change_notify(sdata, changed);
  2431. if (sdata->csa_block_tx) {
  2432. ieee80211_wake_vif_queues(local, sdata,
  2433. IEEE80211_QUEUE_STOP_REASON_CSA);
  2434. sdata->csa_block_tx = false;
  2435. }
  2436. err = drv_post_channel_switch(sdata);
  2437. if (err)
  2438. return err;
  2439. cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
  2440. return 0;
  2441. }
  2442. static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
  2443. {
  2444. if (__ieee80211_csa_finalize(sdata)) {
  2445. sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
  2446. cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
  2447. GFP_KERNEL);
  2448. }
  2449. }
  2450. void ieee80211_csa_finalize_work(struct work_struct *work)
  2451. {
  2452. struct ieee80211_sub_if_data *sdata =
  2453. container_of(work, struct ieee80211_sub_if_data,
  2454. csa_finalize_work);
  2455. struct ieee80211_local *local = sdata->local;
  2456. sdata_lock(sdata);
  2457. mutex_lock(&local->mtx);
  2458. mutex_lock(&local->chanctx_mtx);
  2459. /* AP might have been stopped while waiting for the lock. */
  2460. if (!sdata->vif.csa_active)
  2461. goto unlock;
  2462. if (!ieee80211_sdata_running(sdata))
  2463. goto unlock;
  2464. ieee80211_csa_finalize(sdata);
  2465. unlock:
  2466. mutex_unlock(&local->chanctx_mtx);
  2467. mutex_unlock(&local->mtx);
  2468. sdata_unlock(sdata);
  2469. }
  2470. static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
  2471. struct cfg80211_csa_settings *params,
  2472. u32 *changed)
  2473. {
  2474. struct ieee80211_csa_settings csa = {};
  2475. int err;
  2476. switch (sdata->vif.type) {
  2477. case NL80211_IFTYPE_AP:
  2478. sdata->u.ap.next_beacon =
  2479. cfg80211_beacon_dup(&params->beacon_after);
  2480. if (!sdata->u.ap.next_beacon)
  2481. return -ENOMEM;
  2482. /*
  2483. * With a count of 0, we don't have to wait for any
  2484. * TBTT before switching, so complete the CSA
  2485. * immediately. In theory, with a count == 1 we
  2486. * should delay the switch until just before the next
  2487. * TBTT, but that would complicate things so we switch
  2488. * immediately too. If we would delay the switch
  2489. * until the next TBTT, we would have to set the probe
  2490. * response here.
  2491. *
  2492. * TODO: A channel switch with count <= 1 without
  2493. * sending a CSA action frame is kind of useless,
  2494. * because the clients won't know we're changing
  2495. * channels. The action frame must be implemented
  2496. * either here or in the userspace.
  2497. */
  2498. if (params->count <= 1)
  2499. break;
  2500. if ((params->n_counter_offsets_beacon >
  2501. IEEE80211_MAX_CSA_COUNTERS_NUM) ||
  2502. (params->n_counter_offsets_presp >
  2503. IEEE80211_MAX_CSA_COUNTERS_NUM))
  2504. return -EINVAL;
  2505. csa.counter_offsets_beacon = params->counter_offsets_beacon;
  2506. csa.counter_offsets_presp = params->counter_offsets_presp;
  2507. csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
  2508. csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
  2509. csa.count = params->count;
  2510. err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
  2511. if (err < 0) {
  2512. kfree(sdata->u.ap.next_beacon);
  2513. return err;
  2514. }
  2515. *changed |= err;
  2516. break;
  2517. case NL80211_IFTYPE_ADHOC:
  2518. if (!sdata->vif.bss_conf.ibss_joined)
  2519. return -EINVAL;
  2520. if (params->chandef.width != sdata->u.ibss.chandef.width)
  2521. return -EINVAL;
  2522. switch (params->chandef.width) {
  2523. case NL80211_CHAN_WIDTH_40:
  2524. if (cfg80211_get_chandef_type(&params->chandef) !=
  2525. cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
  2526. return -EINVAL;
  2527. case NL80211_CHAN_WIDTH_5:
  2528. case NL80211_CHAN_WIDTH_10:
  2529. case NL80211_CHAN_WIDTH_20_NOHT:
  2530. case NL80211_CHAN_WIDTH_20:
  2531. break;
  2532. default:
  2533. return -EINVAL;
  2534. }
  2535. /* changes into another band are not supported */
  2536. if (sdata->u.ibss.chandef.chan->band !=
  2537. params->chandef.chan->band)
  2538. return -EINVAL;
  2539. /* see comments in the NL80211_IFTYPE_AP block */
  2540. if (params->count > 1) {
  2541. err = ieee80211_ibss_csa_beacon(sdata, params);
  2542. if (err < 0)
  2543. return err;
  2544. *changed |= err;
  2545. }
  2546. ieee80211_send_action_csa(sdata, params);
  2547. break;
  2548. #ifdef CONFIG_MAC80211_MESH
  2549. case NL80211_IFTYPE_MESH_POINT: {
  2550. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2551. if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
  2552. return -EINVAL;
  2553. /* changes into another band are not supported */
  2554. if (sdata->vif.bss_conf.chandef.chan->band !=
  2555. params->chandef.chan->band)
  2556. return -EINVAL;
  2557. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
  2558. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
  2559. if (!ifmsh->pre_value)
  2560. ifmsh->pre_value = 1;
  2561. else
  2562. ifmsh->pre_value++;
  2563. }
  2564. /* see comments in the NL80211_IFTYPE_AP block */
  2565. if (params->count > 1) {
  2566. err = ieee80211_mesh_csa_beacon(sdata, params);
  2567. if (err < 0) {
  2568. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
  2569. return err;
  2570. }
  2571. *changed |= err;
  2572. }
  2573. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
  2574. ieee80211_send_action_csa(sdata, params);
  2575. break;
  2576. }
  2577. #endif
  2578. default:
  2579. return -EOPNOTSUPP;
  2580. }
  2581. return 0;
  2582. }
  2583. static int
  2584. __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2585. struct cfg80211_csa_settings *params)
  2586. {
  2587. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2588. struct ieee80211_local *local = sdata->local;
  2589. struct ieee80211_channel_switch ch_switch;
  2590. struct ieee80211_chanctx_conf *conf;
  2591. struct ieee80211_chanctx *chanctx;
  2592. u32 changed = 0;
  2593. int err;
  2594. sdata_assert_lock(sdata);
  2595. lockdep_assert_held(&local->mtx);
  2596. if (!list_empty(&local->roc_list) || local->scanning)
  2597. return -EBUSY;
  2598. if (sdata->wdev.cac_started)
  2599. return -EBUSY;
  2600. if (cfg80211_chandef_identical(&params->chandef,
  2601. &sdata->vif.bss_conf.chandef))
  2602. return -EINVAL;
  2603. /* don't allow another channel switch if one is already active. */
  2604. if (sdata->vif.csa_active)
  2605. return -EBUSY;
  2606. mutex_lock(&local->chanctx_mtx);
  2607. conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  2608. lockdep_is_held(&local->chanctx_mtx));
  2609. if (!conf) {
  2610. err = -EBUSY;
  2611. goto out;
  2612. }
  2613. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  2614. ch_switch.timestamp = 0;
  2615. ch_switch.device_timestamp = 0;
  2616. ch_switch.block_tx = params->block_tx;
  2617. ch_switch.chandef = params->chandef;
  2618. ch_switch.count = params->count;
  2619. err = drv_pre_channel_switch(sdata, &ch_switch);
  2620. if (err)
  2621. goto out;
  2622. err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
  2623. chanctx->mode,
  2624. params->radar_required);
  2625. if (err)
  2626. goto out;
  2627. /* if reservation is invalid then this will fail */
  2628. err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
  2629. if (err) {
  2630. ieee80211_vif_unreserve_chanctx(sdata);
  2631. goto out;
  2632. }
  2633. err = ieee80211_set_csa_beacon(sdata, params, &changed);
  2634. if (err) {
  2635. ieee80211_vif_unreserve_chanctx(sdata);
  2636. goto out;
  2637. }
  2638. sdata->csa_chandef = params->chandef;
  2639. sdata->csa_block_tx = params->block_tx;
  2640. sdata->vif.csa_active = true;
  2641. if (sdata->csa_block_tx)
  2642. ieee80211_stop_vif_queues(local, sdata,
  2643. IEEE80211_QUEUE_STOP_REASON_CSA);
  2644. cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
  2645. params->count);
  2646. if (changed) {
  2647. ieee80211_bss_info_change_notify(sdata, changed);
  2648. drv_channel_switch_beacon(sdata, &params->chandef);
  2649. } else {
  2650. /* if the beacon didn't change, we can finalize immediately */
  2651. ieee80211_csa_finalize(sdata);
  2652. }
  2653. out:
  2654. mutex_unlock(&local->chanctx_mtx);
  2655. return err;
  2656. }
  2657. int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  2658. struct cfg80211_csa_settings *params)
  2659. {
  2660. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2661. struct ieee80211_local *local = sdata->local;
  2662. int err;
  2663. mutex_lock(&local->mtx);
  2664. err = __ieee80211_channel_switch(wiphy, dev, params);
  2665. mutex_unlock(&local->mtx);
  2666. return err;
  2667. }
  2668. u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
  2669. {
  2670. lockdep_assert_held(&local->mtx);
  2671. local->roc_cookie_counter++;
  2672. /* wow, you wrapped 64 bits ... more likely a bug */
  2673. if (WARN_ON(local->roc_cookie_counter == 0))
  2674. local->roc_cookie_counter++;
  2675. return local->roc_cookie_counter;
  2676. }
  2677. int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
  2678. u64 *cookie, gfp_t gfp)
  2679. {
  2680. unsigned long spin_flags;
  2681. struct sk_buff *ack_skb;
  2682. int id;
  2683. ack_skb = skb_copy(skb, gfp);
  2684. if (!ack_skb)
  2685. return -ENOMEM;
  2686. spin_lock_irqsave(&local->ack_status_lock, spin_flags);
  2687. id = idr_alloc(&local->ack_status_frames, ack_skb,
  2688. 1, 0x10000, GFP_ATOMIC);
  2689. spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
  2690. if (id < 0) {
  2691. kfree_skb(ack_skb);
  2692. return -ENOMEM;
  2693. }
  2694. IEEE80211_SKB_CB(skb)->ack_frame_id = id;
  2695. *cookie = ieee80211_mgmt_tx_cookie(local);
  2696. IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
  2697. return 0;
  2698. }
  2699. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  2700. struct wireless_dev *wdev,
  2701. u16 frame_type, bool reg)
  2702. {
  2703. struct ieee80211_local *local = wiphy_priv(wiphy);
  2704. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2705. switch (frame_type) {
  2706. case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
  2707. if (reg) {
  2708. local->probe_req_reg++;
  2709. sdata->vif.probe_req_reg++;
  2710. } else {
  2711. if (local->probe_req_reg)
  2712. local->probe_req_reg--;
  2713. if (sdata->vif.probe_req_reg)
  2714. sdata->vif.probe_req_reg--;
  2715. }
  2716. if (!local->open_count)
  2717. break;
  2718. if (sdata->vif.probe_req_reg == 1)
  2719. drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
  2720. FIF_PROBE_REQ);
  2721. else if (sdata->vif.probe_req_reg == 0)
  2722. drv_config_iface_filter(local, sdata, 0,
  2723. FIF_PROBE_REQ);
  2724. ieee80211_configure_filter(local);
  2725. break;
  2726. default:
  2727. break;
  2728. }
  2729. }
  2730. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  2731. {
  2732. struct ieee80211_local *local = wiphy_priv(wiphy);
  2733. if (local->started)
  2734. return -EOPNOTSUPP;
  2735. return drv_set_antenna(local, tx_ant, rx_ant);
  2736. }
  2737. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  2738. {
  2739. struct ieee80211_local *local = wiphy_priv(wiphy);
  2740. return drv_get_antenna(local, tx_ant, rx_ant);
  2741. }
  2742. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  2743. struct net_device *dev,
  2744. struct cfg80211_gtk_rekey_data *data)
  2745. {
  2746. struct ieee80211_local *local = wiphy_priv(wiphy);
  2747. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2748. if (!local->ops->set_rekey_data)
  2749. return -EOPNOTSUPP;
  2750. drv_set_rekey_data(local, sdata, data);
  2751. return 0;
  2752. }
  2753. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2754. const u8 *peer, u64 *cookie)
  2755. {
  2756. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2757. struct ieee80211_local *local = sdata->local;
  2758. struct ieee80211_qos_hdr *nullfunc;
  2759. struct sk_buff *skb;
  2760. int size = sizeof(*nullfunc);
  2761. __le16 fc;
  2762. bool qos;
  2763. struct ieee80211_tx_info *info;
  2764. struct sta_info *sta;
  2765. struct ieee80211_chanctx_conf *chanctx_conf;
  2766. enum nl80211_band band;
  2767. int ret;
  2768. /* the lock is needed to assign the cookie later */
  2769. mutex_lock(&local->mtx);
  2770. rcu_read_lock();
  2771. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2772. if (WARN_ON(!chanctx_conf)) {
  2773. ret = -EINVAL;
  2774. goto unlock;
  2775. }
  2776. band = chanctx_conf->def.chan->band;
  2777. sta = sta_info_get_bss(sdata, peer);
  2778. if (sta) {
  2779. qos = sta->sta.wme;
  2780. } else {
  2781. ret = -ENOLINK;
  2782. goto unlock;
  2783. }
  2784. if (qos) {
  2785. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2786. IEEE80211_STYPE_QOS_NULLFUNC |
  2787. IEEE80211_FCTL_FROMDS);
  2788. } else {
  2789. size -= 2;
  2790. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2791. IEEE80211_STYPE_NULLFUNC |
  2792. IEEE80211_FCTL_FROMDS);
  2793. }
  2794. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2795. if (!skb) {
  2796. ret = -ENOMEM;
  2797. goto unlock;
  2798. }
  2799. skb->dev = dev;
  2800. skb_reserve(skb, local->hw.extra_tx_headroom);
  2801. nullfunc = (void *) skb_put(skb, size);
  2802. nullfunc->frame_control = fc;
  2803. nullfunc->duration_id = 0;
  2804. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2805. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2806. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2807. nullfunc->seq_ctrl = 0;
  2808. info = IEEE80211_SKB_CB(skb);
  2809. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2810. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2811. info->band = band;
  2812. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2813. skb->priority = 7;
  2814. if (qos)
  2815. nullfunc->qos_ctrl = cpu_to_le16(7);
  2816. ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
  2817. if (ret) {
  2818. kfree_skb(skb);
  2819. goto unlock;
  2820. }
  2821. local_bh_disable();
  2822. ieee80211_xmit(sdata, sta, skb);
  2823. local_bh_enable();
  2824. ret = 0;
  2825. unlock:
  2826. rcu_read_unlock();
  2827. mutex_unlock(&local->mtx);
  2828. return ret;
  2829. }
  2830. static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
  2831. struct wireless_dev *wdev,
  2832. struct cfg80211_chan_def *chandef)
  2833. {
  2834. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  2835. struct ieee80211_local *local = wiphy_priv(wiphy);
  2836. struct ieee80211_chanctx_conf *chanctx_conf;
  2837. int ret = -ENODATA;
  2838. rcu_read_lock();
  2839. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2840. if (chanctx_conf) {
  2841. *chandef = sdata->vif.bss_conf.chandef;
  2842. ret = 0;
  2843. } else if (local->open_count > 0 &&
  2844. local->open_count == local->monitors &&
  2845. sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  2846. if (local->use_chanctx)
  2847. *chandef = local->monitor_chandef;
  2848. else
  2849. *chandef = local->_oper_chandef;
  2850. ret = 0;
  2851. }
  2852. rcu_read_unlock();
  2853. return ret;
  2854. }
  2855. #ifdef CONFIG_PM
  2856. static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
  2857. {
  2858. drv_set_wakeup(wiphy_priv(wiphy), enabled);
  2859. }
  2860. #endif
  2861. static int ieee80211_set_qos_map(struct wiphy *wiphy,
  2862. struct net_device *dev,
  2863. struct cfg80211_qos_map *qos_map)
  2864. {
  2865. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2866. struct mac80211_qos_map *new_qos_map, *old_qos_map;
  2867. if (qos_map) {
  2868. new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
  2869. if (!new_qos_map)
  2870. return -ENOMEM;
  2871. memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
  2872. } else {
  2873. /* A NULL qos_map was passed to disable QoS mapping */
  2874. new_qos_map = NULL;
  2875. }
  2876. old_qos_map = sdata_dereference(sdata->qos_map, sdata);
  2877. rcu_assign_pointer(sdata->qos_map, new_qos_map);
  2878. if (old_qos_map)
  2879. kfree_rcu(old_qos_map, rcu_head);
  2880. return 0;
  2881. }
  2882. static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
  2883. struct net_device *dev,
  2884. struct cfg80211_chan_def *chandef)
  2885. {
  2886. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2887. int ret;
  2888. u32 changed = 0;
  2889. ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
  2890. if (ret == 0)
  2891. ieee80211_bss_info_change_notify(sdata, changed);
  2892. return ret;
  2893. }
  2894. static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  2895. u8 tsid, const u8 *peer, u8 up,
  2896. u16 admitted_time)
  2897. {
  2898. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2899. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2900. int ac = ieee802_1d_to_ac[up];
  2901. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2902. return -EOPNOTSUPP;
  2903. if (!(sdata->wmm_acm & BIT(up)))
  2904. return -EINVAL;
  2905. if (ifmgd->tx_tspec[ac].admitted_time)
  2906. return -EBUSY;
  2907. if (admitted_time) {
  2908. ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
  2909. ifmgd->tx_tspec[ac].tsid = tsid;
  2910. ifmgd->tx_tspec[ac].up = up;
  2911. }
  2912. return 0;
  2913. }
  2914. static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
  2915. u8 tsid, const u8 *peer)
  2916. {
  2917. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2918. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2919. struct ieee80211_local *local = wiphy_priv(wiphy);
  2920. int ac;
  2921. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  2922. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  2923. /* skip unused entries */
  2924. if (!tx_tspec->admitted_time)
  2925. continue;
  2926. if (tx_tspec->tsid != tsid)
  2927. continue;
  2928. /* due to this new packets will be reassigned to non-ACM ACs */
  2929. tx_tspec->up = -1;
  2930. /* Make sure that all packets have been sent to avoid to
  2931. * restore the QoS params on packets that are still on the
  2932. * queues.
  2933. */
  2934. synchronize_net();
  2935. ieee80211_flush_queues(local, sdata, false);
  2936. /* restore the normal QoS parameters
  2937. * (unconditionally to avoid races)
  2938. */
  2939. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  2940. tx_tspec->downgraded = false;
  2941. ieee80211_sta_handle_tspec_ac_params(sdata);
  2942. /* finally clear all the data */
  2943. memset(tx_tspec, 0, sizeof(*tx_tspec));
  2944. return 0;
  2945. }
  2946. return -ENOENT;
  2947. }
  2948. void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
  2949. u8 inst_id,
  2950. enum nl80211_nan_func_term_reason reason,
  2951. gfp_t gfp)
  2952. {
  2953. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2954. struct cfg80211_nan_func *func;
  2955. u64 cookie;
  2956. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  2957. return;
  2958. spin_lock_bh(&sdata->u.nan.func_lock);
  2959. func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
  2960. if (WARN_ON(!func)) {
  2961. spin_unlock_bh(&sdata->u.nan.func_lock);
  2962. return;
  2963. }
  2964. cookie = func->cookie;
  2965. idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
  2966. spin_unlock_bh(&sdata->u.nan.func_lock);
  2967. cfg80211_free_nan_func(func);
  2968. cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
  2969. reason, cookie, gfp);
  2970. }
  2971. EXPORT_SYMBOL(ieee80211_nan_func_terminated);
  2972. void ieee80211_nan_func_match(struct ieee80211_vif *vif,
  2973. struct cfg80211_nan_match_params *match,
  2974. gfp_t gfp)
  2975. {
  2976. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2977. struct cfg80211_nan_func *func;
  2978. if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
  2979. return;
  2980. spin_lock_bh(&sdata->u.nan.func_lock);
  2981. func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
  2982. if (WARN_ON(!func)) {
  2983. spin_unlock_bh(&sdata->u.nan.func_lock);
  2984. return;
  2985. }
  2986. match->cookie = func->cookie;
  2987. spin_unlock_bh(&sdata->u.nan.func_lock);
  2988. cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
  2989. }
  2990. EXPORT_SYMBOL(ieee80211_nan_func_match);
  2991. const struct cfg80211_ops mac80211_config_ops = {
  2992. .add_virtual_intf = ieee80211_add_iface,
  2993. .del_virtual_intf = ieee80211_del_iface,
  2994. .change_virtual_intf = ieee80211_change_iface,
  2995. .start_p2p_device = ieee80211_start_p2p_device,
  2996. .stop_p2p_device = ieee80211_stop_p2p_device,
  2997. .add_key = ieee80211_add_key,
  2998. .del_key = ieee80211_del_key,
  2999. .get_key = ieee80211_get_key,
  3000. .set_default_key = ieee80211_config_default_key,
  3001. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  3002. .start_ap = ieee80211_start_ap,
  3003. .change_beacon = ieee80211_change_beacon,
  3004. .stop_ap = ieee80211_stop_ap,
  3005. .add_station = ieee80211_add_station,
  3006. .del_station = ieee80211_del_station,
  3007. .change_station = ieee80211_change_station,
  3008. .get_station = ieee80211_get_station,
  3009. .dump_station = ieee80211_dump_station,
  3010. .dump_survey = ieee80211_dump_survey,
  3011. #ifdef CONFIG_MAC80211_MESH
  3012. .add_mpath = ieee80211_add_mpath,
  3013. .del_mpath = ieee80211_del_mpath,
  3014. .change_mpath = ieee80211_change_mpath,
  3015. .get_mpath = ieee80211_get_mpath,
  3016. .dump_mpath = ieee80211_dump_mpath,
  3017. .get_mpp = ieee80211_get_mpp,
  3018. .dump_mpp = ieee80211_dump_mpp,
  3019. .update_mesh_config = ieee80211_update_mesh_config,
  3020. .get_mesh_config = ieee80211_get_mesh_config,
  3021. .join_mesh = ieee80211_join_mesh,
  3022. .leave_mesh = ieee80211_leave_mesh,
  3023. #endif
  3024. .join_ocb = ieee80211_join_ocb,
  3025. .leave_ocb = ieee80211_leave_ocb,
  3026. .change_bss = ieee80211_change_bss,
  3027. .set_txq_params = ieee80211_set_txq_params,
  3028. .set_monitor_channel = ieee80211_set_monitor_channel,
  3029. .suspend = ieee80211_suspend,
  3030. .resume = ieee80211_resume,
  3031. .scan = ieee80211_scan,
  3032. .abort_scan = ieee80211_abort_scan,
  3033. .sched_scan_start = ieee80211_sched_scan_start,
  3034. .sched_scan_stop = ieee80211_sched_scan_stop,
  3035. .auth = ieee80211_auth,
  3036. .assoc = ieee80211_assoc,
  3037. .deauth = ieee80211_deauth,
  3038. .disassoc = ieee80211_disassoc,
  3039. .join_ibss = ieee80211_join_ibss,
  3040. .leave_ibss = ieee80211_leave_ibss,
  3041. .set_mcast_rate = ieee80211_set_mcast_rate,
  3042. .set_wiphy_params = ieee80211_set_wiphy_params,
  3043. .set_tx_power = ieee80211_set_tx_power,
  3044. .get_tx_power = ieee80211_get_tx_power,
  3045. .set_wds_peer = ieee80211_set_wds_peer,
  3046. .rfkill_poll = ieee80211_rfkill_poll,
  3047. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  3048. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  3049. .set_power_mgmt = ieee80211_set_power_mgmt,
  3050. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  3051. .remain_on_channel = ieee80211_remain_on_channel,
  3052. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  3053. .mgmt_tx = ieee80211_mgmt_tx,
  3054. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  3055. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  3056. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  3057. .set_antenna = ieee80211_set_antenna,
  3058. .get_antenna = ieee80211_get_antenna,
  3059. .set_rekey_data = ieee80211_set_rekey_data,
  3060. .tdls_oper = ieee80211_tdls_oper,
  3061. .tdls_mgmt = ieee80211_tdls_mgmt,
  3062. .tdls_channel_switch = ieee80211_tdls_channel_switch,
  3063. .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
  3064. .probe_client = ieee80211_probe_client,
  3065. .set_noack_map = ieee80211_set_noack_map,
  3066. #ifdef CONFIG_PM
  3067. .set_wakeup = ieee80211_set_wakeup,
  3068. #endif
  3069. .get_channel = ieee80211_cfg_get_channel,
  3070. .start_radar_detection = ieee80211_start_radar_detection,
  3071. .channel_switch = ieee80211_channel_switch,
  3072. .set_qos_map = ieee80211_set_qos_map,
  3073. .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
  3074. .add_tx_ts = ieee80211_add_tx_ts,
  3075. .del_tx_ts = ieee80211_del_tx_ts,
  3076. .start_nan = ieee80211_start_nan,
  3077. .stop_nan = ieee80211_stop_nan,
  3078. .nan_change_conf = ieee80211_nan_change_conf,
  3079. .add_nan_func = ieee80211_add_nan_func,
  3080. .del_nan_func = ieee80211_del_nan_func,
  3081. };