cfg.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  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 bool nl80211_type_check(enum nl80211_iftype type)
  21. {
  22. switch (type) {
  23. case NL80211_IFTYPE_ADHOC:
  24. case NL80211_IFTYPE_STATION:
  25. case NL80211_IFTYPE_MONITOR:
  26. #ifdef CONFIG_MAC80211_MESH
  27. case NL80211_IFTYPE_MESH_POINT:
  28. #endif
  29. case NL80211_IFTYPE_AP:
  30. case NL80211_IFTYPE_AP_VLAN:
  31. case NL80211_IFTYPE_WDS:
  32. return true;
  33. default:
  34. return false;
  35. }
  36. }
  37. static bool nl80211_params_check(enum nl80211_iftype type,
  38. struct vif_params *params)
  39. {
  40. if (!nl80211_type_check(type))
  41. return false;
  42. return true;
  43. }
  44. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  45. enum nl80211_iftype type, u32 *flags,
  46. struct vif_params *params)
  47. {
  48. struct ieee80211_local *local = wiphy_priv(wiphy);
  49. struct net_device *dev;
  50. struct ieee80211_sub_if_data *sdata;
  51. int err;
  52. if (!nl80211_params_check(type, params))
  53. return -EINVAL;
  54. err = ieee80211_if_add(local, name, &dev, type, params);
  55. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  56. return err;
  57. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  58. sdata->u.mntr_flags = *flags;
  59. return 0;
  60. }
  61. static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
  62. {
  63. ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
  64. return 0;
  65. }
  66. static int ieee80211_change_iface(struct wiphy *wiphy,
  67. struct net_device *dev,
  68. enum nl80211_iftype type, u32 *flags,
  69. struct vif_params *params)
  70. {
  71. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  72. int ret;
  73. if (ieee80211_sdata_running(sdata))
  74. return -EBUSY;
  75. if (!nl80211_params_check(type, params))
  76. return -EINVAL;
  77. ret = ieee80211_if_change_type(sdata, type);
  78. if (ret)
  79. return ret;
  80. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  81. ieee80211_sdata_set_mesh_id(sdata,
  82. params->mesh_id_len,
  83. params->mesh_id);
  84. if (type == NL80211_IFTYPE_AP_VLAN &&
  85. params && params->use_4addr == 0)
  86. rcu_assign_pointer(sdata->u.vlan.sta, NULL);
  87. else if (type == NL80211_IFTYPE_STATION &&
  88. params && params->use_4addr >= 0)
  89. sdata->u.mgd.use_4addr = params->use_4addr;
  90. if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
  91. sdata->u.mntr_flags = *flags;
  92. return 0;
  93. }
  94. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  95. u8 key_idx, const u8 *mac_addr,
  96. struct key_params *params)
  97. {
  98. struct ieee80211_sub_if_data *sdata;
  99. struct sta_info *sta = NULL;
  100. enum ieee80211_key_alg alg;
  101. struct ieee80211_key *key;
  102. int err;
  103. if (!netif_running(dev))
  104. return -ENETDOWN;
  105. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  106. switch (params->cipher) {
  107. case WLAN_CIPHER_SUITE_WEP40:
  108. case WLAN_CIPHER_SUITE_WEP104:
  109. alg = ALG_WEP;
  110. break;
  111. case WLAN_CIPHER_SUITE_TKIP:
  112. alg = ALG_TKIP;
  113. break;
  114. case WLAN_CIPHER_SUITE_CCMP:
  115. alg = ALG_CCMP;
  116. break;
  117. case WLAN_CIPHER_SUITE_AES_CMAC:
  118. alg = ALG_AES_CMAC;
  119. break;
  120. default:
  121. return -EINVAL;
  122. }
  123. /* reject WEP and TKIP keys if WEP failed to initialize */
  124. if ((alg == ALG_WEP || alg == ALG_TKIP) &&
  125. IS_ERR(sdata->local->wep_tx_tfm))
  126. return -EINVAL;
  127. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
  128. params->seq_len, params->seq);
  129. if (!key)
  130. return -ENOMEM;
  131. mutex_lock(&sdata->local->sta_mtx);
  132. if (mac_addr) {
  133. sta = sta_info_get_bss(sdata, mac_addr);
  134. if (!sta) {
  135. ieee80211_key_free(key);
  136. err = -ENOENT;
  137. goto out_unlock;
  138. }
  139. }
  140. ieee80211_key_link(key, sdata, sta);
  141. err = 0;
  142. out_unlock:
  143. mutex_unlock(&sdata->local->sta_mtx);
  144. return err;
  145. }
  146. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  147. u8 key_idx, const u8 *mac_addr)
  148. {
  149. struct ieee80211_sub_if_data *sdata;
  150. struct sta_info *sta;
  151. int ret;
  152. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  153. mutex_lock(&sdata->local->sta_mtx);
  154. if (mac_addr) {
  155. ret = -ENOENT;
  156. sta = sta_info_get_bss(sdata, mac_addr);
  157. if (!sta)
  158. goto out_unlock;
  159. if (sta->key) {
  160. ieee80211_key_free(sta->key);
  161. WARN_ON(sta->key);
  162. ret = 0;
  163. }
  164. goto out_unlock;
  165. }
  166. if (!sdata->keys[key_idx]) {
  167. ret = -ENOENT;
  168. goto out_unlock;
  169. }
  170. ieee80211_key_free(sdata->keys[key_idx]);
  171. WARN_ON(sdata->keys[key_idx]);
  172. ret = 0;
  173. out_unlock:
  174. mutex_unlock(&sdata->local->sta_mtx);
  175. return ret;
  176. }
  177. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  178. u8 key_idx, const u8 *mac_addr, void *cookie,
  179. void (*callback)(void *cookie,
  180. struct key_params *params))
  181. {
  182. struct ieee80211_sub_if_data *sdata;
  183. struct sta_info *sta = NULL;
  184. u8 seq[6] = {0};
  185. struct key_params params;
  186. struct ieee80211_key *key;
  187. u32 iv32;
  188. u16 iv16;
  189. int err = -ENOENT;
  190. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  191. rcu_read_lock();
  192. if (mac_addr) {
  193. sta = sta_info_get_bss(sdata, mac_addr);
  194. if (!sta)
  195. goto out;
  196. key = sta->key;
  197. } else
  198. key = sdata->keys[key_idx];
  199. if (!key)
  200. goto out;
  201. memset(&params, 0, sizeof(params));
  202. switch (key->conf.alg) {
  203. case ALG_TKIP:
  204. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  205. iv32 = key->u.tkip.tx.iv32;
  206. iv16 = key->u.tkip.tx.iv16;
  207. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  208. drv_get_tkip_seq(sdata->local,
  209. key->conf.hw_key_idx,
  210. &iv32, &iv16);
  211. seq[0] = iv16 & 0xff;
  212. seq[1] = (iv16 >> 8) & 0xff;
  213. seq[2] = iv32 & 0xff;
  214. seq[3] = (iv32 >> 8) & 0xff;
  215. seq[4] = (iv32 >> 16) & 0xff;
  216. seq[5] = (iv32 >> 24) & 0xff;
  217. params.seq = seq;
  218. params.seq_len = 6;
  219. break;
  220. case ALG_CCMP:
  221. params.cipher = WLAN_CIPHER_SUITE_CCMP;
  222. seq[0] = key->u.ccmp.tx_pn[5];
  223. seq[1] = key->u.ccmp.tx_pn[4];
  224. seq[2] = key->u.ccmp.tx_pn[3];
  225. seq[3] = key->u.ccmp.tx_pn[2];
  226. seq[4] = key->u.ccmp.tx_pn[1];
  227. seq[5] = key->u.ccmp.tx_pn[0];
  228. params.seq = seq;
  229. params.seq_len = 6;
  230. break;
  231. case ALG_WEP:
  232. if (key->conf.keylen == 5)
  233. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  234. else
  235. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  236. break;
  237. case ALG_AES_CMAC:
  238. params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  239. seq[0] = key->u.aes_cmac.tx_pn[5];
  240. seq[1] = key->u.aes_cmac.tx_pn[4];
  241. seq[2] = key->u.aes_cmac.tx_pn[3];
  242. seq[3] = key->u.aes_cmac.tx_pn[2];
  243. seq[4] = key->u.aes_cmac.tx_pn[1];
  244. seq[5] = key->u.aes_cmac.tx_pn[0];
  245. params.seq = seq;
  246. params.seq_len = 6;
  247. break;
  248. }
  249. params.key = key->conf.key;
  250. params.key_len = key->conf.keylen;
  251. callback(cookie, &params);
  252. err = 0;
  253. out:
  254. rcu_read_unlock();
  255. return err;
  256. }
  257. static int ieee80211_config_default_key(struct wiphy *wiphy,
  258. struct net_device *dev,
  259. u8 key_idx)
  260. {
  261. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  262. ieee80211_set_default_key(sdata, key_idx);
  263. return 0;
  264. }
  265. static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
  266. struct net_device *dev,
  267. u8 key_idx)
  268. {
  269. struct ieee80211_sub_if_data *sdata;
  270. rcu_read_lock();
  271. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  272. ieee80211_set_default_mgmt_key(sdata, key_idx);
  273. rcu_read_unlock();
  274. return 0;
  275. }
  276. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  277. {
  278. struct ieee80211_sub_if_data *sdata = sta->sdata;
  279. sinfo->generation = sdata->local->sta_generation;
  280. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  281. STATION_INFO_RX_BYTES |
  282. STATION_INFO_TX_BYTES |
  283. STATION_INFO_RX_PACKETS |
  284. STATION_INFO_TX_PACKETS |
  285. STATION_INFO_TX_BITRATE;
  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. if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
  292. (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
  293. sinfo->filled |= STATION_INFO_SIGNAL;
  294. sinfo->signal = (s8)sta->last_signal;
  295. }
  296. sinfo->txrate.flags = 0;
  297. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  298. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  299. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  300. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  301. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  302. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  303. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  304. struct ieee80211_supported_band *sband;
  305. sband = sta->local->hw.wiphy->bands[
  306. sta->local->hw.conf.channel->band];
  307. sinfo->txrate.legacy =
  308. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  309. } else
  310. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  311. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  312. #ifdef CONFIG_MAC80211_MESH
  313. sinfo->filled |= STATION_INFO_LLID |
  314. STATION_INFO_PLID |
  315. STATION_INFO_PLINK_STATE;
  316. sinfo->llid = le16_to_cpu(sta->llid);
  317. sinfo->plid = le16_to_cpu(sta->plid);
  318. sinfo->plink_state = sta->plink_state;
  319. #endif
  320. }
  321. }
  322. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  323. int idx, u8 *mac, struct station_info *sinfo)
  324. {
  325. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  326. struct sta_info *sta;
  327. int ret = -ENOENT;
  328. rcu_read_lock();
  329. sta = sta_info_get_by_idx(sdata, idx);
  330. if (sta) {
  331. ret = 0;
  332. memcpy(mac, sta->sta.addr, ETH_ALEN);
  333. sta_set_sinfo(sta, sinfo);
  334. }
  335. rcu_read_unlock();
  336. return ret;
  337. }
  338. static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  339. int idx, struct survey_info *survey)
  340. {
  341. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  342. return drv_get_survey(local, idx, survey);
  343. }
  344. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  345. u8 *mac, struct station_info *sinfo)
  346. {
  347. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  348. struct sta_info *sta;
  349. int ret = -ENOENT;
  350. rcu_read_lock();
  351. sta = sta_info_get_bss(sdata, mac);
  352. if (sta) {
  353. ret = 0;
  354. sta_set_sinfo(sta, sinfo);
  355. }
  356. rcu_read_unlock();
  357. return ret;
  358. }
  359. /*
  360. * This handles both adding a beacon and setting new beacon info
  361. */
  362. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  363. struct beacon_parameters *params)
  364. {
  365. struct beacon_data *new, *old;
  366. int new_head_len, new_tail_len;
  367. int size;
  368. int err = -EINVAL;
  369. old = sdata->u.ap.beacon;
  370. /* head must not be zero-length */
  371. if (params->head && !params->head_len)
  372. return -EINVAL;
  373. /*
  374. * This is a kludge. beacon interval should really be part
  375. * of the beacon information.
  376. */
  377. if (params->interval &&
  378. (sdata->vif.bss_conf.beacon_int != params->interval)) {
  379. sdata->vif.bss_conf.beacon_int = params->interval;
  380. ieee80211_bss_info_change_notify(sdata,
  381. BSS_CHANGED_BEACON_INT);
  382. }
  383. /* Need to have a beacon head if we don't have one yet */
  384. if (!params->head && !old)
  385. return err;
  386. /* sorry, no way to start beaconing without dtim period */
  387. if (!params->dtim_period && !old)
  388. return err;
  389. /* new or old head? */
  390. if (params->head)
  391. new_head_len = params->head_len;
  392. else
  393. new_head_len = old->head_len;
  394. /* new or old tail? */
  395. if (params->tail || !old)
  396. /* params->tail_len will be zero for !params->tail */
  397. new_tail_len = params->tail_len;
  398. else
  399. new_tail_len = old->tail_len;
  400. size = sizeof(*new) + new_head_len + new_tail_len;
  401. new = kzalloc(size, GFP_KERNEL);
  402. if (!new)
  403. return -ENOMEM;
  404. /* start filling the new info now */
  405. /* new or old dtim period? */
  406. if (params->dtim_period)
  407. new->dtim_period = params->dtim_period;
  408. else
  409. new->dtim_period = old->dtim_period;
  410. /*
  411. * pointers go into the block we allocated,
  412. * memory is | beacon_data | head | tail |
  413. */
  414. new->head = ((u8 *) new) + sizeof(*new);
  415. new->tail = new->head + new_head_len;
  416. new->head_len = new_head_len;
  417. new->tail_len = new_tail_len;
  418. /* copy in head */
  419. if (params->head)
  420. memcpy(new->head, params->head, new_head_len);
  421. else
  422. memcpy(new->head, old->head, new_head_len);
  423. /* copy in optional tail */
  424. if (params->tail)
  425. memcpy(new->tail, params->tail, new_tail_len);
  426. else
  427. if (old)
  428. memcpy(new->tail, old->tail, new_tail_len);
  429. sdata->vif.bss_conf.dtim_period = new->dtim_period;
  430. rcu_assign_pointer(sdata->u.ap.beacon, new);
  431. synchronize_rcu();
  432. kfree(old);
  433. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  434. BSS_CHANGED_BEACON);
  435. return 0;
  436. }
  437. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  438. struct beacon_parameters *params)
  439. {
  440. struct ieee80211_sub_if_data *sdata;
  441. struct beacon_data *old;
  442. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  443. old = sdata->u.ap.beacon;
  444. if (old)
  445. return -EALREADY;
  446. return ieee80211_config_beacon(sdata, params);
  447. }
  448. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  449. struct beacon_parameters *params)
  450. {
  451. struct ieee80211_sub_if_data *sdata;
  452. struct beacon_data *old;
  453. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  454. old = sdata->u.ap.beacon;
  455. if (!old)
  456. return -ENOENT;
  457. return ieee80211_config_beacon(sdata, params);
  458. }
  459. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  460. {
  461. struct ieee80211_sub_if_data *sdata;
  462. struct beacon_data *old;
  463. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  464. old = sdata->u.ap.beacon;
  465. if (!old)
  466. return -ENOENT;
  467. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  468. synchronize_rcu();
  469. kfree(old);
  470. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  471. return 0;
  472. }
  473. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  474. struct iapp_layer2_update {
  475. u8 da[ETH_ALEN]; /* broadcast */
  476. u8 sa[ETH_ALEN]; /* STA addr */
  477. __be16 len; /* 6 */
  478. u8 dsap; /* 0 */
  479. u8 ssap; /* 0 */
  480. u8 control;
  481. u8 xid_info[3];
  482. } __attribute__ ((packed));
  483. static void ieee80211_send_layer2_update(struct sta_info *sta)
  484. {
  485. struct iapp_layer2_update *msg;
  486. struct sk_buff *skb;
  487. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  488. * bridge devices */
  489. skb = dev_alloc_skb(sizeof(*msg));
  490. if (!skb)
  491. return;
  492. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  493. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  494. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  495. memset(msg->da, 0xff, ETH_ALEN);
  496. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  497. msg->len = htons(6);
  498. msg->dsap = 0;
  499. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  500. msg->control = 0xaf; /* XID response lsb.1111F101.
  501. * F=0 (no poll command; unsolicited frame) */
  502. msg->xid_info[0] = 0x81; /* XID format identifier */
  503. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  504. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  505. skb->dev = sta->sdata->dev;
  506. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  507. memset(skb->cb, 0, sizeof(skb->cb));
  508. netif_rx(skb);
  509. }
  510. static void sta_apply_parameters(struct ieee80211_local *local,
  511. struct sta_info *sta,
  512. struct station_parameters *params)
  513. {
  514. u32 rates;
  515. int i, j;
  516. struct ieee80211_supported_band *sband;
  517. struct ieee80211_sub_if_data *sdata = sta->sdata;
  518. u32 mask, set;
  519. sband = local->hw.wiphy->bands[local->oper_channel->band];
  520. spin_lock_bh(&sta->lock);
  521. mask = params->sta_flags_mask;
  522. set = params->sta_flags_set;
  523. if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
  524. sta->flags &= ~WLAN_STA_AUTHORIZED;
  525. if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  526. sta->flags |= WLAN_STA_AUTHORIZED;
  527. }
  528. if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
  529. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  530. if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
  531. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  532. }
  533. if (mask & BIT(NL80211_STA_FLAG_WME)) {
  534. sta->flags &= ~WLAN_STA_WME;
  535. if (set & BIT(NL80211_STA_FLAG_WME))
  536. sta->flags |= WLAN_STA_WME;
  537. }
  538. if (mask & BIT(NL80211_STA_FLAG_MFP)) {
  539. sta->flags &= ~WLAN_STA_MFP;
  540. if (set & BIT(NL80211_STA_FLAG_MFP))
  541. sta->flags |= WLAN_STA_MFP;
  542. }
  543. spin_unlock_bh(&sta->lock);
  544. /*
  545. * cfg80211 validates this (1-2007) and allows setting the AID
  546. * only when creating a new station entry
  547. */
  548. if (params->aid)
  549. sta->sta.aid = params->aid;
  550. /*
  551. * FIXME: updating the following information is racy when this
  552. * function is called from ieee80211_change_station().
  553. * However, all this information should be static so
  554. * maybe we should just reject attemps to change it.
  555. */
  556. if (params->listen_interval >= 0)
  557. sta->listen_interval = params->listen_interval;
  558. if (params->supported_rates) {
  559. rates = 0;
  560. for (i = 0; i < params->supported_rates_len; i++) {
  561. int rate = (params->supported_rates[i] & 0x7f) * 5;
  562. for (j = 0; j < sband->n_bitrates; j++) {
  563. if (sband->bitrates[j].bitrate == rate)
  564. rates |= BIT(j);
  565. }
  566. }
  567. sta->sta.supp_rates[local->oper_channel->band] = rates;
  568. }
  569. if (params->ht_capa)
  570. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  571. params->ht_capa,
  572. &sta->sta.ht_cap);
  573. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  574. switch (params->plink_action) {
  575. case PLINK_ACTION_OPEN:
  576. mesh_plink_open(sta);
  577. break;
  578. case PLINK_ACTION_BLOCK:
  579. mesh_plink_block(sta);
  580. break;
  581. }
  582. }
  583. }
  584. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  585. u8 *mac, struct station_parameters *params)
  586. {
  587. struct ieee80211_local *local = wiphy_priv(wiphy);
  588. struct sta_info *sta;
  589. struct ieee80211_sub_if_data *sdata;
  590. int err;
  591. int layer2_update;
  592. if (params->vlan) {
  593. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  594. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  595. sdata->vif.type != NL80211_IFTYPE_AP)
  596. return -EINVAL;
  597. } else
  598. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  599. if (compare_ether_addr(mac, sdata->vif.addr) == 0)
  600. return -EINVAL;
  601. if (is_multicast_ether_addr(mac))
  602. return -EINVAL;
  603. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  604. if (!sta)
  605. return -ENOMEM;
  606. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  607. sta_apply_parameters(local, sta, params);
  608. rate_control_rate_init(sta);
  609. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  610. sdata->vif.type == NL80211_IFTYPE_AP;
  611. err = sta_info_insert_rcu(sta);
  612. if (err) {
  613. rcu_read_unlock();
  614. return err;
  615. }
  616. if (layer2_update)
  617. ieee80211_send_layer2_update(sta);
  618. rcu_read_unlock();
  619. return 0;
  620. }
  621. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  622. u8 *mac)
  623. {
  624. struct ieee80211_local *local = wiphy_priv(wiphy);
  625. struct ieee80211_sub_if_data *sdata;
  626. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  627. if (mac)
  628. return sta_info_destroy_addr_bss(sdata, mac);
  629. sta_info_flush(local, sdata);
  630. return 0;
  631. }
  632. static int ieee80211_change_station(struct wiphy *wiphy,
  633. struct net_device *dev,
  634. u8 *mac,
  635. struct station_parameters *params)
  636. {
  637. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  638. struct ieee80211_local *local = wiphy_priv(wiphy);
  639. struct sta_info *sta;
  640. struct ieee80211_sub_if_data *vlansdata;
  641. rcu_read_lock();
  642. sta = sta_info_get_bss(sdata, mac);
  643. if (!sta) {
  644. rcu_read_unlock();
  645. return -ENOENT;
  646. }
  647. if (params->vlan && params->vlan != sta->sdata->dev) {
  648. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  649. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  650. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  651. rcu_read_unlock();
  652. return -EINVAL;
  653. }
  654. if (params->vlan->ieee80211_ptr->use_4addr) {
  655. if (vlansdata->u.vlan.sta) {
  656. rcu_read_unlock();
  657. return -EBUSY;
  658. }
  659. rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
  660. }
  661. sta->sdata = vlansdata;
  662. ieee80211_send_layer2_update(sta);
  663. }
  664. sta_apply_parameters(local, sta, params);
  665. rcu_read_unlock();
  666. return 0;
  667. }
  668. #ifdef CONFIG_MAC80211_MESH
  669. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  670. u8 *dst, u8 *next_hop)
  671. {
  672. struct ieee80211_sub_if_data *sdata;
  673. struct mesh_path *mpath;
  674. struct sta_info *sta;
  675. int err;
  676. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  677. rcu_read_lock();
  678. sta = sta_info_get(sdata, next_hop);
  679. if (!sta) {
  680. rcu_read_unlock();
  681. return -ENOENT;
  682. }
  683. err = mesh_path_add(dst, sdata);
  684. if (err) {
  685. rcu_read_unlock();
  686. return err;
  687. }
  688. mpath = mesh_path_lookup(dst, sdata);
  689. if (!mpath) {
  690. rcu_read_unlock();
  691. return -ENXIO;
  692. }
  693. mesh_path_fix_nexthop(mpath, sta);
  694. rcu_read_unlock();
  695. return 0;
  696. }
  697. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  698. u8 *dst)
  699. {
  700. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  701. if (dst)
  702. return mesh_path_del(dst, sdata);
  703. mesh_path_flush(sdata);
  704. return 0;
  705. }
  706. static int ieee80211_change_mpath(struct wiphy *wiphy,
  707. struct net_device *dev,
  708. u8 *dst, u8 *next_hop)
  709. {
  710. struct ieee80211_sub_if_data *sdata;
  711. struct mesh_path *mpath;
  712. struct sta_info *sta;
  713. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  714. rcu_read_lock();
  715. sta = sta_info_get(sdata, next_hop);
  716. if (!sta) {
  717. rcu_read_unlock();
  718. return -ENOENT;
  719. }
  720. mpath = mesh_path_lookup(dst, sdata);
  721. if (!mpath) {
  722. rcu_read_unlock();
  723. return -ENOENT;
  724. }
  725. mesh_path_fix_nexthop(mpath, sta);
  726. rcu_read_unlock();
  727. return 0;
  728. }
  729. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  730. struct mpath_info *pinfo)
  731. {
  732. if (mpath->next_hop)
  733. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  734. else
  735. memset(next_hop, 0, ETH_ALEN);
  736. pinfo->generation = mesh_paths_generation;
  737. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  738. MPATH_INFO_SN |
  739. MPATH_INFO_METRIC |
  740. MPATH_INFO_EXPTIME |
  741. MPATH_INFO_DISCOVERY_TIMEOUT |
  742. MPATH_INFO_DISCOVERY_RETRIES |
  743. MPATH_INFO_FLAGS;
  744. pinfo->frame_qlen = mpath->frame_queue.qlen;
  745. pinfo->sn = mpath->sn;
  746. pinfo->metric = mpath->metric;
  747. if (time_before(jiffies, mpath->exp_time))
  748. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  749. pinfo->discovery_timeout =
  750. jiffies_to_msecs(mpath->discovery_timeout);
  751. pinfo->discovery_retries = mpath->discovery_retries;
  752. pinfo->flags = 0;
  753. if (mpath->flags & MESH_PATH_ACTIVE)
  754. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  755. if (mpath->flags & MESH_PATH_RESOLVING)
  756. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  757. if (mpath->flags & MESH_PATH_SN_VALID)
  758. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  759. if (mpath->flags & MESH_PATH_FIXED)
  760. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  761. if (mpath->flags & MESH_PATH_RESOLVING)
  762. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  763. pinfo->flags = mpath->flags;
  764. }
  765. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  766. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  767. {
  768. struct ieee80211_sub_if_data *sdata;
  769. struct mesh_path *mpath;
  770. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  771. rcu_read_lock();
  772. mpath = mesh_path_lookup(dst, sdata);
  773. if (!mpath) {
  774. rcu_read_unlock();
  775. return -ENOENT;
  776. }
  777. memcpy(dst, mpath->dst, ETH_ALEN);
  778. mpath_set_pinfo(mpath, next_hop, pinfo);
  779. rcu_read_unlock();
  780. return 0;
  781. }
  782. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  783. int idx, u8 *dst, u8 *next_hop,
  784. struct mpath_info *pinfo)
  785. {
  786. struct ieee80211_sub_if_data *sdata;
  787. struct mesh_path *mpath;
  788. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  789. rcu_read_lock();
  790. mpath = mesh_path_lookup_by_idx(idx, sdata);
  791. if (!mpath) {
  792. rcu_read_unlock();
  793. return -ENOENT;
  794. }
  795. memcpy(dst, mpath->dst, ETH_ALEN);
  796. mpath_set_pinfo(mpath, next_hop, pinfo);
  797. rcu_read_unlock();
  798. return 0;
  799. }
  800. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  801. struct net_device *dev,
  802. struct mesh_config *conf)
  803. {
  804. struct ieee80211_sub_if_data *sdata;
  805. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  806. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  807. return 0;
  808. }
  809. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  810. {
  811. return (mask >> (parm-1)) & 0x1;
  812. }
  813. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  814. struct net_device *dev,
  815. const struct mesh_config *nconf, u32 mask)
  816. {
  817. struct mesh_config *conf;
  818. struct ieee80211_sub_if_data *sdata;
  819. struct ieee80211_if_mesh *ifmsh;
  820. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  821. ifmsh = &sdata->u.mesh;
  822. /* Set the config options which we are interested in setting */
  823. conf = &(sdata->u.mesh.mshcfg);
  824. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  825. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  826. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  827. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  828. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  829. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  830. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  831. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  832. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  833. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  834. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  835. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  836. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  837. conf->auto_open_plinks = nconf->auto_open_plinks;
  838. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  839. conf->dot11MeshHWMPmaxPREQretries =
  840. nconf->dot11MeshHWMPmaxPREQretries;
  841. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  842. conf->path_refresh_time = nconf->path_refresh_time;
  843. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  844. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  845. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  846. conf->dot11MeshHWMPactivePathTimeout =
  847. nconf->dot11MeshHWMPactivePathTimeout;
  848. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  849. conf->dot11MeshHWMPpreqMinInterval =
  850. nconf->dot11MeshHWMPpreqMinInterval;
  851. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  852. mask))
  853. conf->dot11MeshHWMPnetDiameterTraversalTime =
  854. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  855. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
  856. conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
  857. ieee80211_mesh_root_setup(ifmsh);
  858. }
  859. return 0;
  860. }
  861. #endif
  862. static int ieee80211_change_bss(struct wiphy *wiphy,
  863. struct net_device *dev,
  864. struct bss_parameters *params)
  865. {
  866. struct ieee80211_sub_if_data *sdata;
  867. u32 changed = 0;
  868. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  869. if (params->use_cts_prot >= 0) {
  870. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  871. changed |= BSS_CHANGED_ERP_CTS_PROT;
  872. }
  873. if (params->use_short_preamble >= 0) {
  874. sdata->vif.bss_conf.use_short_preamble =
  875. params->use_short_preamble;
  876. changed |= BSS_CHANGED_ERP_PREAMBLE;
  877. }
  878. if (!sdata->vif.bss_conf.use_short_slot &&
  879. sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
  880. sdata->vif.bss_conf.use_short_slot = true;
  881. changed |= BSS_CHANGED_ERP_SLOT;
  882. }
  883. if (params->use_short_slot_time >= 0) {
  884. sdata->vif.bss_conf.use_short_slot =
  885. params->use_short_slot_time;
  886. changed |= BSS_CHANGED_ERP_SLOT;
  887. }
  888. if (params->basic_rates) {
  889. int i, j;
  890. u32 rates = 0;
  891. struct ieee80211_local *local = wiphy_priv(wiphy);
  892. struct ieee80211_supported_band *sband =
  893. wiphy->bands[local->oper_channel->band];
  894. for (i = 0; i < params->basic_rates_len; i++) {
  895. int rate = (params->basic_rates[i] & 0x7f) * 5;
  896. for (j = 0; j < sband->n_bitrates; j++) {
  897. if (sband->bitrates[j].bitrate == rate)
  898. rates |= BIT(j);
  899. }
  900. }
  901. sdata->vif.bss_conf.basic_rates = rates;
  902. changed |= BSS_CHANGED_BASIC_RATES;
  903. }
  904. if (params->ap_isolate >= 0) {
  905. if (params->ap_isolate)
  906. sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  907. else
  908. sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
  909. }
  910. ieee80211_bss_info_change_notify(sdata, changed);
  911. return 0;
  912. }
  913. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  914. struct ieee80211_txq_params *params)
  915. {
  916. struct ieee80211_local *local = wiphy_priv(wiphy);
  917. struct ieee80211_tx_queue_params p;
  918. if (!local->ops->conf_tx)
  919. return -EOPNOTSUPP;
  920. memset(&p, 0, sizeof(p));
  921. p.aifs = params->aifs;
  922. p.cw_max = params->cwmax;
  923. p.cw_min = params->cwmin;
  924. p.txop = params->txop;
  925. /*
  926. * Setting tx queue params disables u-apsd because it's only
  927. * called in master mode.
  928. */
  929. p.uapsd = false;
  930. if (drv_conf_tx(local, params->queue, &p)) {
  931. printk(KERN_DEBUG "%s: failed to set TX queue "
  932. "parameters for queue %d\n",
  933. wiphy_name(local->hw.wiphy), params->queue);
  934. return -EINVAL;
  935. }
  936. return 0;
  937. }
  938. static int ieee80211_set_channel(struct wiphy *wiphy,
  939. struct net_device *netdev,
  940. struct ieee80211_channel *chan,
  941. enum nl80211_channel_type channel_type)
  942. {
  943. struct ieee80211_local *local = wiphy_priv(wiphy);
  944. struct ieee80211_sub_if_data *sdata = NULL;
  945. if (netdev)
  946. sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
  947. switch (ieee80211_get_channel_mode(local, NULL)) {
  948. case CHAN_MODE_HOPPING:
  949. return -EBUSY;
  950. case CHAN_MODE_FIXED:
  951. if (local->oper_channel != chan)
  952. return -EBUSY;
  953. if (!sdata && local->_oper_channel_type == channel_type)
  954. return 0;
  955. break;
  956. case CHAN_MODE_UNDEFINED:
  957. break;
  958. }
  959. local->oper_channel = chan;
  960. if (!ieee80211_set_channel_type(local, sdata, channel_type))
  961. return -EBUSY;
  962. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  963. if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
  964. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
  965. return 0;
  966. }
  967. #ifdef CONFIG_PM
  968. static int ieee80211_suspend(struct wiphy *wiphy)
  969. {
  970. return __ieee80211_suspend(wiphy_priv(wiphy));
  971. }
  972. static int ieee80211_resume(struct wiphy *wiphy)
  973. {
  974. return __ieee80211_resume(wiphy_priv(wiphy));
  975. }
  976. #else
  977. #define ieee80211_suspend NULL
  978. #define ieee80211_resume NULL
  979. #endif
  980. static int ieee80211_scan(struct wiphy *wiphy,
  981. struct net_device *dev,
  982. struct cfg80211_scan_request *req)
  983. {
  984. struct ieee80211_sub_if_data *sdata;
  985. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  986. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  987. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  988. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  989. (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
  990. return -EOPNOTSUPP;
  991. return ieee80211_request_scan(sdata, req);
  992. }
  993. static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
  994. struct cfg80211_auth_request *req)
  995. {
  996. return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
  997. }
  998. static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
  999. struct cfg80211_assoc_request *req)
  1000. {
  1001. struct ieee80211_local *local = wiphy_priv(wiphy);
  1002. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1003. switch (ieee80211_get_channel_mode(local, sdata)) {
  1004. case CHAN_MODE_HOPPING:
  1005. return -EBUSY;
  1006. case CHAN_MODE_FIXED:
  1007. if (local->oper_channel == req->bss->channel)
  1008. break;
  1009. return -EBUSY;
  1010. case CHAN_MODE_UNDEFINED:
  1011. break;
  1012. }
  1013. return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
  1014. }
  1015. static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
  1016. struct cfg80211_deauth_request *req,
  1017. void *cookie)
  1018. {
  1019. return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
  1020. req, cookie);
  1021. }
  1022. static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
  1023. struct cfg80211_disassoc_request *req,
  1024. void *cookie)
  1025. {
  1026. return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
  1027. req, cookie);
  1028. }
  1029. static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
  1030. struct cfg80211_ibss_params *params)
  1031. {
  1032. struct ieee80211_local *local = wiphy_priv(wiphy);
  1033. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1034. switch (ieee80211_get_channel_mode(local, sdata)) {
  1035. case CHAN_MODE_HOPPING:
  1036. return -EBUSY;
  1037. case CHAN_MODE_FIXED:
  1038. if (!params->channel_fixed)
  1039. return -EBUSY;
  1040. if (local->oper_channel == params->channel)
  1041. break;
  1042. return -EBUSY;
  1043. case CHAN_MODE_UNDEFINED:
  1044. break;
  1045. }
  1046. return ieee80211_ibss_join(sdata, params);
  1047. }
  1048. static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
  1049. {
  1050. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1051. return ieee80211_ibss_leave(sdata);
  1052. }
  1053. static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1054. {
  1055. struct ieee80211_local *local = wiphy_priv(wiphy);
  1056. int err;
  1057. if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
  1058. err = drv_set_coverage_class(local, wiphy->coverage_class);
  1059. if (err)
  1060. return err;
  1061. }
  1062. if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
  1063. err = drv_set_rts_threshold(local, wiphy->rts_threshold);
  1064. if (err)
  1065. return err;
  1066. }
  1067. if (changed & WIPHY_PARAM_RETRY_SHORT)
  1068. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  1069. if (changed & WIPHY_PARAM_RETRY_LONG)
  1070. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  1071. if (changed &
  1072. (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
  1073. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  1074. return 0;
  1075. }
  1076. static int ieee80211_set_tx_power(struct wiphy *wiphy,
  1077. enum nl80211_tx_power_setting type, int mbm)
  1078. {
  1079. struct ieee80211_local *local = wiphy_priv(wiphy);
  1080. struct ieee80211_channel *chan = local->hw.conf.channel;
  1081. u32 changes = 0;
  1082. switch (type) {
  1083. case NL80211_TX_POWER_AUTOMATIC:
  1084. local->user_power_level = -1;
  1085. break;
  1086. case NL80211_TX_POWER_LIMITED:
  1087. if (mbm < 0 || (mbm % 100))
  1088. return -EOPNOTSUPP;
  1089. local->user_power_level = MBM_TO_DBM(mbm);
  1090. break;
  1091. case NL80211_TX_POWER_FIXED:
  1092. if (mbm < 0 || (mbm % 100))
  1093. return -EOPNOTSUPP;
  1094. /* TODO: move to cfg80211 when it knows the channel */
  1095. if (MBM_TO_DBM(mbm) > chan->max_power)
  1096. return -EINVAL;
  1097. local->user_power_level = MBM_TO_DBM(mbm);
  1098. break;
  1099. }
  1100. ieee80211_hw_config(local, changes);
  1101. return 0;
  1102. }
  1103. static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
  1104. {
  1105. struct ieee80211_local *local = wiphy_priv(wiphy);
  1106. *dbm = local->hw.conf.power_level;
  1107. return 0;
  1108. }
  1109. static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
  1110. u8 *addr)
  1111. {
  1112. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1113. memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
  1114. return 0;
  1115. }
  1116. static void ieee80211_rfkill_poll(struct wiphy *wiphy)
  1117. {
  1118. struct ieee80211_local *local = wiphy_priv(wiphy);
  1119. drv_rfkill_poll(local);
  1120. }
  1121. #ifdef CONFIG_NL80211_TESTMODE
  1122. static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
  1123. {
  1124. struct ieee80211_local *local = wiphy_priv(wiphy);
  1125. if (!local->ops->testmode_cmd)
  1126. return -EOPNOTSUPP;
  1127. return local->ops->testmode_cmd(&local->hw, data, len);
  1128. }
  1129. #endif
  1130. int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
  1131. enum ieee80211_smps_mode smps_mode)
  1132. {
  1133. const u8 *ap;
  1134. enum ieee80211_smps_mode old_req;
  1135. int err;
  1136. old_req = sdata->u.mgd.req_smps;
  1137. sdata->u.mgd.req_smps = smps_mode;
  1138. if (old_req == smps_mode &&
  1139. smps_mode != IEEE80211_SMPS_AUTOMATIC)
  1140. return 0;
  1141. /*
  1142. * If not associated, or current association is not an HT
  1143. * association, there's no need to send an action frame.
  1144. */
  1145. if (!sdata->u.mgd.associated ||
  1146. sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
  1147. mutex_lock(&sdata->local->iflist_mtx);
  1148. ieee80211_recalc_smps(sdata->local, sdata);
  1149. mutex_unlock(&sdata->local->iflist_mtx);
  1150. return 0;
  1151. }
  1152. ap = sdata->u.mgd.associated->bssid;
  1153. if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
  1154. if (sdata->u.mgd.powersave)
  1155. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1156. else
  1157. smps_mode = IEEE80211_SMPS_OFF;
  1158. }
  1159. /* send SM PS frame to AP */
  1160. err = ieee80211_send_smps_action(sdata, smps_mode,
  1161. ap, ap);
  1162. if (err)
  1163. sdata->u.mgd.req_smps = old_req;
  1164. return err;
  1165. }
  1166. static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  1167. bool enabled, int timeout)
  1168. {
  1169. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1170. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1171. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1172. return -EOPNOTSUPP;
  1173. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  1174. return -EOPNOTSUPP;
  1175. if (enabled == sdata->u.mgd.powersave &&
  1176. timeout == local->dynamic_ps_forced_timeout)
  1177. return 0;
  1178. sdata->u.mgd.powersave = enabled;
  1179. local->dynamic_ps_forced_timeout = timeout;
  1180. /* no change, but if automatic follow powersave */
  1181. mutex_lock(&sdata->u.mgd.mtx);
  1182. __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
  1183. mutex_unlock(&sdata->u.mgd.mtx);
  1184. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  1185. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1186. ieee80211_recalc_ps(local, -1);
  1187. return 0;
  1188. }
  1189. static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
  1190. struct net_device *dev,
  1191. s32 rssi_thold, u32 rssi_hyst)
  1192. {
  1193. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1194. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1195. struct ieee80211_vif *vif = &sdata->vif;
  1196. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  1197. if (rssi_thold == bss_conf->cqm_rssi_thold &&
  1198. rssi_hyst == bss_conf->cqm_rssi_hyst)
  1199. return 0;
  1200. bss_conf->cqm_rssi_thold = rssi_thold;
  1201. bss_conf->cqm_rssi_hyst = rssi_hyst;
  1202. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
  1203. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1204. return -EOPNOTSUPP;
  1205. return 0;
  1206. }
  1207. /* tell the driver upon association, unless already associated */
  1208. if (sdata->u.mgd.associated)
  1209. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
  1210. return 0;
  1211. }
  1212. static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
  1213. struct net_device *dev,
  1214. const u8 *addr,
  1215. const struct cfg80211_bitrate_mask *mask)
  1216. {
  1217. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1218. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1219. int i;
  1220. /*
  1221. * This _could_ be supported by providing a hook for
  1222. * drivers for this function, but at this point it
  1223. * doesn't seem worth bothering.
  1224. */
  1225. if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
  1226. return -EOPNOTSUPP;
  1227. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  1228. sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
  1229. return 0;
  1230. }
  1231. static int ieee80211_remain_on_channel(struct wiphy *wiphy,
  1232. struct net_device *dev,
  1233. struct ieee80211_channel *chan,
  1234. enum nl80211_channel_type channel_type,
  1235. unsigned int duration,
  1236. u64 *cookie)
  1237. {
  1238. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1239. return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
  1240. duration, cookie);
  1241. }
  1242. static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
  1243. struct net_device *dev,
  1244. u64 cookie)
  1245. {
  1246. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1247. return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
  1248. }
  1249. static int ieee80211_action(struct wiphy *wiphy, struct net_device *dev,
  1250. struct ieee80211_channel *chan,
  1251. enum nl80211_channel_type channel_type,
  1252. bool channel_type_valid,
  1253. const u8 *buf, size_t len, u64 *cookie)
  1254. {
  1255. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1256. struct ieee80211_local *local = sdata->local;
  1257. struct sk_buff *skb;
  1258. struct sta_info *sta;
  1259. const struct ieee80211_mgmt *mgmt = (void *)buf;
  1260. u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  1261. IEEE80211_TX_CTL_REQ_TX_STATUS;
  1262. /* Check that we are on the requested channel for transmission */
  1263. if (chan != local->tmp_channel &&
  1264. chan != local->oper_channel)
  1265. return -EBUSY;
  1266. if (channel_type_valid &&
  1267. (channel_type != local->tmp_channel_type &&
  1268. channel_type != local->_oper_channel_type))
  1269. return -EBUSY;
  1270. switch (sdata->vif.type) {
  1271. case NL80211_IFTYPE_ADHOC:
  1272. if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
  1273. break;
  1274. rcu_read_lock();
  1275. sta = sta_info_get(sdata, mgmt->da);
  1276. rcu_read_unlock();
  1277. if (!sta)
  1278. return -ENOLINK;
  1279. break;
  1280. case NL80211_IFTYPE_STATION:
  1281. if (!(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED))
  1282. flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1283. break;
  1284. default:
  1285. return -EOPNOTSUPP;
  1286. }
  1287. skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
  1288. if (!skb)
  1289. return -ENOMEM;
  1290. skb_reserve(skb, local->hw.extra_tx_headroom);
  1291. memcpy(skb_put(skb, len), buf, len);
  1292. IEEE80211_SKB_CB(skb)->flags = flags;
  1293. skb->dev = sdata->dev;
  1294. ieee80211_tx_skb(sdata, skb);
  1295. *cookie = (unsigned long) skb;
  1296. return 0;
  1297. }
  1298. struct cfg80211_ops mac80211_config_ops = {
  1299. .add_virtual_intf = ieee80211_add_iface,
  1300. .del_virtual_intf = ieee80211_del_iface,
  1301. .change_virtual_intf = ieee80211_change_iface,
  1302. .add_key = ieee80211_add_key,
  1303. .del_key = ieee80211_del_key,
  1304. .get_key = ieee80211_get_key,
  1305. .set_default_key = ieee80211_config_default_key,
  1306. .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
  1307. .add_beacon = ieee80211_add_beacon,
  1308. .set_beacon = ieee80211_set_beacon,
  1309. .del_beacon = ieee80211_del_beacon,
  1310. .add_station = ieee80211_add_station,
  1311. .del_station = ieee80211_del_station,
  1312. .change_station = ieee80211_change_station,
  1313. .get_station = ieee80211_get_station,
  1314. .dump_station = ieee80211_dump_station,
  1315. .dump_survey = ieee80211_dump_survey,
  1316. #ifdef CONFIG_MAC80211_MESH
  1317. .add_mpath = ieee80211_add_mpath,
  1318. .del_mpath = ieee80211_del_mpath,
  1319. .change_mpath = ieee80211_change_mpath,
  1320. .get_mpath = ieee80211_get_mpath,
  1321. .dump_mpath = ieee80211_dump_mpath,
  1322. .set_mesh_params = ieee80211_set_mesh_params,
  1323. .get_mesh_params = ieee80211_get_mesh_params,
  1324. #endif
  1325. .change_bss = ieee80211_change_bss,
  1326. .set_txq_params = ieee80211_set_txq_params,
  1327. .set_channel = ieee80211_set_channel,
  1328. .suspend = ieee80211_suspend,
  1329. .resume = ieee80211_resume,
  1330. .scan = ieee80211_scan,
  1331. .auth = ieee80211_auth,
  1332. .assoc = ieee80211_assoc,
  1333. .deauth = ieee80211_deauth,
  1334. .disassoc = ieee80211_disassoc,
  1335. .join_ibss = ieee80211_join_ibss,
  1336. .leave_ibss = ieee80211_leave_ibss,
  1337. .set_wiphy_params = ieee80211_set_wiphy_params,
  1338. .set_tx_power = ieee80211_set_tx_power,
  1339. .get_tx_power = ieee80211_get_tx_power,
  1340. .set_wds_peer = ieee80211_set_wds_peer,
  1341. .rfkill_poll = ieee80211_rfkill_poll,
  1342. CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
  1343. .set_power_mgmt = ieee80211_set_power_mgmt,
  1344. .set_bitrate_mask = ieee80211_set_bitrate_mask,
  1345. .remain_on_channel = ieee80211_remain_on_channel,
  1346. .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
  1347. .action = ieee80211_action,
  1348. .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
  1349. };