cfg.c 105 KB

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