cfg.c 69 KB

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