cfg.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /*
  2. * mac80211 configuration hooks for cfg80211
  3. *
  4. * Copyright 2006, 2007 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 <net/net_namespace.h>
  12. #include <linux/rcupdate.h>
  13. #include <net/cfg80211.h>
  14. #include "ieee80211_i.h"
  15. #include "cfg.h"
  16. #include "rate.h"
  17. #include "mesh.h"
  18. static bool nl80211_type_check(enum nl80211_iftype type)
  19. {
  20. switch (type) {
  21. case NL80211_IFTYPE_ADHOC:
  22. case NL80211_IFTYPE_STATION:
  23. case NL80211_IFTYPE_MONITOR:
  24. #ifdef CONFIG_MAC80211_MESH
  25. case NL80211_IFTYPE_MESH_POINT:
  26. #endif
  27. case NL80211_IFTYPE_AP:
  28. case NL80211_IFTYPE_AP_VLAN:
  29. case NL80211_IFTYPE_WDS:
  30. return true;
  31. default:
  32. return false;
  33. }
  34. }
  35. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  36. enum nl80211_iftype type, u32 *flags,
  37. struct vif_params *params)
  38. {
  39. struct ieee80211_local *local = wiphy_priv(wiphy);
  40. struct net_device *dev;
  41. struct ieee80211_sub_if_data *sdata;
  42. int err;
  43. if (!nl80211_type_check(type))
  44. return -EINVAL;
  45. err = ieee80211_if_add(local, name, &dev, type, params);
  46. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  47. return err;
  48. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  49. sdata->u.mntr_flags = *flags;
  50. return 0;
  51. }
  52. static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
  53. {
  54. struct net_device *dev;
  55. struct ieee80211_sub_if_data *sdata;
  56. /* we're under RTNL */
  57. dev = __dev_get_by_index(&init_net, ifindex);
  58. if (!dev)
  59. return -ENODEV;
  60. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  61. ieee80211_if_remove(sdata);
  62. return 0;
  63. }
  64. static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
  65. enum nl80211_iftype type, u32 *flags,
  66. struct vif_params *params)
  67. {
  68. struct net_device *dev;
  69. struct ieee80211_sub_if_data *sdata;
  70. int ret;
  71. /* we're under RTNL */
  72. dev = __dev_get_by_index(&init_net, ifindex);
  73. if (!dev)
  74. return -ENODEV;
  75. if (!nl80211_type_check(type))
  76. return -EINVAL;
  77. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  78. ret = ieee80211_if_change_type(sdata, type);
  79. if (ret)
  80. return ret;
  81. if (netif_running(sdata->dev))
  82. return -EBUSY;
  83. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  84. ieee80211_sdata_set_mesh_id(sdata,
  85. params->mesh_id_len,
  86. params->mesh_id);
  87. if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
  88. return 0;
  89. sdata->u.mntr_flags = *flags;
  90. return 0;
  91. }
  92. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  93. u8 key_idx, u8 *mac_addr,
  94. struct key_params *params)
  95. {
  96. struct ieee80211_sub_if_data *sdata;
  97. struct sta_info *sta = NULL;
  98. enum ieee80211_key_alg alg;
  99. struct ieee80211_key *key;
  100. int err;
  101. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  102. switch (params->cipher) {
  103. case WLAN_CIPHER_SUITE_WEP40:
  104. case WLAN_CIPHER_SUITE_WEP104:
  105. alg = ALG_WEP;
  106. break;
  107. case WLAN_CIPHER_SUITE_TKIP:
  108. alg = ALG_TKIP;
  109. break;
  110. case WLAN_CIPHER_SUITE_CCMP:
  111. alg = ALG_CCMP;
  112. break;
  113. default:
  114. return -EINVAL;
  115. }
  116. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
  117. if (!key)
  118. return -ENOMEM;
  119. rcu_read_lock();
  120. if (mac_addr) {
  121. sta = sta_info_get(sdata->local, mac_addr);
  122. if (!sta) {
  123. ieee80211_key_free(key);
  124. err = -ENOENT;
  125. goto out_unlock;
  126. }
  127. }
  128. ieee80211_key_link(key, sdata, sta);
  129. err = 0;
  130. out_unlock:
  131. rcu_read_unlock();
  132. return err;
  133. }
  134. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  135. u8 key_idx, u8 *mac_addr)
  136. {
  137. struct ieee80211_sub_if_data *sdata;
  138. struct sta_info *sta;
  139. int ret;
  140. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  141. rcu_read_lock();
  142. if (mac_addr) {
  143. ret = -ENOENT;
  144. sta = sta_info_get(sdata->local, mac_addr);
  145. if (!sta)
  146. goto out_unlock;
  147. if (sta->key) {
  148. ieee80211_key_free(sta->key);
  149. WARN_ON(sta->key);
  150. ret = 0;
  151. }
  152. goto out_unlock;
  153. }
  154. if (!sdata->keys[key_idx]) {
  155. ret = -ENOENT;
  156. goto out_unlock;
  157. }
  158. ieee80211_key_free(sdata->keys[key_idx]);
  159. WARN_ON(sdata->keys[key_idx]);
  160. ret = 0;
  161. out_unlock:
  162. rcu_read_unlock();
  163. return ret;
  164. }
  165. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  166. u8 key_idx, u8 *mac_addr, void *cookie,
  167. void (*callback)(void *cookie,
  168. struct key_params *params))
  169. {
  170. struct ieee80211_sub_if_data *sdata;
  171. struct sta_info *sta = NULL;
  172. u8 seq[6] = {0};
  173. struct key_params params;
  174. struct ieee80211_key *key;
  175. u32 iv32;
  176. u16 iv16;
  177. int err = -ENOENT;
  178. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  179. rcu_read_lock();
  180. if (mac_addr) {
  181. sta = sta_info_get(sdata->local, mac_addr);
  182. if (!sta)
  183. goto out;
  184. key = sta->key;
  185. } else
  186. key = sdata->keys[key_idx];
  187. if (!key)
  188. goto out;
  189. memset(&params, 0, sizeof(params));
  190. switch (key->conf.alg) {
  191. case ALG_TKIP:
  192. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  193. iv32 = key->u.tkip.tx.iv32;
  194. iv16 = key->u.tkip.tx.iv16;
  195. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  196. sdata->local->ops->get_tkip_seq)
  197. sdata->local->ops->get_tkip_seq(
  198. local_to_hw(sdata->local),
  199. key->conf.hw_key_idx,
  200. &iv32, &iv16);
  201. seq[0] = iv16 & 0xff;
  202. seq[1] = (iv16 >> 8) & 0xff;
  203. seq[2] = iv32 & 0xff;
  204. seq[3] = (iv32 >> 8) & 0xff;
  205. seq[4] = (iv32 >> 16) & 0xff;
  206. seq[5] = (iv32 >> 24) & 0xff;
  207. params.seq = seq;
  208. params.seq_len = 6;
  209. break;
  210. case ALG_CCMP:
  211. params.cipher = WLAN_CIPHER_SUITE_CCMP;
  212. seq[0] = key->u.ccmp.tx_pn[5];
  213. seq[1] = key->u.ccmp.tx_pn[4];
  214. seq[2] = key->u.ccmp.tx_pn[3];
  215. seq[3] = key->u.ccmp.tx_pn[2];
  216. seq[4] = key->u.ccmp.tx_pn[1];
  217. seq[5] = key->u.ccmp.tx_pn[0];
  218. params.seq = seq;
  219. params.seq_len = 6;
  220. break;
  221. case ALG_WEP:
  222. if (key->conf.keylen == 5)
  223. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  224. else
  225. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  226. break;
  227. }
  228. params.key = key->conf.key;
  229. params.key_len = key->conf.keylen;
  230. callback(cookie, &params);
  231. err = 0;
  232. out:
  233. rcu_read_unlock();
  234. return err;
  235. }
  236. static int ieee80211_config_default_key(struct wiphy *wiphy,
  237. struct net_device *dev,
  238. u8 key_idx)
  239. {
  240. struct ieee80211_sub_if_data *sdata;
  241. rcu_read_lock();
  242. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  243. ieee80211_set_default_key(sdata, key_idx);
  244. rcu_read_unlock();
  245. return 0;
  246. }
  247. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  248. {
  249. struct ieee80211_sub_if_data *sdata = sta->sdata;
  250. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  251. STATION_INFO_RX_BYTES |
  252. STATION_INFO_TX_BYTES;
  253. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  254. sinfo->rx_bytes = sta->rx_bytes;
  255. sinfo->tx_bytes = sta->tx_bytes;
  256. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  257. #ifdef CONFIG_MAC80211_MESH
  258. sinfo->filled |= STATION_INFO_LLID |
  259. STATION_INFO_PLID |
  260. STATION_INFO_PLINK_STATE;
  261. sinfo->llid = le16_to_cpu(sta->llid);
  262. sinfo->plid = le16_to_cpu(sta->plid);
  263. sinfo->plink_state = sta->plink_state;
  264. #endif
  265. }
  266. }
  267. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  268. int idx, u8 *mac, struct station_info *sinfo)
  269. {
  270. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  271. struct sta_info *sta;
  272. int ret = -ENOENT;
  273. rcu_read_lock();
  274. sta = sta_info_get_by_idx(local, idx, dev);
  275. if (sta) {
  276. ret = 0;
  277. memcpy(mac, sta->sta.addr, ETH_ALEN);
  278. sta_set_sinfo(sta, sinfo);
  279. }
  280. rcu_read_unlock();
  281. return ret;
  282. }
  283. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  284. u8 *mac, struct station_info *sinfo)
  285. {
  286. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  287. struct sta_info *sta;
  288. int ret = -ENOENT;
  289. rcu_read_lock();
  290. /* XXX: verify sta->dev == dev */
  291. sta = sta_info_get(local, mac);
  292. if (sta) {
  293. ret = 0;
  294. sta_set_sinfo(sta, sinfo);
  295. }
  296. rcu_read_unlock();
  297. return ret;
  298. }
  299. /*
  300. * This handles both adding a beacon and setting new beacon info
  301. */
  302. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  303. struct beacon_parameters *params)
  304. {
  305. struct beacon_data *new, *old;
  306. int new_head_len, new_tail_len;
  307. int size;
  308. int err = -EINVAL;
  309. old = sdata->u.ap.beacon;
  310. /* head must not be zero-length */
  311. if (params->head && !params->head_len)
  312. return -EINVAL;
  313. /*
  314. * This is a kludge. beacon interval should really be part
  315. * of the beacon information.
  316. */
  317. if (params->interval) {
  318. sdata->local->hw.conf.beacon_int = params->interval;
  319. ieee80211_hw_config(sdata->local,
  320. IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
  321. /*
  322. * We updated some parameter so if below bails out
  323. * it's not an error.
  324. */
  325. err = 0;
  326. }
  327. /* Need to have a beacon head if we don't have one yet */
  328. if (!params->head && !old)
  329. return err;
  330. /* sorry, no way to start beaconing without dtim period */
  331. if (!params->dtim_period && !old)
  332. return err;
  333. /* new or old head? */
  334. if (params->head)
  335. new_head_len = params->head_len;
  336. else
  337. new_head_len = old->head_len;
  338. /* new or old tail? */
  339. if (params->tail || !old)
  340. /* params->tail_len will be zero for !params->tail */
  341. new_tail_len = params->tail_len;
  342. else
  343. new_tail_len = old->tail_len;
  344. size = sizeof(*new) + new_head_len + new_tail_len;
  345. new = kzalloc(size, GFP_KERNEL);
  346. if (!new)
  347. return -ENOMEM;
  348. /* start filling the new info now */
  349. /* new or old dtim period? */
  350. if (params->dtim_period)
  351. new->dtim_period = params->dtim_period;
  352. else
  353. new->dtim_period = old->dtim_period;
  354. /*
  355. * pointers go into the block we allocated,
  356. * memory is | beacon_data | head | tail |
  357. */
  358. new->head = ((u8 *) new) + sizeof(*new);
  359. new->tail = new->head + new_head_len;
  360. new->head_len = new_head_len;
  361. new->tail_len = new_tail_len;
  362. /* copy in head */
  363. if (params->head)
  364. memcpy(new->head, params->head, new_head_len);
  365. else
  366. memcpy(new->head, old->head, new_head_len);
  367. /* copy in optional tail */
  368. if (params->tail)
  369. memcpy(new->tail, params->tail, new_tail_len);
  370. else
  371. if (old)
  372. memcpy(new->tail, old->tail, new_tail_len);
  373. rcu_assign_pointer(sdata->u.ap.beacon, new);
  374. synchronize_rcu();
  375. kfree(old);
  376. return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  377. }
  378. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  379. struct beacon_parameters *params)
  380. {
  381. struct ieee80211_sub_if_data *sdata;
  382. struct beacon_data *old;
  383. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  384. if (sdata->vif.type != NL80211_IFTYPE_AP)
  385. return -EINVAL;
  386. old = sdata->u.ap.beacon;
  387. if (old)
  388. return -EALREADY;
  389. return ieee80211_config_beacon(sdata, params);
  390. }
  391. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  392. struct beacon_parameters *params)
  393. {
  394. struct ieee80211_sub_if_data *sdata;
  395. struct beacon_data *old;
  396. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  397. if (sdata->vif.type != NL80211_IFTYPE_AP)
  398. return -EINVAL;
  399. old = sdata->u.ap.beacon;
  400. if (!old)
  401. return -ENOENT;
  402. return ieee80211_config_beacon(sdata, params);
  403. }
  404. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  405. {
  406. struct ieee80211_sub_if_data *sdata;
  407. struct beacon_data *old;
  408. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  409. if (sdata->vif.type != NL80211_IFTYPE_AP)
  410. return -EINVAL;
  411. old = sdata->u.ap.beacon;
  412. if (!old)
  413. return -ENOENT;
  414. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  415. synchronize_rcu();
  416. kfree(old);
  417. return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  418. }
  419. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  420. struct iapp_layer2_update {
  421. u8 da[ETH_ALEN]; /* broadcast */
  422. u8 sa[ETH_ALEN]; /* STA addr */
  423. __be16 len; /* 6 */
  424. u8 dsap; /* 0 */
  425. u8 ssap; /* 0 */
  426. u8 control;
  427. u8 xid_info[3];
  428. } __attribute__ ((packed));
  429. static void ieee80211_send_layer2_update(struct sta_info *sta)
  430. {
  431. struct iapp_layer2_update *msg;
  432. struct sk_buff *skb;
  433. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  434. * bridge devices */
  435. skb = dev_alloc_skb(sizeof(*msg));
  436. if (!skb)
  437. return;
  438. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  439. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  440. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  441. memset(msg->da, 0xff, ETH_ALEN);
  442. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  443. msg->len = htons(6);
  444. msg->dsap = 0;
  445. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  446. msg->control = 0xaf; /* XID response lsb.1111F101.
  447. * F=0 (no poll command; unsolicited frame) */
  448. msg->xid_info[0] = 0x81; /* XID format identifier */
  449. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  450. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  451. skb->dev = sta->sdata->dev;
  452. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  453. memset(skb->cb, 0, sizeof(skb->cb));
  454. netif_rx(skb);
  455. }
  456. static void sta_apply_parameters(struct ieee80211_local *local,
  457. struct sta_info *sta,
  458. struct station_parameters *params)
  459. {
  460. u32 rates;
  461. int i, j;
  462. struct ieee80211_supported_band *sband;
  463. struct ieee80211_sub_if_data *sdata = sta->sdata;
  464. sband = local->hw.wiphy->bands[local->oper_channel->band];
  465. /*
  466. * FIXME: updating the flags is racy when this function is
  467. * called from ieee80211_change_station(), this will
  468. * be resolved in a future patch.
  469. */
  470. if (params->station_flags & STATION_FLAG_CHANGED) {
  471. spin_lock_bh(&sta->lock);
  472. sta->flags &= ~WLAN_STA_AUTHORIZED;
  473. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  474. sta->flags |= WLAN_STA_AUTHORIZED;
  475. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  476. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  477. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  478. sta->flags &= ~WLAN_STA_WME;
  479. if (params->station_flags & STATION_FLAG_WME)
  480. sta->flags |= WLAN_STA_WME;
  481. spin_unlock_bh(&sta->lock);
  482. }
  483. /*
  484. * FIXME: updating the following information is racy when this
  485. * function is called from ieee80211_change_station().
  486. * However, all this information should be static so
  487. * maybe we should just reject attemps to change it.
  488. */
  489. if (params->aid) {
  490. sta->sta.aid = params->aid;
  491. if (sta->sta.aid > IEEE80211_MAX_AID)
  492. sta->sta.aid = 0; /* XXX: should this be an error? */
  493. }
  494. if (params->listen_interval >= 0)
  495. sta->listen_interval = params->listen_interval;
  496. if (params->supported_rates) {
  497. rates = 0;
  498. for (i = 0; i < params->supported_rates_len; i++) {
  499. int rate = (params->supported_rates[i] & 0x7f) * 5;
  500. for (j = 0; j < sband->n_bitrates; j++) {
  501. if (sband->bitrates[j].bitrate == rate)
  502. rates |= BIT(j);
  503. }
  504. }
  505. sta->sta.supp_rates[local->oper_channel->band] = rates;
  506. }
  507. if (params->ht_capa)
  508. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  509. params->ht_capa,
  510. &sta->sta.ht_cap);
  511. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  512. switch (params->plink_action) {
  513. case PLINK_ACTION_OPEN:
  514. mesh_plink_open(sta);
  515. break;
  516. case PLINK_ACTION_BLOCK:
  517. mesh_plink_block(sta);
  518. break;
  519. }
  520. }
  521. }
  522. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  523. u8 *mac, struct station_parameters *params)
  524. {
  525. struct ieee80211_local *local = wiphy_priv(wiphy);
  526. struct sta_info *sta;
  527. struct ieee80211_sub_if_data *sdata;
  528. int err;
  529. /* Prevent a race with changing the rate control algorithm */
  530. if (!netif_running(dev))
  531. return -ENETDOWN;
  532. if (params->vlan) {
  533. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  534. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  535. sdata->vif.type != NL80211_IFTYPE_AP)
  536. return -EINVAL;
  537. } else
  538. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  539. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  540. return -EINVAL;
  541. if (is_multicast_ether_addr(mac))
  542. return -EINVAL;
  543. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  544. if (!sta)
  545. return -ENOMEM;
  546. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  547. sta_apply_parameters(local, sta, params);
  548. rate_control_rate_init(sta);
  549. rcu_read_lock();
  550. err = sta_info_insert(sta);
  551. if (err) {
  552. /* STA has been freed */
  553. rcu_read_unlock();
  554. return err;
  555. }
  556. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  557. sdata->vif.type == NL80211_IFTYPE_AP)
  558. ieee80211_send_layer2_update(sta);
  559. rcu_read_unlock();
  560. return 0;
  561. }
  562. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  563. u8 *mac)
  564. {
  565. struct ieee80211_local *local = wiphy_priv(wiphy);
  566. struct ieee80211_sub_if_data *sdata;
  567. struct sta_info *sta;
  568. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  569. if (mac) {
  570. rcu_read_lock();
  571. /* XXX: get sta belonging to dev */
  572. sta = sta_info_get(local, mac);
  573. if (!sta) {
  574. rcu_read_unlock();
  575. return -ENOENT;
  576. }
  577. sta_info_unlink(&sta);
  578. rcu_read_unlock();
  579. sta_info_destroy(sta);
  580. } else
  581. sta_info_flush(local, sdata);
  582. return 0;
  583. }
  584. static int ieee80211_change_station(struct wiphy *wiphy,
  585. struct net_device *dev,
  586. u8 *mac,
  587. struct station_parameters *params)
  588. {
  589. struct ieee80211_local *local = wiphy_priv(wiphy);
  590. struct sta_info *sta;
  591. struct ieee80211_sub_if_data *vlansdata;
  592. rcu_read_lock();
  593. /* XXX: get sta belonging to dev */
  594. sta = sta_info_get(local, mac);
  595. if (!sta) {
  596. rcu_read_unlock();
  597. return -ENOENT;
  598. }
  599. if (params->vlan && params->vlan != sta->sdata->dev) {
  600. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  601. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  602. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  603. rcu_read_unlock();
  604. return -EINVAL;
  605. }
  606. sta->sdata = vlansdata;
  607. ieee80211_send_layer2_update(sta);
  608. }
  609. sta_apply_parameters(local, sta, params);
  610. rcu_read_unlock();
  611. return 0;
  612. }
  613. #ifdef CONFIG_MAC80211_MESH
  614. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  615. u8 *dst, u8 *next_hop)
  616. {
  617. struct ieee80211_local *local = wiphy_priv(wiphy);
  618. struct ieee80211_sub_if_data *sdata;
  619. struct mesh_path *mpath;
  620. struct sta_info *sta;
  621. int err;
  622. if (!netif_running(dev))
  623. return -ENETDOWN;
  624. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  625. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  626. return -ENOTSUPP;
  627. rcu_read_lock();
  628. sta = sta_info_get(local, next_hop);
  629. if (!sta) {
  630. rcu_read_unlock();
  631. return -ENOENT;
  632. }
  633. err = mesh_path_add(dst, sdata);
  634. if (err) {
  635. rcu_read_unlock();
  636. return err;
  637. }
  638. mpath = mesh_path_lookup(dst, sdata);
  639. if (!mpath) {
  640. rcu_read_unlock();
  641. return -ENXIO;
  642. }
  643. mesh_path_fix_nexthop(mpath, sta);
  644. rcu_read_unlock();
  645. return 0;
  646. }
  647. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  648. u8 *dst)
  649. {
  650. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  651. if (dst)
  652. return mesh_path_del(dst, sdata);
  653. mesh_path_flush(sdata);
  654. return 0;
  655. }
  656. static int ieee80211_change_mpath(struct wiphy *wiphy,
  657. struct net_device *dev,
  658. u8 *dst, u8 *next_hop)
  659. {
  660. struct ieee80211_local *local = wiphy_priv(wiphy);
  661. struct ieee80211_sub_if_data *sdata;
  662. struct mesh_path *mpath;
  663. struct sta_info *sta;
  664. if (!netif_running(dev))
  665. return -ENETDOWN;
  666. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  667. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  668. return -ENOTSUPP;
  669. rcu_read_lock();
  670. sta = sta_info_get(local, next_hop);
  671. if (!sta) {
  672. rcu_read_unlock();
  673. return -ENOENT;
  674. }
  675. mpath = mesh_path_lookup(dst, sdata);
  676. if (!mpath) {
  677. rcu_read_unlock();
  678. return -ENOENT;
  679. }
  680. mesh_path_fix_nexthop(mpath, sta);
  681. rcu_read_unlock();
  682. return 0;
  683. }
  684. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  685. struct mpath_info *pinfo)
  686. {
  687. if (mpath->next_hop)
  688. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  689. else
  690. memset(next_hop, 0, ETH_ALEN);
  691. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  692. MPATH_INFO_DSN |
  693. MPATH_INFO_METRIC |
  694. MPATH_INFO_EXPTIME |
  695. MPATH_INFO_DISCOVERY_TIMEOUT |
  696. MPATH_INFO_DISCOVERY_RETRIES |
  697. MPATH_INFO_FLAGS;
  698. pinfo->frame_qlen = mpath->frame_queue.qlen;
  699. pinfo->dsn = mpath->dsn;
  700. pinfo->metric = mpath->metric;
  701. if (time_before(jiffies, mpath->exp_time))
  702. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  703. pinfo->discovery_timeout =
  704. jiffies_to_msecs(mpath->discovery_timeout);
  705. pinfo->discovery_retries = mpath->discovery_retries;
  706. pinfo->flags = 0;
  707. if (mpath->flags & MESH_PATH_ACTIVE)
  708. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  709. if (mpath->flags & MESH_PATH_RESOLVING)
  710. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  711. if (mpath->flags & MESH_PATH_DSN_VALID)
  712. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  713. if (mpath->flags & MESH_PATH_FIXED)
  714. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  715. if (mpath->flags & MESH_PATH_RESOLVING)
  716. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  717. pinfo->flags = mpath->flags;
  718. }
  719. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  720. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  721. {
  722. struct ieee80211_sub_if_data *sdata;
  723. struct mesh_path *mpath;
  724. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  725. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  726. return -ENOTSUPP;
  727. rcu_read_lock();
  728. mpath = mesh_path_lookup(dst, sdata);
  729. if (!mpath) {
  730. rcu_read_unlock();
  731. return -ENOENT;
  732. }
  733. memcpy(dst, mpath->dst, ETH_ALEN);
  734. mpath_set_pinfo(mpath, next_hop, pinfo);
  735. rcu_read_unlock();
  736. return 0;
  737. }
  738. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  739. int idx, u8 *dst, u8 *next_hop,
  740. struct mpath_info *pinfo)
  741. {
  742. struct ieee80211_sub_if_data *sdata;
  743. struct mesh_path *mpath;
  744. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  745. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  746. return -ENOTSUPP;
  747. rcu_read_lock();
  748. mpath = mesh_path_lookup_by_idx(idx, sdata);
  749. if (!mpath) {
  750. rcu_read_unlock();
  751. return -ENOENT;
  752. }
  753. memcpy(dst, mpath->dst, ETH_ALEN);
  754. mpath_set_pinfo(mpath, next_hop, pinfo);
  755. rcu_read_unlock();
  756. return 0;
  757. }
  758. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  759. struct net_device *dev,
  760. struct mesh_config *conf)
  761. {
  762. struct ieee80211_sub_if_data *sdata;
  763. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  764. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  765. return -ENOTSUPP;
  766. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  767. return 0;
  768. }
  769. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  770. {
  771. return (mask >> (parm-1)) & 0x1;
  772. }
  773. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  774. struct net_device *dev,
  775. const struct mesh_config *nconf, u32 mask)
  776. {
  777. struct mesh_config *conf;
  778. struct ieee80211_sub_if_data *sdata;
  779. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  780. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  781. return -ENOTSUPP;
  782. /* Set the config options which we are interested in setting */
  783. conf = &(sdata->u.mesh.mshcfg);
  784. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  785. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  786. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  787. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  788. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  789. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  790. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  791. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  792. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  793. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  794. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  795. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  796. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  797. conf->auto_open_plinks = nconf->auto_open_plinks;
  798. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  799. conf->dot11MeshHWMPmaxPREQretries =
  800. nconf->dot11MeshHWMPmaxPREQretries;
  801. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  802. conf->path_refresh_time = nconf->path_refresh_time;
  803. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  804. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  805. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  806. conf->dot11MeshHWMPactivePathTimeout =
  807. nconf->dot11MeshHWMPactivePathTimeout;
  808. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  809. conf->dot11MeshHWMPpreqMinInterval =
  810. nconf->dot11MeshHWMPpreqMinInterval;
  811. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  812. mask))
  813. conf->dot11MeshHWMPnetDiameterTraversalTime =
  814. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  815. return 0;
  816. }
  817. #endif
  818. static int ieee80211_change_bss(struct wiphy *wiphy,
  819. struct net_device *dev,
  820. struct bss_parameters *params)
  821. {
  822. struct ieee80211_sub_if_data *sdata;
  823. u32 changed = 0;
  824. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  825. if (sdata->vif.type != NL80211_IFTYPE_AP)
  826. return -EINVAL;
  827. if (params->use_cts_prot >= 0) {
  828. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  829. changed |= BSS_CHANGED_ERP_CTS_PROT;
  830. }
  831. if (params->use_short_preamble >= 0) {
  832. sdata->vif.bss_conf.use_short_preamble =
  833. params->use_short_preamble;
  834. changed |= BSS_CHANGED_ERP_PREAMBLE;
  835. }
  836. if (params->use_short_slot_time >= 0) {
  837. sdata->vif.bss_conf.use_short_slot =
  838. params->use_short_slot_time;
  839. changed |= BSS_CHANGED_ERP_SLOT;
  840. }
  841. if (params->basic_rates) {
  842. int i, j;
  843. u32 rates = 0;
  844. struct ieee80211_local *local = wiphy_priv(wiphy);
  845. struct ieee80211_supported_band *sband =
  846. wiphy->bands[local->oper_channel->band];
  847. for (i = 0; i < params->basic_rates_len; i++) {
  848. int rate = (params->basic_rates[i] & 0x7f) * 5;
  849. for (j = 0; j < sband->n_bitrates; j++) {
  850. if (sband->bitrates[j].bitrate == rate)
  851. rates |= BIT(j);
  852. }
  853. }
  854. sdata->vif.bss_conf.basic_rates = rates;
  855. changed |= BSS_CHANGED_BASIC_RATES;
  856. }
  857. ieee80211_bss_info_change_notify(sdata, changed);
  858. return 0;
  859. }
  860. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  861. struct ieee80211_txq_params *params)
  862. {
  863. struct ieee80211_local *local = wiphy_priv(wiphy);
  864. struct ieee80211_tx_queue_params p;
  865. if (!local->ops->conf_tx)
  866. return -EOPNOTSUPP;
  867. memset(&p, 0, sizeof(p));
  868. p.aifs = params->aifs;
  869. p.cw_max = params->cwmax;
  870. p.cw_min = params->cwmin;
  871. p.txop = params->txop;
  872. if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
  873. printk(KERN_DEBUG "%s: failed to set TX queue "
  874. "parameters for queue %d\n", local->mdev->name,
  875. params->queue);
  876. return -EINVAL;
  877. }
  878. return 0;
  879. }
  880. static int ieee80211_set_channel(struct wiphy *wiphy,
  881. struct ieee80211_channel *chan,
  882. enum nl80211_sec_chan_offset sec_chan_offset)
  883. {
  884. struct ieee80211_local *local = wiphy_priv(wiphy);
  885. local->oper_channel = chan;
  886. local->oper_sec_chan_offset = sec_chan_offset;
  887. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  888. }
  889. struct cfg80211_ops mac80211_config_ops = {
  890. .add_virtual_intf = ieee80211_add_iface,
  891. .del_virtual_intf = ieee80211_del_iface,
  892. .change_virtual_intf = ieee80211_change_iface,
  893. .add_key = ieee80211_add_key,
  894. .del_key = ieee80211_del_key,
  895. .get_key = ieee80211_get_key,
  896. .set_default_key = ieee80211_config_default_key,
  897. .add_beacon = ieee80211_add_beacon,
  898. .set_beacon = ieee80211_set_beacon,
  899. .del_beacon = ieee80211_del_beacon,
  900. .add_station = ieee80211_add_station,
  901. .del_station = ieee80211_del_station,
  902. .change_station = ieee80211_change_station,
  903. .get_station = ieee80211_get_station,
  904. .dump_station = ieee80211_dump_station,
  905. #ifdef CONFIG_MAC80211_MESH
  906. .add_mpath = ieee80211_add_mpath,
  907. .del_mpath = ieee80211_del_mpath,
  908. .change_mpath = ieee80211_change_mpath,
  909. .get_mpath = ieee80211_get_mpath,
  910. .dump_mpath = ieee80211_dump_mpath,
  911. .set_mesh_params = ieee80211_set_mesh_params,
  912. .get_mesh_params = ieee80211_get_mesh_params,
  913. #endif
  914. .change_bss = ieee80211_change_bss,
  915. .set_txq_params = ieee80211_set_txq_params,
  916. .set_channel = ieee80211_set_channel,
  917. };