cfg.c 23 KB

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