cfg.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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. /*
  460. * FIXME: updating the flags is racy when this function is
  461. * called from ieee80211_change_station(), this will
  462. * be resolved in a future patch.
  463. */
  464. if (params->station_flags & STATION_FLAG_CHANGED) {
  465. sta->flags &= ~WLAN_STA_AUTHORIZED;
  466. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  467. sta->flags |= WLAN_STA_AUTHORIZED;
  468. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  469. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  470. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  471. sta->flags &= ~WLAN_STA_WME;
  472. if (params->station_flags & STATION_FLAG_WME)
  473. sta->flags |= WLAN_STA_WME;
  474. }
  475. /*
  476. * FIXME: updating the following information is racy when this
  477. * function is called from ieee80211_change_station().
  478. * However, all this information should be static so
  479. * maybe we should just reject attemps to change it.
  480. */
  481. if (params->aid) {
  482. sta->aid = params->aid;
  483. if (sta->aid > IEEE80211_MAX_AID)
  484. sta->aid = 0; /* XXX: should this be an error? */
  485. }
  486. if (params->listen_interval >= 0)
  487. sta->listen_interval = params->listen_interval;
  488. if (params->supported_rates) {
  489. rates = 0;
  490. sband = local->hw.wiphy->bands[local->oper_channel->band];
  491. for (i = 0; i < params->supported_rates_len; i++) {
  492. int rate = (params->supported_rates[i] & 0x7f) * 5;
  493. for (j = 0; j < sband->n_bitrates; j++) {
  494. if (sband->bitrates[j].bitrate == rate)
  495. rates |= BIT(j);
  496. }
  497. }
  498. sta->supp_rates[local->oper_channel->band] = rates;
  499. }
  500. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  501. switch (params->plink_action) {
  502. case PLINK_ACTION_OPEN:
  503. mesh_plink_open(sta);
  504. break;
  505. case PLINK_ACTION_BLOCK:
  506. mesh_plink_block(sta);
  507. break;
  508. }
  509. }
  510. }
  511. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  512. u8 *mac, struct station_parameters *params)
  513. {
  514. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  515. struct sta_info *sta;
  516. struct ieee80211_sub_if_data *sdata;
  517. int err;
  518. /* Prevent a race with changing the rate control algorithm */
  519. if (!netif_running(dev))
  520. return -ENETDOWN;
  521. if (params->vlan) {
  522. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  523. if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
  524. sdata->vif.type != IEEE80211_IF_TYPE_AP)
  525. return -EINVAL;
  526. } else
  527. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  528. if (ieee80211_vif_is_mesh(&sdata->vif))
  529. sta = mesh_plink_alloc(sdata, mac, DEFAULT_RATES, GFP_KERNEL);
  530. else
  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, false);
  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. };