cfg.c 71 KB

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