4 * Copyright (C) 2005 Mike Baker,
5 * Felix Fietkau <openwrt@nbd.name>
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.
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.
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.
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>
32 #include <net/iw_handler.h>
35 static struct net_device
*dev
;
36 static unsigned short bss_force
;
37 static struct iw_statistics wstats
;
38 char buf
[WLC_IOCTL_MAXLEN
];
40 /* The frequency of each channel in MHz */
41 const long channel_frequency
[] = {
42 2412, 2417, 2422, 2427, 2432, 2437, 2442,
43 2447, 2452, 2457, 2462, 2467, 2472, 2484
45 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
47 typedef struct internal_wsec_key
{
49 uint8 unknown_1
; // 0x01
51 uint8 unknown_2
[7]; // 0x03
54 char data
[32]; // 0x0e
58 static int wlcompat_private_ioctl(struct net_device
*dev
,
59 struct iw_request_info
*info
,
60 union iwreq_data
*wrqu
,
63 void print_buffer(int len
, unsigned char *buf
);
66 static int wl_ioctl(struct net_device
*dev
, int cmd
, void *buf
, int len
)
68 mm_segment_t old_fs
= get_fs();
75 strncpy(ifr
.ifr_name
, dev
->name
, IFNAMSIZ
);
76 ifr
.ifr_data
= (caddr_t
) &ioc
;
78 ret
= dev
->do_ioctl(dev
,&ifr
,SIOCDEVPRIVATE
);
83 static int wl_set_val(struct net_device
*dev
, char *var
, void *val
, int len
)
89 /* check for overflow */
90 if ((buf_len
= strlen(var
)) + 1 + len
> sizeof(buf
))
96 /* append int value onto the end of the name string */
97 memcpy(&(buf
[buf_len
]), val
, len
);
100 ret
= wl_ioctl(dev
, WLC_SET_VAR
, buf
, buf_len
);
104 static int wl_get_val(struct net_device
*dev
, char *var
, void *val
, int len
)
110 /* check for overflow */
111 if ((buf_len
= strlen(var
)) + 1 > sizeof(buf
) || len
> sizeof(buf
))
115 if (ret
= wl_ioctl(dev
, WLC_GET_VAR
, buf
, buf_len
+ len
))
118 memcpy(val
, buf
, len
);
122 int get_primary_key(struct net_device
*dev
)
126 for (key
= val
= 0; (key
< 4) && (val
== 0); key
++) {
128 if (wl_ioctl(dev
, WLC_GET_KEY_PRIMARY
, &val
, sizeof(val
)) < 0)
135 static int wlcompat_ioctl_getiwrange(struct net_device
*dev
,
139 struct iw_range
*range
;
141 range
= (struct iw_range
*) extra
;
142 bzero(extra
, sizeof(struct iw_range
));
144 range
->we_version_compiled
= WIRELESS_EXT
;
145 range
->we_version_source
= WIRELESS_EXT
;
147 range
->min_nwid
= range
->max_nwid
= 0;
149 range
->num_channels
= NUM_CHANNELS
;
151 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
152 range
->freq
[k
].i
= i
+ 1;
153 range
->freq
[k
].m
= channel_frequency
[i
] * 100000;
154 range
->freq
[k
].e
= 1;
156 if (k
>= IW_MAX_FREQUENCIES
)
159 range
->num_frequency
= k
;
160 range
->sensitivity
= 3;
162 /* nbd: don't know what this means, but other drivers set it this way */
163 range
->pmp_flags
= IW_POWER_PERIOD
;
164 range
->pmt_flags
= IW_POWER_TIMEOUT
;
165 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_UNICAST_R
;
168 range
->max_pmp
= 65535000;
170 range
->max_pmt
= 65535 * 1000;
172 range
->max_qual
.qual
= 0;
173 range
->max_qual
.level
= 0;
174 range
->max_qual
.noise
= 0;
177 if (wl_ioctl(dev
, WLC_GET_RTS
, &range
->max_rts
, sizeof(int)) < 0)
178 range
->max_rts
= 2347;
180 range
->min_frag
= 256;
182 if (wl_ioctl(dev
, WLC_GET_FRAG
, &range
->max_frag
, sizeof(int)) < 0)
183 range
->max_frag
= 2346;
185 range
->txpower_capa
= IW_TXPOW_DBM
;
191 static int wlcompat_set_scan(struct net_device
*dev
,
192 struct iw_request_info
*info
,
193 union iwreq_data
*wrqu
,
196 int ap
= 0, oldap
= 0;
197 wl_scan_params_t params
;
199 memset(¶ms
, 0, sizeof(params
));
201 /* use defaults (same parameters as wl scan) */
202 memset(¶ms
.bssid
, 0xff, sizeof(params
.bssid
));
203 params
.bss_type
= DOT11_BSSTYPE_ANY
;
204 params
.scan_type
= -1;
206 params
.active_time
= -1;
207 params
.passive_time
= -1;
208 params
.home_time
= -1;
210 /* can only scan in STA mode */
211 wl_ioctl(dev
, WLC_GET_AP
, &oldap
, sizeof(oldap
));
213 wl_ioctl(dev
, WLC_SET_AP
, &ap
, sizeof(ap
));
215 if (wl_ioctl(dev
, WLC_SCAN
, ¶ms
, 64) < 0)
219 wl_ioctl(dev
, WLC_SET_AP
, &oldap
, sizeof(oldap
));
225 struct iw_statistics
*wlcompat_get_wireless_stats(struct net_device
*dev
)
227 wl_bss_info_t
*bss_info
= (wl_bss_info_t
*) buf
;
229 unsigned int rssi
, noise
, ap
;
231 memset(&wstats
, 0, sizeof(wstats
));
232 memset(&pkt
, 0, sizeof(pkt
));
233 memset(buf
, 0, sizeof(buf
));
234 bss_info
->version
= 0x2000;
235 wl_ioctl(dev
, WLC_GET_BSS_INFO
, bss_info
, WLC_IOCTL_MAXLEN
);
236 wl_ioctl(dev
, WLC_GET_PKTCNTS
, &pkt
, sizeof(pkt
));
239 if ((wl_ioctl(dev
, WLC_GET_AP
, &ap
, sizeof(ap
)) < 0) || ap
) {
240 if (wl_ioctl(dev
, WLC_GET_PHY_NOISE
, &noise
, sizeof(noise
)) < 0)
243 // somehow the structure doesn't fit here
247 rssi
= (rssi
== 0 ? 1 : rssi
);
248 wstats
.qual
.updated
= 0x10;
250 wstats
.qual
.updated
|= 0x20;
252 wstats
.qual
.updated
|= 0x40;
254 if ((wstats
.qual
.updated
& 0x60) == 0x60)
257 wstats
.qual
.level
= rssi
;
258 wstats
.qual
.noise
= noise
;
259 wstats
.discard
.misc
= pkt
.rx_bad_pkt
;
260 wstats
.discard
.retries
= pkt
.tx_bad_pkt
;
265 static int wlcompat_get_scan(struct net_device
*dev
,
266 struct iw_request_info
*info
,
267 union iwreq_data
*wrqu
,
270 wl_scan_results_t
*results
= (wl_scan_results_t
*) buf
;
271 wl_bss_info_t
*bss_info
;
273 char *current_ev
= extra
;
275 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
280 results
->buflen
= WLC_IOCTL_MAXLEN
- sizeof(wl_scan_results_t
);
282 if (wl_ioctl(dev
, WLC_SCAN_RESULTS
, buf
, WLC_IOCTL_MAXLEN
) < 0)
285 bss_info
= &(results
->bss_info
[0]);
286 info_ptr
= (char *) bss_info
;
287 for (i
= 0; i
< results
->count
; i
++) {
289 /* send the cell address (must be sent first) */
291 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
292 memcpy(&iwe
.u
.ap_addr
.sa_data
, &bss_info
->BSSID
, sizeof(bss_info
->BSSID
));
293 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
296 iwe
.cmd
= SIOCGIWESSID
;
297 iwe
.u
.data
.length
= bss_info
->SSID_len
;
298 if (iwe
.u
.data
.length
> IW_ESSID_MAX_SIZE
)
299 iwe
.u
.data
.length
= IW_ESSID_MAX_SIZE
;
300 iwe
.u
.data
.flags
= 1;
301 current_ev
= iwe_stream_add_point(current_ev
, end_buf
, &iwe
, bss_info
->SSID
);
303 /* send frequency/channel info */
304 iwe
.cmd
= SIOCGIWFREQ
;
306 iwe
.u
.freq
.m
= bss_info
->channel
;
307 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
309 /* add quality statistics */
312 iwe
.u
.qual
.level
= bss_info
->RSSI
;
313 iwe
.u
.qual
.noise
= bss_info
->phy_noise
;
314 current_ev
= iwe_stream_add_event(current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
316 /* send rate information */
317 iwe
.cmd
= SIOCGIWRATE
;
318 current_val
= current_ev
+ IW_EV_LCP_LEN
;
319 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
321 for(j
= 0 ; j
< bss_info
->rateset
.count
; j
++) {
322 iwe
.u
.bitrate
.value
= ((bss_info
->rateset
.rates
[j
] & 0x7f) * 500000);
323 current_val
= iwe_stream_add_value(current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
325 if((current_val
- current_ev
) > IW_EV_LCP_LEN
)
326 current_ev
= current_val
;
328 info_ptr
+= sizeof(wl_bss_info_t
);
329 if (bss_info
->ie_length
% 4)
330 info_ptr
+= bss_info
->ie_length
+ 4 - (bss_info
->ie_length
% 4);
332 info_ptr
+= bss_info
->ie_length
;
333 bss_info
= (wl_bss_info_t
*) info_ptr
;
336 wrqu
->data
.length
= (current_ev
- extra
);
337 wrqu
->data
.flags
= 0;
342 static int wlcompat_ioctl(struct net_device
*dev
,
343 struct iw_request_info
*info
,
344 union iwreq_data
*wrqu
,
349 strcpy(wrqu
->name
, "IEEE 802.11-DS");
355 if (wl_ioctl(dev
,WLC_GET_CHANNEL
, &ci
, sizeof(ci
)) < 0)
358 wrqu
->freq
.m
= ci
.target_channel
;
364 if (wrqu
->freq
.m
== -1) {
366 if (wl_ioctl(dev
, WLC_SET_CHANNEL
, &wrqu
->freq
.m
, sizeof(int)) < 0)
369 if (wrqu
->freq
.e
== 1) {
371 int f
= wrqu
->freq
.m
/ 100000;
372 while ((channel
< NUM_CHANNELS
+ 1) && (f
!= channel_frequency
[channel
]))
375 if (channel
== NUM_CHANNELS
) // channel not found
379 wrqu
->freq
.m
= channel
+ 1;
381 if ((wrqu
->freq
.e
== 0) && (wrqu
->freq
.m
< 1000)) {
382 if (wl_ioctl(dev
, WLC_SET_CHANNEL
, &wrqu
->freq
.m
, sizeof(int)) < 0)
396 memset(®
, 0, sizeof(reg
));
398 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
401 if (wl_ioctl(dev
, WLC_GET_AP
, &ap
, sizeof(ap
)) < 0)
404 if (wl_ioctl(dev
, WLC_GET_INFRA
, &infra
, sizeof(infra
)) < 0)
408 wl_ioctl(dev
, WLC_SET_BSSID
, wrqu
->ap_addr
.sa_data
, 6);
412 reg
.val
= bss_force
<< 16 | bss_force
;
413 wl_ioctl(dev
, WLC_W_REG
, ®
, sizeof(reg
));
416 wl_ioctl(dev
, WLC_R_REG
, ®
, sizeof(reg
));
417 reg
.val
= bss_force
<< 16;
418 wl_ioctl(dev
, WLC_W_REG
, ®
, sizeof(reg
));
421 if (wl_ioctl(dev
, ((ap
|| !infra
) ? WLC_SET_BSSID
: WLC_REASSOC
), wrqu
->ap_addr
.sa_data
, 6) < 0)
430 memset(®
, 0, sizeof(reg
));
434 wl_ioctl(dev
, WLC_R_REG
, ®
, sizeof(reg
));
435 printk("bss time = 0x%08x", reg
.val
);
438 wl_ioctl(dev
, WLC_R_REG
, ®
, sizeof(reg
));
439 printk("%08x\n", reg
.val
);
442 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
443 if (wl_ioctl(dev
,WLC_GET_BSSID
,wrqu
->ap_addr
.sa_data
,6) < 0)
451 if (wl_ioctl(dev
,WLC_GET_SSID
, &ssid
, sizeof(wlc_ssid_t
)) < 0)
454 wrqu
->essid
.flags
= wrqu
->data
.flags
= 1;
455 wrqu
->essid
.length
= wrqu
->data
.length
= ssid
.SSID_len
+ 1;
456 memcpy(extra
,ssid
.SSID
,ssid
.SSID_len
+ 1);
462 memset(&ssid
, 0, sizeof(ssid
));
463 ssid
.SSID_len
= strlen(extra
);
464 if (ssid
.SSID_len
> WLC_ESSID_MAX_SIZE
)
465 ssid
.SSID_len
= WLC_ESSID_MAX_SIZE
;
466 memcpy(ssid
.SSID
, extra
, ssid
.SSID_len
);
467 if (wl_ioctl(dev
, WLC_SET_SSID
, &ssid
, sizeof(ssid
)) < 0)
473 if (wl_ioctl(dev
,WLC_GET_RTS
,&(wrqu
->rts
.value
),sizeof(int)) < 0)
479 if (wl_ioctl(dev
,WLC_SET_RTS
,&(wrqu
->rts
.value
),sizeof(int)) < 0)
485 if (wl_ioctl(dev
,WLC_GET_FRAG
,&(wrqu
->frag
.value
),sizeof(int)) < 0)
491 if (wl_ioctl(dev
,WLC_SET_FRAG
,&(wrqu
->frag
.value
),sizeof(int)) < 0)
499 wl_ioctl(dev
, WLC_GET_RADIO
, &radio
, sizeof(int));
501 if (wl_get_val(dev
, "qtxpower", &(wrqu
->txpower
.value
), sizeof(int)) < 0)
504 wrqu
->txpower
.value
&= ~WL_TXPWR_OVERRIDE
;
505 wrqu
->txpower
.value
/= 4;
507 wrqu
->txpower
.fixed
= 0;
508 wrqu
->txpower
.disabled
= radio
;
509 wrqu
->txpower
.flags
= IW_TXPOW_DBM
;
514 /* This is weird: WLC_SET_RADIO with 1 as argument disables the radio */
515 int radio
= wrqu
->txpower
.disabled
;
517 wl_ioctl(dev
, WLC_SET_RADIO
, &radio
, sizeof(int));
519 if (!wrqu
->txpower
.disabled
&& (wrqu
->txpower
.value
> 0)) {
522 if (wl_get_val(dev
, "qtxpower", &value
, sizeof(int)) < 0)
525 value
&= WL_TXPWR_OVERRIDE
;
526 wrqu
->txpower
.value
*= 4;
527 wrqu
->txpower
.value
|= value
;
529 if (wrqu
->txpower
.flags
!= IW_TXPOW_DBM
)
532 if (wrqu
->txpower
.value
> 0)
533 if (wl_set_val(dev
, "qtxpower", &(wrqu
->txpower
.value
), sizeof(int)) < 0)
540 int val
= 0, wep
= 1, wrestrict
= 1;
541 int index
= (wrqu
->data
.flags
& IW_ENCODE_INDEX
) - 1;
544 index
= get_primary_key(dev
);
546 if (wrqu
->data
.flags
& IW_ENCODE_DISABLED
) {
548 if (wl_ioctl(dev
, WLC_SET_WSEC
, &wep
, sizeof(val
)) < 0)
553 if (wl_ioctl(dev
, WLC_SET_WSEC
, &wep
, sizeof(val
)) < 0)
556 if (wrqu
->data
.flags
& IW_ENCODE_OPEN
)
559 if (wrqu
->data
.pointer
&& (wrqu
->data
.length
> 0) && (wrqu
->data
.length
<= 16)) {
561 memset(&key
, 0, sizeof(key
));
563 key
.flags
= WL_PRIMARY_KEY
;
564 key
.len
= wrqu
->data
.length
;
566 memcpy(key
.data
, wrqu
->data
.pointer
, wrqu
->data
.length
);
568 if (wl_ioctl(dev
, WLC_SET_KEY
, &key
, sizeof(key
)) < 0)
573 wl_ioctl(dev
, WLC_SET_KEY_PRIMARY
, &index
, sizeof(index
));
576 wl_ioctl(dev
, WLC_SET_WEP_RESTRICT
, &wrestrict
, sizeof(wrestrict
));
584 if (wl_ioctl(dev
, WLC_GET_WEP
, &val
, sizeof(val
)) < 0)
589 int key
= get_primary_key(dev
);
591 wrqu
->data
.flags
= IW_ENCODE_ENABLED
;
596 info_addr
= (int *) dev
->priv
;
597 wep_key
= (wkey
*) ((*info_addr
) + 0x2752 + (key
* 0x110));
599 wrqu
->data
.flags
|= key
+ 1;
600 wrqu
->data
.length
= wep_key
->len
;
602 memset(extra
, 0, 16);
603 memcpy(extra
, wep_key
->data
, 16);
605 wrqu
->data
.flags
|= IW_ENCODE_NOKEY
;
608 wrqu
->data
.flags
= IW_ENCODE_DISABLED
;
615 return wlcompat_ioctl_getiwrange(dev
, extra
);
620 int ap
= -1, infra
= -1, passive
= 0, wet
= 0;
622 switch (wrqu
->mode
) {
623 case IW_MODE_MONITOR
:
648 wl_ioctl(dev
, WLC_SET_PASSIVE
, &passive
, sizeof(passive
));
649 wl_ioctl(dev
, WLC_SET_MONITOR
, &passive
, sizeof(passive
));
650 wl_ioctl(dev
, WLC_SET_WET
, &wet
, sizeof(wet
));
652 wl_ioctl(dev
, WLC_SET_AP
, &ap
, sizeof(ap
));
654 wl_ioctl(dev
, WLC_SET_INFRA
, &infra
, sizeof(infra
));
661 int ap
, infra
, wet
, passive
;
663 if (wl_ioctl(dev
, WLC_GET_AP
, &ap
, sizeof(ap
)) < 0)
665 if (wl_ioctl(dev
, WLC_GET_INFRA
, &infra
, sizeof(infra
)) < 0)
667 if (wl_ioctl(dev
, WLC_GET_PASSIVE
, &passive
, sizeof(passive
)) < 0)
669 if (wl_ioctl(dev
, WLC_GET_WET
, &wet
, sizeof(wet
)) < 0)
673 wrqu
->mode
= IW_MODE_MONITOR
;
675 wrqu
->mode
= IW_MODE_ADHOC
;
678 wrqu
->mode
= IW_MODE_MASTER
;
681 wrqu
->mode
= IW_MODE_REPEAT
;
683 wrqu
->mode
= IW_MODE_INFRA
;
691 if (info
->cmd
>= SIOCIWFIRSTPRIV
)
692 return wlcompat_private_ioctl(dev
, info
, wrqu
, extra
);
701 static const iw_handler wlcompat_handler
[] = {
702 NULL
, /* SIOCSIWCOMMIT */
703 wlcompat_ioctl
, /* SIOCGIWNAME */
704 NULL
, /* SIOCSIWNWID */
705 NULL
, /* SIOCGIWNWID */
706 wlcompat_ioctl
, /* SIOCSIWFREQ */
707 wlcompat_ioctl
, /* SIOCGIWFREQ */
708 wlcompat_ioctl
, /* SIOCSIWMODE */
709 wlcompat_ioctl
, /* SIOCGIWMODE */
710 NULL
, /* SIOCSIWSENS */
711 NULL
, /* SIOCGIWSENS */
712 NULL
, /* SIOCSIWRANGE, unused */
713 wlcompat_ioctl
, /* SIOCGIWRANGE */
714 NULL
, /* SIOCSIWPRIV */
715 NULL
, /* SIOCGIWPRIV */
716 NULL
, /* SIOCSIWSTATS */
717 NULL
, /* SIOCGIWSTATS */
718 iw_handler_set_spy
, /* SIOCSIWSPY */
719 iw_handler_get_spy
, /* SIOCGIWSPY */
720 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
721 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
722 wlcompat_ioctl
, /* SIOCSIWAP */
723 wlcompat_ioctl
, /* SIOCGIWAP */
724 NULL
, /* -- hole -- */
725 NULL
, /* SIOCGIWAPLIST */
726 wlcompat_set_scan
, /* SIOCSIWSCAN */
727 wlcompat_get_scan
, /* SIOCGIWSCAN */
728 wlcompat_ioctl
, /* SIOCSIWESSID */
729 wlcompat_ioctl
, /* SIOCGIWESSID */
730 NULL
, /* SIOCSIWNICKN */
731 NULL
, /* SIOCGIWNICKN */
732 NULL
, /* -- hole -- */
733 NULL
, /* -- hole -- */
734 NULL
, /* SIOCSIWRATE */
735 NULL
, /* SIOCGIWRATE */
736 wlcompat_ioctl
, /* SIOCSIWRTS */
737 wlcompat_ioctl
, /* SIOCGIWRTS */
738 wlcompat_ioctl
, /* SIOCSIWFRAG */
739 wlcompat_ioctl
, /* SIOCGIWFRAG */
740 wlcompat_ioctl
, /* SIOCSIWTXPOW */
741 wlcompat_ioctl
, /* SIOCGIWTXPOW */
742 NULL
, /* SIOCSIWRETRY */
743 NULL
, /* SIOCGIWRETRY */
744 wlcompat_ioctl
, /* SIOCSIWENCODE */
745 wlcompat_ioctl
, /* SIOCGIWENCODE */
749 #define WLCOMPAT_SET_MONITOR SIOCIWFIRSTPRIV + 0
750 #define WLCOMPAT_GET_MONITOR SIOCIWFIRSTPRIV + 1
751 #define WLCOMPAT_SET_TXPWR_LIMIT SIOCIWFIRSTPRIV + 2
752 #define WLCOMPAT_GET_TXPWR_LIMIT SIOCIWFIRSTPRIV + 3
753 #define WLCOMPAT_SET_ANTDIV SIOCIWFIRSTPRIV + 4
754 #define WLCOMPAT_GET_ANTDIV SIOCIWFIRSTPRIV + 5
755 #define WLCOMPAT_SET_TXANT SIOCIWFIRSTPRIV + 6
756 #define WLCOMPAT_GET_TXANT SIOCIWFIRSTPRIV + 7
757 #define WLCOMPAT_SET_BSS_FORCE SIOCIWFIRSTPRIV + 8
758 #define WLCOMPAT_GET_BSS_FORCE SIOCIWFIRSTPRIV + 9
761 static int wlcompat_private_ioctl(struct net_device
*dev
,
762 struct iw_request_info
*info
,
763 union iwreq_data
*wrqu
,
766 int *value
= (int *) wrqu
->name
;
769 case WLCOMPAT_SET_MONITOR
:
771 if (wl_ioctl(dev
, WLC_SET_MONITOR
, value
, sizeof(int)) < 0)
776 case WLCOMPAT_GET_MONITOR
:
778 if (wl_ioctl(dev
, WLC_GET_MONITOR
, extra
, sizeof(int)) < 0)
783 case WLCOMPAT_SET_TXPWR_LIMIT
:
788 if (wl_get_val(dev
, "qtxpower", &val
, sizeof(int)) < 0)
792 val
|= WL_TXPWR_OVERRIDE
;
794 val
&= ~WL_TXPWR_OVERRIDE
;
796 if (wl_set_val(dev
, "qtxpower", &val
, sizeof(int)) < 0)
801 case WLCOMPAT_GET_TXPWR_LIMIT
:
803 if (wl_get_val(dev
, "qtxpower", value
, sizeof(int)) < 0)
806 *value
= ((*value
& WL_TXPWR_OVERRIDE
) == WL_TXPWR_OVERRIDE
? 1 : 0);
810 case WLCOMPAT_SET_ANTDIV
:
812 if (wl_ioctl(dev
, WLC_SET_ANTDIV
, value
, sizeof(int)) < 0)
817 case WLCOMPAT_GET_ANTDIV
:
819 if (wl_ioctl(dev
, WLC_GET_ANTDIV
, extra
, sizeof(int)) < 0)
824 case WLCOMPAT_SET_TXANT
:
826 if (wl_ioctl(dev
, WLC_SET_TXANT
, value
, sizeof(int)) < 0)
831 case WLCOMPAT_GET_TXANT
:
833 if (wl_ioctl(dev
, WLC_GET_TXANT
, extra
, sizeof(int)) < 0)
838 case WLCOMPAT_SET_BSS_FORCE
:
840 bss_force
= (unsigned short) *value
;
843 case WLCOMPAT_GET_BSS_FORCE
:
845 *extra
= (int) bss_force
;
857 static const struct iw_priv_args wlcompat_private_args
[] =
859 { WLCOMPAT_SET_MONITOR
,
860 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
864 { WLCOMPAT_GET_MONITOR
,
866 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
869 { WLCOMPAT_SET_TXPWR_LIMIT
,
870 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
874 { WLCOMPAT_GET_TXPWR_LIMIT
,
876 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
879 { WLCOMPAT_SET_ANTDIV
,
880 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
884 { WLCOMPAT_GET_ANTDIV
,
886 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
889 { WLCOMPAT_SET_TXANT
,
890 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
894 { WLCOMPAT_GET_TXANT
,
896 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
899 { WLCOMPAT_SET_BSS_FORCE
,
900 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
904 { WLCOMPAT_GET_BSS_FORCE
,
906 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
911 static const iw_handler wlcompat_private
[] =
913 wlcompat_private_ioctl
,
918 static const struct iw_handler_def wlcompat_handler_def
=
920 .standard
= (iw_handler
*) wlcompat_handler
,
921 .num_standard
= sizeof(wlcompat_handler
)/sizeof(iw_handler
),
922 .private = wlcompat_private
,
924 .private_args
= wlcompat_private_args
,
925 .num_private_args
= sizeof(wlcompat_private_args
) / sizeof(wlcompat_private_args
[0])
930 void print_buffer(int len
, unsigned char *buf
) {
933 for (x
=0;x
<len
&& x
<180 ;x
++) {
936 printk("%02X",buf
[x
]);
945 static int (*old_ioctl
)(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
946 static int new_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
) {
948 struct iwreq
*iwr
= (struct iwreq
*) ifr
;
949 struct iw_request_info info
;
952 printk("dev: %s ioctl: 0x%04x\n",dev
->name
,cmd
);
955 if (cmd
>= SIOCIWFIRSTPRIV
) {
958 ret
= wlcompat_private_ioctl(dev
, &info
, &(iwr
->u
), (char *) &(iwr
->u
));
960 } else if (cmd
==SIOCDEVPRIVATE
) {
961 wl_ioctl_t
*ioc
= (wl_ioctl_t
*)ifr
->ifr_data
;
962 unsigned char *buf
= ioc
->buf
;
963 printk(" cmd: %d buf: 0x%08x len: %d\n",ioc
->cmd
,&(ioc
->buf
),ioc
->len
);
965 print_buffer(ioc
->len
, buf
);
966 ret
= old_ioctl(dev
,ifr
,cmd
);
968 print_buffer(ioc
->len
, buf
);
969 printk(" ret: %d\n", ret
);
972 ret
= old_ioctl(dev
,ifr
,cmd
);
977 static int __init
wlcompat_init()
980 char *devname
= "eth0";
983 while (!found
&& (dev
= dev_get_by_name(devname
))) {
984 if ((dev
->wireless_handlers
== NULL
) && ((wl_ioctl(dev
, WLC_GET_MAGIC
, &i
, sizeof(i
)) == 0) && i
== WLC_IOCTL_MAGIC
))
990 printk("No Broadcom devices found.\n");
995 old_ioctl
= dev
->do_ioctl
;
996 dev
->do_ioctl
= new_ioctl
;
997 dev
->wireless_handlers
= (struct iw_handler_def
*)&wlcompat_handler_def
;
998 dev
->get_wireless_stats
= wlcompat_get_wireless_stats
;
1000 printk("broadcom driver private data: 0x%08x\n", dev
->priv
);
1005 static void __exit
wlcompat_exit()
1007 dev
->get_wireless_stats
= NULL
;
1008 dev
->wireless_handlers
= NULL
;
1009 dev
->do_ioctl
= old_ioctl
;
1014 MODULE_AUTHOR("openwrt.org");
1015 MODULE_LICENSE("GPL");
1017 module_init(wlcompat_init
);
1018 module_exit(wlcompat_exit
);