wext.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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. u32 reconf_flags = 0;
  350. int new_power_level;
  351. if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
  352. return -EINVAL;
  353. if (data->txpower.flags & IW_TXPOW_RANGE)
  354. return -EINVAL;
  355. if (!chan)
  356. return -EINVAL;
  357. if (data->txpower.fixed)
  358. new_power_level = min(data->txpower.value, chan->max_power);
  359. else /* Automatic power level setting */
  360. new_power_level = chan->max_power;
  361. local->user_power_level = new_power_level;
  362. if (local->hw.conf.power_level != new_power_level)
  363. reconf_flags |= IEEE80211_CONF_CHANGE_POWER;
  364. if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
  365. local->hw.conf.radio_enabled = !(data->txpower.disabled);
  366. reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
  367. ieee80211_led_radio(local, local->hw.conf.radio_enabled);
  368. }
  369. if (reconf_flags)
  370. ieee80211_hw_config(local, reconf_flags);
  371. return 0;
  372. }
  373. static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
  374. struct iw_request_info *info,
  375. union iwreq_data *data, char *extra)
  376. {
  377. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  378. data->txpower.fixed = 1;
  379. data->txpower.disabled = !(local->hw.conf.radio_enabled);
  380. data->txpower.value = local->hw.conf.power_level;
  381. data->txpower.flags = IW_TXPOW_DBM;
  382. return 0;
  383. }
  384. static int ieee80211_ioctl_siwrts(struct net_device *dev,
  385. struct iw_request_info *info,
  386. struct iw_param *rts, char *extra)
  387. {
  388. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  389. if (rts->disabled)
  390. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  391. else if (!rts->fixed)
  392. /* if the rts value is not fixed, then take default */
  393. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  394. else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
  395. return -EINVAL;
  396. else
  397. local->rts_threshold = rts->value;
  398. /* If the wlan card performs RTS/CTS in hardware/firmware,
  399. * configure it here */
  400. if (local->ops->set_rts_threshold)
  401. local->ops->set_rts_threshold(local_to_hw(local),
  402. local->rts_threshold);
  403. return 0;
  404. }
  405. static int ieee80211_ioctl_giwrts(struct net_device *dev,
  406. struct iw_request_info *info,
  407. struct iw_param *rts, char *extra)
  408. {
  409. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  410. rts->value = local->rts_threshold;
  411. rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
  412. rts->fixed = 1;
  413. return 0;
  414. }
  415. static int ieee80211_ioctl_siwfrag(struct net_device *dev,
  416. struct iw_request_info *info,
  417. struct iw_param *frag, char *extra)
  418. {
  419. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  420. if (frag->disabled)
  421. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  422. else if (!frag->fixed)
  423. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  424. else if (frag->value < 256 ||
  425. frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
  426. return -EINVAL;
  427. else {
  428. /* Fragment length must be even, so strip LSB. */
  429. local->fragmentation_threshold = frag->value & ~0x1;
  430. }
  431. return 0;
  432. }
  433. static int ieee80211_ioctl_giwfrag(struct net_device *dev,
  434. struct iw_request_info *info,
  435. struct iw_param *frag, char *extra)
  436. {
  437. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  438. frag->value = local->fragmentation_threshold;
  439. frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
  440. frag->fixed = 1;
  441. return 0;
  442. }
  443. static int ieee80211_ioctl_siwretry(struct net_device *dev,
  444. struct iw_request_info *info,
  445. struct iw_param *retry, char *extra)
  446. {
  447. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  448. if (retry->disabled ||
  449. (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
  450. return -EINVAL;
  451. if (retry->flags & IW_RETRY_MAX) {
  452. local->hw.conf.long_frame_max_tx_count = retry->value;
  453. } else if (retry->flags & IW_RETRY_MIN) {
  454. local->hw.conf.short_frame_max_tx_count = retry->value;
  455. } else {
  456. local->hw.conf.long_frame_max_tx_count = retry->value;
  457. local->hw.conf.short_frame_max_tx_count = retry->value;
  458. }
  459. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
  460. return 0;
  461. }
  462. static int ieee80211_ioctl_giwretry(struct net_device *dev,
  463. struct iw_request_info *info,
  464. struct iw_param *retry, char *extra)
  465. {
  466. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  467. retry->disabled = 0;
  468. if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
  469. /* first return min value, iwconfig will ask max value
  470. * later if needed */
  471. retry->flags |= IW_RETRY_LIMIT;
  472. retry->value = local->hw.conf.short_frame_max_tx_count;
  473. if (local->hw.conf.long_frame_max_tx_count !=
  474. local->hw.conf.short_frame_max_tx_count)
  475. retry->flags |= IW_RETRY_MIN;
  476. return 0;
  477. }
  478. if (retry->flags & IW_RETRY_MAX) {
  479. retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  480. retry->value = local->hw.conf.long_frame_max_tx_count;
  481. }
  482. return 0;
  483. }
  484. static int ieee80211_ioctl_siwmlme(struct net_device *dev,
  485. struct iw_request_info *info,
  486. struct iw_point *data, char *extra)
  487. {
  488. struct ieee80211_sub_if_data *sdata;
  489. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  490. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  491. if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
  492. return -EINVAL;
  493. switch (mlme->cmd) {
  494. case IW_MLME_DEAUTH:
  495. /* TODO: mlme->addr.sa_data */
  496. return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
  497. case IW_MLME_DISASSOC:
  498. /* TODO: mlme->addr.sa_data */
  499. return ieee80211_sta_disassociate(sdata, mlme->reason_code);
  500. default:
  501. return -EOPNOTSUPP;
  502. }
  503. }
  504. static int ieee80211_ioctl_siwencode(struct net_device *dev,
  505. struct iw_request_info *info,
  506. struct iw_point *erq, char *keybuf)
  507. {
  508. struct ieee80211_sub_if_data *sdata;
  509. int idx, i, alg = ALG_WEP;
  510. u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  511. int remove = 0, ret;
  512. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  513. idx = erq->flags & IW_ENCODE_INDEX;
  514. if (idx == 0) {
  515. if (sdata->default_key)
  516. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  517. if (sdata->default_key == sdata->keys[i]) {
  518. idx = i;
  519. break;
  520. }
  521. }
  522. } else if (idx < 1 || idx > 4)
  523. return -EINVAL;
  524. else
  525. idx--;
  526. if (erq->flags & IW_ENCODE_DISABLED)
  527. remove = 1;
  528. else if (erq->length == 0) {
  529. /* No key data - just set the default TX key index */
  530. ieee80211_set_default_key(sdata, idx);
  531. return 0;
  532. }
  533. ret = ieee80211_set_encryption(
  534. sdata, bcaddr,
  535. idx, alg, remove,
  536. !sdata->default_key,
  537. keybuf, erq->length);
  538. if (!ret) {
  539. if (remove)
  540. sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
  541. else
  542. sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
  543. }
  544. return ret;
  545. }
  546. static int ieee80211_ioctl_giwencode(struct net_device *dev,
  547. struct iw_request_info *info,
  548. struct iw_point *erq, char *key)
  549. {
  550. struct ieee80211_sub_if_data *sdata;
  551. int idx, i;
  552. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  553. idx = erq->flags & IW_ENCODE_INDEX;
  554. if (idx < 1 || idx > 4) {
  555. idx = -1;
  556. if (!sdata->default_key)
  557. idx = 0;
  558. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  559. if (sdata->default_key == sdata->keys[i]) {
  560. idx = i;
  561. break;
  562. }
  563. }
  564. if (idx < 0)
  565. return -EINVAL;
  566. } else
  567. idx--;
  568. erq->flags = idx + 1;
  569. if (!sdata->keys[idx]) {
  570. erq->length = 0;
  571. erq->flags |= IW_ENCODE_DISABLED;
  572. return 0;
  573. }
  574. memcpy(key, sdata->keys[idx]->conf.key,
  575. min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
  576. erq->length = sdata->keys[idx]->conf.keylen;
  577. erq->flags |= IW_ENCODE_ENABLED;
  578. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  579. switch (sdata->u.mgd.auth_alg) {
  580. case WLAN_AUTH_OPEN:
  581. case WLAN_AUTH_LEAP:
  582. erq->flags |= IW_ENCODE_OPEN;
  583. break;
  584. case WLAN_AUTH_SHARED_KEY:
  585. erq->flags |= IW_ENCODE_RESTRICTED;
  586. break;
  587. }
  588. }
  589. return 0;
  590. }
  591. static int ieee80211_ioctl_siwpower(struct net_device *dev,
  592. struct iw_request_info *info,
  593. struct iw_param *wrq,
  594. char *extra)
  595. {
  596. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  597. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  598. struct ieee80211_conf *conf = &local->hw.conf;
  599. int ret = 0, timeout = 0;
  600. bool ps;
  601. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
  602. return -EOPNOTSUPP;
  603. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  604. return -EINVAL;
  605. if (wrq->disabled) {
  606. ps = false;
  607. timeout = 0;
  608. goto set;
  609. }
  610. switch (wrq->flags & IW_POWER_MODE) {
  611. case IW_POWER_ON: /* If not specified */
  612. case IW_POWER_MODE: /* If set all mask */
  613. case IW_POWER_ALL_R: /* If explicitely state all */
  614. ps = true;
  615. break;
  616. default: /* Otherwise we ignore */
  617. return -EINVAL;
  618. }
  619. if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
  620. return -EINVAL;
  621. if (wrq->flags & IW_POWER_TIMEOUT)
  622. timeout = wrq->value / 1000;
  623. set:
  624. if (ps == local->powersave && timeout == conf->dynamic_ps_timeout)
  625. return ret;
  626. local->powersave = ps;
  627. conf->dynamic_ps_timeout = timeout;
  628. if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
  629. ret = ieee80211_hw_config(local,
  630. IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
  631. if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
  632. return ret;
  633. if (conf->dynamic_ps_timeout > 0 &&
  634. !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
  635. mod_timer(&local->dynamic_ps_timer, jiffies +
  636. msecs_to_jiffies(conf->dynamic_ps_timeout));
  637. } else {
  638. if (local->powersave) {
  639. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  640. ieee80211_send_nullfunc(local, sdata, 1);
  641. conf->flags |= IEEE80211_CONF_PS;
  642. ret = ieee80211_hw_config(local,
  643. IEEE80211_CONF_CHANGE_PS);
  644. } else {
  645. conf->flags &= ~IEEE80211_CONF_PS;
  646. ret = ieee80211_hw_config(local,
  647. IEEE80211_CONF_CHANGE_PS);
  648. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  649. ieee80211_send_nullfunc(local, sdata, 0);
  650. del_timer_sync(&local->dynamic_ps_timer);
  651. cancel_work_sync(&local->dynamic_ps_enable_work);
  652. }
  653. }
  654. return ret;
  655. }
  656. static int ieee80211_ioctl_giwpower(struct net_device *dev,
  657. struct iw_request_info *info,
  658. union iwreq_data *wrqu,
  659. char *extra)
  660. {
  661. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  662. wrqu->power.disabled = !local->powersave;
  663. return 0;
  664. }
  665. static int ieee80211_ioctl_siwauth(struct net_device *dev,
  666. struct iw_request_info *info,
  667. struct iw_param *data, char *extra)
  668. {
  669. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  670. int ret = 0;
  671. switch (data->flags & IW_AUTH_INDEX) {
  672. case IW_AUTH_WPA_VERSION:
  673. case IW_AUTH_CIPHER_GROUP:
  674. case IW_AUTH_WPA_ENABLED:
  675. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  676. case IW_AUTH_KEY_MGMT:
  677. case IW_AUTH_CIPHER_GROUP_MGMT:
  678. break;
  679. case IW_AUTH_CIPHER_PAIRWISE:
  680. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  681. if (data->value & (IW_AUTH_CIPHER_WEP40 |
  682. IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
  683. sdata->u.mgd.flags |=
  684. IEEE80211_STA_TKIP_WEP_USED;
  685. else
  686. sdata->u.mgd.flags &=
  687. ~IEEE80211_STA_TKIP_WEP_USED;
  688. }
  689. break;
  690. case IW_AUTH_DROP_UNENCRYPTED:
  691. sdata->drop_unencrypted = !!data->value;
  692. break;
  693. case IW_AUTH_PRIVACY_INVOKED:
  694. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  695. ret = -EINVAL;
  696. else {
  697. sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
  698. /*
  699. * Privacy invoked by wpa_supplicant, store the
  700. * value and allow associating to a protected
  701. * network without having a key up front.
  702. */
  703. if (data->value)
  704. sdata->u.mgd.flags |=
  705. IEEE80211_STA_PRIVACY_INVOKED;
  706. }
  707. break;
  708. case IW_AUTH_80211_AUTH_ALG:
  709. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  710. sdata->u.mgd.auth_algs = data->value;
  711. else
  712. ret = -EOPNOTSUPP;
  713. break;
  714. case IW_AUTH_MFP:
  715. if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
  716. ret = -EOPNOTSUPP;
  717. break;
  718. }
  719. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  720. switch (data->value) {
  721. case IW_AUTH_MFP_DISABLED:
  722. sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
  723. break;
  724. case IW_AUTH_MFP_OPTIONAL:
  725. sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
  726. break;
  727. case IW_AUTH_MFP_REQUIRED:
  728. sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
  729. break;
  730. default:
  731. ret = -EINVAL;
  732. }
  733. } else
  734. ret = -EOPNOTSUPP;
  735. break;
  736. default:
  737. ret = -EOPNOTSUPP;
  738. break;
  739. }
  740. return ret;
  741. }
  742. /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
  743. static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
  744. {
  745. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  746. struct iw_statistics *wstats = &local->wstats;
  747. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  748. struct sta_info *sta = NULL;
  749. rcu_read_lock();
  750. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  751. sta = sta_info_get(local, sdata->u.mgd.bssid);
  752. if (!sta) {
  753. wstats->discard.fragment = 0;
  754. wstats->discard.misc = 0;
  755. wstats->qual.qual = 0;
  756. wstats->qual.level = 0;
  757. wstats->qual.noise = 0;
  758. wstats->qual.updated = IW_QUAL_ALL_INVALID;
  759. } else {
  760. wstats->qual.updated = 0;
  761. /*
  762. * mirror what cfg80211 does for iwrange/scan results,
  763. * otherwise userspace gets confused.
  764. */
  765. if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
  766. IEEE80211_HW_SIGNAL_DBM)) {
  767. wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
  768. wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
  769. } else {
  770. wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
  771. wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
  772. }
  773. if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
  774. wstats->qual.level = sta->last_signal;
  775. wstats->qual.qual = sta->last_signal;
  776. } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  777. int sig = sta->last_signal;
  778. wstats->qual.updated |= IW_QUAL_DBM;
  779. wstats->qual.level = sig;
  780. if (sig < -110)
  781. sig = -110;
  782. else if (sig > -40)
  783. sig = -40;
  784. wstats->qual.qual = sig + 110;
  785. }
  786. if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
  787. /*
  788. * This assumes that if driver reports noise, it also
  789. * reports signal in dBm.
  790. */
  791. wstats->qual.noise = sta->last_noise;
  792. wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
  793. } else {
  794. wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
  795. }
  796. }
  797. rcu_read_unlock();
  798. return wstats;
  799. }
  800. static int ieee80211_ioctl_giwauth(struct net_device *dev,
  801. struct iw_request_info *info,
  802. struct iw_param *data, char *extra)
  803. {
  804. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  805. int ret = 0;
  806. switch (data->flags & IW_AUTH_INDEX) {
  807. case IW_AUTH_80211_AUTH_ALG:
  808. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  809. data->value = sdata->u.mgd.auth_algs;
  810. else
  811. ret = -EOPNOTSUPP;
  812. break;
  813. default:
  814. ret = -EOPNOTSUPP;
  815. break;
  816. }
  817. return ret;
  818. }
  819. static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
  820. struct iw_request_info *info,
  821. struct iw_point *erq, char *extra)
  822. {
  823. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  824. struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
  825. int uninitialized_var(alg), idx, i, remove = 0;
  826. switch (ext->alg) {
  827. case IW_ENCODE_ALG_NONE:
  828. remove = 1;
  829. break;
  830. case IW_ENCODE_ALG_WEP:
  831. alg = ALG_WEP;
  832. break;
  833. case IW_ENCODE_ALG_TKIP:
  834. alg = ALG_TKIP;
  835. break;
  836. case IW_ENCODE_ALG_CCMP:
  837. alg = ALG_CCMP;
  838. break;
  839. case IW_ENCODE_ALG_AES_CMAC:
  840. alg = ALG_AES_CMAC;
  841. break;
  842. default:
  843. return -EOPNOTSUPP;
  844. }
  845. if (erq->flags & IW_ENCODE_DISABLED)
  846. remove = 1;
  847. idx = erq->flags & IW_ENCODE_INDEX;
  848. if (alg == ALG_AES_CMAC) {
  849. if (idx < NUM_DEFAULT_KEYS + 1 ||
  850. idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
  851. idx = -1;
  852. if (!sdata->default_mgmt_key)
  853. idx = 0;
  854. else for (i = NUM_DEFAULT_KEYS;
  855. i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
  856. i++) {
  857. if (sdata->default_mgmt_key == sdata->keys[i])
  858. {
  859. idx = i;
  860. break;
  861. }
  862. }
  863. if (idx < 0)
  864. return -EINVAL;
  865. } else
  866. idx--;
  867. } else {
  868. if (idx < 1 || idx > 4) {
  869. idx = -1;
  870. if (!sdata->default_key)
  871. idx = 0;
  872. else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  873. if (sdata->default_key == sdata->keys[i]) {
  874. idx = i;
  875. break;
  876. }
  877. }
  878. if (idx < 0)
  879. return -EINVAL;
  880. } else
  881. idx--;
  882. }
  883. return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
  884. remove,
  885. ext->ext_flags &
  886. IW_ENCODE_EXT_SET_TX_KEY,
  887. ext->key, ext->key_len);
  888. }
  889. /* Structures to export the Wireless Handlers */
  890. static const iw_handler ieee80211_handler[] =
  891. {
  892. (iw_handler) NULL, /* SIOCSIWCOMMIT */
  893. (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
  894. (iw_handler) NULL, /* SIOCSIWNWID */
  895. (iw_handler) NULL, /* SIOCGIWNWID */
  896. (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
  897. (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
  898. (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
  899. (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
  900. (iw_handler) NULL, /* SIOCSIWSENS */
  901. (iw_handler) NULL, /* SIOCGIWSENS */
  902. (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
  903. (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
  904. (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
  905. (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
  906. (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
  907. (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
  908. (iw_handler) NULL, /* SIOCSIWSPY */
  909. (iw_handler) NULL, /* SIOCGIWSPY */
  910. (iw_handler) NULL, /* SIOCSIWTHRSPY */
  911. (iw_handler) NULL, /* SIOCGIWTHRSPY */
  912. (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
  913. (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
  914. (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
  915. (iw_handler) NULL, /* SIOCGIWAPLIST */
  916. (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
  917. (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
  918. (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
  919. (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
  920. (iw_handler) NULL, /* SIOCSIWNICKN */
  921. (iw_handler) NULL, /* SIOCGIWNICKN */
  922. (iw_handler) NULL, /* -- hole -- */
  923. (iw_handler) NULL, /* -- hole -- */
  924. (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
  925. (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
  926. (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
  927. (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
  928. (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
  929. (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
  930. (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
  931. (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
  932. (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
  933. (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
  934. (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
  935. (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
  936. (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
  937. (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
  938. (iw_handler) NULL, /* -- hole -- */
  939. (iw_handler) NULL, /* -- hole -- */
  940. (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
  941. (iw_handler) NULL, /* SIOCGIWGENIE */
  942. (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
  943. (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
  944. (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
  945. (iw_handler) NULL, /* SIOCGIWENCODEEXT */
  946. (iw_handler) NULL, /* SIOCSIWPMKSA */
  947. (iw_handler) NULL, /* -- hole -- */
  948. };
  949. const struct iw_handler_def ieee80211_iw_handler_def =
  950. {
  951. .num_standard = ARRAY_SIZE(ieee80211_handler),
  952. .standard = (iw_handler *) ieee80211_handler,
  953. .get_wireless_stats = ieee80211_get_wireless_stats,
  954. };