cfg.c 102 KB

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