cfg.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185
  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. if (ieee80211_vif_is_mesh(&sdata->vif))
  118. sta = sta_info_get(sdata, mac_addr);
  119. else
  120. sta = sta_info_get_bss(sdata, mac_addr);
  121. if (!sta) {
  122. ieee80211_key_free(sdata->local, key);
  123. err = -ENOENT;
  124. goto out_unlock;
  125. }
  126. }
  127. err = ieee80211_key_link(key, sdata, sta);
  128. if (err)
  129. ieee80211_key_free(sdata->local, key);
  130. out_unlock:
  131. mutex_unlock(&sdata->local->sta_mtx);
  132. return err;
  133. }
  134. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  135. u8 key_idx, bool pairwise, const u8 *mac_addr)
  136. {
  137. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  138. struct ieee80211_local *local = sdata->local;
  139. struct sta_info *sta;
  140. struct ieee80211_key *key = NULL;
  141. int ret;
  142. mutex_lock(&local->sta_mtx);
  143. mutex_lock(&local->key_mtx);
  144. if (mac_addr) {
  145. ret = -ENOENT;
  146. sta = sta_info_get_bss(sdata, mac_addr);
  147. if (!sta)
  148. goto out_unlock;
  149. if (pairwise)
  150. key = key_mtx_dereference(local, sta->ptk);
  151. else
  152. key = key_mtx_dereference(local, sta->gtk[key_idx]);
  153. } else
  154. key = key_mtx_dereference(local, sdata->keys[key_idx]);
  155. if (!key) {
  156. ret = -ENOENT;
  157. goto out_unlock;
  158. }
  159. __ieee80211_key_free(key);
  160. ret = 0;
  161. out_unlock:
  162. mutex_unlock(&local->key_mtx);
  163. mutex_unlock(&local->sta_mtx);
  164. return ret;
  165. }
  166. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  167. u8 key_idx, bool pairwise, const u8 *mac_addr,
  168. void *cookie,
  169. void (*callback)(void *cookie,
  170. struct key_params *params))
  171. {
  172. struct ieee80211_sub_if_data *sdata;
  173. struct sta_info *sta = NULL;
  174. u8 seq[6] = {0};
  175. struct key_params params;
  176. struct ieee80211_key *key = NULL;
  177. u64 pn64;
  178. u32 iv32;
  179. u16 iv16;
  180. int err = -ENOENT;
  181. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  182. rcu_read_lock();
  183. if (mac_addr) {
  184. sta = sta_info_get_bss(sdata, mac_addr);
  185. if (!sta)
  186. goto out;
  187. if (pairwise)
  188. key = rcu_dereference(sta->ptk);
  189. else if (key_idx < NUM_DEFAULT_KEYS)
  190. key = rcu_dereference(sta->gtk[key_idx]);
  191. } else
  192. key = rcu_dereference(sdata->keys[key_idx]);
  193. if (!key)
  194. goto out;
  195. memset(&params, 0, sizeof(params));
  196. params.cipher = key->conf.cipher;
  197. switch (key->conf.cipher) {
  198. case WLAN_CIPHER_SUITE_TKIP:
  199. iv32 = key->u.tkip.tx.iv32;
  200. iv16 = key->u.tkip.tx.iv16;
  201. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  202. drv_get_tkip_seq(sdata->local,
  203. key->conf.hw_key_idx,
  204. &iv32, &iv16);
  205. seq[0] = iv16 & 0xff;
  206. seq[1] = (iv16 >> 8) & 0xff;
  207. seq[2] = iv32 & 0xff;
  208. seq[3] = (iv32 >> 8) & 0xff;
  209. seq[4] = (iv32 >> 16) & 0xff;
  210. seq[5] = (iv32 >> 24) & 0xff;
  211. params.seq = seq;
  212. params.seq_len = 6;
  213. break;
  214. case WLAN_CIPHER_SUITE_CCMP:
  215. pn64 = atomic64_read(&key->u.ccmp.tx_pn);
  216. seq[0] = pn64;
  217. seq[1] = pn64 >> 8;
  218. seq[2] = pn64 >> 16;
  219. seq[3] = pn64 >> 24;
  220. seq[4] = pn64 >> 32;
  221. seq[5] = pn64 >> 40;
  222. params.seq = seq;
  223. params.seq_len = 6;
  224. break;
  225. case WLAN_CIPHER_SUITE_AES_CMAC:
  226. pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
  227. seq[0] = pn64;
  228. seq[1] = pn64 >> 8;
  229. seq[2] = pn64 >> 16;
  230. seq[3] = pn64 >> 24;
  231. seq[4] = pn64 >> 32;
  232. seq[5] = pn64 >> 40;
  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 = rtnl_dereference(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 = rtnl_dereference(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 = rtnl_dereference(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 = rtnl_dereference(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. sta->sta.wme = false;
  556. if (set & BIT(NL80211_STA_FLAG_WME)) {
  557. sta->flags |= WLAN_STA_WME;
  558. sta->sta.wme = true;
  559. }
  560. }
  561. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  562. sta->flags &= ~WLAN_STA_MFP;
  563. if (set & BIT(NL80211_STA_FLAG_MFP))
  564. sta->flags |= WLAN_STA_MFP;
  565. }
  566. if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
  567. sta->flags &= ~WLAN_STA_AUTH;
  568. if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
  569. sta->flags |= WLAN_STA_AUTH;
  570. }
  571. spin_unlock_irqrestore(&sta->flaglock, flags);
  572. /*
  573. * cfg80211 validates this (1-2007) and allows setting the AID
  574. * only when creating a new station entry
  575. */
  576. if (params->aid)
  577. sta->sta.aid = params->aid;
  578. /*
  579. * FIXME: updating the following information is racy when this
  580. * function is called from ieee80211_change_station().
  581. * However, all this information should be static so
  582. * maybe we should just reject attemps to change it.
  583. */
  584. if (params->listen_interval >= 0)
  585. sta->listen_interval = params->listen_interval;
  586. if (params->supported_rates) {
  587. rates = 0;
  588. for (i = 0; i < params->supported_rates_len; i++) {
  589. int rate = (params->supported_rates[i] & 0x7f) * 5;
  590. for (j = 0; j < sband->n_bitrates; j++) {
  591. if (sband->bitrates[j].bitrate == rate)
  592. rates |= BIT(j);
  593. }
  594. }
  595. sta->sta.supp_rates[local->oper_channel->band] = rates;
  596. }
  597. if (params->ht_capa)
  598. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  599. params->ht_capa,
  600. &sta->sta.ht_cap);
  601. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  602. #ifdef CONFIG_MAC80211_MESH
  603. if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
  604. switch (params->plink_state) {
  605. case NL80211_PLINK_LISTEN:
  606. case NL80211_PLINK_ESTAB:
  607. case NL80211_PLINK_BLOCKED:
  608. sta->plink_state = params->plink_state;
  609. break;
  610. default:
  611. /* nothing */
  612. break;
  613. }
  614. else
  615. switch (params->plink_action) {
  616. case PLINK_ACTION_OPEN:
  617. mesh_plink_open(sta);
  618. break;
  619. case PLINK_ACTION_BLOCK:
  620. mesh_plink_block(sta);
  621. break;
  622. }
  623. #endif
  624. }
  625. }
  626. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  627. u8 *mac, struct station_parameters *params)
  628. {
  629. struct ieee80211_local *local = wiphy_priv(wiphy);
  630. struct sta_info *sta;
  631. struct ieee80211_sub_if_data *sdata;
  632. int err;
  633. int layer2_update;
  634. if (params->vlan) {
  635. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  636. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  637. sdata->vif.type != NL80211_IFTYPE_AP)
  638. return -EINVAL;
  639. } else
  640. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  641. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  642. return -EINVAL;
  643. if (is_multicast_ether_addr(mac))
  644. return -EINVAL;
  645. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  646. if (!sta)
  647. return -ENOMEM;
  648. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  649. sta_apply_parameters(local, sta, params);
  650. rate_control_rate_init(sta);
  651. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  652. sdata->vif.type == NL80211_IFTYPE_AP;
  653. err = sta_info_insert_rcu(sta);
  654. if (err) {
  655. rcu_read_unlock();
  656. return err;
  657. }
  658. if (layer2_update)
  659. ieee80211_send_layer2_update(sta);
  660. rcu_read_unlock();
  661. return 0;
  662. }
  663. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  664. u8 *mac)
  665. {
  666. struct ieee80211_local *local = wiphy_priv(wiphy);
  667. struct ieee80211_sub_if_data *sdata;
  668. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  669. if (mac)
  670. return sta_info_destroy_addr_bss(sdata, mac);
  671. sta_info_flush(local, sdata);
  672. return 0;
  673. }
  674. static int ieee80211_change_station(struct wiphy *wiphy,
  675. struct net_device *dev,
  676. u8 *mac,
  677. struct station_parameters *params)
  678. {
  679. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  680. struct ieee80211_local *local = wiphy_priv(wiphy);
  681. struct sta_info *sta;
  682. struct ieee80211_sub_if_data *vlansdata;
  683. rcu_read_lock();
  684. sta = sta_info_get_bss(sdata, mac);
  685. if (!sta) {
  686. rcu_read_unlock();
  687. return -ENOENT;
  688. }
  689. if (params->vlan && params->vlan != sta->sdata->dev) {
  690. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  691. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  692. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  693. rcu_read_unlock();
  694. return -EINVAL;
  695. }
  696. if (params->vlan->ieee80211_ptr->use_4addr) {
  697. if (vlansdata->u.vlan.sta) {
  698. rcu_read_unlock();
  699. return -EBUSY;
  700. }
  701. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  702. }
  703. sta->sdata = vlansdata;
  704. ieee80211_send_layer2_update(sta);
  705. }
  706. sta_apply_parameters(local, sta, params);
  707. rcu_read_unlock();
  708. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  709. params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
  710. ieee80211_recalc_ps(local, -1);
  711. return 0;
  712. }
  713. #ifdef CONFIG_MAC80211_MESH
  714. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  715. u8 *dst, u8 *next_hop)
  716. {
  717. struct ieee80211_sub_if_data *sdata;
  718. struct mesh_path *mpath;
  719. struct sta_info *sta;
  720. int err;
  721. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  722. rcu_read_lock();
  723. sta = sta_info_get(sdata, next_hop);
  724. if (!sta) {
  725. rcu_read_unlock();
  726. return -ENOENT;
  727. }
  728. err = mesh_path_add(dst, sdata);
  729. if (err) {
  730. rcu_read_unlock();
  731. return err;
  732. }
  733. mpath = mesh_path_lookup(dst, sdata);
  734. if (!mpath) {
  735. rcu_read_unlock();
  736. return -ENXIO;
  737. }
  738. mesh_path_fix_nexthop(mpath, sta);
  739. rcu_read_unlock();
  740. return 0;
  741. }
  742. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  743. u8 *dst)
  744. {
  745. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  746. if (dst)
  747. return mesh_path_del(dst, sdata);
  748. mesh_path_flush(sdata);
  749. return 0;
  750. }
  751. static int ieee80211_change_mpath(struct wiphy *wiphy,
  752. struct net_device *dev,
  753. u8 *dst, u8 *next_hop)
  754. {
  755. struct ieee80211_sub_if_data *sdata;
  756. struct mesh_path *mpath;
  757. struct sta_info *sta;
  758. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  759. rcu_read_lock();
  760. sta = sta_info_get(sdata, next_hop);
  761. if (!sta) {
  762. rcu_read_unlock();
  763. return -ENOENT;
  764. }
  765. mpath = mesh_path_lookup(dst, sdata);
  766. if (!mpath) {
  767. rcu_read_unlock();
  768. return -ENOENT;
  769. }
  770. mesh_path_fix_nexthop(mpath, sta);
  771. rcu_read_unlock();
  772. return 0;
  773. }
  774. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  775. struct mpath_info *pinfo)
  776. {
  777. struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
  778. if (next_hop_sta)
  779. memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
  780. else
  781. memset(next_hop, 0, ETH_ALEN);
  782. pinfo->generation = mesh_paths_generation;
  783. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  784. MPATH_INFO_SN |
  785. MPATH_INFO_METRIC |
  786. MPATH_INFO_EXPTIME |
  787. MPATH_INFO_DISCOVERY_TIMEOUT |
  788. MPATH_INFO_DISCOVERY_RETRIES |
  789. MPATH_INFO_FLAGS;
  790. pinfo->frame_qlen = mpath->frame_queue.qlen;
  791. pinfo->sn = mpath->sn;
  792. pinfo->metric = mpath->metric;
  793. if (time_before(jiffies, mpath->exp_time))
  794. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  795. pinfo->discovery_timeout =
  796. jiffies_to_msecs(mpath->discovery_timeout);
  797. pinfo->discovery_retries = mpath->discovery_retries;
  798. pinfo->flags = 0;
  799. if (mpath->flags & MESH_PATH_ACTIVE)
  800. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  801. if (mpath->flags & MESH_PATH_RESOLVING)
  802. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  803. if (mpath->flags & MESH_PATH_SN_VALID)
  804. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  805. if (mpath->flags & MESH_PATH_FIXED)
  806. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  807. if (mpath->flags & MESH_PATH_RESOLVING)
  808. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  809. pinfo->flags = mpath->flags;
  810. }
  811. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  812. u8 *dst, u8 *next_hop, 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(dst, 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_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  829. int idx, u8 *dst, u8 *next_hop,
  830. struct mpath_info *pinfo)
  831. {
  832. struct ieee80211_sub_if_data *sdata;
  833. struct mesh_path *mpath;
  834. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  835. rcu_read_lock();
  836. mpath = mesh_path_lookup_by_idx(idx, sdata);
  837. if (!mpath) {
  838. rcu_read_unlock();
  839. return -ENOENT;
  840. }
  841. memcpy(dst, mpath->dst, ETH_ALEN);
  842. mpath_set_pinfo(mpath, next_hop, pinfo);
  843. rcu_read_unlock();
  844. return 0;
  845. }
  846. static int ieee80211_get_mesh_config(struct wiphy *wiphy,
  847. struct net_device *dev,
  848. struct mesh_config *conf)
  849. {
  850. struct ieee80211_sub_if_data *sdata;
  851. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  852. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  853. return 0;
  854. }
  855. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  856. {
  857. return (mask >> (parm-1)) & 0x1;
  858. }
  859. static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
  860. const struct mesh_setup *setup)
  861. {
  862. u8 *new_ie;
  863. const u8 *old_ie;
  864. /* allocate information elements */
  865. new_ie = NULL;
  866. old_ie = ifmsh->ie;
  867. if (setup->ie_len) {
  868. new_ie = kmemdup(setup->ie, setup->ie_len,
  869. GFP_KERNEL);
  870. if (!new_ie)
  871. return -ENOMEM;
  872. }
  873. ifmsh->ie_len = setup->ie_len;
  874. ifmsh->ie = new_ie;
  875. kfree(old_ie);
  876. /* now copy the rest of the setup parameters */
  877. ifmsh->mesh_id_len = setup->mesh_id_len;
  878. memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
  879. ifmsh->mesh_pp_id = setup->path_sel_proto;
  880. ifmsh->mesh_pm_id = setup->path_metric;
  881. ifmsh->security = IEEE80211_MESH_SEC_NONE;
  882. if (setup->is_authenticated)
  883. ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
  884. if (setup->is_secure)
  885. ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
  886. return 0;
  887. }
  888. static int ieee80211_update_mesh_config(struct wiphy *wiphy,
  889. struct net_device *dev, u32 mask,
  890. const struct mesh_config *nconf)
  891. {
  892. struct mesh_config *conf;
  893. struct ieee80211_sub_if_data *sdata;
  894. struct ieee80211_if_mesh *ifmsh;
  895. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  896. ifmsh = &sdata->u.mesh;
  897. /* Set the config options which we are interested in setting */
  898. conf = &(sdata->u.mesh.mshcfg);
  899. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  900. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  901. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  902. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  903. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  904. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  905. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  906. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  907. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  908. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  909. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  910. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  911. if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  912. conf->dot11MeshTTL = nconf->element_ttl;
  913. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  914. conf->auto_open_plinks = nconf->auto_open_plinks;
  915. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  916. conf->dot11MeshHWMPmaxPREQretries =
  917. nconf->dot11MeshHWMPmaxPREQretries;
  918. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  919. conf->path_refresh_time = nconf->path_refresh_time;
  920. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  921. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  922. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  923. conf->dot11MeshHWMPactivePathTimeout =
  924. nconf->dot11MeshHWMPactivePathTimeout;
  925. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  926. conf->dot11MeshHWMPpreqMinInterval =
  927. nconf->dot11MeshHWMPpreqMinInterval;
  928. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  929. mask))
  930. conf->dot11MeshHWMPnetDiameterTraversalTime =
  931. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  932. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  933. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  934. ieee80211_mesh_root_setup(ifmsh);
  935. }
  936. return 0;
  937. }
  938. static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  939. const struct mesh_config *conf,
  940. const struct mesh_setup *setup)
  941. {
  942. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  943. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  944. int err;
  945. memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
  946. err = copy_mesh_setup(ifmsh, setup);
  947. if (err)
  948. return err;
  949. ieee80211_start_mesh(sdata);
  950. return 0;
  951. }
  952. static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  953. {
  954. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  955. ieee80211_stop_mesh(sdata);
  956. return 0;
  957. }
  958. #endif
  959. static int ieee80211_change_bss(struct wiphy *wiphy,
  960. struct net_device *dev,
  961. struct bss_parameters *params)
  962. {
  963. struct ieee80211_sub_if_data *sdata;
  964. u32 changed = 0;
  965. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  966. if (params->use_cts_prot >= 0) {
  967. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  968. changed |= BSS_CHANGED_ERP_CTS_PROT;
  969. }
  970. if (params->use_short_preamble >= 0) {
  971. sdata->vif.bss_conf.use_short_preamble =
  972. params->use_short_preamble;
  973. changed |= BSS_CHANGED_ERP_PREAMBLE;
  974. }
  975. if (!sdata->vif.bss_conf.use_short_slot &&
  976. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  977. sdata->vif.bss_conf.use_short_slot = true;
  978. changed |= BSS_CHANGED_ERP_SLOT;
  979. }
  980. if (params->use_short_slot_time >= 0) {
  981. sdata->vif.bss_conf.use_short_slot =
  982. params->use_short_slot_time;
  983. changed |= BSS_CHANGED_ERP_SLOT;
  984. }
  985. if (params->basic_rates) {
  986. int i, j;
  987. u32 rates = 0;
  988. struct ieee80211_local *local = wiphy_priv(wiphy);
  989. struct ieee80211_supported_band *sband =
  990. wiphy->bands[local->oper_channel->band];
  991. for (i = 0; i < params->basic_rates_len; i++) {
  992. int rate = (params->basic_rates[i] & 0x7f) * 5;
  993. for (j = 0; j < sband->n_bitrates; j++) {
  994. if (sband->bitrates[j].bitrate == rate)
  995. rates |= BIT(j);
  996. }
  997. }
  998. sdata->vif.bss_conf.basic_rates = rates;
  999. changed |= BSS_CHANGED_BASIC_RATES;
  1000. }
  1001. if (params->ap_isolate >= 0) {
  1002. if (params->ap_isolate)
  1003. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1004. else
  1005. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  1006. }
  1007. if (params->ht_opmode >= 0) {
  1008. sdata->vif.bss_conf.ht_operation_mode =
  1009. (u16) params->ht_opmode;
  1010. changed |= BSS_CHANGED_HT;
  1011. }
  1012. ieee80211_bss_info_change_notify(sdata, changed);
  1013. return 0;
  1014. }
  1015. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  1016. struct ieee80211_txq_params *params)
  1017. {
  1018. struct ieee80211_local *local = wiphy_priv(wiphy);
  1019. struct ieee80211_tx_queue_params p;
  1020. if (!local->ops->conf_tx)
  1021. return -EOPNOTSUPP;
  1022. memset(&p, 0, sizeof(p));
  1023. p.aifs = params->aifs;
  1024. p.cw_max = params->cwmax;
  1025. p.cw_min = params->cwmin;
  1026. p.txop = params->txop;
  1027. /*
  1028. * Setting tx queue params disables u-apsd because it's only
  1029. * called in master mode.
  1030. */
  1031. p.uapsd = false;
  1032. if (drv_conf_tx(local, params->queue, &p)) {
  1033. wiphy_debug(local->hw.wiphy,
  1034. "failed to set TX queue parameters for queue %d\n",
  1035. params->queue);
  1036. return -EINVAL;
  1037. }
  1038. return 0;
  1039. }
  1040. static int ieee80211_set_channel(struct wiphy *wiphy,
  1041. struct net_device *netdev,
  1042. struct ieee80211_channel *chan,
  1043. enum nl80211_channel_type channel_type)
  1044. {
  1045. struct ieee80211_local *local = wiphy_priv(wiphy);
  1046. struct ieee80211_sub_if_data *sdata = NULL;
  1047. struct ieee80211_channel *old_oper;
  1048. enum nl80211_channel_type old_oper_type;
  1049. enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
  1050. if (netdev)
  1051. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  1052. switch (ieee80211_get_channel_mode(local, NULL)) {
  1053. case CHAN_MODE_HOPPING:
  1054. return -EBUSY;
  1055. case CHAN_MODE_FIXED:
  1056. if (local->oper_channel != chan)
  1057. return -EBUSY;
  1058. if (!sdata && local->_oper_channel_type == channel_type)
  1059. return 0;
  1060. break;
  1061. case CHAN_MODE_UNDEFINED:
  1062. break;
  1063. }
  1064. if (sdata)
  1065. old_vif_oper_type = sdata->vif.bss_conf.channel_type;
  1066. old_oper_type = local->_oper_channel_type;
  1067. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  1068. return -EBUSY;
  1069. old_oper = local->oper_channel;
  1070. local->oper_channel = chan;
  1071. /* Update driver if changes were actually made. */
  1072. if ((old_oper != local->oper_channel) ||
  1073. (old_oper_type != local->_oper_channel_type))
  1074. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  1075. if ((sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) &&
  1076. old_vif_oper_type != sdata->vif.bss_conf.channel_type)
  1077. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  1078. return 0;
  1079. }
  1080. #ifdef CONFIG_PM
  1081. static int ieee80211_suspend(struct wiphy *wiphy,
  1082. struct cfg80211_wowlan *wowlan)
  1083. {
  1084. return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
  1085. }
  1086. static int ieee80211_resume(struct wiphy *wiphy)
  1087. {
  1088. return __ieee80211_resume(wiphy_priv(wiphy));
  1089. }
  1090. #else
  1091. #define ieee80211_suspend NULL
  1092. #define ieee80211_resume NULL
  1093. #endif
  1094. static int ieee80211_scan(struct wiphy *wiphy,
  1095. struct net_device *dev,
  1096. struct cfg80211_scan_request *req)
  1097. {
  1098. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1099. switch (ieee80211_vif_type_p2p(&sdata->vif)) {
  1100. case NL80211_IFTYPE_STATION:
  1101. case NL80211_IFTYPE_ADHOC:
  1102. case NL80211_IFTYPE_MESH_POINT:
  1103. case NL80211_IFTYPE_P2P_CLIENT:
  1104. break;
  1105. case NL80211_IFTYPE_P2P_GO:
  1106. if (sdata->local->ops->hw_scan)
  1107. break;
  1108. /*
  1109. * FIXME: implement NoA while scanning in software,
  1110. * for now fall through to allow scanning only when
  1111. * beaconing hasn't been configured yet
  1112. */
  1113. case NL80211_IFTYPE_AP:
  1114. if (sdata->u.ap.beacon)
  1115. return -EOPNOTSUPP;
  1116. break;
  1117. default:
  1118. return -EOPNOTSUPP;
  1119. }
  1120. return ieee80211_request_scan(sdata, req);
  1121. }
  1122. static int
  1123. ieee80211_sched_scan_start(struct wiphy *wiphy,
  1124. struct net_device *dev,
  1125. struct cfg80211_sched_scan_request *req)
  1126. {
  1127. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1128. if (!sdata->local->ops->sched_scan_start)
  1129. return -EOPNOTSUPP;
  1130. return ieee80211_request_sched_scan_start(sdata, req);
  1131. }
  1132. static int
  1133. ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
  1134. {
  1135. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1136. if (!sdata->local->ops->sched_scan_stop)
  1137. return -EOPNOTSUPP;
  1138. return ieee80211_request_sched_scan_stop(sdata);
  1139. }
  1140. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  1141. struct cfg80211_auth_request *req)
  1142. {
  1143. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1144. }
  1145. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  1146. struct cfg80211_assoc_request *req)
  1147. {
  1148. struct ieee80211_local *local = wiphy_priv(wiphy);
  1149. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1150. switch (ieee80211_get_channel_mode(local, sdata)) {
  1151. case CHAN_MODE_HOPPING:
  1152. return -EBUSY;
  1153. case CHAN_MODE_FIXED:
  1154. if (local->oper_channel == req->bss->channel)
  1155. break;
  1156. return -EBUSY;
  1157. case CHAN_MODE_UNDEFINED:
  1158. break;
  1159. }
  1160. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1161. }
  1162. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1163. struct cfg80211_deauth_request *req,
  1164. void *cookie)
  1165. {
  1166. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1167. req, cookie);
  1168. }
  1169. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1170. struct cfg80211_disassoc_request *req,
  1171. void *cookie)
  1172. {
  1173. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1174. req, cookie);
  1175. }
  1176. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1177. struct cfg80211_ibss_params *params)
  1178. {
  1179. struct ieee80211_local *local = wiphy_priv(wiphy);
  1180. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1181. switch (ieee80211_get_channel_mode(local, sdata)) {
  1182. case CHAN_MODE_HOPPING:
  1183. return -EBUSY;
  1184. case CHAN_MODE_FIXED:
  1185. if (!params->channel_fixed)
  1186. return -EBUSY;
  1187. if (local->oper_channel == params->channel)
  1188. break;
  1189. return -EBUSY;
  1190. case CHAN_MODE_UNDEFINED:
  1191. break;
  1192. }
  1193. return ieee80211_ibss_join(sdata, params);
  1194. }
  1195. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1196. {
  1197. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1198. return ieee80211_ibss_leave(sdata);
  1199. }
  1200. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1201. {
  1202. struct ieee80211_local *local = wiphy_priv(wiphy);
  1203. int err;
  1204. if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
  1205. err = drv_set_frag_threshold(local, wiphy->frag_threshold);
  1206. if (err)
  1207. return err;
  1208. }
  1209. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1210. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1211. if (err)
  1212. return err;
  1213. }
  1214. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1215. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1216. if (err)
  1217. return err;
  1218. }
  1219. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1220. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1221. if (changed & WIPHY_PARAM_RETRY_LONG)
  1222. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1223. if (changed &
  1224. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1225. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1226. return 0;
  1227. }
  1228. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1229. enum nl80211_tx_power_setting type, int mbm)
  1230. {
  1231. struct ieee80211_local *local = wiphy_priv(wiphy);
  1232. struct ieee80211_channel *chan = local->hw.conf.channel;
  1233. u32 changes = 0;
  1234. switch (type) {
  1235. case NL80211_TX_POWER_AUTOMATIC:
  1236. local->user_power_level = -1;
  1237. break;
  1238. case NL80211_TX_POWER_LIMITED:
  1239. if (mbm < 0 || (mbm % 100))
  1240. return -EOPNOTSUPP;
  1241. local->user_power_level = MBM_TO_DBM(mbm);
  1242. break;
  1243. case NL80211_TX_POWER_FIXED:
  1244. if (mbm < 0 || (mbm % 100))
  1245. return -EOPNOTSUPP;
  1246. /* TODO: move to cfg80211 when it knows the channel */
  1247. if (MBM_TO_DBM(mbm) > chan->max_power)
  1248. return -EINVAL;
  1249. local->user_power_level = MBM_TO_DBM(mbm);
  1250. break;
  1251. }
  1252. ieee80211_hw_config(local, changes);
  1253. return 0;
  1254. }
  1255. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1256. {
  1257. struct ieee80211_local *local = wiphy_priv(wiphy);
  1258. *dbm = local->hw.conf.power_level;
  1259. return 0;
  1260. }
  1261. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1262. const u8 *addr)
  1263. {
  1264. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1265. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1266. return 0;
  1267. }
  1268. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1269. {
  1270. struct ieee80211_local *local = wiphy_priv(wiphy);
  1271. drv_rfkill_poll(local);
  1272. }
  1273. #ifdef CONFIG_NL80211_TESTMODE
  1274. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1275. {
  1276. struct ieee80211_local *local = wiphy_priv(wiphy);
  1277. if (!local->ops->testmode_cmd)
  1278. return -EOPNOTSUPP;
  1279. return local->ops->testmode_cmd(&local->hw, data, len);
  1280. }
  1281. static int ieee80211_testmode_dump(struct wiphy *wiphy,
  1282. struct sk_buff *skb,
  1283. struct netlink_callback *cb,
  1284. void *data, int len)
  1285. {
  1286. struct ieee80211_local *local = wiphy_priv(wiphy);
  1287. if (!local->ops->testmode_dump)
  1288. return -EOPNOTSUPP;
  1289. return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
  1290. }
  1291. #endif
  1292. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1293. enum ieee80211_smps_mode smps_mode)
  1294. {
  1295. const u8 *ap;
  1296. enum ieee80211_smps_mode old_req;
  1297. int err;
  1298. lockdep_assert_held(&sdata->u.mgd.mtx);
  1299. old_req = sdata->u.mgd.req_smps;
  1300. sdata->u.mgd.req_smps = smps_mode;
  1301. if (old_req == smps_mode &&
  1302. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1303. return 0;
  1304. /*
  1305. * If not associated, or current association is not an HT
  1306. * association, there's no need to send an action frame.
  1307. */
  1308. if (!sdata->u.mgd.associated ||
  1309. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1310. mutex_lock(&sdata->local->iflist_mtx);
  1311. ieee80211_recalc_smps(sdata->local);
  1312. mutex_unlock(&sdata->local->iflist_mtx);
  1313. return 0;
  1314. }
  1315. ap = sdata->u.mgd.associated->bssid;
  1316. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1317. if (sdata->u.mgd.powersave)
  1318. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1319. else
  1320. smps_mode = IEEE80211_SMPS_OFF;
  1321. }
  1322. /* send SM PS frame to AP */
  1323. err = ieee80211_send_smps_action(sdata, smps_mode,
  1324. ap, ap);
  1325. if (err)
  1326. sdata->u.mgd.req_smps = old_req;
  1327. return err;
  1328. }
  1329. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1330. bool enabled, int timeout)
  1331. {
  1332. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1333. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1334. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1335. return -EOPNOTSUPP;
  1336. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1337. return -EOPNOTSUPP;
  1338. if (enabled == sdata->u.mgd.powersave &&
  1339. timeout == local->dynamic_ps_forced_timeout)
  1340. return 0;
  1341. sdata->u.mgd.powersave = enabled;
  1342. local->dynamic_ps_forced_timeout = timeout;
  1343. /* no change, but if automatic follow powersave */
  1344. mutex_lock(&sdata->u.mgd.mtx);
  1345. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1346. mutex_unlock(&sdata->u.mgd.mtx);
  1347. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1348. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1349. ieee80211_recalc_ps(local, -1);
  1350. return 0;
  1351. }
  1352. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1353. struct net_device *dev,
  1354. s32 rssi_thold, u32 rssi_hyst)
  1355. {
  1356. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1357. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1358. struct ieee80211_vif *vif = &sdata->vif;
  1359. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1360. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1361. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1362. return 0;
  1363. bss_conf->cqm_rssi_thold = rssi_thold;
  1364. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1365. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1366. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1367. return -EOPNOTSUPP;
  1368. return 0;
  1369. }
  1370. /* tell the driver upon association, unless already associated */
  1371. if (sdata->u.mgd.associated)
  1372. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1373. return 0;
  1374. }
  1375. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1376. struct net_device *dev,
  1377. const u8 *addr,
  1378. const struct cfg80211_bitrate_mask *mask)
  1379. {
  1380. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1381. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1382. int i, ret;
  1383. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
  1384. ret = drv_set_bitrate_mask(local, sdata, mask);
  1385. if (ret)
  1386. return ret;
  1387. }
  1388. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1389. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1390. return 0;
  1391. }
  1392. static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
  1393. struct net_device *dev,
  1394. struct ieee80211_channel *chan,
  1395. enum nl80211_channel_type chantype,
  1396. unsigned int duration, u64 *cookie)
  1397. {
  1398. int ret;
  1399. u32 random_cookie;
  1400. lockdep_assert_held(&local->mtx);
  1401. if (local->hw_roc_cookie)
  1402. return -EBUSY;
  1403. /* must be nonzero */
  1404. random_cookie = random32() | 1;
  1405. *cookie = random_cookie;
  1406. local->hw_roc_dev = dev;
  1407. local->hw_roc_cookie = random_cookie;
  1408. local->hw_roc_channel = chan;
  1409. local->hw_roc_channel_type = chantype;
  1410. local->hw_roc_duration = duration;
  1411. ret = drv_remain_on_channel(local, chan, chantype, duration);
  1412. if (ret) {
  1413. local->hw_roc_channel = NULL;
  1414. local->hw_roc_cookie = 0;
  1415. }
  1416. return ret;
  1417. }
  1418. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1419. struct net_device *dev,
  1420. struct ieee80211_channel *chan,
  1421. enum nl80211_channel_type channel_type,
  1422. unsigned int duration,
  1423. u64 *cookie)
  1424. {
  1425. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1426. struct ieee80211_local *local = sdata->local;
  1427. if (local->ops->remain_on_channel) {
  1428. int ret;
  1429. mutex_lock(&local->mtx);
  1430. ret = ieee80211_remain_on_channel_hw(local, dev,
  1431. chan, channel_type,
  1432. duration, cookie);
  1433. local->hw_roc_for_tx = false;
  1434. mutex_unlock(&local->mtx);
  1435. return ret;
  1436. }
  1437. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1438. duration, cookie);
  1439. }
  1440. static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
  1441. u64 cookie)
  1442. {
  1443. int ret;
  1444. lockdep_assert_held(&local->mtx);
  1445. if (local->hw_roc_cookie != cookie)
  1446. return -ENOENT;
  1447. ret = drv_cancel_remain_on_channel(local);
  1448. if (ret)
  1449. return ret;
  1450. local->hw_roc_cookie = 0;
  1451. local->hw_roc_channel = NULL;
  1452. ieee80211_recalc_idle(local);
  1453. return 0;
  1454. }
  1455. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1456. struct net_device *dev,
  1457. u64 cookie)
  1458. {
  1459. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1460. struct ieee80211_local *local = sdata->local;
  1461. if (local->ops->cancel_remain_on_channel) {
  1462. int ret;
  1463. mutex_lock(&local->mtx);
  1464. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1465. mutex_unlock(&local->mtx);
  1466. return ret;
  1467. }
  1468. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1469. }
  1470. static enum work_done_result
  1471. ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
  1472. {
  1473. /*
  1474. * Use the data embedded in the work struct for reporting
  1475. * here so if the driver mangled the SKB before dropping
  1476. * it (which is the only way we really should get here)
  1477. * then we don't report mangled data.
  1478. *
  1479. * If there was no wait time, then by the time we get here
  1480. * the driver will likely not have reported the status yet,
  1481. * so in that case userspace will have to deal with it.
  1482. */
  1483. if (wk->offchan_tx.wait && wk->offchan_tx.frame)
  1484. cfg80211_mgmt_tx_status(wk->sdata->dev,
  1485. (unsigned long) wk->offchan_tx.frame,
  1486. wk->ie, wk->ie_len, false, GFP_KERNEL);
  1487. return WORK_DONE_DESTROY;
  1488. }
  1489. static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
  1490. struct ieee80211_channel *chan, bool offchan,
  1491. enum nl80211_channel_type channel_type,
  1492. bool channel_type_valid, unsigned int wait,
  1493. const u8 *buf, size_t len, u64 *cookie)
  1494. {
  1495. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1496. struct ieee80211_local *local = sdata->local;
  1497. struct sk_buff *skb;
  1498. struct sta_info *sta;
  1499. struct ieee80211_work *wk;
  1500. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1501. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1502. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1503. bool is_offchan = false;
  1504. /* Check that we are on the requested channel for transmission */
  1505. if (chan != local->tmp_channel &&
  1506. chan != local->oper_channel)
  1507. is_offchan = true;
  1508. if (channel_type_valid &&
  1509. (channel_type != local->tmp_channel_type &&
  1510. channel_type != local->_oper_channel_type))
  1511. is_offchan = true;
  1512. if (chan == local->hw_roc_channel) {
  1513. /* TODO: check channel type? */
  1514. is_offchan = false;
  1515. flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1516. }
  1517. if (is_offchan && !offchan)
  1518. return -EBUSY;
  1519. switch (sdata->vif.type) {
  1520. case NL80211_IFTYPE_ADHOC:
  1521. case NL80211_IFTYPE_AP:
  1522. case NL80211_IFTYPE_AP_VLAN:
  1523. case NL80211_IFTYPE_P2P_GO:
  1524. case NL80211_IFTYPE_MESH_POINT:
  1525. if (!ieee80211_is_action(mgmt->frame_control) ||
  1526. mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1527. break;
  1528. rcu_read_lock();
  1529. sta = sta_info_get(sdata, mgmt->da);
  1530. rcu_read_unlock();
  1531. if (!sta)
  1532. return -ENOLINK;
  1533. break;
  1534. case NL80211_IFTYPE_STATION:
  1535. case NL80211_IFTYPE_P2P_CLIENT:
  1536. break;
  1537. default:
  1538. return -EOPNOTSUPP;
  1539. }
  1540. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1541. if (!skb)
  1542. return -ENOMEM;
  1543. skb_reserve(skb, local->hw.extra_tx_headroom);
  1544. memcpy(skb_put(skb, len), buf, len);
  1545. IEEE80211_SKB_CB(skb)->flags = flags;
  1546. skb->dev = sdata->dev;
  1547. *cookie = (unsigned long) skb;
  1548. if (is_offchan && local->ops->offchannel_tx) {
  1549. int ret;
  1550. IEEE80211_SKB_CB(skb)->band = chan->band;
  1551. mutex_lock(&local->mtx);
  1552. if (local->hw_offchan_tx_cookie) {
  1553. mutex_unlock(&local->mtx);
  1554. return -EBUSY;
  1555. }
  1556. /* TODO: bitrate control, TX processing? */
  1557. ret = drv_offchannel_tx(local, skb, chan, channel_type, wait);
  1558. if (ret == 0)
  1559. local->hw_offchan_tx_cookie = *cookie;
  1560. mutex_unlock(&local->mtx);
  1561. /*
  1562. * Allow driver to return 1 to indicate it wants to have the
  1563. * frame transmitted with a remain_on_channel + regular TX.
  1564. */
  1565. if (ret != 1)
  1566. return ret;
  1567. }
  1568. if (is_offchan && local->ops->remain_on_channel) {
  1569. unsigned int duration;
  1570. int ret;
  1571. mutex_lock(&local->mtx);
  1572. /*
  1573. * If the duration is zero, then the driver
  1574. * wouldn't actually do anything. Set it to
  1575. * 100 for now.
  1576. *
  1577. * TODO: cancel the off-channel operation
  1578. * when we get the SKB's TX status and
  1579. * the wait time was zero before.
  1580. */
  1581. duration = 100;
  1582. if (wait)
  1583. duration = wait;
  1584. ret = ieee80211_remain_on_channel_hw(local, dev, chan,
  1585. channel_type,
  1586. duration, cookie);
  1587. if (ret) {
  1588. kfree_skb(skb);
  1589. mutex_unlock(&local->mtx);
  1590. return ret;
  1591. }
  1592. local->hw_roc_for_tx = true;
  1593. local->hw_roc_duration = wait;
  1594. /*
  1595. * queue up frame for transmission after
  1596. * ieee80211_ready_on_channel call
  1597. */
  1598. /* modify cookie to prevent API mismatches */
  1599. *cookie ^= 2;
  1600. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
  1601. local->hw_roc_skb = skb;
  1602. local->hw_roc_skb_for_status = skb;
  1603. mutex_unlock(&local->mtx);
  1604. return 0;
  1605. }
  1606. /*
  1607. * Can transmit right away if the channel was the
  1608. * right one and there's no wait involved... If a
  1609. * wait is involved, we might otherwise not be on
  1610. * the right channel for long enough!
  1611. */
  1612. if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
  1613. ieee80211_tx_skb(sdata, skb);
  1614. return 0;
  1615. }
  1616. wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
  1617. if (!wk) {
  1618. kfree_skb(skb);
  1619. return -ENOMEM;
  1620. }
  1621. wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
  1622. wk->chan = chan;
  1623. wk->chan_type = channel_type;
  1624. wk->sdata = sdata;
  1625. wk->done = ieee80211_offchan_tx_done;
  1626. wk->offchan_tx.frame = skb;
  1627. wk->offchan_tx.wait = wait;
  1628. wk->ie_len = len;
  1629. memcpy(wk->ie, buf, len);
  1630. ieee80211_add_work(wk);
  1631. return 0;
  1632. }
  1633. static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  1634. struct net_device *dev,
  1635. u64 cookie)
  1636. {
  1637. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1638. struct ieee80211_local *local = sdata->local;
  1639. struct ieee80211_work *wk;
  1640. int ret = -ENOENT;
  1641. mutex_lock(&local->mtx);
  1642. if (local->ops->offchannel_tx_cancel_wait &&
  1643. local->hw_offchan_tx_cookie == cookie) {
  1644. ret = drv_offchannel_tx_cancel_wait(local);
  1645. if (!ret)
  1646. local->hw_offchan_tx_cookie = 0;
  1647. mutex_unlock(&local->mtx);
  1648. return ret;
  1649. }
  1650. if (local->ops->cancel_remain_on_channel) {
  1651. cookie ^= 2;
  1652. ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
  1653. if (ret == 0) {
  1654. kfree_skb(local->hw_roc_skb);
  1655. local->hw_roc_skb = NULL;
  1656. local->hw_roc_skb_for_status = NULL;
  1657. }
  1658. mutex_unlock(&local->mtx);
  1659. return ret;
  1660. }
  1661. list_for_each_entry(wk, &local->work_list, list) {
  1662. if (wk->sdata != sdata)
  1663. continue;
  1664. if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
  1665. continue;
  1666. if (cookie != (unsigned long) wk->offchan_tx.frame)
  1667. continue;
  1668. wk->timeout = jiffies;
  1669. ieee80211_queue_work(&local->hw, &local->work_work);
  1670. ret = 0;
  1671. break;
  1672. }
  1673. mutex_unlock(&local->mtx);
  1674. return ret;
  1675. }
  1676. static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
  1677. struct net_device *dev,
  1678. u16 frame_type, bool reg)
  1679. {
  1680. struct ieee80211_local *local = wiphy_priv(wiphy);
  1681. if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
  1682. return;
  1683. if (reg)
  1684. local->probe_req_reg++;
  1685. else
  1686. local->probe_req_reg--;
  1687. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  1688. }
  1689. static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
  1690. {
  1691. struct ieee80211_local *local = wiphy_priv(wiphy);
  1692. if (local->started)
  1693. return -EOPNOTSUPP;
  1694. return drv_set_antenna(local, tx_ant, rx_ant);
  1695. }
  1696. static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
  1697. {
  1698. struct ieee80211_local *local = wiphy_priv(wiphy);
  1699. return drv_get_antenna(local, tx_ant, rx_ant);
  1700. }
  1701. static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
  1702. {
  1703. struct ieee80211_local *local = wiphy_priv(wiphy);
  1704. return drv_set_ringparam(local, tx, rx);
  1705. }
  1706. static void ieee80211_get_ringparam(struct wiphy *wiphy,
  1707. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  1708. {
  1709. struct ieee80211_local *local = wiphy_priv(wiphy);
  1710. drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  1711. }
  1712. static int ieee80211_set_rekey_data(struct wiphy *wiphy,
  1713. struct net_device *dev,
  1714. struct cfg80211_gtk_rekey_data *data)
  1715. {
  1716. struct ieee80211_local *local = wiphy_priv(wiphy);
  1717. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1718. if (!local->ops->set_rekey_data)
  1719. return -EOPNOTSUPP;
  1720. drv_set_rekey_data(local, sdata, data);
  1721. return 0;
  1722. }
  1723. struct cfg80211_ops mac80211_config_ops = {
  1724. .add_virtual_intf = ieee80211_add_iface,
  1725. .del_virtual_intf = ieee80211_del_iface,
  1726. .change_virtual_intf = ieee80211_change_iface,
  1727. .add_key = ieee80211_add_key,
  1728. .del_key = ieee80211_del_key,
  1729. .get_key = ieee80211_get_key,
  1730. .set_default_key = ieee80211_config_default_key,
  1731. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1732. .add_beacon = ieee80211_add_beacon,
  1733. .set_beacon = ieee80211_set_beacon,
  1734. .del_beacon = ieee80211_del_beacon,
  1735. .add_station = ieee80211_add_station,
  1736. .del_station = ieee80211_del_station,
  1737. .change_station = ieee80211_change_station,
  1738. .get_station = ieee80211_get_station,
  1739. .dump_station = ieee80211_dump_station,
  1740. .dump_survey = ieee80211_dump_survey,
  1741. #ifdef CONFIG_MAC80211_MESH
  1742. .add_mpath = ieee80211_add_mpath,
  1743. .del_mpath = ieee80211_del_mpath,
  1744. .change_mpath = ieee80211_change_mpath,
  1745. .get_mpath = ieee80211_get_mpath,
  1746. .dump_mpath = ieee80211_dump_mpath,
  1747. .update_mesh_config = ieee80211_update_mesh_config,
  1748. .get_mesh_config = ieee80211_get_mesh_config,
  1749. .join_mesh = ieee80211_join_mesh,
  1750. .leave_mesh = ieee80211_leave_mesh,
  1751. #endif
  1752. .change_bss = ieee80211_change_bss,
  1753. .set_txq_params = ieee80211_set_txq_params,
  1754. .set_channel = ieee80211_set_channel,
  1755. .suspend = ieee80211_suspend,
  1756. .resume = ieee80211_resume,
  1757. .scan = ieee80211_scan,
  1758. .sched_scan_start = ieee80211_sched_scan_start,
  1759. .sched_scan_stop = ieee80211_sched_scan_stop,
  1760. .auth = ieee80211_auth,
  1761. .assoc = ieee80211_assoc,
  1762. .deauth = ieee80211_deauth,
  1763. .disassoc = ieee80211_disassoc,
  1764. .join_ibss = ieee80211_join_ibss,
  1765. .leave_ibss = ieee80211_leave_ibss,
  1766. .set_wiphy_params = ieee80211_set_wiphy_params,
  1767. .set_tx_power = ieee80211_set_tx_power,
  1768. .get_tx_power = ieee80211_get_tx_power,
  1769. .set_wds_peer = ieee80211_set_wds_peer,
  1770. .rfkill_poll = ieee80211_rfkill_poll,
  1771. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1772. CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
  1773. .set_power_mgmt = ieee80211_set_power_mgmt,
  1774. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1775. .remain_on_channel = ieee80211_remain_on_channel,
  1776. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1777. .mgmt_tx = ieee80211_mgmt_tx,
  1778. .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
  1779. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1780. .mgmt_frame_register = ieee80211_mgmt_frame_register,
  1781. .set_antenna = ieee80211_set_antenna,
  1782. .get_antenna = ieee80211_get_antenna,
  1783. .set_ringparam = ieee80211_set_ringparam,
  1784. .get_ringparam = ieee80211_get_ringparam,
  1785. .set_rekey_data = ieee80211_set_rekey_data,
  1786. };