cfg.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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_AP:
  28. case NL80211_IFTYPE_AP_VLAN:
  29. case NL80211_IFTYPE_WDS:
  30. return true;
  31. default:
  32. return false;
  33. }
  34. }
  35. static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
  36. enum nl80211_iftype type, u32 *flags,
  37. struct vif_params *params)
  38. {
  39. struct ieee80211_local *local = wiphy_priv(wiphy);
  40. struct net_device *dev;
  41. struct ieee80211_sub_if_data *sdata;
  42. int err;
  43. if (!nl80211_type_check(type))
  44. return -EINVAL;
  45. err = ieee80211_if_add(local, name, &dev, type, params);
  46. if (err || type != NL80211_IFTYPE_MONITOR || !flags)
  47. return err;
  48. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  49. sdata->u.mntr_flags = *flags;
  50. return 0;
  51. }
  52. static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
  53. {
  54. struct net_device *dev;
  55. struct ieee80211_sub_if_data *sdata;
  56. /* we're under RTNL */
  57. dev = __dev_get_by_index(&init_net, ifindex);
  58. if (!dev)
  59. return -ENODEV;
  60. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  61. ieee80211_if_remove(sdata);
  62. return 0;
  63. }
  64. static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
  65. enum nl80211_iftype type, u32 *flags,
  66. struct vif_params *params)
  67. {
  68. struct net_device *dev;
  69. struct ieee80211_sub_if_data *sdata;
  70. int ret;
  71. /* we're under RTNL */
  72. dev = __dev_get_by_index(&init_net, ifindex);
  73. if (!dev)
  74. return -ENODEV;
  75. if (!nl80211_type_check(type))
  76. return -EINVAL;
  77. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  78. ret = ieee80211_if_change_type(sdata, type);
  79. if (ret)
  80. return ret;
  81. if (netif_running(sdata->dev))
  82. return -EBUSY;
  83. if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
  84. ieee80211_sdata_set_mesh_id(sdata,
  85. params->mesh_id_len,
  86. params->mesh_id);
  87. if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
  88. return 0;
  89. sdata->u.mntr_flags = *flags;
  90. return 0;
  91. }
  92. static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
  93. u8 key_idx, u8 *mac_addr,
  94. struct key_params *params)
  95. {
  96. struct ieee80211_sub_if_data *sdata;
  97. struct sta_info *sta = NULL;
  98. enum ieee80211_key_alg alg;
  99. struct ieee80211_key *key;
  100. int err;
  101. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  102. switch (params->cipher) {
  103. case WLAN_CIPHER_SUITE_WEP40:
  104. case WLAN_CIPHER_SUITE_WEP104:
  105. alg = ALG_WEP;
  106. break;
  107. case WLAN_CIPHER_SUITE_TKIP:
  108. alg = ALG_TKIP;
  109. break;
  110. case WLAN_CIPHER_SUITE_CCMP:
  111. alg = ALG_CCMP;
  112. break;
  113. default:
  114. return -EINVAL;
  115. }
  116. key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
  117. if (!key)
  118. return -ENOMEM;
  119. rcu_read_lock();
  120. if (mac_addr) {
  121. sta = sta_info_get(sdata->local, mac_addr);
  122. if (!sta) {
  123. ieee80211_key_free(key);
  124. err = -ENOENT;
  125. goto out_unlock;
  126. }
  127. }
  128. ieee80211_key_link(key, sdata, sta);
  129. err = 0;
  130. out_unlock:
  131. rcu_read_unlock();
  132. return err;
  133. }
  134. static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
  135. u8 key_idx, u8 *mac_addr)
  136. {
  137. struct ieee80211_sub_if_data *sdata;
  138. struct sta_info *sta;
  139. int ret;
  140. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  141. rcu_read_lock();
  142. if (mac_addr) {
  143. ret = -ENOENT;
  144. sta = sta_info_get(sdata->local, mac_addr);
  145. if (!sta)
  146. goto out_unlock;
  147. if (sta->key) {
  148. ieee80211_key_free(sta->key);
  149. WARN_ON(sta->key);
  150. ret = 0;
  151. }
  152. goto out_unlock;
  153. }
  154. if (!sdata->keys[key_idx]) {
  155. ret = -ENOENT;
  156. goto out_unlock;
  157. }
  158. ieee80211_key_free(sdata->keys[key_idx]);
  159. WARN_ON(sdata->keys[key_idx]);
  160. ret = 0;
  161. out_unlock:
  162. rcu_read_unlock();
  163. return ret;
  164. }
  165. static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
  166. u8 key_idx, u8 *mac_addr, void *cookie,
  167. void (*callback)(void *cookie,
  168. struct key_params *params))
  169. {
  170. struct ieee80211_sub_if_data *sdata;
  171. struct sta_info *sta = NULL;
  172. u8 seq[6] = {0};
  173. struct key_params params;
  174. struct ieee80211_key *key;
  175. u32 iv32;
  176. u16 iv16;
  177. int err = -ENOENT;
  178. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  179. rcu_read_lock();
  180. if (mac_addr) {
  181. sta = sta_info_get(sdata->local, mac_addr);
  182. if (!sta)
  183. goto out;
  184. key = sta->key;
  185. } else
  186. key = sdata->keys[key_idx];
  187. if (!key)
  188. goto out;
  189. memset(&params, 0, sizeof(params));
  190. switch (key->conf.alg) {
  191. case ALG_TKIP:
  192. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  193. iv32 = key->u.tkip.tx.iv32;
  194. iv16 = key->u.tkip.tx.iv16;
  195. if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
  196. sdata->local->ops->get_tkip_seq)
  197. sdata->local->ops->get_tkip_seq(
  198. local_to_hw(sdata->local),
  199. key->conf.hw_key_idx,
  200. &iv32, &iv16);
  201. seq[0] = iv16 & 0xff;
  202. seq[1] = (iv16 >> 8) & 0xff;
  203. seq[2] = iv32 & 0xff;
  204. seq[3] = (iv32 >> 8) & 0xff;
  205. seq[4] = (iv32 >> 16) & 0xff;
  206. seq[5] = (iv32 >> 24) & 0xff;
  207. params.seq = seq;
  208. params.seq_len = 6;
  209. break;
  210. case ALG_CCMP:
  211. params.cipher = WLAN_CIPHER_SUITE_CCMP;
  212. seq[0] = key->u.ccmp.tx_pn[5];
  213. seq[1] = key->u.ccmp.tx_pn[4];
  214. seq[2] = key->u.ccmp.tx_pn[3];
  215. seq[3] = key->u.ccmp.tx_pn[2];
  216. seq[4] = key->u.ccmp.tx_pn[1];
  217. seq[5] = key->u.ccmp.tx_pn[0];
  218. params.seq = seq;
  219. params.seq_len = 6;
  220. break;
  221. case ALG_WEP:
  222. if (key->conf.keylen == 5)
  223. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  224. else
  225. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  226. break;
  227. }
  228. params.key = key->conf.key;
  229. params.key_len = key->conf.keylen;
  230. callback(cookie, &params);
  231. err = 0;
  232. out:
  233. rcu_read_unlock();
  234. return err;
  235. }
  236. static int ieee80211_config_default_key(struct wiphy *wiphy,
  237. struct net_device *dev,
  238. u8 key_idx)
  239. {
  240. struct ieee80211_sub_if_data *sdata;
  241. rcu_read_lock();
  242. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  243. ieee80211_set_default_key(sdata, key_idx);
  244. rcu_read_unlock();
  245. return 0;
  246. }
  247. static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
  248. {
  249. struct ieee80211_sub_if_data *sdata = sta->sdata;
  250. sinfo->filled = STATION_INFO_INACTIVE_TIME |
  251. STATION_INFO_RX_BYTES |
  252. STATION_INFO_TX_BYTES |
  253. STATION_INFO_TX_BITRATE;
  254. sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
  255. sinfo->rx_bytes = sta->rx_bytes;
  256. sinfo->tx_bytes = sta->tx_bytes;
  257. if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  258. sinfo->filled |= STATION_INFO_SIGNAL;
  259. sinfo->signal = (s8)sta->last_signal;
  260. }
  261. sinfo->txrate.flags = 0;
  262. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  263. sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
  264. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  265. sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  266. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
  267. sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
  268. if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
  269. struct ieee80211_supported_band *sband;
  270. sband = sta->local->hw.wiphy->bands[
  271. sta->local->hw.conf.channel->band];
  272. sinfo->txrate.legacy =
  273. sband->bitrates[sta->last_tx_rate.idx].bitrate;
  274. } else
  275. sinfo->txrate.mcs = sta->last_tx_rate.idx;
  276. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  277. #ifdef CONFIG_MAC80211_MESH
  278. sinfo->filled |= STATION_INFO_LLID |
  279. STATION_INFO_PLID |
  280. STATION_INFO_PLINK_STATE;
  281. sinfo->llid = le16_to_cpu(sta->llid);
  282. sinfo->plid = le16_to_cpu(sta->plid);
  283. sinfo->plink_state = sta->plink_state;
  284. #endif
  285. }
  286. }
  287. static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
  288. int idx, u8 *mac, struct station_info *sinfo)
  289. {
  290. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  291. struct sta_info *sta;
  292. int ret = -ENOENT;
  293. rcu_read_lock();
  294. sta = sta_info_get_by_idx(local, idx, dev);
  295. if (sta) {
  296. ret = 0;
  297. memcpy(mac, sta->sta.addr, ETH_ALEN);
  298. sta_set_sinfo(sta, sinfo);
  299. }
  300. rcu_read_unlock();
  301. return ret;
  302. }
  303. static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
  304. u8 *mac, struct station_info *sinfo)
  305. {
  306. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  307. struct sta_info *sta;
  308. int ret = -ENOENT;
  309. rcu_read_lock();
  310. /* XXX: verify sta->dev == dev */
  311. sta = sta_info_get(local, mac);
  312. if (sta) {
  313. ret = 0;
  314. sta_set_sinfo(sta, sinfo);
  315. }
  316. rcu_read_unlock();
  317. return ret;
  318. }
  319. /*
  320. * This handles both adding a beacon and setting new beacon info
  321. */
  322. static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
  323. struct beacon_parameters *params)
  324. {
  325. struct beacon_data *new, *old;
  326. int new_head_len, new_tail_len;
  327. int size;
  328. int err = -EINVAL;
  329. old = sdata->u.ap.beacon;
  330. /* head must not be zero-length */
  331. if (params->head && !params->head_len)
  332. return -EINVAL;
  333. /*
  334. * This is a kludge. beacon interval should really be part
  335. * of the beacon information.
  336. */
  337. if (params->interval) {
  338. sdata->local->hw.conf.beacon_int = params->interval;
  339. err = ieee80211_hw_config(sdata->local,
  340. IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
  341. if (err < 0)
  342. return err;
  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_sub_if_data *sdata;
  404. struct beacon_data *old;
  405. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  406. if (sdata->vif.type != NL80211_IFTYPE_AP)
  407. return -EINVAL;
  408. old = sdata->u.ap.beacon;
  409. if (old)
  410. return -EALREADY;
  411. return ieee80211_config_beacon(sdata, params);
  412. }
  413. static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
  414. struct beacon_parameters *params)
  415. {
  416. struct ieee80211_sub_if_data *sdata;
  417. struct beacon_data *old;
  418. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  419. if (sdata->vif.type != NL80211_IFTYPE_AP)
  420. return -EINVAL;
  421. old = sdata->u.ap.beacon;
  422. if (!old)
  423. return -ENOENT;
  424. return ieee80211_config_beacon(sdata, params);
  425. }
  426. static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
  427. {
  428. struct ieee80211_sub_if_data *sdata;
  429. struct beacon_data *old;
  430. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  431. if (sdata->vif.type != NL80211_IFTYPE_AP)
  432. return -EINVAL;
  433. old = sdata->u.ap.beacon;
  434. if (!old)
  435. return -ENOENT;
  436. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  437. synchronize_rcu();
  438. kfree(old);
  439. return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  440. }
  441. /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
  442. struct iapp_layer2_update {
  443. u8 da[ETH_ALEN]; /* broadcast */
  444. u8 sa[ETH_ALEN]; /* STA addr */
  445. __be16 len; /* 6 */
  446. u8 dsap; /* 0 */
  447. u8 ssap; /* 0 */
  448. u8 control;
  449. u8 xid_info[3];
  450. } __attribute__ ((packed));
  451. static void ieee80211_send_layer2_update(struct sta_info *sta)
  452. {
  453. struct iapp_layer2_update *msg;
  454. struct sk_buff *skb;
  455. /* Send Level 2 Update Frame to update forwarding tables in layer 2
  456. * bridge devices */
  457. skb = dev_alloc_skb(sizeof(*msg));
  458. if (!skb)
  459. return;
  460. msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
  461. /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
  462. * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
  463. memset(msg->da, 0xff, ETH_ALEN);
  464. memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
  465. msg->len = htons(6);
  466. msg->dsap = 0;
  467. msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
  468. msg->control = 0xaf; /* XID response lsb.1111F101.
  469. * F=0 (no poll command; unsolicited frame) */
  470. msg->xid_info[0] = 0x81; /* XID format identifier */
  471. msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
  472. msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
  473. skb->dev = sta->sdata->dev;
  474. skb->protocol = eth_type_trans(skb, sta->sdata->dev);
  475. memset(skb->cb, 0, sizeof(skb->cb));
  476. netif_rx(skb);
  477. }
  478. static void sta_apply_parameters(struct ieee80211_local *local,
  479. struct sta_info *sta,
  480. struct station_parameters *params)
  481. {
  482. u32 rates;
  483. int i, j;
  484. struct ieee80211_supported_band *sband;
  485. struct ieee80211_sub_if_data *sdata = sta->sdata;
  486. sband = local->hw.wiphy->bands[local->oper_channel->band];
  487. /*
  488. * FIXME: updating the flags is racy when this function is
  489. * called from ieee80211_change_station(), this will
  490. * be resolved in a future patch.
  491. */
  492. if (params->station_flags & STATION_FLAG_CHANGED) {
  493. spin_lock_bh(&sta->lock);
  494. sta->flags &= ~WLAN_STA_AUTHORIZED;
  495. if (params->station_flags & STATION_FLAG_AUTHORIZED)
  496. sta->flags |= WLAN_STA_AUTHORIZED;
  497. sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
  498. if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
  499. sta->flags |= WLAN_STA_SHORT_PREAMBLE;
  500. sta->flags &= ~WLAN_STA_WME;
  501. if (params->station_flags & STATION_FLAG_WME)
  502. sta->flags |= WLAN_STA_WME;
  503. spin_unlock_bh(&sta->lock);
  504. }
  505. /*
  506. * FIXME: updating the following information is racy when this
  507. * function is called from ieee80211_change_station().
  508. * However, all this information should be static so
  509. * maybe we should just reject attemps to change it.
  510. */
  511. if (params->aid) {
  512. sta->sta.aid = params->aid;
  513. if (sta->sta.aid > IEEE80211_MAX_AID)
  514. sta->sta.aid = 0; /* XXX: should this be an error? */
  515. }
  516. if (params->listen_interval >= 0)
  517. sta->listen_interval = params->listen_interval;
  518. if (params->supported_rates) {
  519. rates = 0;
  520. for (i = 0; i < params->supported_rates_len; i++) {
  521. int rate = (params->supported_rates[i] & 0x7f) * 5;
  522. for (j = 0; j < sband->n_bitrates; j++) {
  523. if (sband->bitrates[j].bitrate == rate)
  524. rates |= BIT(j);
  525. }
  526. }
  527. sta->sta.supp_rates[local->oper_channel->band] = rates;
  528. }
  529. if (params->ht_capa)
  530. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  531. params->ht_capa,
  532. &sta->sta.ht_cap);
  533. if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
  534. switch (params->plink_action) {
  535. case PLINK_ACTION_OPEN:
  536. mesh_plink_open(sta);
  537. break;
  538. case PLINK_ACTION_BLOCK:
  539. mesh_plink_block(sta);
  540. break;
  541. }
  542. }
  543. }
  544. static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
  545. u8 *mac, struct station_parameters *params)
  546. {
  547. struct ieee80211_local *local = wiphy_priv(wiphy);
  548. struct sta_info *sta;
  549. struct ieee80211_sub_if_data *sdata;
  550. int err;
  551. /* Prevent a race with changing the rate control algorithm */
  552. if (!netif_running(dev))
  553. return -ENETDOWN;
  554. if (params->vlan) {
  555. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  556. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  557. sdata->vif.type != NL80211_IFTYPE_AP)
  558. return -EINVAL;
  559. } else
  560. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  561. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  562. return -EINVAL;
  563. if (is_multicast_ether_addr(mac))
  564. return -EINVAL;
  565. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  566. if (!sta)
  567. return -ENOMEM;
  568. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  569. sta_apply_parameters(local, sta, params);
  570. rate_control_rate_init(sta);
  571. rcu_read_lock();
  572. err = sta_info_insert(sta);
  573. if (err) {
  574. /* STA has been freed */
  575. rcu_read_unlock();
  576. return err;
  577. }
  578. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  579. sdata->vif.type == NL80211_IFTYPE_AP)
  580. ieee80211_send_layer2_update(sta);
  581. rcu_read_unlock();
  582. return 0;
  583. }
  584. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  585. u8 *mac)
  586. {
  587. struct ieee80211_local *local = wiphy_priv(wiphy);
  588. struct ieee80211_sub_if_data *sdata;
  589. struct sta_info *sta;
  590. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  591. if (mac) {
  592. rcu_read_lock();
  593. /* XXX: get sta belonging to dev */
  594. sta = sta_info_get(local, mac);
  595. if (!sta) {
  596. rcu_read_unlock();
  597. return -ENOENT;
  598. }
  599. sta_info_unlink(&sta);
  600. rcu_read_unlock();
  601. sta_info_destroy(sta);
  602. } else
  603. sta_info_flush(local, sdata);
  604. return 0;
  605. }
  606. static int ieee80211_change_station(struct wiphy *wiphy,
  607. struct net_device *dev,
  608. u8 *mac,
  609. struct station_parameters *params)
  610. {
  611. struct ieee80211_local *local = wiphy_priv(wiphy);
  612. struct sta_info *sta;
  613. struct ieee80211_sub_if_data *vlansdata;
  614. rcu_read_lock();
  615. /* XXX: get sta belonging to dev */
  616. sta = sta_info_get(local, mac);
  617. if (!sta) {
  618. rcu_read_unlock();
  619. return -ENOENT;
  620. }
  621. if (params->vlan && params->vlan != sta->sdata->dev) {
  622. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  623. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  624. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  625. rcu_read_unlock();
  626. return -EINVAL;
  627. }
  628. sta->sdata = vlansdata;
  629. ieee80211_send_layer2_update(sta);
  630. }
  631. sta_apply_parameters(local, sta, params);
  632. rcu_read_unlock();
  633. return 0;
  634. }
  635. #ifdef CONFIG_MAC80211_MESH
  636. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  637. u8 *dst, u8 *next_hop)
  638. {
  639. struct ieee80211_local *local = wiphy_priv(wiphy);
  640. struct ieee80211_sub_if_data *sdata;
  641. struct mesh_path *mpath;
  642. struct sta_info *sta;
  643. int err;
  644. if (!netif_running(dev))
  645. return -ENETDOWN;
  646. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  647. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  648. return -ENOTSUPP;
  649. rcu_read_lock();
  650. sta = sta_info_get(local, next_hop);
  651. if (!sta) {
  652. rcu_read_unlock();
  653. return -ENOENT;
  654. }
  655. err = mesh_path_add(dst, sdata);
  656. if (err) {
  657. rcu_read_unlock();
  658. return err;
  659. }
  660. mpath = mesh_path_lookup(dst, sdata);
  661. if (!mpath) {
  662. rcu_read_unlock();
  663. return -ENXIO;
  664. }
  665. mesh_path_fix_nexthop(mpath, sta);
  666. rcu_read_unlock();
  667. return 0;
  668. }
  669. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  670. u8 *dst)
  671. {
  672. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  673. if (dst)
  674. return mesh_path_del(dst, sdata);
  675. mesh_path_flush(sdata);
  676. return 0;
  677. }
  678. static int ieee80211_change_mpath(struct wiphy *wiphy,
  679. struct net_device *dev,
  680. u8 *dst, u8 *next_hop)
  681. {
  682. struct ieee80211_local *local = wiphy_priv(wiphy);
  683. struct ieee80211_sub_if_data *sdata;
  684. struct mesh_path *mpath;
  685. struct sta_info *sta;
  686. if (!netif_running(dev))
  687. return -ENETDOWN;
  688. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  689. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  690. return -ENOTSUPP;
  691. rcu_read_lock();
  692. sta = sta_info_get(local, next_hop);
  693. if (!sta) {
  694. rcu_read_unlock();
  695. return -ENOENT;
  696. }
  697. mpath = mesh_path_lookup(dst, sdata);
  698. if (!mpath) {
  699. rcu_read_unlock();
  700. return -ENOENT;
  701. }
  702. mesh_path_fix_nexthop(mpath, sta);
  703. rcu_read_unlock();
  704. return 0;
  705. }
  706. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  707. struct mpath_info *pinfo)
  708. {
  709. if (mpath->next_hop)
  710. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  711. else
  712. memset(next_hop, 0, ETH_ALEN);
  713. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  714. MPATH_INFO_DSN |
  715. MPATH_INFO_METRIC |
  716. MPATH_INFO_EXPTIME |
  717. MPATH_INFO_DISCOVERY_TIMEOUT |
  718. MPATH_INFO_DISCOVERY_RETRIES |
  719. MPATH_INFO_FLAGS;
  720. pinfo->frame_qlen = mpath->frame_queue.qlen;
  721. pinfo->dsn = mpath->dsn;
  722. pinfo->metric = mpath->metric;
  723. if (time_before(jiffies, mpath->exp_time))
  724. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  725. pinfo->discovery_timeout =
  726. jiffies_to_msecs(mpath->discovery_timeout);
  727. pinfo->discovery_retries = mpath->discovery_retries;
  728. pinfo->flags = 0;
  729. if (mpath->flags & MESH_PATH_ACTIVE)
  730. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  731. if (mpath->flags & MESH_PATH_RESOLVING)
  732. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  733. if (mpath->flags & MESH_PATH_DSN_VALID)
  734. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  735. if (mpath->flags & MESH_PATH_FIXED)
  736. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  737. if (mpath->flags & MESH_PATH_RESOLVING)
  738. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  739. pinfo->flags = mpath->flags;
  740. }
  741. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  742. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  743. {
  744. struct ieee80211_sub_if_data *sdata;
  745. struct mesh_path *mpath;
  746. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  747. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  748. return -ENOTSUPP;
  749. rcu_read_lock();
  750. mpath = mesh_path_lookup(dst, sdata);
  751. if (!mpath) {
  752. rcu_read_unlock();
  753. return -ENOENT;
  754. }
  755. memcpy(dst, mpath->dst, ETH_ALEN);
  756. mpath_set_pinfo(mpath, next_hop, pinfo);
  757. rcu_read_unlock();
  758. return 0;
  759. }
  760. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  761. int idx, u8 *dst, u8 *next_hop,
  762. struct mpath_info *pinfo)
  763. {
  764. struct ieee80211_sub_if_data *sdata;
  765. struct mesh_path *mpath;
  766. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  767. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  768. return -ENOTSUPP;
  769. rcu_read_lock();
  770. mpath = mesh_path_lookup_by_idx(idx, sdata);
  771. if (!mpath) {
  772. rcu_read_unlock();
  773. return -ENOENT;
  774. }
  775. memcpy(dst, mpath->dst, ETH_ALEN);
  776. mpath_set_pinfo(mpath, next_hop, pinfo);
  777. rcu_read_unlock();
  778. return 0;
  779. }
  780. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  781. struct net_device *dev,
  782. struct mesh_config *conf)
  783. {
  784. struct ieee80211_sub_if_data *sdata;
  785. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  786. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  787. return -ENOTSUPP;
  788. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  789. return 0;
  790. }
  791. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  792. {
  793. return (mask >> (parm-1)) & 0x1;
  794. }
  795. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  796. struct net_device *dev,
  797. const struct mesh_config *nconf, u32 mask)
  798. {
  799. struct mesh_config *conf;
  800. struct ieee80211_sub_if_data *sdata;
  801. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  802. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  803. return -ENOTSUPP;
  804. /* Set the config options which we are interested in setting */
  805. conf = &(sdata->u.mesh.mshcfg);
  806. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  807. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  808. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  809. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  810. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  811. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  812. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  813. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  814. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  815. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  816. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  817. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  818. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  819. conf->auto_open_plinks = nconf->auto_open_plinks;
  820. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  821. conf->dot11MeshHWMPmaxPREQretries =
  822. nconf->dot11MeshHWMPmaxPREQretries;
  823. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  824. conf->path_refresh_time = nconf->path_refresh_time;
  825. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  826. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  827. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  828. conf->dot11MeshHWMPactivePathTimeout =
  829. nconf->dot11MeshHWMPactivePathTimeout;
  830. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  831. conf->dot11MeshHWMPpreqMinInterval =
  832. nconf->dot11MeshHWMPpreqMinInterval;
  833. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  834. mask))
  835. conf->dot11MeshHWMPnetDiameterTraversalTime =
  836. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  837. return 0;
  838. }
  839. #endif
  840. static int ieee80211_change_bss(struct wiphy *wiphy,
  841. struct net_device *dev,
  842. struct bss_parameters *params)
  843. {
  844. struct ieee80211_sub_if_data *sdata;
  845. u32 changed = 0;
  846. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  847. if (sdata->vif.type != NL80211_IFTYPE_AP)
  848. return -EINVAL;
  849. if (params->use_cts_prot >= 0) {
  850. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  851. changed |= BSS_CHANGED_ERP_CTS_PROT;
  852. }
  853. if (params->use_short_preamble >= 0) {
  854. sdata->vif.bss_conf.use_short_preamble =
  855. params->use_short_preamble;
  856. changed |= BSS_CHANGED_ERP_PREAMBLE;
  857. }
  858. if (params->use_short_slot_time >= 0) {
  859. sdata->vif.bss_conf.use_short_slot =
  860. params->use_short_slot_time;
  861. changed |= BSS_CHANGED_ERP_SLOT;
  862. }
  863. if (params->basic_rates) {
  864. int i, j;
  865. u32 rates = 0;
  866. struct ieee80211_local *local = wiphy_priv(wiphy);
  867. struct ieee80211_supported_band *sband =
  868. wiphy->bands[local->oper_channel->band];
  869. for (i = 0; i < params->basic_rates_len; i++) {
  870. int rate = (params->basic_rates[i] & 0x7f) * 5;
  871. for (j = 0; j < sband->n_bitrates; j++) {
  872. if (sband->bitrates[j].bitrate == rate)
  873. rates |= BIT(j);
  874. }
  875. }
  876. sdata->vif.bss_conf.basic_rates = rates;
  877. changed |= BSS_CHANGED_BASIC_RATES;
  878. }
  879. ieee80211_bss_info_change_notify(sdata, changed);
  880. return 0;
  881. }
  882. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  883. struct ieee80211_txq_params *params)
  884. {
  885. struct ieee80211_local *local = wiphy_priv(wiphy);
  886. struct ieee80211_tx_queue_params p;
  887. if (!local->ops->conf_tx)
  888. return -EOPNOTSUPP;
  889. memset(&p, 0, sizeof(p));
  890. p.aifs = params->aifs;
  891. p.cw_max = params->cwmax;
  892. p.cw_min = params->cwmin;
  893. p.txop = params->txop;
  894. if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
  895. printk(KERN_DEBUG "%s: failed to set TX queue "
  896. "parameters for queue %d\n", local->mdev->name,
  897. params->queue);
  898. return -EINVAL;
  899. }
  900. return 0;
  901. }
  902. static int ieee80211_set_channel(struct wiphy *wiphy,
  903. struct ieee80211_channel *chan,
  904. enum nl80211_channel_type channel_type)
  905. {
  906. struct ieee80211_local *local = wiphy_priv(wiphy);
  907. local->oper_channel = chan;
  908. local->oper_channel_type = channel_type;
  909. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  910. }
  911. struct cfg80211_ops mac80211_config_ops = {
  912. .add_virtual_intf = ieee80211_add_iface,
  913. .del_virtual_intf = ieee80211_del_iface,
  914. .change_virtual_intf = ieee80211_change_iface,
  915. .add_key = ieee80211_add_key,
  916. .del_key = ieee80211_del_key,
  917. .get_key = ieee80211_get_key,
  918. .set_default_key = ieee80211_config_default_key,
  919. .add_beacon = ieee80211_add_beacon,
  920. .set_beacon = ieee80211_set_beacon,
  921. .del_beacon = ieee80211_del_beacon,
  922. .add_station = ieee80211_add_station,
  923. .del_station = ieee80211_del_station,
  924. .change_station = ieee80211_change_station,
  925. .get_station = ieee80211_get_station,
  926. .dump_station = ieee80211_dump_station,
  927. #ifdef CONFIG_MAC80211_MESH
  928. .add_mpath = ieee80211_add_mpath,
  929. .del_mpath = ieee80211_del_mpath,
  930. .change_mpath = ieee80211_change_mpath,
  931. .get_mpath = ieee80211_get_mpath,
  932. .dump_mpath = ieee80211_dump_mpath,
  933. .set_mesh_params = ieee80211_set_mesh_params,
  934. .get_mesh_params = ieee80211_get_mesh_params,
  935. #endif
  936. .change_bss = ieee80211_change_bss,
  937. .set_txq_params = ieee80211_set_txq_params,
  938. .set_channel = ieee80211_set_channel,
  939. };