cfg.c 23 KB

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