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