]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/wireless/wext-compat.c
wext: fix get_wireless_stats locking
[net-next-2.6.git] / net / wireless / wext-compat.c
CommitLineData
fee52678
JB
1/*
2 * cfg80211 - wext compat code
3 *
4 * This is temporary code until all wireless functionality is migrated
5 * into cfg80211, when that happens all the exports here go away and
6 * we directly assign the wireless handlers of wireless interfaces.
7 *
8 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
9 */
10
11#include <linux/wireless.h>
12#include <linux/nl80211.h>
691597cb 13#include <linux/if_arp.h>
fee52678 14#include <net/iw_handler.h>
fee52678
JB
15#include <net/cfg80211.h>
16#include "core.h"
17
18int cfg80211_wext_giwname(struct net_device *dev,
19 struct iw_request_info *info,
20 char *name, char *extra)
21{
22 struct wireless_dev *wdev = dev->ieee80211_ptr;
23 struct ieee80211_supported_band *sband;
24 bool is_ht = false, is_a = false, is_b = false, is_g = false;
25
26 if (!wdev)
27 return -EOPNOTSUPP;
28
29 sband = wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
30 if (sband) {
31 is_a = true;
32 is_ht |= sband->ht_cap.ht_supported;
33 }
34
35 sband = wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
36 if (sband) {
37 int i;
38 /* Check for mandatory rates */
39 for (i = 0; i < sband->n_bitrates; i++) {
40 if (sband->bitrates[i].bitrate == 10)
41 is_b = true;
42 if (sband->bitrates[i].bitrate == 60)
43 is_g = true;
44 }
45 is_ht |= sband->ht_cap.ht_supported;
46 }
47
48 strcpy(name, "IEEE 802.11");
49 if (is_a)
50 strcat(name, "a");
51 if (is_b)
52 strcat(name, "b");
53 if (is_g)
54 strcat(name, "g");
55 if (is_ht)
56 strcat(name, "n");
57
58 return 0;
59}
ba44cb72 60EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
e60c7744
JB
61
62int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
63 u32 *mode, char *extra)
64{
65 struct wireless_dev *wdev = dev->ieee80211_ptr;
66 struct cfg80211_registered_device *rdev;
67 struct vif_params vifparams;
68 enum nl80211_iftype type;
ac7f9cfa 69 int ret;
e60c7744
JB
70
71 if (!wdev)
72 return -EOPNOTSUPP;
73
74 rdev = wiphy_to_dev(wdev->wiphy);
75
76 if (!rdev->ops->change_virtual_intf)
77 return -EOPNOTSUPP;
78
79 /* don't support changing VLANs, you just re-create them */
80 if (wdev->iftype == NL80211_IFTYPE_AP_VLAN)
81 return -EOPNOTSUPP;
82
83 switch (*mode) {
84 case IW_MODE_INFRA:
85 type = NL80211_IFTYPE_STATION;
86 break;
87 case IW_MODE_ADHOC:
88 type = NL80211_IFTYPE_ADHOC;
89 break;
90 case IW_MODE_REPEAT:
91 type = NL80211_IFTYPE_WDS;
92 break;
93 case IW_MODE_MONITOR:
94 type = NL80211_IFTYPE_MONITOR;
95 break;
96 default:
97 return -EINVAL;
98 }
99
ac7f9cfa
JB
100 if (type == wdev->iftype)
101 return 0;
102
e60c7744
JB
103 memset(&vifparams, 0, sizeof(vifparams));
104
ac7f9cfa
JB
105 ret = rdev->ops->change_virtual_intf(wdev->wiphy, dev->ifindex, type,
106 NULL, &vifparams);
107 WARN_ON(!ret && wdev->iftype != type);
108
109 return ret;
e60c7744 110}
ba44cb72 111EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
e60c7744
JB
112
113int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
114 u32 *mode, char *extra)
115{
116 struct wireless_dev *wdev = dev->ieee80211_ptr;
117
118 if (!wdev)
119 return -EOPNOTSUPP;
120
121 switch (wdev->iftype) {
122 case NL80211_IFTYPE_AP:
123 *mode = IW_MODE_MASTER;
124 break;
125 case NL80211_IFTYPE_STATION:
126 *mode = IW_MODE_INFRA;
127 break;
128 case NL80211_IFTYPE_ADHOC:
129 *mode = IW_MODE_ADHOC;
130 break;
131 case NL80211_IFTYPE_MONITOR:
132 *mode = IW_MODE_MONITOR;
133 break;
134 case NL80211_IFTYPE_WDS:
135 *mode = IW_MODE_REPEAT;
136 break;
137 case NL80211_IFTYPE_AP_VLAN:
138 *mode = IW_MODE_SECOND; /* FIXME */
139 break;
140 default:
141 *mode = IW_MODE_AUTO;
142 break;
143 }
144 return 0;
145}
ba44cb72 146EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
4aa188e1
JB
147
148
149int cfg80211_wext_giwrange(struct net_device *dev,
150 struct iw_request_info *info,
151 struct iw_point *data, char *extra)
152{
153 struct wireless_dev *wdev = dev->ieee80211_ptr;
154 struct iw_range *range = (struct iw_range *) extra;
155 enum ieee80211_band band;
156 int c = 0;
157
158 if (!wdev)
159 return -EOPNOTSUPP;
160
161 data->length = sizeof(struct iw_range);
162 memset(range, 0, sizeof(struct iw_range));
163
164 range->we_version_compiled = WIRELESS_EXT;
165 range->we_version_source = 21;
166 range->retry_capa = IW_RETRY_LIMIT;
167 range->retry_flags = IW_RETRY_LIMIT;
168 range->min_retry = 0;
169 range->max_retry = 255;
170 range->min_rts = 0;
171 range->max_rts = 2347;
172 range->min_frag = 256;
173 range->max_frag = 2346;
174
175 range->encoding_size[0] = 5;
176 range->encoding_size[1] = 13;
177 range->num_encoding_sizes = 2;
178 range->max_encoding_tokens = 4;
179
180 range->max_qual.updated = IW_QUAL_NOISE_INVALID;
181
182 switch (wdev->wiphy->signal_type) {
183 case CFG80211_SIGNAL_TYPE_NONE:
184 break;
185 case CFG80211_SIGNAL_TYPE_MBM:
186 range->max_qual.level = -110;
187 range->max_qual.qual = 70;
188 range->avg_qual.qual = 35;
189 range->max_qual.updated |= IW_QUAL_DBM;
190 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
191 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
192 break;
193 case CFG80211_SIGNAL_TYPE_UNSPEC:
194 range->max_qual.level = 100;
195 range->max_qual.qual = 100;
196 range->avg_qual.qual = 50;
197 range->max_qual.updated |= IW_QUAL_QUAL_UPDATED;
198 range->max_qual.updated |= IW_QUAL_LEVEL_UPDATED;
199 break;
200 }
201
202 range->avg_qual.level = range->max_qual.level / 2;
203 range->avg_qual.noise = range->max_qual.noise / 2;
204 range->avg_qual.updated = range->max_qual.updated;
205
206 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
207 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
208
4aa188e1
JB
209 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
210 int i;
211 struct ieee80211_supported_band *sband;
212
213 sband = wdev->wiphy->bands[band];
214
215 if (!sband)
216 continue;
217
218 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
219 struct ieee80211_channel *chan = &sband->channels[i];
220
221 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
222 range->freq[c].i =
223 ieee80211_frequency_to_channel(
224 chan->center_freq);
225 range->freq[c].m = chan->center_freq;
226 range->freq[c].e = 6;
227 c++;
228 }
229 }
230 }
231 range->num_channels = c;
232 range->num_frequency = c;
233
234 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
235 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
236 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
237
238 range->scan_capa |= IW_SCAN_CAPA_ESSID;
239
240 return 0;
241}
ba44cb72 242EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
691597cb
JB
243
244int cfg80211_wext_siwmlme(struct net_device *dev,
245 struct iw_request_info *info,
246 struct iw_point *data, char *extra)
247{
248 struct wireless_dev *wdev = dev->ieee80211_ptr;
249 struct iw_mlme *mlme = (struct iw_mlme *)extra;
250 struct cfg80211_registered_device *rdev;
251 union {
252 struct cfg80211_disassoc_request disassoc;
253 struct cfg80211_deauth_request deauth;
254 } cmd;
255
256 if (!wdev)
257 return -EOPNOTSUPP;
258
259 rdev = wiphy_to_dev(wdev->wiphy);
260
261 if (wdev->iftype != NL80211_IFTYPE_STATION)
262 return -EINVAL;
263
264 if (mlme->addr.sa_family != ARPHRD_ETHER)
265 return -EINVAL;
266
267 memset(&cmd, 0, sizeof(cmd));
268
269 switch (mlme->cmd) {
270 case IW_MLME_DEAUTH:
271 if (!rdev->ops->deauth)
272 return -EOPNOTSUPP;
273 cmd.deauth.peer_addr = mlme->addr.sa_data;
274 cmd.deauth.reason_code = mlme->reason_code;
275 return rdev->ops->deauth(wdev->wiphy, dev, &cmd.deauth);
276 case IW_MLME_DISASSOC:
277 if (!rdev->ops->disassoc)
278 return -EOPNOTSUPP;
279 cmd.disassoc.peer_addr = mlme->addr.sa_data;
280 cmd.disassoc.reason_code = mlme->reason_code;
281 return rdev->ops->disassoc(wdev->wiphy, dev, &cmd.disassoc);
282 default:
283 return -EOPNOTSUPP;
284 }
285}
ba44cb72 286EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme);
04a773ad
JB
287
288
289/**
290 * cfg80211_wext_freq - get wext frequency for non-"auto"
291 * @wiphy: the wiphy
292 * @freq: the wext freq encoding
293 *
294 * Returns a channel, %NULL for auto, or an ERR_PTR for errors!
295 */
296struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy,
297 struct iw_freq *freq)
298{
0b258582
JB
299 struct ieee80211_channel *chan;
300 int f;
301
302 /*
303 * Parse frequency - return NULL for auto and
304 * -EINVAL for impossible things.
305 */
04a773ad
JB
306 if (freq->e == 0) {
307 if (freq->m < 0)
308 return NULL;
0b258582 309 f = ieee80211_channel_to_frequency(freq->m);
04a773ad
JB
310 } else {
311 int i, div = 1000000;
312 for (i = 0; i < freq->e; i++)
313 div /= 10;
0b258582 314 if (div <= 0)
04a773ad 315 return ERR_PTR(-EINVAL);
0b258582 316 f = freq->m / div;
04a773ad
JB
317 }
318
0b258582
JB
319 /*
320 * Look up channel struct and return -EINVAL when
321 * it cannot be found.
322 */
323 chan = ieee80211_get_channel(wiphy, f);
324 if (!chan)
325 return ERR_PTR(-EINVAL);
326 return chan;
04a773ad 327}
ba44cb72 328EXPORT_SYMBOL_GPL(cfg80211_wext_freq);
b9a5f8ca
JM
329
330int cfg80211_wext_siwrts(struct net_device *dev,
331 struct iw_request_info *info,
332 struct iw_param *rts, char *extra)
333{
334 struct wireless_dev *wdev = dev->ieee80211_ptr;
335 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
336 u32 orts = wdev->wiphy->rts_threshold;
337 int err;
338
339 if (rts->disabled || !rts->fixed)
340 wdev->wiphy->rts_threshold = (u32) -1;
341 else if (rts->value < 0)
342 return -EINVAL;
343 else
344 wdev->wiphy->rts_threshold = rts->value;
345
346 err = rdev->ops->set_wiphy_params(wdev->wiphy,
347 WIPHY_PARAM_RTS_THRESHOLD);
348 if (err)
349 wdev->wiphy->rts_threshold = orts;
350
351 return err;
352}
ba44cb72 353EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
b9a5f8ca
JM
354
355int cfg80211_wext_giwrts(struct net_device *dev,
356 struct iw_request_info *info,
357 struct iw_param *rts, char *extra)
358{
359 struct wireless_dev *wdev = dev->ieee80211_ptr;
360
361 rts->value = wdev->wiphy->rts_threshold;
362 rts->disabled = rts->value == (u32) -1;
363 rts->fixed = 1;
364
365 return 0;
366}
ba44cb72 367EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
b9a5f8ca
JM
368
369int cfg80211_wext_siwfrag(struct net_device *dev,
370 struct iw_request_info *info,
371 struct iw_param *frag, char *extra)
372{
373 struct wireless_dev *wdev = dev->ieee80211_ptr;
374 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
375 u32 ofrag = wdev->wiphy->frag_threshold;
376 int err;
377
378 if (frag->disabled || !frag->fixed)
379 wdev->wiphy->frag_threshold = (u32) -1;
380 else if (frag->value < 256)
381 return -EINVAL;
382 else {
383 /* Fragment length must be even, so strip LSB. */
384 wdev->wiphy->frag_threshold = frag->value & ~0x1;
385 }
386
387 err = rdev->ops->set_wiphy_params(wdev->wiphy,
388 WIPHY_PARAM_FRAG_THRESHOLD);
389 if (err)
390 wdev->wiphy->frag_threshold = ofrag;
391
392 return err;
393}
ba44cb72 394EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
b9a5f8ca
JM
395
396int cfg80211_wext_giwfrag(struct net_device *dev,
397 struct iw_request_info *info,
398 struct iw_param *frag, char *extra)
399{
400 struct wireless_dev *wdev = dev->ieee80211_ptr;
401
402 frag->value = wdev->wiphy->frag_threshold;
403 frag->disabled = frag->value == (u32) -1;
404 frag->fixed = 1;
405
406 return 0;
407}
ba44cb72 408EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
b9a5f8ca
JM
409
410int cfg80211_wext_siwretry(struct net_device *dev,
411 struct iw_request_info *info,
412 struct iw_param *retry, char *extra)
413{
414 struct wireless_dev *wdev = dev->ieee80211_ptr;
415 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
416 u32 changed = 0;
417 u8 olong = wdev->wiphy->retry_long;
418 u8 oshort = wdev->wiphy->retry_short;
419 int err;
420
421 if (retry->disabled ||
422 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
423 return -EINVAL;
424
425 if (retry->flags & IW_RETRY_LONG) {
426 wdev->wiphy->retry_long = retry->value;
427 changed |= WIPHY_PARAM_RETRY_LONG;
428 } else if (retry->flags & IW_RETRY_SHORT) {
429 wdev->wiphy->retry_short = retry->value;
430 changed |= WIPHY_PARAM_RETRY_SHORT;
431 } else {
432 wdev->wiphy->retry_short = retry->value;
433 wdev->wiphy->retry_long = retry->value;
434 changed |= WIPHY_PARAM_RETRY_LONG;
435 changed |= WIPHY_PARAM_RETRY_SHORT;
436 }
437
438 if (!changed)
439 return 0;
440
441 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
442 if (err) {
443 wdev->wiphy->retry_short = oshort;
444 wdev->wiphy->retry_long = olong;
445 }
446
447 return err;
448}
ba44cb72 449EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
b9a5f8ca
JM
450
451int cfg80211_wext_giwretry(struct net_device *dev,
452 struct iw_request_info *info,
453 struct iw_param *retry, char *extra)
454{
455 struct wireless_dev *wdev = dev->ieee80211_ptr;
456
457 retry->disabled = 0;
458
459 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
460 /*
461 * First return short value, iwconfig will ask long value
462 * later if needed
463 */
464 retry->flags |= IW_RETRY_LIMIT;
465 retry->value = wdev->wiphy->retry_short;
466 if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
467 retry->flags |= IW_RETRY_LONG;
468
469 return 0;
470 }
471
472 if (retry->flags & IW_RETRY_LONG) {
473 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
474 retry->value = wdev->wiphy->retry_long;
475 }
476
477 return 0;
478}
ba44cb72 479EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);