cfg.c 99 KB

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