some additions to the ar7 system code, added cpmac network driver
[openwrt.git] / openwrt / target / linux / package / wlcompat / wlcompat.c
1 /*
2 * wlcompat.c
3 *
4 * Copyright (C) 2005 Mike Baker,
5 * Felix Fietkau <nbd@vd-s.ath.cx>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * $Id$
22 */
23
24
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/if_arp.h>
29 #include <asm/uaccess.h>
30 #include <linux/wireless.h>
31
32 #include <net/iw_handler.h>
33 #include <wlioctl.h>
34 #include <wlcompat.h>
35
36 static struct net_device *dev;
37 char buf[WLC_IOCTL_MAXLEN];
38
39 /* The frequency of each channel in MHz */
40 const long channel_frequency[] = {
41 2412, 2417, 2422, 2427, 2432, 2437, 2442,
42 2447, 2452, 2457, 2462, 2467, 2472, 2484
43 };
44 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
45
46 typedef struct internal_wsec_key {
47 uint8 index; // 0x00
48 uint8 unknown_1; // 0x01
49 uint8 type; // 0x02
50 uint8 unknown_2[7]; // 0x03
51 uint8 len; // 0x0a
52 uint8 pad[3];
53 char data[32]; // 0x0e
54 } wkey;
55
56
57 static int wlcompat_private_ioctl(struct net_device *dev,
58 struct iw_request_info *info,
59 union iwreq_data *wrqu,
60 char *extra);
61 #ifdef DEBUG
62 void print_buffer(int len, unsigned char *buf);
63 #endif
64
65 static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
66 {
67 mm_segment_t old_fs = get_fs();
68 struct ifreq ifr;
69 int ret;
70 wl_ioctl_t ioc;
71 ioc.cmd = cmd;
72 ioc.buf = buf;
73 ioc.len = len;
74 strncpy(ifr.ifr_name, dev->name, IFNAMSIZ);
75 ifr.ifr_data = (caddr_t) &ioc;
76 set_fs(KERNEL_DS);
77 ret = dev->do_ioctl(dev,&ifr,SIOCDEVPRIVATE);
78 set_fs (old_fs);
79 return ret;
80 }
81
82 static int wl_set_val(struct net_device *dev, char *var, void *val, int len)
83 {
84 char buf[128];
85 int buf_len;
86 int ret;
87
88 /* check for overflow */
89 if ((buf_len = strlen(var)) + 1 + len > sizeof(buf))
90 return -1;
91
92 strcpy(buf, var);
93 buf_len += 1;
94
95 /* append int value onto the end of the name string */
96 memcpy(&(buf[buf_len]), val, len);
97 buf_len += len;
98
99 ret = wl_ioctl(dev, WLC_SET_VAR, buf, buf_len);
100 return ret;
101 }
102
103 static int wl_get_val(struct net_device *dev, char *var, void *val, int len)
104 {
105 char buf[128];
106 int buf_len;
107 int ret;
108
109 /* check for overflow */
110 if ((buf_len = strlen(var)) + 1 > sizeof(buf) || len > sizeof(buf))
111 return -1;
112
113 strcpy(buf, var);
114 if (ret = wl_ioctl(dev, WLC_GET_VAR, buf, buf_len + len))
115 return ret;
116
117 memcpy(val, buf, len);
118 return 0;
119 }
120
121 int get_primary_key(struct net_device *dev)
122 {
123 int key, val;
124
125 for (key = val = 0; (key < 4) && (val == 0); key++) {
126 val = key;
127 if (wl_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val)) < 0)
128 return -EINVAL;
129 }
130 return key;
131 }
132
133
134 static int wlcompat_ioctl_getiwrange(struct net_device *dev,
135 char *extra)
136 {
137 int i, k;
138 struct iw_range *range;
139
140 range = (struct iw_range *) extra;
141
142 range->we_version_compiled = WIRELESS_EXT;
143 range->we_version_source = WIRELESS_EXT;
144
145 range->min_nwid = range->max_nwid = 0;
146
147 range->num_channels = NUM_CHANNELS;
148 k = 0;
149 for (i = 0; i < NUM_CHANNELS; i++) {
150 range->freq[k].i = i + 1;
151 range->freq[k].m = channel_frequency[i] * 100000;
152 range->freq[k].e = 1;
153 k++;
154 if (k >= IW_MAX_FREQUENCIES)
155 break;
156 }
157 range->num_frequency = k;
158 range->sensitivity = 3;
159
160 /* nbd: don't know what this means, but other drivers set it this way */
161 range->pmp_flags = IW_POWER_PERIOD;
162 range->pmt_flags = IW_POWER_TIMEOUT;
163 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
164
165 range->min_pmp = 0;
166 range->max_pmp = 65535000;
167 range->min_pmt = 0;
168 range->max_pmt = 65535 * 1000;
169
170 range->min_rts = 0;
171 if (wl_ioctl(dev, WLC_GET_RTS, &range->max_rts, sizeof(int)) < 0)
172 range->max_rts = 2347;
173
174 range->min_frag = 256;
175
176 if (wl_ioctl(dev, WLC_GET_FRAG, &range->max_frag, sizeof(int)) < 0)
177 range->max_frag = 2346;
178
179 range->txpower_capa = IW_TXPOW_DBM;
180
181 return 0;
182 }
183
184
185 static int wlcompat_set_scan(struct net_device *dev,
186 struct iw_request_info *info,
187 union iwreq_data *wrqu,
188 char *extra)
189 {
190 int ap = 0, oldap = 0;
191 wl_scan_params_t params;
192
193 memset(&params, 0, sizeof(params));
194
195 /* use defaults (same parameters as wl scan) */
196 memset(&params.bssid, 0xff, sizeof(params.bssid));
197 params.bss_type = DOT11_BSSTYPE_ANY;
198 params.scan_type = -1;
199 params.nprobes = -1;
200 params.active_time = -1;
201 params.passive_time = -1;
202 params.home_time = -1;
203
204 /* can only scan in STA mode */
205 wl_ioctl(dev, WLC_GET_AP, &oldap, sizeof(oldap));
206 if (oldap > 0)
207 wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap));
208
209 if (wl_ioctl(dev, WLC_SCAN, &params, 64) < 0)
210 return -EINVAL;
211
212 if (oldap > 0)
213 wl_ioctl(dev, WLC_SET_AP, &oldap, sizeof(oldap));
214
215 return 0;
216 }
217
218
219 static int wlcompat_get_scan(struct net_device *dev,
220 struct iw_request_info *info,
221 union iwreq_data *wrqu,
222 char *extra)
223 {
224 wl_scan_results_t *results = (wl_scan_results_t *) buf;
225 wl_bss_info_t *bss_info;
226 char *info_ptr;
227 char *current_ev = extra;
228 char *current_val;
229 char *end_buf = extra + IW_SCAN_MAX_DATA;
230 struct iw_event iwe;
231 int i, j;
232
233 if (wl_ioctl(dev, WLC_SCAN_RESULTS, buf, WLC_IOCTL_MAXLEN) < 0)
234 return -EAGAIN;
235
236 bss_info = &(results->bss_info[0]);
237 info_ptr = (char *) bss_info;
238 for (i = 0; i < results->count; i++) {
239
240 /* send the cell address (must be sent first) */
241 iwe.cmd = SIOCGIWAP;
242 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
243 memcpy(&iwe.u.ap_addr.sa_data, &bss_info->BSSID, sizeof(bss_info->BSSID));
244 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
245
246 /* send the ESSID */
247 iwe.cmd = SIOCGIWESSID;
248 iwe.u.data.length = bss_info->SSID_len;
249 if (iwe.u.data.length > IW_ESSID_MAX_SIZE)
250 iwe.u.data.length = IW_ESSID_MAX_SIZE;
251 iwe.u.data.flags = 1;
252 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss_info->SSID);
253
254 /* send frequency/channel info */
255 iwe.cmd = SIOCGIWFREQ;
256 iwe.u.freq.e = 0;
257 iwe.u.freq.m = bss_info->channel;
258 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
259
260 /* add quality statistics */
261 iwe.cmd = IWEVQUAL;
262 iwe.u.qual.level = bss_info->RSSI;
263 iwe.u.qual.noise = bss_info->phy_noise;
264 iwe.u.qual.qual = 0;
265 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
266
267 /* send rate information */
268 iwe.cmd = SIOCGIWRATE;
269 current_val = current_ev + IW_EV_LCP_LEN;
270 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
271
272 for(j = 0 ; j < bss_info->rateset.count ; j++) {
273 iwe.u.bitrate.value = ((bss_info->rateset.rates[j] & 0x7f) * 500000);
274 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
275 }
276 if((current_val - current_ev) > IW_EV_LCP_LEN)
277 current_ev = current_val;
278
279 info_ptr += sizeof(wl_bss_info_t);
280 if (bss_info->ie_length % 4)
281 info_ptr += bss_info->ie_length + 4 - (bss_info->ie_length % 4);
282 else
283 info_ptr += bss_info->ie_length;
284 bss_info = (wl_bss_info_t *) info_ptr;
285 }
286
287 wrqu->data.length = (current_ev - extra);
288 wrqu->data.flags = 0;
289
290 return 0;
291 }
292
293 static int wlcompat_ioctl(struct net_device *dev,
294 struct iw_request_info *info,
295 union iwreq_data *wrqu,
296 char *extra)
297 {
298 switch (info->cmd) {
299 case SIOCGIWNAME:
300 strcpy(wrqu->name, "IEEE 802.11-DS");
301 break;
302 case SIOCGIWFREQ:
303 {
304 channel_info_t ci;
305
306 if (wl_ioctl(dev,WLC_GET_CHANNEL, &ci, sizeof(ci)) < 0)
307 return -EINVAL;
308
309 wrqu->freq.m = ci.target_channel;
310 wrqu->freq.e = 0;
311 break;
312 }
313 case SIOCSIWFREQ:
314 {
315 if (wrqu->freq.m == -1) {
316 wrqu->freq.m = 0;
317 if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
318 return -EINVAL;
319 } else {
320 if (wrqu->freq.e == 1) {
321 int channel = 0;
322 int f = wrqu->freq.m / 100000;
323 while ((channel < NUM_CHANNELS + 1) && (f != channel_frequency[channel]))
324 channel++;
325
326 if (channel == NUM_CHANNELS) // channel not found
327 return -EINVAL;
328
329 wrqu->freq.e = 0;
330 wrqu->freq.m = channel + 1;
331 }
332 if ((wrqu->freq.e == 0) && (wrqu->freq.m < 1000)) {
333 if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
334 return -EINVAL;
335 } else {
336 return -EINVAL;
337 }
338 }
339 break;
340 }
341 case SIOCSIWAP:
342 {
343 int ap = 0;
344
345 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
346 return -EINVAL;
347
348 if (wl_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)) < 0)
349 return -EINVAL;
350
351 if (wl_ioctl(dev, (ap ? WLC_SET_BSSID : WLC_REASSOC), wrqu->ap_addr.sa_data, 6) < 0)
352 return -EINVAL;
353
354 break;
355 }
356 case SIOCGIWAP:
357 {
358 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
359 if (wl_ioctl(dev,WLC_GET_BSSID,wrqu->ap_addr.sa_data,6) < 0)
360 return -EINVAL;
361 break;
362 }
363 case SIOCGIWESSID:
364 {
365 wlc_ssid_t ssid;
366
367 if (wl_ioctl(dev,WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t)) < 0)
368 return -EINVAL;
369
370 wrqu->essid.flags = wrqu->data.flags = 1;
371 wrqu->essid.length = wrqu->data.length = ssid.SSID_len + 1;
372 memcpy(extra,ssid.SSID,ssid.SSID_len + 1);
373 break;
374 }
375 case SIOCSIWESSID:
376 {
377 wlc_ssid_t ssid;
378 memset(&ssid, 0, sizeof(ssid));
379 ssid.SSID_len = strlen(extra);
380 if (ssid.SSID_len > WLC_ESSID_MAX_SIZE)
381 ssid.SSID_len = WLC_ESSID_MAX_SIZE;
382 memcpy(ssid.SSID, extra, ssid.SSID_len);
383 if (wl_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)) < 0)
384 return -EINVAL;
385 break;
386 }
387 case SIOCGIWRTS:
388 {
389 if (wl_ioctl(dev,WLC_GET_RTS,&(wrqu->rts.value),sizeof(int)) < 0)
390 return -EINVAL;
391 break;
392 }
393 case SIOCSIWRTS:
394 {
395 if (wl_ioctl(dev,WLC_SET_RTS,&(wrqu->rts.value),sizeof(int)) < 0)
396 return -EINVAL;
397 break;
398 }
399 case SIOCGIWFRAG:
400 {
401 if (wl_ioctl(dev,WLC_GET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
402 return -EINVAL;
403 break;
404 }
405 case SIOCSIWFRAG:
406 {
407 if (wl_ioctl(dev,WLC_SET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
408 return -EINVAL;
409 break;
410 }
411 case SIOCGIWTXPOW:
412 {
413 int radio;
414
415 if (wl_ioctl(dev, WLC_GET_RADIO, &radio, sizeof(int)) < 0)
416 return -EINVAL;
417
418 if (wl_get_val(dev, "qtxpower", &(wrqu->txpower.value), sizeof(int)) < 0)
419 return -EINVAL;
420
421 wrqu->txpower.value &= ~WL_TXPWR_OVERRIDE;
422 wrqu->txpower.value /= 4;
423
424 wrqu->txpower.fixed = 0;
425 wrqu->txpower.disabled = radio;
426 wrqu->txpower.flags = IW_TXPOW_DBM;
427 break;
428 }
429 case SIOCSIWTXPOW:
430 {
431 /* This is weird: WLC_SET_RADIO with 1 as argument disables the radio */
432 int radio = wrqu->txpower.disabled;
433
434 if (wl_ioctl(dev, WLC_SET_RADIO, &radio, sizeof(int)) < 0)
435 return -EINVAL;
436
437 if (!wrqu->txpower.disabled) {
438 int value;
439
440 if (wl_get_val(dev, "qtxpower", &value, sizeof(int)) < 0)
441 return -EINVAL;
442
443 value &= WL_TXPWR_OVERRIDE;
444 wrqu->txpower.value *= 4;
445 wrqu->txpower.value |= value;
446
447 if (wrqu->txpower.flags != IW_TXPOW_DBM)
448 return -EINVAL;
449
450 if (wrqu->txpower.value > 0)
451 if (wl_set_val(dev, "qtxpower", &(wrqu->txpower.value), sizeof(int)) < 0)
452 return -EINVAL;
453 }
454 break;
455 }
456 case SIOCSIWENCODE:
457 {
458 int val = 0, wep = 1, wrestrict = 1;
459 int index = (wrqu->data.flags & IW_ENCODE_INDEX) - 1;
460
461 if (index < 0)
462 index = get_primary_key(dev);
463
464 if (wrqu->data.flags & IW_ENCODE_DISABLED)
465 wep = 0;
466
467 if (wrqu->data.flags & IW_ENCODE_OPEN)
468 wrestrict = 0;
469
470 if (wrqu->data.pointer && (wrqu->data.length > 0) && (wrqu->data.length <= 16)) {
471 wl_wsec_key_t key;
472 memset(&key, 0, sizeof(key));
473
474 key.flags = WL_PRIMARY_KEY;
475 key.len = wrqu->data.length;
476 key.index = index;
477 memcpy(key.data, wrqu->data.pointer, wrqu->data.length);
478
479 if (wl_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)) < 0)
480 return -EINVAL;
481 }
482
483 if (index >= 0)
484 if (wl_ioctl(dev, WLC_SET_KEY_PRIMARY, &index, sizeof(index)) < 0)
485 return -EINVAL;
486
487 if (wl_ioctl(dev, WLC_GET_WSEC, &val, sizeof(val)) < 0)
488 return -EINVAL;
489 val |= wep;
490 if (wl_ioctl(dev, WLC_SET_WSEC, &val, sizeof(val)) < 0)
491 return -EINVAL;
492
493 if (wrestrict >= 0)
494 if (wl_ioctl(dev, WLC_SET_WEP_RESTRICT, &wrestrict, sizeof(wrestrict)) < 0)
495 return -EINVAL;
496 break;
497 }
498 case SIOCGIWENCODE:
499 {
500 int val;
501
502 if (wl_ioctl(dev, WLC_GET_WEP, &val, sizeof(val)) < 0)
503 return -EINVAL;
504
505
506 if (val > 0) {
507 int key = get_primary_key(dev);
508
509 wrqu->data.flags = IW_ENCODE_ENABLED;
510 if (key-- > 0) {
511 int *info_addr;
512 wkey *wep_key;
513
514 info_addr = (int *) dev->priv;
515 wep_key = (wkey *) ((*info_addr) + 0x2752 + (key * 0x110));
516
517 wrqu->data.flags |= key + 1;
518 wrqu->data.length = wep_key->len;
519
520 memset(extra, 0, 16);
521 memcpy(extra, wep_key->data, 16);
522 } else {
523 wrqu->data.flags |= IW_ENCODE_NOKEY;
524 }
525 } else {
526 wrqu->data.flags = IW_ENCODE_DISABLED;
527 }
528
529 break;
530 }
531 case SIOCGIWRANGE:
532 {
533 return wlcompat_ioctl_getiwrange(dev, extra);
534 break;
535 }
536 case SIOCSIWMODE:
537 {
538 int ap = -1, infra = -1, passive = 0, wet = 0;
539
540 switch (wrqu->mode) {
541 case IW_MODE_MONITOR:
542 passive = 1;
543 break;
544 case IW_MODE_ADHOC:
545 infra = 0;
546 ap = 0;
547 break;
548 case IW_MODE_MASTER:
549 infra = 1;
550 ap = 1;
551 break;
552 case IW_MODE_INFRA:
553 infra = 1;
554 ap = 0;
555 break;
556 case IW_MODE_REPEAT:
557 infra = 1;
558 ap = 0;
559 wet = 1;
560 break;
561
562 default:
563 return -EINVAL;
564 }
565
566 wl_ioctl(dev, WLC_SET_PASSIVE, &passive, sizeof(passive));
567 wl_ioctl(dev, WLC_SET_MONITOR, &passive, sizeof(passive));
568 wl_ioctl(dev, WLC_SET_WET, &wet, sizeof(wet));
569 if (ap >= 0)
570 wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap));
571 if (infra >= 0)
572 wl_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra));
573
574 break;
575
576 }
577 case SIOCGIWMODE:
578 {
579 int ap, infra, wet, passive;
580
581 if (wl_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)) < 0)
582 return -EINVAL;
583 if (wl_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra)) < 0)
584 return -EINVAL;
585 if (wl_ioctl(dev, WLC_GET_PASSIVE, &passive, sizeof(passive)) < 0)
586 return -EINVAL;
587 if (wl_ioctl(dev, WLC_GET_WET, &wet, sizeof(wet)) < 0)
588 return -EINVAL;
589
590 if (passive) {
591 wrqu->mode = IW_MODE_MONITOR;
592 } else if (!infra) {
593 wrqu->mode = IW_MODE_ADHOC;
594 } else {
595 if (ap) {
596 wrqu->mode = IW_MODE_MASTER;
597 } else {
598 if (wet) {
599 wrqu->mode = IW_MODE_REPEAT;
600 } else {
601 wrqu->mode = IW_MODE_INFRA;
602 }
603 }
604 }
605 break;
606 }
607 default:
608 {
609 if (info->cmd >= SIOCIWFIRSTPRIV)
610 return wlcompat_private_ioctl(dev, info, wrqu, extra);
611
612 return -EINVAL;
613 }
614 }
615
616 return 0;
617 }
618
619 static const iw_handler wlcompat_handler[] = {
620 NULL, /* SIOCSIWCOMMIT */
621 wlcompat_ioctl, /* SIOCGIWNAME */
622 NULL, /* SIOCSIWNWID */
623 NULL, /* SIOCGIWNWID */
624 wlcompat_ioctl, /* SIOCSIWFREQ */
625 wlcompat_ioctl, /* SIOCGIWFREQ */
626 wlcompat_ioctl, /* SIOCSIWMODE */
627 wlcompat_ioctl, /* SIOCGIWMODE */
628 NULL, /* SIOCSIWSENS */
629 NULL, /* SIOCGIWSENS */
630 NULL, /* SIOCSIWRANGE, unused */
631 wlcompat_ioctl, /* SIOCGIWRANGE */
632 NULL, /* SIOCSIWPRIV */
633 NULL, /* SIOCGIWPRIV */
634 NULL, /* SIOCSIWSTATS */
635 NULL, /* SIOCGIWSTATS */
636 iw_handler_set_spy, /* SIOCSIWSPY */
637 iw_handler_get_spy, /* SIOCGIWSPY */
638 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
639 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
640 wlcompat_ioctl, /* SIOCSIWAP */
641 wlcompat_ioctl, /* SIOCGIWAP */
642 NULL, /* -- hole -- */
643 NULL, /* SIOCGIWAPLIST */
644 wlcompat_set_scan, /* SIOCSIWSCAN */
645 wlcompat_get_scan, /* SIOCGIWSCAN */
646 wlcompat_ioctl, /* SIOCSIWESSID */
647 wlcompat_ioctl, /* SIOCGIWESSID */
648 NULL, /* SIOCSIWNICKN */
649 NULL, /* SIOCGIWNICKN */
650 NULL, /* -- hole -- */
651 NULL, /* -- hole -- */
652 NULL, /* SIOCSIWRATE */
653 NULL, /* SIOCGIWRATE */
654 wlcompat_ioctl, /* SIOCSIWRTS */
655 wlcompat_ioctl, /* SIOCGIWRTS */
656 wlcompat_ioctl, /* SIOCSIWFRAG */
657 wlcompat_ioctl, /* SIOCGIWFRAG */
658 wlcompat_ioctl, /* SIOCSIWTXPOW */
659 wlcompat_ioctl, /* SIOCGIWTXPOW */
660 NULL, /* SIOCSIWRETRY */
661 NULL, /* SIOCGIWRETRY */
662 wlcompat_ioctl, /* SIOCSIWENCODE */
663 wlcompat_ioctl, /* SIOCGIWENCODE */
664 };
665
666 static int wlcompat_private_ioctl(struct net_device *dev,
667 struct iw_request_info *info,
668 union iwreq_data *wrqu,
669 char *extra)
670 {
671 int *value = (int *) wrqu->name;
672
673 switch (info->cmd) {
674 case WLCOMPAT_SET_MONITOR:
675 {
676 if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0)
677 return -EINVAL;
678
679 break;
680 }
681 case WLCOMPAT_GET_MONITOR:
682 {
683 if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0)
684 return -EINVAL;
685
686 break;
687 }
688 case WLCOMPAT_SET_TXPWR_LIMIT:
689 {
690 int val;
691
692
693 if (wl_get_val(dev, "qtxpower", &val, sizeof(int)) < 0)
694 return -EINVAL;
695
696 if (*extra > 0)
697 val |= WL_TXPWR_OVERRIDE;
698 else
699 val &= ~WL_TXPWR_OVERRIDE;
700
701 if (wl_set_val(dev, "qtxpower", &val, sizeof(int)) < 0)
702 return -EINVAL;
703
704 break;
705 }
706 case WLCOMPAT_GET_TXPWR_LIMIT:
707 {
708 if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0)
709 return -EINVAL;
710
711 *value = ((*value & WL_TXPWR_OVERRIDE) == WL_TXPWR_OVERRIDE ? 1 : 0);
712
713 break;
714 }
715 case WLCOMPAT_SET_ANTDIV:
716 {
717 if (wl_ioctl(dev, WLC_SET_ANTDIV, value, sizeof(int)) < 0)
718 return -EINVAL;
719
720 break;
721 }
722 case WLCOMPAT_GET_ANTDIV:
723 {
724 if (wl_ioctl(dev, WLC_GET_ANTDIV, extra, sizeof(int)) < 0)
725 return -EINVAL;
726
727 break;
728 }
729 case WLCOMPAT_SET_TXANT:
730 {
731 if (wl_ioctl(dev, WLC_SET_TXANT, value, sizeof(int)) < 0)
732 return -EINVAL;
733
734 break;
735 }
736 case WLCOMPAT_GET_TXANT:
737 {
738 if (wl_ioctl(dev, WLC_GET_TXANT, extra, sizeof(int)) < 0)
739 return -EINVAL;
740
741 break;
742 }
743 default:
744 {
745 return -EINVAL;
746 }
747
748 }
749 return 0;
750 }
751
752 static const struct iw_priv_args wlcompat_private_args[] =
753 {
754 { WLCOMPAT_SET_MONITOR,
755 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
756 0,
757 "set_monitor"
758 },
759 { WLCOMPAT_GET_MONITOR,
760 0,
761 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
762 "get_monitor"
763 },
764 { WLCOMPAT_SET_TXPWR_LIMIT,
765 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
766 0,
767 "set_txpwr_force"
768 },
769 { WLCOMPAT_GET_TXPWR_LIMIT,
770 0,
771 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
772 "get_txpwr_force"
773 },
774 { WLCOMPAT_SET_ANTDIV,
775 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
776 0,
777 "set_antdiv"
778 },
779 { WLCOMPAT_GET_ANTDIV,
780 0,
781 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
782 "get_antdiv"
783 },
784 { WLCOMPAT_SET_TXANT,
785 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
786 0,
787 "set_txant"
788 },
789 { WLCOMPAT_GET_TXANT,
790 0,
791 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
792 "get_txant"
793 },
794 };
795
796 static const iw_handler wlcompat_private[] =
797 {
798 wlcompat_private_ioctl,
799 NULL
800 };
801
802
803 static const struct iw_handler_def wlcompat_handler_def =
804 {
805 .standard = (iw_handler *) wlcompat_handler,
806 .num_standard = sizeof(wlcompat_handler)/sizeof(iw_handler),
807 .private = wlcompat_private,
808 .num_private = 1,
809 .private_args = wlcompat_private_args,
810 .num_private_args = sizeof(wlcompat_private_args) / sizeof(wlcompat_private_args[0])
811 };
812
813
814 #ifdef DEBUG
815 void print_buffer(int len, unsigned char *buf) {
816 int x;
817 if (buf != NULL) {
818 for (x=0;x<len && x<180 ;x++) {
819 if ((x % 4) == 0)
820 printk(" ");
821 printk("%02X",buf[x]);
822 }
823 } else {
824 printk(" NULL");
825 }
826 printk("\n");
827
828 }
829 #endif
830 static int (*old_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
831 static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
832 int ret = 0;
833 struct iwreq *iwr = (struct iwreq *) ifr;
834 struct iw_request_info info;
835
836 #ifdef DEBUG
837 printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd);
838 #endif
839
840 if (cmd >= SIOCIWFIRSTPRIV) {
841 info.cmd = cmd;
842 info.flags = 0;
843 ret = wlcompat_private_ioctl(dev, &info, &(iwr->u), (char *) &(iwr->u));
844 #ifdef DEBUG
845 } else if (cmd==SIOCDEVPRIVATE) {
846 wl_ioctl_t *ioc = (wl_ioctl_t *)ifr->ifr_data;
847 unsigned char *buf = ioc->buf;
848 printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len);
849 printk(" send: ->");
850 print_buffer(ioc->len, buf);
851 ret = old_ioctl(dev,ifr,cmd);
852 printk(" recv: ->");
853 print_buffer(ioc->len, buf);
854 printk(" ret: %d\n", ret);
855 #endif
856 } else {
857 ret = old_ioctl(dev,ifr,cmd);
858 }
859 return ret;
860 }
861
862 static int __init wlcompat_init()
863 {
864 int found = 0, i;
865 char *devname = "eth0";
866
867 while (!found && (dev = dev_get_by_name(devname))) {
868 if ((dev->wireless_handlers == NULL) && ((wl_ioctl(dev, WLC_GET_MAGIC, &i, sizeof(i)) == 0) && i == WLC_IOCTL_MAGIC))
869 found = 1;
870 devname[3]++;
871 }
872
873 if (!found) {
874 printk("No Broadcom devices found.\n");
875 return -ENODEV;
876 }
877
878
879 old_ioctl = dev->do_ioctl;
880 dev->do_ioctl = new_ioctl;
881 dev->wireless_handlers = (struct iw_handler_def *)&wlcompat_handler_def;
882 #ifdef DEBUG
883 printk("broadcom driver private data: 0x%08x\n", dev->priv);
884 #endif
885 return 0;
886 }
887
888 static void __exit wlcompat_exit()
889 {
890 dev->wireless_handlers = NULL;
891 dev->do_ioctl = old_ioctl;
892 return;
893 }
894
895 EXPORT_NO_SYMBOLS;
896 MODULE_AUTHOR("openwrt.org");
897 MODULE_LICENSE("GPL");
898
899 module_init(wlcompat_init);
900 module_exit(wlcompat_exit);
This page took 0.089205 seconds and 5 git commands to generate.