cfg.c 90 KB

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