cfg.c 82 KB

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