ieee80211_ioctl.c 42 KB

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