cfg.c 86 KB

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