cfg.c 92 KB

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