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 if (wl_ioctl(dev
, WLC_GET_RTS
, &range
->max_rts
, sizeof(int)) < 0)
75 range
->max_rts
= 2347;
77 range
->min_frag
= 256;
79 if (wl_ioctl(dev
, WLC_GET_FRAG
, &range
->max_frag
, sizeof(int)) < 0)
80 range
->max_frag
= 2346;
83 range
->max_pmp
= 65535000;
85 range
->max_pmt
= 65535 * 1000;
87 range
->txpower_capa
= IW_TXPOW_MWATT
;
92 static int wlcompat_ioctl(struct net_device
*dev
,
93 struct iw_request_info
*info
,
94 union iwreq_data
*wrqu
,
99 strcpy(wrqu
->name
, "IEEE 802.11-DS");
105 if (wl_ioctl(dev
,WLC_GET_CHANNEL
, &ci
, sizeof(ci
)) < 0)
108 wrqu
->freq
.m
= ci
.target_channel
;
114 if (wrqu
->freq
.e
== 1) {
116 int f
= wrqu
->freq
.m
/ 100000;
117 while ((channel
< NUM_CHANNELS
+ 1) && (f
!= channel_frequency
[channel
]))
120 if (channel
== NUM_CHANNELS
) // channel not found
124 wrqu
->freq
.m
= channel
+ 1;
126 if ((wrqu
->freq
.e
== 0) && (wrqu
->freq
.m
< 1000)) {
127 if (wl_ioctl(dev
, WLC_SET_CHANNEL
, &wrqu
->freq
.m
, sizeof(int)) < 0)
135 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
136 if (wl_ioctl(dev
,WLC_GET_BSSID
,wrqu
->ap_addr
.sa_data
,6) < 0)
144 if (wl_ioctl(dev
,WLC_GET_SSID
, &ssid
, sizeof(wlc_ssid_t
)) < 0)
147 wrqu
->essid
.flags
= wrqu
->data
.flags
= 1;
148 wrqu
->essid
.length
= wrqu
->data
.length
= ssid
.SSID_len
+ 1;
149 memcpy(extra
,ssid
.SSID
,ssid
.SSID_len
+ 1);
155 memset(&ssid
, 0, sizeof(ssid
));
156 ssid
.SSID_len
= strlen(extra
);
157 if (ssid
.SSID_len
> WLC_ESSID_MAX_SIZE
)
158 ssid
.SSID_len
= WLC_ESSID_MAX_SIZE
;
159 memcpy(ssid
.SSID
, extra
, ssid
.SSID_len
);
160 if (wl_ioctl(dev
, WLC_SET_SSID
, &ssid
, sizeof(ssid
)) < 0)
166 if (wl_ioctl(dev
,WLC_GET_RTS
,&(wrqu
->rts
.value
),sizeof(int)) < 0)
172 if (wl_ioctl(dev
,WLC_GET_FRAG
,&(wrqu
->frag
.value
),sizeof(int)) < 0)
178 wrqu
->txpower
.value
= 0;
179 if (wl_ioctl(dev
,WLC_GET_TXPWR
, &(wrqu
->txpower
.value
), sizeof(int)) < 0)
181 wrqu
->txpower
.fixed
= 0;
182 wrqu
->txpower
.disabled
= 0;
183 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
188 if (wrqu
->txpower
.flags
!= IW_TXPOW_MWATT
)
191 if (wl_ioctl(dev
, WLC_SET_TXPWR
, &wrqu
->txpower
.value
, sizeof(int)) < 0)
196 wrqu
->data
.flags
= IW_ENCODE_DISABLED
;
201 return wlcompat_ioctl_getiwrange(dev
, extra
);
206 int ap
= -1, infra
= -1, passive
= 0, wet
= 0;
208 switch (wrqu
->mode
) {
209 case IW_MODE_MONITOR
:
233 if (wl_ioctl(dev
, WLC_SET_PASSIVE
, &passive
, sizeof(passive
)) < 0)
235 if (wl_ioctl(dev
, WLC_SET_MONITOR
, &passive
, sizeof(passive
)) < 0)
237 if (wl_ioctl(dev
, WLC_SET_WET
, &wet
, sizeof(wet
)) < 0)
240 if (wl_ioctl(dev
, WLC_SET_AP
, &ap
, sizeof(ap
)) < 0)
243 if (wl_ioctl(dev
, WLC_SET_INFRA
, &infra
, sizeof(infra
)) < 0)
251 int ap
, infra
, wet
, passive
;
253 if (wl_ioctl(dev
, WLC_GET_AP
, &ap
, sizeof(ap
)) < 0)
255 if (wl_ioctl(dev
, WLC_GET_INFRA
, &infra
, sizeof(infra
)) < 0)
257 if (wl_ioctl(dev
, WLC_GET_PASSIVE
, &passive
, sizeof(passive
)) < 0)
259 if (wl_ioctl(dev
, WLC_GET_WET
, &wet
, sizeof(wet
)) < 0)
263 wrqu
->mode
= IW_MODE_MONITOR
;
265 wrqu
->mode
= IW_MODE_ADHOC
;
268 wrqu
->mode
= IW_MODE_MASTER
;
271 wrqu
->mode
= IW_MODE_REPEAT
;
273 wrqu
->mode
= IW_MODE_INFRA
;
288 static const iw_handler wlcompat_handler
[] = {
289 NULL
, /* SIOCSIWCOMMIT */
290 wlcompat_ioctl
, /* SIOCGIWNAME */
291 NULL
, /* SIOCSIWNWID */
292 NULL
, /* SIOCGIWNWID */
293 wlcompat_ioctl
, /* SIOCSIWFREQ */
294 wlcompat_ioctl
, /* SIOCGIWFREQ */
295 wlcompat_ioctl
, /* SIOCSIWMODE */
296 wlcompat_ioctl
, /* SIOCGIWMODE */
297 NULL
, /* SIOCSIWSENS */
298 NULL
, /* SIOCGIWSENS */
299 NULL
, /* SIOCSIWRANGE */
300 wlcompat_ioctl
, /* SIOCGIWRANGE */
301 NULL
, /* SIOCSIWPRIV */
302 NULL
, /* SIOCGIWPRIV */
303 NULL
, /* SIOCSIWSTATS */
304 NULL
, /* SIOCGIWSTATS */
305 iw_handler_set_spy
, /* SIOCSIWSPY */
306 iw_handler_get_spy
, /* SIOCGIWSPY */
307 iw_handler_set_thrspy
, /* SIOCSIWTHRSPY */
308 iw_handler_get_thrspy
, /* SIOCGIWTHRSPY */
309 NULL
, /* SIOCSIWAP */
310 wlcompat_ioctl
, /* SIOCGIWAP */
311 NULL
, /* -- hole -- */
312 NULL
, /* SIOCGIWAPLIST */
313 NULL
, /* -- hole -- */
314 NULL
, /* -- hole -- */
315 wlcompat_ioctl
, /* SIOCSIWESSID */
316 wlcompat_ioctl
, /* SIOCGIWESSID */
317 NULL
, /* SIOCSIWNICKN */
318 NULL
, /* SIOCGIWNICKN */
319 NULL
, /* -- hole -- */
320 NULL
, /* -- hole -- */
321 NULL
, /* SIOCSIWRATE */
322 NULL
, /* SIOCGIWRATE */
323 NULL
, /* SIOCSIWRTS */
324 wlcompat_ioctl
, /* SIOCGIWRTS */
325 NULL
, /* SIOCSIWFRAG */
326 wlcompat_ioctl
, /* SIOCGIWFRAG */
327 wlcompat_ioctl
, /* SIOCSIWTXPOW */
328 wlcompat_ioctl
, /* SIOCGIWTXPOW */
329 NULL
, /* SIOCSIWRETRY */
330 NULL
, /* SIOCGIWRETRY */
331 NULL
, /* SIOCSIWENCODE */
332 wlcompat_ioctl
, /* SIOCGIWENCODE */
335 static const struct iw_handler_def wlcompat_handler_def
=
337 .standard
= (iw_handler
*) wlcompat_handler
,
338 .num_standard
= sizeof(wlcompat_handler
)/sizeof(iw_handler
),
341 .private_args
= NULL
,
342 .num_private_args
= 0,
346 static int (*old_ioctl
)(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
);
347 static int new_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
) {
348 int ret
= old_ioctl(dev
,ifr
,cmd
);
349 printk("dev: %s ioctl: 0x%04x\n",dev
->name
,cmd
);
350 if (cmd
==SIOCDEVPRIVATE
) {
352 wl_ioctl_t
*ioc
= (wl_ioctl_t
*)ifr
->ifr_data
;
353 unsigned char *buf
= ioc
->buf
;
354 printk(" cmd: %d buf: 0x%08x len: %d\n",ioc
->cmd
,&(ioc
->buf
),ioc
->len
);
356 for (x
=0;x
<ioc
->len
&& x
<128 ;x
++) {
357 printk("%02X",buf
[x
]);
365 static int __init
wlcompat_init()
367 dev
= dev_get_by_name("eth1");
369 old_ioctl
= dev
->do_ioctl
;
370 dev
->do_ioctl
= new_ioctl
;
372 dev
->wireless_handlers
= (struct iw_handler_def
*)&wlcompat_handler_def
;
376 static void __exit
wlcompat_exit()
378 dev
->wireless_handlers
= NULL
;
380 dev
->do_ioctl
= old_ioctl
;
386 MODULE_AUTHOR("openwrt.org");
387 MODULE_LICENSE("GPL");
389 module_init(wlcompat_init
);
390 module_exit(wlcompat_exit
);