cfg.c 72 KB

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