cfg.c 65 KB

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