cfg.c 71 KB

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