cfg.c 101 KB

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