cfg.c 81 KB

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