cfg.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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. int layer2_update;
  552. /* Prevent a race with changing the rate control algorithm */
  553. if (!netif_running(dev))
  554. return -ENETDOWN;
  555. if (params->vlan) {
  556. sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  557. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  558. sdata->vif.type != NL80211_IFTYPE_AP)
  559. return -EINVAL;
  560. } else
  561. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  562. if (compare_ether_addr(mac, dev->dev_addr) == 0)
  563. return -EINVAL;
  564. if (is_multicast_ether_addr(mac))
  565. return -EINVAL;
  566. sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
  567. if (!sta)
  568. return -ENOMEM;
  569. sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
  570. sta_apply_parameters(local, sta, params);
  571. rate_control_rate_init(sta);
  572. layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  573. sdata->vif.type == NL80211_IFTYPE_AP;
  574. rcu_read_lock();
  575. err = sta_info_insert(sta);
  576. if (err) {
  577. /* STA has been freed */
  578. if (err == -EEXIST && layer2_update) {
  579. /* Need to update layer 2 devices on reassociation */
  580. sta = sta_info_get(local, mac);
  581. if (sta)
  582. ieee80211_send_layer2_update(sta);
  583. }
  584. rcu_read_unlock();
  585. return err;
  586. }
  587. if (layer2_update)
  588. ieee80211_send_layer2_update(sta);
  589. rcu_read_unlock();
  590. return 0;
  591. }
  592. static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
  593. u8 *mac)
  594. {
  595. struct ieee80211_local *local = wiphy_priv(wiphy);
  596. struct ieee80211_sub_if_data *sdata;
  597. struct sta_info *sta;
  598. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  599. if (mac) {
  600. rcu_read_lock();
  601. /* XXX: get sta belonging to dev */
  602. sta = sta_info_get(local, mac);
  603. if (!sta) {
  604. rcu_read_unlock();
  605. return -ENOENT;
  606. }
  607. sta_info_unlink(&sta);
  608. rcu_read_unlock();
  609. sta_info_destroy(sta);
  610. } else
  611. sta_info_flush(local, sdata);
  612. return 0;
  613. }
  614. static int ieee80211_change_station(struct wiphy *wiphy,
  615. struct net_device *dev,
  616. u8 *mac,
  617. struct station_parameters *params)
  618. {
  619. struct ieee80211_local *local = wiphy_priv(wiphy);
  620. struct sta_info *sta;
  621. struct ieee80211_sub_if_data *vlansdata;
  622. rcu_read_lock();
  623. /* XXX: get sta belonging to dev */
  624. sta = sta_info_get(local, mac);
  625. if (!sta) {
  626. rcu_read_unlock();
  627. return -ENOENT;
  628. }
  629. if (params->vlan && params->vlan != sta->sdata->dev) {
  630. vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
  631. if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  632. vlansdata->vif.type != NL80211_IFTYPE_AP) {
  633. rcu_read_unlock();
  634. return -EINVAL;
  635. }
  636. sta->sdata = vlansdata;
  637. ieee80211_send_layer2_update(sta);
  638. }
  639. sta_apply_parameters(local, sta, params);
  640. rcu_read_unlock();
  641. return 0;
  642. }
  643. #ifdef CONFIG_MAC80211_MESH
  644. static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
  645. u8 *dst, u8 *next_hop)
  646. {
  647. struct ieee80211_local *local = wiphy_priv(wiphy);
  648. struct ieee80211_sub_if_data *sdata;
  649. struct mesh_path *mpath;
  650. struct sta_info *sta;
  651. int err;
  652. if (!netif_running(dev))
  653. return -ENETDOWN;
  654. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  655. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  656. return -ENOTSUPP;
  657. rcu_read_lock();
  658. sta = sta_info_get(local, next_hop);
  659. if (!sta) {
  660. rcu_read_unlock();
  661. return -ENOENT;
  662. }
  663. err = mesh_path_add(dst, sdata);
  664. if (err) {
  665. rcu_read_unlock();
  666. return err;
  667. }
  668. mpath = mesh_path_lookup(dst, sdata);
  669. if (!mpath) {
  670. rcu_read_unlock();
  671. return -ENXIO;
  672. }
  673. mesh_path_fix_nexthop(mpath, sta);
  674. rcu_read_unlock();
  675. return 0;
  676. }
  677. static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
  678. u8 *dst)
  679. {
  680. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  681. if (dst)
  682. return mesh_path_del(dst, sdata);
  683. mesh_path_flush(sdata);
  684. return 0;
  685. }
  686. static int ieee80211_change_mpath(struct wiphy *wiphy,
  687. struct net_device *dev,
  688. u8 *dst, u8 *next_hop)
  689. {
  690. struct ieee80211_local *local = wiphy_priv(wiphy);
  691. struct ieee80211_sub_if_data *sdata;
  692. struct mesh_path *mpath;
  693. struct sta_info *sta;
  694. if (!netif_running(dev))
  695. return -ENETDOWN;
  696. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  697. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  698. return -ENOTSUPP;
  699. rcu_read_lock();
  700. sta = sta_info_get(local, next_hop);
  701. if (!sta) {
  702. rcu_read_unlock();
  703. return -ENOENT;
  704. }
  705. mpath = mesh_path_lookup(dst, sdata);
  706. if (!mpath) {
  707. rcu_read_unlock();
  708. return -ENOENT;
  709. }
  710. mesh_path_fix_nexthop(mpath, sta);
  711. rcu_read_unlock();
  712. return 0;
  713. }
  714. static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
  715. struct mpath_info *pinfo)
  716. {
  717. if (mpath->next_hop)
  718. memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
  719. else
  720. memset(next_hop, 0, ETH_ALEN);
  721. pinfo->filled = MPATH_INFO_FRAME_QLEN |
  722. MPATH_INFO_DSN |
  723. MPATH_INFO_METRIC |
  724. MPATH_INFO_EXPTIME |
  725. MPATH_INFO_DISCOVERY_TIMEOUT |
  726. MPATH_INFO_DISCOVERY_RETRIES |
  727. MPATH_INFO_FLAGS;
  728. pinfo->frame_qlen = mpath->frame_queue.qlen;
  729. pinfo->dsn = mpath->dsn;
  730. pinfo->metric = mpath->metric;
  731. if (time_before(jiffies, mpath->exp_time))
  732. pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
  733. pinfo->discovery_timeout =
  734. jiffies_to_msecs(mpath->discovery_timeout);
  735. pinfo->discovery_retries = mpath->discovery_retries;
  736. pinfo->flags = 0;
  737. if (mpath->flags & MESH_PATH_ACTIVE)
  738. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  739. if (mpath->flags & MESH_PATH_RESOLVING)
  740. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  741. if (mpath->flags & MESH_PATH_DSN_VALID)
  742. pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
  743. if (mpath->flags & MESH_PATH_FIXED)
  744. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  745. if (mpath->flags & MESH_PATH_RESOLVING)
  746. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  747. pinfo->flags = mpath->flags;
  748. }
  749. static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
  750. u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  751. {
  752. struct ieee80211_sub_if_data *sdata;
  753. struct mesh_path *mpath;
  754. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  755. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  756. return -ENOTSUPP;
  757. rcu_read_lock();
  758. mpath = mesh_path_lookup(dst, sdata);
  759. if (!mpath) {
  760. rcu_read_unlock();
  761. return -ENOENT;
  762. }
  763. memcpy(dst, mpath->dst, ETH_ALEN);
  764. mpath_set_pinfo(mpath, next_hop, pinfo);
  765. rcu_read_unlock();
  766. return 0;
  767. }
  768. static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
  769. int idx, u8 *dst, u8 *next_hop,
  770. struct mpath_info *pinfo)
  771. {
  772. struct ieee80211_sub_if_data *sdata;
  773. struct mesh_path *mpath;
  774. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  775. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  776. return -ENOTSUPP;
  777. rcu_read_lock();
  778. mpath = mesh_path_lookup_by_idx(idx, sdata);
  779. if (!mpath) {
  780. rcu_read_unlock();
  781. return -ENOENT;
  782. }
  783. memcpy(dst, mpath->dst, ETH_ALEN);
  784. mpath_set_pinfo(mpath, next_hop, pinfo);
  785. rcu_read_unlock();
  786. return 0;
  787. }
  788. static int ieee80211_get_mesh_params(struct wiphy *wiphy,
  789. struct net_device *dev,
  790. struct mesh_config *conf)
  791. {
  792. struct ieee80211_sub_if_data *sdata;
  793. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  794. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  795. return -ENOTSUPP;
  796. memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
  797. return 0;
  798. }
  799. static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  800. {
  801. return (mask >> (parm-1)) & 0x1;
  802. }
  803. static int ieee80211_set_mesh_params(struct wiphy *wiphy,
  804. struct net_device *dev,
  805. const struct mesh_config *nconf, u32 mask)
  806. {
  807. struct mesh_config *conf;
  808. struct ieee80211_sub_if_data *sdata;
  809. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  810. if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  811. return -ENOTSUPP;
  812. /* Set the config options which we are interested in setting */
  813. conf = &(sdata->u.mesh.mshcfg);
  814. if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
  815. conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
  816. if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
  817. conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
  818. if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
  819. conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
  820. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
  821. conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
  822. if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
  823. conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
  824. if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
  825. conf->dot11MeshTTL = nconf->dot11MeshTTL;
  826. if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
  827. conf->auto_open_plinks = nconf->auto_open_plinks;
  828. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  829. conf->dot11MeshHWMPmaxPREQretries =
  830. nconf->dot11MeshHWMPmaxPREQretries;
  831. if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  832. conf->path_refresh_time = nconf->path_refresh_time;
  833. if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  834. conf->min_discovery_timeout = nconf->min_discovery_timeout;
  835. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  836. conf->dot11MeshHWMPactivePathTimeout =
  837. nconf->dot11MeshHWMPactivePathTimeout;
  838. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  839. conf->dot11MeshHWMPpreqMinInterval =
  840. nconf->dot11MeshHWMPpreqMinInterval;
  841. if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
  842. mask))
  843. conf->dot11MeshHWMPnetDiameterTraversalTime =
  844. nconf->dot11MeshHWMPnetDiameterTraversalTime;
  845. return 0;
  846. }
  847. #endif
  848. static int ieee80211_change_bss(struct wiphy *wiphy,
  849. struct net_device *dev,
  850. struct bss_parameters *params)
  851. {
  852. struct ieee80211_sub_if_data *sdata;
  853. u32 changed = 0;
  854. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  855. if (sdata->vif.type != NL80211_IFTYPE_AP)
  856. return -EINVAL;
  857. if (params->use_cts_prot >= 0) {
  858. sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
  859. changed |= BSS_CHANGED_ERP_CTS_PROT;
  860. }
  861. if (params->use_short_preamble >= 0) {
  862. sdata->vif.bss_conf.use_short_preamble =
  863. params->use_short_preamble;
  864. changed |= BSS_CHANGED_ERP_PREAMBLE;
  865. }
  866. if (params->use_short_slot_time >= 0) {
  867. sdata->vif.bss_conf.use_short_slot =
  868. params->use_short_slot_time;
  869. changed |= BSS_CHANGED_ERP_SLOT;
  870. }
  871. if (params->basic_rates) {
  872. int i, j;
  873. u32 rates = 0;
  874. struct ieee80211_local *local = wiphy_priv(wiphy);
  875. struct ieee80211_supported_band *sband =
  876. wiphy->bands[local->oper_channel->band];
  877. for (i = 0; i < params->basic_rates_len; i++) {
  878. int rate = (params->basic_rates[i] & 0x7f) * 5;
  879. for (j = 0; j < sband->n_bitrates; j++) {
  880. if (sband->bitrates[j].bitrate == rate)
  881. rates |= BIT(j);
  882. }
  883. }
  884. sdata->vif.bss_conf.basic_rates = rates;
  885. changed |= BSS_CHANGED_BASIC_RATES;
  886. }
  887. ieee80211_bss_info_change_notify(sdata, changed);
  888. return 0;
  889. }
  890. static int ieee80211_set_txq_params(struct wiphy *wiphy,
  891. struct ieee80211_txq_params *params)
  892. {
  893. struct ieee80211_local *local = wiphy_priv(wiphy);
  894. struct ieee80211_tx_queue_params p;
  895. if (!local->ops->conf_tx)
  896. return -EOPNOTSUPP;
  897. memset(&p, 0, sizeof(p));
  898. p.aifs = params->aifs;
  899. p.cw_max = params->cwmax;
  900. p.cw_min = params->cwmin;
  901. p.txop = params->txop;
  902. if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
  903. printk(KERN_DEBUG "%s: failed to set TX queue "
  904. "parameters for queue %d\n", local->mdev->name,
  905. params->queue);
  906. return -EINVAL;
  907. }
  908. return 0;
  909. }
  910. static int ieee80211_set_channel(struct wiphy *wiphy,
  911. struct ieee80211_channel *chan,
  912. enum nl80211_channel_type channel_type)
  913. {
  914. struct ieee80211_local *local = wiphy_priv(wiphy);
  915. local->oper_channel = chan;
  916. local->oper_channel_type = channel_type;
  917. return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  918. }
  919. struct cfg80211_ops mac80211_config_ops = {
  920. .add_virtual_intf = ieee80211_add_iface,
  921. .del_virtual_intf = ieee80211_del_iface,
  922. .change_virtual_intf = ieee80211_change_iface,
  923. .add_key = ieee80211_add_key,
  924. .del_key = ieee80211_del_key,
  925. .get_key = ieee80211_get_key,
  926. .set_default_key = ieee80211_config_default_key,
  927. .add_beacon = ieee80211_add_beacon,
  928. .set_beacon = ieee80211_set_beacon,
  929. .del_beacon = ieee80211_del_beacon,
  930. .add_station = ieee80211_add_station,
  931. .del_station = ieee80211_del_station,
  932. .change_station = ieee80211_change_station,
  933. .get_station = ieee80211_get_station,
  934. .dump_station = ieee80211_dump_station,
  935. #ifdef CONFIG_MAC80211_MESH
  936. .add_mpath = ieee80211_add_mpath,
  937. .del_mpath = ieee80211_del_mpath,
  938. .change_mpath = ieee80211_change_mpath,
  939. .get_mpath = ieee80211_get_mpath,
  940. .dump_mpath = ieee80211_dump_mpath,
  941. .set_mesh_params = ieee80211_set_mesh_params,
  942. .get_mesh_params = ieee80211_get_mesh_params,
  943. #endif
  944. .change_bss = ieee80211_change_bss,
  945. .set_txq_params = ieee80211_set_txq_params,
  946. .set_channel = ieee80211_set_channel,
  947. };