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 | ||
51fb61e7 JB |
125 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
126 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
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_giwname(struct net_device *dev, |
139 | struct iw_request_info *info, | |
140 | char *name, char *extra) | |
141 | { | |
f37d08bd TW |
142 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
143 | struct ieee80211_supported_band *sband; | |
144 | u8 is_ht = 0, is_a = 0, is_b = 0, is_g = 0; | |
145 | ||
146 | ||
147 | sband = local->hw.wiphy->bands[IEEE80211_BAND_5GHZ]; | |
148 | if (sband) { | |
149 | is_a = 1; | |
150 | is_ht |= sband->ht_info.ht_supported; | |
151 | } | |
152 | ||
153 | sband = local->hw.wiphy->bands[IEEE80211_BAND_2GHZ]; | |
154 | if (sband) { | |
155 | int i; | |
156 | /* Check for mandatory rates */ | |
157 | for (i = 0; i < sband->n_bitrates; i++) { | |
158 | if (sband->bitrates[i].bitrate == 10) | |
159 | is_b = 1; | |
160 | if (sband->bitrates[i].bitrate == 60) | |
161 | is_g = 1; | |
162 | } | |
163 | is_ht |= sband->ht_info.ht_supported; | |
164 | } | |
165 | ||
8318d78a | 166 | strcpy(name, "IEEE 802.11"); |
f37d08bd TW |
167 | if (is_a) |
168 | strcat(name, "a"); | |
169 | if (is_b) | |
170 | strcat(name, "b"); | |
171 | if (is_g) | |
172 | strcat(name, "g"); | |
173 | if (is_ht) | |
174 | strcat(name, "n"); | |
f0706e82 JB |
175 | |
176 | return 0; | |
177 | } | |
178 | ||
179 | ||
180 | static int ieee80211_ioctl_giwrange(struct net_device *dev, | |
181 | struct iw_request_info *info, | |
182 | struct iw_point *data, char *extra) | |
183 | { | |
184 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
185 | struct iw_range *range = (struct iw_range *) extra; | |
8318d78a | 186 | enum ieee80211_band band; |
333af2f0 | 187 | int c = 0; |
f0706e82 JB |
188 | |
189 | data->length = sizeof(struct iw_range); | |
190 | memset(range, 0, sizeof(struct iw_range)); | |
191 | ||
192 | range->we_version_compiled = WIRELESS_EXT; | |
193 | range->we_version_source = 21; | |
194 | range->retry_capa = IW_RETRY_LIMIT; | |
195 | range->retry_flags = IW_RETRY_LIMIT; | |
196 | range->min_retry = 0; | |
197 | range->max_retry = 255; | |
198 | range->min_rts = 0; | |
199 | range->max_rts = 2347; | |
200 | range->min_frag = 256; | |
201 | range->max_frag = 2346; | |
202 | ||
203 | range->encoding_size[0] = 5; | |
204 | range->encoding_size[1] = 13; | |
205 | range->num_encoding_sizes = 2; | |
206 | range->max_encoding_tokens = NUM_DEFAULT_KEYS; | |
207 | ||
566bfe5a BR |
208 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC || |
209 | local->hw.flags & IEEE80211_HW_SIGNAL_DB) | |
210 | range->max_qual.level = local->hw.max_signal; | |
211 | else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) | |
212 | range->max_qual.level = -110; | |
213 | else | |
214 | range->max_qual.level = 0; | |
215 | ||
216 | if (local->hw.flags & IEEE80211_HW_NOISE_DBM) | |
217 | range->max_qual.noise = -110; | |
218 | else | |
219 | range->max_qual.noise = 0; | |
220 | ||
221 | range->max_qual.qual = 100; | |
f0706e82 JB |
222 | range->max_qual.updated = local->wstats_flags; |
223 | ||
566bfe5a BR |
224 | range->avg_qual.qual = 50; |
225 | /* not always true but better than nothing */ | |
226 | range->avg_qual.level = range->max_qual.level / 2; | |
227 | range->avg_qual.noise = range->max_qual.noise / 2; | |
f0706e82 JB |
228 | range->avg_qual.updated = local->wstats_flags; |
229 | ||
230 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | | |
231 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | |
232 | ||
333af2f0 | 233 | |
8318d78a JB |
234 | for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { |
235 | int i; | |
236 | struct ieee80211_supported_band *sband; | |
237 | ||
238 | sband = local->hw.wiphy->bands[band]; | |
239 | ||
240 | if (!sband) | |
333af2f0 HL |
241 | continue; |
242 | ||
8318d78a JB |
243 | for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) { |
244 | struct ieee80211_channel *chan = &sband->channels[i]; | |
333af2f0 | 245 | |
8318d78a JB |
246 | if (!(chan->flags & IEEE80211_CHAN_DISABLED)) { |
247 | range->freq[c].i = | |
248 | ieee80211_frequency_to_channel( | |
249 | chan->center_freq); | |
250 | range->freq[c].m = chan->center_freq; | |
251 | range->freq[c].e = 6; | |
333af2f0 HL |
252 | c++; |
253 | } | |
333af2f0 HL |
254 | } |
255 | } | |
256 | range->num_channels = c; | |
257 | range->num_frequency = c; | |
258 | ||
f0706e82 | 259 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
f0706e82 JB |
260 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
261 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | |
262 | ||
374fdfbc DW |
263 | range->scan_capa |= IW_SCAN_CAPA_ESSID; |
264 | ||
f0706e82 JB |
265 | return 0; |
266 | } | |
267 | ||
268 | ||
f0706e82 JB |
269 | static int ieee80211_ioctl_siwmode(struct net_device *dev, |
270 | struct iw_request_info *info, | |
271 | __u32 *mode, char *extra) | |
272 | { | |
273 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
274 | int type; | |
275 | ||
51fb61e7 | 276 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) |
f0706e82 JB |
277 | return -EOPNOTSUPP; |
278 | ||
279 | switch (*mode) { | |
280 | case IW_MODE_INFRA: | |
281 | type = IEEE80211_IF_TYPE_STA; | |
282 | break; | |
283 | case IW_MODE_ADHOC: | |
284 | type = IEEE80211_IF_TYPE_IBSS; | |
285 | break; | |
b454048c JB |
286 | case IW_MODE_REPEAT: |
287 | type = IEEE80211_IF_TYPE_WDS; | |
288 | break; | |
f0706e82 JB |
289 | case IW_MODE_MONITOR: |
290 | type = IEEE80211_IF_TYPE_MNTR; | |
291 | break; | |
292 | default: | |
293 | return -EINVAL; | |
294 | } | |
295 | ||
f3947e2d | 296 | return ieee80211_if_change_type(sdata, type); |
f0706e82 JB |
297 | } |
298 | ||
299 | ||
300 | static int ieee80211_ioctl_giwmode(struct net_device *dev, | |
301 | struct iw_request_info *info, | |
302 | __u32 *mode, char *extra) | |
303 | { | |
304 | struct ieee80211_sub_if_data *sdata; | |
305 | ||
306 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 | 307 | switch (sdata->vif.type) { |
f0706e82 JB |
308 | case IEEE80211_IF_TYPE_AP: |
309 | *mode = IW_MODE_MASTER; | |
310 | break; | |
311 | case IEEE80211_IF_TYPE_STA: | |
312 | *mode = IW_MODE_INFRA; | |
313 | break; | |
314 | case IEEE80211_IF_TYPE_IBSS: | |
315 | *mode = IW_MODE_ADHOC; | |
316 | break; | |
317 | case IEEE80211_IF_TYPE_MNTR: | |
318 | *mode = IW_MODE_MONITOR; | |
319 | break; | |
320 | case IEEE80211_IF_TYPE_WDS: | |
321 | *mode = IW_MODE_REPEAT; | |
322 | break; | |
323 | case IEEE80211_IF_TYPE_VLAN: | |
324 | *mode = IW_MODE_SECOND; /* FIXME */ | |
325 | break; | |
326 | default: | |
327 | *mode = IW_MODE_AUTO; | |
328 | break; | |
329 | } | |
330 | return 0; | |
331 | } | |
332 | ||
f698d856 | 333 | int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz) |
f0706e82 | 334 | { |
f0706e82 | 335 | int ret = -EINVAL; |
e048c6e4 | 336 | struct ieee80211_channel *chan; |
f698d856 | 337 | struct ieee80211_local *local = sdata->local; |
8318d78a | 338 | |
e048c6e4 | 339 | chan = ieee80211_get_channel(local->hw.wiphy, freqMHz); |
8318d78a | 340 | |
e048c6e4 | 341 | if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { |
be038b37 AK |
342 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
343 | chan->flags & IEEE80211_CHAN_NO_IBSS) { | |
344 | printk(KERN_DEBUG "%s: IBSS not allowed on frequency " | |
f698d856 | 345 | "%d MHz\n", sdata->dev->name, chan->center_freq); |
be038b37 AK |
346 | return ret; |
347 | } | |
e048c6e4 | 348 | local->oper_channel = chan; |
f0706e82 | 349 | |
675ef586 | 350 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
f0706e82 JB |
351 | ret = 0; |
352 | else | |
353 | ret = ieee80211_hw_config(local); | |
354 | ||
355 | rate_control_clear(local); | |
356 | } | |
357 | ||
358 | return ret; | |
359 | } | |
360 | ||
361 | static int ieee80211_ioctl_siwfreq(struct net_device *dev, | |
362 | struct iw_request_info *info, | |
363 | struct iw_freq *freq, char *extra) | |
364 | { | |
f0706e82 JB |
365 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
366 | ||
51fb61e7 | 367 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) |
d6f2da5b | 368 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; |
f0706e82 JB |
369 | |
370 | /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ | |
371 | if (freq->e == 0) { | |
372 | if (freq->m < 0) { | |
51fb61e7 | 373 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) |
d6f2da5b JS |
374 | sdata->u.sta.flags |= |
375 | IEEE80211_STA_AUTO_CHANNEL_SEL; | |
f0706e82 JB |
376 | return 0; |
377 | } else | |
f698d856 | 378 | return ieee80211_set_freq(sdata, |
8318d78a | 379 | ieee80211_channel_to_frequency(freq->m)); |
f0706e82 JB |
380 | } else { |
381 | int i, div = 1000000; | |
382 | for (i = 0; i < freq->e; i++) | |
383 | div /= 10; | |
384 | if (div > 0) | |
f698d856 | 385 | return ieee80211_set_freq(sdata, freq->m / div); |
f0706e82 JB |
386 | else |
387 | return -EINVAL; | |
388 | } | |
389 | } | |
390 | ||
391 | ||
392 | static int ieee80211_ioctl_giwfreq(struct net_device *dev, | |
393 | struct iw_request_info *info, | |
394 | struct iw_freq *freq, char *extra) | |
395 | { | |
396 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
397 | ||
8318d78a | 398 | freq->m = local->hw.conf.channel->center_freq; |
f0706e82 JB |
399 | freq->e = 6; |
400 | ||
401 | return 0; | |
402 | } | |
403 | ||
404 | ||
405 | static int ieee80211_ioctl_siwessid(struct net_device *dev, | |
406 | struct iw_request_info *info, | |
407 | struct iw_point *data, char *ssid) | |
408 | { | |
f0706e82 JB |
409 | struct ieee80211_sub_if_data *sdata; |
410 | size_t len = data->length; | |
411 | ||
412 | /* iwconfig uses nul termination in SSID.. */ | |
413 | if (len > 0 && ssid[len - 1] == '\0') | |
414 | len--; | |
415 | ||
416 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 JB |
417 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
418 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
f0706e82 | 419 | int ret; |
ddd3d2be | 420 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
f0706e82 JB |
421 | if (len > IEEE80211_MAX_SSID_LEN) |
422 | return -EINVAL; | |
423 | memcpy(sdata->u.sta.ssid, ssid, len); | |
424 | sdata->u.sta.ssid_len = len; | |
425 | return 0; | |
426 | } | |
d6f2da5b JS |
427 | if (data->flags) |
428 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; | |
429 | else | |
430 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL; | |
f698d856 | 431 | ret = ieee80211_sta_set_ssid(sdata, ssid, len); |
f0706e82 JB |
432 | if (ret) |
433 | return ret; | |
f698d856 | 434 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
f0706e82 JB |
435 | return 0; |
436 | } | |
437 | ||
51fb61e7 | 438 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
f0706e82 JB |
439 | memcpy(sdata->u.ap.ssid, ssid, len); |
440 | memset(sdata->u.ap.ssid + len, 0, | |
441 | IEEE80211_MAX_SSID_LEN - len); | |
442 | sdata->u.ap.ssid_len = len; | |
9d139c81 | 443 | return ieee80211_if_config(sdata, IEEE80211_IFCC_SSID); |
f0706e82 JB |
444 | } |
445 | return -EOPNOTSUPP; | |
446 | } | |
447 | ||
448 | ||
449 | static int ieee80211_ioctl_giwessid(struct net_device *dev, | |
450 | struct iw_request_info *info, | |
451 | struct iw_point *data, char *ssid) | |
452 | { | |
453 | size_t len; | |
454 | ||
455 | struct ieee80211_sub_if_data *sdata; | |
456 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 JB |
457 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
458 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
f698d856 | 459 | int res = ieee80211_sta_get_ssid(sdata, ssid, &len); |
f0706e82 JB |
460 | if (res == 0) { |
461 | data->length = len; | |
462 | data->flags = 1; | |
463 | } else | |
464 | data->flags = 0; | |
465 | return res; | |
466 | } | |
467 | ||
51fb61e7 | 468 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
f0706e82 JB |
469 | len = sdata->u.ap.ssid_len; |
470 | if (len > IW_ESSID_MAX_SIZE) | |
471 | len = IW_ESSID_MAX_SIZE; | |
472 | memcpy(ssid, sdata->u.ap.ssid, len); | |
473 | data->length = len; | |
474 | data->flags = 1; | |
475 | return 0; | |
476 | } | |
477 | return -EOPNOTSUPP; | |
478 | } | |
479 | ||
480 | ||
481 | static int ieee80211_ioctl_siwap(struct net_device *dev, | |
482 | struct iw_request_info *info, | |
483 | struct sockaddr *ap_addr, char *extra) | |
484 | { | |
f0706e82 JB |
485 | struct ieee80211_sub_if_data *sdata; |
486 | ||
487 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 JB |
488 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
489 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
f0706e82 | 490 | int ret; |
ddd3d2be | 491 | if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { |
f0706e82 JB |
492 | memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, |
493 | ETH_ALEN); | |
494 | return 0; | |
495 | } | |
d6f2da5b JS |
496 | if (is_zero_ether_addr((u8 *) &ap_addr->sa_data)) |
497 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL | | |
498 | IEEE80211_STA_AUTO_CHANNEL_SEL; | |
499 | else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data)) | |
500 | sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL; | |
f0706e82 | 501 | else |
d6f2da5b | 502 | sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
f698d856 | 503 | ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data); |
f0706e82 JB |
504 | if (ret) |
505 | return ret; | |
f698d856 | 506 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
f0706e82 | 507 | return 0; |
51fb61e7 | 508 | } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) { |
44213b5e JB |
509 | /* |
510 | * If it is necessary to update the WDS peer address | |
511 | * while the interface is running, then we need to do | |
512 | * more work here, namely if it is running we need to | |
513 | * add a new and remove the old STA entry, this is | |
514 | * normally handled by _open() and _stop(). | |
515 | */ | |
516 | if (netif_running(dev)) | |
517 | return -EBUSY; | |
518 | ||
519 | memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, | |
520 | ETH_ALEN); | |
521 | ||
522 | return 0; | |
f0706e82 JB |
523 | } |
524 | ||
525 | return -EOPNOTSUPP; | |
526 | } | |
527 | ||
528 | ||
529 | static int ieee80211_ioctl_giwap(struct net_device *dev, | |
530 | struct iw_request_info *info, | |
531 | struct sockaddr *ap_addr, char *extra) | |
532 | { | |
533 | struct ieee80211_sub_if_data *sdata; | |
534 | ||
535 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 JB |
536 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
537 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
5c5f9664 AK |
538 | if (sdata->u.sta.state == IEEE80211_ASSOCIATED || |
539 | sdata->u.sta.state == IEEE80211_IBSS_JOINED) { | |
d4231ca3 AK |
540 | ap_addr->sa_family = ARPHRD_ETHER; |
541 | memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN); | |
542 | return 0; | |
543 | } else { | |
544 | memset(&ap_addr->sa_data, 0, ETH_ALEN); | |
545 | return 0; | |
546 | } | |
51fb61e7 | 547 | } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) { |
f0706e82 JB |
548 | ap_addr->sa_family = ARPHRD_ETHER; |
549 | memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); | |
550 | return 0; | |
551 | } | |
552 | ||
553 | return -EOPNOTSUPP; | |
554 | } | |
555 | ||
556 | ||
557 | static int ieee80211_ioctl_siwscan(struct net_device *dev, | |
558 | struct iw_request_info *info, | |
107acb23 | 559 | union iwreq_data *wrqu, char *extra) |
f0706e82 | 560 | { |
f0706e82 | 561 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
107acb23 | 562 | struct iw_scan_req *req = NULL; |
f0706e82 JB |
563 | u8 *ssid = NULL; |
564 | size_t ssid_len = 0; | |
565 | ||
566 | if (!netif_running(dev)) | |
567 | return -ENETDOWN; | |
568 | ||
51fb61e7 JB |
569 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
570 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS && | |
ee385855 | 571 | sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT && |
51fb61e7 | 572 | sdata->vif.type != IEEE80211_IF_TYPE_AP) |
d114f399 | 573 | return -EOPNOTSUPP; |
d114f399 JL |
574 | |
575 | /* if SSID was specified explicitly then use that */ | |
107acb23 BM |
576 | if (wrqu->data.length == sizeof(struct iw_scan_req) && |
577 | wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
578 | req = (struct iw_scan_req *)extra; | |
579 | ssid = req->essid; | |
580 | ssid_len = req->essid_len; | |
f0706e82 | 581 | } |
f27b62d3 | 582 | |
f698d856 | 583 | return ieee80211_sta_req_scan(sdata, ssid, ssid_len); |
f0706e82 JB |
584 | } |
585 | ||
586 | ||
587 | static int ieee80211_ioctl_giwscan(struct net_device *dev, | |
588 | struct iw_request_info *info, | |
589 | struct iw_point *data, char *extra) | |
590 | { | |
591 | int res; | |
592 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
f698d856 JBG |
593 | struct ieee80211_sub_if_data *sdata; |
594 | ||
595 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
ece8eddd ZY |
596 | |
597 | if (local->sta_sw_scanning || local->sta_hw_scanning) | |
f0706e82 | 598 | return -EAGAIN; |
ece8eddd | 599 | |
f698d856 | 600 | res = ieee80211_sta_scan_results(local, info, extra, data->length); |
f0706e82 JB |
601 | if (res >= 0) { |
602 | data->length = res; | |
603 | return 0; | |
604 | } | |
605 | data->length = 0; | |
606 | return res; | |
607 | } | |
608 | ||
609 | ||
1fd5e589 LF |
610 | static int ieee80211_ioctl_siwrate(struct net_device *dev, |
611 | struct iw_request_info *info, | |
612 | struct iw_param *rate, char *extra) | |
613 | { | |
614 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
8318d78a | 615 | int i, err = -EINVAL; |
1fd5e589 LF |
616 | u32 target_rate = rate->value / 100000; |
617 | struct ieee80211_sub_if_data *sdata; | |
8318d78a | 618 | struct ieee80211_supported_band *sband; |
1fd5e589 LF |
619 | |
620 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
8318d78a JB |
621 | |
622 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
623 | ||
1fd5e589 LF |
624 | /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates |
625 | * target_rate = X, rate->fixed = 1 means only rate X | |
626 | * target_rate = X, rate->fixed = 0 means all rates <= X */ | |
3e122be0 JB |
627 | sdata->max_ratectrl_rateidx = -1; |
628 | sdata->force_unicast_rateidx = -1; | |
1fd5e589 LF |
629 | if (rate->value < 0) |
630 | return 0; | |
8318d78a JB |
631 | |
632 | for (i=0; i< sband->n_bitrates; i++) { | |
633 | struct ieee80211_rate *brate = &sband->bitrates[i]; | |
634 | int this_rate = brate->bitrate; | |
1fd5e589 | 635 | |
1fd5e589 | 636 | if (target_rate == this_rate) { |
3e122be0 | 637 | sdata->max_ratectrl_rateidx = i; |
1fd5e589 | 638 | if (rate->fixed) |
3e122be0 | 639 | sdata->force_unicast_rateidx = i; |
8318d78a JB |
640 | err = 0; |
641 | break; | |
1fd5e589 LF |
642 | } |
643 | } | |
8318d78a | 644 | return err; |
1fd5e589 LF |
645 | } |
646 | ||
b3d88ad4 LF |
647 | static int ieee80211_ioctl_giwrate(struct net_device *dev, |
648 | struct iw_request_info *info, | |
649 | struct iw_param *rate, char *extra) | |
650 | { | |
651 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
652 | struct sta_info *sta; | |
653 | struct ieee80211_sub_if_data *sdata; | |
8318d78a | 654 | struct ieee80211_supported_band *sband; |
b3d88ad4 LF |
655 | |
656 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
8318d78a | 657 | |
380a942b | 658 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
b3d88ad4 | 659 | return -EOPNOTSUPP; |
8318d78a JB |
660 | |
661 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
662 | ||
380a942b JB |
663 | rcu_read_lock(); |
664 | ||
665 | sta = sta_info_get(local, sdata->u.sta.bssid); | |
666 | ||
667 | if (sta && sta->txrate_idx < sband->n_bitrates) | |
8318d78a | 668 | rate->value = sband->bitrates[sta->txrate_idx].bitrate; |
b3d88ad4 LF |
669 | else |
670 | rate->value = 0; | |
380a942b JB |
671 | |
672 | rcu_read_unlock(); | |
673 | ||
674 | if (!sta) | |
675 | return -ENODEV; | |
676 | ||
8318d78a | 677 | rate->value *= 100000; |
d0709a65 | 678 | |
b3d88ad4 LF |
679 | return 0; |
680 | } | |
681 | ||
61609bc0 MB |
682 | static int ieee80211_ioctl_siwtxpower(struct net_device *dev, |
683 | struct iw_request_info *info, | |
684 | union iwreq_data *data, char *extra) | |
685 | { | |
686 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
687 | bool need_reconfig = 0; | |
8318d78a | 688 | int new_power_level; |
61609bc0 MB |
689 | |
690 | if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) | |
691 | return -EINVAL; | |
692 | if (data->txpower.flags & IW_TXPOW_RANGE) | |
693 | return -EINVAL; | |
61609bc0 | 694 | |
6a432955 MN |
695 | if (data->txpower.fixed) { |
696 | new_power_level = data->txpower.value; | |
697 | } else { | |
8318d78a JB |
698 | /* |
699 | * Automatic power level. Use maximum power for the current | |
700 | * channel. Should be part of rate control. | |
701 | */ | |
702 | struct ieee80211_channel* chan = local->hw.conf.channel; | |
6a432955 MN |
703 | if (!chan) |
704 | return -EINVAL; | |
705 | ||
8318d78a | 706 | new_power_level = chan->max_power; |
6a432955 MN |
707 | } |
708 | ||
709 | if (local->hw.conf.power_level != new_power_level) { | |
710 | local->hw.conf.power_level = new_power_level; | |
61609bc0 MB |
711 | need_reconfig = 1; |
712 | } | |
6a432955 | 713 | |
61609bc0 MB |
714 | if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) { |
715 | local->hw.conf.radio_enabled = !(data->txpower.disabled); | |
716 | need_reconfig = 1; | |
cdcb006f | 717 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
61609bc0 | 718 | } |
6a432955 | 719 | |
61609bc0 MB |
720 | if (need_reconfig) { |
721 | ieee80211_hw_config(local); | |
722 | /* The return value of hw_config is not of big interest here, | |
723 | * as it doesn't say that it failed because of _this_ config | |
724 | * change or something else. Ignore it. */ | |
725 | } | |
726 | ||
727 | return 0; | |
728 | } | |
729 | ||
fe6aa301 LF |
730 | static int ieee80211_ioctl_giwtxpower(struct net_device *dev, |
731 | struct iw_request_info *info, | |
732 | union iwreq_data *data, char *extra) | |
733 | { | |
734 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
735 | ||
736 | data->txpower.fixed = 1; | |
737 | data->txpower.disabled = !(local->hw.conf.radio_enabled); | |
738 | data->txpower.value = local->hw.conf.power_level; | |
739 | data->txpower.flags = IW_TXPOW_DBM; | |
740 | ||
741 | return 0; | |
742 | } | |
743 | ||
f0706e82 JB |
744 | static int ieee80211_ioctl_siwrts(struct net_device *dev, |
745 | struct iw_request_info *info, | |
746 | struct iw_param *rts, char *extra) | |
747 | { | |
748 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
749 | ||
750 | if (rts->disabled) | |
751 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
fa6adfe9 EG |
752 | else if (!rts->fixed) |
753 | /* if the rts value is not fixed, then take default */ | |
754 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
f0706e82 JB |
755 | else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD) |
756 | return -EINVAL; | |
757 | else | |
758 | local->rts_threshold = rts->value; | |
759 | ||
760 | /* If the wlan card performs RTS/CTS in hardware/firmware, | |
761 | * configure it here */ | |
762 | ||
763 | if (local->ops->set_rts_threshold) | |
764 | local->ops->set_rts_threshold(local_to_hw(local), | |
765 | local->rts_threshold); | |
766 | ||
767 | return 0; | |
768 | } | |
769 | ||
770 | static int ieee80211_ioctl_giwrts(struct net_device *dev, | |
771 | struct iw_request_info *info, | |
772 | struct iw_param *rts, char *extra) | |
773 | { | |
774 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
775 | ||
776 | rts->value = local->rts_threshold; | |
777 | rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD); | |
778 | rts->fixed = 1; | |
779 | ||
780 | return 0; | |
781 | } | |
782 | ||
783 | ||
784 | static int ieee80211_ioctl_siwfrag(struct net_device *dev, | |
785 | struct iw_request_info *info, | |
786 | struct iw_param *frag, char *extra) | |
787 | { | |
788 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
789 | ||
790 | if (frag->disabled) | |
791 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
e4abd4d4 EG |
792 | else if (!frag->fixed) |
793 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
f0706e82 JB |
794 | else if (frag->value < 256 || |
795 | frag->value > IEEE80211_MAX_FRAG_THRESHOLD) | |
796 | return -EINVAL; | |
797 | else { | |
798 | /* Fragment length must be even, so strip LSB. */ | |
799 | local->fragmentation_threshold = frag->value & ~0x1; | |
800 | } | |
801 | ||
802 | /* If the wlan card performs fragmentation in hardware/firmware, | |
803 | * configure it here */ | |
804 | ||
805 | if (local->ops->set_frag_threshold) | |
806 | local->ops->set_frag_threshold( | |
807 | local_to_hw(local), | |
808 | local->fragmentation_threshold); | |
809 | ||
810 | return 0; | |
811 | } | |
812 | ||
813 | static int ieee80211_ioctl_giwfrag(struct net_device *dev, | |
814 | struct iw_request_info *info, | |
815 | struct iw_param *frag, char *extra) | |
816 | { | |
817 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
818 | ||
819 | frag->value = local->fragmentation_threshold; | |
820 | frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD); | |
821 | frag->fixed = 1; | |
822 | ||
823 | return 0; | |
824 | } | |
825 | ||
826 | ||
827 | static int ieee80211_ioctl_siwretry(struct net_device *dev, | |
828 | struct iw_request_info *info, | |
829 | struct iw_param *retry, char *extra) | |
830 | { | |
831 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
832 | ||
833 | if (retry->disabled || | |
834 | (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) | |
835 | return -EINVAL; | |
836 | ||
837 | if (retry->flags & IW_RETRY_MAX) | |
838 | local->long_retry_limit = retry->value; | |
839 | else if (retry->flags & IW_RETRY_MIN) | |
840 | local->short_retry_limit = retry->value; | |
841 | else { | |
842 | local->long_retry_limit = retry->value; | |
843 | local->short_retry_limit = retry->value; | |
844 | } | |
845 | ||
846 | if (local->ops->set_retry_limit) { | |
847 | return local->ops->set_retry_limit( | |
848 | local_to_hw(local), | |
849 | local->short_retry_limit, | |
850 | local->long_retry_limit); | |
851 | } | |
852 | ||
853 | return 0; | |
854 | } | |
855 | ||
856 | ||
857 | static int ieee80211_ioctl_giwretry(struct net_device *dev, | |
858 | struct iw_request_info *info, | |
859 | struct iw_param *retry, char *extra) | |
860 | { | |
861 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
862 | ||
863 | retry->disabled = 0; | |
864 | if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) { | |
865 | /* first return min value, iwconfig will ask max value | |
866 | * later if needed */ | |
867 | retry->flags |= IW_RETRY_LIMIT; | |
868 | retry->value = local->short_retry_limit; | |
869 | if (local->long_retry_limit != local->short_retry_limit) | |
870 | retry->flags |= IW_RETRY_MIN; | |
871 | return 0; | |
872 | } | |
873 | if (retry->flags & IW_RETRY_MAX) { | |
874 | retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
875 | retry->value = local->long_retry_limit; | |
876 | } | |
877 | ||
878 | return 0; | |
879 | } | |
880 | ||
f0706e82 JB |
881 | static int ieee80211_ioctl_siwmlme(struct net_device *dev, |
882 | struct iw_request_info *info, | |
883 | struct iw_point *data, char *extra) | |
884 | { | |
885 | struct ieee80211_sub_if_data *sdata; | |
886 | struct iw_mlme *mlme = (struct iw_mlme *) extra; | |
887 | ||
888 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 JB |
889 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
890 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) | |
f0706e82 JB |
891 | return -EINVAL; |
892 | ||
893 | switch (mlme->cmd) { | |
894 | case IW_MLME_DEAUTH: | |
895 | /* TODO: mlme->addr.sa_data */ | |
f698d856 | 896 | return ieee80211_sta_deauthenticate(sdata, mlme->reason_code); |
f0706e82 JB |
897 | case IW_MLME_DISASSOC: |
898 | /* TODO: mlme->addr.sa_data */ | |
f698d856 | 899 | return ieee80211_sta_disassociate(sdata, mlme->reason_code); |
f0706e82 JB |
900 | default: |
901 | return -EOPNOTSUPP; | |
902 | } | |
903 | } | |
904 | ||
905 | ||
906 | static int ieee80211_ioctl_siwencode(struct net_device *dev, | |
907 | struct iw_request_info *info, | |
908 | struct iw_point *erq, char *keybuf) | |
909 | { | |
910 | struct ieee80211_sub_if_data *sdata; | |
911 | int idx, i, alg = ALG_WEP; | |
912 | u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
628a140b | 913 | int remove = 0; |
f0706e82 JB |
914 | |
915 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
916 | ||
917 | idx = erq->flags & IW_ENCODE_INDEX; | |
918 | if (idx == 0) { | |
919 | if (sdata->default_key) | |
920 | for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
921 | if (sdata->default_key == sdata->keys[i]) { | |
922 | idx = i; | |
923 | break; | |
924 | } | |
925 | } | |
926 | } else if (idx < 1 || idx > 4) | |
927 | return -EINVAL; | |
928 | else | |
929 | idx--; | |
930 | ||
931 | if (erq->flags & IW_ENCODE_DISABLED) | |
628a140b | 932 | remove = 1; |
f0706e82 JB |
933 | else if (erq->length == 0) { |
934 | /* No key data - just set the default TX key index */ | |
11a843b7 | 935 | ieee80211_set_default_key(sdata, idx); |
f0706e82 JB |
936 | return 0; |
937 | } | |
938 | ||
939 | return ieee80211_set_encryption( | |
f698d856 | 940 | sdata, bcaddr, |
628a140b | 941 | idx, alg, remove, |
f0706e82 JB |
942 | !sdata->default_key, |
943 | keybuf, erq->length); | |
944 | } | |
945 | ||
946 | ||
947 | static int ieee80211_ioctl_giwencode(struct net_device *dev, | |
948 | struct iw_request_info *info, | |
949 | struct iw_point *erq, char *key) | |
950 | { | |
951 | struct ieee80211_sub_if_data *sdata; | |
952 | int idx, i; | |
953 | ||
954 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
955 | ||
956 | idx = erq->flags & IW_ENCODE_INDEX; | |
957 | if (idx < 1 || idx > 4) { | |
958 | idx = -1; | |
959 | if (!sdata->default_key) | |
960 | idx = 0; | |
961 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
962 | if (sdata->default_key == sdata->keys[i]) { | |
963 | idx = i; | |
964 | break; | |
965 | } | |
966 | } | |
967 | if (idx < 0) | |
968 | return -EINVAL; | |
969 | } else | |
970 | idx--; | |
971 | ||
972 | erq->flags = idx + 1; | |
973 | ||
974 | if (!sdata->keys[idx]) { | |
975 | erq->length = 0; | |
976 | erq->flags |= IW_ENCODE_DISABLED; | |
977 | return 0; | |
978 | } | |
979 | ||
8f20fc24 | 980 | memcpy(key, sdata->keys[idx]->conf.key, |
11a843b7 | 981 | min_t(int, erq->length, sdata->keys[idx]->conf.keylen)); |
8f20fc24 | 982 | erq->length = sdata->keys[idx]->conf.keylen; |
f0706e82 JB |
983 | erq->flags |= IW_ENCODE_ENABLED; |
984 | ||
b9fcc4f2 EG |
985 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
986 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
987 | switch (ifsta->auth_alg) { | |
988 | case WLAN_AUTH_OPEN: | |
989 | case WLAN_AUTH_LEAP: | |
990 | erq->flags |= IW_ENCODE_OPEN; | |
991 | break; | |
992 | case WLAN_AUTH_SHARED_KEY: | |
993 | erq->flags |= IW_ENCODE_RESTRICTED; | |
994 | break; | |
995 | } | |
996 | } | |
997 | ||
f0706e82 JB |
998 | return 0; |
999 | } | |
1000 | ||
49292d56 SO |
1001 | static int ieee80211_ioctl_siwpower(struct net_device *dev, |
1002 | struct iw_request_info *info, | |
1003 | struct iw_param *wrq, | |
1004 | char *extra) | |
1005 | { | |
1006 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
1007 | struct ieee80211_conf *conf = &local->hw.conf; | |
1008 | ||
1009 | if (wrq->disabled) { | |
1010 | conf->flags &= ~IEEE80211_CONF_PS; | |
1011 | return ieee80211_hw_config(local); | |
1012 | } | |
1013 | ||
1014 | switch (wrq->flags & IW_POWER_MODE) { | |
1015 | case IW_POWER_ON: /* If not specified */ | |
1016 | case IW_POWER_MODE: /* If set all mask */ | |
1017 | case IW_POWER_ALL_R: /* If explicitely state all */ | |
1018 | conf->flags |= IEEE80211_CONF_PS; | |
1019 | break; | |
1020 | default: /* Otherwise we don't support it */ | |
1021 | return -EINVAL; | |
1022 | } | |
1023 | ||
1024 | return ieee80211_hw_config(local); | |
1025 | } | |
1026 | ||
1027 | static int ieee80211_ioctl_giwpower(struct net_device *dev, | |
1028 | struct iw_request_info *info, | |
1029 | union iwreq_data *wrqu, | |
1030 | char *extra) | |
1031 | { | |
1032 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
1033 | struct ieee80211_conf *conf = &local->hw.conf; | |
1034 | ||
1035 | wrqu->power.disabled = !(conf->flags & IEEE80211_CONF_PS); | |
1036 | ||
1037 | return 0; | |
1038 | } | |
1039 | ||
f0706e82 JB |
1040 | static int ieee80211_ioctl_siwauth(struct net_device *dev, |
1041 | struct iw_request_info *info, | |
1042 | struct iw_param *data, char *extra) | |
1043 | { | |
f0706e82 JB |
1044 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1045 | int ret = 0; | |
1046 | ||
1047 | switch (data->flags & IW_AUTH_INDEX) { | |
1048 | case IW_AUTH_WPA_VERSION: | |
1049 | case IW_AUTH_CIPHER_PAIRWISE: | |
1050 | case IW_AUTH_CIPHER_GROUP: | |
1051 | case IW_AUTH_WPA_ENABLED: | |
1052 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
f0706e82 | 1053 | case IW_AUTH_KEY_MGMT: |
5b98b1f7 | 1054 | break; |
b1357a81 JB |
1055 | case IW_AUTH_DROP_UNENCRYPTED: |
1056 | sdata->drop_unencrypted = !!data->value; | |
1057 | break; | |
5b98b1f7 | 1058 | case IW_AUTH_PRIVACY_INVOKED: |
51fb61e7 | 1059 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
f0706e82 JB |
1060 | ret = -EINVAL; |
1061 | else { | |
5b98b1f7 | 1062 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
f0706e82 | 1063 | /* |
5b98b1f7 JB |
1064 | * Privacy invoked by wpa_supplicant, store the |
1065 | * value and allow associating to a protected | |
1066 | * network without having a key up front. | |
f0706e82 | 1067 | */ |
5b98b1f7 JB |
1068 | if (data->value) |
1069 | sdata->u.sta.flags |= | |
1070 | IEEE80211_STA_PRIVACY_INVOKED; | |
f0706e82 JB |
1071 | } |
1072 | break; | |
1073 | case IW_AUTH_80211_AUTH_ALG: | |
51fb61e7 JB |
1074 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
1075 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) | |
f0706e82 JB |
1076 | sdata->u.sta.auth_algs = data->value; |
1077 | else | |
1078 | ret = -EOPNOTSUPP; | |
1079 | break; | |
f0706e82 JB |
1080 | default: |
1081 | ret = -EOPNOTSUPP; | |
1082 | break; | |
1083 | } | |
1084 | return ret; | |
1085 | } | |
1086 | ||
1087 | /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */ | |
1088 | static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev) | |
1089 | { | |
1090 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
1091 | struct iw_statistics *wstats = &local->wstats; | |
1092 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1093 | struct sta_info *sta = NULL; | |
1094 | ||
98dd6a57 JB |
1095 | rcu_read_lock(); |
1096 | ||
51fb61e7 JB |
1097 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
1098 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) | |
f0706e82 JB |
1099 | sta = sta_info_get(local, sdata->u.sta.bssid); |
1100 | if (!sta) { | |
1101 | wstats->discard.fragment = 0; | |
1102 | wstats->discard.misc = 0; | |
1103 | wstats->qual.qual = 0; | |
1104 | wstats->qual.level = 0; | |
1105 | wstats->qual.noise = 0; | |
1106 | wstats->qual.updated = IW_QUAL_ALL_INVALID; | |
1107 | } else { | |
566bfe5a BR |
1108 | wstats->qual.level = sta->last_signal; |
1109 | wstats->qual.qual = sta->last_qual; | |
f0706e82 JB |
1110 | wstats->qual.noise = sta->last_noise; |
1111 | wstats->qual.updated = local->wstats_flags; | |
f0706e82 | 1112 | } |
98dd6a57 JB |
1113 | |
1114 | rcu_read_unlock(); | |
1115 | ||
f0706e82 JB |
1116 | return wstats; |
1117 | } | |
1118 | ||
1119 | static int ieee80211_ioctl_giwauth(struct net_device *dev, | |
1120 | struct iw_request_info *info, | |
1121 | struct iw_param *data, char *extra) | |
1122 | { | |
1123 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1124 | int ret = 0; | |
1125 | ||
1126 | switch (data->flags & IW_AUTH_INDEX) { | |
1127 | case IW_AUTH_80211_AUTH_ALG: | |
51fb61e7 JB |
1128 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
1129 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) | |
f0706e82 JB |
1130 | data->value = sdata->u.sta.auth_algs; |
1131 | else | |
1132 | ret = -EOPNOTSUPP; | |
1133 | break; | |
1134 | default: | |
1135 | ret = -EOPNOTSUPP; | |
1136 | break; | |
1137 | } | |
1138 | return ret; | |
1139 | } | |
1140 | ||
1141 | ||
1142 | static int ieee80211_ioctl_siwencodeext(struct net_device *dev, | |
1143 | struct iw_request_info *info, | |
1144 | struct iw_point *erq, char *extra) | |
1145 | { | |
1146 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1147 | struct iw_encode_ext *ext = (struct iw_encode_ext *) extra; | |
628a140b | 1148 | int uninitialized_var(alg), idx, i, remove = 0; |
f0706e82 JB |
1149 | |
1150 | switch (ext->alg) { | |
1151 | case IW_ENCODE_ALG_NONE: | |
628a140b | 1152 | remove = 1; |
f0706e82 JB |
1153 | break; |
1154 | case IW_ENCODE_ALG_WEP: | |
1155 | alg = ALG_WEP; | |
1156 | break; | |
1157 | case IW_ENCODE_ALG_TKIP: | |
1158 | alg = ALG_TKIP; | |
1159 | break; | |
1160 | case IW_ENCODE_ALG_CCMP: | |
1161 | alg = ALG_CCMP; | |
1162 | break; | |
1163 | default: | |
1164 | return -EOPNOTSUPP; | |
1165 | } | |
1166 | ||
1167 | if (erq->flags & IW_ENCODE_DISABLED) | |
628a140b | 1168 | remove = 1; |
f0706e82 JB |
1169 | |
1170 | idx = erq->flags & IW_ENCODE_INDEX; | |
1171 | if (idx < 1 || idx > 4) { | |
1172 | idx = -1; | |
1173 | if (!sdata->default_key) | |
1174 | idx = 0; | |
1175 | else for (i = 0; i < NUM_DEFAULT_KEYS; i++) { | |
1176 | if (sdata->default_key == sdata->keys[i]) { | |
1177 | idx = i; | |
1178 | break; | |
1179 | } | |
1180 | } | |
1181 | if (idx < 0) | |
1182 | return -EINVAL; | |
1183 | } else | |
1184 | idx--; | |
1185 | ||
f698d856 | 1186 | return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg, |
628a140b | 1187 | remove, |
f0706e82 JB |
1188 | ext->ext_flags & |
1189 | IW_ENCODE_EXT_SET_TX_KEY, | |
1190 | ext->key, ext->key_len); | |
1191 | } | |
1192 | ||
1193 | ||
f0706e82 JB |
1194 | /* Structures to export the Wireless Handlers */ |
1195 | ||
1196 | static const iw_handler ieee80211_handler[] = | |
1197 | { | |
1198 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ | |
1199 | (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */ | |
1200 | (iw_handler) NULL, /* SIOCSIWNWID */ | |
1201 | (iw_handler) NULL, /* SIOCGIWNWID */ | |
1202 | (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */ | |
1203 | (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */ | |
1204 | (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */ | |
1205 | (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */ | |
1206 | (iw_handler) NULL, /* SIOCSIWSENS */ | |
1207 | (iw_handler) NULL, /* SIOCGIWSENS */ | |
1208 | (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */ | |
1209 | (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */ | |
1210 | (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ | |
1211 | (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ | |
1212 | (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ | |
1213 | (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ | |
5d4ecd93 JB |
1214 | (iw_handler) NULL, /* SIOCSIWSPY */ |
1215 | (iw_handler) NULL, /* SIOCGIWSPY */ | |
1216 | (iw_handler) NULL, /* SIOCSIWTHRSPY */ | |
1217 | (iw_handler) NULL, /* SIOCGIWTHRSPY */ | |
f0706e82 JB |
1218 | (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ |
1219 | (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ | |
1220 | (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ | |
1221 | (iw_handler) NULL, /* SIOCGIWAPLIST */ | |
1222 | (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */ | |
1223 | (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */ | |
1224 | (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */ | |
1225 | (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */ | |
1226 | (iw_handler) NULL, /* SIOCSIWNICKN */ | |
1227 | (iw_handler) NULL, /* SIOCGIWNICKN */ | |
1228 | (iw_handler) NULL, /* -- hole -- */ | |
1229 | (iw_handler) NULL, /* -- hole -- */ | |
1fd5e589 | 1230 | (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ |
b3d88ad4 | 1231 | (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ |
f0706e82 JB |
1232 | (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ |
1233 | (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ | |
1234 | (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ | |
1235 | (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ | |
61609bc0 | 1236 | (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ |
fe6aa301 | 1237 | (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ |
f0706e82 JB |
1238 | (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ |
1239 | (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ | |
1240 | (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ | |
1241 | (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ | |
49292d56 SO |
1242 | (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ |
1243 | (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ | |
f0706e82 JB |
1244 | (iw_handler) NULL, /* -- hole -- */ |
1245 | (iw_handler) NULL, /* -- hole -- */ | |
1246 | (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */ | |
1247 | (iw_handler) NULL, /* SIOCGIWGENIE */ | |
1248 | (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ | |
1249 | (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ | |
1250 | (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ | |
1251 | (iw_handler) NULL, /* SIOCGIWENCODEEXT */ | |
1252 | (iw_handler) NULL, /* SIOCSIWPMKSA */ | |
1253 | (iw_handler) NULL, /* -- hole -- */ | |
1254 | }; | |
1255 | ||
f0706e82 JB |
1256 | const struct iw_handler_def ieee80211_iw_handler_def = |
1257 | { | |
1258 | .num_standard = ARRAY_SIZE(ieee80211_handler), | |
f0706e82 | 1259 | .standard = (iw_handler *) ieee80211_handler, |
f0706e82 JB |
1260 | .get_wireless_stats = ieee80211_get_wireless_stats, |
1261 | }; |