wext.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/types.h>
  13. #include <linux/slab.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/wireless.h>
  18. #include <net/iw_handler.h>
  19. #include <asm/uaccess.h>
  20. #include <net/mac80211.h>
  21. #include "ieee80211_i.h"
  22. #include "led.h"
  23. #include "rate.h"
  24. #include "wpa.h"
  25. #include "aes_ccm.h"
  26. static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr,
  27. int idx, int alg, int remove,
  28. int set_tx_key, const u8 *_key,
  29. size_t key_len)
  30. {
  31. struct ieee80211_local *local = sdata->local;
  32. struct sta_info *sta;
  33. struct ieee80211_key *key;
  34. int err;
  35. if (alg == ALG_AES_CMAC) {
  36. if (idx < NUM_DEFAULT_KEYS ||
  37. idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
  38. printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d "
  39. "(BIP)\n", sdata->dev->name, idx);
  40. return -EINVAL;
  41. }
  42. } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
  43. printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
  44. sdata->dev->name, idx);
  45. return -EINVAL;
  46. }
  47. if (remove) {
  48. rcu_read_lock();
  49. err = 0;
  50. if (is_broadcast_ether_addr(sta_addr)) {
  51. key = sdata->keys[idx];
  52. } else {
  53. sta = sta_info_get(local, sta_addr);
  54. if (!sta) {
  55. err = -ENOENT;
  56. goto out_unlock;
  57. }
  58. key = sta->key;
  59. }
  60. ieee80211_key_free(key);
  61. } else {
  62. key = ieee80211_key_alloc(alg, idx, key_len, _key);
  63. if (!key)
  64. return -ENOMEM;
  65. sta = NULL;
  66. err = 0;
  67. rcu_read_lock();
  68. if (!is_broadcast_ether_addr(sta_addr)) {
  69. set_tx_key = 0;
  70. /*
  71. * According to the standard, the key index of a
  72. * pairwise key must be zero. However, some AP are
  73. * broken when it comes to WEP key indices, so we
  74. * work around this.
  75. */
  76. if (idx != 0 && alg != ALG_WEP) {
  77. ieee80211_key_free(key);
  78. err = -EINVAL;
  79. goto out_unlock;
  80. }
  81. sta = sta_info_get(local, sta_addr);
  82. if (!sta) {
  83. ieee80211_key_free(key);
  84. err = -ENOENT;
  85. goto out_unlock;
  86. }
  87. }
  88. if (alg == ALG_WEP &&
  89. key_len != LEN_WEP40 && key_len != LEN_WEP104) {
  90. ieee80211_key_free(key);
  91. err = -EINVAL;
  92. goto out_unlock;
  93. }
  94. ieee80211_key_link(key, sdata, sta);
  95. if (set_tx_key || (!sta && !sdata->default_key && key))
  96. ieee80211_set_default_key(sdata, idx);
  97. if (alg == ALG_AES_CMAC &&
  98. (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
  99. ieee80211_set_default_mgmt_key(sdata, idx);
  100. }
  101. out_unlock:
  102. rcu_read_unlock();
  103. return err;
  104. }
  105. static int ieee80211_ioctl_siwgenie(struct net_device *dev,
  106. struct iw_request_info *info,
  107. struct iw_point *data, char *extra)
  108. {
  109. struct ieee80211_sub_if_data *sdata;
  110. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  111. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  112. int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
  113. if (ret)
  114. return ret;
  115. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  116. sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
  117. ieee80211_sta_req_auth(sdata);
  118. return 0;
  119. }
  120. return -EOPNOTSUPP;
  121. }
  122. static int ieee80211_ioctl_siwfreq(struct net_device *dev,
  123. struct iw_request_info *info,
  124. struct iw_freq *freq, char *extra)
  125. {
  126. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  127. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  128. return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
  129. else if (sdata->vif.type == NL80211_IFTYPE_STATION)
  130. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
  131. /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
  132. if (freq->e == 0) {
  133. if (freq->m < 0) {
  134. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  135. sdata->u.mgd.flags |=
  136. IEEE80211_STA_AUTO_CHANNEL_SEL;
  137. return 0;
  138. } else
  139. return ieee80211_set_freq(sdata,
  140. ieee80211_channel_to_frequency(freq->m));
  141. } else {
  142. int i, div = 1000000;
  143. for (i = 0; i < freq->e; i++)
  144. div /= 10;
  145. if (div > 0)
  146. return ieee80211_set_freq(sdata, freq->m / div);
  147. else
  148. return -EINVAL;
  149. }
  150. }
  151. static int ieee80211_ioctl_giwfreq(struct net_device *dev,
  152. struct iw_request_info *info,
  153. struct iw_freq *freq, char *extra)
  154. {
  155. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  156. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  157. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  158. return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
  159. freq->m = local->oper_channel->center_freq;
  160. freq->e = 6;
  161. return 0;
  162. }
  163. static int ieee80211_ioctl_siwessid(struct net_device *dev,
  164. struct iw_request_info *info,
  165. struct iw_point *data, char *ssid)
  166. {
  167. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  168. size_t len = data->length;
  169. int ret;
  170. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  171. return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
  172. /* iwconfig uses nul termination in SSID.. */
  173. if (len > 0 && ssid[len - 1] == '\0')
  174. len--;
  175. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  176. if (data->flags)
  177. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  178. else
  179. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
  180. ret = ieee80211_sta_set_ssid(sdata, ssid, len);
  181. if (ret)
  182. return ret;
  183. sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
  184. ieee80211_sta_req_auth(sdata);
  185. return 0;
  186. }
  187. return -EOPNOTSUPP;
  188. }
  189. static int ieee80211_ioctl_giwessid(struct net_device *dev,
  190. struct iw_request_info *info,
  191. struct iw_point *data, char *ssid)
  192. {
  193. size_t len;
  194. struct ieee80211_sub_if_data *sdata;
  195. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  196. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  197. return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
  198. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  199. int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
  200. if (res == 0) {
  201. data->length = len;
  202. data->flags = 1;
  203. } else
  204. data->flags = 0;
  205. return res;
  206. }
  207. return -EOPNOTSUPP;
  208. }
  209. static int ieee80211_ioctl_siwap(struct net_device *dev,
  210. struct iw_request_info *info,
  211. struct sockaddr *ap_addr, char *extra)
  212. {
  213. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  214. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  215. return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
  216. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  217. int ret;
  218. if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
  219. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
  220. IEEE80211_STA_AUTO_CHANNEL_SEL;
  221. else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
  222. sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
  223. else
  224. sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  225. ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
  226. if (ret)
  227. return ret;
  228. sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
  229. ieee80211_sta_req_auth(sdata);
  230. return 0;
  231. } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
  232. /*
  233. * If it is necessary to update the WDS peer address
  234. * while the interface is running, then we need to do
  235. * more work here, namely if it is running we need to
  236. * add a new and remove the old STA entry, this is
  237. * normally handled by _open() and _stop().
  238. */
  239. if (netif_running(dev))
  240. return -EBUSY;
  241. memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
  242. ETH_ALEN);
  243. return 0;
  244. }
  245. return -EOPNOTSUPP;
  246. }
  247. static int ieee80211_ioctl_giwap(struct net_device *dev,
  248. struct iw_request_info *info,
  249. struct sockaddr *ap_addr, char *extra)
  250. {
  251. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  252. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  253. return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
  254. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  255. if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
  256. ap_addr->sa_family = ARPHRD_ETHER;
  257. memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
  258. } else
  259. memset(&ap_addr->sa_data, 0, ETH_ALEN);
  260. return 0;
  261. } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
  262. ap_addr->sa_family = ARPHRD_ETHER;
  263. memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
  264. return 0;
  265. }
  266. return -EOPNOTSUPP;
  267. }
  268. static int ieee80211_ioctl_siwrate(struct net_device *dev,
  269. struct iw_request_info *info,
  270. struct iw_param *rate, char *extra)
  271. {
  272. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  273. int i, err = -EINVAL;
  274. u32 target_rate = rate->value / 100000;
  275. struct ieee80211_sub_if_data *sdata;
  276. struct ieee80211_supported_band *sband;
  277. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  278. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  279. /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
  280. * target_rate = X, rate->fixed = 1 means only rate X
  281. * target_rate = X, rate->fixed = 0 means all rates <= X */
  282. sdata->max_ratectrl_rateidx = -1;
  283. sdata->force_unicast_rateidx = -1;
  284. if (rate->value < 0)
  285. return 0;
  286. for (i=0; i< sband->n_bitrates; i++) {
  287. struct ieee80211_rate *brate = &sband->bitrates[i];
  288. int this_rate = brate->bitrate;
  289. if (target_rate == this_rate) {
  290. sdata->max_ratectrl_rateidx = i;
  291. if (rate->fixed)
  292. sdata->force_unicast_rateidx = i;
  293. err = 0;
  294. break;
  295. }
  296. }
  297. return err;
  298. }
  299. static int ieee80211_ioctl_giwrate(struct net_device *dev,
  300. struct iw_request_info *info,
  301. struct iw_param *rate, char *extra)
  302. {
  303. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  304. struct sta_info *sta;
  305. struct ieee80211_sub_if_data *sdata;
  306. struct ieee80211_supported_band *sband;
  307. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  308. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  309. return -EOPNOTSUPP;
  310. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  311. rcu_read_lock();
  312. sta = sta_info_get(local, sdata->u.mgd.bssid);
  313. if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
  314. rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
  315. else
  316. rate->value = 0;
  317. rcu_read_unlock();
  318. if (!sta)
  319. return -ENODEV;
  320. rate->value *= 100000;
  321. return 0;
  322. }
  323. static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
  324. struct iw_request_info *info,
  325. union iwreq_data *data, char *extra)
  326. {
  327. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  328. struct ieee80211_channel* chan = local->hw.conf.channel;
  329. bool reconf = false;
  330. u32 reconf_flags = 0;
  331. int new_power_level;
  332. if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
  333. return -EINVAL;
  334. if (data->txpower.flags & IW_TXPOW_RANGE)
  335. return -EINVAL;
  336. if (!chan)
  337. return -EINVAL;
  338. /* only change when not disabling */
  339. if (!data->txpower.disabled) {
  340. if (data->txpower.fixed) {
  341. if (data->txpower.value < 0)
  342. return -EINVAL;
  343. new_power_level = data->txpower.value;
  344. /*
  345. * Debatable, but we cannot do a fixed power
  346. * level above the regulatory constraint.
  347. * Use "iwconfig wlan0 txpower 15dBm" instead.
  348. */
  349. if (new_power_level > chan->max_power)
  350. return -EINVAL;
  351. } else {
  352. /*
  353. * Automatic power level setting, max being the value
  354. * passed in from userland.
  355. */
  356. if (data->txpower.value < 0)
  357. new_power_level = -1;
  358. else
  359. new_power_level = data->txpower.value;
  360. }
  361. reconf = true;
  362. /*
  363. * ieee80211_hw_config() will limit to the channel's
  364. * max power and possibly power constraint from AP.
  365. */
  366. local->user_power_level = new_power_level;
  367. }
  368. if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
  369. local->hw.conf.radio_enabled = !(data->txpower.disabled);
  370. reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
  371. ieee80211_led_radio(local, local->hw.conf.radio_enabled);
  372. }
  373. if (reconf || reconf_flags)
  374. ieee80211_hw_config(local, reconf_flags);
  375. return 0;
  376. }
  377. static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
  378. struct iw_request_info *info,
  379. union iwreq_data *data, char *extra)
  380. {
  381. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  382. data->txpower.fixed = 1;
  383. data->txpower.disabled = !(local->hw.conf.radio_enabled);
  384. data->txpower.value = local->hw.conf.power_level;
  385. data->txpower.flags = IW_TXPOW_DBM;
  386. return 0;
  387. }
  388. static int ieee80211_ioctl_siwencode(struct net_device *dev,
  389. struct iw_request_info *info,
  390. struct iw_point *erq, char *keybuf)
  391. {
  392. struct ieee80211_sub_if_data *sdata;
  393. int idx, i, alg = ALG_WEP;
  394. u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  395. int remove = 0, ret;
  396. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  397. idx = erq->flags & IW_ENCODE_INDEX;
  398. if (idx == 0) {
  399. if (sdata->default_key)
  400. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  401. if (sdata->default_key == sdata->keys[i]) {
  402. idx = i;
  403. break;
  404. }
  405. }
  406. } else if (idx < 1 || idx > 4)
  407. return -EINVAL;
  408. else
  409. idx--;
  410. if (erq->flags & IW_ENCODE_DISABLED)
  411. remove = 1;
  412. else if (erq->length == 0) {
  413. /* No key data - just set the default TX key index */
  414. ieee80211_set_default_key(sdata, idx);
  415. return 0;
  416. }
  417. ret = ieee80211_set_encryption(
  418. sdata, bcaddr,
  419. idx, alg, remove,
  420. !sdata->default_key,
  421. keybuf, erq->length);
  422. if (!ret && sdata->vif.type == NL80211_IFTYPE_STATION) {
  423. if (remove)
  424. sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
  425. else
  426. sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
  427. }
  428. return ret;
  429. }
  430. static int ieee80211_ioctl_giwencode(struct net_device *dev,
  431. struct iw_request_info *info,
  432. struct iw_point *erq, char *key)
  433. {
  434. struct ieee80211_sub_if_data *sdata;
  435. int idx, i;
  436. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  437. idx = erq->flags & IW_ENCODE_INDEX;
  438. if (idx < 1 || idx > 4) {
  439. idx = -1;
  440. if (!sdata->default_key)
  441. idx = 0;
  442. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  443. if (sdata->default_key == sdata->keys[i]) {
  444. idx = i;
  445. break;
  446. }
  447. }
  448. if (idx < 0)
  449. return -EINVAL;
  450. } else
  451. idx--;
  452. erq->flags = idx + 1;
  453. if (!sdata->keys[idx]) {
  454. erq->length = 0;
  455. erq->flags |= IW_ENCODE_DISABLED;
  456. return 0;
  457. }
  458. memcpy(key, sdata->keys[idx]->conf.key,
  459. min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
  460. erq->length = sdata->keys[idx]->conf.keylen;
  461. erq->flags |= IW_ENCODE_ENABLED;
  462. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  463. switch (sdata->u.mgd.auth_alg) {
  464. case WLAN_AUTH_OPEN:
  465. case WLAN_AUTH_LEAP:
  466. erq->flags |= IW_ENCODE_OPEN;
  467. break;
  468. case WLAN_AUTH_SHARED_KEY:
  469. erq->flags |= IW_ENCODE_RESTRICTED;
  470. break;
  471. }
  472. }
  473. return 0;
  474. }
  475. static int ieee80211_ioctl_siwpower(struct net_device *dev,
  476. struct iw_request_info *info,
  477. struct iw_param *wrq,
  478. char *extra)
  479. {
  480. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  481. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  482. struct ieee80211_conf *conf = &local->hw.conf;
  483. int timeout = 0;
  484. bool ps;
  485. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  486. return -EOPNOTSUPP;
  487. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  488. return -EINVAL;
  489. if (wrq->disabled) {
  490. ps = false;
  491. timeout = 0;
  492. goto set;
  493. }
  494. switch (wrq->flags & IW_POWER_MODE) {
  495. case IW_POWER_ON: /* If not specified */
  496. case IW_POWER_MODE: /* If set all mask */
  497. case IW_POWER_ALL_R: /* If explicitely state all */
  498. ps = true;
  499. break;
  500. default: /* Otherwise we ignore */
  501. return -EINVAL;
  502. }
  503. if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
  504. return -EINVAL;
  505. if (wrq->flags & IW_POWER_TIMEOUT)
  506. timeout = wrq->value / 1000;
  507. set:
  508. if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
  509. return 0;
  510. sdata->u.mgd.powersave = ps;
  511. conf->dynamic_ps_timeout = timeout;
  512. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  513. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  514. ieee80211_recalc_ps(local, -1);
  515. return 0;
  516. }
  517. static int ieee80211_ioctl_giwpower(struct net_device *dev,
  518. struct iw_request_info *info,
  519. union iwreq_data *wrqu,
  520. char *extra)
  521. {
  522. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  523. wrqu->power.disabled = !sdata->u.mgd.powersave;
  524. return 0;
  525. }
  526. static int ieee80211_ioctl_siwauth(struct net_device *dev,
  527. struct iw_request_info *info,
  528. struct iw_param *data, char *extra)
  529. {
  530. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  531. int ret = 0;
  532. switch (data->flags & IW_AUTH_INDEX) {
  533. case IW_AUTH_WPA_VERSION:
  534. case IW_AUTH_CIPHER_GROUP:
  535. case IW_AUTH_WPA_ENABLED:
  536. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  537. case IW_AUTH_KEY_MGMT:
  538. case IW_AUTH_CIPHER_GROUP_MGMT:
  539. break;
  540. case IW_AUTH_CIPHER_PAIRWISE:
  541. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  542. if (data->value & (IW_AUTH_CIPHER_WEP40 |
  543. IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
  544. sdata->u.mgd.flags |=
  545. IEEE80211_STA_TKIP_WEP_USED;
  546. else
  547. sdata->u.mgd.flags &=
  548. ~IEEE80211_STA_TKIP_WEP_USED;
  549. }
  550. break;
  551. case IW_AUTH_DROP_UNENCRYPTED:
  552. sdata->drop_unencrypted = !!data->value;
  553. break;
  554. case IW_AUTH_PRIVACY_INVOKED:
  555. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  556. ret = -EINVAL;
  557. else {
  558. sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
  559. /*
  560. * Privacy invoked by wpa_supplicant, store the
  561. * value and allow associating to a protected
  562. * network without having a key up front.
  563. */
  564. if (data->value)
  565. sdata->u.mgd.flags |=
  566. IEEE80211_STA_PRIVACY_INVOKED;
  567. }
  568. break;
  569. case IW_AUTH_80211_AUTH_ALG:
  570. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  571. sdata->u.mgd.auth_algs = data->value;
  572. else
  573. ret = -EOPNOTSUPP;
  574. break;
  575. case IW_AUTH_MFP:
  576. if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
  577. ret = -EOPNOTSUPP;
  578. break;
  579. }
  580. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  581. switch (data->value) {
  582. case IW_AUTH_MFP_DISABLED:
  583. sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
  584. break;
  585. case IW_AUTH_MFP_OPTIONAL:
  586. sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
  587. break;
  588. case IW_AUTH_MFP_REQUIRED:
  589. sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
  590. break;
  591. default:
  592. ret = -EINVAL;
  593. }
  594. } else
  595. ret = -EOPNOTSUPP;
  596. break;
  597. default:
  598. ret = -EOPNOTSUPP;
  599. break;
  600. }
  601. return ret;
  602. }
  603. /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
  604. static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
  605. {
  606. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  607. struct iw_statistics *wstats = &local->wstats;
  608. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  609. struct sta_info *sta = NULL;
  610. rcu_read_lock();
  611. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  612. sta = sta_info_get(local, sdata->u.mgd.bssid);
  613. if (!sta) {
  614. wstats->discard.fragment = 0;
  615. wstats->discard.misc = 0;
  616. wstats->qual.qual = 0;
  617. wstats->qual.level = 0;
  618. wstats->qual.noise = 0;
  619. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  620. } else {
  621. wstats->qual.updated = 0;
  622. /*
  623. * mirror what cfg80211 does for iwrange/scan results,
  624. * otherwise userspace gets confused.
  625. */
  626. if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
  627. IEEE80211_HW_SIGNAL_DBM)) {
  628. wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
  629. wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
  630. } else {
  631. wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
  632. wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
  633. }
  634. if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
  635. wstats->qual.level = sta->last_signal;
  636. wstats->qual.qual = sta->last_signal;
  637. } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  638. int sig = sta->last_signal;
  639. wstats->qual.updated |= IW_QUAL_DBM;
  640. wstats->qual.level = sig;
  641. if (sig < -110)
  642. sig = -110;
  643. else if (sig > -40)
  644. sig = -40;
  645. wstats->qual.qual = sig + 110;
  646. }
  647. if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
  648. /*
  649. * This assumes that if driver reports noise, it also
  650. * reports signal in dBm.
  651. */
  652. wstats->qual.noise = sta->last_noise;
  653. wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
  654. } else {
  655. wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
  656. }
  657. }
  658. rcu_read_unlock();
  659. return wstats;
  660. }
  661. static int ieee80211_ioctl_giwauth(struct net_device *dev,
  662. struct iw_request_info *info,
  663. struct iw_param *data, char *extra)
  664. {
  665. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  666. int ret = 0;
  667. switch (data->flags & IW_AUTH_INDEX) {
  668. case IW_AUTH_80211_AUTH_ALG:
  669. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  670. data->value = sdata->u.mgd.auth_algs;
  671. else
  672. ret = -EOPNOTSUPP;
  673. break;
  674. default:
  675. ret = -EOPNOTSUPP;
  676. break;
  677. }
  678. return ret;
  679. }
  680. static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
  681. struct iw_request_info *info,
  682. struct iw_point *erq, char *extra)
  683. {
  684. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  685. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  686. int uninitialized_var(alg), idx, i, remove = 0;
  687. switch (ext->alg) {
  688. case IW_ENCODE_ALG_NONE:
  689. remove = 1;
  690. break;
  691. case IW_ENCODE_ALG_WEP:
  692. alg = ALG_WEP;
  693. break;
  694. case IW_ENCODE_ALG_TKIP:
  695. alg = ALG_TKIP;
  696. break;
  697. case IW_ENCODE_ALG_CCMP:
  698. alg = ALG_CCMP;
  699. break;
  700. case IW_ENCODE_ALG_AES_CMAC:
  701. alg = ALG_AES_CMAC;
  702. break;
  703. default:
  704. return -EOPNOTSUPP;
  705. }
  706. if (erq->flags & IW_ENCODE_DISABLED)
  707. remove = 1;
  708. idx = erq->flags & IW_ENCODE_INDEX;
  709. if (alg == ALG_AES_CMAC) {
  710. if (idx < NUM_DEFAULT_KEYS + 1 ||
  711. idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
  712. idx = -1;
  713. if (!sdata->default_mgmt_key)
  714. idx = 0;
  715. else for (i = NUM_DEFAULT_KEYS;
  716. i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
  717. i++) {
  718. if (sdata->default_mgmt_key == sdata->keys[i])
  719. {
  720. idx = i;
  721. break;
  722. }
  723. }
  724. if (idx < 0)
  725. return -EINVAL;
  726. } else
  727. idx--;
  728. } else {
  729. if (idx < 1 || idx > 4) {
  730. idx = -1;
  731. if (!sdata->default_key)
  732. idx = 0;
  733. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  734. if (sdata->default_key == sdata->keys[i]) {
  735. idx = i;
  736. break;
  737. }
  738. }
  739. if (idx < 0)
  740. return -EINVAL;
  741. } else
  742. idx--;
  743. }
  744. return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
  745. remove,
  746. ext->ext_flags &
  747. IW_ENCODE_EXT_SET_TX_KEY,
  748. ext->key, ext->key_len);
  749. }
  750. /* Structures to export the Wireless Handlers */
  751. static const iw_handler ieee80211_handler[] =
  752. {
  753. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  754. (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
  755. (iw_handler) NULL, /* SIOCSIWNWID */
  756. (iw_handler) NULL, /* SIOCGIWNWID */
  757. (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
  758. (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
  759. (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
  760. (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
  761. (iw_handler) NULL, /* SIOCSIWSENS */
  762. (iw_handler) NULL, /* SIOCGIWSENS */
  763. (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
  764. (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
  765. (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
  766. (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
  767. (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
  768. (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
  769. (iw_handler) NULL, /* SIOCSIWSPY */
  770. (iw_handler) NULL, /* SIOCGIWSPY */
  771. (iw_handler) NULL, /* SIOCSIWTHRSPY */
  772. (iw_handler) NULL, /* SIOCGIWTHRSPY */
  773. (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
  774. (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
  775. (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
  776. (iw_handler) NULL, /* SIOCGIWAPLIST */
  777. (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
  778. (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
  779. (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
  780. (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
  781. (iw_handler) NULL, /* SIOCSIWNICKN */
  782. (iw_handler) NULL, /* SIOCGIWNICKN */
  783. (iw_handler) NULL, /* -- hole -- */
  784. (iw_handler) NULL, /* -- hole -- */
  785. (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
  786. (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
  787. (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
  788. (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
  789. (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
  790. (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
  791. (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
  792. (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
  793. (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
  794. (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
  795. (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
  796. (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
  797. (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
  798. (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
  799. (iw_handler) NULL, /* -- hole -- */
  800. (iw_handler) NULL, /* -- hole -- */
  801. (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
  802. (iw_handler) NULL, /* SIOCGIWGENIE */
  803. (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
  804. (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
  805. (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
  806. (iw_handler) NULL, /* SIOCGIWENCODEEXT */
  807. (iw_handler) NULL, /* SIOCSIWPMKSA */
  808. (iw_handler) NULL, /* -- hole -- */
  809. };
  810. const struct iw_handler_def ieee80211_iw_handler_def =
  811. {
  812. .num_standard = ARRAY_SIZE(ieee80211_handler),
  813. .standard = (iw_handler *) ieee80211_handler,
  814. .get_wireless_stats = ieee80211_get_wireless_stats,
  815. };