cfg.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  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 <net/cfg80211.h>
  15. #include "ieee80211_i.h"
  16. #include "driver-ops.h"
  17. #include "cfg.h"
  18. #include "rate.h"
  19. #include "mesh.h"
  20. static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
  21. enum nl80211_iftype type,
  22. u32 *flags,
  23. struct vif_params *params)
  24. {
  25. struct ieee80211_local *local = wiphy_priv(wiphy);
  26. struct net_device *dev;
  27. struct ieee80211_sub_if_data *sdata;
  28. int err;
  29. err = ieee80211_if_add(local, name, &dev, type, params);
  30. if (err)
  31. return ERR_PTR(err);
  32. if (type == NL80211_IFTYPE_MONITOR && flags) {
  33. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  34. sdata->u.mntr_flags = *flags;
  35. }
  36. return dev;
  37. }
  38. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  39. {
  40. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  41. return 0;
  42. }
  43. static int ieee80211_change_iface(struct wiphy *wiphy,
  44. struct net_device *dev,
  45. enum nl80211_iftype type, u32 *flags,
  46. struct vif_params *params)
  47. {
  48. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  49. int ret;
  50. ret = ieee80211_if_change_type(sdata, type);
  51. if (ret)
  52. return ret;
  53. if (type == NL80211_IFTYPE_AP_VLAN &&
  54. params && params->use_4addr == 0)
  55. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  56. else if (type == NL80211_IFTYPE_STATION &&
  57. params && params->use_4addr >= 0)
  58. sdata->u.mgd.use_4addr = params->use_4addr;
  59. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
  60. struct ieee80211_local *local = sdata->local;
  61. if (ieee80211_sdata_running(sdata)) {
  62. /*
  63. * Prohibit MONITOR_FLAG_COOK_FRAMES to be
  64. * changed while the interface is up.
  65. * Else we would need to add a lot of cruft
  66. * to update everything:
  67. * cooked_mntrs, monitor and all fif_* counters
  68. * reconfigure hardware
  69. */
  70. if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
  71. (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  72. return -EBUSY;
  73. ieee80211_adjust_monitor_flags(sdata, -1);
  74. sdata->u.mntr_flags = *flags;
  75. ieee80211_adjust_monitor_flags(sdata, 1);
  76. ieee80211_configure_filter(local);
  77. } else {
  78. /*
  79. * Because the interface is down, ieee80211_do_stop
  80. * and ieee80211_do_open take care of "everything"
  81. * mentioned in the comment above.
  82. */
  83. sdata->u.mntr_flags = *flags;
  84. }
  85. }
  86. return 0;
  87. }
  88. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  89. u8 key_idx, bool pairwise, const u8 *mac_addr,
  90. struct key_params *params)
  91. {
  92. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  93. struct sta_info *sta = NULL;
  94. struct ieee80211_key *key;
  95. int err;
  96. if (!ieee80211_sdata_running(sdata))
  97. return -ENETDOWN;
  98. /* reject WEP and TKIP keys if WEP failed to initialize */
  99. switch (params->cipher) {
  100. case WLAN_CIPHER_SUITE_WEP40:
  101. case WLAN_CIPHER_SUITE_TKIP:
  102. case WLAN_CIPHER_SUITE_WEP104:
  103. if (IS_ERR(sdata->local->wep_tx_tfm))
  104. return -EINVAL;
  105. break;
  106. default:
  107. break;
  108. }
  109. key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
  110. params->key, params->seq_len, params->seq);
  111. if (IS_ERR(key))
  112. return PTR_ERR(key);
  113. if (pairwise)
  114. key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
  115. mutex_lock(&sdata->local->sta_mtx);
  116. if (mac_addr) {
  117. sta = sta_info_get_bss(sdata, mac_addr);
  118. if (!sta) {
  119. ieee80211_key_free(sdata->local, key);
  120. err = -ENOENT;
  121. goto out_unlock;
  122. }
  123. }
  124. err = ieee80211_key_link(key, sdata, sta);
  125. if (err)
  126. ieee80211_key_free(sdata->local, key);
  127. out_unlock:
  128. mutex_unlock(&sdata->local->sta_mtx);
  129. return err;
  130. }
  131. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  132. u8 key_idx, bool pairwise, const u8 *mac_addr)
  133. {
  134. struct ieee80211_sub_if_data *sdata;
  135. struct sta_info *sta;
  136. int ret;
  137. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  138. mutex_lock(&sdata->local->sta_mtx);
  139. if (mac_addr) {
  140. ret = -ENOENT;
  141. sta = sta_info_get_bss(sdata, mac_addr);
  142. if (!sta)
  143. goto out_unlock;
  144. if (pairwise) {
  145. if (sta->ptk) {
  146. ieee80211_key_free(sdata->local, sta->ptk);
  147. ret = 0;
  148. }
  149. } else {
  150. if (sta->gtk[key_idx]) {
  151. ieee80211_key_free(sdata->local,
  152. sta->gtk[key_idx]);
  153. ret = 0;
  154. }
  155. }
  156. goto out_unlock;
  157. }
  158. if (!sdata->keys[key_idx]) {
  159. ret = -ENOENT;
  160. goto out_unlock;
  161. }
  162. ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
  163. WARN_ON(sdata->keys[key_idx]);
  164. ret = 0;
  165. out_unlock:
  166. mutex_unlock(&sdata->local->sta_mtx);
  167. return ret;
  168. }
  169. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  170. u8 key_idx, bool pairwise, const u8 *mac_addr,
  171. void *cookie,
  172. void (*callback)(void *cookie,
  173. struct key_params *params))
  174. {
  175. struct ieee80211_sub_if_data *sdata;
  176. struct sta_info *sta = NULL;
  177. u8 seq[6] = {0};
  178. struct key_params params;
  179. struct ieee80211_key *key = NULL;
  180. u32 iv32;
  181. u16 iv16;
  182. int err = -ENOENT;
  183. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  184. rcu_read_lock();
  185. if (mac_addr) {
  186. sta = sta_info_get_bss(sdata, mac_addr);
  187. if (!sta)
  188. goto out;
  189. if (pairwise)
  190. key = sta->ptk;
  191. else if (key_idx < NUM_DEFAULT_KEYS)
  192. key = sta->gtk[key_idx];
  193. } else
  194. key = sdata->keys[key_idx];
  195. if (!key)
  196. goto out;
  197. memset(&params, 0, sizeof(params));
  198. params.cipher = key->conf.cipher;
  199. switch (key->conf.cipher) {
  200. case WLAN_CIPHER_SUITE_TKIP:
  201. iv32 = key->u.tkip.tx.iv32;
  202. iv16 = key->u.tkip.tx.iv16;
  203. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  204. drv_get_tkip_seq(sdata->local,
  205. key->conf.hw_key_idx,
  206. &iv32, &iv16);
  207. seq[0] = iv16 & 0xff;
  208. seq[1] = (iv16 >> 8) & 0xff;
  209. seq[2] = iv32 & 0xff;
  210. seq[3] = (iv32 >> 8) & 0xff;
  211. seq[4] = (iv32 >> 16) & 0xff;
  212. seq[5] = (iv32 >> 24) & 0xff;
  213. params.seq = seq;
  214. params.seq_len = 6;
  215. break;
  216. case WLAN_CIPHER_SUITE_CCMP:
  217. seq[0] = key->u.ccmp.tx_pn[5];
  218. seq[1] = key->u.ccmp.tx_pn[4];
  219. seq[2] = key->u.ccmp.tx_pn[3];
  220. seq[3] = key->u.ccmp.tx_pn[2];
  221. seq[4] = key->u.ccmp.tx_pn[1];
  222. seq[5] = key->u.ccmp.tx_pn[0];
  223. params.seq = seq;
  224. params.seq_len = 6;
  225. break;
  226. case WLAN_CIPHER_SUITE_AES_CMAC:
  227. seq[0] = key->u.aes_cmac.tx_pn[5];
  228. seq[1] = key->u.aes_cmac.tx_pn[4];
  229. seq[2] = key->u.aes_cmac.tx_pn[3];
  230. seq[3] = key->u.aes_cmac.tx_pn[2];
  231. seq[4] = key->u.aes_cmac.tx_pn[1];
  232. seq[5] = key->u.aes_cmac.tx_pn[0];
  233. params.seq = seq;
  234. params.seq_len = 6;
  235. break;
  236. }
  237. params.key = key->conf.key;
  238. params.key_len = key->conf.keylen;
  239. callback(cookie, &params);
  240. err = 0;
  241. out:
  242. rcu_read_unlock();
  243. return err;
  244. }
  245. static int ieee80211_config_default_key(struct wiphy *wiphy,
  246. struct net_device *dev,
  247. u8 key_idx, bool uni,
  248. bool multi)
  249. {
  250. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  251. ieee80211_set_default_key(sdata, key_idx, uni, multi);
  252. return 0;
  253. }
  254. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  255. struct net_device *dev,
  256. u8 key_idx)
  257. {
  258. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  259. ieee80211_set_default_mgmt_key(sdata, key_idx);
  260. return 0;
  261. }
  262. static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
  263. {
  264. if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
  265. struct ieee80211_supported_band *sband;
  266. sband = sta->local->hw.wiphy->bands[
  267. sta->local->hw.conf.channel->band];
  268. rate->legacy = sband->bitrates[idx].bitrate;
  269. } else
  270. rate->mcs = idx;
  271. }
  272. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  273. {
  274. struct ieee80211_sub_if_data *sdata = sta->sdata;
  275. struct timespec uptime;
  276. sinfo->generation = sdata->local->sta_generation;
  277. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  278. STATION_INFO_RX_BYTES |
  279. STATION_INFO_TX_BYTES |
  280. STATION_INFO_RX_PACKETS |
  281. STATION_INFO_TX_PACKETS |
  282. STATION_INFO_TX_RETRIES |
  283. STATION_INFO_TX_FAILED |
  284. STATION_INFO_TX_BITRATE |
  285. STATION_INFO_RX_BITRATE |
  286. STATION_INFO_RX_DROP_MISC |
  287. STATION_INFO_BSS_PARAM |
  288. STATION_INFO_CONNECTED_TIME;
  289. do_posix_clock_monotonic_gettime(&uptime);
  290. sinfo->connected_time = uptime.tv_sec - sta->last_connected;
  291. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  292. sinfo->rx_bytes = sta->rx_bytes;
  293. sinfo->tx_bytes = sta->tx_bytes;
  294. sinfo->rx_packets = sta->rx_packets;
  295. sinfo->tx_packets = sta->tx_packets;
  296. sinfo->tx_retries = sta->tx_retry_count;
  297. sinfo->tx_failed = sta->tx_retry_failed;
  298. sinfo->rx_dropped_misc = sta->rx_dropped;
  299. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  300. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  301. sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
  302. sinfo->signal = (s8)sta->last_signal;
  303. sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
  304. }
  305. sinfo->txrate.flags = 0;
  306. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  307. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  308. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  309. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  310. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  311. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  312. rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
  313. sinfo->rxrate.flags = 0;
  314. if (sta->last_rx_rate_flag & RX_FLAG_HT)
  315. sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
  316. if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
  317. sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  318. if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
  319. sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  320. rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
  321. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  322. #ifdef CONFIG_MAC80211_MESH
  323. sinfo->filled |= STATION_INFO_LLID |
  324. STATION_INFO_PLID |
  325. STATION_INFO_PLINK_STATE;
  326. sinfo->llid = le16_to_cpu(sta->llid);
  327. sinfo->plid = le16_to_cpu(sta->plid);
  328. sinfo->plink_state = sta->plink_state;
  329. #endif
  330. }
  331. sinfo->bss_param.flags = 0;
  332. if (sdata->vif.bss_conf.use_cts_prot)
  333. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
  334. if (sdata->vif.bss_conf.use_short_preamble)
  335. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
  336. if (sdata->vif.bss_conf.use_short_slot)
  337. sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
  338. sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
  339. sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
  340. }
  341. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  342. int idx, u8 *mac, struct station_info *sinfo)
  343. {
  344. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  345. struct sta_info *sta;
  346. int ret = -ENOENT;
  347. rcu_read_lock();
  348. sta = sta_info_get_by_idx(sdata, idx);
  349. if (sta) {
  350. ret = 0;
  351. memcpy(mac, sta->sta.addr, ETH_ALEN);
  352. sta_set_sinfo(sta, sinfo);
  353. }
  354. rcu_read_unlock();
  355. return ret;
  356. }
  357. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  358. int idx, struct survey_info *survey)
  359. {
  360. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  361. return drv_get_survey(local, idx, survey);
  362. }
  363. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  364. u8 *mac, struct station_info *sinfo)
  365. {
  366. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  367. struct sta_info *sta;
  368. int ret = -ENOENT;
  369. rcu_read_lock();
  370. sta = sta_info_get_bss(sdata, mac);
  371. if (sta) {
  372. ret = 0;
  373. sta_set_sinfo(sta, sinfo);
  374. }
  375. rcu_read_unlock();
  376. return ret;
  377. }
  378. /*
  379. * This handles both adding a beacon and setting new beacon info
  380. */
  381. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  382. struct beacon_parameters *params)
  383. {
  384. struct beacon_data *new, *old;
  385. int new_head_len, new_tail_len;
  386. int size;
  387. int err = -EINVAL;
  388. old = sdata->u.ap.beacon;
  389. /* head must not be zero-length */
  390. if (params->head && !params->head_len)
  391. return -EINVAL;
  392. /*
  393. * This is a kludge. beacon interval should really be part
  394. * of the beacon information.
  395. */
  396. if (params->interval &&
  397. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  398. sdata->vif.bss_conf.beacon_int = params->interval;
  399. ieee80211_bss_info_change_notify(sdata,
  400. BSS_CHANGED_BEACON_INT);
  401. }
  402. /* Need to have a beacon head if we don't have one yet */
  403. if (!params->head && !old)
  404. return err;
  405. /* sorry, no way to start beaconing without dtim period */
  406. if (!params->dtim_period && !old)
  407. return err;
  408. /* new or old head? */
  409. if (params->head)
  410. new_head_len = params->head_len;
  411. else
  412. new_head_len = old->head_len;
  413. /* new or old tail? */
  414. if (params->tail || !old)
  415. /* params->tail_len will be zero for !params->tail */
  416. new_tail_len = params->tail_len;
  417. else
  418. new_tail_len = old->tail_len;
  419. size = sizeof(*new) + new_head_len + new_tail_len;
  420. new = kzalloc(size, GFP_KERNEL);
  421. if (!new)
  422. return -ENOMEM;
  423. /* start filling the new info now */
  424. /* new or old dtim period? */
  425. if (params->dtim_period)
  426. new->dtim_period = params->dtim_period;
  427. else
  428. new->dtim_period = old->dtim_period;
  429. /*
  430. * pointers go into the block we allocated,
  431. * memory is | beacon_data | head | tail |
  432. */
  433. new->head = ((u8 *) new) + sizeof(*new);
  434. new->tail = new->head + new_head_len;
  435. new->head_len = new_head_len;
  436. new->tail_len = new_tail_len;
  437. /* copy in head */
  438. if (params->head)
  439. memcpy(new->head, params->head, new_head_len);
  440. else
  441. memcpy(new->head, old->head, new_head_len);
  442. /* copy in optional tail */
  443. if (params->tail)
  444. memcpy(new->tail, params->tail, new_tail_len);
  445. else
  446. if (old)
  447. memcpy(new->tail, old->tail, new_tail_len);
  448. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  449. rcu_assign_pointer(sdata->u.ap.beacon, new);
  450. synchronize_rcu();
  451. kfree(old);
  452. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  453. BSS_CHANGED_BEACON);
  454. return 0;
  455. }
  456. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  457. struct beacon_parameters *params)
  458. {
  459. struct ieee80211_sub_if_data *sdata;
  460. struct beacon_data *old;
  461. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  462. old = sdata->u.ap.beacon;
  463. if (old)
  464. return -EALREADY;
  465. return ieee80211_config_beacon(sdata, params);
  466. }
  467. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  468. struct beacon_parameters *params)
  469. {
  470. struct ieee80211_sub_if_data *sdata;
  471. struct beacon_data *old;
  472. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  473. old = sdata->u.ap.beacon;
  474. if (!old)
  475. return -ENOENT;
  476. return ieee80211_config_beacon(sdata, params);
  477. }
  478. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  479. {
  480. struct ieee80211_sub_if_data *sdata;
  481. struct beacon_data *old;
  482. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  483. old = sdata->u.ap.beacon;
  484. if (!old)
  485. return -ENOENT;
  486. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  487. synchronize_rcu();
  488. kfree(old);
  489. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  490. return 0;
  491. }
  492. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  493. struct iapp_layer2_update {
  494. u8 da[ETH_ALEN]; /* broadcast */
  495. u8 sa[ETH_ALEN]; /* STA addr */
  496. __be16 len; /* 6 */
  497. u8 dsap; /* 0 */
  498. u8 ssap; /* 0 */
  499. u8 control;
  500. u8 xid_info[3];
  501. } __packed;
  502. static void ieee80211_send_layer2_update(struct sta_info *sta)
  503. {
  504. struct iapp_layer2_update *msg;
  505. struct sk_buff *skb;
  506. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  507. * bridge devices */
  508. skb = dev_alloc_skb(sizeof(*msg));
  509. if (!skb)
  510. return;
  511. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  512. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  513. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  514. memset(msg->da, 0xff, ETH_ALEN);
  515. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  516. msg->len = htons(6);
  517. msg->dsap = 0;
  518. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  519. msg->control = 0xaf; /* XID response lsb.1111F101.
  520. * F=0 (no poll command; unsolicited frame) */
  521. msg->xid_info[0] = 0x81; /* XID format identifier */
  522. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  523. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  524. skb->dev = sta->sdata->dev;
  525. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  526. memset(skb->cb, 0, sizeof(skb->cb));
  527. netif_rx_ni(skb);
  528. }
  529. static void sta_apply_parameters(struct ieee80211_local *local,
  530. struct sta_info *sta,
  531. struct station_parameters *params)
  532. {
  533. unsigned long flags;
  534. u32 rates;
  535. int i, j;
  536. struct ieee80211_supported_band *sband;
  537. struct ieee80211_sub_if_data *sdata = sta->sdata;
  538. u32 mask, set;
  539. sband = local->hw.wiphy->bands[local->oper_channel->band];
  540. spin_lock_irqsave(&sta->flaglock, flags);
  541. mask = params->sta_flags_mask;
  542. set = params->sta_flags_set;
  543. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  544. sta->flags &= ~WLAN_STA_AUTHORIZED;
  545. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  546. sta->flags |= WLAN_STA_AUTHORIZED;
  547. }
  548. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  549. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  550. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  551. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  552. }
  553. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  554. sta->flags &= ~WLAN_STA_WME;
  555. if (set & BIT(NL80211_STA_FLAG_WME))
  556. sta->flags |= WLAN_STA_WME;
  557. }
  558. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  559. sta->flags &= ~WLAN_STA_MFP;
  560. if (set & BIT(NL80211_STA_FLAG_MFP))
  561. sta->flags |= WLAN_STA_MFP;
  562. }
  563. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  564. sta->flags &= ~WLAN_STA_AUTH;
  565. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  566. sta->flags |= WLAN_STA_AUTH;
  567. }
  568. spin_unlock_irqrestore(&sta->flaglock, flags);
  569. /*
  570. * cfg80211 validates this (1-2007) and allows setting the AID
  571. * only when creating a new station entry
  572. */
  573. if (params->aid)
  574. sta->sta.aid = params->aid;
  575. /*
  576. * FIXME: updating the following information is racy when this
  577. * function is called from ieee80211_change_station().
  578. * However, all this information should be static so
  579. * maybe we should just reject attemps to change it.
  580. */
  581. if (params->listen_interval >= 0)
  582. sta->listen_interval = params->listen_interval;
  583. if (params->supported_rates) {
  584. rates = 0;
  585. for (i = 0; i < params->supported_rates_len; i++) {
  586. int rate = (params->supported_rates[i] & 0x7f) * 5;
  587. for (j = 0; j < sband->n_bitrates; j++) {
  588. if (sband->bitrates[j].bitrate == rate)
  589. rates |= BIT(j);
  590. }
  591. }
  592. sta->sta.supp_rates[local->oper_channel->band] = rates;
  593. }
  594. if (params->ht_capa)
  595. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  596. params->ht_capa,
  597. &sta->sta.ht_cap);
  598. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  599. switch (params->plink_action) {
  600. case PLINK_ACTION_OPEN:
  601. mesh_plink_open(sta);
  602. break;
  603. case PLINK_ACTION_BLOCK:
  604. mesh_plink_block(sta);
  605. break;
  606. }
  607. }
  608. }
  609. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  610. u8 *mac, struct station_parameters *params)
  611. {
  612. struct ieee80211_local *local = wiphy_priv(wiphy);
  613. struct sta_info *sta;
  614. struct ieee80211_sub_if_data *sdata;
  615. int err;
  616. int layer2_update;
  617. if (params->vlan) {
  618. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  619. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  620. sdata->vif.type != NL80211_IFTYPE_AP)
  621. return -EINVAL;
  622. } else
  623. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  624. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  625. return -EINVAL;
  626. if (is_multicast_ether_addr(mac))
  627. return -EINVAL;
  628. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  629. if (!sta)
  630. return -ENOMEM;
  631. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  632. sta_apply_parameters(local, sta, params);
  633. rate_control_rate_init(sta);
  634. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  635. sdata->vif.type == NL80211_IFTYPE_AP;
  636. err = sta_info_insert_rcu(sta);
  637. if (err) {
  638. rcu_read_unlock();
  639. return err;
  640. }
  641. if (layer2_update)
  642. ieee80211_send_layer2_update(sta);
  643. rcu_read_unlock();
  644. return 0;
  645. }
  646. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  647. u8 *mac)
  648. {
  649. struct ieee80211_local *local = wiphy_priv(wiphy);
  650. struct ieee80211_sub_if_data *sdata;
  651. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  652. if (mac)
  653. return sta_info_destroy_addr_bss(sdata, mac);
  654. sta_info_flush(local, sdata);
  655. return 0;
  656. }
  657. static int ieee80211_change_station(struct wiphy *wiphy,
  658. struct net_device *dev,
  659. u8 *mac,
  660. struct station_parameters *params)
  661. {
  662. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  663. struct ieee80211_local *local = wiphy_priv(wiphy);
  664. struct sta_info *sta;
  665. struct ieee80211_sub_if_data *vlansdata;
  666. rcu_read_lock();
  667. sta = sta_info_get_bss(sdata, mac);
  668. if (!sta) {
  669. rcu_read_unlock();
  670. return -ENOENT;
  671. }
  672. if (params->vlan && params->vlan != sta->sdata->dev) {
  673. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  674. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  675. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  676. rcu_read_unlock();
  677. return -EINVAL;
  678. }
  679. if (params->vlan->ieee80211_ptr->use_4addr) {
  680. if (vlansdata->u.vlan.sta) {
  681. rcu_read_unlock();
  682. return -EBUSY;
  683. }
  684. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  685. }
  686. sta->sdata = vlansdata;
  687. ieee80211_send_layer2_update(sta);
  688. }
  689. sta_apply_parameters(local, sta, params);
  690. rcu_read_unlock();
  691. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  692. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  693. ieee80211_recalc_ps(local, -1);
  694. return 0;
  695. }
  696. #ifdef CONFIG_MAC80211_MESH
  697. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  698. u8 *dst, u8 *next_hop)
  699. {
  700. struct ieee80211_sub_if_data *sdata;
  701. struct mesh_path *mpath;
  702. struct sta_info *sta;
  703. int err;
  704. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  705. rcu_read_lock();
  706. sta = sta_info_get(sdata, next_hop);
  707. if (!sta) {
  708. rcu_read_unlock();
  709. return -ENOENT;
  710. }
  711. err = mesh_path_add(dst, sdata);
  712. if (err) {
  713. rcu_read_unlock();
  714. return err;
  715. }
  716. mpath = mesh_path_lookup(dst, sdata);
  717. if (!mpath) {
  718. rcu_read_unlock();
  719. return -ENXIO;
  720. }
  721. mesh_path_fix_nexthop(mpath, sta);
  722. rcu_read_unlock();
  723. return 0;
  724. }
  725. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  726. u8 *dst)
  727. {
  728. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  729. if (dst)
  730. return mesh_path_del(dst, sdata);
  731. mesh_path_flush(sdata);
  732. return 0;
  733. }
  734. static int ieee80211_change_mpath(struct wiphy *wiphy,
  735. struct net_device *dev,
  736. u8 *dst, u8 *next_hop)
  737. {
  738. struct ieee80211_sub_if_data *sdata;
  739. struct mesh_path *mpath;
  740. struct sta_info *sta;
  741. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  742. rcu_read_lock();
  743. sta = sta_info_get(sdata, next_hop);
  744. if (!sta) {
  745. rcu_read_unlock();
  746. return -ENOENT;
  747. }
  748. mpath = mesh_path_lookup(dst, sdata);
  749. if (!mpath) {
  750. rcu_read_unlock();
  751. return -ENOENT;
  752. }
  753. mesh_path_fix_nexthop(mpath, sta);
  754. rcu_read_unlock();
  755. return 0;
  756. }
  757. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  758. struct mpath_info *pinfo)
  759. {
  760. if (mpath->next_hop)
  761. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  762. else
  763. memset(next_hop, 0, ETH_ALEN);
  764. pinfo->generation = mesh_paths_generation;
  765. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  766. MPATH_INFO_SN |
  767. MPATH_INFO_METRIC |
  768. MPATH_INFO_EXPTIME |
  769. MPATH_INFO_DISCOVERY_TIMEOUT |
  770. MPATH_INFO_DISCOVERY_RETRIES |
  771. MPATH_INFO_FLAGS;
  772. pinfo->frame_qlen = mpath->frame_queue.qlen;
  773. pinfo->sn = mpath->sn;
  774. pinfo->metric = mpath->metric;
  775. if (time_before(jiffies, mpath->exp_time))
  776. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  777. pinfo->discovery_timeout =
  778. jiffies_to_msecs(mpath->discovery_timeout);
  779. pinfo->discovery_retries = mpath->discovery_retries;
  780. pinfo->flags = 0;
  781. if (mpath->flags & MESH_PATH_ACTIVE)
  782. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  783. if (mpath->flags & MESH_PATH_RESOLVING)
  784. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  785. if (mpath->flags & MESH_PATH_SN_VALID)
  786. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  787. if (mpath->flags & MESH_PATH_FIXED)
  788. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  789. if (mpath->flags & MESH_PATH_RESOLVING)
  790. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  791. pinfo->flags = mpath->flags;
  792. }
  793. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  794. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  795. {
  796. struct ieee80211_sub_if_data *sdata;
  797. struct mesh_path *mpath;
  798. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  799. rcu_read_lock();
  800. mpath = mesh_path_lookup(dst, sdata);
  801. if (!mpath) {
  802. rcu_read_unlock();
  803. return -ENOENT;
  804. }
  805. memcpy(dst, mpath->dst, ETH_ALEN);
  806. mpath_set_pinfo(mpath, next_hop, pinfo);
  807. rcu_read_unlock();
  808. return 0;
  809. }
  810. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  811. int idx, u8 *dst, u8 *next_hop,
  812. struct mpath_info *pinfo)
  813. {
  814. struct ieee80211_sub_if_data *sdata;
  815. struct mesh_path *mpath;
  816. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  817. rcu_read_lock();
  818. mpath = mesh_path_lookup_by_idx(idx, sdata);
  819. if (!mpath) {
  820. rcu_read_unlock();
  821. return -ENOENT;
  822. }
  823. memcpy(dst, mpath->dst, ETH_ALEN);
  824. mpath_set_pinfo(mpath, next_hop, pinfo);
  825. rcu_read_unlock();
  826. return 0;
  827. }
  828. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  829. struct net_device *dev,
  830. struct mesh_config *conf)
  831. {
  832. struct ieee80211_sub_if_data *sdata;
  833. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  834. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  835. return 0;
  836. }
  837. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  838. {
  839. return (mask >> (parm-1)) & 0x1;
  840. }
  841. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  842. const struct mesh_setup *setup)
  843. {
  844. u8 *new_ie;
  845. const u8 *old_ie;
  846. /* allocate information elements */
  847. new_ie = NULL;
  848. old_ie = ifmsh->ie;
  849. if (setup->ie_len) {
  850. new_ie = kmemdup(setup->ie, setup->ie_len,
  851. GFP_KERNEL);
  852. if (!new_ie)
  853. return -ENOMEM;
  854. }
  855. ifmsh->ie_len = setup->ie_len;
  856. ifmsh->ie = new_ie;
  857. kfree(old_ie);
  858. /* now copy the rest of the setup parameters */
  859. ifmsh->mesh_id_len = setup->mesh_id_len;
  860. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  861. ifmsh->mesh_pp_id = setup->path_sel_proto;
  862. ifmsh->mesh_pm_id = setup->path_metric;
  863. ifmsh->is_secure = setup->is_secure;
  864. return 0;
  865. }
  866. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  867. struct net_device *dev, u32 mask,
  868. const struct mesh_config *nconf)
  869. {
  870. struct mesh_config *conf;
  871. struct ieee80211_sub_if_data *sdata;
  872. struct ieee80211_if_mesh *ifmsh;
  873. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  874. ifmsh = &sdata->u.mesh;
  875. /* Set the config options which we are interested in setting */
  876. conf = &(sdata->u.mesh.mshcfg);
  877. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  878. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  879. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  880. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  881. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  882. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  883. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  884. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  885. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  886. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  887. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  888. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  889. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  890. conf->dot11MeshTTL = nconf->element_ttl;
  891. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  892. conf->auto_open_plinks = nconf->auto_open_plinks;
  893. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  894. conf->dot11MeshHWMPmaxPREQretries =
  895. nconf->dot11MeshHWMPmaxPREQretries;
  896. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  897. conf->path_refresh_time = nconf->path_refresh_time;
  898. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  899. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  900. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  901. conf->dot11MeshHWMPactivePathTimeout =
  902. nconf->dot11MeshHWMPactivePathTimeout;
  903. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  904. conf->dot11MeshHWMPpreqMinInterval =
  905. nconf->dot11MeshHWMPpreqMinInterval;
  906. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  907. mask))
  908. conf->dot11MeshHWMPnetDiameterTraversalTime =
  909. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  910. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  911. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  912. ieee80211_mesh_root_setup(ifmsh);
  913. }
  914. return 0;
  915. }
  916. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  917. const struct mesh_config *conf,
  918. const struct mesh_setup *setup)
  919. {
  920. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  921. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  922. int err;
  923. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  924. err = copy_mesh_setup(ifmsh, setup);
  925. if (err)
  926. return err;
  927. ieee80211_start_mesh(sdata);
  928. return 0;
  929. }
  930. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  931. {
  932. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  933. ieee80211_stop_mesh(sdata);
  934. return 0;
  935. }
  936. #endif
  937. static int ieee80211_change_bss(struct wiphy *wiphy,
  938. struct net_device *dev,
  939. struct bss_parameters *params)
  940. {
  941. struct ieee80211_sub_if_data *sdata;
  942. u32 changed = 0;
  943. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  944. if (params->use_cts_prot >= 0) {
  945. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  946. changed |= BSS_CHANGED_ERP_CTS_PROT;
  947. }
  948. if (params->use_short_preamble >= 0) {
  949. sdata->vif.bss_conf.use_short_preamble =
  950. params->use_short_preamble;
  951. changed |= BSS_CHANGED_ERP_PREAMBLE;
  952. }
  953. if (!sdata->vif.bss_conf.use_short_slot &&
  954. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  955. sdata->vif.bss_conf.use_short_slot = true;
  956. changed |= BSS_CHANGED_ERP_SLOT;
  957. }
  958. if (params->use_short_slot_time >= 0) {
  959. sdata->vif.bss_conf.use_short_slot =
  960. params->use_short_slot_time;
  961. changed |= BSS_CHANGED_ERP_SLOT;
  962. }
  963. if (params->basic_rates) {
  964. int i, j;
  965. u32 rates = 0;
  966. struct ieee80211_local *local = wiphy_priv(wiphy);
  967. struct ieee80211_supported_band *sband =
  968. wiphy->bands[local->oper_channel->band];
  969. for (i = 0; i < params->basic_rates_len; i++) {
  970. int rate = (params->basic_rates[i] & 0x7f) * 5;
  971. for (j = 0; j < sband->n_bitrates; j++) {
  972. if (sband->bitrates[j].bitrate == rate)
  973. rates |= BIT(j);
  974. }
  975. }
  976. sdata->vif.bss_conf.basic_rates = rates;
  977. changed |= BSS_CHANGED_BASIC_RATES;
  978. }
  979. if (params->ap_isolate >= 0) {
  980. if (params->ap_isolate)
  981. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  982. else
  983. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  984. }
  985. if (params->ht_opmode >= 0) {
  986. sdata->vif.bss_conf.ht_operation_mode =
  987. (u16) params->ht_opmode;
  988. changed |= BSS_CHANGED_HT;
  989. }
  990. ieee80211_bss_info_change_notify(sdata, changed);
  991. return 0;
  992. }
  993. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  994. struct ieee80211_txq_params *params)
  995. {
  996. struct ieee80211_local *local = wiphy_priv(wiphy);
  997. struct ieee80211_tx_queue_params p;
  998. if (!local->ops->conf_tx)
  999. return -EOPNOTSUPP;
  1000. memset(&p, 0, sizeof(p));
  1001. p.aifs = params->aifs;
  1002. p.cw_max = params->cwmax;
  1003. p.cw_min = params->cwmin;
  1004. p.txop = params->txop;
  1005. /*
  1006. * Setting tx queue params disables u-apsd because it's only
  1007. * called in master mode.
  1008. */
  1009. p.uapsd = false;
  1010. if (drv_conf_tx(local, params->queue, &p)) {
  1011. wiphy_debug(local->hw.wiphy,
  1012. "failed to set TX queue parameters for queue %d\n",
  1013. params->queue);
  1014. return -EINVAL;
  1015. }
  1016. return 0;
  1017. }
  1018. static int ieee80211_set_channel(struct wiphy *wiphy,
  1019. struct net_device *netdev,
  1020. struct ieee80211_channel *chan,
  1021. enum nl80211_channel_type channel_type)
  1022. {
  1023. struct ieee80211_local *local = wiphy_priv(wiphy);
  1024. struct ieee80211_sub_if_data *sdata = NULL;
  1025. struct ieee80211_channel *old_oper;
  1026. enum nl80211_channel_type old_oper_type;
  1027. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1028. if (netdev)
  1029. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1030. switch (ieee80211_get_channel_mode(local, NULL)) {
  1031. case CHAN_MODE_HOPPING:
  1032. return -EBUSY;
  1033. case CHAN_MODE_FIXED:
  1034. if (local->oper_channel != chan)
  1035. return -EBUSY;
  1036. if (!sdata && local->_oper_channel_type == channel_type)
  1037. return 0;
  1038. break;
  1039. case CHAN_MODE_UNDEFINED:
  1040. break;
  1041. }
  1042. if (sdata)
  1043. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1044. old_oper_type = local->_oper_channel_type;
  1045. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1046. return -EBUSY;
  1047. old_oper = local->oper_channel;
  1048. local->oper_channel = chan;
  1049. /* Update driver if changes were actually made. */
  1050. if ((old_oper != local->oper_channel) ||
  1051. (old_oper_type != local->_oper_channel_type))
  1052. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1053. if ((sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) &&
  1054. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1055. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1056. return 0;
  1057. }
  1058. #ifdef CONFIG_PM
  1059. static int ieee80211_suspend(struct wiphy *wiphy)
  1060. {
  1061. return __ieee80211_suspend(wiphy_priv(wiphy));
  1062. }
  1063. static int ieee80211_resume(struct wiphy *wiphy)
  1064. {
  1065. return __ieee80211_resume(wiphy_priv(wiphy));
  1066. }
  1067. #else
  1068. #define ieee80211_suspend NULL
  1069. #define ieee80211_resume NULL
  1070. #endif
  1071. static int ieee80211_scan(struct wiphy *wiphy,
  1072. struct net_device *dev,
  1073. struct cfg80211_scan_request *req)
  1074. {
  1075. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1076. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1077. case NL80211_IFTYPE_STATION:
  1078. case NL80211_IFTYPE_ADHOC:
  1079. case NL80211_IFTYPE_MESH_POINT:
  1080. case NL80211_IFTYPE_P2P_CLIENT:
  1081. break;
  1082. case NL80211_IFTYPE_P2P_GO:
  1083. if (sdata->local->ops->hw_scan)
  1084. break;
  1085. /*
  1086. * FIXME: implement NoA while scanning in software,
  1087. * for now fall through to allow scanning only when
  1088. * beaconing hasn't been configured yet
  1089. */
  1090. case NL80211_IFTYPE_AP:
  1091. if (sdata->u.ap.beacon)
  1092. return -EOPNOTSUPP;
  1093. break;
  1094. default:
  1095. return -EOPNOTSUPP;
  1096. }
  1097. return ieee80211_request_scan(sdata, req);
  1098. }
  1099. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1100. struct cfg80211_auth_request *req)
  1101. {
  1102. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1103. }
  1104. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1105. struct cfg80211_assoc_request *req)
  1106. {
  1107. struct ieee80211_local *local = wiphy_priv(wiphy);
  1108. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1109. switch (ieee80211_get_channel_mode(local, sdata)) {
  1110. case CHAN_MODE_HOPPING:
  1111. return -EBUSY;
  1112. case CHAN_MODE_FIXED:
  1113. if (local->oper_channel == req->bss->channel)
  1114. break;
  1115. return -EBUSY;
  1116. case CHAN_MODE_UNDEFINED:
  1117. break;
  1118. }
  1119. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1120. }
  1121. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1122. struct cfg80211_deauth_request *req,
  1123. void *cookie)
  1124. {
  1125. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1126. req, cookie);
  1127. }
  1128. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1129. struct cfg80211_disassoc_request *req,
  1130. void *cookie)
  1131. {
  1132. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1133. req, cookie);
  1134. }
  1135. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1136. struct cfg80211_ibss_params *params)
  1137. {
  1138. struct ieee80211_local *local = wiphy_priv(wiphy);
  1139. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1140. switch (ieee80211_get_channel_mode(local, sdata)) {
  1141. case CHAN_MODE_HOPPING:
  1142. return -EBUSY;
  1143. case CHAN_MODE_FIXED:
  1144. if (!params->channel_fixed)
  1145. return -EBUSY;
  1146. if (local->oper_channel == params->channel)
  1147. break;
  1148. return -EBUSY;
  1149. case CHAN_MODE_UNDEFINED:
  1150. break;
  1151. }
  1152. return ieee80211_ibss_join(sdata, params);
  1153. }
  1154. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1155. {
  1156. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1157. return ieee80211_ibss_leave(sdata);
  1158. }
  1159. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1160. {
  1161. struct ieee80211_local *local = wiphy_priv(wiphy);
  1162. int err;
  1163. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1164. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1165. if (err)
  1166. return err;
  1167. }
  1168. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1169. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1170. if (err)
  1171. return err;
  1172. }
  1173. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1174. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1175. if (err)
  1176. return err;
  1177. }
  1178. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1179. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1180. if (changed & WIPHY_PARAM_RETRY_LONG)
  1181. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1182. if (changed &
  1183. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1184. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1185. return 0;
  1186. }
  1187. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1188. enum nl80211_tx_power_setting type, int mbm)
  1189. {
  1190. struct ieee80211_local *local = wiphy_priv(wiphy);
  1191. struct ieee80211_channel *chan = local->hw.conf.channel;
  1192. u32 changes = 0;
  1193. switch (type) {
  1194. case NL80211_TX_POWER_AUTOMATIC:
  1195. local->user_power_level = -1;
  1196. break;
  1197. case NL80211_TX_POWER_LIMITED:
  1198. if (mbm < 0 || (mbm % 100))
  1199. return -EOPNOTSUPP;
  1200. local->user_power_level = MBM_TO_DBM(mbm);
  1201. break;
  1202. case NL80211_TX_POWER_FIXED:
  1203. if (mbm < 0 || (mbm % 100))
  1204. return -EOPNOTSUPP;
  1205. /* TODO: move to cfg80211 when it knows the channel */
  1206. if (MBM_TO_DBM(mbm) > chan->max_power)
  1207. return -EINVAL;
  1208. local->user_power_level = MBM_TO_DBM(mbm);
  1209. break;
  1210. }
  1211. ieee80211_hw_config(local, changes);
  1212. return 0;
  1213. }
  1214. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1215. {
  1216. struct ieee80211_local *local = wiphy_priv(wiphy);
  1217. *dbm = local->hw.conf.power_level;
  1218. return 0;
  1219. }
  1220. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1221. const u8 *addr)
  1222. {
  1223. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1224. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1225. return 0;
  1226. }
  1227. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1228. {
  1229. struct ieee80211_local *local = wiphy_priv(wiphy);
  1230. drv_rfkill_poll(local);
  1231. }
  1232. #ifdef CONFIG_NL80211_TESTMODE
  1233. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1234. {
  1235. struct ieee80211_local *local = wiphy_priv(wiphy);
  1236. if (!local->ops->testmode_cmd)
  1237. return -EOPNOTSUPP;
  1238. return local->ops->testmode_cmd(&local->hw, data, len);
  1239. }
  1240. #endif
  1241. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1242. enum ieee80211_smps_mode smps_mode)
  1243. {
  1244. const u8 *ap;
  1245. enum ieee80211_smps_mode old_req;
  1246. int err;
  1247. lockdep_assert_held(&sdata->u.mgd.mtx);
  1248. old_req = sdata->u.mgd.req_smps;
  1249. sdata->u.mgd.req_smps = smps_mode;
  1250. if (old_req == smps_mode &&
  1251. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1252. return 0;
  1253. /*
  1254. * If not associated, or current association is not an HT
  1255. * association, there's no need to send an action frame.
  1256. */
  1257. if (!sdata->u.mgd.associated ||
  1258. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1259. mutex_lock(&sdata->local->iflist_mtx);
  1260. ieee80211_recalc_smps(sdata->local);
  1261. mutex_unlock(&sdata->local->iflist_mtx);
  1262. return 0;
  1263. }
  1264. ap = sdata->u.mgd.associated->bssid;
  1265. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1266. if (sdata->u.mgd.powersave)
  1267. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1268. else
  1269. smps_mode = IEEE80211_SMPS_OFF;
  1270. }
  1271. /* send SM PS frame to AP */
  1272. err = ieee80211_send_smps_action(sdata, smps_mode,
  1273. ap, ap);
  1274. if (err)
  1275. sdata->u.mgd.req_smps = old_req;
  1276. return err;
  1277. }
  1278. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1279. bool enabled, int timeout)
  1280. {
  1281. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1282. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1283. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1284. return -EOPNOTSUPP;
  1285. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1286. return -EOPNOTSUPP;
  1287. if (enabled == sdata->u.mgd.powersave &&
  1288. timeout == local->dynamic_ps_forced_timeout)
  1289. return 0;
  1290. sdata->u.mgd.powersave = enabled;
  1291. local->dynamic_ps_forced_timeout = timeout;
  1292. /* no change, but if automatic follow powersave */
  1293. mutex_lock(&sdata->u.mgd.mtx);
  1294. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1295. mutex_unlock(&sdata->u.mgd.mtx);
  1296. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1297. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1298. ieee80211_recalc_ps(local, -1);
  1299. return 0;
  1300. }
  1301. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1302. struct net_device *dev,
  1303. s32 rssi_thold, u32 rssi_hyst)
  1304. {
  1305. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1306. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1307. struct ieee80211_vif *vif = &sdata->vif;
  1308. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1309. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1310. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1311. return 0;
  1312. bss_conf->cqm_rssi_thold = rssi_thold;
  1313. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1314. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1315. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1316. return -EOPNOTSUPP;
  1317. return 0;
  1318. }
  1319. /* tell the driver upon association, unless already associated */
  1320. if (sdata->u.mgd.associated)
  1321. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1322. return 0;
  1323. }
  1324. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1325. struct net_device *dev,
  1326. const u8 *addr,
  1327. const struct cfg80211_bitrate_mask *mask)
  1328. {
  1329. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1330. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1331. int i, ret;
  1332. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1333. ret = drv_set_bitrate_mask(local, sdata, mask);
  1334. if (ret)
  1335. return ret;
  1336. }
  1337. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1338. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1339. return 0;
  1340. }
  1341. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1342. struct net_device *dev,
  1343. struct ieee80211_channel *chan,
  1344. enum nl80211_channel_type chantype,
  1345. unsigned int duration, u64 *cookie)
  1346. {
  1347. int ret;
  1348. u32 random_cookie;
  1349. lockdep_assert_held(&local->mtx);
  1350. if (local->hw_roc_cookie)
  1351. return -EBUSY;
  1352. /* must be nonzero */
  1353. random_cookie = random32() | 1;
  1354. *cookie = random_cookie;
  1355. local->hw_roc_dev = dev;
  1356. local->hw_roc_cookie = random_cookie;
  1357. local->hw_roc_channel = chan;
  1358. local->hw_roc_channel_type = chantype;
  1359. local->hw_roc_duration = duration;
  1360. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1361. if (ret) {
  1362. local->hw_roc_channel = NULL;
  1363. local->hw_roc_cookie = 0;
  1364. }
  1365. return ret;
  1366. }
  1367. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1368. struct net_device *dev,
  1369. struct ieee80211_channel *chan,
  1370. enum nl80211_channel_type channel_type,
  1371. unsigned int duration,
  1372. u64 *cookie)
  1373. {
  1374. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1375. struct ieee80211_local *local = sdata->local;
  1376. if (local->ops->remain_on_channel) {
  1377. int ret;
  1378. mutex_lock(&local->mtx);
  1379. ret = ieee80211_remain_on_channel_hw(local, dev,
  1380. chan, channel_type,
  1381. duration, cookie);
  1382. local->hw_roc_for_tx = false;
  1383. mutex_unlock(&local->mtx);
  1384. return ret;
  1385. }
  1386. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1387. duration, cookie);
  1388. }
  1389. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1390. u64 cookie)
  1391. {
  1392. int ret;
  1393. lockdep_assert_held(&local->mtx);
  1394. if (local->hw_roc_cookie != cookie)
  1395. return -ENOENT;
  1396. ret = drv_cancel_remain_on_channel(local);
  1397. if (ret)
  1398. return ret;
  1399. local->hw_roc_cookie = 0;
  1400. local->hw_roc_channel = NULL;
  1401. ieee80211_recalc_idle(local);
  1402. return 0;
  1403. }
  1404. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1405. struct net_device *dev,
  1406. u64 cookie)
  1407. {
  1408. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1409. struct ieee80211_local *local = sdata->local;
  1410. if (local->ops->cancel_remain_on_channel) {
  1411. int ret;
  1412. mutex_lock(&local->mtx);
  1413. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1414. mutex_unlock(&local->mtx);
  1415. return ret;
  1416. }
  1417. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1418. }
  1419. static enum work_done_result
  1420. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1421. {
  1422. /*
  1423. * Use the data embedded in the work struct for reporting
  1424. * here so if the driver mangled the SKB before dropping
  1425. * it (which is the only way we really should get here)
  1426. * then we don't report mangled data.
  1427. *
  1428. * If there was no wait time, then by the time we get here
  1429. * the driver will likely not have reported the status yet,
  1430. * so in that case userspace will have to deal with it.
  1431. */
  1432. if (wk->offchan_tx.wait && wk->offchan_tx.frame)
  1433. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1434. (unsigned long) wk->offchan_tx.frame,
  1435. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1436. return WORK_DONE_DESTROY;
  1437. }
  1438. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1439. struct ieee80211_channel *chan, bool offchan,
  1440. enum nl80211_channel_type channel_type,
  1441. bool channel_type_valid, unsigned int wait,
  1442. const u8 *buf, size_t len, u64 *cookie)
  1443. {
  1444. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1445. struct ieee80211_local *local = sdata->local;
  1446. struct sk_buff *skb;
  1447. struct sta_info *sta;
  1448. struct ieee80211_work *wk;
  1449. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1450. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1451. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1452. bool is_offchan = false;
  1453. /* Check that we are on the requested channel for transmission */
  1454. if (chan != local->tmp_channel &&
  1455. chan != local->oper_channel)
  1456. is_offchan = true;
  1457. if (channel_type_valid &&
  1458. (channel_type != local->tmp_channel_type &&
  1459. channel_type != local->_oper_channel_type))
  1460. is_offchan = true;
  1461. if (chan == local->hw_roc_channel) {
  1462. /* TODO: check channel type? */
  1463. is_offchan = false;
  1464. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1465. }
  1466. if (is_offchan && !offchan)
  1467. return -EBUSY;
  1468. switch (sdata->vif.type) {
  1469. case NL80211_IFTYPE_ADHOC:
  1470. case NL80211_IFTYPE_AP:
  1471. case NL80211_IFTYPE_AP_VLAN:
  1472. case NL80211_IFTYPE_P2P_GO:
  1473. case NL80211_IFTYPE_MESH_POINT:
  1474. if (!ieee80211_is_action(mgmt->frame_control) ||
  1475. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1476. break;
  1477. rcu_read_lock();
  1478. sta = sta_info_get(sdata, mgmt->da);
  1479. rcu_read_unlock();
  1480. if (!sta)
  1481. return -ENOLINK;
  1482. break;
  1483. case NL80211_IFTYPE_STATION:
  1484. case NL80211_IFTYPE_P2P_CLIENT:
  1485. break;
  1486. default:
  1487. return -EOPNOTSUPP;
  1488. }
  1489. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1490. if (!skb)
  1491. return -ENOMEM;
  1492. skb_reserve(skb, local->hw.extra_tx_headroom);
  1493. memcpy(skb_put(skb, len), buf, len);
  1494. IEEE80211_SKB_CB(skb)->flags = flags;
  1495. skb->dev = sdata->dev;
  1496. *cookie = (unsigned long) skb;
  1497. if (is_offchan && local->ops->offchannel_tx) {
  1498. int ret;
  1499. IEEE80211_SKB_CB(skb)->band = chan->band;
  1500. mutex_lock(&local->mtx);
  1501. if (local->hw_offchan_tx_cookie) {
  1502. mutex_unlock(&local->mtx);
  1503. return -EBUSY;
  1504. }
  1505. /* TODO: bitrate control, TX processing? */
  1506. ret = drv_offchannel_tx(local, skb, chan, channel_type, wait);
  1507. if (ret == 0)
  1508. local->hw_offchan_tx_cookie = *cookie;
  1509. mutex_unlock(&local->mtx);
  1510. /*
  1511. * Allow driver to return 1 to indicate it wants to have the
  1512. * frame transmitted with a remain_on_channel + regular TX.
  1513. */
  1514. if (ret != 1)
  1515. return ret;
  1516. }
  1517. if (is_offchan && local->ops->remain_on_channel) {
  1518. unsigned int duration;
  1519. int ret;
  1520. mutex_lock(&local->mtx);
  1521. /*
  1522. * If the duration is zero, then the driver
  1523. * wouldn't actually do anything. Set it to
  1524. * 100 for now.
  1525. *
  1526. * TODO: cancel the off-channel operation
  1527. * when we get the SKB's TX status and
  1528. * the wait time was zero before.
  1529. */
  1530. duration = 100;
  1531. if (wait)
  1532. duration = wait;
  1533. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1534. channel_type,
  1535. duration, cookie);
  1536. if (ret) {
  1537. kfree_skb(skb);
  1538. mutex_unlock(&local->mtx);
  1539. return ret;
  1540. }
  1541. local->hw_roc_for_tx = true;
  1542. local->hw_roc_duration = wait;
  1543. /*
  1544. * queue up frame for transmission after
  1545. * ieee80211_ready_on_channel call
  1546. */
  1547. /* modify cookie to prevent API mismatches */
  1548. *cookie ^= 2;
  1549. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1550. local->hw_roc_skb = skb;
  1551. local->hw_roc_skb_for_status = skb;
  1552. mutex_unlock(&local->mtx);
  1553. return 0;
  1554. }
  1555. /*
  1556. * Can transmit right away if the channel was the
  1557. * right one and there's no wait involved... If a
  1558. * wait is involved, we might otherwise not be on
  1559. * the right channel for long enough!
  1560. */
  1561. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1562. ieee80211_tx_skb(sdata, skb);
  1563. return 0;
  1564. }
  1565. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1566. if (!wk) {
  1567. kfree_skb(skb);
  1568. return -ENOMEM;
  1569. }
  1570. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1571. wk->chan = chan;
  1572. wk->chan_type = channel_type;
  1573. wk->sdata = sdata;
  1574. wk->done = ieee80211_offchan_tx_done;
  1575. wk->offchan_tx.frame = skb;
  1576. wk->offchan_tx.wait = wait;
  1577. wk->ie_len = len;
  1578. memcpy(wk->ie, buf, len);
  1579. ieee80211_add_work(wk);
  1580. return 0;
  1581. }
  1582. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1583. struct net_device *dev,
  1584. u64 cookie)
  1585. {
  1586. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1587. struct ieee80211_local *local = sdata->local;
  1588. struct ieee80211_work *wk;
  1589. int ret = -ENOENT;
  1590. mutex_lock(&local->mtx);
  1591. if (local->ops->offchannel_tx_cancel_wait &&
  1592. local->hw_offchan_tx_cookie == cookie) {
  1593. ret = drv_offchannel_tx_cancel_wait(local);
  1594. if (!ret)
  1595. local->hw_offchan_tx_cookie = 0;
  1596. mutex_unlock(&local->mtx);
  1597. return ret;
  1598. }
  1599. if (local->ops->cancel_remain_on_channel) {
  1600. cookie ^= 2;
  1601. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1602. if (ret == 0) {
  1603. kfree_skb(local->hw_roc_skb);
  1604. local->hw_roc_skb = NULL;
  1605. local->hw_roc_skb_for_status = NULL;
  1606. }
  1607. mutex_unlock(&local->mtx);
  1608. return ret;
  1609. }
  1610. list_for_each_entry(wk, &local->work_list, list) {
  1611. if (wk->sdata != sdata)
  1612. continue;
  1613. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1614. continue;
  1615. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1616. continue;
  1617. wk->timeout = jiffies;
  1618. ieee80211_queue_work(&local->hw, &local->work_work);
  1619. ret = 0;
  1620. break;
  1621. }
  1622. mutex_unlock(&local->mtx);
  1623. return ret;
  1624. }
  1625. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1626. struct net_device *dev,
  1627. u16 frame_type, bool reg)
  1628. {
  1629. struct ieee80211_local *local = wiphy_priv(wiphy);
  1630. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1631. return;
  1632. if (reg)
  1633. local->probe_req_reg++;
  1634. else
  1635. local->probe_req_reg--;
  1636. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1637. }
  1638. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1639. {
  1640. struct ieee80211_local *local = wiphy_priv(wiphy);
  1641. if (local->started)
  1642. return -EOPNOTSUPP;
  1643. return drv_set_antenna(local, tx_ant, rx_ant);
  1644. }
  1645. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1646. {
  1647. struct ieee80211_local *local = wiphy_priv(wiphy);
  1648. return drv_get_antenna(local, tx_ant, rx_ant);
  1649. }
  1650. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1651. {
  1652. struct ieee80211_local *local = wiphy_priv(wiphy);
  1653. return drv_set_ringparam(local, tx, rx);
  1654. }
  1655. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1656. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1657. {
  1658. struct ieee80211_local *local = wiphy_priv(wiphy);
  1659. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1660. }
  1661. struct cfg80211_ops mac80211_config_ops = {
  1662. .add_virtual_intf = ieee80211_add_iface,
  1663. .del_virtual_intf = ieee80211_del_iface,
  1664. .change_virtual_intf = ieee80211_change_iface,
  1665. .add_key = ieee80211_add_key,
  1666. .del_key = ieee80211_del_key,
  1667. .get_key = ieee80211_get_key,
  1668. .set_default_key = ieee80211_config_default_key,
  1669. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1670. .add_beacon = ieee80211_add_beacon,
  1671. .set_beacon = ieee80211_set_beacon,
  1672. .del_beacon = ieee80211_del_beacon,
  1673. .add_station = ieee80211_add_station,
  1674. .del_station = ieee80211_del_station,
  1675. .change_station = ieee80211_change_station,
  1676. .get_station = ieee80211_get_station,
  1677. .dump_station = ieee80211_dump_station,
  1678. .dump_survey = ieee80211_dump_survey,
  1679. #ifdef CONFIG_MAC80211_MESH
  1680. .add_mpath = ieee80211_add_mpath,
  1681. .del_mpath = ieee80211_del_mpath,
  1682. .change_mpath = ieee80211_change_mpath,
  1683. .get_mpath = ieee80211_get_mpath,
  1684. .dump_mpath = ieee80211_dump_mpath,
  1685. .update_mesh_config = ieee80211_update_mesh_config,
  1686. .get_mesh_config = ieee80211_get_mesh_config,
  1687. .join_mesh = ieee80211_join_mesh,
  1688. .leave_mesh = ieee80211_leave_mesh,
  1689. #endif
  1690. .change_bss = ieee80211_change_bss,
  1691. .set_txq_params = ieee80211_set_txq_params,
  1692. .set_channel = ieee80211_set_channel,
  1693. .suspend = ieee80211_suspend,
  1694. .resume = ieee80211_resume,
  1695. .scan = ieee80211_scan,
  1696. .auth = ieee80211_auth,
  1697. .assoc = ieee80211_assoc,
  1698. .deauth = ieee80211_deauth,
  1699. .disassoc = ieee80211_disassoc,
  1700. .join_ibss = ieee80211_join_ibss,
  1701. .leave_ibss = ieee80211_leave_ibss,
  1702. .set_wiphy_params = ieee80211_set_wiphy_params,
  1703. .set_tx_power = ieee80211_set_tx_power,
  1704. .get_tx_power = ieee80211_get_tx_power,
  1705. .set_wds_peer = ieee80211_set_wds_peer,
  1706. .rfkill_poll = ieee80211_rfkill_poll,
  1707. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1708. .set_power_mgmt = ieee80211_set_power_mgmt,
  1709. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1710. .remain_on_channel = ieee80211_remain_on_channel,
  1711. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1712. .mgmt_tx = ieee80211_mgmt_tx,
  1713. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  1714. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1715. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  1716. .set_antenna = ieee80211_set_antenna,
  1717. .get_antenna = ieee80211_get_antenna,
  1718. .set_ringparam = ieee80211_set_ringparam,
  1719. .get_ringparam = ieee80211_get_ringparam,
  1720. };