cfg.c 82 KB

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