cfg.c 24 KB

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