wext.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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 (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
  36. printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
  37. sdata->dev->name, idx);
  38. return -EINVAL;
  39. }
  40. if (remove) {
  41. rcu_read_lock();
  42. err = 0;
  43. if (is_broadcast_ether_addr(sta_addr)) {
  44. key = sdata->keys[idx];
  45. } else {
  46. sta = sta_info_get(local, sta_addr);
  47. if (!sta) {
  48. err = -ENOENT;
  49. goto out_unlock;
  50. }
  51. key = sta->key;
  52. }
  53. ieee80211_key_free(key);
  54. } else {
  55. key = ieee80211_key_alloc(alg, idx, key_len, _key);
  56. if (!key)
  57. return -ENOMEM;
  58. sta = NULL;
  59. err = 0;
  60. rcu_read_lock();
  61. if (!is_broadcast_ether_addr(sta_addr)) {
  62. set_tx_key = 0;
  63. /*
  64. * According to the standard, the key index of a
  65. * pairwise key must be zero. However, some AP are
  66. * broken when it comes to WEP key indices, so we
  67. * work around this.
  68. */
  69. if (idx != 0 && alg != ALG_WEP) {
  70. ieee80211_key_free(key);
  71. err = -EINVAL;
  72. goto out_unlock;
  73. }
  74. sta = sta_info_get(local, sta_addr);
  75. if (!sta) {
  76. ieee80211_key_free(key);
  77. err = -ENOENT;
  78. goto out_unlock;
  79. }
  80. }
  81. if (alg == ALG_WEP &&
  82. key_len != LEN_WEP40 && key_len != LEN_WEP104) {
  83. ieee80211_key_free(key);
  84. err = -EINVAL;
  85. goto out_unlock;
  86. }
  87. ieee80211_key_link(key, sdata, sta);
  88. if (set_tx_key || (!sta && !sdata->default_key && key))
  89. ieee80211_set_default_key(sdata, idx);
  90. }
  91. out_unlock:
  92. rcu_read_unlock();
  93. return err;
  94. }
  95. static int ieee80211_ioctl_siwgenie(struct net_device *dev,
  96. struct iw_request_info *info,
  97. struct iw_point *data, char *extra)
  98. {
  99. struct ieee80211_sub_if_data *sdata;
  100. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  101. if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
  102. return -EOPNOTSUPP;
  103. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  104. sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  105. int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
  106. if (ret)
  107. return ret;
  108. sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  109. ieee80211_sta_req_auth(sdata, &sdata->u.sta);
  110. return 0;
  111. }
  112. return -EOPNOTSUPP;
  113. }
  114. static int ieee80211_ioctl_giwrange(struct net_device *dev,
  115. struct iw_request_info *info,
  116. struct iw_point *data, char *extra)
  117. {
  118. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  119. struct iw_range *range = (struct iw_range *) extra;
  120. enum ieee80211_band band;
  121. int c = 0;
  122. data->length = sizeof(struct iw_range);
  123. memset(range, 0, sizeof(struct iw_range));
  124. range->we_version_compiled = WIRELESS_EXT;
  125. range->we_version_source = 21;
  126. range->retry_capa = IW_RETRY_LIMIT;
  127. range->retry_flags = IW_RETRY_LIMIT;
  128. range->min_retry = 0;
  129. range->max_retry = 255;
  130. range->min_rts = 0;
  131. range->max_rts = 2347;
  132. range->min_frag = 256;
  133. range->max_frag = 2346;
  134. range->encoding_size[0] = 5;
  135. range->encoding_size[1] = 13;
  136. range->num_encoding_sizes = 2;
  137. range->max_encoding_tokens = NUM_DEFAULT_KEYS;
  138. if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC ||
  139. local->hw.flags & IEEE80211_HW_SIGNAL_DB)
  140. range->max_qual.level = local->hw.max_signal;
  141. else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  142. range->max_qual.level = -110;
  143. else
  144. range->max_qual.level = 0;
  145. if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
  146. range->max_qual.noise = -110;
  147. else
  148. range->max_qual.noise = 0;
  149. range->max_qual.qual = 100;
  150. range->max_qual.updated = local->wstats_flags;
  151. range->avg_qual.qual = 50;
  152. /* not always true but better than nothing */
  153. range->avg_qual.level = range->max_qual.level / 2;
  154. range->avg_qual.noise = range->max_qual.noise / 2;
  155. range->avg_qual.updated = local->wstats_flags;
  156. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
  157. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  158. for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
  159. int i;
  160. struct ieee80211_supported_band *sband;
  161. sband = local->hw.wiphy->bands[band];
  162. if (!sband)
  163. continue;
  164. for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
  165. struct ieee80211_channel *chan = &sband->channels[i];
  166. if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
  167. range->freq[c].i =
  168. ieee80211_frequency_to_channel(
  169. chan->center_freq);
  170. range->freq[c].m = chan->center_freq;
  171. range->freq[c].e = 6;
  172. c++;
  173. }
  174. }
  175. }
  176. range->num_channels = c;
  177. range->num_frequency = c;
  178. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  179. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  180. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  181. range->scan_capa |= IW_SCAN_CAPA_ESSID;
  182. return 0;
  183. }
  184. static int ieee80211_ioctl_siwfreq(struct net_device *dev,
  185. struct iw_request_info *info,
  186. struct iw_freq *freq, char *extra)
  187. {
  188. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  189. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  190. sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
  191. /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
  192. if (freq->e == 0) {
  193. if (freq->m < 0) {
  194. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  195. sdata->u.sta.flags |=
  196. IEEE80211_STA_AUTO_CHANNEL_SEL;
  197. return 0;
  198. } else
  199. return ieee80211_set_freq(sdata,
  200. ieee80211_channel_to_frequency(freq->m));
  201. } else {
  202. int i, div = 1000000;
  203. for (i = 0; i < freq->e; i++)
  204. div /= 10;
  205. if (div > 0)
  206. return ieee80211_set_freq(sdata, freq->m / div);
  207. else
  208. return -EINVAL;
  209. }
  210. }
  211. static int ieee80211_ioctl_giwfreq(struct net_device *dev,
  212. struct iw_request_info *info,
  213. struct iw_freq *freq, char *extra)
  214. {
  215. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  216. freq->m = local->hw.conf.channel->center_freq;
  217. freq->e = 6;
  218. return 0;
  219. }
  220. static int ieee80211_ioctl_siwessid(struct net_device *dev,
  221. struct iw_request_info *info,
  222. struct iw_point *data, char *ssid)
  223. {
  224. struct ieee80211_sub_if_data *sdata;
  225. size_t len = data->length;
  226. /* iwconfig uses nul termination in SSID.. */
  227. if (len > 0 && ssid[len - 1] == '\0')
  228. len--;
  229. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  230. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  231. sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  232. int ret;
  233. if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
  234. if (len > IEEE80211_MAX_SSID_LEN)
  235. return -EINVAL;
  236. memcpy(sdata->u.sta.ssid, ssid, len);
  237. sdata->u.sta.ssid_len = len;
  238. return 0;
  239. }
  240. if (data->flags)
  241. sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
  242. else
  243. sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
  244. ret = ieee80211_sta_set_ssid(sdata, ssid, len);
  245. if (ret)
  246. return ret;
  247. ieee80211_sta_req_auth(sdata, &sdata->u.sta);
  248. return 0;
  249. }
  250. return -EOPNOTSUPP;
  251. }
  252. static int ieee80211_ioctl_giwessid(struct net_device *dev,
  253. struct iw_request_info *info,
  254. struct iw_point *data, char *ssid)
  255. {
  256. size_t len;
  257. struct ieee80211_sub_if_data *sdata;
  258. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  259. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  260. sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  261. int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
  262. if (res == 0) {
  263. data->length = len;
  264. data->flags = 1;
  265. } else
  266. data->flags = 0;
  267. return res;
  268. }
  269. return -EOPNOTSUPP;
  270. }
  271. static int ieee80211_ioctl_siwap(struct net_device *dev,
  272. struct iw_request_info *info,
  273. struct sockaddr *ap_addr, char *extra)
  274. {
  275. struct ieee80211_sub_if_data *sdata;
  276. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  277. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  278. sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  279. int ret;
  280. if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
  281. memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
  282. ETH_ALEN);
  283. return 0;
  284. }
  285. if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
  286. sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
  287. IEEE80211_STA_AUTO_CHANNEL_SEL;
  288. else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
  289. sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
  290. else
  291. sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
  292. ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
  293. if (ret)
  294. return ret;
  295. ieee80211_sta_req_auth(sdata, &sdata->u.sta);
  296. return 0;
  297. } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
  298. /*
  299. * If it is necessary to update the WDS peer address
  300. * while the interface is running, then we need to do
  301. * more work here, namely if it is running we need to
  302. * add a new and remove the old STA entry, this is
  303. * normally handled by _open() and _stop().
  304. */
  305. if (netif_running(dev))
  306. return -EBUSY;
  307. memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
  308. ETH_ALEN);
  309. return 0;
  310. }
  311. return -EOPNOTSUPP;
  312. }
  313. static int ieee80211_ioctl_giwap(struct net_device *dev,
  314. struct iw_request_info *info,
  315. struct sockaddr *ap_addr, char *extra)
  316. {
  317. struct ieee80211_sub_if_data *sdata;
  318. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  319. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  320. sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  321. if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
  322. sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
  323. ap_addr->sa_family = ARPHRD_ETHER;
  324. memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
  325. return 0;
  326. } else {
  327. memset(&ap_addr->sa_data, 0, ETH_ALEN);
  328. return 0;
  329. }
  330. } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
  331. ap_addr->sa_family = ARPHRD_ETHER;
  332. memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
  333. return 0;
  334. }
  335. return -EOPNOTSUPP;
  336. }
  337. static int ieee80211_ioctl_siwscan(struct net_device *dev,
  338. struct iw_request_info *info,
  339. union iwreq_data *wrqu, char *extra)
  340. {
  341. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  342. struct iw_scan_req *req = NULL;
  343. u8 *ssid = NULL;
  344. size_t ssid_len = 0;
  345. if (!netif_running(dev))
  346. return -ENETDOWN;
  347. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  348. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  349. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  350. return -EOPNOTSUPP;
  351. /* if SSID was specified explicitly then use that */
  352. if (wrqu->data.length == sizeof(struct iw_scan_req) &&
  353. wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  354. req = (struct iw_scan_req *)extra;
  355. ssid = req->essid;
  356. ssid_len = req->essid_len;
  357. }
  358. return ieee80211_request_scan(sdata, ssid, ssid_len);
  359. }
  360. static int ieee80211_ioctl_giwscan(struct net_device *dev,
  361. struct iw_request_info *info,
  362. struct iw_point *data, char *extra)
  363. {
  364. int res;
  365. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  366. struct ieee80211_sub_if_data *sdata;
  367. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  368. if (local->sw_scanning || local->hw_scanning)
  369. return -EAGAIN;
  370. res = ieee80211_scan_results(local, info, extra, data->length);
  371. if (res >= 0) {
  372. data->length = res;
  373. return 0;
  374. }
  375. data->length = 0;
  376. return res;
  377. }
  378. static int ieee80211_ioctl_siwrate(struct net_device *dev,
  379. struct iw_request_info *info,
  380. struct iw_param *rate, char *extra)
  381. {
  382. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  383. int i, err = -EINVAL;
  384. u32 target_rate = rate->value / 100000;
  385. struct ieee80211_sub_if_data *sdata;
  386. struct ieee80211_supported_band *sband;
  387. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  388. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  389. /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
  390. * target_rate = X, rate->fixed = 1 means only rate X
  391. * target_rate = X, rate->fixed = 0 means all rates <= X */
  392. sdata->max_ratectrl_rateidx = -1;
  393. sdata->force_unicast_rateidx = -1;
  394. if (rate->value < 0)
  395. return 0;
  396. for (i=0; i< sband->n_bitrates; i++) {
  397. struct ieee80211_rate *brate = &sband->bitrates[i];
  398. int this_rate = brate->bitrate;
  399. if (target_rate == this_rate) {
  400. sdata->max_ratectrl_rateidx = i;
  401. if (rate->fixed)
  402. sdata->force_unicast_rateidx = i;
  403. err = 0;
  404. break;
  405. }
  406. }
  407. return err;
  408. }
  409. static int ieee80211_ioctl_giwrate(struct net_device *dev,
  410. struct iw_request_info *info,
  411. struct iw_param *rate, char *extra)
  412. {
  413. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  414. struct sta_info *sta;
  415. struct ieee80211_sub_if_data *sdata;
  416. struct ieee80211_supported_band *sband;
  417. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  418. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  419. return -EOPNOTSUPP;
  420. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  421. rcu_read_lock();
  422. sta = sta_info_get(local, sdata->u.sta.bssid);
  423. if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
  424. rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
  425. else
  426. rate->value = 0;
  427. rcu_read_unlock();
  428. if (!sta)
  429. return -ENODEV;
  430. rate->value *= 100000;
  431. return 0;
  432. }
  433. static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
  434. struct iw_request_info *info,
  435. union iwreq_data *data, char *extra)
  436. {
  437. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  438. struct ieee80211_channel* chan = local->hw.conf.channel;
  439. u32 reconf_flags = 0;
  440. int new_power_level;
  441. if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
  442. return -EINVAL;
  443. if (data->txpower.flags & IW_TXPOW_RANGE)
  444. return -EINVAL;
  445. if (!chan)
  446. return -EINVAL;
  447. if (data->txpower.fixed)
  448. new_power_level = min(data->txpower.value, chan->max_power);
  449. else /* Automatic power level setting */
  450. new_power_level = chan->max_power;
  451. if (local->hw.conf.power_level != new_power_level) {
  452. local->hw.conf.power_level = new_power_level;
  453. reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
  454. }
  455. if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
  456. local->hw.conf.radio_enabled = !(data->txpower.disabled);
  457. reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
  458. ieee80211_led_radio(local, local->hw.conf.radio_enabled);
  459. }
  460. if (reconf_flags)
  461. ieee80211_hw_config(local, reconf_flags);
  462. return 0;
  463. }
  464. static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
  465. struct iw_request_info *info,
  466. union iwreq_data *data, char *extra)
  467. {
  468. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  469. data->txpower.fixed = 1;
  470. data->txpower.disabled = !(local->hw.conf.radio_enabled);
  471. data->txpower.value = local->hw.conf.power_level;
  472. data->txpower.flags = IW_TXPOW_DBM;
  473. return 0;
  474. }
  475. static int ieee80211_ioctl_siwrts(struct net_device *dev,
  476. struct iw_request_info *info,
  477. struct iw_param *rts, char *extra)
  478. {
  479. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  480. if (rts->disabled)
  481. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  482. else if (!rts->fixed)
  483. /* if the rts value is not fixed, then take default */
  484. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  485. else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
  486. return -EINVAL;
  487. else
  488. local->rts_threshold = rts->value;
  489. /* If the wlan card performs RTS/CTS in hardware/firmware,
  490. * configure it here */
  491. if (local->ops->set_rts_threshold)
  492. local->ops->set_rts_threshold(local_to_hw(local),
  493. local->rts_threshold);
  494. return 0;
  495. }
  496. static int ieee80211_ioctl_giwrts(struct net_device *dev,
  497. struct iw_request_info *info,
  498. struct iw_param *rts, char *extra)
  499. {
  500. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  501. rts->value = local->rts_threshold;
  502. rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
  503. rts->fixed = 1;
  504. return 0;
  505. }
  506. static int ieee80211_ioctl_siwfrag(struct net_device *dev,
  507. struct iw_request_info *info,
  508. struct iw_param *frag, char *extra)
  509. {
  510. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  511. if (frag->disabled)
  512. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  513. else if (!frag->fixed)
  514. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  515. else if (frag->value < 256 ||
  516. frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
  517. return -EINVAL;
  518. else {
  519. /* Fragment length must be even, so strip LSB. */
  520. local->fragmentation_threshold = frag->value & ~0x1;
  521. }
  522. return 0;
  523. }
  524. static int ieee80211_ioctl_giwfrag(struct net_device *dev,
  525. struct iw_request_info *info,
  526. struct iw_param *frag, char *extra)
  527. {
  528. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  529. frag->value = local->fragmentation_threshold;
  530. frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
  531. frag->fixed = 1;
  532. return 0;
  533. }
  534. static int ieee80211_ioctl_siwretry(struct net_device *dev,
  535. struct iw_request_info *info,
  536. struct iw_param *retry, char *extra)
  537. {
  538. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  539. if (retry->disabled ||
  540. (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
  541. return -EINVAL;
  542. if (retry->flags & IW_RETRY_MAX) {
  543. local->hw.conf.long_frame_max_tx_count = retry->value;
  544. } else if (retry->flags & IW_RETRY_MIN) {
  545. local->hw.conf.short_frame_max_tx_count = retry->value;
  546. } else {
  547. local->hw.conf.long_frame_max_tx_count = retry->value;
  548. local->hw.conf.short_frame_max_tx_count = retry->value;
  549. }
  550. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  551. return 0;
  552. }
  553. static int ieee80211_ioctl_giwretry(struct net_device *dev,
  554. struct iw_request_info *info,
  555. struct iw_param *retry, char *extra)
  556. {
  557. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  558. retry->disabled = 0;
  559. if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
  560. /* first return min value, iwconfig will ask max value
  561. * later if needed */
  562. retry->flags |= IW_RETRY_LIMIT;
  563. retry->value = local->hw.conf.short_frame_max_tx_count;
  564. if (local->hw.conf.long_frame_max_tx_count !=
  565. local->hw.conf.short_frame_max_tx_count)
  566. retry->flags |= IW_RETRY_MIN;
  567. return 0;
  568. }
  569. if (retry->flags & IW_RETRY_MAX) {
  570. retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  571. retry->value = local->hw.conf.long_frame_max_tx_count;
  572. }
  573. return 0;
  574. }
  575. static int ieee80211_ioctl_siwmlme(struct net_device *dev,
  576. struct iw_request_info *info,
  577. struct iw_point *data, char *extra)
  578. {
  579. struct ieee80211_sub_if_data *sdata;
  580. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  581. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  582. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  583. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  584. return -EINVAL;
  585. switch (mlme->cmd) {
  586. case IW_MLME_DEAUTH:
  587. /* TODO: mlme->addr.sa_data */
  588. return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
  589. case IW_MLME_DISASSOC:
  590. /* TODO: mlme->addr.sa_data */
  591. return ieee80211_sta_disassociate(sdata, mlme->reason_code);
  592. default:
  593. return -EOPNOTSUPP;
  594. }
  595. }
  596. static int ieee80211_ioctl_siwencode(struct net_device *dev,
  597. struct iw_request_info *info,
  598. struct iw_point *erq, char *keybuf)
  599. {
  600. struct ieee80211_sub_if_data *sdata;
  601. int idx, i, alg = ALG_WEP;
  602. u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  603. int remove = 0;
  604. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  605. idx = erq->flags & IW_ENCODE_INDEX;
  606. if (idx == 0) {
  607. if (sdata->default_key)
  608. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  609. if (sdata->default_key == sdata->keys[i]) {
  610. idx = i;
  611. break;
  612. }
  613. }
  614. } else if (idx < 1 || idx > 4)
  615. return -EINVAL;
  616. else
  617. idx--;
  618. if (erq->flags & IW_ENCODE_DISABLED)
  619. remove = 1;
  620. else if (erq->length == 0) {
  621. /* No key data - just set the default TX key index */
  622. ieee80211_set_default_key(sdata, idx);
  623. return 0;
  624. }
  625. return ieee80211_set_encryption(
  626. sdata, bcaddr,
  627. idx, alg, remove,
  628. !sdata->default_key,
  629. keybuf, erq->length);
  630. }
  631. static int ieee80211_ioctl_giwencode(struct net_device *dev,
  632. struct iw_request_info *info,
  633. struct iw_point *erq, char *key)
  634. {
  635. struct ieee80211_sub_if_data *sdata;
  636. int idx, i;
  637. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  638. idx = erq->flags & IW_ENCODE_INDEX;
  639. if (idx < 1 || idx > 4) {
  640. idx = -1;
  641. if (!sdata->default_key)
  642. idx = 0;
  643. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  644. if (sdata->default_key == sdata->keys[i]) {
  645. idx = i;
  646. break;
  647. }
  648. }
  649. if (idx < 0)
  650. return -EINVAL;
  651. } else
  652. idx--;
  653. erq->flags = idx + 1;
  654. if (!sdata->keys[idx]) {
  655. erq->length = 0;
  656. erq->flags |= IW_ENCODE_DISABLED;
  657. return 0;
  658. }
  659. memcpy(key, sdata->keys[idx]->conf.key,
  660. min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
  661. erq->length = sdata->keys[idx]->conf.keylen;
  662. erq->flags |= IW_ENCODE_ENABLED;
  663. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  664. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  665. switch (ifsta->auth_alg) {
  666. case WLAN_AUTH_OPEN:
  667. case WLAN_AUTH_LEAP:
  668. erq->flags |= IW_ENCODE_OPEN;
  669. break;
  670. case WLAN_AUTH_SHARED_KEY:
  671. erq->flags |= IW_ENCODE_RESTRICTED;
  672. break;
  673. }
  674. }
  675. return 0;
  676. }
  677. static int ieee80211_ioctl_siwpower(struct net_device *dev,
  678. struct iw_request_info *info,
  679. struct iw_param *wrq,
  680. char *extra)
  681. {
  682. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  683. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  684. struct ieee80211_conf *conf = &local->hw.conf;
  685. int ret = 0, timeout = 0;
  686. bool ps;
  687. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  688. return -EINVAL;
  689. if (wrq->disabled) {
  690. ps = false;
  691. timeout = 0;
  692. goto set;
  693. }
  694. switch (wrq->flags & IW_POWER_MODE) {
  695. case IW_POWER_ON: /* If not specified */
  696. case IW_POWER_MODE: /* If set all mask */
  697. case IW_POWER_ALL_R: /* If explicitely state all */
  698. ps = true;
  699. break;
  700. default: /* Otherwise we ignore */
  701. break;
  702. }
  703. if (wrq->flags & IW_POWER_TIMEOUT)
  704. timeout = wrq->value / 1000;
  705. set:
  706. if (ps == local->powersave && timeout == local->dynamic_ps_timeout)
  707. return ret;
  708. local->powersave = ps;
  709. local->dynamic_ps_timeout = timeout;
  710. if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS) &&
  711. (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)) {
  712. if (local->dynamic_ps_timeout > 0)
  713. mod_timer(&local->dynamic_ps_timer, jiffies +
  714. msecs_to_jiffies(local->dynamic_ps_timeout));
  715. else {
  716. if (local->powersave)
  717. conf->flags |= IEEE80211_CONF_PS;
  718. else
  719. conf->flags &= ~IEEE80211_CONF_PS;
  720. ret = ieee80211_hw_config(local,
  721. IEEE80211_CONF_CHANGE_PS);
  722. }
  723. }
  724. return ret;
  725. }
  726. static int ieee80211_ioctl_giwpower(struct net_device *dev,
  727. struct iw_request_info *info,
  728. union iwreq_data *wrqu,
  729. char *extra)
  730. {
  731. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  732. wrqu->power.disabled = !local->powersave;
  733. return 0;
  734. }
  735. static int ieee80211_ioctl_siwauth(struct net_device *dev,
  736. struct iw_request_info *info,
  737. struct iw_param *data, char *extra)
  738. {
  739. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  740. int ret = 0;
  741. switch (data->flags & IW_AUTH_INDEX) {
  742. case IW_AUTH_WPA_VERSION:
  743. case IW_AUTH_CIPHER_GROUP:
  744. case IW_AUTH_WPA_ENABLED:
  745. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  746. case IW_AUTH_KEY_MGMT:
  747. break;
  748. case IW_AUTH_CIPHER_PAIRWISE:
  749. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  750. if (data->value & (IW_AUTH_CIPHER_WEP40 |
  751. IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
  752. sdata->u.sta.flags |=
  753. IEEE80211_STA_TKIP_WEP_USED;
  754. else
  755. sdata->u.sta.flags &=
  756. ~IEEE80211_STA_TKIP_WEP_USED;
  757. }
  758. break;
  759. case IW_AUTH_DROP_UNENCRYPTED:
  760. sdata->drop_unencrypted = !!data->value;
  761. break;
  762. case IW_AUTH_PRIVACY_INVOKED:
  763. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  764. ret = -EINVAL;
  765. else {
  766. sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
  767. /*
  768. * Privacy invoked by wpa_supplicant, store the
  769. * value and allow associating to a protected
  770. * network without having a key up front.
  771. */
  772. if (data->value)
  773. sdata->u.sta.flags |=
  774. IEEE80211_STA_PRIVACY_INVOKED;
  775. }
  776. break;
  777. case IW_AUTH_80211_AUTH_ALG:
  778. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  779. sdata->vif.type == NL80211_IFTYPE_ADHOC)
  780. sdata->u.sta.auth_algs = data->value;
  781. else
  782. ret = -EOPNOTSUPP;
  783. break;
  784. default:
  785. ret = -EOPNOTSUPP;
  786. break;
  787. }
  788. return ret;
  789. }
  790. /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
  791. static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
  792. {
  793. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  794. struct iw_statistics *wstats = &local->wstats;
  795. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  796. struct sta_info *sta = NULL;
  797. rcu_read_lock();
  798. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  799. sdata->vif.type == NL80211_IFTYPE_ADHOC)
  800. sta = sta_info_get(local, sdata->u.sta.bssid);
  801. if (!sta) {
  802. wstats->discard.fragment = 0;
  803. wstats->discard.misc = 0;
  804. wstats->qual.qual = 0;
  805. wstats->qual.level = 0;
  806. wstats->qual.noise = 0;
  807. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  808. } else {
  809. wstats->qual.level = sta->last_signal;
  810. wstats->qual.qual = sta->last_qual;
  811. wstats->qual.noise = sta->last_noise;
  812. wstats->qual.updated = local->wstats_flags;
  813. }
  814. rcu_read_unlock();
  815. return wstats;
  816. }
  817. static int ieee80211_ioctl_giwauth(struct net_device *dev,
  818. struct iw_request_info *info,
  819. struct iw_param *data, char *extra)
  820. {
  821. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  822. int ret = 0;
  823. switch (data->flags & IW_AUTH_INDEX) {
  824. case IW_AUTH_80211_AUTH_ALG:
  825. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  826. sdata->vif.type == NL80211_IFTYPE_ADHOC)
  827. data->value = sdata->u.sta.auth_algs;
  828. else
  829. ret = -EOPNOTSUPP;
  830. break;
  831. default:
  832. ret = -EOPNOTSUPP;
  833. break;
  834. }
  835. return ret;
  836. }
  837. static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
  838. struct iw_request_info *info,
  839. struct iw_point *erq, char *extra)
  840. {
  841. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  842. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  843. int uninitialized_var(alg), idx, i, remove = 0;
  844. switch (ext->alg) {
  845. case IW_ENCODE_ALG_NONE:
  846. remove = 1;
  847. break;
  848. case IW_ENCODE_ALG_WEP:
  849. alg = ALG_WEP;
  850. break;
  851. case IW_ENCODE_ALG_TKIP:
  852. alg = ALG_TKIP;
  853. break;
  854. case IW_ENCODE_ALG_CCMP:
  855. alg = ALG_CCMP;
  856. break;
  857. default:
  858. return -EOPNOTSUPP;
  859. }
  860. if (erq->flags & IW_ENCODE_DISABLED)
  861. remove = 1;
  862. idx = erq->flags & IW_ENCODE_INDEX;
  863. if (idx < 1 || idx > 4) {
  864. idx = -1;
  865. if (!sdata->default_key)
  866. idx = 0;
  867. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  868. if (sdata->default_key == sdata->keys[i]) {
  869. idx = i;
  870. break;
  871. }
  872. }
  873. if (idx < 0)
  874. return -EINVAL;
  875. } else
  876. idx--;
  877. return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
  878. remove,
  879. ext->ext_flags &
  880. IW_ENCODE_EXT_SET_TX_KEY,
  881. ext->key, ext->key_len);
  882. }
  883. /* Structures to export the Wireless Handlers */
  884. static const iw_handler ieee80211_handler[] =
  885. {
  886. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  887. (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
  888. (iw_handler) NULL, /* SIOCSIWNWID */
  889. (iw_handler) NULL, /* SIOCGIWNWID */
  890. (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
  891. (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
  892. (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
  893. (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
  894. (iw_handler) NULL, /* SIOCSIWSENS */
  895. (iw_handler) NULL, /* SIOCGIWSENS */
  896. (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
  897. (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
  898. (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
  899. (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
  900. (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
  901. (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
  902. (iw_handler) NULL, /* SIOCSIWSPY */
  903. (iw_handler) NULL, /* SIOCGIWSPY */
  904. (iw_handler) NULL, /* SIOCSIWTHRSPY */
  905. (iw_handler) NULL, /* SIOCGIWTHRSPY */
  906. (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
  907. (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
  908. (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
  909. (iw_handler) NULL, /* SIOCGIWAPLIST */
  910. (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
  911. (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
  912. (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
  913. (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
  914. (iw_handler) NULL, /* SIOCSIWNICKN */
  915. (iw_handler) NULL, /* SIOCGIWNICKN */
  916. (iw_handler) NULL, /* -- hole -- */
  917. (iw_handler) NULL, /* -- hole -- */
  918. (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
  919. (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
  920. (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
  921. (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
  922. (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
  923. (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
  924. (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
  925. (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
  926. (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
  927. (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
  928. (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
  929. (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
  930. (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
  931. (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
  932. (iw_handler) NULL, /* -- hole -- */
  933. (iw_handler) NULL, /* -- hole -- */
  934. (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
  935. (iw_handler) NULL, /* SIOCGIWGENIE */
  936. (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
  937. (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
  938. (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
  939. (iw_handler) NULL, /* SIOCGIWENCODEEXT */
  940. (iw_handler) NULL, /* SIOCSIWPMKSA */
  941. (iw_handler) NULL, /* -- hole -- */
  942. };
  943. const struct iw_handler_def ieee80211_iw_handler_def =
  944. {
  945. .num_standard = ARRAY_SIZE(ieee80211_handler),
  946. .standard = (iw_handler *) ieee80211_handler,
  947. .get_wireless_stats = ieee80211_get_wireless_stats,
  948. };