cfg.c 22 KB

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