add txant and antdiv to wlcompat
[openwrt.git] / package / openwrt / 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 static int wlcompat_private_ioctl(struct net_device *dev,
47 struct iw_request_info *info,
48 union iwreq_data *wrqu,
49 char *extra);
50
51 static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
52 {
53 mm_segment_t old_fs = get_fs();
54 struct ifreq ifr;
55 int ret;
56 wl_ioctl_t ioc;
57 ioc.cmd = cmd;
58 ioc.buf = buf;
59 ioc.len = len;
60 strncpy(ifr.ifr_name, dev->name, IFNAMSIZ);
61 ifr.ifr_data = (caddr_t) &ioc;
62 set_fs(KERNEL_DS);
63 ret = dev->do_ioctl(dev,&ifr,SIOCDEVPRIVATE);
64 set_fs (old_fs);
65 return ret;
66 }
67
68 static int wl_set_val(struct net_device *dev, char *var, void *val, int len)
69 {
70 char buf[128];
71 int buf_len;
72
73 /* check for overflow */
74 if ((buf_len = strlen(var)) + 1 + len > sizeof(buf))
75 return -1;
76
77 strcpy(buf, var);
78 buf_len += 1;
79
80 /* append int value onto the end of the name string */
81 memcpy(&buf[buf_len], val, len);
82 buf_len += len;
83
84 return wl_ioctl(dev, WLC_SET_VAR, buf, buf_len);
85 }
86
87 static int wl_get_val(struct net_device *dev, char *var, void *val, int len)
88 {
89 char buf[128];
90 int ret;
91
92 /* check for overflow */
93 if (strlen(var) + 1 > sizeof(buf) || len > sizeof(buf))
94 return -1;
95
96 strcpy(buf, var);
97 if ((ret = wl_ioctl(dev, WLC_GET_VAR, buf, sizeof(buf))))
98 return ret;
99
100 memcpy(val, buf, len);
101 return 0;
102 }
103
104
105 static int wlcompat_ioctl_getiwrange(struct net_device *dev,
106 char *extra)
107 {
108 int i, k;
109 struct iw_range *range;
110
111 range = (struct iw_range *) extra;
112
113 range->we_version_compiled = WIRELESS_EXT;
114 range->we_version_source = WIRELESS_EXT;
115
116 range->min_nwid = range->max_nwid = 0;
117
118 range->num_channels = NUM_CHANNELS;
119 k = 0;
120 for (i = 0; i < NUM_CHANNELS; i++) {
121 range->freq[k].i = i + 1;
122 range->freq[k].m = channel_frequency[i] * 100000;
123 range->freq[k].e = 1;
124 k++;
125 if (k >= IW_MAX_FREQUENCIES)
126 break;
127 }
128 range->num_frequency = k;
129 range->sensitivity = 3;
130
131 /* nbd: don't know what this means, but other drivers set it this way */
132 range->pmp_flags = IW_POWER_PERIOD;
133 range->pmt_flags = IW_POWER_TIMEOUT;
134 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
135
136 range->min_pmp = 0;
137 range->max_pmp = 65535000;
138 range->min_pmt = 0;
139 range->max_pmt = 65535 * 1000;
140
141 range->min_rts = 0;
142 if (wl_ioctl(dev, WLC_GET_RTS, &range->max_rts, sizeof(int)) < 0)
143 range->max_rts = 2347;
144
145 range->min_frag = 256;
146
147 if (wl_ioctl(dev, WLC_GET_FRAG, &range->max_frag, sizeof(int)) < 0)
148 range->max_frag = 2346;
149
150 range->txpower_capa = IW_TXPOW_MWATT;
151
152 return 0;
153 }
154
155
156 static int wlcompat_set_scan(struct net_device *dev,
157 struct iw_request_info *info,
158 union iwreq_data *wrqu,
159 char *extra)
160 {
161 int ap = 0, oldap = 0;
162 wl_scan_params_t params;
163
164 memset(&params, 0, sizeof(params));
165
166 /* use defaults (same parameters as wl scan) */
167 memset(&params.bssid, 0xff, sizeof(params.bssid));
168 params.bss_type = DOT11_BSSTYPE_ANY;
169 params.scan_type = -1;
170 params.nprobes = -1;
171 params.active_time = -1;
172 params.passive_time = -1;
173 params.home_time = -1;
174
175 /* can only scan in STA mode */
176 wl_ioctl(dev, WLC_GET_AP, &oldap, sizeof(oldap));
177 if (oldap > 0)
178 wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap));
179
180 if (wl_ioctl(dev, WLC_SCAN, &params, 64) < 0)
181 return -EINVAL;
182
183 if (oldap > 0)
184 wl_ioctl(dev, WLC_SET_AP, &oldap, sizeof(oldap));
185
186 return 0;
187 }
188
189
190 static int wlcompat_get_scan(struct net_device *dev,
191 struct iw_request_info *info,
192 union iwreq_data *wrqu,
193 char *extra)
194 {
195 wl_scan_results_t *results = (wl_scan_results_t *) buf;
196 wl_bss_info_t *bss_info;
197 char *info_ptr;
198 char *current_ev = extra;
199 char *current_val;
200 char *end_buf = extra + IW_SCAN_MAX_DATA;
201 struct iw_event iwe;
202 int i, j;
203
204 if (wl_ioctl(dev, WLC_SCAN_RESULTS, buf, WLC_IOCTL_MAXLEN) < 0)
205 return -EAGAIN;
206
207 bss_info = &(results->bss_info[0]);
208 info_ptr = (char *) bss_info;
209 for (i = 0; i < results->count; i++) {
210
211 /* send the cell address (must be sent first) */
212 iwe.cmd = SIOCGIWAP;
213 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
214 memcpy(&iwe.u.ap_addr.sa_data, &bss_info->BSSID, sizeof(bss_info->BSSID));
215 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
216
217 /* send the ESSID */
218 iwe.cmd = SIOCGIWESSID;
219 iwe.u.data.length = bss_info->SSID_len;
220 if (iwe.u.data.length > IW_ESSID_MAX_SIZE)
221 iwe.u.data.length = IW_ESSID_MAX_SIZE;
222 iwe.u.data.flags = 1;
223 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss_info->SSID);
224
225 /* send frequency/channel info */
226 iwe.cmd = SIOCGIWFREQ;
227 iwe.u.freq.e = 0;
228 iwe.u.freq.m = bss_info->channel;
229 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
230
231 /* add quality statistics */
232 iwe.cmd = IWEVQUAL;
233 iwe.u.qual.level = bss_info->RSSI;
234 iwe.u.qual.noise = bss_info->phy_noise;
235 iwe.u.qual.qual = 0;
236 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
237
238 /* send rate information */
239 iwe.cmd = SIOCGIWRATE;
240 current_val = current_ev + IW_EV_LCP_LEN;
241 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
242
243 for(j = 0 ; j < bss_info->rateset.count ; j++) {
244 iwe.u.bitrate.value = ((bss_info->rateset.rates[j] & 0x7f) * 500000);
245 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
246 }
247 if((current_val - current_ev) > IW_EV_LCP_LEN)
248 current_ev = current_val;
249
250 info_ptr += sizeof(wl_bss_info_t);
251 if (bss_info->ie_length % 4)
252 info_ptr += bss_info->ie_length + 4 - (bss_info->ie_length % 4);
253 else
254 info_ptr += bss_info->ie_length;
255 bss_info = (wl_bss_info_t *) info_ptr;
256 }
257
258 wrqu->data.length = (current_ev - extra);
259 wrqu->data.flags = 0;
260
261 return 0;
262 }
263
264 static int wlcompat_ioctl(struct net_device *dev,
265 struct iw_request_info *info,
266 union iwreq_data *wrqu,
267 char *extra)
268 {
269 switch (info->cmd) {
270 case SIOCGIWNAME:
271 strcpy(wrqu->name, "IEEE 802.11-DS");
272 break;
273 case SIOCGIWFREQ:
274 {
275 channel_info_t ci;
276
277 if (wl_ioctl(dev,WLC_GET_CHANNEL, &ci, sizeof(ci)) < 0)
278 return -EINVAL;
279
280 wrqu->freq.m = ci.target_channel;
281 wrqu->freq.e = 0;
282 break;
283 }
284 case SIOCSIWFREQ:
285 {
286 if (wrqu->freq.e == 1) {
287 int channel = 0;
288 int f = wrqu->freq.m / 100000;
289 while ((channel < NUM_CHANNELS + 1) && (f != channel_frequency[channel]))
290 channel++;
291
292 if (channel == NUM_CHANNELS) // channel not found
293 return -EINVAL;
294
295 wrqu->freq.e = 0;
296 wrqu->freq.m = channel + 1;
297 }
298 if ((wrqu->freq.e == 0) && (wrqu->freq.m < 1000)) {
299 if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
300 return -EINVAL;
301 } else {
302 return -EINVAL;
303 }
304 break;
305 }
306 case SIOCSIWAP:
307 {
308 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
309 return -EINVAL;
310
311 if (wl_ioctl(dev,WLC_SET_BSSID,wrqu->ap_addr.sa_data,6) < 0)
312 return -EINVAL;
313
314 break;
315 }
316 case SIOCGIWAP:
317 {
318 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
319 if (wl_ioctl(dev,WLC_GET_BSSID,wrqu->ap_addr.sa_data,6) < 0)
320 return -EINVAL;
321 break;
322 }
323 case SIOCGIWESSID:
324 {
325 wlc_ssid_t ssid;
326
327 if (wl_ioctl(dev,WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t)) < 0)
328 return -EINVAL;
329
330 wrqu->essid.flags = wrqu->data.flags = 1;
331 wrqu->essid.length = wrqu->data.length = ssid.SSID_len + 1;
332 memcpy(extra,ssid.SSID,ssid.SSID_len + 1);
333 break;
334 }
335 case SIOCSIWESSID:
336 {
337 wlc_ssid_t ssid;
338 memset(&ssid, 0, sizeof(ssid));
339 ssid.SSID_len = strlen(extra);
340 if (ssid.SSID_len > WLC_ESSID_MAX_SIZE)
341 ssid.SSID_len = WLC_ESSID_MAX_SIZE;
342 memcpy(ssid.SSID, extra, ssid.SSID_len);
343 if (wl_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)) < 0)
344 return -EINVAL;
345 break;
346 }
347 case SIOCGIWRTS:
348 {
349 if (wl_ioctl(dev,WLC_GET_RTS,&(wrqu->rts.value),sizeof(int)) < 0)
350 return -EINVAL;
351 break;
352 }
353 case SIOCSIWRTS:
354 {
355 if (wl_ioctl(dev,WLC_SET_RTS,&(wrqu->rts.value),sizeof(int)) < 0)
356 return -EINVAL;
357 break;
358 }
359 case SIOCGIWFRAG:
360 {
361 if (wl_ioctl(dev,WLC_GET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
362 return -EINVAL;
363 break;
364 }
365 case SIOCSIWFRAG:
366 {
367 if (wl_ioctl(dev,WLC_SET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
368 return -EINVAL;
369 break;
370 }
371 case SIOCGIWTXPOW:
372 {
373 if (wl_get_val(dev, "qtxpower", &(wrqu->txpower.value), sizeof(int)) < 0)
374 return -EINVAL;
375
376 wrqu->txpower.value &= ~WL_TXPWR_OVERRIDE;
377
378 wrqu->txpower.fixed = 0;
379 wrqu->txpower.disabled = 0;
380 wrqu->txpower.flags = IW_TXPOW_MWATT;
381 break;
382 }
383 case SIOCSIWTXPOW:
384 {
385 int override;
386
387 if (wl_get_val(dev, "qtxpower", &override, sizeof(int)) < 0)
388 return -EINVAL;
389
390 wrqu->txpower.value |= override & WL_TXPWR_OVERRIDE;
391
392 if (wrqu->txpower.flags != IW_TXPOW_MWATT)
393 return -EINVAL;
394
395 if (wl_set_val(dev, "qtxpower", &wrqu->txpower.value, sizeof(int)) < 0)
396 return -EINVAL;
397 }
398 case SIOCGIWENCODE:
399 {
400 int val = 0;
401 if (wl_ioctl(dev, WLC_GET_WEP, &val, sizeof(val)) < 0)
402 return -EINVAL;
403
404 if (val > 0) {
405 wrqu->data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
406 } else {
407 wrqu->data.flags = IW_ENCODE_DISABLED;
408 }
409
410
411
412 break;
413 }
414 case SIOCGIWRANGE:
415 {
416 return wlcompat_ioctl_getiwrange(dev, extra);
417 break;
418 }
419 case SIOCSIWMODE:
420 {
421 int ap = -1, infra = -1, passive = 0, wet = 0;
422
423 switch (wrqu->mode) {
424 case IW_MODE_MONITOR:
425 passive = 1;
426 break;
427 case IW_MODE_ADHOC:
428 infra = 0;
429 ap = 0;
430 break;
431 case IW_MODE_MASTER:
432 infra = 1;
433 ap = 1;
434 break;
435 case IW_MODE_INFRA:
436 infra = 1;
437 ap = 0;
438 break;
439 case IW_MODE_REPEAT:
440 infra = 1;
441 ap = 0;
442 wet = 1;
443 break;
444 default:
445 return -EINVAL;
446 }
447
448 if (wl_ioctl(dev, WLC_SET_PASSIVE, &passive, sizeof(passive)) < 0)
449 return -EINVAL;
450 if (wl_ioctl(dev, WLC_SET_MONITOR, &passive, sizeof(passive)) < 0)
451 return -EINVAL;
452 if (wl_ioctl(dev, WLC_SET_WET, &wet, sizeof(wet)) < 0)
453 return -EINVAL;
454 if (ap >= 0)
455 if (wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap)) < 0)
456 return -EINVAL;
457 if (infra >= 0)
458 if (wl_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra)) < 0)
459 return -EINVAL;
460
461 break;
462
463 }
464 case SIOCGIWMODE:
465 {
466 int ap, infra, wet, passive;
467
468 if (wl_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)) < 0)
469 return -EINVAL;
470 if (wl_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra)) < 0)
471 return -EINVAL;
472 if (wl_ioctl(dev, WLC_GET_PASSIVE, &passive, sizeof(passive)) < 0)
473 return -EINVAL;
474 if (wl_ioctl(dev, WLC_GET_WET, &wet, sizeof(wet)) < 0)
475 return -EINVAL;
476
477 if (passive) {
478 wrqu->mode = IW_MODE_MONITOR;
479 } else if (!infra) {
480 wrqu->mode = IW_MODE_ADHOC;
481 } else {
482 if (ap) {
483 wrqu->mode = IW_MODE_MASTER;
484 } else {
485 if (wet) {
486 wrqu->mode = IW_MODE_REPEAT;
487 } else {
488 wrqu->mode = IW_MODE_INFRA;
489 }
490 }
491 }
492 break;
493 }
494 default:
495 {
496 if (info->cmd >= SIOCIWFIRSTPRIV)
497 return wlcompat_private_ioctl(dev, info, wrqu, extra);
498
499 return -EINVAL;
500 }
501 }
502
503 return 0;
504 }
505
506 static const iw_handler wlcompat_handler[] = {
507 NULL, /* SIOCSIWCOMMIT */
508 wlcompat_ioctl, /* SIOCGIWNAME */
509 NULL, /* SIOCSIWNWID */
510 NULL, /* SIOCGIWNWID */
511 wlcompat_ioctl, /* SIOCSIWFREQ */
512 wlcompat_ioctl, /* SIOCGIWFREQ */
513 wlcompat_ioctl, /* SIOCSIWMODE */
514 wlcompat_ioctl, /* SIOCGIWMODE */
515 NULL, /* SIOCSIWSENS */
516 NULL, /* SIOCGIWSENS */
517 NULL, /* SIOCSIWRANGE, unused */
518 wlcompat_ioctl, /* SIOCGIWRANGE */
519 NULL, /* SIOCSIWPRIV */
520 NULL, /* SIOCGIWPRIV */
521 NULL, /* SIOCSIWSTATS */
522 NULL, /* SIOCGIWSTATS */
523 iw_handler_set_spy, /* SIOCSIWSPY */
524 iw_handler_get_spy, /* SIOCGIWSPY */
525 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
526 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
527 wlcompat_ioctl, /* SIOCSIWAP */
528 wlcompat_ioctl, /* SIOCGIWAP */
529 NULL, /* -- hole -- */
530 NULL, /* SIOCGIWAPLIST */
531 wlcompat_set_scan, /* SIOCSIWSCAN */
532 wlcompat_get_scan, /* SIOCGIWSCAN */
533 wlcompat_ioctl, /* SIOCSIWESSID */
534 wlcompat_ioctl, /* SIOCGIWESSID */
535 NULL, /* SIOCSIWNICKN */
536 NULL, /* SIOCGIWNICKN */
537 NULL, /* -- hole -- */
538 NULL, /* -- hole -- */
539 NULL, /* SIOCSIWRATE */
540 NULL, /* SIOCGIWRATE */
541 wlcompat_ioctl, /* SIOCSIWRTS */
542 wlcompat_ioctl, /* SIOCGIWRTS */
543 wlcompat_ioctl, /* SIOCSIWFRAG */
544 wlcompat_ioctl, /* SIOCGIWFRAG */
545 wlcompat_ioctl, /* SIOCSIWTXPOW */
546 wlcompat_ioctl, /* SIOCGIWTXPOW */
547 NULL, /* SIOCSIWRETRY */
548 NULL, /* SIOCGIWRETRY */
549 NULL, /* SIOCSIWENCODE */
550 wlcompat_ioctl, /* SIOCGIWENCODE */
551 };
552
553 static int wlcompat_private_ioctl(struct net_device *dev,
554 struct iw_request_info *info,
555 union iwreq_data *wrqu,
556 char *extra)
557 {
558 int *value = (int *) wrqu->name;
559
560 switch (info->cmd) {
561 case WLCOMPAT_SET_MONITOR:
562 {
563 if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0)
564 return -EINVAL;
565
566 break;
567 }
568 case WLCOMPAT_GET_MONITOR:
569 {
570 if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0)
571 return -EINVAL;
572
573 break;
574 }
575 case WLCOMPAT_SET_TXPWR_LIMIT:
576 {
577 int val;
578
579
580 if (wl_get_val(dev, "qtxpower", &val, sizeof(int)) < 0)
581 return -EINVAL;
582
583 if (*extra > 0)
584 val |= WL_TXPWR_OVERRIDE;
585 else
586 val &= ~WL_TXPWR_OVERRIDE;
587
588 if (wl_set_val(dev, "qtxpower", &val, sizeof(int)) < 0)
589 return -EINVAL;
590
591 break;
592 }
593 case WLCOMPAT_GET_TXPWR_LIMIT:
594 {
595 if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0)
596 return -EINVAL;
597
598 *value = ((*value & WL_TXPWR_OVERRIDE) == WL_TXPWR_OVERRIDE ? 1 : 0);
599
600 break;
601 }
602 case WLCOMPAT_SET_ANTDIV:
603 {
604 if (wl_ioctl(dev, WLC_SET_ANTDIV, value, sizeof(int)) < 0)
605 return -EINVAL;
606
607 break;
608 }
609 case WLCOMPAT_GET_ANTDIV:
610 {
611 if (wl_ioctl(dev, WLC_GET_ANTDIV, extra, sizeof(int)) < 0)
612 return -EINVAL;
613
614 break;
615 }
616 case WLCOMPAT_SET_TXANT:
617 {
618 if (wl_ioctl(dev, WLC_SET_TXANT, value, sizeof(int)) < 0)
619 return -EINVAL;
620
621 break;
622 }
623 case WLCOMPAT_GET_TXANT:
624 {
625 if (wl_ioctl(dev, WLC_GET_TXANT, extra, sizeof(int)) < 0)
626 return -EINVAL;
627
628 break;
629 }
630 default:
631 {
632 return -EINVAL;
633 }
634
635 }
636 return 0;
637 }
638
639 static const struct iw_priv_args wlcompat_private_args[] =
640 {
641 { WLCOMPAT_SET_MONITOR,
642 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
643 0,
644 "set_monitor"
645 },
646 { WLCOMPAT_GET_MONITOR,
647 0,
648 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
649 "get_monitor"
650 },
651 { WLCOMPAT_SET_TXPWR_LIMIT,
652 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
653 0,
654 "set_txpwr_force"
655 },
656 { WLCOMPAT_GET_TXPWR_LIMIT,
657 0,
658 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
659 "get_txpwr_force"
660 },
661 { WLCOMPAT_SET_ANTDIV,
662 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
663 0,
664 "set_antdiv"
665 },
666 { WLCOMPAT_GET_ANTDIV,
667 0,
668 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
669 "get_antdiv"
670 },
671 { WLCOMPAT_SET_TXANT,
672 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
673 0,
674 "set_txant"
675 },
676 { WLCOMPAT_GET_TXANT,
677 0,
678 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
679 "get_txant"
680 },
681 };
682
683 static const iw_handler wlcompat_private[] =
684 {
685 wlcompat_private_ioctl,
686 NULL
687 };
688
689
690 static const struct iw_handler_def wlcompat_handler_def =
691 {
692 .standard = (iw_handler *) wlcompat_handler,
693 .num_standard = sizeof(wlcompat_handler)/sizeof(iw_handler),
694 .private = wlcompat_private,
695 .num_private = 1,
696 .private_args = wlcompat_private_args,
697 .num_private_args = sizeof(wlcompat_private_args) / sizeof(wlcompat_private_args[0])
698 };
699
700
701 #ifdef DEBUG
702 void print_buffer(int len, unsigned char *buf) {
703 int x;
704 if (buf != NULL) {
705 for (x=0;x<len && x<180 ;x++) {
706 if ((x % 4) == 0)
707 printk(" ");
708 printk("%02X",buf[x]);
709 }
710 } else {
711 printk(" NULL");
712 }
713 printk("\n");
714
715 }
716 #endif
717 static int (*old_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
718 static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
719 int ret = 0;
720 struct iwreq *iwr = (struct iwreq *) ifr;
721 struct iw_request_info info;
722
723 #ifdef DEBUG
724 printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd);
725 #endif
726
727 if (cmd >= SIOCIWFIRSTPRIV) {
728 info.cmd = cmd;
729 info.flags = 0;
730 ret = wlcompat_private_ioctl(dev, &info, &(iwr->u), (char *) &(iwr->u));
731 #ifdef DEBUG
732 } else if (cmd==SIOCDEVPRIVATE) {
733 wl_ioctl_t *ioc = (wl_ioctl_t *)ifr->ifr_data;
734 unsigned char *buf = ioc->buf;
735 printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len);
736 printk(" send: ->");
737 print_buffer(ioc->len, buf);
738 ret = old_ioctl(dev,ifr,cmd);
739 printk(" recv: ->");
740 print_buffer(ioc->len, buf);
741 printk(" ret: %d\n", ret);
742 #endif
743 } else {
744 ret = old_ioctl(dev,ifr,cmd);
745 }
746 return ret;
747 }
748
749 static int __init wlcompat_init()
750 {
751 int found = 0, i;
752 char *devname = "eth0";
753
754 while (!found && (dev = dev_get_by_name(devname))) {
755 if ((dev->wireless_handlers == NULL) && ((wl_ioctl(dev, WLC_GET_MAGIC, &i, sizeof(i)) == 0) && i == WLC_IOCTL_MAGIC))
756 found = 1;
757 devname[3]++;
758 }
759
760 if (!found) {
761 printk("No Broadcom devices found.\n");
762 return -ENODEV;
763 }
764
765
766 old_ioctl = dev->do_ioctl;
767 dev->do_ioctl = new_ioctl;
768 dev->wireless_handlers = (struct iw_handler_def *)&wlcompat_handler_def;
769 return 0;
770 }
771
772 static void __exit wlcompat_exit()
773 {
774 dev->wireless_handlers = NULL;
775 dev->do_ioctl = old_ioctl;
776 return;
777 }
778
779 EXPORT_NO_SYMBOLS;
780 MODULE_AUTHOR("openwrt.org");
781 MODULE_LICENSE("GPL");
782
783 module_init(wlcompat_init);
784 module_exit(wlcompat_exit);
This page took 0.069969 seconds and 5 git commands to generate.