cfg.c 22 KB

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