ieee80211_ioctl.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  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. if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
  604. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  605. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  606. ssid = sdata->u.sta.ssid;
  607. ssid_len = sdata->u.sta.ssid_len;
  608. } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
  609. ssid = sdata->u.ap.ssid;
  610. ssid_len = sdata->u.ap.ssid_len;
  611. } else
  612. return -EINVAL;
  613. }
  614. return ieee80211_sta_req_scan(dev, ssid, ssid_len);
  615. }
  616. static int ieee80211_ioctl_giwscan(struct net_device *dev,
  617. struct iw_request_info *info,
  618. struct iw_point *data, char *extra)
  619. {
  620. int res;
  621. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  622. if (local->sta_scanning)
  623. return -EAGAIN;
  624. res = ieee80211_sta_scan_results(dev, extra, data->length);
  625. if (res >= 0) {
  626. data->length = res;
  627. return 0;
  628. }
  629. data->length = 0;
  630. return res;
  631. }
  632. static int ieee80211_ioctl_siwrate(struct net_device *dev,
  633. struct iw_request_info *info,
  634. struct iw_param *rate, char *extra)
  635. {
  636. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  637. struct ieee80211_hw_mode *mode;
  638. int i;
  639. u32 target_rate = rate->value / 100000;
  640. struct ieee80211_sub_if_data *sdata;
  641. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  642. if (!sdata->bss)
  643. return -ENODEV;
  644. mode = local->oper_hw_mode;
  645. /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
  646. * target_rate = X, rate->fixed = 1 means only rate X
  647. * target_rate = X, rate->fixed = 0 means all rates <= X */
  648. sdata->bss->max_ratectrl_rateidx = -1;
  649. sdata->bss->force_unicast_rateidx = -1;
  650. if (rate->value < 0)
  651. return 0;
  652. for (i=0; i< mode->num_rates; i++) {
  653. struct ieee80211_rate *rates = &mode->rates[i];
  654. int this_rate = rates->rate;
  655. if (mode->mode == MODE_ATHEROS_TURBO ||
  656. mode->mode == MODE_ATHEROS_TURBOG)
  657. this_rate *= 2;
  658. if (target_rate == this_rate) {
  659. sdata->bss->max_ratectrl_rateidx = i;
  660. if (rate->fixed)
  661. sdata->bss->force_unicast_rateidx = i;
  662. break;
  663. }
  664. }
  665. return 0;
  666. }
  667. static int ieee80211_ioctl_giwrate(struct net_device *dev,
  668. struct iw_request_info *info,
  669. struct iw_param *rate, char *extra)
  670. {
  671. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  672. struct sta_info *sta;
  673. struct ieee80211_sub_if_data *sdata;
  674. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  675. if (sdata->type == IEEE80211_IF_TYPE_STA)
  676. sta = sta_info_get(local, sdata->u.sta.bssid);
  677. else
  678. return -EOPNOTSUPP;
  679. if (!sta)
  680. return -ENODEV;
  681. if (sta->txrate < local->oper_hw_mode->num_rates)
  682. rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000;
  683. else
  684. rate->value = 0;
  685. sta_info_put(sta);
  686. return 0;
  687. }
  688. static int ieee80211_ioctl_siwrts(struct net_device *dev,
  689. struct iw_request_info *info,
  690. struct iw_param *rts, char *extra)
  691. {
  692. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  693. if (rts->disabled)
  694. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  695. else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
  696. return -EINVAL;
  697. else
  698. local->rts_threshold = rts->value;
  699. /* If the wlan card performs RTS/CTS in hardware/firmware,
  700. * configure it here */
  701. if (local->ops->set_rts_threshold)
  702. local->ops->set_rts_threshold(local_to_hw(local),
  703. local->rts_threshold);
  704. return 0;
  705. }
  706. static int ieee80211_ioctl_giwrts(struct net_device *dev,
  707. struct iw_request_info *info,
  708. struct iw_param *rts, char *extra)
  709. {
  710. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  711. rts->value = local->rts_threshold;
  712. rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
  713. rts->fixed = 1;
  714. return 0;
  715. }
  716. static int ieee80211_ioctl_siwfrag(struct net_device *dev,
  717. struct iw_request_info *info,
  718. struct iw_param *frag, char *extra)
  719. {
  720. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  721. if (frag->disabled)
  722. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  723. else if (frag->value < 256 ||
  724. frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
  725. return -EINVAL;
  726. else {
  727. /* Fragment length must be even, so strip LSB. */
  728. local->fragmentation_threshold = frag->value & ~0x1;
  729. }
  730. /* If the wlan card performs fragmentation in hardware/firmware,
  731. * configure it here */
  732. if (local->ops->set_frag_threshold)
  733. local->ops->set_frag_threshold(
  734. local_to_hw(local),
  735. local->fragmentation_threshold);
  736. return 0;
  737. }
  738. static int ieee80211_ioctl_giwfrag(struct net_device *dev,
  739. struct iw_request_info *info,
  740. struct iw_param *frag, char *extra)
  741. {
  742. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  743. frag->value = local->fragmentation_threshold;
  744. frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
  745. frag->fixed = 1;
  746. return 0;
  747. }
  748. static int ieee80211_ioctl_siwretry(struct net_device *dev,
  749. struct iw_request_info *info,
  750. struct iw_param *retry, char *extra)
  751. {
  752. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  753. if (retry->disabled ||
  754. (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
  755. return -EINVAL;
  756. if (retry->flags & IW_RETRY_MAX)
  757. local->long_retry_limit = retry->value;
  758. else if (retry->flags & IW_RETRY_MIN)
  759. local->short_retry_limit = retry->value;
  760. else {
  761. local->long_retry_limit = retry->value;
  762. local->short_retry_limit = retry->value;
  763. }
  764. if (local->ops->set_retry_limit) {
  765. return local->ops->set_retry_limit(
  766. local_to_hw(local),
  767. local->short_retry_limit,
  768. local->long_retry_limit);
  769. }
  770. return 0;
  771. }
  772. static int ieee80211_ioctl_giwretry(struct net_device *dev,
  773. struct iw_request_info *info,
  774. struct iw_param *retry, char *extra)
  775. {
  776. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  777. retry->disabled = 0;
  778. if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
  779. /* first return min value, iwconfig will ask max value
  780. * later if needed */
  781. retry->flags |= IW_RETRY_LIMIT;
  782. retry->value = local->short_retry_limit;
  783. if (local->long_retry_limit != local->short_retry_limit)
  784. retry->flags |= IW_RETRY_MIN;
  785. return 0;
  786. }
  787. if (retry->flags & IW_RETRY_MAX) {
  788. retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  789. retry->value = local->long_retry_limit;
  790. }
  791. return 0;
  792. }
  793. static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
  794. struct ieee80211_key *key)
  795. {
  796. struct ieee80211_key_conf *keyconf;
  797. u8 addr[ETH_ALEN];
  798. if (!key || key->alg != ALG_WEP || !key->force_sw_encrypt ||
  799. (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
  800. return;
  801. memset(addr, 0xff, ETH_ALEN);
  802. keyconf = ieee80211_key_data2conf(local, key);
  803. if (keyconf && local->ops->set_key &&
  804. local->ops->set_key(local_to_hw(local),
  805. SET_KEY, addr, keyconf, 0) == 0) {
  806. key->force_sw_encrypt =
  807. !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
  808. key->hw_key_idx = keyconf->hw_key_idx;
  809. }
  810. kfree(keyconf);
  811. }
  812. static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
  813. struct ieee80211_key *key)
  814. {
  815. struct ieee80211_key_conf *keyconf;
  816. u8 addr[ETH_ALEN];
  817. if (!key || key->alg != ALG_WEP || key->force_sw_encrypt ||
  818. (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP))
  819. return;
  820. memset(addr, 0xff, ETH_ALEN);
  821. keyconf = ieee80211_key_data2conf(local, key);
  822. if (keyconf && local->ops->set_key)
  823. local->ops->set_key(local_to_hw(local), DISABLE_KEY,
  824. addr, keyconf, 0);
  825. kfree(keyconf);
  826. key->force_sw_encrypt = 1;
  827. }
  828. static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
  829. int value)
  830. {
  831. int i;
  832. struct ieee80211_sub_if_data *sdata;
  833. local->default_wep_only = value;
  834. read_lock(&local->sub_if_lock);
  835. list_for_each_entry(sdata, &local->sub_if_list, list)
  836. for (i = 0; i < NUM_DEFAULT_KEYS; i++)
  837. if (value)
  838. ieee80211_key_enable_hwaccel(local,
  839. sdata->keys[i]);
  840. else
  841. ieee80211_key_disable_hwaccel(local,
  842. sdata->keys[i]);
  843. read_unlock(&local->sub_if_lock);
  844. return 0;
  845. }
  846. void ieee80211_update_default_wep_only(struct ieee80211_local *local)
  847. {
  848. int i = 0;
  849. struct ieee80211_sub_if_data *sdata;
  850. read_lock(&local->sub_if_lock);
  851. list_for_each_entry(sdata, &local->sub_if_list, list) {
  852. if (sdata->dev == local->mdev)
  853. continue;
  854. /* If there is an AP interface then depend on userspace to
  855. set default_wep_only correctly. */
  856. if (sdata->type == IEEE80211_IF_TYPE_AP) {
  857. read_unlock(&local->sub_if_lock);
  858. return;
  859. }
  860. i++;
  861. }
  862. read_unlock(&local->sub_if_lock);
  863. if (i <= 1)
  864. ieee80211_ioctl_default_wep_only(local, 1);
  865. else
  866. ieee80211_ioctl_default_wep_only(local, 0);
  867. }
  868. static int ieee80211_ioctl_prism2_param(struct net_device *dev,
  869. struct iw_request_info *info,
  870. void *wrqu, char *extra)
  871. {
  872. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  873. struct ieee80211_sub_if_data *sdata;
  874. int *i = (int *) extra;
  875. int param = *i;
  876. int value = *(i + 1);
  877. int ret = 0;
  878. if (!capable(CAP_NET_ADMIN))
  879. return -EPERM;
  880. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  881. switch (param) {
  882. case PRISM2_PARAM_IEEE_802_1X:
  883. if (local->ops->set_ieee8021x)
  884. ret = local->ops->set_ieee8021x(local_to_hw(local),
  885. value);
  886. if (ret)
  887. printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
  888. "for low-level driver\n", dev->name, value);
  889. else
  890. sdata->ieee802_1x = value;
  891. break;
  892. case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
  893. if (sdata->type != IEEE80211_IF_TYPE_AP)
  894. ret = -ENOENT;
  895. else
  896. sdata->use_protection = value;
  897. break;
  898. case PRISM2_PARAM_PREAMBLE:
  899. local->short_preamble = value;
  900. break;
  901. case PRISM2_PARAM_STAT_TIME:
  902. if (!local->stat_time && value) {
  903. local->stat_timer.expires = jiffies + HZ * value / 100;
  904. add_timer(&local->stat_timer);
  905. } else if (local->stat_time && !value) {
  906. del_timer_sync(&local->stat_timer);
  907. }
  908. local->stat_time = value;
  909. break;
  910. case PRISM2_PARAM_SHORT_SLOT_TIME:
  911. if (value)
  912. local->hw.conf.flags |= IEEE80211_CONF_SHORT_SLOT_TIME;
  913. else
  914. local->hw.conf.flags &= ~IEEE80211_CONF_SHORT_SLOT_TIME;
  915. if (ieee80211_hw_config(local))
  916. ret = -EINVAL;
  917. break;
  918. case PRISM2_PARAM_NEXT_MODE:
  919. local->next_mode = value;
  920. break;
  921. case PRISM2_PARAM_RADIO_ENABLED:
  922. ret = ieee80211_ioctl_set_radio_enabled(dev, value);
  923. break;
  924. case PRISM2_PARAM_ANTENNA_MODE:
  925. local->hw.conf.antenna_mode = value;
  926. if (ieee80211_hw_config(local))
  927. ret = -EINVAL;
  928. break;
  929. case PRISM2_PARAM_STA_ANTENNA_SEL:
  930. local->sta_antenna_sel = value;
  931. break;
  932. case PRISM2_PARAM_TX_POWER_REDUCTION:
  933. if (value < 0)
  934. ret = -EINVAL;
  935. else
  936. local->hw.conf.tx_power_reduction = value;
  937. break;
  938. case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
  939. local->key_tx_rx_threshold = value;
  940. break;
  941. case PRISM2_PARAM_DEFAULT_WEP_ONLY:
  942. ret = ieee80211_ioctl_default_wep_only(local, value);
  943. break;
  944. case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
  945. local->wifi_wme_noack_test = value;
  946. break;
  947. case PRISM2_PARAM_SCAN_FLAGS:
  948. local->scan_flags = value;
  949. break;
  950. case PRISM2_PARAM_MIXED_CELL:
  951. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  952. sdata->type != IEEE80211_IF_TYPE_IBSS)
  953. ret = -EINVAL;
  954. else
  955. sdata->u.sta.mixed_cell = !!value;
  956. break;
  957. case PRISM2_PARAM_HW_MODES:
  958. local->enabled_modes = value;
  959. break;
  960. case PRISM2_PARAM_CREATE_IBSS:
  961. if (sdata->type != IEEE80211_IF_TYPE_IBSS)
  962. ret = -EINVAL;
  963. else
  964. sdata->u.sta.create_ibss = !!value;
  965. break;
  966. case PRISM2_PARAM_WMM_ENABLED:
  967. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  968. sdata->type != IEEE80211_IF_TYPE_IBSS)
  969. ret = -EINVAL;
  970. else
  971. sdata->u.sta.wmm_enabled = !!value;
  972. break;
  973. case PRISM2_PARAM_RADAR_DETECT:
  974. local->hw.conf.radar_detect = value;
  975. break;
  976. case PRISM2_PARAM_SPECTRUM_MGMT:
  977. local->hw.conf.spect_mgmt = value;
  978. break;
  979. default:
  980. ret = -EOPNOTSUPP;
  981. break;
  982. }
  983. return ret;
  984. }
  985. static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
  986. struct iw_request_info *info,
  987. void *wrqu, char *extra)
  988. {
  989. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  990. struct ieee80211_sub_if_data *sdata;
  991. int *param = (int *) extra;
  992. int ret = 0;
  993. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  994. switch (*param) {
  995. case PRISM2_PARAM_IEEE_802_1X:
  996. *param = sdata->ieee802_1x;
  997. break;
  998. case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
  999. *param = sdata->use_protection;
  1000. break;
  1001. case PRISM2_PARAM_PREAMBLE:
  1002. *param = local->short_preamble;
  1003. break;
  1004. case PRISM2_PARAM_STAT_TIME:
  1005. *param = local->stat_time;
  1006. break;
  1007. case PRISM2_PARAM_SHORT_SLOT_TIME:
  1008. *param = !!(local->hw.conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME);
  1009. break;
  1010. case PRISM2_PARAM_NEXT_MODE:
  1011. *param = local->next_mode;
  1012. break;
  1013. case PRISM2_PARAM_ANTENNA_MODE:
  1014. *param = local->hw.conf.antenna_mode;
  1015. break;
  1016. case PRISM2_PARAM_STA_ANTENNA_SEL:
  1017. *param = local->sta_antenna_sel;
  1018. break;
  1019. case PRISM2_PARAM_TX_POWER_REDUCTION:
  1020. *param = local->hw.conf.tx_power_reduction;
  1021. break;
  1022. case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
  1023. *param = local->key_tx_rx_threshold;
  1024. break;
  1025. case PRISM2_PARAM_DEFAULT_WEP_ONLY:
  1026. *param = local->default_wep_only;
  1027. break;
  1028. case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
  1029. *param = local->wifi_wme_noack_test;
  1030. break;
  1031. case PRISM2_PARAM_SCAN_FLAGS:
  1032. *param = local->scan_flags;
  1033. break;
  1034. case PRISM2_PARAM_HW_MODES:
  1035. *param = local->enabled_modes;
  1036. break;
  1037. case PRISM2_PARAM_CREATE_IBSS:
  1038. if (sdata->type != IEEE80211_IF_TYPE_IBSS)
  1039. ret = -EINVAL;
  1040. else
  1041. *param = !!sdata->u.sta.create_ibss;
  1042. break;
  1043. case PRISM2_PARAM_MIXED_CELL:
  1044. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1045. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1046. ret = -EINVAL;
  1047. else
  1048. *param = !!sdata->u.sta.mixed_cell;
  1049. break;
  1050. case PRISM2_PARAM_WMM_ENABLED:
  1051. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1052. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1053. ret = -EINVAL;
  1054. else
  1055. *param = !!sdata->u.sta.wmm_enabled;
  1056. break;
  1057. default:
  1058. ret = -EOPNOTSUPP;
  1059. break;
  1060. }
  1061. return ret;
  1062. }
  1063. static int ieee80211_ioctl_siwmlme(struct net_device *dev,
  1064. struct iw_request_info *info,
  1065. struct iw_point *data, char *extra)
  1066. {
  1067. struct ieee80211_sub_if_data *sdata;
  1068. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  1069. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1070. if (sdata->type != IEEE80211_IF_TYPE_STA &&
  1071. sdata->type != IEEE80211_IF_TYPE_IBSS)
  1072. return -EINVAL;
  1073. switch (mlme->cmd) {
  1074. case IW_MLME_DEAUTH:
  1075. /* TODO: mlme->addr.sa_data */
  1076. return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
  1077. case IW_MLME_DISASSOC:
  1078. /* TODO: mlme->addr.sa_data */
  1079. return ieee80211_sta_disassociate(dev, mlme->reason_code);
  1080. default:
  1081. return -EOPNOTSUPP;
  1082. }
  1083. }
  1084. static int ieee80211_ioctl_siwencode(struct net_device *dev,
  1085. struct iw_request_info *info,
  1086. struct iw_point *erq, char *keybuf)
  1087. {
  1088. struct ieee80211_sub_if_data *sdata;
  1089. int idx, i, alg = ALG_WEP;
  1090. u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1091. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1092. idx = erq->flags & IW_ENCODE_INDEX;
  1093. if (idx == 0) {
  1094. if (sdata->default_key)
  1095. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1096. if (sdata->default_key == sdata->keys[i]) {
  1097. idx = i;
  1098. break;
  1099. }
  1100. }
  1101. } else if (idx < 1 || idx > 4)
  1102. return -EINVAL;
  1103. else
  1104. idx--;
  1105. if (erq->flags & IW_ENCODE_DISABLED)
  1106. alg = ALG_NONE;
  1107. else if (erq->length == 0) {
  1108. /* No key data - just set the default TX key index */
  1109. if (sdata->default_key != sdata->keys[idx]) {
  1110. ieee80211_debugfs_key_remove_default(sdata);
  1111. sdata->default_key = sdata->keys[idx];
  1112. if (sdata->default_key)
  1113. ieee80211_debugfs_key_add_default(sdata);
  1114. }
  1115. return 0;
  1116. }
  1117. return ieee80211_set_encryption(
  1118. dev, bcaddr,
  1119. idx, alg,
  1120. !sdata->default_key,
  1121. keybuf, erq->length);
  1122. }
  1123. static int ieee80211_ioctl_giwencode(struct net_device *dev,
  1124. struct iw_request_info *info,
  1125. struct iw_point *erq, char *key)
  1126. {
  1127. struct ieee80211_sub_if_data *sdata;
  1128. int idx, i;
  1129. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1130. idx = erq->flags & IW_ENCODE_INDEX;
  1131. if (idx < 1 || idx > 4) {
  1132. idx = -1;
  1133. if (!sdata->default_key)
  1134. idx = 0;
  1135. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1136. if (sdata->default_key == sdata->keys[i]) {
  1137. idx = i;
  1138. break;
  1139. }
  1140. }
  1141. if (idx < 0)
  1142. return -EINVAL;
  1143. } else
  1144. idx--;
  1145. erq->flags = idx + 1;
  1146. if (!sdata->keys[idx]) {
  1147. erq->length = 0;
  1148. erq->flags |= IW_ENCODE_DISABLED;
  1149. return 0;
  1150. }
  1151. memcpy(key, sdata->keys[idx]->key,
  1152. min((int)erq->length, sdata->keys[idx]->keylen));
  1153. erq->length = sdata->keys[idx]->keylen;
  1154. erq->flags |= IW_ENCODE_ENABLED;
  1155. return 0;
  1156. }
  1157. static int ieee80211_ioctl_siwauth(struct net_device *dev,
  1158. struct iw_request_info *info,
  1159. struct iw_param *data, char *extra)
  1160. {
  1161. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1162. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1163. int ret = 0;
  1164. switch (data->flags & IW_AUTH_INDEX) {
  1165. case IW_AUTH_WPA_VERSION:
  1166. case IW_AUTH_CIPHER_PAIRWISE:
  1167. case IW_AUTH_CIPHER_GROUP:
  1168. case IW_AUTH_WPA_ENABLED:
  1169. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  1170. break;
  1171. case IW_AUTH_KEY_MGMT:
  1172. if (sdata->type != IEEE80211_IF_TYPE_STA)
  1173. ret = -EINVAL;
  1174. else {
  1175. /*
  1176. * TODO: sdata->u.sta.key_mgmt does not match with WE18
  1177. * value completely; could consider modifying this to
  1178. * be closer to WE18. For now, this value is not really
  1179. * used for anything else than Privacy matching, so the
  1180. * current code here should be more or less OK.
  1181. */
  1182. if (data->value & IW_AUTH_KEY_MGMT_802_1X) {
  1183. sdata->u.sta.key_mgmt =
  1184. IEEE80211_KEY_MGMT_WPA_EAP;
  1185. } else if (data->value & IW_AUTH_KEY_MGMT_PSK) {
  1186. sdata->u.sta.key_mgmt =
  1187. IEEE80211_KEY_MGMT_WPA_PSK;
  1188. } else {
  1189. sdata->u.sta.key_mgmt =
  1190. IEEE80211_KEY_MGMT_NONE;
  1191. }
  1192. }
  1193. break;
  1194. case IW_AUTH_80211_AUTH_ALG:
  1195. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  1196. sdata->type == IEEE80211_IF_TYPE_IBSS)
  1197. sdata->u.sta.auth_algs = data->value;
  1198. else
  1199. ret = -EOPNOTSUPP;
  1200. break;
  1201. case IW_AUTH_PRIVACY_INVOKED:
  1202. if (local->ops->set_privacy_invoked)
  1203. ret = local->ops->set_privacy_invoked(
  1204. local_to_hw(local), data->value);
  1205. break;
  1206. default:
  1207. ret = -EOPNOTSUPP;
  1208. break;
  1209. }
  1210. return ret;
  1211. }
  1212. /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
  1213. static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
  1214. {
  1215. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1216. struct iw_statistics *wstats = &local->wstats;
  1217. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1218. struct sta_info *sta = NULL;
  1219. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  1220. sdata->type == IEEE80211_IF_TYPE_IBSS)
  1221. sta = sta_info_get(local, sdata->u.sta.bssid);
  1222. if (!sta) {
  1223. wstats->discard.fragment = 0;
  1224. wstats->discard.misc = 0;
  1225. wstats->qual.qual = 0;
  1226. wstats->qual.level = 0;
  1227. wstats->qual.noise = 0;
  1228. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  1229. } else {
  1230. wstats->qual.level = sta->last_rssi;
  1231. wstats->qual.qual = sta->last_signal;
  1232. wstats->qual.noise = sta->last_noise;
  1233. wstats->qual.updated = local->wstats_flags;
  1234. sta_info_put(sta);
  1235. }
  1236. return wstats;
  1237. }
  1238. static int ieee80211_ioctl_giwauth(struct net_device *dev,
  1239. struct iw_request_info *info,
  1240. struct iw_param *data, char *extra)
  1241. {
  1242. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1243. int ret = 0;
  1244. switch (data->flags & IW_AUTH_INDEX) {
  1245. case IW_AUTH_80211_AUTH_ALG:
  1246. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  1247. sdata->type == IEEE80211_IF_TYPE_IBSS)
  1248. data->value = sdata->u.sta.auth_algs;
  1249. else
  1250. ret = -EOPNOTSUPP;
  1251. break;
  1252. default:
  1253. ret = -EOPNOTSUPP;
  1254. break;
  1255. }
  1256. return ret;
  1257. }
  1258. static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
  1259. struct iw_request_info *info,
  1260. struct iw_point *erq, char *extra)
  1261. {
  1262. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1263. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  1264. int alg, idx, i;
  1265. switch (ext->alg) {
  1266. case IW_ENCODE_ALG_NONE:
  1267. alg = ALG_NONE;
  1268. break;
  1269. case IW_ENCODE_ALG_WEP:
  1270. alg = ALG_WEP;
  1271. break;
  1272. case IW_ENCODE_ALG_TKIP:
  1273. alg = ALG_TKIP;
  1274. break;
  1275. case IW_ENCODE_ALG_CCMP:
  1276. alg = ALG_CCMP;
  1277. break;
  1278. default:
  1279. return -EOPNOTSUPP;
  1280. }
  1281. if (erq->flags & IW_ENCODE_DISABLED)
  1282. alg = ALG_NONE;
  1283. idx = erq->flags & IW_ENCODE_INDEX;
  1284. if (idx < 1 || idx > 4) {
  1285. idx = -1;
  1286. if (!sdata->default_key)
  1287. idx = 0;
  1288. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1289. if (sdata->default_key == sdata->keys[i]) {
  1290. idx = i;
  1291. break;
  1292. }
  1293. }
  1294. if (idx < 0)
  1295. return -EINVAL;
  1296. } else
  1297. idx--;
  1298. return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
  1299. ext->ext_flags &
  1300. IW_ENCODE_EXT_SET_TX_KEY,
  1301. ext->key, ext->key_len);
  1302. }
  1303. static const struct iw_priv_args ieee80211_ioctl_priv[] = {
  1304. { PRISM2_IOCTL_PRISM2_PARAM,
  1305. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
  1306. { PRISM2_IOCTL_GET_PRISM2_PARAM,
  1307. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  1308. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
  1309. };
  1310. /* Structures to export the Wireless Handlers */
  1311. static const iw_handler ieee80211_handler[] =
  1312. {
  1313. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  1314. (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
  1315. (iw_handler) NULL, /* SIOCSIWNWID */
  1316. (iw_handler) NULL, /* SIOCGIWNWID */
  1317. (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
  1318. (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
  1319. (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
  1320. (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
  1321. (iw_handler) NULL, /* SIOCSIWSENS */
  1322. (iw_handler) NULL, /* SIOCGIWSENS */
  1323. (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
  1324. (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
  1325. (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
  1326. (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
  1327. (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
  1328. (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
  1329. iw_handler_set_spy, /* SIOCSIWSPY */
  1330. iw_handler_get_spy, /* SIOCGIWSPY */
  1331. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  1332. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  1333. (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
  1334. (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
  1335. (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
  1336. (iw_handler) NULL, /* SIOCGIWAPLIST */
  1337. (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
  1338. (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
  1339. (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
  1340. (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
  1341. (iw_handler) NULL, /* SIOCSIWNICKN */
  1342. (iw_handler) NULL, /* SIOCGIWNICKN */
  1343. (iw_handler) NULL, /* -- hole -- */
  1344. (iw_handler) NULL, /* -- hole -- */
  1345. (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
  1346. (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
  1347. (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
  1348. (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
  1349. (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
  1350. (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
  1351. (iw_handler) NULL, /* SIOCSIWTXPOW */
  1352. (iw_handler) NULL, /* SIOCGIWTXPOW */
  1353. (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
  1354. (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
  1355. (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
  1356. (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
  1357. (iw_handler) NULL, /* SIOCSIWPOWER */
  1358. (iw_handler) NULL, /* SIOCGIWPOWER */
  1359. (iw_handler) NULL, /* -- hole -- */
  1360. (iw_handler) NULL, /* -- hole -- */
  1361. (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
  1362. (iw_handler) NULL, /* SIOCGIWGENIE */
  1363. (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
  1364. (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
  1365. (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
  1366. (iw_handler) NULL, /* SIOCGIWENCODEEXT */
  1367. (iw_handler) NULL, /* SIOCSIWPMKSA */
  1368. (iw_handler) NULL, /* -- hole -- */
  1369. };
  1370. static const iw_handler ieee80211_private_handler[] =
  1371. { /* SIOCIWFIRSTPRIV + */
  1372. (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */
  1373. (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */
  1374. };
  1375. const struct iw_handler_def ieee80211_iw_handler_def =
  1376. {
  1377. .num_standard = ARRAY_SIZE(ieee80211_handler),
  1378. .num_private = ARRAY_SIZE(ieee80211_private_handler),
  1379. .num_private_args = ARRAY_SIZE(ieee80211_ioctl_priv),
  1380. .standard = (iw_handler *) ieee80211_handler,
  1381. .private = (iw_handler *) ieee80211_private_handler,
  1382. .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv,
  1383. .get_wireless_stats = ieee80211_get_wireless_stats,
  1384. };