cfg.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668
  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 net_device *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 net_device *dev;
  28. struct ieee80211_sub_if_data *sdata;
  29. int err;
  30. err = ieee80211_if_add(local, name, &dev, type, params);
  31. if (err)
  32. return ERR_PTR(err);
  33. if (type == NL80211_IFTYPE_MONITOR && flags) {
  34. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  35. sdata->u.mntr_flags = *flags;
  36. }
  37. return dev;
  38. }
  39. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  40. {
  41. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  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_add_key(struct wiphy *wiphy, struct net_device *dev,
  90. u8 key_idx, bool pairwise, const u8 *mac_addr,
  91. struct key_params *params)
  92. {
  93. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. struct sta_info *sta = NULL;
  95. struct ieee80211_key *key;
  96. int err;
  97. if (!ieee80211_sdata_running(sdata))
  98. return -ENETDOWN;
  99. /* reject WEP and TKIP keys if WEP failed to initialize */
  100. switch (params->cipher) {
  101. case WLAN_CIPHER_SUITE_WEP40:
  102. case WLAN_CIPHER_SUITE_TKIP:
  103. case WLAN_CIPHER_SUITE_WEP104:
  104. if (IS_ERR(sdata->local->wep_tx_tfm))
  105. return -EINVAL;
  106. break;
  107. default:
  108. break;
  109. }
  110. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  111. params->key, params->seq_len, params->seq);
  112. if (IS_ERR(key))
  113. return PTR_ERR(key);
  114. if (pairwise)
  115. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  116. mutex_lock(&sdata->local->sta_mtx);
  117. if (mac_addr) {
  118. if (ieee80211_vif_is_mesh(&sdata->vif))
  119. sta = sta_info_get(sdata, mac_addr);
  120. else
  121. sta = sta_info_get_bss(sdata, mac_addr);
  122. if (!sta) {
  123. ieee80211_key_free(sdata->local, key);
  124. err = -ENOENT;
  125. goto out_unlock;
  126. }
  127. }
  128. err = ieee80211_key_link(key, sdata, sta);
  129. if (err)
  130. ieee80211_key_free(sdata->local, key);
  131. out_unlock:
  132. mutex_unlock(&sdata->local->sta_mtx);
  133. return err;
  134. }
  135. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  136. u8 key_idx, bool pairwise, const u8 *mac_addr)
  137. {
  138. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  139. struct ieee80211_local *local = sdata->local;
  140. struct sta_info *sta;
  141. struct ieee80211_key *key = NULL;
  142. int ret;
  143. mutex_lock(&local->sta_mtx);
  144. mutex_lock(&local->key_mtx);
  145. if (mac_addr) {
  146. ret = -ENOENT;
  147. sta = sta_info_get_bss(sdata, mac_addr);
  148. if (!sta)
  149. goto out_unlock;
  150. if (pairwise)
  151. key = key_mtx_dereference(local, sta->ptk);
  152. else
  153. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  154. } else
  155. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  156. if (!key) {
  157. ret = -ENOENT;
  158. goto out_unlock;
  159. }
  160. __ieee80211_key_free(key);
  161. ret = 0;
  162. out_unlock:
  163. mutex_unlock(&local->key_mtx);
  164. mutex_unlock(&local->sta_mtx);
  165. return ret;
  166. }
  167. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  168. u8 key_idx, bool pairwise, const u8 *mac_addr,
  169. void *cookie,
  170. void (*callback)(void *cookie,
  171. struct key_params *params))
  172. {
  173. struct ieee80211_sub_if_data *sdata;
  174. struct sta_info *sta = NULL;
  175. u8 seq[6] = {0};
  176. struct key_params params;
  177. struct ieee80211_key *key = NULL;
  178. u64 pn64;
  179. u32 iv32;
  180. u16 iv16;
  181. int err = -ENOENT;
  182. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  183. rcu_read_lock();
  184. if (mac_addr) {
  185. sta = sta_info_get_bss(sdata, mac_addr);
  186. if (!sta)
  187. goto out;
  188. if (pairwise)
  189. key = rcu_dereference(sta->ptk);
  190. else if (key_idx < NUM_DEFAULT_KEYS)
  191. key = rcu_dereference(sta->gtk[key_idx]);
  192. } else
  193. key = rcu_dereference(sdata->keys[key_idx]);
  194. if (!key)
  195. goto out;
  196. memset(&params, 0, sizeof(params));
  197. params.cipher = key->conf.cipher;
  198. switch (key->conf.cipher) {
  199. case WLAN_CIPHER_SUITE_TKIP:
  200. iv32 = key->u.tkip.tx.iv32;
  201. iv16 = key->u.tkip.tx.iv16;
  202. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  203. drv_get_tkip_seq(sdata->local,
  204. key->conf.hw_key_idx,
  205. &iv32, &iv16);
  206. seq[0] = iv16 & 0xff;
  207. seq[1] = (iv16 >> 8) & 0xff;
  208. seq[2] = iv32 & 0xff;
  209. seq[3] = (iv32 >> 8) & 0xff;
  210. seq[4] = (iv32 >> 16) & 0xff;
  211. seq[5] = (iv32 >> 24) & 0xff;
  212. params.seq = seq;
  213. params.seq_len = 6;
  214. break;
  215. case WLAN_CIPHER_SUITE_CCMP:
  216. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  217. seq[0] = pn64;
  218. seq[1] = pn64 >> 8;
  219. seq[2] = pn64 >> 16;
  220. seq[3] = pn64 >> 24;
  221. seq[4] = pn64 >> 32;
  222. seq[5] = pn64 >> 40;
  223. params.seq = seq;
  224. params.seq_len = 6;
  225. break;
  226. case WLAN_CIPHER_SUITE_AES_CMAC:
  227. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  228. seq[0] = pn64;
  229. seq[1] = pn64 >> 8;
  230. seq[2] = pn64 >> 16;
  231. seq[3] = pn64 >> 24;
  232. seq[4] = pn64 >> 32;
  233. seq[5] = pn64 >> 40;
  234. params.seq = seq;
  235. params.seq_len = 6;
  236. break;
  237. }
  238. params.key = key->conf.key;
  239. params.key_len = key->conf.keylen;
  240. callback(cookie, &params);
  241. err = 0;
  242. out:
  243. rcu_read_unlock();
  244. return err;
  245. }
  246. static int ieee80211_config_default_key(struct wiphy *wiphy,
  247. struct net_device *dev,
  248. u8 key_idx, bool uni,
  249. bool multi)
  250. {
  251. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  252. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  253. return 0;
  254. }
  255. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  256. struct net_device *dev,
  257. u8 key_idx)
  258. {
  259. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  260. ieee80211_set_default_mgmt_key(sdata, key_idx);
  261. return 0;
  262. }
  263. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  264. {
  265. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  266. struct ieee80211_supported_band *sband;
  267. sband = sta->local->hw.wiphy->bands[
  268. sta->local->hw.conf.channel->band];
  269. rate->legacy = sband->bitrates[idx].bitrate;
  270. } else
  271. rate->mcs = idx;
  272. }
  273. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  274. {
  275. struct ieee80211_sub_if_data *sdata = sta->sdata;
  276. struct timespec uptime;
  277. sinfo->generation = sdata->local->sta_generation;
  278. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  279. STATION_INFO_RX_BYTES |
  280. STATION_INFO_TX_BYTES |
  281. STATION_INFO_RX_PACKETS |
  282. STATION_INFO_TX_PACKETS |
  283. STATION_INFO_TX_RETRIES |
  284. STATION_INFO_TX_FAILED |
  285. STATION_INFO_TX_BITRATE |
  286. STATION_INFO_RX_BITRATE |
  287. STATION_INFO_RX_DROP_MISC |
  288. STATION_INFO_BSS_PARAM |
  289. STATION_INFO_CONNECTED_TIME |
  290. STATION_INFO_STA_FLAGS;
  291. do_posix_clock_monotonic_gettime(&uptime);
  292. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  293. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  294. sinfo->rx_bytes = sta->rx_bytes;
  295. sinfo->tx_bytes = sta->tx_bytes;
  296. sinfo->rx_packets = sta->rx_packets;
  297. sinfo->tx_packets = sta->tx_packets;
  298. sinfo->tx_retries = sta->tx_retry_count;
  299. sinfo->tx_failed = sta->tx_retry_failed;
  300. sinfo->rx_dropped_misc = sta->rx_dropped;
  301. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  302. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  303. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  304. sinfo->signal = (s8)sta->last_signal;
  305. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  306. }
  307. sinfo->txrate.flags = 0;
  308. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  309. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  310. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  311. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  312. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  313. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  314. rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
  315. sinfo->rxrate.flags = 0;
  316. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  317. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  318. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  319. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  320. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  321. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  322. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  323. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  324. #ifdef CONFIG_MAC80211_MESH
  325. sinfo->filled |= STATION_INFO_LLID |
  326. STATION_INFO_PLID |
  327. STATION_INFO_PLINK_STATE;
  328. sinfo->llid = le16_to_cpu(sta->llid);
  329. sinfo->plid = le16_to_cpu(sta->plid);
  330. sinfo->plink_state = sta->plink_state;
  331. #endif
  332. }
  333. sinfo->bss_param.flags = 0;
  334. if (sdata->vif.bss_conf.use_cts_prot)
  335. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  336. if (sdata->vif.bss_conf.use_short_preamble)
  337. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  338. if (sdata->vif.bss_conf.use_short_slot)
  339. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  340. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  341. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  342. sinfo->sta_flags.set = 0;
  343. sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
  344. BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
  345. BIT(NL80211_STA_FLAG_WME) |
  346. BIT(NL80211_STA_FLAG_MFP) |
  347. BIT(NL80211_STA_FLAG_AUTHENTICATED) |
  348. BIT(NL80211_STA_FLAG_TDLS_PEER);
  349. if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  350. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  351. if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
  352. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  353. if (test_sta_flag(sta, WLAN_STA_WME))
  354. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
  355. if (test_sta_flag(sta, WLAN_STA_MFP))
  356. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
  357. if (test_sta_flag(sta, WLAN_STA_AUTH))
  358. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  359. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  360. sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  361. }
  362. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  363. int idx, u8 *mac, struct station_info *sinfo)
  364. {
  365. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  366. struct sta_info *sta;
  367. int ret = -ENOENT;
  368. rcu_read_lock();
  369. sta = sta_info_get_by_idx(sdata, idx);
  370. if (sta) {
  371. ret = 0;
  372. memcpy(mac, sta->sta.addr, ETH_ALEN);
  373. sta_set_sinfo(sta, sinfo);
  374. }
  375. rcu_read_unlock();
  376. return ret;
  377. }
  378. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  379. int idx, struct survey_info *survey)
  380. {
  381. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  382. return drv_get_survey(local, idx, survey);
  383. }
  384. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  385. u8 *mac, struct station_info *sinfo)
  386. {
  387. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  388. struct sta_info *sta;
  389. int ret = -ENOENT;
  390. rcu_read_lock();
  391. sta = sta_info_get_bss(sdata, mac);
  392. if (sta) {
  393. ret = 0;
  394. sta_set_sinfo(sta, sinfo);
  395. }
  396. rcu_read_unlock();
  397. return ret;
  398. }
  399. static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
  400. struct beacon_parameters *params)
  401. {
  402. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  403. bss_conf->ssid_len = params->ssid_len;
  404. if (params->ssid_len)
  405. memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
  406. bss_conf->hidden_ssid =
  407. (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
  408. }
  409. /*
  410. * This handles both adding a beacon and setting new beacon info
  411. */
  412. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  413. struct beacon_parameters *params)
  414. {
  415. struct beacon_data *new, *old;
  416. int new_head_len, new_tail_len;
  417. int size;
  418. int err = -EINVAL;
  419. old = rtnl_dereference(sdata->u.ap.beacon);
  420. /* head must not be zero-length */
  421. if (params->head && !params->head_len)
  422. return -EINVAL;
  423. /*
  424. * This is a kludge. beacon interval should really be part
  425. * of the beacon information.
  426. */
  427. if (params->interval &&
  428. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  429. sdata->vif.bss_conf.beacon_int = params->interval;
  430. ieee80211_bss_info_change_notify(sdata,
  431. BSS_CHANGED_BEACON_INT);
  432. }
  433. /* Need to have a beacon head if we don't have one yet */
  434. if (!params->head && !old)
  435. return err;
  436. /* sorry, no way to start beaconing without dtim period */
  437. if (!params->dtim_period && !old)
  438. return err;
  439. /* new or old head? */
  440. if (params->head)
  441. new_head_len = params->head_len;
  442. else
  443. new_head_len = old->head_len;
  444. /* new or old tail? */
  445. if (params->tail || !old)
  446. /* params->tail_len will be zero for !params->tail */
  447. new_tail_len = params->tail_len;
  448. else
  449. new_tail_len = old->tail_len;
  450. size = sizeof(*new) + new_head_len + new_tail_len;
  451. new = kzalloc(size, GFP_KERNEL);
  452. if (!new)
  453. return -ENOMEM;
  454. /* start filling the new info now */
  455. /* new or old dtim period? */
  456. if (params->dtim_period)
  457. new->dtim_period = params->dtim_period;
  458. else
  459. new->dtim_period = old->dtim_period;
  460. /*
  461. * pointers go into the block we allocated,
  462. * memory is | beacon_data | head | tail |
  463. */
  464. new->head = ((u8 *) new) + sizeof(*new);
  465. new->tail = new->head + new_head_len;
  466. new->head_len = new_head_len;
  467. new->tail_len = new_tail_len;
  468. /* copy in head */
  469. if (params->head)
  470. memcpy(new->head, params->head, new_head_len);
  471. else
  472. memcpy(new->head, old->head, new_head_len);
  473. /* copy in optional tail */
  474. if (params->tail)
  475. memcpy(new->tail, params->tail, new_tail_len);
  476. else
  477. if (old)
  478. memcpy(new->tail, old->tail, new_tail_len);
  479. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  480. RCU_INIT_POINTER(sdata->u.ap.beacon, new);
  481. synchronize_rcu();
  482. kfree(old);
  483. ieee80211_config_ap_ssid(sdata, params);
  484. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  485. BSS_CHANGED_BEACON |
  486. BSS_CHANGED_SSID);
  487. return 0;
  488. }
  489. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  490. struct beacon_parameters *params)
  491. {
  492. struct ieee80211_sub_if_data *sdata;
  493. struct beacon_data *old;
  494. struct ieee80211_sub_if_data *vlan;
  495. int ret;
  496. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  497. old = rtnl_dereference(sdata->u.ap.beacon);
  498. if (old)
  499. return -EALREADY;
  500. ret = ieee80211_config_beacon(sdata, params);
  501. if (ret)
  502. return ret;
  503. /*
  504. * Apply control port protocol, this allows us to
  505. * not encrypt dynamic WEP control frames.
  506. */
  507. sdata->control_port_protocol = params->crypto.control_port_ethertype;
  508. sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
  509. list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
  510. vlan->control_port_protocol =
  511. params->crypto.control_port_ethertype;
  512. vlan->control_port_no_encrypt =
  513. params->crypto.control_port_no_encrypt;
  514. }
  515. return 0;
  516. }
  517. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  518. struct beacon_parameters *params)
  519. {
  520. struct ieee80211_sub_if_data *sdata;
  521. struct beacon_data *old;
  522. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  523. old = rtnl_dereference(sdata->u.ap.beacon);
  524. if (!old)
  525. return -ENOENT;
  526. return ieee80211_config_beacon(sdata, params);
  527. }
  528. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  529. {
  530. struct ieee80211_sub_if_data *sdata;
  531. struct beacon_data *old;
  532. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  533. old = rtnl_dereference(sdata->u.ap.beacon);
  534. if (!old)
  535. return -ENOENT;
  536. RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
  537. synchronize_rcu();
  538. kfree(old);
  539. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  540. return 0;
  541. }
  542. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  543. struct iapp_layer2_update {
  544. u8 da[ETH_ALEN]; /* broadcast */
  545. u8 sa[ETH_ALEN]; /* STA addr */
  546. __be16 len; /* 6 */
  547. u8 dsap; /* 0 */
  548. u8 ssap; /* 0 */
  549. u8 control;
  550. u8 xid_info[3];
  551. } __packed;
  552. static void ieee80211_send_layer2_update(struct sta_info *sta)
  553. {
  554. struct iapp_layer2_update *msg;
  555. struct sk_buff *skb;
  556. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  557. * bridge devices */
  558. skb = dev_alloc_skb(sizeof(*msg));
  559. if (!skb)
  560. return;
  561. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  562. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  563. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  564. memset(msg->da, 0xff, ETH_ALEN);
  565. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  566. msg->len = htons(6);
  567. msg->dsap = 0;
  568. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  569. msg->control = 0xaf; /* XID response lsb.1111F101.
  570. * F=0 (no poll command; unsolicited frame) */
  571. msg->xid_info[0] = 0x81; /* XID format identifier */
  572. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  573. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  574. skb->dev = sta->sdata->dev;
  575. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  576. memset(skb->cb, 0, sizeof(skb->cb));
  577. netif_rx_ni(skb);
  578. }
  579. static void sta_apply_parameters(struct ieee80211_local *local,
  580. struct sta_info *sta,
  581. struct station_parameters *params)
  582. {
  583. u32 rates;
  584. int i, j;
  585. struct ieee80211_supported_band *sband;
  586. struct ieee80211_sub_if_data *sdata = sta->sdata;
  587. u32 mask, set;
  588. sband = local->hw.wiphy->bands[local->oper_channel->band];
  589. mask = params->sta_flags_mask;
  590. set = params->sta_flags_set;
  591. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  592. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  593. set_sta_flag(sta, WLAN_STA_AUTHORIZED);
  594. else
  595. clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
  596. }
  597. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  598. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  599. set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  600. else
  601. clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
  602. }
  603. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  604. if (set & BIT(NL80211_STA_FLAG_WME)) {
  605. set_sta_flag(sta, WLAN_STA_WME);
  606. sta->sta.wme = true;
  607. } else {
  608. clear_sta_flag(sta, WLAN_STA_WME);
  609. sta->sta.wme = false;
  610. }
  611. }
  612. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  613. if (set & BIT(NL80211_STA_FLAG_MFP))
  614. set_sta_flag(sta, WLAN_STA_MFP);
  615. else
  616. clear_sta_flag(sta, WLAN_STA_MFP);
  617. }
  618. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  619. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  620. set_sta_flag(sta, WLAN_STA_AUTH);
  621. else
  622. clear_sta_flag(sta, WLAN_STA_AUTH);
  623. }
  624. if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
  625. if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
  626. set_sta_flag(sta, WLAN_STA_TDLS_PEER);
  627. else
  628. clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
  629. }
  630. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
  631. sta->sta.uapsd_queues = params->uapsd_queues;
  632. sta->sta.max_sp = params->max_sp;
  633. }
  634. /*
  635. * cfg80211 validates this (1-2007) and allows setting the AID
  636. * only when creating a new station entry
  637. */
  638. if (params->aid)
  639. sta->sta.aid = params->aid;
  640. /*
  641. * FIXME: updating the following information is racy when this
  642. * function is called from ieee80211_change_station().
  643. * However, all this information should be static so
  644. * maybe we should just reject attemps to change it.
  645. */
  646. if (params->listen_interval >= 0)
  647. sta->listen_interval = params->listen_interval;
  648. if (params->supported_rates) {
  649. rates = 0;
  650. for (i = 0; i < params->supported_rates_len; i++) {
  651. int rate = (params->supported_rates[i] & 0x7f) * 5;
  652. for (j = 0; j < sband->n_bitrates; j++) {
  653. if (sband->bitrates[j].bitrate == rate)
  654. rates |= BIT(j);
  655. }
  656. }
  657. sta->sta.supp_rates[local->oper_channel->band] = rates;
  658. }
  659. if (params->ht_capa)
  660. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  661. params->ht_capa,
  662. &sta->sta.ht_cap);
  663. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  664. #ifdef CONFIG_MAC80211_MESH
  665. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  666. switch (params->plink_state) {
  667. case NL80211_PLINK_LISTEN:
  668. case NL80211_PLINK_ESTAB:
  669. case NL80211_PLINK_BLOCKED:
  670. sta->plink_state = params->plink_state;
  671. break;
  672. default:
  673. /* nothing */
  674. break;
  675. }
  676. else
  677. switch (params->plink_action) {
  678. case PLINK_ACTION_OPEN:
  679. mesh_plink_open(sta);
  680. break;
  681. case PLINK_ACTION_BLOCK:
  682. mesh_plink_block(sta);
  683. break;
  684. }
  685. #endif
  686. }
  687. }
  688. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  689. u8 *mac, struct station_parameters *params)
  690. {
  691. struct ieee80211_local *local = wiphy_priv(wiphy);
  692. struct sta_info *sta;
  693. struct ieee80211_sub_if_data *sdata;
  694. int err;
  695. int layer2_update;
  696. if (params->vlan) {
  697. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  698. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  699. sdata->vif.type != NL80211_IFTYPE_AP)
  700. return -EINVAL;
  701. } else
  702. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  703. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  704. return -EINVAL;
  705. if (is_multicast_ether_addr(mac))
  706. return -EINVAL;
  707. /* Only TDLS-supporting stations can add TDLS peers */
  708. if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  709. !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
  710. sdata->vif.type == NL80211_IFTYPE_STATION))
  711. return -ENOTSUPP;
  712. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  713. if (!sta)
  714. return -ENOMEM;
  715. set_sta_flag(sta, WLAN_STA_AUTH);
  716. set_sta_flag(sta, WLAN_STA_ASSOC);
  717. sta_apply_parameters(local, sta, params);
  718. /*
  719. * for TDLS, rate control should be initialized only when supported
  720. * rates are known.
  721. */
  722. if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
  723. rate_control_rate_init(sta);
  724. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  725. sdata->vif.type == NL80211_IFTYPE_AP;
  726. err = sta_info_insert_rcu(sta);
  727. if (err) {
  728. rcu_read_unlock();
  729. return err;
  730. }
  731. if (layer2_update)
  732. ieee80211_send_layer2_update(sta);
  733. rcu_read_unlock();
  734. return 0;
  735. }
  736. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  737. u8 *mac)
  738. {
  739. struct ieee80211_local *local = wiphy_priv(wiphy);
  740. struct ieee80211_sub_if_data *sdata;
  741. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  742. if (mac)
  743. return sta_info_destroy_addr_bss(sdata, mac);
  744. sta_info_flush(local, sdata);
  745. return 0;
  746. }
  747. static int ieee80211_change_station(struct wiphy *wiphy,
  748. struct net_device *dev,
  749. u8 *mac,
  750. struct station_parameters *params)
  751. {
  752. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  753. struct ieee80211_local *local = wiphy_priv(wiphy);
  754. struct sta_info *sta;
  755. struct ieee80211_sub_if_data *vlansdata;
  756. rcu_read_lock();
  757. sta = sta_info_get_bss(sdata, mac);
  758. if (!sta) {
  759. rcu_read_unlock();
  760. return -ENOENT;
  761. }
  762. /* The TDLS bit cannot be toggled after the STA was added */
  763. if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
  764. !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
  765. !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  766. rcu_read_unlock();
  767. return -EINVAL;
  768. }
  769. if (params->vlan && params->vlan != sta->sdata->dev) {
  770. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  771. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  772. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  773. rcu_read_unlock();
  774. return -EINVAL;
  775. }
  776. if (params->vlan->ieee80211_ptr->use_4addr) {
  777. if (vlansdata->u.vlan.sta) {
  778. rcu_read_unlock();
  779. return -EBUSY;
  780. }
  781. RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
  782. }
  783. sta->sdata = vlansdata;
  784. ieee80211_send_layer2_update(sta);
  785. }
  786. sta_apply_parameters(local, sta, params);
  787. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
  788. rate_control_rate_init(sta);
  789. rcu_read_unlock();
  790. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  791. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  792. ieee80211_recalc_ps(local, -1);
  793. return 0;
  794. }
  795. #ifdef CONFIG_MAC80211_MESH
  796. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  797. u8 *dst, u8 *next_hop)
  798. {
  799. struct ieee80211_sub_if_data *sdata;
  800. struct mesh_path *mpath;
  801. struct sta_info *sta;
  802. int err;
  803. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  804. rcu_read_lock();
  805. sta = sta_info_get(sdata, next_hop);
  806. if (!sta) {
  807. rcu_read_unlock();
  808. return -ENOENT;
  809. }
  810. err = mesh_path_add(dst, sdata);
  811. if (err) {
  812. rcu_read_unlock();
  813. return err;
  814. }
  815. mpath = mesh_path_lookup(dst, sdata);
  816. if (!mpath) {
  817. rcu_read_unlock();
  818. return -ENXIO;
  819. }
  820. mesh_path_fix_nexthop(mpath, sta);
  821. rcu_read_unlock();
  822. return 0;
  823. }
  824. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  825. u8 *dst)
  826. {
  827. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  828. if (dst)
  829. return mesh_path_del(dst, sdata);
  830. mesh_path_flush_by_iface(sdata);
  831. return 0;
  832. }
  833. static int ieee80211_change_mpath(struct wiphy *wiphy,
  834. struct net_device *dev,
  835. u8 *dst, u8 *next_hop)
  836. {
  837. struct ieee80211_sub_if_data *sdata;
  838. struct mesh_path *mpath;
  839. struct sta_info *sta;
  840. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  841. rcu_read_lock();
  842. sta = sta_info_get(sdata, next_hop);
  843. if (!sta) {
  844. rcu_read_unlock();
  845. return -ENOENT;
  846. }
  847. mpath = mesh_path_lookup(dst, sdata);
  848. if (!mpath) {
  849. rcu_read_unlock();
  850. return -ENOENT;
  851. }
  852. mesh_path_fix_nexthop(mpath, sta);
  853. rcu_read_unlock();
  854. return 0;
  855. }
  856. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  857. struct mpath_info *pinfo)
  858. {
  859. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  860. if (next_hop_sta)
  861. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  862. else
  863. memset(next_hop, 0, ETH_ALEN);
  864. pinfo->generation = mesh_paths_generation;
  865. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  866. MPATH_INFO_SN |
  867. MPATH_INFO_METRIC |
  868. MPATH_INFO_EXPTIME |
  869. MPATH_INFO_DISCOVERY_TIMEOUT |
  870. MPATH_INFO_DISCOVERY_RETRIES |
  871. MPATH_INFO_FLAGS;
  872. pinfo->frame_qlen = mpath->frame_queue.qlen;
  873. pinfo->sn = mpath->sn;
  874. pinfo->metric = mpath->metric;
  875. if (time_before(jiffies, mpath->exp_time))
  876. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  877. pinfo->discovery_timeout =
  878. jiffies_to_msecs(mpath->discovery_timeout);
  879. pinfo->discovery_retries = mpath->discovery_retries;
  880. pinfo->flags = 0;
  881. if (mpath->flags & MESH_PATH_ACTIVE)
  882. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  883. if (mpath->flags & MESH_PATH_RESOLVING)
  884. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  885. if (mpath->flags & MESH_PATH_SN_VALID)
  886. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  887. if (mpath->flags & MESH_PATH_FIXED)
  888. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  889. if (mpath->flags & MESH_PATH_RESOLVING)
  890. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  891. pinfo->flags = mpath->flags;
  892. }
  893. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  894. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  895. {
  896. struct ieee80211_sub_if_data *sdata;
  897. struct mesh_path *mpath;
  898. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  899. rcu_read_lock();
  900. mpath = mesh_path_lookup(dst, sdata);
  901. if (!mpath) {
  902. rcu_read_unlock();
  903. return -ENOENT;
  904. }
  905. memcpy(dst, mpath->dst, ETH_ALEN);
  906. mpath_set_pinfo(mpath, next_hop, pinfo);
  907. rcu_read_unlock();
  908. return 0;
  909. }
  910. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  911. int idx, u8 *dst, u8 *next_hop,
  912. struct mpath_info *pinfo)
  913. {
  914. struct ieee80211_sub_if_data *sdata;
  915. struct mesh_path *mpath;
  916. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  917. rcu_read_lock();
  918. mpath = mesh_path_lookup_by_idx(idx, sdata);
  919. if (!mpath) {
  920. rcu_read_unlock();
  921. return -ENOENT;
  922. }
  923. memcpy(dst, mpath->dst, ETH_ALEN);
  924. mpath_set_pinfo(mpath, next_hop, pinfo);
  925. rcu_read_unlock();
  926. return 0;
  927. }
  928. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  929. struct net_device *dev,
  930. struct mesh_config *conf)
  931. {
  932. struct ieee80211_sub_if_data *sdata;
  933. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  934. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  935. return 0;
  936. }
  937. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  938. {
  939. return (mask >> (parm-1)) & 0x1;
  940. }
  941. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  942. const struct mesh_setup *setup)
  943. {
  944. u8 *new_ie;
  945. const u8 *old_ie;
  946. /* allocate information elements */
  947. new_ie = NULL;
  948. old_ie = ifmsh->ie;
  949. if (setup->ie_len) {
  950. new_ie = kmemdup(setup->ie, setup->ie_len,
  951. GFP_KERNEL);
  952. if (!new_ie)
  953. return -ENOMEM;
  954. }
  955. ifmsh->ie_len = setup->ie_len;
  956. ifmsh->ie = new_ie;
  957. kfree(old_ie);
  958. /* now copy the rest of the setup parameters */
  959. ifmsh->mesh_id_len = setup->mesh_id_len;
  960. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  961. ifmsh->mesh_pp_id = setup->path_sel_proto;
  962. ifmsh->mesh_pm_id = setup->path_metric;
  963. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  964. if (setup->is_authenticated)
  965. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  966. if (setup->is_secure)
  967. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  968. return 0;
  969. }
  970. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  971. struct net_device *dev, u32 mask,
  972. const struct mesh_config *nconf)
  973. {
  974. struct mesh_config *conf;
  975. struct ieee80211_sub_if_data *sdata;
  976. struct ieee80211_if_mesh *ifmsh;
  977. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  978. ifmsh = &sdata->u.mesh;
  979. /* Set the config options which we are interested in setting */
  980. conf = &(sdata->u.mesh.mshcfg);
  981. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  982. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  983. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  984. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  985. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  986. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  987. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  988. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  989. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  990. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  991. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  992. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  993. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  994. conf->dot11MeshTTL = nconf->element_ttl;
  995. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  996. conf->auto_open_plinks = nconf->auto_open_plinks;
  997. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  998. conf->dot11MeshHWMPmaxPREQretries =
  999. nconf->dot11MeshHWMPmaxPREQretries;
  1000. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  1001. conf->path_refresh_time = nconf->path_refresh_time;
  1002. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  1003. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  1004. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  1005. conf->dot11MeshHWMPactivePathTimeout =
  1006. nconf->dot11MeshHWMPactivePathTimeout;
  1007. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  1008. conf->dot11MeshHWMPpreqMinInterval =
  1009. nconf->dot11MeshHWMPpreqMinInterval;
  1010. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  1011. mask))
  1012. conf->dot11MeshHWMPnetDiameterTraversalTime =
  1013. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  1014. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  1015. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  1016. ieee80211_mesh_root_setup(ifmsh);
  1017. }
  1018. if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
  1019. /* our current gate announcement implementation rides on root
  1020. * announcements, so require this ifmsh to also be a root node
  1021. * */
  1022. if (nconf->dot11MeshGateAnnouncementProtocol &&
  1023. !conf->dot11MeshHWMPRootMode) {
  1024. conf->dot11MeshHWMPRootMode = 1;
  1025. ieee80211_mesh_root_setup(ifmsh);
  1026. }
  1027. conf->dot11MeshGateAnnouncementProtocol =
  1028. nconf->dot11MeshGateAnnouncementProtocol;
  1029. }
  1030. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
  1031. conf->dot11MeshHWMPRannInterval =
  1032. nconf->dot11MeshHWMPRannInterval;
  1033. }
  1034. return 0;
  1035. }
  1036. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  1037. const struct mesh_config *conf,
  1038. const struct mesh_setup *setup)
  1039. {
  1040. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1041. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1042. int err;
  1043. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  1044. err = copy_mesh_setup(ifmsh, setup);
  1045. if (err)
  1046. return err;
  1047. ieee80211_start_mesh(sdata);
  1048. return 0;
  1049. }
  1050. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  1051. {
  1052. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1053. ieee80211_stop_mesh(sdata);
  1054. return 0;
  1055. }
  1056. #endif
  1057. static int ieee80211_change_bss(struct wiphy *wiphy,
  1058. struct net_device *dev,
  1059. struct bss_parameters *params)
  1060. {
  1061. struct ieee80211_sub_if_data *sdata;
  1062. u32 changed = 0;
  1063. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1064. if (params->use_cts_prot >= 0) {
  1065. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  1066. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1067. }
  1068. if (params->use_short_preamble >= 0) {
  1069. sdata->vif.bss_conf.use_short_preamble =
  1070. params->use_short_preamble;
  1071. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1072. }
  1073. if (!sdata->vif.bss_conf.use_short_slot &&
  1074. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  1075. sdata->vif.bss_conf.use_short_slot = true;
  1076. changed |= BSS_CHANGED_ERP_SLOT;
  1077. }
  1078. if (params->use_short_slot_time >= 0) {
  1079. sdata->vif.bss_conf.use_short_slot =
  1080. params->use_short_slot_time;
  1081. changed |= BSS_CHANGED_ERP_SLOT;
  1082. }
  1083. if (params->basic_rates) {
  1084. int i, j;
  1085. u32 rates = 0;
  1086. struct ieee80211_local *local = wiphy_priv(wiphy);
  1087. struct ieee80211_supported_band *sband =
  1088. wiphy->bands[local->oper_channel->band];
  1089. for (i = 0; i < params->basic_rates_len; i++) {
  1090. int rate = (params->basic_rates[i] & 0x7f) * 5;
  1091. for (j = 0; j < sband->n_bitrates; j++) {
  1092. if (sband->bitrates[j].bitrate == rate)
  1093. rates |= BIT(j);
  1094. }
  1095. }
  1096. sdata->vif.bss_conf.basic_rates = rates;
  1097. changed |= BSS_CHANGED_BASIC_RATES;
  1098. }
  1099. if (params->ap_isolate >= 0) {
  1100. if (params->ap_isolate)
  1101. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1102. else
  1103. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1104. }
  1105. if (params->ht_opmode >= 0) {
  1106. sdata->vif.bss_conf.ht_operation_mode =
  1107. (u16) params->ht_opmode;
  1108. changed |= BSS_CHANGED_HT;
  1109. }
  1110. ieee80211_bss_info_change_notify(sdata, changed);
  1111. return 0;
  1112. }
  1113. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1114. struct net_device *dev,
  1115. struct ieee80211_txq_params *params)
  1116. {
  1117. struct ieee80211_local *local = wiphy_priv(wiphy);
  1118. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1119. struct ieee80211_tx_queue_params p;
  1120. if (!local->ops->conf_tx)
  1121. return -EOPNOTSUPP;
  1122. memset(&p, 0, sizeof(p));
  1123. p.aifs = params->aifs;
  1124. p.cw_max = params->cwmax;
  1125. p.cw_min = params->cwmin;
  1126. p.txop = params->txop;
  1127. /*
  1128. * Setting tx queue params disables u-apsd because it's only
  1129. * called in master mode.
  1130. */
  1131. p.uapsd = false;
  1132. if (params->queue >= local->hw.queues)
  1133. return -EINVAL;
  1134. sdata->tx_conf[params->queue] = p;
  1135. if (drv_conf_tx(local, sdata, params->queue, &p)) {
  1136. wiphy_debug(local->hw.wiphy,
  1137. "failed to set TX queue parameters for queue %d\n",
  1138. params->queue);
  1139. return -EINVAL;
  1140. }
  1141. return 0;
  1142. }
  1143. static int ieee80211_set_channel(struct wiphy *wiphy,
  1144. struct net_device *netdev,
  1145. struct ieee80211_channel *chan,
  1146. enum nl80211_channel_type channel_type)
  1147. {
  1148. struct ieee80211_local *local = wiphy_priv(wiphy);
  1149. struct ieee80211_sub_if_data *sdata = NULL;
  1150. struct ieee80211_channel *old_oper;
  1151. enum nl80211_channel_type old_oper_type;
  1152. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1153. if (netdev)
  1154. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1155. switch (ieee80211_get_channel_mode(local, NULL)) {
  1156. case CHAN_MODE_HOPPING:
  1157. return -EBUSY;
  1158. case CHAN_MODE_FIXED:
  1159. if (local->oper_channel != chan)
  1160. return -EBUSY;
  1161. if (!sdata && local->_oper_channel_type == channel_type)
  1162. return 0;
  1163. break;
  1164. case CHAN_MODE_UNDEFINED:
  1165. break;
  1166. }
  1167. if (sdata)
  1168. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1169. old_oper_type = local->_oper_channel_type;
  1170. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1171. return -EBUSY;
  1172. old_oper = local->oper_channel;
  1173. local->oper_channel = chan;
  1174. /* Update driver if changes were actually made. */
  1175. if ((old_oper != local->oper_channel) ||
  1176. (old_oper_type != local->_oper_channel_type))
  1177. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1178. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1179. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1180. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1181. return 0;
  1182. }
  1183. #ifdef CONFIG_PM
  1184. static int ieee80211_suspend(struct wiphy *wiphy,
  1185. struct cfg80211_wowlan *wowlan)
  1186. {
  1187. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1188. }
  1189. static int ieee80211_resume(struct wiphy *wiphy)
  1190. {
  1191. return __ieee80211_resume(wiphy_priv(wiphy));
  1192. }
  1193. #else
  1194. #define ieee80211_suspend NULL
  1195. #define ieee80211_resume NULL
  1196. #endif
  1197. static int ieee80211_scan(struct wiphy *wiphy,
  1198. struct net_device *dev,
  1199. struct cfg80211_scan_request *req)
  1200. {
  1201. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1202. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1203. case NL80211_IFTYPE_STATION:
  1204. case NL80211_IFTYPE_ADHOC:
  1205. case NL80211_IFTYPE_MESH_POINT:
  1206. case NL80211_IFTYPE_P2P_CLIENT:
  1207. break;
  1208. case NL80211_IFTYPE_P2P_GO:
  1209. if (sdata->local->ops->hw_scan)
  1210. break;
  1211. /*
  1212. * FIXME: implement NoA while scanning in software,
  1213. * for now fall through to allow scanning only when
  1214. * beaconing hasn't been configured yet
  1215. */
  1216. case NL80211_IFTYPE_AP:
  1217. if (sdata->u.ap.beacon)
  1218. return -EOPNOTSUPP;
  1219. break;
  1220. default:
  1221. return -EOPNOTSUPP;
  1222. }
  1223. return ieee80211_request_scan(sdata, req);
  1224. }
  1225. static int
  1226. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1227. struct net_device *dev,
  1228. struct cfg80211_sched_scan_request *req)
  1229. {
  1230. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1231. if (!sdata->local->ops->sched_scan_start)
  1232. return -EOPNOTSUPP;
  1233. return ieee80211_request_sched_scan_start(sdata, req);
  1234. }
  1235. static int
  1236. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1237. {
  1238. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1239. if (!sdata->local->ops->sched_scan_stop)
  1240. return -EOPNOTSUPP;
  1241. return ieee80211_request_sched_scan_stop(sdata);
  1242. }
  1243. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1244. struct cfg80211_auth_request *req)
  1245. {
  1246. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1247. }
  1248. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1249. struct cfg80211_assoc_request *req)
  1250. {
  1251. struct ieee80211_local *local = wiphy_priv(wiphy);
  1252. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1253. switch (ieee80211_get_channel_mode(local, sdata)) {
  1254. case CHAN_MODE_HOPPING:
  1255. return -EBUSY;
  1256. case CHAN_MODE_FIXED:
  1257. if (local->oper_channel == req->bss->channel)
  1258. break;
  1259. return -EBUSY;
  1260. case CHAN_MODE_UNDEFINED:
  1261. break;
  1262. }
  1263. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1264. }
  1265. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1266. struct cfg80211_deauth_request *req,
  1267. void *cookie)
  1268. {
  1269. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1270. req, cookie);
  1271. }
  1272. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1273. struct cfg80211_disassoc_request *req,
  1274. void *cookie)
  1275. {
  1276. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1277. req, cookie);
  1278. }
  1279. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1280. struct cfg80211_ibss_params *params)
  1281. {
  1282. struct ieee80211_local *local = wiphy_priv(wiphy);
  1283. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1284. switch (ieee80211_get_channel_mode(local, sdata)) {
  1285. case CHAN_MODE_HOPPING:
  1286. return -EBUSY;
  1287. case CHAN_MODE_FIXED:
  1288. if (!params->channel_fixed)
  1289. return -EBUSY;
  1290. if (local->oper_channel == params->channel)
  1291. break;
  1292. return -EBUSY;
  1293. case CHAN_MODE_UNDEFINED:
  1294. break;
  1295. }
  1296. return ieee80211_ibss_join(sdata, params);
  1297. }
  1298. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1299. {
  1300. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1301. return ieee80211_ibss_leave(sdata);
  1302. }
  1303. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1304. {
  1305. struct ieee80211_local *local = wiphy_priv(wiphy);
  1306. int err;
  1307. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1308. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1309. if (err)
  1310. return err;
  1311. }
  1312. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1313. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1314. if (err)
  1315. return err;
  1316. }
  1317. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1318. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1319. if (err)
  1320. return err;
  1321. }
  1322. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1323. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1324. if (changed & WIPHY_PARAM_RETRY_LONG)
  1325. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1326. if (changed &
  1327. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1328. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1329. return 0;
  1330. }
  1331. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1332. enum nl80211_tx_power_setting type, int mbm)
  1333. {
  1334. struct ieee80211_local *local = wiphy_priv(wiphy);
  1335. struct ieee80211_channel *chan = local->hw.conf.channel;
  1336. u32 changes = 0;
  1337. switch (type) {
  1338. case NL80211_TX_POWER_AUTOMATIC:
  1339. local->user_power_level = -1;
  1340. break;
  1341. case NL80211_TX_POWER_LIMITED:
  1342. if (mbm < 0 || (mbm % 100))
  1343. return -EOPNOTSUPP;
  1344. local->user_power_level = MBM_TO_DBM(mbm);
  1345. break;
  1346. case NL80211_TX_POWER_FIXED:
  1347. if (mbm < 0 || (mbm % 100))
  1348. return -EOPNOTSUPP;
  1349. /* TODO: move to cfg80211 when it knows the channel */
  1350. if (MBM_TO_DBM(mbm) > chan->max_power)
  1351. return -EINVAL;
  1352. local->user_power_level = MBM_TO_DBM(mbm);
  1353. break;
  1354. }
  1355. ieee80211_hw_config(local, changes);
  1356. return 0;
  1357. }
  1358. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1359. {
  1360. struct ieee80211_local *local = wiphy_priv(wiphy);
  1361. *dbm = local->hw.conf.power_level;
  1362. return 0;
  1363. }
  1364. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1365. const u8 *addr)
  1366. {
  1367. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1368. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1369. return 0;
  1370. }
  1371. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1372. {
  1373. struct ieee80211_local *local = wiphy_priv(wiphy);
  1374. drv_rfkill_poll(local);
  1375. }
  1376. #ifdef CONFIG_NL80211_TESTMODE
  1377. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1378. {
  1379. struct ieee80211_local *local = wiphy_priv(wiphy);
  1380. if (!local->ops->testmode_cmd)
  1381. return -EOPNOTSUPP;
  1382. return local->ops->testmode_cmd(&local->hw, data, len);
  1383. }
  1384. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1385. struct sk_buff *skb,
  1386. struct netlink_callback *cb,
  1387. void *data, int len)
  1388. {
  1389. struct ieee80211_local *local = wiphy_priv(wiphy);
  1390. if (!local->ops->testmode_dump)
  1391. return -EOPNOTSUPP;
  1392. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1393. }
  1394. #endif
  1395. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1396. enum ieee80211_smps_mode smps_mode)
  1397. {
  1398. const u8 *ap;
  1399. enum ieee80211_smps_mode old_req;
  1400. int err;
  1401. lockdep_assert_held(&sdata->u.mgd.mtx);
  1402. old_req = sdata->u.mgd.req_smps;
  1403. sdata->u.mgd.req_smps = smps_mode;
  1404. if (old_req == smps_mode &&
  1405. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1406. return 0;
  1407. /*
  1408. * If not associated, or current association is not an HT
  1409. * association, there's no need to send an action frame.
  1410. */
  1411. if (!sdata->u.mgd.associated ||
  1412. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1413. mutex_lock(&sdata->local->iflist_mtx);
  1414. ieee80211_recalc_smps(sdata->local);
  1415. mutex_unlock(&sdata->local->iflist_mtx);
  1416. return 0;
  1417. }
  1418. ap = sdata->u.mgd.associated->bssid;
  1419. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1420. if (sdata->u.mgd.powersave)
  1421. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1422. else
  1423. smps_mode = IEEE80211_SMPS_OFF;
  1424. }
  1425. /* send SM PS frame to AP */
  1426. err = ieee80211_send_smps_action(sdata, smps_mode,
  1427. ap, ap);
  1428. if (err)
  1429. sdata->u.mgd.req_smps = old_req;
  1430. return err;
  1431. }
  1432. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1433. bool enabled, int timeout)
  1434. {
  1435. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1436. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1437. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1438. return -EOPNOTSUPP;
  1439. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1440. return -EOPNOTSUPP;
  1441. if (enabled == sdata->u.mgd.powersave &&
  1442. timeout == local->dynamic_ps_forced_timeout)
  1443. return 0;
  1444. sdata->u.mgd.powersave = enabled;
  1445. local->dynamic_ps_forced_timeout = timeout;
  1446. /* no change, but if automatic follow powersave */
  1447. mutex_lock(&sdata->u.mgd.mtx);
  1448. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1449. mutex_unlock(&sdata->u.mgd.mtx);
  1450. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1451. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1452. ieee80211_recalc_ps(local, -1);
  1453. return 0;
  1454. }
  1455. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1456. struct net_device *dev,
  1457. s32 rssi_thold, u32 rssi_hyst)
  1458. {
  1459. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1460. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1461. struct ieee80211_vif *vif = &sdata->vif;
  1462. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1463. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1464. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1465. return 0;
  1466. bss_conf->cqm_rssi_thold = rssi_thold;
  1467. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1468. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1469. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1470. return -EOPNOTSUPP;
  1471. return 0;
  1472. }
  1473. /* tell the driver upon association, unless already associated */
  1474. if (sdata->u.mgd.associated)
  1475. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1476. return 0;
  1477. }
  1478. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1479. struct net_device *dev,
  1480. const u8 *addr,
  1481. const struct cfg80211_bitrate_mask *mask)
  1482. {
  1483. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1484. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1485. int i, ret;
  1486. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1487. ret = drv_set_bitrate_mask(local, sdata, mask);
  1488. if (ret)
  1489. return ret;
  1490. }
  1491. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1492. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1493. return 0;
  1494. }
  1495. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1496. struct net_device *dev,
  1497. struct ieee80211_channel *chan,
  1498. enum nl80211_channel_type chantype,
  1499. unsigned int duration, u64 *cookie)
  1500. {
  1501. int ret;
  1502. u32 random_cookie;
  1503. lockdep_assert_held(&local->mtx);
  1504. if (local->hw_roc_cookie)
  1505. return -EBUSY;
  1506. /* must be nonzero */
  1507. random_cookie = random32() | 1;
  1508. *cookie = random_cookie;
  1509. local->hw_roc_dev = dev;
  1510. local->hw_roc_cookie = random_cookie;
  1511. local->hw_roc_channel = chan;
  1512. local->hw_roc_channel_type = chantype;
  1513. local->hw_roc_duration = duration;
  1514. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1515. if (ret) {
  1516. local->hw_roc_channel = NULL;
  1517. local->hw_roc_cookie = 0;
  1518. }
  1519. return ret;
  1520. }
  1521. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1522. struct net_device *dev,
  1523. struct ieee80211_channel *chan,
  1524. enum nl80211_channel_type channel_type,
  1525. unsigned int duration,
  1526. u64 *cookie)
  1527. {
  1528. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1529. struct ieee80211_local *local = sdata->local;
  1530. if (local->ops->remain_on_channel) {
  1531. int ret;
  1532. mutex_lock(&local->mtx);
  1533. ret = ieee80211_remain_on_channel_hw(local, dev,
  1534. chan, channel_type,
  1535. duration, cookie);
  1536. local->hw_roc_for_tx = false;
  1537. mutex_unlock(&local->mtx);
  1538. return ret;
  1539. }
  1540. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1541. duration, cookie);
  1542. }
  1543. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1544. u64 cookie)
  1545. {
  1546. int ret;
  1547. lockdep_assert_held(&local->mtx);
  1548. if (local->hw_roc_cookie != cookie)
  1549. return -ENOENT;
  1550. ret = drv_cancel_remain_on_channel(local);
  1551. if (ret)
  1552. return ret;
  1553. local->hw_roc_cookie = 0;
  1554. local->hw_roc_channel = NULL;
  1555. ieee80211_recalc_idle(local);
  1556. return 0;
  1557. }
  1558. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1559. struct net_device *dev,
  1560. u64 cookie)
  1561. {
  1562. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1563. struct ieee80211_local *local = sdata->local;
  1564. if (local->ops->cancel_remain_on_channel) {
  1565. int ret;
  1566. mutex_lock(&local->mtx);
  1567. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1568. mutex_unlock(&local->mtx);
  1569. return ret;
  1570. }
  1571. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1572. }
  1573. static enum work_done_result
  1574. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1575. {
  1576. /*
  1577. * Use the data embedded in the work struct for reporting
  1578. * here so if the driver mangled the SKB before dropping
  1579. * it (which is the only way we really should get here)
  1580. * then we don't report mangled data.
  1581. *
  1582. * If there was no wait time, then by the time we get here
  1583. * the driver will likely not have reported the status yet,
  1584. * so in that case userspace will have to deal with it.
  1585. */
  1586. if (wk->offchan_tx.wait && !wk->offchan_tx.status)
  1587. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1588. (unsigned long) wk->offchan_tx.frame,
  1589. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1590. return WORK_DONE_DESTROY;
  1591. }
  1592. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1593. struct ieee80211_channel *chan, bool offchan,
  1594. enum nl80211_channel_type channel_type,
  1595. bool channel_type_valid, unsigned int wait,
  1596. const u8 *buf, size_t len, bool no_cck,
  1597. bool dont_wait_for_ack, u64 *cookie)
  1598. {
  1599. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1600. struct ieee80211_local *local = sdata->local;
  1601. struct sk_buff *skb;
  1602. struct sta_info *sta;
  1603. struct ieee80211_work *wk;
  1604. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1605. u32 flags;
  1606. bool is_offchan = false;
  1607. if (dont_wait_for_ack)
  1608. flags = IEEE80211_TX_CTL_NO_ACK;
  1609. else
  1610. flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1611. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1612. /* Check that we are on the requested channel for transmission */
  1613. if (chan != local->tmp_channel &&
  1614. chan != local->oper_channel)
  1615. is_offchan = true;
  1616. if (channel_type_valid &&
  1617. (channel_type != local->tmp_channel_type &&
  1618. channel_type != local->_oper_channel_type))
  1619. is_offchan = true;
  1620. if (chan == local->hw_roc_channel) {
  1621. /* TODO: check channel type? */
  1622. is_offchan = false;
  1623. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1624. }
  1625. if (no_cck)
  1626. flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  1627. if (is_offchan && !offchan)
  1628. return -EBUSY;
  1629. switch (sdata->vif.type) {
  1630. case NL80211_IFTYPE_ADHOC:
  1631. case NL80211_IFTYPE_AP:
  1632. case NL80211_IFTYPE_AP_VLAN:
  1633. case NL80211_IFTYPE_P2P_GO:
  1634. case NL80211_IFTYPE_MESH_POINT:
  1635. if (!ieee80211_is_action(mgmt->frame_control) ||
  1636. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1637. break;
  1638. rcu_read_lock();
  1639. sta = sta_info_get(sdata, mgmt->da);
  1640. rcu_read_unlock();
  1641. if (!sta)
  1642. return -ENOLINK;
  1643. break;
  1644. case NL80211_IFTYPE_STATION:
  1645. case NL80211_IFTYPE_P2P_CLIENT:
  1646. break;
  1647. default:
  1648. return -EOPNOTSUPP;
  1649. }
  1650. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1651. if (!skb)
  1652. return -ENOMEM;
  1653. skb_reserve(skb, local->hw.extra_tx_headroom);
  1654. memcpy(skb_put(skb, len), buf, len);
  1655. IEEE80211_SKB_CB(skb)->flags = flags;
  1656. skb->dev = sdata->dev;
  1657. *cookie = (unsigned long) skb;
  1658. if (is_offchan && local->ops->remain_on_channel) {
  1659. unsigned int duration;
  1660. int ret;
  1661. mutex_lock(&local->mtx);
  1662. /*
  1663. * If the duration is zero, then the driver
  1664. * wouldn't actually do anything. Set it to
  1665. * 100 for now.
  1666. *
  1667. * TODO: cancel the off-channel operation
  1668. * when we get the SKB's TX status and
  1669. * the wait time was zero before.
  1670. */
  1671. duration = 100;
  1672. if (wait)
  1673. duration = wait;
  1674. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1675. channel_type,
  1676. duration, cookie);
  1677. if (ret) {
  1678. kfree_skb(skb);
  1679. mutex_unlock(&local->mtx);
  1680. return ret;
  1681. }
  1682. local->hw_roc_for_tx = true;
  1683. local->hw_roc_duration = wait;
  1684. /*
  1685. * queue up frame for transmission after
  1686. * ieee80211_ready_on_channel call
  1687. */
  1688. /* modify cookie to prevent API mismatches */
  1689. *cookie ^= 2;
  1690. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1691. local->hw_roc_skb = skb;
  1692. local->hw_roc_skb_for_status = skb;
  1693. mutex_unlock(&local->mtx);
  1694. return 0;
  1695. }
  1696. /*
  1697. * Can transmit right away if the channel was the
  1698. * right one and there's no wait involved... If a
  1699. * wait is involved, we might otherwise not be on
  1700. * the right channel for long enough!
  1701. */
  1702. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1703. ieee80211_tx_skb(sdata, skb);
  1704. return 0;
  1705. }
  1706. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1707. if (!wk) {
  1708. kfree_skb(skb);
  1709. return -ENOMEM;
  1710. }
  1711. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1712. wk->chan = chan;
  1713. wk->chan_type = channel_type;
  1714. wk->sdata = sdata;
  1715. wk->done = ieee80211_offchan_tx_done;
  1716. wk->offchan_tx.frame = skb;
  1717. wk->offchan_tx.wait = wait;
  1718. wk->ie_len = len;
  1719. memcpy(wk->ie, buf, len);
  1720. ieee80211_add_work(wk);
  1721. return 0;
  1722. }
  1723. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1724. struct net_device *dev,
  1725. u64 cookie)
  1726. {
  1727. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1728. struct ieee80211_local *local = sdata->local;
  1729. struct ieee80211_work *wk;
  1730. int ret = -ENOENT;
  1731. mutex_lock(&local->mtx);
  1732. if (local->ops->cancel_remain_on_channel) {
  1733. cookie ^= 2;
  1734. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1735. if (ret == 0) {
  1736. kfree_skb(local->hw_roc_skb);
  1737. local->hw_roc_skb = NULL;
  1738. local->hw_roc_skb_for_status = NULL;
  1739. }
  1740. mutex_unlock(&local->mtx);
  1741. return ret;
  1742. }
  1743. list_for_each_entry(wk, &local->work_list, list) {
  1744. if (wk->sdata != sdata)
  1745. continue;
  1746. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1747. continue;
  1748. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1749. continue;
  1750. wk->timeout = jiffies;
  1751. ieee80211_queue_work(&local->hw, &local->work_work);
  1752. ret = 0;
  1753. break;
  1754. }
  1755. mutex_unlock(&local->mtx);
  1756. return ret;
  1757. }
  1758. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1759. struct net_device *dev,
  1760. u16 frame_type, bool reg)
  1761. {
  1762. struct ieee80211_local *local = wiphy_priv(wiphy);
  1763. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1764. return;
  1765. if (reg)
  1766. local->probe_req_reg++;
  1767. else
  1768. local->probe_req_reg--;
  1769. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1770. }
  1771. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1772. {
  1773. struct ieee80211_local *local = wiphy_priv(wiphy);
  1774. if (local->started)
  1775. return -EOPNOTSUPP;
  1776. return drv_set_antenna(local, tx_ant, rx_ant);
  1777. }
  1778. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1779. {
  1780. struct ieee80211_local *local = wiphy_priv(wiphy);
  1781. return drv_get_antenna(local, tx_ant, rx_ant);
  1782. }
  1783. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1784. {
  1785. struct ieee80211_local *local = wiphy_priv(wiphy);
  1786. return drv_set_ringparam(local, tx, rx);
  1787. }
  1788. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1789. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1790. {
  1791. struct ieee80211_local *local = wiphy_priv(wiphy);
  1792. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1793. }
  1794. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  1795. struct net_device *dev,
  1796. struct cfg80211_gtk_rekey_data *data)
  1797. {
  1798. struct ieee80211_local *local = wiphy_priv(wiphy);
  1799. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1800. if (!local->ops->set_rekey_data)
  1801. return -EOPNOTSUPP;
  1802. drv_set_rekey_data(local, sdata, data);
  1803. return 0;
  1804. }
  1805. static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
  1806. {
  1807. u8 *pos = (void *)skb_put(skb, 7);
  1808. *pos++ = WLAN_EID_EXT_CAPABILITY;
  1809. *pos++ = 5; /* len */
  1810. *pos++ = 0x0;
  1811. *pos++ = 0x0;
  1812. *pos++ = 0x0;
  1813. *pos++ = 0x0;
  1814. *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
  1815. }
  1816. static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
  1817. {
  1818. struct ieee80211_local *local = sdata->local;
  1819. u16 capab;
  1820. capab = 0;
  1821. if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
  1822. return capab;
  1823. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  1824. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  1825. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  1826. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  1827. return capab;
  1828. }
  1829. static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
  1830. u8 *peer, u8 *bssid)
  1831. {
  1832. struct ieee80211_tdls_lnkie *lnkid;
  1833. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  1834. lnkid->ie_type = WLAN_EID_LINK_ID;
  1835. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
  1836. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  1837. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  1838. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  1839. }
  1840. static int
  1841. ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
  1842. u8 *peer, u8 action_code, u8 dialog_token,
  1843. u16 status_code, struct sk_buff *skb)
  1844. {
  1845. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1846. struct ieee80211_tdls_data *tf;
  1847. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  1848. memcpy(tf->da, peer, ETH_ALEN);
  1849. memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
  1850. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  1851. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  1852. switch (action_code) {
  1853. case WLAN_TDLS_SETUP_REQUEST:
  1854. tf->category = WLAN_CATEGORY_TDLS;
  1855. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  1856. skb_put(skb, sizeof(tf->u.setup_req));
  1857. tf->u.setup_req.dialog_token = dialog_token;
  1858. tf->u.setup_req.capability =
  1859. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1860. ieee80211_add_srates_ie(&sdata->vif, skb);
  1861. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1862. ieee80211_tdls_add_ext_capab(skb);
  1863. break;
  1864. case WLAN_TDLS_SETUP_RESPONSE:
  1865. tf->category = WLAN_CATEGORY_TDLS;
  1866. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  1867. skb_put(skb, sizeof(tf->u.setup_resp));
  1868. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  1869. tf->u.setup_resp.dialog_token = dialog_token;
  1870. tf->u.setup_resp.capability =
  1871. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1872. ieee80211_add_srates_ie(&sdata->vif, skb);
  1873. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1874. ieee80211_tdls_add_ext_capab(skb);
  1875. break;
  1876. case WLAN_TDLS_SETUP_CONFIRM:
  1877. tf->category = WLAN_CATEGORY_TDLS;
  1878. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  1879. skb_put(skb, sizeof(tf->u.setup_cfm));
  1880. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  1881. tf->u.setup_cfm.dialog_token = dialog_token;
  1882. break;
  1883. case WLAN_TDLS_TEARDOWN:
  1884. tf->category = WLAN_CATEGORY_TDLS;
  1885. tf->action_code = WLAN_TDLS_TEARDOWN;
  1886. skb_put(skb, sizeof(tf->u.teardown));
  1887. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  1888. break;
  1889. case WLAN_TDLS_DISCOVERY_REQUEST:
  1890. tf->category = WLAN_CATEGORY_TDLS;
  1891. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  1892. skb_put(skb, sizeof(tf->u.discover_req));
  1893. tf->u.discover_req.dialog_token = dialog_token;
  1894. break;
  1895. default:
  1896. return -EINVAL;
  1897. }
  1898. return 0;
  1899. }
  1900. static int
  1901. ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
  1902. u8 *peer, u8 action_code, u8 dialog_token,
  1903. u16 status_code, struct sk_buff *skb)
  1904. {
  1905. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1906. struct ieee80211_mgmt *mgmt;
  1907. mgmt = (void *)skb_put(skb, 24);
  1908. memset(mgmt, 0, 24);
  1909. memcpy(mgmt->da, peer, ETH_ALEN);
  1910. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1911. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1912. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1913. IEEE80211_STYPE_ACTION);
  1914. switch (action_code) {
  1915. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1916. skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
  1917. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  1918. mgmt->u.action.u.tdls_discover_resp.action_code =
  1919. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  1920. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  1921. dialog_token;
  1922. mgmt->u.action.u.tdls_discover_resp.capability =
  1923. cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
  1924. ieee80211_add_srates_ie(&sdata->vif, skb);
  1925. ieee80211_add_ext_srates_ie(&sdata->vif, skb);
  1926. ieee80211_tdls_add_ext_capab(skb);
  1927. break;
  1928. default:
  1929. return -EINVAL;
  1930. }
  1931. return 0;
  1932. }
  1933. static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1934. u8 *peer, u8 action_code, u8 dialog_token,
  1935. u16 status_code, const u8 *extra_ies,
  1936. size_t extra_ies_len)
  1937. {
  1938. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1939. struct ieee80211_local *local = sdata->local;
  1940. struct ieee80211_tx_info *info;
  1941. struct sk_buff *skb = NULL;
  1942. bool send_direct;
  1943. int ret;
  1944. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  1945. return -ENOTSUPP;
  1946. /* make sure we are in managed mode, and associated */
  1947. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  1948. !sdata->u.mgd.associated)
  1949. return -EINVAL;
  1950. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  1951. printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
  1952. #endif
  1953. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  1954. max(sizeof(struct ieee80211_mgmt),
  1955. sizeof(struct ieee80211_tdls_data)) +
  1956. 50 + /* supported rates */
  1957. 7 + /* ext capab */
  1958. extra_ies_len +
  1959. sizeof(struct ieee80211_tdls_lnkie));
  1960. if (!skb)
  1961. return -ENOMEM;
  1962. info = IEEE80211_SKB_CB(skb);
  1963. skb_reserve(skb, local->hw.extra_tx_headroom);
  1964. switch (action_code) {
  1965. case WLAN_TDLS_SETUP_REQUEST:
  1966. case WLAN_TDLS_SETUP_RESPONSE:
  1967. case WLAN_TDLS_SETUP_CONFIRM:
  1968. case WLAN_TDLS_TEARDOWN:
  1969. case WLAN_TDLS_DISCOVERY_REQUEST:
  1970. ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
  1971. action_code, dialog_token,
  1972. status_code, skb);
  1973. send_direct = false;
  1974. break;
  1975. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  1976. ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
  1977. dialog_token, status_code,
  1978. skb);
  1979. send_direct = true;
  1980. break;
  1981. default:
  1982. ret = -ENOTSUPP;
  1983. break;
  1984. }
  1985. if (ret < 0)
  1986. goto fail;
  1987. if (extra_ies_len)
  1988. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  1989. /* the TDLS link IE is always added last */
  1990. switch (action_code) {
  1991. case WLAN_TDLS_SETUP_REQUEST:
  1992. case WLAN_TDLS_SETUP_CONFIRM:
  1993. case WLAN_TDLS_TEARDOWN:
  1994. case WLAN_TDLS_DISCOVERY_REQUEST:
  1995. /* we are the initiator */
  1996. ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
  1997. sdata->u.mgd.bssid);
  1998. break;
  1999. case WLAN_TDLS_SETUP_RESPONSE:
  2000. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  2001. /* we are the responder */
  2002. ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
  2003. sdata->u.mgd.bssid);
  2004. break;
  2005. default:
  2006. ret = -ENOTSUPP;
  2007. goto fail;
  2008. }
  2009. if (send_direct) {
  2010. ieee80211_tx_skb(sdata, skb);
  2011. return 0;
  2012. }
  2013. /*
  2014. * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
  2015. * we should default to AC_VI.
  2016. */
  2017. switch (action_code) {
  2018. case WLAN_TDLS_SETUP_REQUEST:
  2019. case WLAN_TDLS_SETUP_RESPONSE:
  2020. skb_set_queue_mapping(skb, IEEE80211_AC_BK);
  2021. skb->priority = 2;
  2022. break;
  2023. default:
  2024. skb_set_queue_mapping(skb, IEEE80211_AC_VI);
  2025. skb->priority = 5;
  2026. break;
  2027. }
  2028. /* disable bottom halves when entering the Tx path */
  2029. local_bh_disable();
  2030. ret = ieee80211_subif_start_xmit(skb, dev);
  2031. local_bh_enable();
  2032. return ret;
  2033. fail:
  2034. dev_kfree_skb(skb);
  2035. return ret;
  2036. }
  2037. static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
  2038. u8 *peer, enum nl80211_tdls_operation oper)
  2039. {
  2040. struct sta_info *sta;
  2041. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2042. if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
  2043. return -ENOTSUPP;
  2044. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2045. return -EINVAL;
  2046. #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
  2047. printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
  2048. #endif
  2049. switch (oper) {
  2050. case NL80211_TDLS_ENABLE_LINK:
  2051. rcu_read_lock();
  2052. sta = sta_info_get(sdata, peer);
  2053. if (!sta) {
  2054. rcu_read_unlock();
  2055. return -ENOLINK;
  2056. }
  2057. set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
  2058. rcu_read_unlock();
  2059. break;
  2060. case NL80211_TDLS_DISABLE_LINK:
  2061. return sta_info_destroy_addr(sdata, peer);
  2062. case NL80211_TDLS_TEARDOWN:
  2063. case NL80211_TDLS_SETUP:
  2064. case NL80211_TDLS_DISCOVERY_REQ:
  2065. /* We don't support in-driver setup/teardown/discovery */
  2066. return -ENOTSUPP;
  2067. default:
  2068. return -ENOTSUPP;
  2069. }
  2070. return 0;
  2071. }
  2072. static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
  2073. const u8 *peer, u64 *cookie)
  2074. {
  2075. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2076. struct ieee80211_local *local = sdata->local;
  2077. struct ieee80211_qos_hdr *nullfunc;
  2078. struct sk_buff *skb;
  2079. int size = sizeof(*nullfunc);
  2080. __le16 fc;
  2081. bool qos;
  2082. struct ieee80211_tx_info *info;
  2083. struct sta_info *sta;
  2084. rcu_read_lock();
  2085. sta = sta_info_get(sdata, peer);
  2086. if (sta)
  2087. qos = test_sta_flag(sta, WLAN_STA_WME);
  2088. rcu_read_unlock();
  2089. if (!sta)
  2090. return -ENOLINK;
  2091. if (qos) {
  2092. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2093. IEEE80211_STYPE_QOS_NULLFUNC |
  2094. IEEE80211_FCTL_FROMDS);
  2095. } else {
  2096. size -= 2;
  2097. fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
  2098. IEEE80211_STYPE_NULLFUNC |
  2099. IEEE80211_FCTL_FROMDS);
  2100. }
  2101. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
  2102. if (!skb)
  2103. return -ENOMEM;
  2104. skb->dev = dev;
  2105. skb_reserve(skb, local->hw.extra_tx_headroom);
  2106. nullfunc = (void *) skb_put(skb, size);
  2107. nullfunc->frame_control = fc;
  2108. nullfunc->duration_id = 0;
  2109. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  2110. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2111. memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
  2112. nullfunc->seq_ctrl = 0;
  2113. info = IEEE80211_SKB_CB(skb);
  2114. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2115. IEEE80211_TX_INTFL_NL80211_FRAME_TX;
  2116. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  2117. skb->priority = 7;
  2118. if (qos)
  2119. nullfunc->qos_ctrl = cpu_to_le16(7);
  2120. local_bh_disable();
  2121. ieee80211_xmit(sdata, skb);
  2122. local_bh_enable();
  2123. *cookie = (unsigned long) skb;
  2124. return 0;
  2125. }
  2126. static struct ieee80211_channel *
  2127. ieee80211_wiphy_get_channel(struct wiphy *wiphy)
  2128. {
  2129. struct ieee80211_local *local = wiphy_priv(wiphy);
  2130. return local->oper_channel;
  2131. }
  2132. struct cfg80211_ops mac80211_config_ops = {
  2133. .add_virtual_intf = ieee80211_add_iface,
  2134. .del_virtual_intf = ieee80211_del_iface,
  2135. .change_virtual_intf = ieee80211_change_iface,
  2136. .add_key = ieee80211_add_key,
  2137. .del_key = ieee80211_del_key,
  2138. .get_key = ieee80211_get_key,
  2139. .set_default_key = ieee80211_config_default_key,
  2140. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  2141. .add_beacon = ieee80211_add_beacon,
  2142. .set_beacon = ieee80211_set_beacon,
  2143. .del_beacon = ieee80211_del_beacon,
  2144. .add_station = ieee80211_add_station,
  2145. .del_station = ieee80211_del_station,
  2146. .change_station = ieee80211_change_station,
  2147. .get_station = ieee80211_get_station,
  2148. .dump_station = ieee80211_dump_station,
  2149. .dump_survey = ieee80211_dump_survey,
  2150. #ifdef CONFIG_MAC80211_MESH
  2151. .add_mpath = ieee80211_add_mpath,
  2152. .del_mpath = ieee80211_del_mpath,
  2153. .change_mpath = ieee80211_change_mpath,
  2154. .get_mpath = ieee80211_get_mpath,
  2155. .dump_mpath = ieee80211_dump_mpath,
  2156. .update_mesh_config = ieee80211_update_mesh_config,
  2157. .get_mesh_config = ieee80211_get_mesh_config,
  2158. .join_mesh = ieee80211_join_mesh,
  2159. .leave_mesh = ieee80211_leave_mesh,
  2160. #endif
  2161. .change_bss = ieee80211_change_bss,
  2162. .set_txq_params = ieee80211_set_txq_params,
  2163. .set_channel = ieee80211_set_channel,
  2164. .suspend = ieee80211_suspend,
  2165. .resume = ieee80211_resume,
  2166. .scan = ieee80211_scan,
  2167. .sched_scan_start = ieee80211_sched_scan_start,
  2168. .sched_scan_stop = ieee80211_sched_scan_stop,
  2169. .auth = ieee80211_auth,
  2170. .assoc = ieee80211_assoc,
  2171. .deauth = ieee80211_deauth,
  2172. .disassoc = ieee80211_disassoc,
  2173. .join_ibss = ieee80211_join_ibss,
  2174. .leave_ibss = ieee80211_leave_ibss,
  2175. .set_wiphy_params = ieee80211_set_wiphy_params,
  2176. .set_tx_power = ieee80211_set_tx_power,
  2177. .get_tx_power = ieee80211_get_tx_power,
  2178. .set_wds_peer = ieee80211_set_wds_peer,
  2179. .rfkill_poll = ieee80211_rfkill_poll,
  2180. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  2181. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  2182. .set_power_mgmt = ieee80211_set_power_mgmt,
  2183. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  2184. .remain_on_channel = ieee80211_remain_on_channel,
  2185. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  2186. .mgmt_tx = ieee80211_mgmt_tx,
  2187. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  2188. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  2189. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  2190. .set_antenna = ieee80211_set_antenna,
  2191. .get_antenna = ieee80211_get_antenna,
  2192. .set_ringparam = ieee80211_set_ringparam,
  2193. .get_ringparam = ieee80211_get_ringparam,
  2194. .set_rekey_data = ieee80211_set_rekey_data,
  2195. .tdls_oper = ieee80211_tdls_oper,
  2196. .tdls_mgmt = ieee80211_tdls_mgmt,
  2197. .probe_client = ieee80211_probe_client,
  2198. .get_channel = ieee80211_wiphy_get_channel,
  2199. };