cfg.c 92 KB

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