cfg.c 24 KB

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