ieee80211_ioctl.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  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 "hostapd_ioctl.h"
  23. #include "ieee80211_rate.h"
  24. #include "wpa.h"
  25. #include "aes_ccm.h"
  26. #include "debugfs_key.h"
  27. static int ieee80211_regdom = 0x10; /* FCC */
  28. module_param(ieee80211_regdom, int, 0444);
  29. MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
  30. /*
  31. * If firmware is upgraded by the vendor, additional channels can be used based
  32. * on the new Japanese regulatory rules. This is indicated by setting
  33. * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
  34. * module.
  35. */
  36. static int ieee80211_japan_5ghz /* = 0 */;
  37. module_param(ieee80211_japan_5ghz, int, 0444);
  38. MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
  39. static void ieee80211_set_hw_encryption(struct net_device *dev,
  40. struct sta_info *sta, u8 addr[ETH_ALEN],
  41. struct ieee80211_key *key)
  42. {
  43. struct ieee80211_key_conf *keyconf = NULL;
  44. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  45. /* default to sw encryption; this will be cleared by low-level
  46. * driver if the hw supports requested encryption */
  47. if (key)
  48. key->force_sw_encrypt = 1;
  49. if (key && local->ops->set_key &&
  50. (keyconf = ieee80211_key_data2conf(local, key))) {
  51. if (local->ops->set_key(local_to_hw(local), SET_KEY, addr,
  52. keyconf, sta ? sta->aid : 0)) {
  53. key->force_sw_encrypt = 1;
  54. key->hw_key_idx = HW_KEY_IDX_INVALID;
  55. } else {
  56. key->force_sw_encrypt =
  57. !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
  58. key->hw_key_idx =
  59. keyconf->hw_key_idx;
  60. }
  61. }
  62. kfree(keyconf);
  63. }
  64. static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
  65. int idx, int alg, int set_tx_key,
  66. const u8 *_key, size_t key_len)
  67. {
  68. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  69. int ret = 0;
  70. struct sta_info *sta;
  71. struct ieee80211_key *key, *old_key;
  72. int try_hwaccel = 1;
  73. struct ieee80211_key_conf *keyconf;
  74. struct ieee80211_sub_if_data *sdata;
  75. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  76. if (is_broadcast_ether_addr(sta_addr)) {
  77. sta = NULL;
  78. if (idx >= NUM_DEFAULT_KEYS) {
  79. printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
  80. dev->name, idx);
  81. return -EINVAL;
  82. }
  83. key = sdata->keys[idx];
  84. /* TODO: consider adding hwaccel support for these; at least
  85. * Atheros key cache should be able to handle this since AP is
  86. * only transmitting frames with default keys. */
  87. /* FIX: hw key cache can be used when only one virtual
  88. * STA is associated with each AP. If more than one STA
  89. * is associated to the same AP, software encryption
  90. * must be used. This should be done automatically
  91. * based on configured station devices. For the time
  92. * being, this can be only set at compile time. */
  93. } else {
  94. set_tx_key = 0;
  95. if (idx != 0) {
  96. printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
  97. "individual key\n", dev->name);
  98. return -EINVAL;
  99. }
  100. sta = sta_info_get(local, sta_addr);
  101. if (!sta) {
  102. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  103. printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
  104. MAC_FMT "\n",
  105. dev->name, MAC_ARG(sta_addr));
  106. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  107. return -ENOENT;
  108. }
  109. key = sta->key;
  110. }
  111. /* FIX:
  112. * Cannot configure default hwaccel keys with WEP algorithm, if
  113. * any of the virtual interfaces is using static WEP
  114. * configuration because hwaccel would otherwise try to decrypt
  115. * these frames.
  116. *
  117. * For now, just disable WEP hwaccel for broadcast when there is
  118. * possibility of conflict with default keys. This can maybe later be
  119. * optimized by using non-default keys (at least with Atheros ar521x).
  120. */
  121. if (!sta && alg == ALG_WEP && !local->default_wep_only &&
  122. sdata->type != IEEE80211_IF_TYPE_IBSS &&
  123. sdata->type != IEEE80211_IF_TYPE_AP) {
  124. try_hwaccel = 0;
  125. }
  126. if (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) {
  127. /* Software encryption cannot be used with devices that hide
  128. * encryption from the host system, so always try to use
  129. * hardware acceleration with such devices. */
  130. try_hwaccel = 1;
  131. }
  132. if ((local->hw.flags & IEEE80211_HW_NO_TKIP_WMM_HWACCEL) &&
  133. alg == ALG_TKIP) {
  134. if (sta && (sta->flags & WLAN_STA_WME)) {
  135. /* Hardware does not support hwaccel with TKIP when using WMM.
  136. */
  137. try_hwaccel = 0;
  138. }
  139. else if (sdata->type == IEEE80211_IF_TYPE_STA) {
  140. sta = sta_info_get(local, sdata->u.sta.bssid);
  141. if (sta) {
  142. if (sta->flags & WLAN_STA_WME) {
  143. try_hwaccel = 0;
  144. }
  145. sta_info_put(sta);
  146. sta = NULL;
  147. }
  148. }
  149. }
  150. if (alg == ALG_NONE) {
  151. keyconf = NULL;
  152. if (try_hwaccel && key &&
  153. key->hw_key_idx != HW_KEY_IDX_INVALID &&
  154. local->ops->set_key &&
  155. (keyconf = ieee80211_key_data2conf(local, key)) != NULL &&
  156. local->ops->set_key(local_to_hw(local), DISABLE_KEY,
  157. sta_addr, keyconf, sta ? sta->aid : 0)) {
  158. printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
  159. " failed\n", dev->name);
  160. ret = -EINVAL;
  161. }
  162. kfree(keyconf);
  163. if (set_tx_key || sdata->default_key == key) {
  164. ieee80211_debugfs_key_remove_default(sdata);
  165. sdata->default_key = NULL;
  166. }
  167. ieee80211_debugfs_key_remove(key);
  168. if (sta)
  169. sta->key = NULL;
  170. else
  171. sdata->keys[idx] = NULL;
  172. ieee80211_key_free(key);
  173. key = NULL;
  174. } else {
  175. old_key = key;
  176. key = ieee80211_key_alloc(sta ? NULL : sdata, idx, key_len,
  177. GFP_KERNEL);
  178. if (!key) {
  179. ret = -ENOMEM;
  180. goto err_out;
  181. }
  182. /* default to sw encryption; low-level driver sets these if the
  183. * requested encryption is supported */
  184. key->hw_key_idx = HW_KEY_IDX_INVALID;
  185. key->force_sw_encrypt = 1;
  186. key->alg = alg;
  187. key->keyidx = idx;
  188. key->keylen = key_len;
  189. memcpy(key->key, _key, key_len);
  190. if (set_tx_key)
  191. key->default_tx_key = 1;
  192. if (alg == ALG_CCMP) {
  193. /* Initialize AES key state here as an optimization
  194. * so that it does not need to be initialized for every
  195. * packet. */
  196. key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(
  197. key->key);
  198. if (!key->u.ccmp.tfm) {
  199. ret = -ENOMEM;
  200. goto err_free;
  201. }
  202. }
  203. if (set_tx_key || sdata->default_key == old_key) {
  204. ieee80211_debugfs_key_remove_default(sdata);
  205. sdata->default_key = NULL;
  206. }
  207. ieee80211_debugfs_key_remove(old_key);
  208. if (sta)
  209. sta->key = key;
  210. else
  211. sdata->keys[idx] = key;
  212. ieee80211_key_free(old_key);
  213. ieee80211_debugfs_key_add(local, key);
  214. if (sta)
  215. ieee80211_debugfs_key_sta_link(key, sta);
  216. if (try_hwaccel &&
  217. (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP))
  218. ieee80211_set_hw_encryption(dev, sta, sta_addr, key);
  219. }
  220. if (set_tx_key || (!sta && !sdata->default_key && key)) {
  221. sdata->default_key = key;
  222. if (key)
  223. ieee80211_debugfs_key_add_default(sdata);
  224. if (local->ops->set_key_idx &&
  225. local->ops->set_key_idx(local_to_hw(local), idx))
  226. printk(KERN_DEBUG "%s: failed to set TX key idx for "
  227. "low-level driver\n", dev->name);
  228. }
  229. if (sta)
  230. sta_info_put(sta);
  231. return 0;
  232. err_free:
  233. ieee80211_key_free(key);
  234. err_out:
  235. if (sta)
  236. sta_info_put(sta);
  237. return ret;
  238. }
  239. static int ieee80211_ioctl_siwgenie(struct net_device *dev,
  240. struct iw_request_info *info,
  241. struct iw_point *data, char *extra)
  242. {
  243. struct ieee80211_sub_if_data *sdata;
  244. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  245. if (local->user_space_mlme)
  246. return -EOPNOTSUPP;
  247. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  248. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  249. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  250. int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
  251. if (ret)
  252. return ret;
  253. sdata->u.sta.auto_bssid_sel = 0;
  254. ieee80211_sta_req_auth(dev, &sdata->u.sta);
  255. return 0;
  256. }
  257. if (sdata->type == IEEE80211_IF_TYPE_AP) {
  258. kfree(sdata->u.ap.generic_elem);
  259. sdata->u.ap.generic_elem = kmalloc(data->length, GFP_KERNEL);
  260. if (!sdata->u.ap.generic_elem)
  261. return -ENOMEM;
  262. memcpy(sdata->u.ap.generic_elem, extra, data->length);
  263. sdata->u.ap.generic_elem_len = data->length;
  264. return ieee80211_if_config(dev);
  265. }
  266. return -EOPNOTSUPP;
  267. }
  268. static int ieee80211_ioctl_set_radio_enabled(struct net_device *dev,
  269. int val)
  270. {
  271. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  272. struct ieee80211_conf *conf = &local->hw.conf;
  273. conf->radio_enabled = val;
  274. return ieee80211_hw_config(wdev_priv(dev->ieee80211_ptr));
  275. }
  276. static int ieee80211_ioctl_giwname(struct net_device *dev,
  277. struct iw_request_info *info,
  278. char *name, char *extra)
  279. {
  280. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  281. switch (local->hw.conf.phymode) {
  282. case MODE_IEEE80211A:
  283. strcpy(name, "IEEE 802.11a");
  284. break;
  285. case MODE_IEEE80211B:
  286. strcpy(name, "IEEE 802.11b");
  287. break;
  288. case MODE_IEEE80211G:
  289. strcpy(name, "IEEE 802.11g");
  290. break;
  291. case MODE_ATHEROS_TURBO:
  292. strcpy(name, "5GHz Turbo");
  293. break;
  294. default:
  295. strcpy(name, "IEEE 802.11");
  296. break;
  297. }
  298. return 0;
  299. }
  300. static int ieee80211_ioctl_giwrange(struct net_device *dev,
  301. struct iw_request_info *info,
  302. struct iw_point *data, char *extra)
  303. {
  304. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  305. struct iw_range *range = (struct iw_range *) extra;
  306. struct ieee80211_hw_mode *mode = NULL;
  307. int c = 0;
  308. data->length = sizeof(struct iw_range);
  309. memset(range, 0, sizeof(struct iw_range));
  310. range->we_version_compiled = WIRELESS_EXT;
  311. range->we_version_source = 21;
  312. range->retry_capa = IW_RETRY_LIMIT;
  313. range->retry_flags = IW_RETRY_LIMIT;
  314. range->min_retry = 0;
  315. range->max_retry = 255;
  316. range->min_rts = 0;
  317. range->max_rts = 2347;
  318. range->min_frag = 256;
  319. range->max_frag = 2346;
  320. range->encoding_size[0] = 5;
  321. range->encoding_size[1] = 13;
  322. range->num_encoding_sizes = 2;
  323. range->max_encoding_tokens = NUM_DEFAULT_KEYS;
  324. range->max_qual.qual = local->hw.max_signal;
  325. range->max_qual.level = local->hw.max_rssi;
  326. range->max_qual.noise = local->hw.max_noise;
  327. range->max_qual.updated = local->wstats_flags;
  328. range->avg_qual.qual = local->hw.max_signal/2;
  329. range->avg_qual.level = 0;
  330. range->avg_qual.noise = 0;
  331. range->avg_qual.updated = local->wstats_flags;
  332. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
  333. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  334. list_for_each_entry(mode, &local->modes_list, list) {
  335. int i = 0;
  336. if (!(local->enabled_modes & (1 << mode->mode)) ||
  337. (local->hw_modes & local->enabled_modes &
  338. (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
  339. continue;
  340. while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) {
  341. struct ieee80211_channel *chan = &mode->channels[i];
  342. if (chan->flag & IEEE80211_CHAN_W_SCAN) {
  343. range->freq[c].i = chan->chan;
  344. range->freq[c].m = chan->freq * 100000;
  345. range->freq[c].e = 1;
  346. c++;
  347. }
  348. i++;
  349. }
  350. }
  351. range->num_channels = c;
  352. range->num_frequency = c;
  353. IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
  354. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
  355. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
  356. IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
  357. return 0;
  358. }
  359. struct ieee80211_channel_range {
  360. short start_freq;
  361. short end_freq;
  362. unsigned char power_level;
  363. unsigned char antenna_max;
  364. };
  365. static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
  366. { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
  367. { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
  368. { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
  369. { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
  370. { 0 }
  371. };
  372. static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
  373. { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
  374. { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
  375. { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
  376. { 0 }
  377. };
  378. static const struct ieee80211_channel_range *channel_range =
  379. ieee80211_fcc_channels;
  380. static void ieee80211_unmask_channel(struct net_device *dev, int mode,
  381. struct ieee80211_channel *chan)
  382. {
  383. int i;
  384. chan->flag = 0;
  385. if (ieee80211_regdom == 64 &&
  386. (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
  387. /* Do not allow Turbo modes in Japan. */
  388. return;
  389. }
  390. for (i = 0; channel_range[i].start_freq; i++) {
  391. const struct ieee80211_channel_range *r = &channel_range[i];
  392. if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
  393. if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
  394. chan->freq >= 5260 && chan->freq <= 5320) {
  395. /*
  396. * Skip new channels in Japan since the
  397. * firmware was not marked having been upgraded
  398. * by the vendor.
  399. */
  400. continue;
  401. }
  402. if (ieee80211_regdom == 0x10 &&
  403. (chan->freq == 5190 || chan->freq == 5210 ||
  404. chan->freq == 5230)) {
  405. /* Skip MKK channels when in FCC domain. */
  406. continue;
  407. }
  408. chan->flag |= IEEE80211_CHAN_W_SCAN |
  409. IEEE80211_CHAN_W_ACTIVE_SCAN |
  410. IEEE80211_CHAN_W_IBSS;
  411. chan->power_level = r->power_level;
  412. chan->antenna_max = r->antenna_max;
  413. if (ieee80211_regdom == 64 &&
  414. (chan->freq == 5170 || chan->freq == 5190 ||
  415. chan->freq == 5210 || chan->freq == 5230)) {
  416. /*
  417. * New regulatory rules in Japan have backwards
  418. * compatibility with old channels in 5.15-5.25
  419. * GHz band, but the station is not allowed to
  420. * use active scan on these old channels.
  421. */
  422. chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
  423. }
  424. if (ieee80211_regdom == 64 &&
  425. (chan->freq == 5260 || chan->freq == 5280 ||
  426. chan->freq == 5300 || chan->freq == 5320)) {
  427. /*
  428. * IBSS is not allowed on 5.25-5.35 GHz band
  429. * due to radar detection requirements.
  430. */
  431. chan->flag &= ~IEEE80211_CHAN_W_IBSS;
  432. }
  433. break;
  434. }
  435. }
  436. }
  437. static int ieee80211_unmask_channels(struct net_device *dev)
  438. {
  439. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  440. struct ieee80211_hw_mode *mode;
  441. int c;
  442. list_for_each_entry(mode, &local->modes_list, list) {
  443. for (c = 0; c < mode->num_channels; c++) {
  444. ieee80211_unmask_channel(dev, mode->mode,
  445. &mode->channels[c]);
  446. }
  447. }
  448. return 0;
  449. }
  450. int ieee80211_init_client(struct net_device *dev)
  451. {
  452. if (ieee80211_regdom == 0x40)
  453. channel_range = ieee80211_mkk_channels;
  454. ieee80211_unmask_channels(dev);
  455. return 0;
  456. }
  457. static int ieee80211_ioctl_siwmode(struct net_device *dev,
  458. struct iw_request_info *info,
  459. __u32 *mode, char *extra)
  460. {
  461. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  462. int type;
  463. if (sdata->type == IEEE80211_IF_TYPE_VLAN)
  464. return -EOPNOTSUPP;
  465. switch (*mode) {
  466. case IW_MODE_INFRA:
  467. type = IEEE80211_IF_TYPE_STA;
  468. break;
  469. case IW_MODE_ADHOC:
  470. type = IEEE80211_IF_TYPE_IBSS;
  471. break;
  472. case IW_MODE_MONITOR:
  473. type = IEEE80211_IF_TYPE_MNTR;
  474. break;
  475. default:
  476. return -EINVAL;
  477. }
  478. if (type == sdata->type)
  479. return 0;
  480. if (netif_running(dev))
  481. return -EBUSY;
  482. ieee80211_if_reinit(dev);
  483. ieee80211_if_set_type(dev, type);
  484. return 0;
  485. }
  486. static int ieee80211_ioctl_giwmode(struct net_device *dev,
  487. struct iw_request_info *info,
  488. __u32 *mode, char *extra)
  489. {
  490. struct ieee80211_sub_if_data *sdata;
  491. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  492. switch (sdata->type) {
  493. case IEEE80211_IF_TYPE_AP:
  494. *mode = IW_MODE_MASTER;
  495. break;
  496. case IEEE80211_IF_TYPE_STA:
  497. *mode = IW_MODE_INFRA;
  498. break;
  499. case IEEE80211_IF_TYPE_IBSS:
  500. *mode = IW_MODE_ADHOC;
  501. break;
  502. case IEEE80211_IF_TYPE_MNTR:
  503. *mode = IW_MODE_MONITOR;
  504. break;
  505. case IEEE80211_IF_TYPE_WDS:
  506. *mode = IW_MODE_REPEAT;
  507. break;
  508. case IEEE80211_IF_TYPE_VLAN:
  509. *mode = IW_MODE_SECOND; /* FIXME */
  510. break;
  511. default:
  512. *mode = IW_MODE_AUTO;
  513. break;
  514. }
  515. return 0;
  516. }
  517. int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
  518. {
  519. struct ieee80211_hw_mode *mode;
  520. int c, set = 0;
  521. int ret = -EINVAL;
  522. list_for_each_entry(mode, &local->modes_list, list) {
  523. if (!(local->enabled_modes & (1 << mode->mode)))
  524. continue;
  525. for (c = 0; c < mode->num_channels; c++) {
  526. struct ieee80211_channel *chan = &mode->channels[c];
  527. if (chan->flag & IEEE80211_CHAN_W_SCAN &&
  528. ((chan->chan == channel) || (chan->freq == freq))) {
  529. /* Use next_mode as the mode preference to
  530. * resolve non-unique channel numbers. */
  531. if (set && mode->mode != local->next_mode)
  532. continue;
  533. local->oper_channel = chan;
  534. local->oper_hw_mode = mode;
  535. set++;
  536. }
  537. }
  538. }
  539. if (set) {
  540. if (local->sta_scanning)
  541. ret = 0;
  542. else
  543. ret = ieee80211_hw_config(local);
  544. rate_control_clear(local);
  545. }
  546. return ret;
  547. }
  548. static int ieee80211_ioctl_siwfreq(struct net_device *dev,
  549. struct iw_request_info *info,
  550. struct iw_freq *freq, char *extra)
  551. {
  552. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  553. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  554. if (sdata->type == IEEE80211_IF_TYPE_STA)
  555. sdata->u.sta.auto_channel_sel = 0;
  556. /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
  557. if (freq->e == 0) {
  558. if (freq->m < 0) {
  559. if (sdata->type == IEEE80211_IF_TYPE_STA)
  560. sdata->u.sta.auto_channel_sel = 1;
  561. return 0;
  562. } else
  563. return ieee80211_set_channel(local, freq->m, -1);
  564. } else {
  565. int i, div = 1000000;
  566. for (i = 0; i < freq->e; i++)
  567. div /= 10;
  568. if (div > 0)
  569. return ieee80211_set_channel(local, -1, freq->m / div);
  570. else
  571. return -EINVAL;
  572. }
  573. }
  574. static int ieee80211_ioctl_giwfreq(struct net_device *dev,
  575. struct iw_request_info *info,
  576. struct iw_freq *freq, char *extra)
  577. {
  578. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  579. /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
  580. * driver for the current channel with firmware-based management */
  581. freq->m = local->hw.conf.freq;
  582. freq->e = 6;
  583. return 0;
  584. }
  585. static int ieee80211_ioctl_siwessid(struct net_device *dev,
  586. struct iw_request_info *info,
  587. struct iw_point *data, char *ssid)
  588. {
  589. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  590. struct ieee80211_sub_if_data *sdata;
  591. size_t len = data->length;
  592. /* iwconfig uses nul termination in SSID.. */
  593. if (len > 0 && ssid[len - 1] == '\0')
  594. len--;
  595. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  596. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  597. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  598. int ret;
  599. if (local->user_space_mlme) {
  600. if (len > IEEE80211_MAX_SSID_LEN)
  601. return -EINVAL;
  602. memcpy(sdata->u.sta.ssid, ssid, len);
  603. sdata->u.sta.ssid_len = len;
  604. return 0;
  605. }
  606. sdata->u.sta.auto_ssid_sel = !data->flags;
  607. ret = ieee80211_sta_set_ssid(dev, ssid, len);
  608. if (ret)
  609. return ret;
  610. ieee80211_sta_req_auth(dev, &sdata->u.sta);
  611. return 0;
  612. }
  613. if (sdata->type == IEEE80211_IF_TYPE_AP) {
  614. memcpy(sdata->u.ap.ssid, ssid, len);
  615. memset(sdata->u.ap.ssid + len, 0,
  616. IEEE80211_MAX_SSID_LEN - len);
  617. sdata->u.ap.ssid_len = len;
  618. return ieee80211_if_config(dev);
  619. }
  620. return -EOPNOTSUPP;
  621. }
  622. static int ieee80211_ioctl_giwessid(struct net_device *dev,
  623. struct iw_request_info *info,
  624. struct iw_point *data, char *ssid)
  625. {
  626. size_t len;
  627. struct ieee80211_sub_if_data *sdata;
  628. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  629. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  630. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  631. int res = ieee80211_sta_get_ssid(dev, ssid, &len);
  632. if (res == 0) {
  633. data->length = len;
  634. data->flags = 1;
  635. } else
  636. data->flags = 0;
  637. return res;
  638. }
  639. if (sdata->type == IEEE80211_IF_TYPE_AP) {
  640. len = sdata->u.ap.ssid_len;
  641. if (len > IW_ESSID_MAX_SIZE)
  642. len = IW_ESSID_MAX_SIZE;
  643. memcpy(ssid, sdata->u.ap.ssid, len);
  644. data->length = len;
  645. data->flags = 1;
  646. return 0;
  647. }
  648. return -EOPNOTSUPP;
  649. }
  650. static int ieee80211_ioctl_siwap(struct net_device *dev,
  651. struct iw_request_info *info,
  652. struct sockaddr *ap_addr, char *extra)
  653. {
  654. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  655. struct ieee80211_sub_if_data *sdata;
  656. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  657. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  658. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  659. int ret;
  660. if (local->user_space_mlme) {
  661. memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
  662. ETH_ALEN);
  663. return 0;
  664. }
  665. if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) {
  666. sdata->u.sta.auto_bssid_sel = 1;
  667. sdata->u.sta.auto_channel_sel = 1;
  668. } else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
  669. sdata->u.sta.auto_bssid_sel = 1;
  670. else
  671. sdata->u.sta.auto_bssid_sel = 0;
  672. ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
  673. if (ret)
  674. return ret;
  675. ieee80211_sta_req_auth(dev, &sdata->u.sta);
  676. return 0;
  677. } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
  678. if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
  679. ETH_ALEN) == 0)
  680. return 0;
  681. return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
  682. }
  683. return -EOPNOTSUPP;
  684. }
  685. static int ieee80211_ioctl_giwap(struct net_device *dev,
  686. struct iw_request_info *info,
  687. struct sockaddr *ap_addr, char *extra)
  688. {
  689. struct ieee80211_sub_if_data *sdata;
  690. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  691. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  692. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  693. ap_addr->sa_family = ARPHRD_ETHER;
  694. memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
  695. return 0;
  696. } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
  697. ap_addr->sa_family = ARPHRD_ETHER;
  698. memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
  699. return 0;
  700. }
  701. return -EOPNOTSUPP;
  702. }
  703. static int ieee80211_ioctl_siwscan(struct net_device *dev,
  704. struct iw_request_info *info,
  705. struct iw_point *data, char *extra)
  706. {
  707. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  708. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  709. u8 *ssid = NULL;
  710. size_t ssid_len = 0;
  711. if (!netif_running(dev))
  712. return -ENETDOWN;
  713. if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
  714. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  715. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  716. ssid = sdata->u.sta.ssid;
  717. ssid_len = sdata->u.sta.ssid_len;
  718. } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
  719. ssid = sdata->u.ap.ssid;
  720. ssid_len = sdata->u.ap.ssid_len;
  721. } else
  722. return -EINVAL;
  723. }
  724. return ieee80211_sta_req_scan(dev, ssid, ssid_len);
  725. }
  726. static int ieee80211_ioctl_giwscan(struct net_device *dev,
  727. struct iw_request_info *info,
  728. struct iw_point *data, char *extra)
  729. {
  730. int res;
  731. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  732. if (local->sta_scanning)
  733. return -EAGAIN;
  734. res = ieee80211_sta_scan_results(dev, extra, data->length);
  735. if (res >= 0) {
  736. data->length = res;
  737. return 0;
  738. }
  739. data->length = 0;
  740. return res;
  741. }
  742. static int ieee80211_ioctl_giwrate(struct net_device *dev,
  743. struct iw_request_info *info,
  744. struct iw_param *rate, char *extra)
  745. {
  746. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  747. struct sta_info *sta;
  748. struct ieee80211_sub_if_data *sdata;
  749. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  750. if (sdata->type == IEEE80211_IF_TYPE_STA)
  751. sta = sta_info_get(local, sdata->u.sta.bssid);
  752. else
  753. return -EOPNOTSUPP;
  754. if (!sta)
  755. return -ENODEV;
  756. if (sta->txrate < local->oper_hw_mode->num_rates)
  757. rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000;
  758. else
  759. rate->value = 0;
  760. sta_info_put(sta);
  761. return 0;
  762. }
  763. static int ieee80211_ioctl_siwrts(struct net_device *dev,
  764. struct iw_request_info *info,
  765. struct iw_param *rts, char *extra)
  766. {
  767. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  768. if (rts->disabled)
  769. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  770. else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
  771. return -EINVAL;
  772. else
  773. local->rts_threshold = rts->value;
  774. /* If the wlan card performs RTS/CTS in hardware/firmware,
  775. * configure it here */
  776. if (local->ops->set_rts_threshold)
  777. local->ops->set_rts_threshold(local_to_hw(local),
  778. local->rts_threshold);
  779. return 0;
  780. }
  781. static int ieee80211_ioctl_giwrts(struct net_device *dev,
  782. struct iw_request_info *info,
  783. struct iw_param *rts, char *extra)
  784. {
  785. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  786. rts->value = local->rts_threshold;
  787. rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
  788. rts->fixed = 1;
  789. return 0;
  790. }
  791. static int ieee80211_ioctl_siwfrag(struct net_device *dev,
  792. struct iw_request_info *info,
  793. struct iw_param *frag, char *extra)
  794. {
  795. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  796. if (frag->disabled)
  797. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  798. else if (frag->value < 256 ||
  799. frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
  800. return -EINVAL;
  801. else {
  802. /* Fragment length must be even, so strip LSB. */
  803. local->fragmentation_threshold = frag->value & ~0x1;
  804. }
  805. /* If the wlan card performs fragmentation in hardware/firmware,
  806. * configure it here */
  807. if (local->ops->set_frag_threshold)
  808. local->ops->set_frag_threshold(
  809. local_to_hw(local),
  810. local->fragmentation_threshold);
  811. return 0;
  812. }
  813. static int ieee80211_ioctl_giwfrag(struct net_device *dev,
  814. struct iw_request_info *info,
  815. struct iw_param *frag, char *extra)
  816. {
  817. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  818. frag->value = local->fragmentation_threshold;
  819. frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
  820. frag->fixed = 1;
  821. return 0;
  822. }
  823. static int ieee80211_ioctl_siwretry(struct net_device *dev,
  824. struct iw_request_info *info,
  825. struct iw_param *retry, char *extra)
  826. {
  827. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  828. if (retry->disabled ||
  829. (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
  830. return -EINVAL;
  831. if (retry->flags & IW_RETRY_MAX)
  832. local->long_retry_limit = retry->value;
  833. else if (retry->flags & IW_RETRY_MIN)
  834. local->short_retry_limit = retry->value;
  835. else {
  836. local->long_retry_limit = retry->value;
  837. local->short_retry_limit = retry->value;
  838. }
  839. if (local->ops->set_retry_limit) {
  840. return local->ops->set_retry_limit(
  841. local_to_hw(local),
  842. local->short_retry_limit,
  843. local->long_retry_limit);
  844. }
  845. return 0;
  846. }
  847. static int ieee80211_ioctl_giwretry(struct net_device *dev,
  848. struct iw_request_info *info,
  849. struct iw_param *retry, char *extra)
  850. {
  851. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  852. retry->disabled = 0;
  853. if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
  854. /* first return min value, iwconfig will ask max value
  855. * later if needed */
  856. retry->flags |= IW_RETRY_LIMIT;
  857. retry->value = local->short_retry_limit;
  858. if (local->long_retry_limit != local->short_retry_limit)
  859. retry->flags |= IW_RETRY_MIN;
  860. return 0;
  861. }
  862. if (retry->flags & IW_RETRY_MAX) {
  863. retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  864. retry->value = local->long_retry_limit;
  865. }
  866. return 0;
  867. }
  868. static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
  869. struct ieee80211_key *key)
  870. {
  871. struct ieee80211_key_conf *keyconf;
  872. u8 addr[ETH_ALEN];
  873. if (!key || key->alg != ALG_WEP || !key->force_sw_encrypt ||
  874. (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
  875. return;
  876. memset(addr, 0xff, ETH_ALEN);
  877. keyconf = ieee80211_key_data2conf(local, key);
  878. if (keyconf && local->ops->set_key &&
  879. local->ops->set_key(local_to_hw(local),
  880. SET_KEY, addr, keyconf, 0) == 0) {
  881. key->force_sw_encrypt =
  882. !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
  883. key->hw_key_idx = keyconf->hw_key_idx;
  884. }
  885. kfree(keyconf);
  886. }
  887. static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
  888. struct ieee80211_key *key)
  889. {
  890. struct ieee80211_key_conf *keyconf;
  891. u8 addr[ETH_ALEN];
  892. if (!key || key->alg != ALG_WEP || key->force_sw_encrypt ||
  893. (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
  894. return;
  895. memset(addr, 0xff, ETH_ALEN);
  896. keyconf = ieee80211_key_data2conf(local, key);
  897. if (keyconf && local->ops->set_key)
  898. local->ops->set_key(local_to_hw(local), DISABLE_KEY,
  899. addr, keyconf, 0);
  900. kfree(keyconf);
  901. key->force_sw_encrypt = 1;
  902. }
  903. static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
  904. int value)
  905. {
  906. int i;
  907. struct ieee80211_sub_if_data *sdata;
  908. local->default_wep_only = value;
  909. read_lock(&local->sub_if_lock);
  910. list_for_each_entry(sdata, &local->sub_if_list, list)
  911. for (i = 0; i < NUM_DEFAULT_KEYS; i++)
  912. if (value)
  913. ieee80211_key_enable_hwaccel(local,
  914. sdata->keys[i]);
  915. else
  916. ieee80211_key_disable_hwaccel(local,
  917. sdata->keys[i]);
  918. read_unlock(&local->sub_if_lock);
  919. return 0;
  920. }
  921. void ieee80211_update_default_wep_only(struct ieee80211_local *local)
  922. {
  923. int i = 0;
  924. struct ieee80211_sub_if_data *sdata;
  925. read_lock(&local->sub_if_lock);
  926. list_for_each_entry(sdata, &local->sub_if_list, list) {
  927. if (sdata->dev == local->mdev)
  928. continue;
  929. /* If there is an AP interface then depend on userspace to
  930. set default_wep_only correctly. */
  931. if (sdata->type == IEEE80211_IF_TYPE_AP) {
  932. read_unlock(&local->sub_if_lock);
  933. return;
  934. }
  935. i++;
  936. }
  937. read_unlock(&local->sub_if_lock);
  938. if (i <= 1)
  939. ieee80211_ioctl_default_wep_only(local, 1);
  940. else
  941. ieee80211_ioctl_default_wep_only(local, 0);
  942. }
  943. static int ieee80211_ioctl_prism2_param(struct net_device *dev,
  944. struct iw_request_info *info,
  945. void *wrqu, char *extra)
  946. {
  947. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  948. struct ieee80211_sub_if_data *sdata;
  949. int *i = (int *) extra;
  950. int param = *i;
  951. int value = *(i + 1);
  952. int ret = 0;
  953. if (!capable(CAP_NET_ADMIN))
  954. return -EPERM;
  955. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  956. switch (param) {
  957. case PRISM2_PARAM_IEEE_802_1X:
  958. if (local->ops->set_ieee8021x)
  959. ret = local->ops->set_ieee8021x(local_to_hw(local),
  960. value);
  961. if (ret)
  962. printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
  963. "for low-level driver\n", dev->name, value);
  964. else
  965. sdata->ieee802_1x = value;
  966. break;
  967. case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
  968. local->cts_protect_erp_frames = value;
  969. break;
  970. case PRISM2_PARAM_PREAMBLE:
  971. local->short_preamble = value;
  972. break;
  973. case PRISM2_PARAM_STAT_TIME:
  974. if (!local->stat_time && value) {
  975. local->stat_timer.expires = jiffies + HZ * value / 100;
  976. add_timer(&local->stat_timer);
  977. } else if (local->stat_time && !value) {
  978. del_timer_sync(&local->stat_timer);
  979. }
  980. local->stat_time = value;
  981. break;
  982. case PRISM2_PARAM_SHORT_SLOT_TIME:
  983. if (value)
  984. local->hw.conf.flags |= IEEE80211_CONF_SHORT_SLOT_TIME;
  985. else
  986. local->hw.conf.flags &= ~IEEE80211_CONF_SHORT_SLOT_TIME;
  987. if (ieee80211_hw_config(local))
  988. ret = -EINVAL;
  989. break;
  990. case PRISM2_PARAM_NEXT_MODE:
  991. local->next_mode = value;
  992. break;
  993. case PRISM2_PARAM_RADIO_ENABLED:
  994. ret = ieee80211_ioctl_set_radio_enabled(dev, value);
  995. break;
  996. case PRISM2_PARAM_ANTENNA_MODE:
  997. local->hw.conf.antenna_mode = value;
  998. if (ieee80211_hw_config(local))
  999. ret = -EINVAL;
  1000. break;
  1001. case PRISM2_PARAM_STA_ANTENNA_SEL:
  1002. local->sta_antenna_sel = value;
  1003. break;
  1004. case PRISM2_PARAM_TX_POWER_REDUCTION:
  1005. if (value < 0)
  1006. ret = -EINVAL;
  1007. else
  1008. local->hw.conf.tx_power_reduction = value;
  1009. break;
  1010. case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
  1011. local->key_tx_rx_threshold = value;
  1012. break;
  1013. case PRISM2_PARAM_DEFAULT_WEP_ONLY:
  1014. ret = ieee80211_ioctl_default_wep_only(local, value);
  1015. break;
  1016. case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
  1017. local->wifi_wme_noack_test = value;
  1018. break;
  1019. case PRISM2_PARAM_SCAN_FLAGS:
  1020. local->scan_flags = value;
  1021. break;
  1022. case PRISM2_PARAM_MIXED_CELL:
  1023. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1024. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1025. ret = -EINVAL;
  1026. else
  1027. sdata->u.sta.mixed_cell = !!value;
  1028. break;
  1029. case PRISM2_PARAM_HW_MODES:
  1030. local->enabled_modes = value;
  1031. break;
  1032. case PRISM2_PARAM_CREATE_IBSS:
  1033. if (sdata->type != IEEE80211_IF_TYPE_IBSS)
  1034. ret = -EINVAL;
  1035. else
  1036. sdata->u.sta.create_ibss = !!value;
  1037. break;
  1038. case PRISM2_PARAM_WMM_ENABLED:
  1039. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1040. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1041. ret = -EINVAL;
  1042. else
  1043. sdata->u.sta.wmm_enabled = !!value;
  1044. break;
  1045. case PRISM2_PARAM_RADAR_DETECT:
  1046. local->hw.conf.radar_detect = value;
  1047. break;
  1048. case PRISM2_PARAM_SPECTRUM_MGMT:
  1049. local->hw.conf.spect_mgmt = value;
  1050. break;
  1051. default:
  1052. ret = -EOPNOTSUPP;
  1053. break;
  1054. }
  1055. return ret;
  1056. }
  1057. static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
  1058. struct iw_request_info *info,
  1059. void *wrqu, char *extra)
  1060. {
  1061. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1062. struct ieee80211_sub_if_data *sdata;
  1063. int *param = (int *) extra;
  1064. int ret = 0;
  1065. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1066. switch (*param) {
  1067. case PRISM2_PARAM_IEEE_802_1X:
  1068. *param = sdata->ieee802_1x;
  1069. break;
  1070. case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
  1071. *param = local->cts_protect_erp_frames;
  1072. break;
  1073. case PRISM2_PARAM_PREAMBLE:
  1074. *param = local->short_preamble;
  1075. break;
  1076. case PRISM2_PARAM_STAT_TIME:
  1077. *param = local->stat_time;
  1078. break;
  1079. case PRISM2_PARAM_SHORT_SLOT_TIME:
  1080. *param = !!(local->hw.conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME);
  1081. break;
  1082. case PRISM2_PARAM_NEXT_MODE:
  1083. *param = local->next_mode;
  1084. break;
  1085. case PRISM2_PARAM_ANTENNA_MODE:
  1086. *param = local->hw.conf.antenna_mode;
  1087. break;
  1088. case PRISM2_PARAM_STA_ANTENNA_SEL:
  1089. *param = local->sta_antenna_sel;
  1090. break;
  1091. case PRISM2_PARAM_TX_POWER_REDUCTION:
  1092. *param = local->hw.conf.tx_power_reduction;
  1093. break;
  1094. case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
  1095. *param = local->key_tx_rx_threshold;
  1096. break;
  1097. case PRISM2_PARAM_DEFAULT_WEP_ONLY:
  1098. *param = local->default_wep_only;
  1099. break;
  1100. case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
  1101. *param = local->wifi_wme_noack_test;
  1102. break;
  1103. case PRISM2_PARAM_SCAN_FLAGS:
  1104. *param = local->scan_flags;
  1105. break;
  1106. case PRISM2_PARAM_HW_MODES:
  1107. *param = local->enabled_modes;
  1108. break;
  1109. case PRISM2_PARAM_CREATE_IBSS:
  1110. if (sdata->type != IEEE80211_IF_TYPE_IBSS)
  1111. ret = -EINVAL;
  1112. else
  1113. *param = !!sdata->u.sta.create_ibss;
  1114. break;
  1115. case PRISM2_PARAM_MIXED_CELL:
  1116. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1117. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1118. ret = -EINVAL;
  1119. else
  1120. *param = !!sdata->u.sta.mixed_cell;
  1121. break;
  1122. case PRISM2_PARAM_WMM_ENABLED:
  1123. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1124. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1125. ret = -EINVAL;
  1126. else
  1127. *param = !!sdata->u.sta.wmm_enabled;
  1128. break;
  1129. default:
  1130. ret = -EOPNOTSUPP;
  1131. break;
  1132. }
  1133. return ret;
  1134. }
  1135. static int ieee80211_ioctl_siwmlme(struct net_device *dev,
  1136. struct iw_request_info *info,
  1137. struct iw_point *data, char *extra)
  1138. {
  1139. struct ieee80211_sub_if_data *sdata;
  1140. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  1141. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1142. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1143. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1144. return -EINVAL;
  1145. switch (mlme->cmd) {
  1146. case IW_MLME_DEAUTH:
  1147. /* TODO: mlme->addr.sa_data */
  1148. return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
  1149. case IW_MLME_DISASSOC:
  1150. /* TODO: mlme->addr.sa_data */
  1151. return ieee80211_sta_disassociate(dev, mlme->reason_code);
  1152. default:
  1153. return -EOPNOTSUPP;
  1154. }
  1155. }
  1156. static int ieee80211_ioctl_siwencode(struct net_device *dev,
  1157. struct iw_request_info *info,
  1158. struct iw_point *erq, char *keybuf)
  1159. {
  1160. struct ieee80211_sub_if_data *sdata;
  1161. int idx, i, alg = ALG_WEP;
  1162. u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1163. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1164. idx = erq->flags & IW_ENCODE_INDEX;
  1165. if (idx == 0) {
  1166. if (sdata->default_key)
  1167. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1168. if (sdata->default_key == sdata->keys[i]) {
  1169. idx = i;
  1170. break;
  1171. }
  1172. }
  1173. } else if (idx < 1 || idx > 4)
  1174. return -EINVAL;
  1175. else
  1176. idx--;
  1177. if (erq->flags & IW_ENCODE_DISABLED)
  1178. alg = ALG_NONE;
  1179. else if (erq->length == 0) {
  1180. /* No key data - just set the default TX key index */
  1181. if (sdata->default_key != sdata->keys[idx]) {
  1182. ieee80211_debugfs_key_remove_default(sdata);
  1183. sdata->default_key = sdata->keys[idx];
  1184. if (sdata->default_key)
  1185. ieee80211_debugfs_key_add_default(sdata);
  1186. }
  1187. return 0;
  1188. }
  1189. return ieee80211_set_encryption(
  1190. dev, bcaddr,
  1191. idx, alg,
  1192. !sdata->default_key,
  1193. keybuf, erq->length);
  1194. }
  1195. static int ieee80211_ioctl_giwencode(struct net_device *dev,
  1196. struct iw_request_info *info,
  1197. struct iw_point *erq, char *key)
  1198. {
  1199. struct ieee80211_sub_if_data *sdata;
  1200. int idx, i;
  1201. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1202. idx = erq->flags & IW_ENCODE_INDEX;
  1203. if (idx < 1 || idx > 4) {
  1204. idx = -1;
  1205. if (!sdata->default_key)
  1206. idx = 0;
  1207. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1208. if (sdata->default_key == sdata->keys[i]) {
  1209. idx = i;
  1210. break;
  1211. }
  1212. }
  1213. if (idx < 0)
  1214. return -EINVAL;
  1215. } else
  1216. idx--;
  1217. erq->flags = idx + 1;
  1218. if (!sdata->keys[idx]) {
  1219. erq->length = 0;
  1220. erq->flags |= IW_ENCODE_DISABLED;
  1221. return 0;
  1222. }
  1223. memcpy(key, sdata->keys[idx]->key,
  1224. min((int)erq->length, sdata->keys[idx]->keylen));
  1225. erq->length = sdata->keys[idx]->keylen;
  1226. erq->flags |= IW_ENCODE_ENABLED;
  1227. return 0;
  1228. }
  1229. static int ieee80211_ioctl_siwauth(struct net_device *dev,
  1230. struct iw_request_info *info,
  1231. struct iw_param *data, char *extra)
  1232. {
  1233. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1234. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1235. int ret = 0;
  1236. switch (data->flags & IW_AUTH_INDEX) {
  1237. case IW_AUTH_WPA_VERSION:
  1238. case IW_AUTH_CIPHER_PAIRWISE:
  1239. case IW_AUTH_CIPHER_GROUP:
  1240. case IW_AUTH_WPA_ENABLED:
  1241. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1242. break;
  1243. case IW_AUTH_KEY_MGMT:
  1244. if (sdata->type != IEEE80211_IF_TYPE_STA)
  1245. ret = -EINVAL;
  1246. else {
  1247. /*
  1248. * TODO: sdata->u.sta.key_mgmt does not match with WE18
  1249. * value completely; could consider modifying this to
  1250. * be closer to WE18. For now, this value is not really
  1251. * used for anything else than Privacy matching, so the
  1252. * current code here should be more or less OK.
  1253. */
  1254. if (data->value & IW_AUTH_KEY_MGMT_802_1X) {
  1255. sdata->u.sta.key_mgmt =
  1256. IEEE80211_KEY_MGMT_WPA_EAP;
  1257. } else if (data->value & IW_AUTH_KEY_MGMT_PSK) {
  1258. sdata->u.sta.key_mgmt =
  1259. IEEE80211_KEY_MGMT_WPA_PSK;
  1260. } else {
  1261. sdata->u.sta.key_mgmt =
  1262. IEEE80211_KEY_MGMT_NONE;
  1263. }
  1264. }
  1265. break;
  1266. case IW_AUTH_80211_AUTH_ALG:
  1267. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  1268. sdata->type == IEEE80211_IF_TYPE_IBSS)
  1269. sdata->u.sta.auth_algs = data->value;
  1270. else
  1271. ret = -EOPNOTSUPP;
  1272. break;
  1273. case IW_AUTH_PRIVACY_INVOKED:
  1274. if (local->ops->set_privacy_invoked)
  1275. ret = local->ops->set_privacy_invoked(
  1276. local_to_hw(local), data->value);
  1277. break;
  1278. default:
  1279. ret = -EOPNOTSUPP;
  1280. break;
  1281. }
  1282. return ret;
  1283. }
  1284. /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
  1285. static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
  1286. {
  1287. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1288. struct iw_statistics *wstats = &local->wstats;
  1289. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1290. struct sta_info *sta = NULL;
  1291. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  1292. sdata->type == IEEE80211_IF_TYPE_IBSS)
  1293. sta = sta_info_get(local, sdata->u.sta.bssid);
  1294. if (!sta) {
  1295. wstats->discard.fragment = 0;
  1296. wstats->discard.misc = 0;
  1297. wstats->qual.qual = 0;
  1298. wstats->qual.level = 0;
  1299. wstats->qual.noise = 0;
  1300. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  1301. } else {
  1302. wstats->qual.level = sta->last_rssi;
  1303. wstats->qual.qual = sta->last_signal;
  1304. wstats->qual.noise = sta->last_noise;
  1305. wstats->qual.updated = local->wstats_flags;
  1306. sta_info_put(sta);
  1307. }
  1308. return wstats;
  1309. }
  1310. static int ieee80211_ioctl_giwauth(struct net_device *dev,
  1311. struct iw_request_info *info,
  1312. struct iw_param *data, char *extra)
  1313. {
  1314. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1315. int ret = 0;
  1316. switch (data->flags & IW_AUTH_INDEX) {
  1317. case IW_AUTH_80211_AUTH_ALG:
  1318. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  1319. sdata->type == IEEE80211_IF_TYPE_IBSS)
  1320. data->value = sdata->u.sta.auth_algs;
  1321. else
  1322. ret = -EOPNOTSUPP;
  1323. break;
  1324. default:
  1325. ret = -EOPNOTSUPP;
  1326. break;
  1327. }
  1328. return ret;
  1329. }
  1330. static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
  1331. struct iw_request_info *info,
  1332. struct iw_point *erq, char *extra)
  1333. {
  1334. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1335. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  1336. int alg, idx, i;
  1337. switch (ext->alg) {
  1338. case IW_ENCODE_ALG_NONE:
  1339. alg = ALG_NONE;
  1340. break;
  1341. case IW_ENCODE_ALG_WEP:
  1342. alg = ALG_WEP;
  1343. break;
  1344. case IW_ENCODE_ALG_TKIP:
  1345. alg = ALG_TKIP;
  1346. break;
  1347. case IW_ENCODE_ALG_CCMP:
  1348. alg = ALG_CCMP;
  1349. break;
  1350. default:
  1351. return -EOPNOTSUPP;
  1352. }
  1353. if (erq->flags & IW_ENCODE_DISABLED)
  1354. alg = ALG_NONE;
  1355. idx = erq->flags & IW_ENCODE_INDEX;
  1356. if (idx < 1 || idx > 4) {
  1357. idx = -1;
  1358. if (!sdata->default_key)
  1359. idx = 0;
  1360. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1361. if (sdata->default_key == sdata->keys[i]) {
  1362. idx = i;
  1363. break;
  1364. }
  1365. }
  1366. if (idx < 0)
  1367. return -EINVAL;
  1368. } else
  1369. idx--;
  1370. return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
  1371. ext->ext_flags &
  1372. IW_ENCODE_EXT_SET_TX_KEY,
  1373. ext->key, ext->key_len);
  1374. }
  1375. static const struct iw_priv_args ieee80211_ioctl_priv[] = {
  1376. { PRISM2_IOCTL_PRISM2_PARAM,
  1377. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
  1378. { PRISM2_IOCTL_GET_PRISM2_PARAM,
  1379. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1380. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
  1381. };
  1382. /* Structures to export the Wireless Handlers */
  1383. static const iw_handler ieee80211_handler[] =
  1384. {
  1385. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1386. (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
  1387. (iw_handler) NULL, /* SIOCSIWNWID */
  1388. (iw_handler) NULL, /* SIOCGIWNWID */
  1389. (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
  1390. (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
  1391. (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
  1392. (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
  1393. (iw_handler) NULL, /* SIOCSIWSENS */
  1394. (iw_handler) NULL, /* SIOCGIWSENS */
  1395. (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
  1396. (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
  1397. (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
  1398. (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
  1399. (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
  1400. (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
  1401. iw_handler_set_spy, /* SIOCSIWSPY */
  1402. iw_handler_get_spy, /* SIOCGIWSPY */
  1403. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1404. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1405. (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
  1406. (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
  1407. (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
  1408. (iw_handler) NULL, /* SIOCGIWAPLIST */
  1409. (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
  1410. (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
  1411. (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
  1412. (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
  1413. (iw_handler) NULL, /* SIOCSIWNICKN */
  1414. (iw_handler) NULL, /* SIOCGIWNICKN */
  1415. (iw_handler) NULL, /* -- hole -- */
  1416. (iw_handler) NULL, /* -- hole -- */
  1417. (iw_handler) NULL, /* SIOCSIWRATE */
  1418. (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
  1419. (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
  1420. (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
  1421. (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
  1422. (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
  1423. (iw_handler) NULL, /* SIOCSIWTXPOW */
  1424. (iw_handler) NULL, /* SIOCGIWTXPOW */
  1425. (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
  1426. (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
  1427. (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
  1428. (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
  1429. (iw_handler) NULL, /* SIOCSIWPOWER */
  1430. (iw_handler) NULL, /* SIOCGIWPOWER */
  1431. (iw_handler) NULL, /* -- hole -- */
  1432. (iw_handler) NULL, /* -- hole -- */
  1433. (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
  1434. (iw_handler) NULL, /* SIOCGIWGENIE */
  1435. (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
  1436. (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
  1437. (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
  1438. (iw_handler) NULL, /* SIOCGIWENCODEEXT */
  1439. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1440. (iw_handler) NULL, /* -- hole -- */
  1441. };
  1442. static const iw_handler ieee80211_private_handler[] =
  1443. { /* SIOCIWFIRSTPRIV + */
  1444. (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */
  1445. (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */
  1446. };
  1447. const struct iw_handler_def ieee80211_iw_handler_def =
  1448. {
  1449. .num_standard = ARRAY_SIZE(ieee80211_handler),
  1450. .num_private = ARRAY_SIZE(ieee80211_private_handler),
  1451. .num_private_args = ARRAY_SIZE(ieee80211_ioctl_priv),
  1452. .standard = (iw_handler *) ieee80211_handler,
  1453. .private = (iw_handler *) ieee80211_private_handler,
  1454. .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv,
  1455. .get_wireless_stats = ieee80211_get_wireless_stats,
  1456. };