cfg.c 98 KB

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