cfg.c 23 KB

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