blob: beae664ab4801eff2204b75cb404367f414a33d4 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
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"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040024#include "led.h"
25#include "rate.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070026#include "wpa.h"
27#include "aes_ccm.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070028
Johannes Bergb708e612007-09-14 11:10:25 -040029
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120030static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr,
Johannes Berg628a1402007-09-26 17:53:17 +020031 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
33 size_t key_len)
Jiri Bencf0706e82007-05-05 11:45:53 -070034{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120035 struct ieee80211_local *local = sdata->local;
Johannes Bergd0709a62008-02-25 16:27:46 +010036 struct sta_info *sta;
Johannes Berg11a843b2007-08-28 17:01:55 -040037 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +020038 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070039
Volker Braun139c3a02007-09-14 11:10:25 -040040 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
41 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120042 sdata->dev->name, idx);
Volker Braun139c3a02007-09-14 11:10:25 -040043 return -EINVAL;
44 }
45
Johannes Berg628a1402007-09-26 17:53:17 +020046 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020047 rcu_read_lock();
48
49 err = 0;
50
Johannes Bergdb4d1162008-02-25 16:27:45 +010051 if (is_broadcast_ether_addr(sta_addr)) {
52 key = sdata->keys[idx];
53 } else {
54 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020055 if (!sta) {
56 err = -ENOENT;
57 goto out_unlock;
58 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010059 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070060 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010061
Johannes Bergd0709a62008-02-25 16:27:46 +010062 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010063 } else {
64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
65 if (!key)
66 return -ENOMEM;
67
Johannes Bergd0709a62008-02-25 16:27:46 +010068 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020069 err = 0;
70
71 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010072
Johannes Bergdb4d1162008-02-25 16:27:45 +010073 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) {
Johannes Bergd0709a62008-02-25 16:27:46 +010082 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020083 err = -EINVAL;
84 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010085 }
86
87 sta = sta_info_get(local, sta_addr);
88 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010089 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020090 err = -ENOENT;
91 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010092 }
93 }
94
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +030095 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
Johannes Bergdb4d1162008-02-25 16:27:45 +0100102 ieee80211_key_link(key, sdata, sta);
103
104 if (set_tx_key || (!sta && !sdata->default_key && key))
105 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700106 }
107
Johannes Berg3b967662008-04-08 17:56:52 +0200108 out_unlock:
109 rcu_read_unlock();
110
111 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700112}
113
114static 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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700119
120 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200121
122 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
123 return -EOPNOTSUPP;
124
Johannes Berg51fb61e2007-12-19 01:31:27 +0100125 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
126 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200127 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700128 if (ret)
129 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400130 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200131 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700132 return 0;
133 }
134
Jiri Bencf0706e82007-05-05 11:45:53 -0700135 return -EOPNOTSUPP;
136}
137
Jiri Bencf0706e82007-05-05 11:45:53 -0700138static int ieee80211_ioctl_giwname(struct net_device *dev,
139 struct iw_request_info *info,
140 char *name, char *extra)
141{
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300142 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
Johannes Berg8318d782008-01-24 19:38:38 +0100166 strcpy(name, "IEEE 802.11");
Tomas Winklerf37d08b2008-06-24 15:50:17 +0300167 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");
Jiri Bencf0706e82007-05-05 11:45:53 -0700175
176 return 0;
177}
178
179
180static 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;
Johannes Berg8318d782008-01-24 19:38:38 +0100186 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200187 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700188
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
Bruno Randolf566bfe52008-05-08 19:15:40 +0200208 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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700222 range->max_qual.updated = local->wstats_flags;
223
Bruno Randolf566bfe52008-05-08 19:15:40 +0200224 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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700228 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
Hong Liu333af2f2007-07-10 19:32:08 +0200233
Johannes Berg8318d782008-01-24 19:38:38 +0100234 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)
Hong Liu333af2f2007-07-10 19:32:08 +0200241 continue;
242
Johannes Berg8318d782008-01-24 19:38:38 +0100243 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
244 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200245
Johannes Berg8318d782008-01-24 19:38:38 +0100246 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;
Hong Liu333af2f2007-07-10 19:32:08 +0200252 c++;
253 }
Hong Liu333af2f2007-07-10 19:32:08 +0200254 }
255 }
256 range->num_channels = c;
257 range->num_frequency = c;
258
Jiri Bencf0706e82007-05-05 11:45:53 -0700259 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700260 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
261 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
262
Dan Williams374fdfb2007-12-12 10:25:07 -0500263 range->scan_capa |= IW_SCAN_CAPA_ESSID;
264
Jiri Bencf0706e82007-05-05 11:45:53 -0700265 return 0;
266}
267
268
Jiri Bencf0706e82007-05-05 11:45:53 -0700269static 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
Johannes Berg51fb61e2007-12-19 01:31:27 +0100276 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700277 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;
Johannes Bergb4540482008-04-14 15:37:03 +0200286 case IW_MODE_REPEAT:
287 type = IEEE80211_IF_TYPE_WDS;
288 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700289 case IW_MODE_MONITOR:
290 type = IEEE80211_IF_TYPE_MNTR;
291 break;
292 default:
293 return -EINVAL;
294 }
295
Johannes Bergf3947e22008-07-09 14:40:36 +0200296 return ieee80211_if_change_type(sdata, type);
Jiri Bencf0706e82007-05-05 11:45:53 -0700297}
298
299
300static 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);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100307 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700308 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
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200333int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700334{
Jiri Bencf0706e82007-05-05 11:45:53 -0700335 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100336 struct ieee80211_channel *chan;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200337 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700338
Johannes Berge048c6e2008-03-16 18:35:56 +0100339 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100340
Johannes Berge048c6e2008-03-16 18:35:56 +0100341 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Assaf Kraussbe038b32008-06-05 19:55:21 +0300342 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 "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200345 "%d MHz\n", sdata->dev->name, chan->center_freq);
Assaf Kraussbe038b32008-06-05 19:55:21 +0300346 return ret;
347 }
Johannes Berge048c6e2008-03-16 18:35:56 +0100348 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100349
Mohamed Abbas675ef582008-03-20 08:14:29 -0700350 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700351 ret = 0;
352 else
353 ret = ieee80211_hw_config(local);
354
355 rate_control_clear(local);
356 }
357
358 return ret;
359}
360
361static int ieee80211_ioctl_siwfreq(struct net_device *dev,
362 struct iw_request_info *info,
363 struct iw_freq *freq, char *extra)
364{
Jiri Bencf0706e82007-05-05 11:45:53 -0700365 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
366
Johannes Berg51fb61e2007-12-19 01:31:27 +0100367 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400368 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700369
370 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
371 if (freq->e == 0) {
372 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100373 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400374 sdata->u.sta.flags |=
375 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700376 return 0;
377 } else
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200378 return ieee80211_set_freq(sdata,
Johannes Berg8318d782008-01-24 19:38:38 +0100379 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700380 } else {
381 int i, div = 1000000;
382 for (i = 0; i < freq->e; i++)
383 div /= 10;
384 if (div > 0)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200385 return ieee80211_set_freq(sdata, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700386 else
387 return -EINVAL;
388 }
389}
390
391
392static 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
Johannes Berg8318d782008-01-24 19:38:38 +0100398 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700399 freq->e = 6;
400
401 return 0;
402}
403
404
405static int ieee80211_ioctl_siwessid(struct net_device *dev,
406 struct iw_request_info *info,
407 struct iw_point *data, char *ssid)
408{
Jiri Bencf0706e82007-05-05 11:45:53 -0700409 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);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100417 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
418 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700419 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200420 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700421 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 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400427 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;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200431 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700432 if (ret)
433 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200434 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700435 return 0;
436 }
437
Johannes Berg51fb61e2007-12-19 01:31:27 +0100438 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700439 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;
Johannes Berg9d139c82008-07-09 14:40:37 +0200443 return ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
Jiri Bencf0706e82007-05-05 11:45:53 -0700444 }
445 return -EOPNOTSUPP;
446}
447
448
449static 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);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100457 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
458 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200459 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700460 if (res == 0) {
461 data->length = len;
462 data->flags = 1;
463 } else
464 data->flags = 0;
465 return res;
466 }
467
Johannes Berg51fb61e2007-12-19 01:31:27 +0100468 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700469 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
481static int ieee80211_ioctl_siwap(struct net_device *dev,
482 struct iw_request_info *info,
483 struct sockaddr *ap_addr, char *extra)
484{
Jiri Bencf0706e82007-05-05 11:45:53 -0700485 struct ieee80211_sub_if_data *sdata;
486
487 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100488 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
489 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700490 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200491 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700492 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
493 ETH_ALEN);
494 return 0;
495 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400496 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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700501 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400502 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200503 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
Jiri Bencf0706e82007-05-05 11:45:53 -0700504 if (ret)
505 return ret;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200506 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
Jiri Bencf0706e82007-05-05 11:45:53 -0700507 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100508 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100509 /*
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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700523 }
524
525 return -EOPNOTSUPP;
526}
527
528
529static 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);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100536 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
537 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Tomas Winkler48c2fc52008-08-06 14:22:01 +0300538 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
539 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700540 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 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100547 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700548 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
557static int ieee80211_ioctl_siwscan(struct net_device *dev,
558 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400559 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700560{
Jiri Bencf0706e82007-05-05 11:45:53 -0700561 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400562 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700563 u8 *ssid = NULL;
564 size_t ssid_len = 0;
565
566 if (!netif_running(dev))
567 return -ENETDOWN;
568
Johannes Berg51fb61e2007-12-19 01:31:27 +0100569 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
570 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100571 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100572 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700573 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700574
575 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400576 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;
Jiri Bencf0706e82007-05-05 11:45:53 -0700581 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200582
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200583 return ieee80211_sta_req_scan(sdata, ssid, ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700584}
585
586
587static 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);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200593 struct ieee80211_sub_if_data *sdata;
594
595 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Zhu Yiece8edd2007-11-22 10:53:21 +0800596
597 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700598 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800599
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200600 res = ieee80211_sta_scan_results(local, info, extra, data->length);
Jiri Bencf0706e82007-05-05 11:45:53 -0700601 if (res >= 0) {
602 data->length = res;
603 return 0;
604 }
605 data->length = 0;
606 return res;
607}
608
609
Larry Finger1fd5e582007-07-10 19:32:10 +0200610static 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);
Johannes Berg8318d782008-01-24 19:38:38 +0100615 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200616 u32 target_rate = rate->value / 100000;
617 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100618 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200619
620 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100621
622 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
623
Larry Finger1fd5e582007-07-10 19:32:10 +0200624 /* 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 */
Johannes Berg3e122be2008-07-09 14:40:34 +0200627 sdata->max_ratectrl_rateidx = -1;
628 sdata->force_unicast_rateidx = -1;
Larry Finger1fd5e582007-07-10 19:32:10 +0200629 if (rate->value < 0)
630 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100631
632 for (i=0; i< sband->n_bitrates; i++) {
633 struct ieee80211_rate *brate = &sband->bitrates[i];
634 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200635
Larry Finger1fd5e582007-07-10 19:32:10 +0200636 if (target_rate == this_rate) {
Johannes Berg3e122be2008-07-09 14:40:34 +0200637 sdata->max_ratectrl_rateidx = i;
Larry Finger1fd5e582007-07-10 19:32:10 +0200638 if (rate->fixed)
Johannes Berg3e122be2008-07-09 14:40:34 +0200639 sdata->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100640 err = 0;
641 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200642 }
643 }
Johannes Berg8318d782008-01-24 19:38:38 +0100644 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200645}
646
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700647static 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;
Johannes Berg8318d782008-01-24 19:38:38 +0100654 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700655
656 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100657
Johannes Berg380a9422008-04-04 23:40:35 +0200658 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700659 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100660
661 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
662
Johannes Berg380a9422008-04-04 23:40:35 +0200663 rcu_read_lock();
664
665 sta = sta_info_get(local, sdata->u.sta.bssid);
666
667 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100668 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700669 else
670 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200671
672 rcu_read_unlock();
673
674 if (!sta)
675 return -ENODEV;
676
Johannes Berg8318d782008-01-24 19:38:38 +0100677 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100678
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700679 return 0;
680}
681
Michael Buesch61609bc2007-09-20 22:06:39 +0200682static 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;
Johannes Berg8318d782008-01-24 19:38:38 +0100688 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200689
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;
Michael Buesch61609bc2007-09-20 22:06:39 +0200694
Mattias Nissler6a432952007-10-24 23:30:36 +0200695 if (data->txpower.fixed) {
696 new_power_level = data->txpower.value;
697 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100698 /*
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;
Mattias Nissler6a432952007-10-24 23:30:36 +0200703 if (!chan)
704 return -EINVAL;
705
Johannes Berg8318d782008-01-24 19:38:38 +0100706 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200707 }
708
709 if (local->hw.conf.power_level != new_power_level) {
710 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200711 need_reconfig = 1;
712 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200713
Michael Buesch61609bc2007-09-20 22:06:39 +0200714 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
715 local->hw.conf.radio_enabled = !(data->txpower.disabled);
716 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100717 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200718 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200719
Michael Buesch61609bc2007-09-20 22:06:39 +0200720 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
Larry Fingerfe6aa302007-08-10 11:23:20 -0500730static 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
Jiri Bencf0706e82007-05-05 11:45:53 -0700744static 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;
Emmanuel Grumbachfa6adfe2008-06-24 13:37:58 +0300752 else if (!rts->fixed)
753 /* if the rts value is not fixed, then take default */
754 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700755 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
770static 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
784static 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;
Emmanuel Grumbache4abd4d2008-07-03 18:02:27 +0300792 else if (!frag->fixed)
793 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
Jiri Bencf0706e82007-05-05 11:45:53 -0700794 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
813static 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
827static 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
857static 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
Jiri Bencf0706e82007-05-05 11:45:53 -0700881static 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);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100889 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
890 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700891 return -EINVAL;
892
893 switch (mlme->cmd) {
894 case IW_MLME_DEAUTH:
895 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200896 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700897 case IW_MLME_DISASSOC:
898 /* TODO: mlme->addr.sa_data */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200899 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -0700900 default:
901 return -EOPNOTSUPP;
902 }
903}
904
905
906static 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 };
Johannes Berg628a1402007-09-26 17:53:17 +0200913 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700914
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)
Johannes Berg628a1402007-09-26 17:53:17 +0200932 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700933 else if (erq->length == 0) {
934 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400935 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700936 return 0;
937 }
938
939 return ieee80211_set_encryption(
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200940 sdata, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200941 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700942 !sdata->default_key,
943 keybuf, erq->length);
944}
945
946
947static 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
Johannes Berg8f20fc22007-08-28 17:01:54 -0400980 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400981 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400982 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700983 erq->flags |= IW_ENCODE_ENABLED;
984
Emmanuel Grumbachb9fcc4f2008-06-24 13:37:59 +0300985 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
Jiri Bencf0706e82007-05-05 11:45:53 -0700998 return 0;
999}
1000
Samuel Ortiz49292d52008-07-04 10:49:31 +02001001static 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
1027static 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
Jiri Bencf0706e82007-05-05 11:45:53 -07001040static int ieee80211_ioctl_siwauth(struct net_device *dev,
1041 struct iw_request_info *info,
1042 struct iw_param *data, char *extra)
1043{
Jiri Bencf0706e82007-05-05 11:45:53 -07001044 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:
Jiri Bencf0706e82007-05-05 11:45:53 -07001053 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001054 break;
Johannes Bergb1357a82007-11-28 11:04:21 +01001055 case IW_AUTH_DROP_UNENCRYPTED:
1056 sdata->drop_unencrypted = !!data->value;
1057 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001058 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001059 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -07001060 ret = -EINVAL;
1061 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001062 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001063 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001064 * Privacy invoked by wpa_supplicant, store the
1065 * value and allow associating to a protected
1066 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -07001067 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001068 if (data->value)
1069 sdata->u.sta.flags |=
1070 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001071 }
1072 break;
1073 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001074 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1075 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001076 sdata->u.sta.auth_algs = data->value;
1077 else
1078 ret = -EOPNOTSUPP;
1079 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001080 default:
1081 ret = -EOPNOTSUPP;
1082 break;
1083 }
1084 return ret;
1085}
1086
1087/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
1088static 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
Johannes Berg98dd6a52008-04-10 15:36:09 +02001095 rcu_read_lock();
1096
Johannes Berg51fb61e2007-12-19 01:31:27 +01001097 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1098 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001099 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 {
Bruno Randolf566bfe52008-05-08 19:15:40 +02001108 wstats->qual.level = sta->last_signal;
1109 wstats->qual.qual = sta->last_qual;
Jiri Bencf0706e82007-05-05 11:45:53 -07001110 wstats->qual.noise = sta->last_noise;
1111 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001112 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001113
1114 rcu_read_unlock();
1115
Jiri Bencf0706e82007-05-05 11:45:53 -07001116 return wstats;
1117}
1118
1119static 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:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001128 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1129 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001130 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
1142static 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;
Johannes Berg628a1402007-09-26 17:53:17 +02001148 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001149
1150 switch (ext->alg) {
1151 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001152 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001153 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)
Johannes Berg628a1402007-09-26 17:53:17 +02001168 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001169
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
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001186 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001187 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001188 ext->ext_flags &
1189 IW_ENCODE_EXT_SET_TX_KEY,
1190 ext->key, ext->key_len);
1191}
1192
1193
Jiri Bencf0706e82007-05-05 11:45:53 -07001194/* Structures to export the Wireless Handlers */
1195
1196static 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 */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001214 (iw_handler) NULL, /* SIOCSIWSPY */
1215 (iw_handler) NULL, /* SIOCGIWSPY */
1216 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1217 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001218 (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 -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001230 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001231 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001232 (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 */
Michael Buesch61609bc2007-09-20 22:06:39 +02001236 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001237 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001238 (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 */
Samuel Ortiz49292d52008-07-04 10:49:31 +02001242 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1243 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
Jiri Bencf0706e82007-05-05 11:45:53 -07001244 (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
Jiri Bencf0706e82007-05-05 11:45:53 -07001256const struct iw_handler_def ieee80211_iw_handler_def =
1257{
1258 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001259 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001260 .get_wireless_stats = ieee80211_get_wireless_stats,
1261};