4 #include <linux/config.h>
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/if_arp.h>
8 #include <asm/uaccess.h>
9 #include <linux/wireless.h>
11 #include <net/iw_handler.h>
16 static struct net_device
*dev
;
18 /* The frequency of each channel in MHz */
19 const long channel_frequency
[] = {
20 2412, 2417, 2422, 2427, 2432, 2437, 2442,
21 2447, 2452, 2457, 2462, 2467, 2472, 2484
23 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
25 static int wl_ioctl(struct net_device
*dev
, int cmd
, void *buf
, int len
)
27 mm_segment_t old_fs
= get_fs();
34 strncpy(ifr
.ifr_name
, dev
->name
, IFNAMSIZ
);
35 ifr
.ifr_data
= (caddr_t
) &ioc
;
37 ret
= dev
->do_ioctl(dev
,&ifr
,SIOCDEVPRIVATE
);
42 static int wlcompat_ioctl_getiwrange(struct net_device
*dev
,
46 struct iw_range
*range
;
48 range
= (struct iw_range
*) extra
;
50 range
->we_version_compiled
= WIRELESS_EXT
;
51 range
->we_version_source
= WIRELESS_EXT
;
53 range
->min_nwid
= range
->max_nwid
= 0;
55 range
->num_channels
= NUM_CHANNELS
;
57 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
58 range
->freq
[k
].i
= i
+ 1;
59 range
->freq
[k
].m
= channel_frequency
[i
] * 100000;
62 if (k
>= IW_MAX_FREQUENCIES
)
65 range
->num_frequency
= k
;
66 range
->sensitivity
= 3;
68 /* nbd: don't know what this means, but other drivers set it this way */
69 range
->pmp_flags
= IW_POWER_PERIOD
;
70 range
->pmt_flags
= IW_POWER_TIMEOUT
;
71 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_UNICAST_R
;
74 range
->max_rts
= 2347;
75 range
->min_frag
= 256;
76 range
->max_frag
= 2346;
79 range
->max_pmp
= 65535000;
81 range
->max_pmt
= 65535 * 1000;
83 range
->txpower_capa
= IW_TXPOW_MWATT
;
88 static int wlcompat_ioctl(struct net_device
*dev
,
89 struct iw_request_info
*info
,
90 union iwreq_data
*wrqu
,
97 strcpy(wrqu
->name
, "IEEE 802.11-DS");
102 wl_ioctl(dev
,WLC_GET_CHANNEL
, &ci
, sizeof(ci
));
103 wrqu
->freq
.m
= ci
.target_channel
;
109 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
110 wl_ioctl(dev
,WLC_GET_BSSID
,wrqu
->ap_addr
.sa_data
,6);
116 wl_ioctl(dev
,WLC_GET_SSID
, &ssid
, sizeof(wlc_ssid_t
));
117 wrqu
->essid
.flags
= wrqu
->data
.flags
= 1;
118 wrqu
->essid
.length
= wrqu
->data
.length
= ssid
.SSID_len
+ 1;
119 memcpy(extra
,ssid
.SSID
,ssid
.SSID_len
+ 1);
124 wl_ioctl(dev
,WLC_GET_RTS
,&(wrqu
->rts
.value
),sizeof(int));
129 wl_ioctl(dev
,WLC_GET_FRAG
,&(wrqu
->frag
.value
),sizeof(int));
134 wrqu
->txpower
.value
= 0;
135 wl_ioctl(dev
,WLC_GET_TXPWR
, &(wrqu
->txpower
.value
), sizeof(int));
136 wrqu
->txpower
.fixed
= 0;
137 wrqu
->txpower
.disabled
= 0;
138 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
143 wrqu
->data
.flags
= IW_ENCODE_DISABLED
;
148 err
= wlcompat_ioctl_getiwrange(dev
, extra
);
156 static const iw_handler wlcompat_handler
[] = {
157 NULL
, /* SIOCSIWCOMMIT */
158 wlcompat_ioctl
, /* SIOCGIWNAME */
159 NULL
, /* SIOCSIWNWID */
160 NULL
, /* SIOCGIWNWID */
161 NULL
, /* SIOCSIWFREQ */
162 wlcompat_ioctl
, /* SIOCGIWFREQ */
163 NULL
, /* SIOCSIWMODE */
164 NULL
, /* SIOCGIWMODE */
165 NULL
, /* SIOCSIWSENS */
166 NULL
, /* SIOCGIWSENS */
167 NULL
, /* SIOCSIWRANGE */
168 wlcompat_ioctl
, /* SIOCGIWRANGE */
169 NULL
, /* SIOCSIWPRIV */
170 NULL
, /* SIOCGIWPRIV */
171 NULL
, /* SIOCSIWSTATS */
172 NULL
, /* SIOCGIWSTATS */
173 iw_handler_set_spy
, /* SIOCSIWSPY */
174 iw_handler_get_spy
, /* SIOCGIWSPY */
175 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
176 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
177 NULL
, /* SIOCSIWAP */
178 wlcompat_ioctl
, /* SIOCGIWAP */
179 NULL
, /* -- hole -- */
180 NULL
, /* SIOCGIWAPLIST */
181 NULL
, /* -- hole -- */
182 NULL
, /* -- hole -- */
183 NULL
, /* SIOCSIWESSID */
184 wlcompat_ioctl
, /* SIOCGIWESSID */
185 NULL
, /* SIOCSIWNICKN */
186 NULL
, /* SIOCGIWNICKN */
187 NULL
, /* -- hole -- */
188 NULL
, /* -- hole -- */
189 NULL
, /* SIOCSIWRATE */
190 NULL
, /* SIOCGIWRATE */
191 NULL
, /* SIOCSIWRTS */
192 wlcompat_ioctl
, /* SIOCGIWRTS */
193 NULL
, /* SIOCSIWFRAG */
194 wlcompat_ioctl
, /* SIOCGIWFRAG */
195 NULL
, /* SIOCSIWTXPOW */
196 wlcompat_ioctl
, /* SIOCGIWTXPOW */
197 NULL
, /* SIOCSIWRETRY */
198 NULL
, /* SIOCGIWRETRY */
199 NULL
, /* SIOCSIWENCODE */
200 wlcompat_ioctl
, /* SIOCGIWENCODE */
203 static const struct iw_handler_def wlcompat_handler_def
=
205 .standard
= (iw_handler
*) wlcompat_handler
,
206 .num_standard
= sizeof(wlcompat_handler
)/sizeof(iw_handler
),
209 .private_args
= NULL
,
210 .num_private_args
= 0,
214 static int (*old_ioctl
)(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
215 static int new_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
) {
216 int ret
= old_ioctl(dev
,ifr
,cmd
);
217 printk("dev: %s ioctl: 0x%04x\n",dev
->name
,cmd
);
218 if (cmd
==SIOCDEVPRIVATE
) {
220 wl_ioctl_t
*ioc
= (wl_ioctl_t
*)ifr
->ifr_data
;
221 unsigned char *buf
= ioc
->buf
;
222 printk(" cmd: %d buf: 0x%08x len: %d\n",ioc
->cmd
,&(ioc
->buf
),ioc
->len
);
224 for (x
=0;x
<ioc
->len
&& x
<128 ;x
++) {
225 printk("%02X",buf
[x
]);
233 static int __init
wlcompat_init()
235 dev
= dev_get_by_name("eth1");
237 old_ioctl
= dev
->do_ioctl
;
238 dev
->do_ioctl
= new_ioctl
;
240 dev
->wireless_handlers
= (struct iw_handler_def
*)&wlcompat_handler_def
;
244 static void __exit
wlcompat_exit()
246 dev
->wireless_handlers
= NULL
;
248 dev
->do_ioctl
= old_ioctl
;
254 MODULE_AUTHOR("openwrt.org");
255 MODULE_LICENSE("GPL");
257 module_init(wlcompat_init
);
258 module_exit(wlcompat_exit
);