cfg.c 85 KB

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