]>
Commit | Line | Data |
---|---|---|
f0706e82 JB |
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 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/init.h> | |
12 | #include <linux/netdevice.h> | |
13 | #include <linux/types.h> | |
14 | #include <linux/slab.h> | |
15 | #include <linux/skbuff.h> | |
16 | #include <linux/etherdevice.h> | |
17 | #include <linux/if_arp.h> | |
18 | #include <linux/wireless.h> | |
19 | #include <net/iw_handler.h> | |
20 | #include <asm/uaccess.h> | |
21 | ||
22 | #include <net/mac80211.h> | |
23 | #include "ieee80211_i.h" | |
2c8dccc7 JB |
24 | #include "led.h" |
25 | #include "rate.h" | |
f0706e82 JB |
26 | #include "wpa.h" |
27 | #include "aes_ccm.h" | |
f0706e82 | 28 | |
b708e610 | 29 | |
f698d856 | 30 | static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr, |
628a140b JB |
31 | int idx, int alg, int remove, |
32 | int set_tx_key, const u8 *_key, | |
33 | size_t key_len) | |
f0706e82 | 34 | { |
f698d856 | 35 | struct ieee80211_local *local = sdata->local; |
d0709a65 | 36 | struct sta_info *sta; |
11a843b7 | 37 | struct ieee80211_key *key; |
3b96766f | 38 | int err; |
f0706e82 | 39 | |
139c3a04 VB |
40 | if (idx < 0 || idx >= NUM_DEFAULT_KEYS) { |
41 | printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n", | |
f698d856 | 42 | sdata->dev->name, idx); |
139c3a04 VB |
43 | return -EINVAL; |
44 | } | |
45 | ||
db4d1169 | 46 | if (remove) { |
3b96766f JB |
47 | rcu_read_lock(); |
48 | ||
49 | err = 0; | |
50 | ||
db4d1169 JB |
51 | if (is_broadcast_ether_addr(sta_addr)) { |
52 | key = sdata->keys[idx]; | |
53 | } else { | |
54 | sta = sta_info_get(local, sta_addr); | |
3b96766f JB |
55 | if (!sta) { |
56 | err = -ENOENT; | |
57 | goto out_unlock; | |
58 | } | |
db4d1169 | 59 | key = sta->key; |
f0706e82 JB |
60 | } |
61 | ||
d0709a65 | 62 | ieee80211_key_free(key); |
db4d1169 JB |
63 | } else { |
64 | key = ieee80211_key_alloc(alg, idx, key_len, _key); | |
65 | if (!key) | |
66 | return -ENOMEM; | |
67 | ||
d0709a65 | 68 | sta = NULL; |
3b96766f JB |
69 | err = 0; |
70 | ||
71 | rcu_read_lock(); | |
d0709a65 | 72 | |
db4d1169 JB |
73 | if (!is_broadcast_ether_addr(sta_addr)) { |
74 | set_tx_key = 0; | |
75 | /* | |
76 | * According to the standard, the key index of a | |
77 | * pairwise key must be zero. However, some AP are | |
78 | * broken when it comes to WEP key indices, so we | |
79 | * work around this. | |
80 | */ | |
81 | if (idx != 0 && alg != ALG_WEP) { | |
d0709a65 | 82 | ieee80211_key_free(key); |
3b96766f JB |
83 | err = -EINVAL; |
84 | goto out_unlock; | |
db4d1169 | 85 | } |
f0706e82 | 86 | |
db4d1169 JB |
87 | sta = sta_info_get(local, sta_addr); |
88 | if (!sta) { | |
d0709a65 | 89 | ieee80211_key_free(key); |
3b96766f JB |
90 | err = -ENOENT; |
91 | goto out_unlock; | |
db4d1169 | 92 | } |
f0706e82 JB |
93 | } |
94 | ||
23976efe EG |
95 | if (alg == ALG_WEP && |
96 | key_len != LEN_WEP40 && key_len != LEN_WEP104) { | |
97 | ieee80211_key_free(key); | |
98 | err = -EINVAL; | |
99 | goto out_unlock; | |
100 | } | |
101 | ||
db4d1169 | 102 | ieee80211_key_link(key, sdata, sta); |
f0706e82 | 103 | |
db4d1169 JB |
104 | if (set_tx_key || (!sta && !sdata->default_key && key)) |
105 | ieee80211_set_default_key(sdata, idx); | |
db4d1169 | 106 | } |
f0706e82 | 107 | |
3b96766f JB |
108 | out_unlock: |
109 | rcu_read_unlock(); | |
110 | ||
111 | return err; | |
f0706e82 JB |
112 | } |
113 | ||
114 | static int ieee80211_ioctl_siwgenie(struct net_device *dev, | |
115 | struct iw_request_info *info, | |
116 | struct iw_point *data, char *extra) | |
117 | { | |
118 | struct ieee80211_sub_if_data *sdata; | |
f0706e82 | 119 | |
ddd3d2be JB |
120 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
121 | ||
122 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) | |
f0706e82 JB |
123 | return -EOPNOTSUPP; |
124 | ||
05c914fe JB |
125 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
126 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
f698d856 | 127 | int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length); |
f0706e82 JB |
128 | if (ret) |
129 | return ret; | |
d6f2da5b | 130 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
f698d856 | 131 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
f0706e82 JB |
132 | return 0; |
133 | } | |
134 | ||
f0706e82 JB |
135 | return -EOPNOTSUPP; |
136 | } | |
137 | ||
f0706e82 JB |
138 | static int ieee80211_ioctl_giwrange(struct net_device *dev, |
139 | struct iw_request_info *info, | |
140 | struct iw_point *data, char *extra) | |
141 | { | |
142 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
143 | struct iw_range *range = (struct iw_range *) extra; | |
8318d78a | 144 | enum ieee80211_band band; |
333af2f0 | 145 | int c = 0; |
f0706e82 JB |
146 | |
147 | data->length = sizeof(struct iw_range); | |
148 | memset(range, 0, sizeof(struct iw_range)); | |
149 | ||
150 | range->we_version_compiled = WIRELESS_EXT; | |
151 | range->we_version_source = 21; | |
152 | range->retry_capa = IW_RETRY_LIMIT; | |
153 | range->retry_flags = IW_RETRY_LIMIT; | |
154 | range->min_retry = 0; | |
155 | range->max_retry = 255; | |
156 | range->min_rts = 0; | |
157 | range->max_rts = 2347; | |
158 | range->min_frag = 256; | |
159 | range->max_frag = 2346; | |
160 | ||
161 | range->encoding_size[0] = 5; | |
162 | range->encoding_size[1] = 13; | |
163 | range->num_encoding_sizes = 2; | |
164 | range->max_encoding_tokens = NUM_DEFAULT_KEYS; | |
165 | ||
566bfe5a BR |
166 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC || |
167 | local->hw.flags & IEEE80211_HW_SIGNAL_DB) | |
168 | range->max_qual.level = local->hw.max_signal; | |
169 | else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) | |
170 | range->max_qual.level = -110; | |
171 | else | |
172 | range->max_qual.level = 0; | |
173 | ||
174 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) | |
175 | range->max_qual.noise = -110; | |
176 | else | |
177 | range->max_qual.noise = 0; | |
178 | ||
179 | range->max_qual.qual = 100; | |
f0706e82 JB |
180 | range->max_qual.updated = local->wstats_flags; |
181 | ||
566bfe5a BR |
182 | range->avg_qual.qual = 50; |
183 | /* not always true but better than nothing */ | |
184 | range->avg_qual.level = range->max_qual.level / 2; | |
185 | range->avg_qual.noise = range->max_qual.noise / 2; | |
f0706e82 JB |
186 | range->avg_qual.updated = local->wstats_flags; |
187 | ||
188 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | |
189 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | |
190 | ||
333af2f0 | 191 | |
8318d78a JB |
192 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
193 | int i; | |
194 | struct ieee80211_supported_band *sband; | |
195 | ||
196 | sband = local->hw.wiphy->bands[band]; | |
197 | ||
198 | if (!sband) | |
333af2f0 HL |
199 | continue; |
200 | ||
8318d78a JB |
201 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { |
202 | struct ieee80211_channel *chan = &sband->channels[i]; | |
333af2f0 | 203 | |
8318d78a JB |
204 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { |
205 | range->freq[c].i = | |
206 | ieee80211_frequency_to_channel( | |
207 | chan->center_freq); | |
208 | range->freq[c].m = chan->center_freq; | |
209 | range->freq[c].e = 6; | |
333af2f0 HL |
210 | c++; |
211 | } | |
333af2f0 HL |
212 | } |
213 | } | |
214 | range->num_channels = c; | |
215 | range->num_frequency = c; | |
216 | ||
f0706e82 | 217 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
f0706e82 JB |
218 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
219 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | |
220 | ||
374fdfbc DW |
221 | range->scan_capa |= IW_SCAN_CAPA_ESSID; |
222 | ||
f0706e82 JB |
223 | return 0; |
224 | } | |
225 | ||
226 | ||
f0706e82 JB |
227 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, |
228 | struct iw_request_info *info, | |
229 | struct iw_freq *freq, char *extra) | |
230 | { | |
f0706e82 JB |
231 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
232 | ||
b522ed56 AF |
233 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC || |
234 | sdata->vif.type == NL80211_IFTYPE_STATION) | |
d6f2da5b | 235 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
f0706e82 JB |
236 | |
237 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ | |
238 | if (freq->e == 0) { | |
239 | if (freq->m < 0) { | |
b522ed56 AF |
240 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC || |
241 | sdata->vif.type == NL80211_IFTYPE_STATION) | |
d6f2da5b JS |
242 | sdata->u.sta.flags |= |
243 | IEEE80211_STA_AUTO_CHANNEL_SEL; | |
f0706e82 JB |
244 | return 0; |
245 | } else | |
f698d856 | 246 | return ieee80211_set_freq(sdata, |
8318d78a | 247 | ieee80211_channel_to_frequency(freq->m)); |
f0706e82 JB |
248 | } else { |
249 | int i, div = 1000000; | |
250 | for (i = 0; i < freq->e; i++) | |
251 | div /= 10; | |
252 | if (div > 0) | |
f698d856 | 253 | return ieee80211_set_freq(sdata, freq->m / div); |
f0706e82 JB |
254 | else |
255 | return -EINVAL; | |
256 | } | |
257 | } | |
258 | ||
259 | ||
260 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, | |
261 | struct iw_request_info *info, | |
262 | struct iw_freq *freq, char *extra) | |
263 | { | |
264 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
265 | ||
8318d78a | 266 | freq->m = local->hw.conf.channel->center_freq; |
f0706e82 JB |
267 | freq->e = 6; |
268 | ||
269 | return 0; | |
270 | } | |
271 | ||
272 | ||
273 | static int ieee80211_ioctl_siwessid(struct net_device *dev, | |
274 | struct iw_request_info *info, | |
275 | struct iw_point *data, char *ssid) | |
276 | { | |
f0706e82 JB |
277 | struct ieee80211_sub_if_data *sdata; |
278 | size_t len = data->length; | |
279 | ||
280 | /* iwconfig uses nul termination in SSID.. */ | |
281 | if (len > 0 && ssid[len - 1] == '\0') | |
282 | len--; | |
283 | ||
284 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
05c914fe JB |
285 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
286 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
f0706e82 | 287 | int ret; |
ddd3d2be | 288 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
f0706e82 JB |
289 | if (len > IEEE80211_MAX_SSID_LEN) |
290 | return -EINVAL; | |
291 | memcpy(sdata->u.sta.ssid, ssid, len); | |
292 | sdata->u.sta.ssid_len = len; | |
293 | return 0; | |
294 | } | |
d6f2da5b JS |
295 | if (data->flags) |
296 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; | |
297 | else | |
298 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL; | |
f698d856 | 299 | ret = ieee80211_sta_set_ssid(sdata, ssid, len); |
f0706e82 JB |
300 | if (ret) |
301 | return ret; | |
f698d856 | 302 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
f0706e82 JB |
303 | return 0; |
304 | } | |
305 | ||
f0706e82 JB |
306 | return -EOPNOTSUPP; |
307 | } | |
308 | ||
309 | ||
310 | static int ieee80211_ioctl_giwessid(struct net_device *dev, | |
311 | struct iw_request_info *info, | |
312 | struct iw_point *data, char *ssid) | |
313 | { | |
314 | size_t len; | |
315 | ||
316 | struct ieee80211_sub_if_data *sdata; | |
317 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
05c914fe JB |
318 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
319 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
f698d856 | 320 | int res = ieee80211_sta_get_ssid(sdata, ssid, &len); |
f0706e82 JB |
321 | if (res == 0) { |
322 | data->length = len; | |
323 | data->flags = 1; | |
324 | } else | |
325 | data->flags = 0; | |
326 | return res; | |
327 | } | |
328 | ||
f0706e82 JB |
329 | return -EOPNOTSUPP; |
330 | } | |
331 | ||
332 | ||
333 | static int ieee80211_ioctl_siwap(struct net_device *dev, | |
334 | struct iw_request_info *info, | |
335 | struct sockaddr *ap_addr, char *extra) | |
336 | { | |
f0706e82 JB |
337 | struct ieee80211_sub_if_data *sdata; |
338 | ||
339 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
05c914fe JB |
340 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
341 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
f0706e82 | 342 | int ret; |
ddd3d2be | 343 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
f0706e82 JB |
344 | memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, |
345 | ETH_ALEN); | |
346 | return 0; | |
347 | } | |
d6f2da5b JS |
348 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
349 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL | | |
350 | IEEE80211_STA_AUTO_CHANNEL_SEL; | |
351 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) | |
352 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL; | |
f0706e82 | 353 | else |
d6f2da5b | 354 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
f698d856 | 355 | ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data); |
f0706e82 JB |
356 | if (ret) |
357 | return ret; | |
f698d856 | 358 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
f0706e82 | 359 | return 0; |
05c914fe | 360 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
44213b5e JB |
361 | /* |
362 | * If it is necessary to update the WDS peer address | |
363 | * while the interface is running, then we need to do | |
364 | * more work here, namely if it is running we need to | |
365 | * add a new and remove the old STA entry, this is | |
366 | * normally handled by _open() and _stop(). | |
367 | */ | |
368 | if (netif_running(dev)) | |
369 | return -EBUSY; | |
370 | ||
371 | memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, | |
372 | ETH_ALEN); | |
373 | ||
374 | return 0; | |
f0706e82 JB |
375 | } |
376 | ||
377 | return -EOPNOTSUPP; | |
378 | } | |
379 | ||
380 | ||
381 | static int ieee80211_ioctl_giwap(struct net_device *dev, | |
382 | struct iw_request_info *info, | |
383 | struct sockaddr *ap_addr, char *extra) | |
384 | { | |
385 | struct ieee80211_sub_if_data *sdata; | |
386 | ||
387 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
05c914fe JB |
388 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
389 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { | |
48c2fc59 TW |
390 | if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED || |
391 | sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) { | |
d4231ca3 AK |
392 | ap_addr->sa_family = ARPHRD_ETHER; |
393 | memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN); | |
394 | return 0; | |
395 | } else { | |
396 | memset(&ap_addr->sa_data, 0, ETH_ALEN); | |
397 | return 0; | |
398 | } | |
05c914fe | 399 | } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
f0706e82 JB |
400 | ap_addr->sa_family = ARPHRD_ETHER; |
401 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); | |
402 | return 0; | |
403 | } | |
404 | ||
405 | return -EOPNOTSUPP; | |
406 | } | |
407 | ||
408 | ||
409 | static int ieee80211_ioctl_siwscan(struct net_device *dev, | |
410 | struct iw_request_info *info, | |
107acb23 | 411 | union iwreq_data *wrqu, char *extra) |
f0706e82 | 412 | { |
f0706e82 | 413 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
107acb23 | 414 | struct iw_scan_req *req = NULL; |
f0706e82 JB |
415 | u8 *ssid = NULL; |
416 | size_t ssid_len = 0; | |
417 | ||
418 | if (!netif_running(dev)) | |
419 | return -ENETDOWN; | |
420 | ||
05c914fe JB |
421 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
422 | sdata->vif.type != NL80211_IFTYPE_ADHOC && | |
b7a530d8 | 423 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
d114f399 | 424 | return -EOPNOTSUPP; |
d114f399 JL |
425 | |
426 | /* if SSID was specified explicitly then use that */ | |
107acb23 BM |
427 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
428 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
429 | req = (struct iw_scan_req *)extra; | |
430 | ssid = req->essid; | |
431 | ssid_len = req->essid_len; | |
f0706e82 | 432 | } |
f27b62d3 | 433 | |
c2b13452 | 434 | return ieee80211_request_scan(sdata, ssid, ssid_len); |
f0706e82 JB |
435 | } |
436 | ||
437 | ||
438 | static int ieee80211_ioctl_giwscan(struct net_device *dev, | |
439 | struct iw_request_info *info, | |
440 | struct iw_point *data, char *extra) | |
441 | { | |
442 | int res; | |
443 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
f698d856 JBG |
444 | struct ieee80211_sub_if_data *sdata; |
445 | ||
446 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
ece8eddd | 447 | |
c2b13452 | 448 | if (local->sw_scanning || local->hw_scanning) |
f0706e82 | 449 | return -EAGAIN; |
ece8eddd | 450 | |
c2b13452 | 451 | res = ieee80211_scan_results(local, info, extra, data->length); |
f0706e82 JB |
452 | if (res >= 0) { |
453 | data->length = res; | |
454 | return 0; | |
455 | } | |
456 | data->length = 0; | |
457 | return res; | |
458 | } | |
459 | ||
460 | ||
1fd5e589 LF |
461 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
462 | struct iw_request_info *info, | |
463 | struct iw_param *rate, char *extra) | |
464 | { | |
465 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
8318d78a | 466 | int i, err = -EINVAL; |
1fd5e589 LF |
467 | u32 target_rate = rate->value / 100000; |
468 | struct ieee80211_sub_if_data *sdata; | |
8318d78a | 469 | struct ieee80211_supported_band *sband; |
1fd5e589 LF |
470 | |
471 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
8318d78a JB |
472 | |
473 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
474 | ||
1fd5e589 LF |
475 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
476 | * target_rate = X, rate->fixed = 1 means only rate X | |
477 | * target_rate = X, rate->fixed = 0 means all rates <= X */ | |
3e122be0 JB |
478 | sdata->max_ratectrl_rateidx = -1; |
479 | sdata->force_unicast_rateidx = -1; | |
1fd5e589 LF |
480 | if (rate->value < 0) |
481 | return 0; | |
8318d78a JB |
482 | |
483 | for (i=0; i< sband->n_bitrates; i++) { | |
484 | struct ieee80211_rate *brate = &sband->bitrates[i]; | |
485 | int this_rate = brate->bitrate; | |
1fd5e589 | 486 | |
1fd5e589 | 487 | if (target_rate == this_rate) { |
3e122be0 | 488 | sdata->max_ratectrl_rateidx = i; |
1fd5e589 | 489 | if (rate->fixed) |
3e122be0 | 490 | sdata->force_unicast_rateidx = i; |
8318d78a JB |
491 | err = 0; |
492 | break; | |
1fd5e589 LF |
493 | } |
494 | } | |
8318d78a | 495 | return err; |
1fd5e589 LF |
496 | } |
497 | ||
b3d88ad4 LF |
498 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
499 | struct iw_request_info *info, | |
500 | struct iw_param *rate, char *extra) | |
501 | { | |
502 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
503 | struct sta_info *sta; | |
504 | struct ieee80211_sub_if_data *sdata; | |
8318d78a | 505 | struct ieee80211_supported_band *sband; |
b3d88ad4 LF |
506 | |
507 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
8318d78a | 508 | |
05c914fe | 509 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
b3d88ad4 | 510 | return -EOPNOTSUPP; |
8318d78a JB |
511 | |
512 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
513 | ||
380a942b JB |
514 | rcu_read_lock(); |
515 | ||
516 | sta = sta_info_get(local, sdata->u.sta.bssid); | |
517 | ||
e6a9854b JB |
518 | if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) |
519 | rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate; | |
b3d88ad4 LF |
520 | else |
521 | rate->value = 0; | |
380a942b JB |
522 | |
523 | rcu_read_unlock(); | |
524 | ||
525 | if (!sta) | |
526 | return -ENODEV; | |
527 | ||
8318d78a | 528 | rate->value *= 100000; |
d0709a65 | 529 | |
b3d88ad4 LF |
530 | return 0; |
531 | } | |
532 | ||
61609bc0 MB |
533 | static int ieee80211_ioctl_siwtxpower(struct net_device *dev, |
534 | struct iw_request_info *info, | |
535 | union iwreq_data *data, char *extra) | |
536 | { | |
537 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
d9d29257 | 538 | struct ieee80211_channel* chan = local->hw.conf.channel; |
e8975581 | 539 | u32 reconf_flags = 0; |
8318d78a | 540 | int new_power_level; |
61609bc0 MB |
541 | |
542 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | |
543 | return -EINVAL; | |
544 | if (data->txpower.flags & IW_TXPOW_RANGE) | |
545 | return -EINVAL; | |
d9d29257 LR |
546 | if (!chan) |
547 | return -EINVAL; | |
61609bc0 | 548 | |
d9d29257 LR |
549 | if (data->txpower.fixed) |
550 | new_power_level = min(data->txpower.value, chan->max_power); | |
551 | else /* Automatic power level setting */ | |
8318d78a | 552 | new_power_level = chan->max_power; |
6a432955 | 553 | |
2bf30fab | 554 | local->user_power_level = new_power_level; |
e3c92df0 | 555 | if (local->hw.conf.power_level != new_power_level) |
e8975581 | 556 | reconf_flags |= IEEE80211_CONF_CHANGE_POWER; |
6a432955 | 557 | |
61609bc0 MB |
558 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
559 | local->hw.conf.radio_enabled = !(data->txpower.disabled); | |
e8975581 | 560 | reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED; |
cdcb006f | 561 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
61609bc0 | 562 | } |
6a432955 | 563 | |
e8975581 JB |
564 | if (reconf_flags) |
565 | ieee80211_hw_config(local, reconf_flags); | |
61609bc0 MB |
566 | |
567 | return 0; | |
568 | } | |
569 | ||
fe6aa301 LF |
570 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
571 | struct iw_request_info *info, | |
572 | union iwreq_data *data, char *extra) | |
573 | { | |
574 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
575 | ||
576 | data->txpower.fixed = 1; | |
577 | data->txpower.disabled = !(local->hw.conf.radio_enabled); | |
578 | data->txpower.value = local->hw.conf.power_level; | |
579 | data->txpower.flags = IW_TXPOW_DBM; | |
580 | ||
581 | return 0; | |
582 | } | |
583 | ||
f0706e82 JB |
584 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
585 | struct iw_request_info *info, | |
586 | struct iw_param *rts, char *extra) | |
587 | { | |
588 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
589 | ||
590 | if (rts->disabled) | |
591 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
fa6adfe9 EG |
592 | else if (!rts->fixed) |
593 | /* if the rts value is not fixed, then take default */ | |
594 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
f0706e82 JB |
595 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
596 | return -EINVAL; | |
597 | else | |
598 | local->rts_threshold = rts->value; | |
599 | ||
600 | /* If the wlan card performs RTS/CTS in hardware/firmware, | |
601 | * configure it here */ | |
602 | ||
603 | if (local->ops->set_rts_threshold) | |
604 | local->ops->set_rts_threshold(local_to_hw(local), | |
605 | local->rts_threshold); | |
606 | ||
607 | return 0; | |
608 | } | |
609 | ||
610 | static int ieee80211_ioctl_giwrts(struct net_device *dev, | |
611 | struct iw_request_info *info, | |
612 | struct iw_param *rts, char *extra) | |
613 | { | |
614 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
615 | ||
616 | rts->value = local->rts_threshold; | |
617 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); | |
618 | rts->fixed = 1; | |
619 | ||
620 | return 0; | |
621 | } | |
622 | ||
623 | ||
624 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, | |
625 | struct iw_request_info *info, | |
626 | struct iw_param *frag, char *extra) | |
627 | { | |
628 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
629 | ||
630 | if (frag->disabled) | |
631 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
e4abd4d4 EG |
632 | else if (!frag->fixed) |
633 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
f0706e82 JB |
634 | else if (frag->value < 256 || |
635 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) | |
636 | return -EINVAL; | |
637 | else { | |
638 | /* Fragment length must be even, so strip LSB. */ | |
639 | local->fragmentation_threshold = frag->value & ~0x1; | |
640 | } | |
641 | ||
f0706e82 JB |
642 | return 0; |
643 | } | |
644 | ||
645 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, | |
646 | struct iw_request_info *info, | |
647 | struct iw_param *frag, char *extra) | |
648 | { | |
649 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
650 | ||
651 | frag->value = local->fragmentation_threshold; | |
652 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); | |
653 | frag->fixed = 1; | |
654 | ||
655 | return 0; | |
656 | } | |
657 | ||
658 | ||
659 | static int ieee80211_ioctl_siwretry(struct net_device *dev, | |
660 | struct iw_request_info *info, | |
661 | struct iw_param *retry, char *extra) | |
662 | { | |
663 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
664 | ||
665 | if (retry->disabled || | |
666 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) | |
667 | return -EINVAL; | |
668 | ||
9124b077 JB |
669 | if (retry->flags & IW_RETRY_MAX) { |
670 | local->hw.conf.long_frame_max_tx_count = retry->value; | |
671 | } else if (retry->flags & IW_RETRY_MIN) { | |
672 | local->hw.conf.short_frame_max_tx_count = retry->value; | |
673 | } else { | |
674 | local->hw.conf.long_frame_max_tx_count = retry->value; | |
675 | local->hw.conf.short_frame_max_tx_count = retry->value; | |
f0706e82 JB |
676 | } |
677 | ||
9124b077 | 678 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
f0706e82 JB |
679 | |
680 | return 0; | |
681 | } | |
682 | ||
683 | ||
684 | static int ieee80211_ioctl_giwretry(struct net_device *dev, | |
685 | struct iw_request_info *info, | |
686 | struct iw_param *retry, char *extra) | |
687 | { | |
688 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
689 | ||
690 | retry->disabled = 0; | |
691 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { | |
692 | /* first return min value, iwconfig will ask max value | |
693 | * later if needed */ | |
694 | retry->flags |= IW_RETRY_LIMIT; | |
9124b077 JB |
695 | retry->value = local->hw.conf.short_frame_max_tx_count; |
696 | if (local->hw.conf.long_frame_max_tx_count != | |
697 | local->hw.conf.short_frame_max_tx_count) | |
f0706e82 JB |
698 | retry->flags |= IW_RETRY_MIN; |
699 | return 0; | |
700 | } | |
701 | if (retry->flags & IW_RETRY_MAX) { | |
702 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
9124b077 | 703 | retry->value = local->hw.conf.long_frame_max_tx_count; |
f0706e82 JB |
704 | } |
705 | ||
706 | return 0; | |
707 | } | |
708 | ||
f0706e82 JB |
709 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
710 | struct iw_request_info *info, | |
711 | struct iw_point *data, char *extra) | |
712 | { | |
713 | struct ieee80211_sub_if_data *sdata; | |
714 | struct iw_mlme *mlme = (struct iw_mlme *) extra; | |
715 | ||
716 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
05c914fe JB |
717 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
718 | sdata->vif.type != NL80211_IFTYPE_ADHOC) | |
f0706e82 JB |
719 | return -EINVAL; |
720 | ||
721 | switch (mlme->cmd) { | |
722 | case IW_MLME_DEAUTH: | |
723 | /* TODO: mlme->addr.sa_data */ | |
f698d856 | 724 | return ieee80211_sta_deauthenticate(sdata, mlme->reason_code); |
f0706e82 JB |
725 | case IW_MLME_DISASSOC: |
726 | /* TODO: mlme->addr.sa_data */ | |
f698d856 | 727 | return ieee80211_sta_disassociate(sdata, mlme->reason_code); |
f0706e82 JB |
728 | default: |
729 | return -EOPNOTSUPP; | |
730 | } | |
731 | } | |
732 | ||
733 | ||
734 | static int ieee80211_ioctl_siwencode(struct net_device *dev, | |
735 | struct iw_request_info *info, | |
736 | struct iw_point *erq, char *keybuf) | |
737 | { | |
738 | struct ieee80211_sub_if_data *sdata; | |
739 | int idx, i, alg = ALG_WEP; | |
740 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
628a140b | 741 | int remove = 0; |
f0706e82 JB |
742 | |
743 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
744 | ||
745 | idx = erq->flags & IW_ENCODE_INDEX; | |
746 | if (idx == 0) { | |
747 | if (sdata->default_key) | |
748 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
749 | if (sdata->default_key == sdata->keys[i]) { | |
750 | idx = i; | |
751 | break; | |
752 | } | |
753 | } | |
754 | } else if (idx < 1 || idx > 4) | |
755 | return -EINVAL; | |
756 | else | |
757 | idx--; | |
758 | ||
759 | if (erq->flags & IW_ENCODE_DISABLED) | |
628a140b | 760 | remove = 1; |
f0706e82 JB |
761 | else if (erq->length == 0) { |
762 | /* No key data - just set the default TX key index */ | |
11a843b7 | 763 | ieee80211_set_default_key(sdata, idx); |
f0706e82 JB |
764 | return 0; |
765 | } | |
766 | ||
767 | return ieee80211_set_encryption( | |
f698d856 | 768 | sdata, bcaddr, |
628a140b | 769 | idx, alg, remove, |
f0706e82 JB |
770 | !sdata->default_key, |
771 | keybuf, erq->length); | |
772 | } | |
773 | ||
774 | ||
775 | static int ieee80211_ioctl_giwencode(struct net_device *dev, | |
776 | struct iw_request_info *info, | |
777 | struct iw_point *erq, char *key) | |
778 | { | |
779 | struct ieee80211_sub_if_data *sdata; | |
780 | int idx, i; | |
781 | ||
782 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
783 | ||
784 | idx = erq->flags & IW_ENCODE_INDEX; | |
785 | if (idx < 1 || idx > 4) { | |
786 | idx = -1; | |
787 | if (!sdata->default_key) | |
788 | idx = 0; | |
789 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
790 | if (sdata->default_key == sdata->keys[i]) { | |
791 | idx = i; | |
792 | break; | |
793 | } | |
794 | } | |
795 | if (idx < 0) | |
796 | return -EINVAL; | |
797 | } else | |
798 | idx--; | |
799 | ||
800 | erq->flags = idx + 1; | |
801 | ||
802 | if (!sdata->keys[idx]) { | |
803 | erq->length = 0; | |
804 | erq->flags |= IW_ENCODE_DISABLED; | |
805 | return 0; | |
806 | } | |
807 | ||
8f20fc24 | 808 | memcpy(key, sdata->keys[idx]->conf.key, |
11a843b7 | 809 | min_t(int, erq->length, sdata->keys[idx]->conf.keylen)); |
8f20fc24 | 810 | erq->length = sdata->keys[idx]->conf.keylen; |
f0706e82 JB |
811 | erq->flags |= IW_ENCODE_ENABLED; |
812 | ||
05c914fe | 813 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
b9fcc4f2 EG |
814 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
815 | switch (ifsta->auth_alg) { | |
816 | case WLAN_AUTH_OPEN: | |
817 | case WLAN_AUTH_LEAP: | |
818 | erq->flags |= IW_ENCODE_OPEN; | |
819 | break; | |
820 | case WLAN_AUTH_SHARED_KEY: | |
821 | erq->flags |= IW_ENCODE_RESTRICTED; | |
822 | break; | |
823 | } | |
824 | } | |
825 | ||
f0706e82 JB |
826 | return 0; |
827 | } | |
828 | ||
49292d56 SO |
829 | static int ieee80211_ioctl_siwpower(struct net_device *dev, |
830 | struct iw_request_info *info, | |
831 | struct iw_param *wrq, | |
832 | char *extra) | |
833 | { | |
e0cb686f | 834 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
49292d56 SO |
835 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
836 | struct ieee80211_conf *conf = &local->hw.conf; | |
520eb820 | 837 | int ret = 0, timeout = 0; |
e0cb686f KV |
838 | bool ps; |
839 | ||
840 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
841 | return -EINVAL; | |
49292d56 SO |
842 | |
843 | if (wrq->disabled) { | |
e0cb686f | 844 | ps = false; |
520eb820 | 845 | timeout = 0; |
e0cb686f | 846 | goto set; |
49292d56 SO |
847 | } |
848 | ||
849 | switch (wrq->flags & IW_POWER_MODE) { | |
850 | case IW_POWER_ON: /* If not specified */ | |
851 | case IW_POWER_MODE: /* If set all mask */ | |
852 | case IW_POWER_ALL_R: /* If explicitely state all */ | |
e0cb686f | 853 | ps = true; |
49292d56 | 854 | break; |
520eb820 KV |
855 | default: /* Otherwise we ignore */ |
856 | break; | |
49292d56 SO |
857 | } |
858 | ||
520eb820 KV |
859 | if (wrq->flags & IW_POWER_TIMEOUT) |
860 | timeout = wrq->value / 1000; | |
e0cb686f KV |
861 | |
862 | set: | |
520eb820 KV |
863 | if (ps == local->powersave && timeout == local->dynamic_ps_timeout) |
864 | return ret; | |
865 | ||
e0cb686f | 866 | local->powersave = ps; |
520eb820 | 867 | local->dynamic_ps_timeout = timeout; |
e0cb686f | 868 | |
869717fb VN |
869 | if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS) && |
870 | (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)) { | |
871 | if (local->dynamic_ps_timeout > 0) | |
520eb820 KV |
872 | mod_timer(&local->dynamic_ps_timer, jiffies + |
873 | msecs_to_jiffies(local->dynamic_ps_timeout)); | |
874 | else { | |
a97b77b9 VN |
875 | if (local->powersave) { |
876 | ieee80211_send_nullfunc(local, sdata, 1); | |
520eb820 | 877 | conf->flags |= IEEE80211_CONF_PS; |
a97b77b9 VN |
878 | ret = ieee80211_hw_config(local, |
879 | IEEE80211_CONF_CHANGE_PS); | |
880 | } else { | |
520eb820 | 881 | conf->flags &= ~IEEE80211_CONF_PS; |
a97b77b9 VN |
882 | ret = ieee80211_hw_config(local, |
883 | IEEE80211_CONF_CHANGE_PS); | |
884 | ieee80211_send_nullfunc(local, sdata, 0); | |
885 | } | |
520eb820 | 886 | } |
e0cb686f KV |
887 | } |
888 | ||
889 | return ret; | |
49292d56 SO |
890 | } |
891 | ||
892 | static int ieee80211_ioctl_giwpower(struct net_device *dev, | |
893 | struct iw_request_info *info, | |
894 | union iwreq_data *wrqu, | |
895 | char *extra) | |
896 | { | |
897 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
49292d56 | 898 | |
e0cb686f | 899 | wrqu->power.disabled = !local->powersave; |
49292d56 SO |
900 | |
901 | return 0; | |
902 | } | |
903 | ||
f0706e82 JB |
904 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
905 | struct iw_request_info *info, | |
906 | struct iw_param *data, char *extra) | |
907 | { | |
f0706e82 JB |
908 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
909 | int ret = 0; | |
910 | ||
911 | switch (data->flags & IW_AUTH_INDEX) { | |
912 | case IW_AUTH_WPA_VERSION: | |
f0706e82 JB |
913 | case IW_AUTH_CIPHER_GROUP: |
914 | case IW_AUTH_WPA_ENABLED: | |
915 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
f0706e82 | 916 | case IW_AUTH_KEY_MGMT: |
5b98b1f7 | 917 | break; |
eb46936b VT |
918 | case IW_AUTH_CIPHER_PAIRWISE: |
919 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { | |
920 | if (data->value & (IW_AUTH_CIPHER_WEP40 | | |
921 | IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP)) | |
922 | sdata->u.sta.flags |= | |
923 | IEEE80211_STA_TKIP_WEP_USED; | |
924 | else | |
925 | sdata->u.sta.flags &= | |
926 | ~IEEE80211_STA_TKIP_WEP_USED; | |
927 | } | |
928 | break; | |
b1357a81 JB |
929 | case IW_AUTH_DROP_UNENCRYPTED: |
930 | sdata->drop_unencrypted = !!data->value; | |
931 | break; | |
5b98b1f7 | 932 | case IW_AUTH_PRIVACY_INVOKED: |
05c914fe | 933 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
f0706e82 JB |
934 | ret = -EINVAL; |
935 | else { | |
5b98b1f7 | 936 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
f0706e82 | 937 | /* |
5b98b1f7 JB |
938 | * Privacy invoked by wpa_supplicant, store the |
939 | * value and allow associating to a protected | |
940 | * network without having a key up front. | |
f0706e82 | 941 | */ |
5b98b1f7 JB |
942 | if (data->value) |
943 | sdata->u.sta.flags |= | |
944 | IEEE80211_STA_PRIVACY_INVOKED; | |
f0706e82 JB |
945 | } |
946 | break; | |
947 | case IW_AUTH_80211_AUTH_ALG: | |
05c914fe JB |
948 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
949 | sdata->vif.type == NL80211_IFTYPE_ADHOC) | |
f0706e82 JB |
950 | sdata->u.sta.auth_algs = data->value; |
951 | else | |
952 | ret = -EOPNOTSUPP; | |
953 | break; | |
f0706e82 JB |
954 | default: |
955 | ret = -EOPNOTSUPP; | |
956 | break; | |
957 | } | |
958 | return ret; | |
959 | } | |
960 | ||
961 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ | |
962 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) | |
963 | { | |
964 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
965 | struct iw_statistics *wstats = &local->wstats; | |
966 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
967 | struct sta_info *sta = NULL; | |
968 | ||
98dd6a57 JB |
969 | rcu_read_lock(); |
970 | ||
05c914fe JB |
971 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
972 | sdata->vif.type == NL80211_IFTYPE_ADHOC) | |
f0706e82 JB |
973 | sta = sta_info_get(local, sdata->u.sta.bssid); |
974 | if (!sta) { | |
975 | wstats->discard.fragment = 0; | |
976 | wstats->discard.misc = 0; | |
977 | wstats->qual.qual = 0; | |
978 | wstats->qual.level = 0; | |
979 | wstats->qual.noise = 0; | |
980 | wstats->qual.updated = IW_QUAL_ALL_INVALID; | |
981 | } else { | |
566bfe5a BR |
982 | wstats->qual.level = sta->last_signal; |
983 | wstats->qual.qual = sta->last_qual; | |
f0706e82 JB |
984 | wstats->qual.noise = sta->last_noise; |
985 | wstats->qual.updated = local->wstats_flags; | |
f0706e82 | 986 | } |
98dd6a57 JB |
987 | |
988 | rcu_read_unlock(); | |
989 | ||
f0706e82 JB |
990 | return wstats; |
991 | } | |
992 | ||
993 | static int ieee80211_ioctl_giwauth(struct net_device *dev, | |
994 | struct iw_request_info *info, | |
995 | struct iw_param *data, char *extra) | |
996 | { | |
997 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
998 | int ret = 0; | |
999 | ||
1000 | switch (data->flags & IW_AUTH_INDEX) { | |
1001 | case IW_AUTH_80211_AUTH_ALG: | |
05c914fe JB |
1002 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
1003 | sdata->vif.type == NL80211_IFTYPE_ADHOC) | |
f0706e82 JB |
1004 | data->value = sdata->u.sta.auth_algs; |
1005 | else | |
1006 | ret = -EOPNOTSUPP; | |
1007 | break; | |
1008 | default: | |
1009 | ret = -EOPNOTSUPP; | |
1010 | break; | |
1011 | } | |
1012 | return ret; | |
1013 | } | |
1014 | ||
1015 | ||
1016 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, | |
1017 | struct iw_request_info *info, | |
1018 | struct iw_point *erq, char *extra) | |
1019 | { | |
1020 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1021 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; | |
628a140b | 1022 | int uninitialized_var(alg), idx, i, remove = 0; |
f0706e82 JB |
1023 | |
1024 | switch (ext->alg) { | |
1025 | case IW_ENCODE_ALG_NONE: | |
628a140b | 1026 | remove = 1; |
f0706e82 JB |
1027 | break; |
1028 | case IW_ENCODE_ALG_WEP: | |
1029 | alg = ALG_WEP; | |
1030 | break; | |
1031 | case IW_ENCODE_ALG_TKIP: | |
1032 | alg = ALG_TKIP; | |
1033 | break; | |
1034 | case IW_ENCODE_ALG_CCMP: | |
1035 | alg = ALG_CCMP; | |
1036 | break; | |
1037 | default: | |
1038 | return -EOPNOTSUPP; | |
1039 | } | |
1040 | ||
1041 | if (erq->flags & IW_ENCODE_DISABLED) | |
628a140b | 1042 | remove = 1; |
f0706e82 JB |
1043 | |
1044 | idx = erq->flags & IW_ENCODE_INDEX; | |
1045 | if (idx < 1 || idx > 4) { | |
1046 | idx = -1; | |
1047 | if (!sdata->default_key) | |
1048 | idx = 0; | |
1049 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
1050 | if (sdata->default_key == sdata->keys[i]) { | |
1051 | idx = i; | |
1052 | break; | |
1053 | } | |
1054 | } | |
1055 | if (idx < 0) | |
1056 | return -EINVAL; | |
1057 | } else | |
1058 | idx--; | |
1059 | ||
f698d856 | 1060 | return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg, |
628a140b | 1061 | remove, |
f0706e82 JB |
1062 | ext->ext_flags & |
1063 | IW_ENCODE_EXT_SET_TX_KEY, | |
1064 | ext->key, ext->key_len); | |
1065 | } | |
1066 | ||
1067 | ||
f0706e82 JB |
1068 | /* Structures to export the Wireless Handlers */ |
1069 | ||
1070 | static const iw_handler ieee80211_handler[] = | |
1071 | { | |
1072 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ | |
fee52678 | 1073 | (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */ |
f0706e82 JB |
1074 | (iw_handler) NULL, /* SIOCSIWNWID */ |
1075 | (iw_handler) NULL, /* SIOCGIWNWID */ | |
1076 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ | |
1077 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ | |
e60c7744 JB |
1078 | (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */ |
1079 | (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */ | |
f0706e82 JB |
1080 | (iw_handler) NULL, /* SIOCSIWSENS */ |
1081 | (iw_handler) NULL, /* SIOCGIWSENS */ | |
1082 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ | |
1083 | (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */ | |
1084 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ | |
1085 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ | |
1086 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ | |
1087 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ | |
5d4ecd93 JB |
1088 | (iw_handler) NULL, /* SIOCSIWSPY */ |
1089 | (iw_handler) NULL, /* SIOCGIWSPY */ | |
1090 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ | |
1091 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ | |
f0706e82 JB |
1092 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
1093 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ | |
1094 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ | |
1095 | (iw_handler) NULL, /* SIOCGIWAPLIST */ | |
1096 | (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */ | |
1097 | (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */ | |
1098 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ | |
1099 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ | |
1100 | (iw_handler) NULL, /* SIOCSIWNICKN */ | |
1101 | (iw_handler) NULL, /* SIOCGIWNICKN */ | |
1102 | (iw_handler) NULL, /* -- hole -- */ | |
1103 | (iw_handler) NULL, /* -- hole -- */ | |
1fd5e589 | 1104 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
b3d88ad4 | 1105 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
f0706e82 JB |
1106 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
1107 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ | |
1108 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ | |
1109 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ | |
61609bc0 | 1110 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
fe6aa301 | 1111 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
f0706e82 JB |
1112 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
1113 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ | |
1114 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ | |
1115 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ | |
49292d56 SO |
1116 | (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ |
1117 | (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ | |
f0706e82 JB |
1118 | (iw_handler) NULL, /* -- hole -- */ |
1119 | (iw_handler) NULL, /* -- hole -- */ | |
1120 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ | |
1121 | (iw_handler) NULL, /* SIOCGIWGENIE */ | |
1122 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ | |
1123 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ | |
1124 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ | |
1125 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ | |
1126 | (iw_handler) NULL, /* SIOCSIWPMKSA */ | |
1127 | (iw_handler) NULL, /* -- hole -- */ | |
1128 | }; | |
1129 | ||
f0706e82 JB |
1130 | const struct iw_handler_def ieee80211_iw_handler_def = |
1131 | { | |
1132 | .num_standard = ARRAY_SIZE(ieee80211_handler), | |
f0706e82 | 1133 | .standard = (iw_handler *) ieee80211_handler, |
f0706e82 JB |
1134 | .get_wireless_stats = ieee80211_get_wireless_stats, |
1135 | }; |