cfg.c 51 KB

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