cfg.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. #define DEFAULT_RATES 0
  19. static enum ieee80211_if_types
  20. nl80211_type_to_mac80211_type(enum nl80211_iftype type)
  21. {
  22. switch (type) {
  23. case NL80211_IFTYPE_UNSPECIFIED:
  24. return IEEE80211_IF_TYPE_STA;
  25. case NL80211_IFTYPE_ADHOC:
  26. return IEEE80211_IF_TYPE_IBSS;
  27. case NL80211_IFTYPE_STATION:
  28. return IEEE80211_IF_TYPE_STA;
  29. case NL80211_IFTYPE_MONITOR:
  30. return IEEE80211_IF_TYPE_MNTR;
  31. #ifdef CONFIG_MAC80211_MESH
  32. case NL80211_IFTYPE_MESH_POINT:
  33. return IEEE80211_IF_TYPE_MESH_POINT;
  34. #endif
  35. default:
  36. return IEEE80211_IF_TYPE_INVALID;
  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. enum ieee80211_if_types itype;
  45. struct net_device *dev;
  46. struct ieee80211_sub_if_data *sdata;
  47. int err;
  48. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
  49. return -ENODEV;
  50. itype = nl80211_type_to_mac80211_type(type);
  51. if (itype == IEEE80211_IF_TYPE_INVALID)
  52. return -EINVAL;
  53. err = ieee80211_if_add(local->mdev, name, &dev, itype, params);
  54. if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags)
  55. return err;
  56. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  57. sdata->u.mntr_flags = *flags;
  58. return 0;
  59. }
  60. static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
  61. {
  62. struct ieee80211_local *local = wiphy_priv(wiphy);
  63. struct net_device *dev;
  64. char *name;
  65. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
  66. return -ENODEV;
  67. /* we're under RTNL */
  68. dev = __dev_get_by_index(&init_net, ifindex);
  69. if (!dev)
  70. return 0;
  71. name = dev->name;
  72. return ieee80211_if_remove(local->mdev, name, -1);
  73. }
  74. static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
  75. enum nl80211_iftype type, u32 *flags,
  76. struct vif_params *params)
  77. {
  78. struct ieee80211_local *local = wiphy_priv(wiphy);
  79. struct net_device *dev;
  80. enum ieee80211_if_types itype;
  81. struct ieee80211_sub_if_data *sdata;
  82. if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
  83. return -ENODEV;
  84. /* we're under RTNL */
  85. dev = __dev_get_by_index(&init_net, ifindex);
  86. if (!dev)
  87. return -ENODEV;
  88. if (netif_running(dev))
  89. return -EBUSY;
  90. itype = nl80211_type_to_mac80211_type(type);
  91. if (itype == IEEE80211_IF_TYPE_INVALID)
  92. return -EINVAL;
  93. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  94. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  95. return -EOPNOTSUPP;
  96. ieee80211_if_reinit(dev);
  97. ieee80211_if_set_type(dev, itype);
  98. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  99. ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
  100. params->mesh_id_len,
  101. params->mesh_id);
  102. if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
  103. return 0;
  104. sdata->u.mntr_flags = *flags;
  105. return 0;
  106. }
  107. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  108. u8 key_idx, u8 *mac_addr,
  109. struct key_params *params)
  110. {
  111. struct ieee80211_sub_if_data *sdata;
  112. struct sta_info *sta = NULL;
  113. enum ieee80211_key_alg alg;
  114. struct ieee80211_key *key;
  115. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  116. switch (params->cipher) {
  117. case WLAN_CIPHER_SUITE_WEP40:
  118. case WLAN_CIPHER_SUITE_WEP104:
  119. alg = ALG_WEP;
  120. break;
  121. case WLAN_CIPHER_SUITE_TKIP:
  122. alg = ALG_TKIP;
  123. break;
  124. case WLAN_CIPHER_SUITE_CCMP:
  125. alg = ALG_CCMP;
  126. break;
  127. default:
  128. return -EINVAL;
  129. }
  130. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
  131. if (!key)
  132. return -ENOMEM;
  133. if (mac_addr) {
  134. sta = sta_info_get(sdata->local, mac_addr);
  135. if (!sta) {
  136. ieee80211_key_free(key);
  137. return -ENOENT;
  138. }
  139. }
  140. ieee80211_key_link(key, sdata, sta);
  141. return 0;
  142. }
  143. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  144. u8 key_idx, u8 *mac_addr)
  145. {
  146. struct ieee80211_sub_if_data *sdata;
  147. struct sta_info *sta;
  148. int ret;
  149. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  150. if (mac_addr) {
  151. sta = sta_info_get(sdata->local, mac_addr);
  152. if (!sta)
  153. return -ENOENT;
  154. ret = 0;
  155. if (sta->key) {
  156. ieee80211_key_free(sta->key);
  157. WARN_ON(sta->key);
  158. } else
  159. ret = -ENOENT;
  160. return ret;
  161. }
  162. if (!sdata->keys[key_idx])
  163. return -ENOENT;
  164. ieee80211_key_free(sdata->keys[key_idx]);
  165. WARN_ON(sdata->keys[key_idx]);
  166. return 0;
  167. }
  168. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  169. u8 key_idx, u8 *mac_addr, void *cookie,
  170. void (*callback)(void *cookie,
  171. struct key_params *params))
  172. {
  173. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  174. struct sta_info *sta = NULL;
  175. u8 seq[6] = {0};
  176. struct key_params params;
  177. struct ieee80211_key *key;
  178. u32 iv32;
  179. u16 iv16;
  180. int err = -ENOENT;
  181. if (mac_addr) {
  182. sta = sta_info_get(sdata->local, mac_addr);
  183. if (!sta)
  184. goto out;
  185. key = sta->key;
  186. } else
  187. key = sdata->keys[key_idx];
  188. if (!key)
  189. goto out;
  190. memset(&params, 0, sizeof(params));
  191. switch (key->conf.alg) {
  192. case ALG_TKIP:
  193. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  194. iv32 = key->u.tkip.iv32;
  195. iv16 = key->u.tkip.iv16;
  196. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  197. sdata->local->ops->get_tkip_seq)
  198. sdata->local->ops->get_tkip_seq(
  199. local_to_hw(sdata->local),
  200. key->conf.hw_key_idx,
  201. &iv32, &iv16);
  202. seq[0] = iv16 & 0xff;
  203. seq[1] = (iv16 >> 8) & 0xff;
  204. seq[2] = iv32 & 0xff;
  205. seq[3] = (iv32 >> 8) & 0xff;
  206. seq[4] = (iv32 >> 16) & 0xff;
  207. seq[5] = (iv32 >> 24) & 0xff;
  208. params.seq = seq;
  209. params.seq_len = 6;
  210. break;
  211. case ALG_CCMP:
  212. params.cipher = WLAN_CIPHER_SUITE_CCMP;
  213. seq[0] = key->u.ccmp.tx_pn[5];
  214. seq[1] = key->u.ccmp.tx_pn[4];
  215. seq[2] = key->u.ccmp.tx_pn[3];
  216. seq[3] = key->u.ccmp.tx_pn[2];
  217. seq[4] = key->u.ccmp.tx_pn[1];
  218. seq[5] = key->u.ccmp.tx_pn[0];
  219. params.seq = seq;
  220. params.seq_len = 6;
  221. break;
  222. case ALG_WEP:
  223. if (key->conf.keylen == 5)
  224. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  225. else
  226. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  227. break;
  228. }
  229. params.key = key->conf.key;
  230. params.key_len = key->conf.keylen;
  231. callback(cookie, &params);
  232. err = 0;
  233. out:
  234. return err;
  235. }
  236. static int ieee80211_config_default_key(struct wiphy *wiphy,
  237. struct net_device *dev,
  238. u8 key_idx)
  239. {
  240. struct ieee80211_sub_if_data *sdata;
  241. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  242. ieee80211_set_default_key(sdata, key_idx);
  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->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. if (ieee80211_hw_config(sdata->local))
  318. return -EINVAL;
  319. /*
  320. * We updated some parameter so if below bails out
  321. * it's not an error.
  322. */
  323. err = 0;
  324. }
  325. /* Need to have a beacon head if we don't have one yet */
  326. if (!params->head && !old)
  327. return err;
  328. /* sorry, no way to start beaconing without dtim period */
  329. if (!params->dtim_period && !old)
  330. return err;
  331. /* new or old head? */
  332. if (params->head)
  333. new_head_len = params->head_len;
  334. else
  335. new_head_len = old->head_len;
  336. /* new or old tail? */
  337. if (params->tail || !old)
  338. /* params->tail_len will be zero for !params->tail */
  339. new_tail_len = params->tail_len;
  340. else
  341. new_tail_len = old->tail_len;
  342. size = sizeof(*new) + new_head_len + new_tail_len;
  343. new = kzalloc(size, GFP_KERNEL);
  344. if (!new)
  345. return -ENOMEM;
  346. /* start filling the new info now */
  347. /* new or old dtim period? */
  348. if (params->dtim_period)
  349. new->dtim_period = params->dtim_period;
  350. else
  351. new->dtim_period = old->dtim_period;
  352. /*
  353. * pointers go into the block we allocated,
  354. * memory is | beacon_data | head | tail |
  355. */
  356. new->head = ((u8 *) new) + sizeof(*new);
  357. new->tail = new->head + new_head_len;
  358. new->head_len = new_head_len;
  359. new->tail_len = new_tail_len;
  360. /* copy in head */
  361. if (params->head)
  362. memcpy(new->head, params->head, new_head_len);
  363. else
  364. memcpy(new->head, old->head, new_head_len);
  365. /* copy in optional tail */
  366. if (params->tail)
  367. memcpy(new->tail, params->tail, new_tail_len);
  368. else
  369. if (old)
  370. memcpy(new->tail, old->tail, new_tail_len);
  371. rcu_assign_pointer(sdata->u.ap.beacon, new);
  372. synchronize_rcu();
  373. kfree(old);
  374. return ieee80211_if_config_beacon(sdata->dev);
  375. }
  376. static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
  377. struct beacon_parameters *params)
  378. {
  379. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  380. struct beacon_data *old;
  381. if (sdata->vif.type != IEEE80211_IF_TYPE_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 = IEEE80211_DEV_TO_SUB_IF(dev);
  392. struct beacon_data *old;
  393. if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
  394. return -EINVAL;
  395. old = sdata->u.ap.beacon;
  396. if (!old)
  397. return -ENOENT;
  398. return ieee80211_config_beacon(sdata, params);
  399. }
  400. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  401. {
  402. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  403. struct beacon_data *old;
  404. if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
  405. return -EINVAL;
  406. old = sdata->u.ap.beacon;
  407. if (!old)
  408. return -ENOENT;
  409. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  410. synchronize_rcu();
  411. kfree(old);
  412. return ieee80211_if_config_beacon(dev);
  413. }
  414. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  415. struct iapp_layer2_update {
  416. u8 da[ETH_ALEN]; /* broadcast */
  417. u8 sa[ETH_ALEN]; /* STA addr */
  418. __be16 len; /* 6 */
  419. u8 dsap; /* 0 */
  420. u8 ssap; /* 0 */
  421. u8 control;
  422. u8 xid_info[3];
  423. } __attribute__ ((packed));
  424. static void ieee80211_send_layer2_update(struct sta_info *sta)
  425. {
  426. struct iapp_layer2_update *msg;
  427. struct sk_buff *skb;
  428. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  429. * bridge devices */
  430. skb = dev_alloc_skb(sizeof(*msg));
  431. if (!skb)
  432. return;
  433. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  434. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  435. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  436. memset(msg->da, 0xff, ETH_ALEN);
  437. memcpy(msg->sa, sta->addr, ETH_ALEN);
  438. msg->len = htons(6);
  439. msg->dsap = 0;
  440. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  441. msg->control = 0xaf; /* XID response lsb.1111F101.
  442. * F=0 (no poll command; unsolicited frame) */
  443. msg->xid_info[0] = 0x81; /* XID format identifier */
  444. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  445. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  446. skb->dev = sta->sdata->dev;
  447. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  448. memset(skb->cb, 0, sizeof(skb->cb));
  449. netif_rx(skb);
  450. }
  451. static void sta_apply_parameters(struct ieee80211_local *local,
  452. struct sta_info *sta,
  453. struct station_parameters *params)
  454. {
  455. u32 rates;
  456. int i, j;
  457. struct ieee80211_supported_band *sband;
  458. struct ieee80211_sub_if_data *sdata = sta->sdata;
  459. if (params->station_flags & STATION_FLAG_CHANGED) {
  460. sta->flags &= ~WLAN_STA_AUTHORIZED;
  461. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  462. sta->flags |= WLAN_STA_AUTHORIZED;
  463. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  464. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  465. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  466. sta->flags &= ~WLAN_STA_WME;
  467. if (params->station_flags & STATION_FLAG_WME)
  468. sta->flags |= WLAN_STA_WME;
  469. }
  470. if (params->aid) {
  471. sta->aid = params->aid;
  472. if (sta->aid > IEEE80211_MAX_AID)
  473. sta->aid = 0; /* XXX: should this be an error? */
  474. }
  475. if (params->listen_interval >= 0)
  476. sta->listen_interval = params->listen_interval;
  477. if (params->supported_rates) {
  478. rates = 0;
  479. sband = local->hw.wiphy->bands[local->oper_channel->band];
  480. for (i = 0; i < params->supported_rates_len; i++) {
  481. int rate = (params->supported_rates[i] & 0x7f) * 5;
  482. for (j = 0; j < sband->n_bitrates; j++) {
  483. if (sband->bitrates[j].bitrate == rate)
  484. rates |= BIT(j);
  485. }
  486. }
  487. sta->supp_rates[local->oper_channel->band] = rates;
  488. }
  489. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  490. switch (params->plink_action) {
  491. case PLINK_ACTION_OPEN:
  492. mesh_plink_open(sta);
  493. break;
  494. case PLINK_ACTION_BLOCK:
  495. mesh_plink_block(sta);
  496. break;
  497. }
  498. }
  499. }
  500. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  501. u8 *mac, struct station_parameters *params)
  502. {
  503. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  504. struct sta_info *sta;
  505. struct ieee80211_sub_if_data *sdata;
  506. /* Prevent a race with changing the rate control algorithm */
  507. if (!netif_running(dev))
  508. return -ENETDOWN;
  509. if (params->vlan) {
  510. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  511. if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
  512. sdata->vif.type != IEEE80211_IF_TYPE_AP)
  513. return -EINVAL;
  514. } else
  515. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  516. if (ieee80211_vif_is_mesh(&sdata->vif))
  517. sta = mesh_plink_add(mac, DEFAULT_RATES, sdata);
  518. else
  519. sta = sta_info_add(sdata, mac);
  520. if (IS_ERR(sta))
  521. return PTR_ERR(sta);
  522. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
  523. sdata->vif.type == IEEE80211_IF_TYPE_AP)
  524. ieee80211_send_layer2_update(sta);
  525. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  526. sta_apply_parameters(local, sta, params);
  527. rate_control_rate_init(sta, local);
  528. return 0;
  529. }
  530. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  531. u8 *mac)
  532. {
  533. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  534. struct ieee80211_local *local = sdata->local;
  535. struct sta_info *sta;
  536. if (mac) {
  537. /* XXX: get sta belonging to dev */
  538. sta = sta_info_get(local, mac);
  539. if (!sta)
  540. return -ENOENT;
  541. sta_info_unlink(&sta);
  542. if (sta) {
  543. synchronize_rcu();
  544. sta_info_destroy(sta);
  545. }
  546. } else
  547. sta_info_flush(local, sdata);
  548. return 0;
  549. }
  550. static int ieee80211_change_station(struct wiphy *wiphy,
  551. struct net_device *dev,
  552. u8 *mac,
  553. struct station_parameters *params)
  554. {
  555. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  556. struct sta_info *sta;
  557. struct ieee80211_sub_if_data *vlansdata;
  558. /* XXX: get sta belonging to dev */
  559. sta = sta_info_get(local, mac);
  560. if (!sta)
  561. return -ENOENT;
  562. if (params->vlan && params->vlan != sta->sdata->dev) {
  563. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  564. if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
  565. vlansdata->vif.type != IEEE80211_IF_TYPE_AP)
  566. return -EINVAL;
  567. sta->sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  568. ieee80211_send_layer2_update(sta);
  569. }
  570. sta_apply_parameters(local, sta, params);
  571. return 0;
  572. }
  573. #ifdef CONFIG_MAC80211_MESH
  574. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  575. u8 *dst, u8 *next_hop)
  576. {
  577. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  578. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  579. struct mesh_path *mpath;
  580. struct sta_info *sta;
  581. int err;
  582. if (!netif_running(dev))
  583. return -ENETDOWN;
  584. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  585. return -ENOTSUPP;
  586. rcu_read_lock();
  587. sta = sta_info_get(local, next_hop);
  588. if (!sta) {
  589. rcu_read_unlock();
  590. return -ENOENT;
  591. }
  592. err = mesh_path_add(dst, dev);
  593. if (err) {
  594. rcu_read_unlock();
  595. return err;
  596. }
  597. mpath = mesh_path_lookup(dst, dev);
  598. if (!mpath) {
  599. rcu_read_unlock();
  600. return -ENXIO;
  601. }
  602. mesh_path_fix_nexthop(mpath, sta);
  603. rcu_read_unlock();
  604. return 0;
  605. }
  606. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  607. u8 *dst)
  608. {
  609. if (dst)
  610. return mesh_path_del(dst, dev, false);
  611. mesh_path_flush(dev);
  612. return 0;
  613. }
  614. static int ieee80211_change_mpath(struct wiphy *wiphy,
  615. struct net_device *dev,
  616. u8 *dst, u8 *next_hop)
  617. {
  618. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  619. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  620. struct mesh_path *mpath;
  621. struct sta_info *sta;
  622. if (!netif_running(dev))
  623. return -ENETDOWN;
  624. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  625. return -ENOTSUPP;
  626. rcu_read_lock();
  627. sta = sta_info_get(local, next_hop);
  628. if (!sta) {
  629. rcu_read_unlock();
  630. return -ENOENT;
  631. }
  632. mpath = mesh_path_lookup(dst, dev);
  633. if (!mpath) {
  634. rcu_read_unlock();
  635. return -ENOENT;
  636. }
  637. mesh_path_fix_nexthop(mpath, sta);
  638. rcu_read_unlock();
  639. return 0;
  640. }
  641. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  642. struct mpath_info *pinfo)
  643. {
  644. if (mpath->next_hop)
  645. memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
  646. else
  647. memset(next_hop, 0, ETH_ALEN);
  648. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  649. MPATH_INFO_DSN |
  650. MPATH_INFO_METRIC |
  651. MPATH_INFO_EXPTIME |
  652. MPATH_INFO_DISCOVERY_TIMEOUT |
  653. MPATH_INFO_DISCOVERY_RETRIES |
  654. MPATH_INFO_FLAGS;
  655. pinfo->frame_qlen = mpath->frame_queue.qlen;
  656. pinfo->dsn = mpath->dsn;
  657. pinfo->metric = mpath->metric;
  658. if (time_before(jiffies, mpath->exp_time))
  659. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  660. pinfo->discovery_timeout =
  661. jiffies_to_msecs(mpath->discovery_timeout);
  662. pinfo->discovery_retries = mpath->discovery_retries;
  663. pinfo->flags = 0;
  664. if (mpath->flags & MESH_PATH_ACTIVE)
  665. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  666. if (mpath->flags & MESH_PATH_RESOLVING)
  667. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  668. if (mpath->flags & MESH_PATH_DSN_VALID)
  669. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  670. if (mpath->flags & MESH_PATH_FIXED)
  671. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  672. if (mpath->flags & MESH_PATH_RESOLVING)
  673. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  674. pinfo->flags = mpath->flags;
  675. }
  676. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  677. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  678. {
  679. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  680. struct mesh_path *mpath;
  681. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  682. return -ENOTSUPP;
  683. rcu_read_lock();
  684. mpath = mesh_path_lookup(dst, dev);
  685. if (!mpath) {
  686. rcu_read_unlock();
  687. return -ENOENT;
  688. }
  689. memcpy(dst, mpath->dst, ETH_ALEN);
  690. mpath_set_pinfo(mpath, next_hop, pinfo);
  691. rcu_read_unlock();
  692. return 0;
  693. }
  694. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  695. int idx, u8 *dst, u8 *next_hop,
  696. struct mpath_info *pinfo)
  697. {
  698. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  699. struct mesh_path *mpath;
  700. if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
  701. return -ENOTSUPP;
  702. rcu_read_lock();
  703. mpath = mesh_path_lookup_by_idx(idx, dev);
  704. if (!mpath) {
  705. rcu_read_unlock();
  706. return -ENOENT;
  707. }
  708. memcpy(dst, mpath->dst, ETH_ALEN);
  709. mpath_set_pinfo(mpath, next_hop, pinfo);
  710. rcu_read_unlock();
  711. return 0;
  712. }
  713. #endif
  714. struct cfg80211_ops mac80211_config_ops = {
  715. .add_virtual_intf = ieee80211_add_iface,
  716. .del_virtual_intf = ieee80211_del_iface,
  717. .change_virtual_intf = ieee80211_change_iface,
  718. .add_key = ieee80211_add_key,
  719. .del_key = ieee80211_del_key,
  720. .get_key = ieee80211_get_key,
  721. .set_default_key = ieee80211_config_default_key,
  722. .add_beacon = ieee80211_add_beacon,
  723. .set_beacon = ieee80211_set_beacon,
  724. .del_beacon = ieee80211_del_beacon,
  725. .add_station = ieee80211_add_station,
  726. .del_station = ieee80211_del_station,
  727. .change_station = ieee80211_change_station,
  728. .get_station = ieee80211_get_station,
  729. .dump_station = ieee80211_dump_station,
  730. #ifdef CONFIG_MAC80211_MESH
  731. .add_mpath = ieee80211_add_mpath,
  732. .del_mpath = ieee80211_del_mpath,
  733. .change_mpath = ieee80211_change_mpath,
  734. .get_mpath = ieee80211_get_mpath,
  735. .dump_mpath = ieee80211_dump_mpath,
  736. #endif
  737. };