wext.c 29 KB

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