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