cfg.c 99 KB

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