cfg.c 91 KB

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