cfg.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  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 "ieee80211_rate.h"
  17. #include "mesh.h"
  18. static enum ieee80211_if_types
  19. nl80211_type_to_mac80211_type(enum nl80211_iftype type)
  20. {
  21. switch (type) {
  22. case NL80211_IFTYPE_UNSPECIFIED:
  23. return IEEE80211_IF_TYPE_STA;
  24. case NL80211_IFTYPE_ADHOC:
  25. return IEEE80211_IF_TYPE_IBSS;
  26. case NL80211_IFTYPE_STATION:
  27. return IEEE80211_IF_TYPE_STA;
  28. case NL80211_IFTYPE_MONITOR:
  29. return IEEE80211_IF_TYPE_MNTR;
  30. #ifdef CONFIG_MAC80211_MESH
  31. case NL80211_IFTYPE_MESH_POINT:
  32. return IEEE80211_IF_TYPE_MESH_POINT;
  33. #endif
  34. default:
  35. return IEEE80211_IF_TYPE_INVALID;
  36. }
  37. }
  38. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  39. enum nl80211_iftype type, u32 *flags,
  40. struct vif_params *params)
  41. {
  42. struct ieee80211_local *local = wiphy_priv(wiphy);
  43. enum ieee80211_if_types itype;
  44. struct net_device *dev;
  45. struct ieee80211_sub_if_data *sdata;
  46. int err;
  47. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
  48. return -ENODEV;
  49. itype = nl80211_type_to_mac80211_type(type);
  50. if (itype == IEEE80211_IF_TYPE_INVALID)
  51. return -EINVAL;
  52. err = ieee80211_if_add(local->mdev, name, &dev, itype, params);
  53. if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags)
  54. return err;
  55. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  56. sdata->u.mntr_flags = *flags;
  57. return 0;
  58. }
  59. static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
  60. {
  61. struct ieee80211_local *local = wiphy_priv(wiphy);
  62. struct net_device *dev;
  63. char *name;
  64. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
  65. return -ENODEV;
  66. /* we're under RTNL */
  67. dev = __dev_get_by_index(&init_net, ifindex);
  68. if (!dev)
  69. return 0;
  70. name = dev->name;
  71. return ieee80211_if_remove(local->mdev, name, -1);
  72. }
  73. static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
  74. enum nl80211_iftype type, u32 *flags,
  75. struct vif_params *params)
  76. {
  77. struct ieee80211_local *local = wiphy_priv(wiphy);
  78. struct net_device *dev;
  79. enum ieee80211_if_types itype;
  80. struct ieee80211_sub_if_data *sdata;
  81. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
  82. return -ENODEV;
  83. /* we're under RTNL */
  84. dev = __dev_get_by_index(&init_net, ifindex);
  85. if (!dev)
  86. return -ENODEV;
  87. if (netif_running(dev))
  88. return -EBUSY;
  89. itype = nl80211_type_to_mac80211_type(type);
  90. if (itype == IEEE80211_IF_TYPE_INVALID)
  91. return -EINVAL;
  92. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  93. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  94. return -EOPNOTSUPP;
  95. ieee80211_if_reinit(dev);
  96. ieee80211_if_set_type(dev, itype);
  97. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  98. ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
  99. params->mesh_id_len,
  100. params->mesh_id);
  101. if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
  102. return 0;
  103. sdata->u.mntr_flags = *flags;
  104. return 0;
  105. }
  106. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  107. u8 key_idx, u8 *mac_addr,
  108. struct key_params *params)
  109. {
  110. struct ieee80211_sub_if_data *sdata;
  111. struct sta_info *sta = NULL;
  112. enum ieee80211_key_alg alg;
  113. struct ieee80211_key *key;
  114. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  115. switch (params->cipher) {
  116. case WLAN_CIPHER_SUITE_WEP40:
  117. case WLAN_CIPHER_SUITE_WEP104:
  118. alg = ALG_WEP;
  119. break;
  120. case WLAN_CIPHER_SUITE_TKIP:
  121. alg = ALG_TKIP;
  122. break;
  123. case WLAN_CIPHER_SUITE_CCMP:
  124. alg = ALG_CCMP;
  125. break;
  126. default:
  127. return -EINVAL;
  128. }
  129. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
  130. if (!key)
  131. return -ENOMEM;
  132. if (mac_addr) {
  133. sta = sta_info_get(sdata->local, mac_addr);
  134. if (!sta) {
  135. ieee80211_key_free(key);
  136. return -ENOENT;
  137. }
  138. }
  139. ieee80211_key_link(key, sdata, sta);
  140. return 0;
  141. }
  142. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  143. u8 key_idx, u8 *mac_addr)
  144. {
  145. struct ieee80211_sub_if_data *sdata;
  146. struct sta_info *sta;
  147. int ret;
  148. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  149. if (mac_addr) {
  150. sta = sta_info_get(sdata->local, mac_addr);
  151. if (!sta)
  152. return -ENOENT;
  153. ret = 0;
  154. if (sta->key) {
  155. ieee80211_key_free(sta->key);
  156. WARN_ON(sta->key);
  157. } else
  158. ret = -ENOENT;
  159. return ret;
  160. }
  161. if (!sdata->keys[key_idx])
  162. return -ENOENT;
  163. ieee80211_key_free(sdata->keys[key_idx]);
  164. WARN_ON(sdata->keys[key_idx]);
  165. return 0;
  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 = IEEE80211_DEV_TO_SUB_IF(dev);
  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. 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.iv32;
  194. iv16 = key->u.tkip.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. return err;
  234. }
  235. static int ieee80211_config_default_key(struct wiphy *wiphy,
  236. struct net_device *dev,
  237. u8 key_idx)
  238. {
  239. struct ieee80211_sub_if_data *sdata;
  240. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  241. ieee80211_set_default_key(sdata, key_idx);
  242. return 0;
  243. }
  244. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  245. {
  246. struct ieee80211_sub_if_data *sdata = sta->sdata;
  247. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  248. STATION_INFO_RX_BYTES |
  249. STATION_INFO_TX_BYTES;
  250. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  251. sinfo->rx_bytes = sta->rx_bytes;
  252. sinfo->tx_bytes = sta->tx_bytes;
  253. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  254. #ifdef CONFIG_MAC80211_MESH
  255. sinfo->filled |= STATION_INFO_LLID |
  256. STATION_INFO_PLID |
  257. STATION_INFO_PLINK_STATE;
  258. sinfo->llid = le16_to_cpu(sta->llid);
  259. sinfo->plid = le16_to_cpu(sta->plid);
  260. sinfo->plink_state = sta->plink_state;
  261. #endif
  262. }
  263. }
  264. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  265. int idx, u8 *mac, struct station_info *sinfo)
  266. {
  267. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  268. struct sta_info *sta;
  269. int ret = -ENOENT;
  270. rcu_read_lock();
  271. sta = sta_info_get_by_idx(local, idx, dev);
  272. if (sta) {
  273. ret = 0;
  274. memcpy(mac, sta->addr, ETH_ALEN);
  275. sta_set_sinfo(sta, sinfo);
  276. }
  277. rcu_read_unlock();
  278. return ret;
  279. }
  280. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  281. u8 *mac, struct station_info *sinfo)
  282. {
  283. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  284. struct sta_info *sta;
  285. int ret = -ENOENT;
  286. rcu_read_lock();
  287. /* XXX: verify sta->dev == dev */
  288. sta = sta_info_get(local, mac);
  289. if (sta) {
  290. ret = 0;
  291. sta_set_sinfo(sta, sinfo);
  292. }
  293. rcu_read_unlock();
  294. return ret;
  295. }
  296. /*
  297. * This handles both adding a beacon and setting new beacon info
  298. */
  299. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  300. struct beacon_parameters *params)
  301. {
  302. struct beacon_data *new, *old;
  303. int new_head_len, new_tail_len;
  304. int size;
  305. int err = -EINVAL;
  306. old = sdata->u.ap.beacon;
  307. /* head must not be zero-length */
  308. if (params->head && !params->head_len)
  309. return -EINVAL;
  310. /*
  311. * This is a kludge. beacon interval should really be part
  312. * of the beacon information.
  313. */
  314. if (params->interval) {
  315. sdata->local->hw.conf.beacon_int = params->interval;
  316. if (ieee80211_hw_config(sdata->local))
  317. return -EINVAL;
  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_beacon(sdata->dev);
  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 = IEEE80211_DEV_TO_SUB_IF(dev);
  379. struct beacon_data *old;
  380. if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
  381. return -EINVAL;
  382. old = sdata->u.ap.beacon;
  383. if (old)
  384. return -EALREADY;
  385. return ieee80211_config_beacon(sdata, params);
  386. }
  387. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  388. struct beacon_parameters *params)
  389. {
  390. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  391. struct beacon_data *old;
  392. if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
  393. return -EINVAL;
  394. old = sdata->u.ap.beacon;
  395. if (!old)
  396. return -ENOENT;
  397. return ieee80211_config_beacon(sdata, params);
  398. }
  399. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  400. {
  401. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  402. struct beacon_data *old;
  403. if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
  404. return -EINVAL;
  405. old = sdata->u.ap.beacon;
  406. if (!old)
  407. return -ENOENT;
  408. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  409. synchronize_rcu();
  410. kfree(old);
  411. return ieee80211_if_config_beacon(dev);
  412. }
  413. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  414. struct iapp_layer2_update {
  415. u8 da[ETH_ALEN]; /* broadcast */
  416. u8 sa[ETH_ALEN]; /* STA addr */
  417. __be16 len; /* 6 */
  418. u8 dsap; /* 0 */
  419. u8 ssap; /* 0 */
  420. u8 control;
  421. u8 xid_info[3];
  422. } __attribute__ ((packed));
  423. static void ieee80211_send_layer2_update(struct sta_info *sta)
  424. {
  425. struct iapp_layer2_update *msg;
  426. struct sk_buff *skb;
  427. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  428. * bridge devices */
  429. skb = dev_alloc_skb(sizeof(*msg));
  430. if (!skb)
  431. return;
  432. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  433. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  434. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  435. memset(msg->da, 0xff, ETH_ALEN);
  436. memcpy(msg->sa, sta->addr, ETH_ALEN);
  437. msg->len = htons(6);
  438. msg->dsap = 0;
  439. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  440. msg->control = 0xaf; /* XID response lsb.1111F101.
  441. * F=0 (no poll command; unsolicited frame) */
  442. msg->xid_info[0] = 0x81; /* XID format identifier */
  443. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  444. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  445. skb->dev = sta->sdata->dev;
  446. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  447. memset(skb->cb, 0, sizeof(skb->cb));
  448. netif_rx(skb);
  449. }
  450. static void sta_apply_parameters(struct ieee80211_local *local,
  451. struct sta_info *sta,
  452. struct station_parameters *params)
  453. {
  454. u32 rates;
  455. int i, j;
  456. struct ieee80211_supported_band *sband;
  457. struct ieee80211_sub_if_data *sdata = sta->sdata;
  458. /*
  459. * FIXME: updating the flags is racy when this function is
  460. * called from ieee80211_change_station(), this will
  461. * be resolved in a future patch.
  462. */
  463. if (params->station_flags & STATION_FLAG_CHANGED) {
  464. sta->flags &= ~WLAN_STA_AUTHORIZED;
  465. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  466. sta->flags |= WLAN_STA_AUTHORIZED;
  467. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  468. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  469. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  470. sta->flags &= ~WLAN_STA_WME;
  471. if (params->station_flags & STATION_FLAG_WME)
  472. sta->flags |= WLAN_STA_WME;
  473. }
  474. /*
  475. * FIXME: updating the following information is racy when this
  476. * function is called from ieee80211_change_station().
  477. * However, all this information should be static so
  478. * maybe we should just reject attemps to change it.
  479. */
  480. if (params->aid) {
  481. sta->aid = params->aid;
  482. if (sta->aid > IEEE80211_MAX_AID)
  483. sta->aid = 0; /* XXX: should this be an error? */
  484. }
  485. if (params->listen_interval >= 0)
  486. sta->listen_interval = params->listen_interval;
  487. if (params->supported_rates) {
  488. rates = 0;
  489. sband = local->hw.wiphy->bands[local->oper_channel->band];
  490. for (i = 0; i < params->supported_rates_len; i++) {
  491. int rate = (params->supported_rates[i] & 0x7f) * 5;
  492. for (j = 0; j < sband->n_bitrates; j++) {
  493. if (sband->bitrates[j].bitrate == rate)
  494. rates |= BIT(j);
  495. }
  496. }
  497. sta->supp_rates[local->oper_channel->band] = rates;
  498. }
  499. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  500. switch (params->plink_action) {
  501. case PLINK_ACTION_OPEN:
  502. mesh_plink_open(sta);
  503. break;
  504. case PLINK_ACTION_BLOCK:
  505. mesh_plink_block(sta);
  506. break;
  507. }
  508. }
  509. }
  510. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  511. u8 *mac, struct station_parameters *params)
  512. {
  513. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  514. struct sta_info *sta;
  515. struct ieee80211_sub_if_data *sdata;
  516. int err;
  517. /* Prevent a race with changing the rate control algorithm */
  518. if (!netif_running(dev))
  519. return -ENETDOWN;
  520. if (params->vlan) {
  521. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  522. if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
  523. sdata->vif.type != IEEE80211_IF_TYPE_AP)
  524. return -EINVAL;
  525. } else
  526. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  527. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  528. return -EINVAL;
  529. if (is_multicast_ether_addr(mac))
  530. return -EINVAL;
  531. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  532. if (!sta)
  533. return -ENOMEM;
  534. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  535. sta_apply_parameters(local, sta, params);
  536. rate_control_rate_init(sta, local);
  537. rcu_read_lock();
  538. err = sta_info_insert(sta);
  539. if (err) {
  540. sta_info_destroy(sta);
  541. rcu_read_unlock();
  542. return err;
  543. }
  544. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
  545. sdata->vif.type == IEEE80211_IF_TYPE_AP)
  546. ieee80211_send_layer2_update(sta);
  547. rcu_read_unlock();
  548. return 0;
  549. }
  550. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  551. u8 *mac)
  552. {
  553. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  554. struct ieee80211_local *local = sdata->local;
  555. struct sta_info *sta;
  556. if (mac) {
  557. /* XXX: get sta belonging to dev */
  558. sta = sta_info_get(local, mac);
  559. if (!sta)
  560. return -ENOENT;
  561. sta_info_unlink(&sta);
  562. if (sta) {
  563. synchronize_rcu();
  564. sta_info_destroy(sta);
  565. }
  566. } else
  567. sta_info_flush(local, sdata);
  568. return 0;
  569. }
  570. static int ieee80211_change_station(struct wiphy *wiphy,
  571. struct net_device *dev,
  572. u8 *mac,
  573. struct station_parameters *params)
  574. {
  575. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  576. struct sta_info *sta;
  577. struct ieee80211_sub_if_data *vlansdata;
  578. /* XXX: get sta belonging to dev */
  579. sta = sta_info_get(local, mac);
  580. if (!sta)
  581. return -ENOENT;
  582. if (params->vlan && params->vlan != sta->sdata->dev) {
  583. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  584. if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
  585. vlansdata->vif.type != IEEE80211_IF_TYPE_AP)
  586. return -EINVAL;
  587. sta->sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  588. ieee80211_send_layer2_update(sta);
  589. }
  590. sta_apply_parameters(local, sta, params);
  591. return 0;
  592. }
  593. #ifdef CONFIG_MAC80211_MESH
  594. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  595. u8 *dst, u8 *next_hop)
  596. {
  597. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  598. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  599. struct mesh_path *mpath;
  600. struct sta_info *sta;
  601. int err;
  602. if (!netif_running(dev))
  603. return -ENETDOWN;
  604. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  605. return -ENOTSUPP;
  606. rcu_read_lock();
  607. sta = sta_info_get(local, next_hop);
  608. if (!sta) {
  609. rcu_read_unlock();
  610. return -ENOENT;
  611. }
  612. err = mesh_path_add(dst, dev);
  613. if (err) {
  614. rcu_read_unlock();
  615. return err;
  616. }
  617. mpath = mesh_path_lookup(dst, dev);
  618. if (!mpath) {
  619. rcu_read_unlock();
  620. return -ENXIO;
  621. }
  622. mesh_path_fix_nexthop(mpath, sta);
  623. rcu_read_unlock();
  624. return 0;
  625. }
  626. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  627. u8 *dst)
  628. {
  629. if (dst)
  630. return mesh_path_del(dst, dev);
  631. mesh_path_flush(dev);
  632. return 0;
  633. }
  634. static int ieee80211_change_mpath(struct wiphy *wiphy,
  635. struct net_device *dev,
  636. u8 *dst, u8 *next_hop)
  637. {
  638. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  639. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  640. struct mesh_path *mpath;
  641. struct sta_info *sta;
  642. if (!netif_running(dev))
  643. return -ENETDOWN;
  644. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  645. return -ENOTSUPP;
  646. rcu_read_lock();
  647. sta = sta_info_get(local, next_hop);
  648. if (!sta) {
  649. rcu_read_unlock();
  650. return -ENOENT;
  651. }
  652. mpath = mesh_path_lookup(dst, dev);
  653. if (!mpath) {
  654. rcu_read_unlock();
  655. return -ENOENT;
  656. }
  657. mesh_path_fix_nexthop(mpath, sta);
  658. rcu_read_unlock();
  659. return 0;
  660. }
  661. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  662. struct mpath_info *pinfo)
  663. {
  664. if (mpath->next_hop)
  665. memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
  666. else
  667. memset(next_hop, 0, ETH_ALEN);
  668. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  669. MPATH_INFO_DSN |
  670. MPATH_INFO_METRIC |
  671. MPATH_INFO_EXPTIME |
  672. MPATH_INFO_DISCOVERY_TIMEOUT |
  673. MPATH_INFO_DISCOVERY_RETRIES |
  674. MPATH_INFO_FLAGS;
  675. pinfo->frame_qlen = mpath->frame_queue.qlen;
  676. pinfo->dsn = mpath->dsn;
  677. pinfo->metric = mpath->metric;
  678. if (time_before(jiffies, mpath->exp_time))
  679. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  680. pinfo->discovery_timeout =
  681. jiffies_to_msecs(mpath->discovery_timeout);
  682. pinfo->discovery_retries = mpath->discovery_retries;
  683. pinfo->flags = 0;
  684. if (mpath->flags & MESH_PATH_ACTIVE)
  685. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  686. if (mpath->flags & MESH_PATH_RESOLVING)
  687. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  688. if (mpath->flags & MESH_PATH_DSN_VALID)
  689. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  690. if (mpath->flags & MESH_PATH_FIXED)
  691. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  692. if (mpath->flags & MESH_PATH_RESOLVING)
  693. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  694. pinfo->flags = mpath->flags;
  695. }
  696. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  697. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  698. {
  699. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  700. struct mesh_path *mpath;
  701. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  702. return -ENOTSUPP;
  703. rcu_read_lock();
  704. mpath = mesh_path_lookup(dst, dev);
  705. if (!mpath) {
  706. rcu_read_unlock();
  707. return -ENOENT;
  708. }
  709. memcpy(dst, mpath->dst, ETH_ALEN);
  710. mpath_set_pinfo(mpath, next_hop, pinfo);
  711. rcu_read_unlock();
  712. return 0;
  713. }
  714. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  715. int idx, u8 *dst, u8 *next_hop,
  716. struct mpath_info *pinfo)
  717. {
  718. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  719. struct mesh_path *mpath;
  720. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  721. return -ENOTSUPP;
  722. rcu_read_lock();
  723. mpath = mesh_path_lookup_by_idx(idx, dev);
  724. if (!mpath) {
  725. rcu_read_unlock();
  726. return -ENOENT;
  727. }
  728. memcpy(dst, mpath->dst, ETH_ALEN);
  729. mpath_set_pinfo(mpath, next_hop, pinfo);
  730. rcu_read_unlock();
  731. return 0;
  732. }
  733. #endif
  734. struct cfg80211_ops mac80211_config_ops = {
  735. .add_virtual_intf = ieee80211_add_iface,
  736. .del_virtual_intf = ieee80211_del_iface,
  737. .change_virtual_intf = ieee80211_change_iface,
  738. .add_key = ieee80211_add_key,
  739. .del_key = ieee80211_del_key,
  740. .get_key = ieee80211_get_key,
  741. .set_default_key = ieee80211_config_default_key,
  742. .add_beacon = ieee80211_add_beacon,
  743. .set_beacon = ieee80211_set_beacon,
  744. .del_beacon = ieee80211_del_beacon,
  745. .add_station = ieee80211_add_station,
  746. .del_station = ieee80211_del_station,
  747. .change_station = ieee80211_change_station,
  748. .get_station = ieee80211_get_station,
  749. .dump_station = ieee80211_dump_station,
  750. #ifdef CONFIG_MAC80211_MESH
  751. .add_mpath = ieee80211_add_mpath,
  752. .del_mpath = ieee80211_del_mpath,
  753. .change_mpath = ieee80211_change_mpath,
  754. .get_mpath = ieee80211_get_mpath,
  755. .dump_mpath = ieee80211_dump_mpath,
  756. #endif
  757. };