cfg.c 71 KB

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