ieee80211_ioctl.c 29 KB

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