add SIOCSIWESSID
[openwrt.git] / package / openwrt / wlcompat.c
1 // insert header here
2 // mbm. gpl.
3
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>
10
11 #include <net/iw_handler.h>
12 #include <wlioctl.h>
13
14 #define DEBUG
15
16 static struct net_device *dev;
17
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
22 };
23 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
24
25 static int wl_ioctl(struct net_device *dev, int cmd, void *buf, int len)
26 {
27 mm_segment_t old_fs = get_fs();
28 struct ifreq ifr;
29 int ret;
30 wl_ioctl_t ioc;
31 ioc.cmd = cmd;
32 ioc.buf = buf;
33 ioc.len = len;
34 strncpy(ifr.ifr_name, dev->name, IFNAMSIZ);
35 ifr.ifr_data = (caddr_t) &ioc;
36 set_fs(KERNEL_DS);
37 ret = dev->do_ioctl(dev,&ifr,SIOCDEVPRIVATE);
38 set_fs (old_fs);
39 return ret;
40 }
41
42 static int wlcompat_ioctl_getiwrange(struct net_device *dev,
43 char *extra)
44 {
45 int i, k;
46 struct iw_range *range;
47
48 range = (struct iw_range *) extra;
49
50 range->we_version_compiled = WIRELESS_EXT;
51 range->we_version_source = WIRELESS_EXT;
52
53 range->min_nwid = range->max_nwid = 0;
54
55 range->num_channels = NUM_CHANNELS;
56 k = 0;
57 for (i = 0; i < NUM_CHANNELS; i++) {
58 range->freq[k].i = i + 1;
59 range->freq[k].m = channel_frequency[i] * 100000;
60 range->freq[k].e = 1;
61 k++;
62 if (k >= IW_MAX_FREQUENCIES)
63 break;
64 }
65 range->num_frequency = k;
66 range->sensitivity = 3;
67
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;
72
73 range->min_rts = 0;
74 range->max_rts = 2347;
75 range->min_frag = 256;
76 range->max_frag = 2346;
77
78 range->min_pmp = 0;
79 range->max_pmp = 65535000;
80 range->min_pmt = 0;
81 range->max_pmt = 65535 * 1000;
82
83 range->txpower_capa = IW_TXPOW_MWATT;
84
85 return 0;
86 }
87
88 static int wlcompat_ioctl(struct net_device *dev,
89 struct iw_request_info *info,
90 union iwreq_data *wrqu,
91 char *extra)
92 {
93 int err = 0;
94
95 switch (info->cmd) {
96 case SIOCGIWNAME:
97 strcpy(wrqu->name, "IEEE 802.11-DS");
98 break;
99 case SIOCGIWFREQ:
100 {
101 channel_info_t ci;
102 wl_ioctl(dev,WLC_GET_CHANNEL, &ci, sizeof(ci));
103 wrqu->freq.m = ci.target_channel;
104 wrqu->freq.e = 0;
105 break;
106 }
107 case SIOCGIWAP:
108 {
109 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
110 wl_ioctl(dev,WLC_GET_BSSID,wrqu->ap_addr.sa_data,6);
111 break;
112 }
113 case SIOCGIWESSID:
114 {
115 wlc_ssid_t ssid;
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);
120 break;
121 }
122 case SIOCSIWESSID:
123 {
124 wlc_ssid_t ssid;
125 memset(&ssid, 0, sizeof(ssid));
126 ssid.SSID_len = strlen(extra);
127 if (ssid.SSID_len > WLC_ESSID_MAX_SIZE)
128 ssid.SSID_len = WLC_ESSID_MAX_SIZE;
129 memcpy(ssid.SSID, extra, ssid.SSID_len);
130 wl_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid));
131 break;
132 }
133 case SIOCGIWRTS:
134 {
135 wl_ioctl(dev,WLC_GET_RTS,&(wrqu->rts.value),sizeof(int));
136 break;
137 }
138 case SIOCGIWFRAG:
139 {
140 wl_ioctl(dev,WLC_GET_FRAG,&(wrqu->frag.value),sizeof(int));
141 break;
142 }
143 case SIOCGIWTXPOW:
144 {
145 wrqu->txpower.value = 0;
146 wl_ioctl(dev,WLC_GET_TXPWR, &(wrqu->txpower.value), sizeof(int));
147 wrqu->txpower.fixed = 0;
148 wrqu->txpower.disabled = 0;
149 wrqu->txpower.flags = IW_TXPOW_MWATT;
150 break;
151 }
152 case SIOCGIWENCODE:
153 {
154 wrqu->data.flags = IW_ENCODE_DISABLED;
155 break;
156 }
157 case SIOCGIWRANGE:
158 {
159 err = wlcompat_ioctl_getiwrange(dev, extra);
160 break;
161 }
162 default:
163 {
164 err = -EINVAL;
165 break;
166 }
167 }
168
169 return err;
170 }
171
172 static const iw_handler wlcompat_handler[] = {
173 NULL, /* SIOCSIWCOMMIT */
174 wlcompat_ioctl, /* SIOCGIWNAME */
175 NULL, /* SIOCSIWNWID */
176 NULL, /* SIOCGIWNWID */
177 NULL, /* SIOCSIWFREQ */
178 wlcompat_ioctl, /* SIOCGIWFREQ */
179 NULL, /* SIOCSIWMODE */
180 NULL, /* SIOCGIWMODE */
181 NULL, /* SIOCSIWSENS */
182 NULL, /* SIOCGIWSENS */
183 NULL, /* SIOCSIWRANGE */
184 wlcompat_ioctl, /* SIOCGIWRANGE */
185 NULL, /* SIOCSIWPRIV */
186 NULL, /* SIOCGIWPRIV */
187 NULL, /* SIOCSIWSTATS */
188 NULL, /* SIOCGIWSTATS */
189 iw_handler_set_spy, /* SIOCSIWSPY */
190 iw_handler_get_spy, /* SIOCGIWSPY */
191 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
192 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
193 NULL, /* SIOCSIWAP */
194 wlcompat_ioctl, /* SIOCGIWAP */
195 NULL, /* -- hole -- */
196 NULL, /* SIOCGIWAPLIST */
197 NULL, /* -- hole -- */
198 NULL, /* -- hole -- */
199 wlcompat_ioctl, /* SIOCSIWESSID */
200 wlcompat_ioctl, /* SIOCGIWESSID */
201 NULL, /* SIOCSIWNICKN */
202 NULL, /* SIOCGIWNICKN */
203 NULL, /* -- hole -- */
204 NULL, /* -- hole -- */
205 NULL, /* SIOCSIWRATE */
206 NULL, /* SIOCGIWRATE */
207 NULL, /* SIOCSIWRTS */
208 wlcompat_ioctl, /* SIOCGIWRTS */
209 NULL, /* SIOCSIWFRAG */
210 wlcompat_ioctl, /* SIOCGIWFRAG */
211 NULL, /* SIOCSIWTXPOW */
212 wlcompat_ioctl, /* SIOCGIWTXPOW */
213 NULL, /* SIOCSIWRETRY */
214 NULL, /* SIOCGIWRETRY */
215 NULL, /* SIOCSIWENCODE */
216 wlcompat_ioctl, /* SIOCGIWENCODE */
217 };
218
219 static const struct iw_handler_def wlcompat_handler_def =
220 {
221 .standard = (iw_handler *) wlcompat_handler,
222 .num_standard = sizeof(wlcompat_handler)/sizeof(iw_handler),
223 .private = NULL,
224 .num_private = 0,
225 .private_args = NULL,
226 .num_private_args = 0,
227 };
228
229 #ifdef DEBUG
230 static int (*old_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
231 static int new_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) {
232 int ret = old_ioctl(dev,ifr,cmd);
233 printk("dev: %s ioctl: 0x%04x\n",dev->name,cmd);
234 if (cmd==SIOCDEVPRIVATE) {
235 int x;
236 wl_ioctl_t *ioc = (wl_ioctl_t *)ifr->ifr_data;
237 unsigned char *buf = ioc->buf;
238 printk(" cmd: %d buf: 0x%08x len: %d\n",ioc->cmd,&(ioc->buf),ioc->len);
239 printk(" ->");
240 for (x=0;x<ioc->len && x<128 ;x++) {
241 printk("%02X",buf[x]);
242 }
243 printk("\n");
244 }
245 return ret;
246 }
247 #endif
248
249 static int __init wlcompat_init()
250 {
251 dev = dev_get_by_name("eth1");
252 #ifdef DEBUG
253 old_ioctl = dev->do_ioctl;
254 dev->do_ioctl = new_ioctl;
255 #endif
256 dev->wireless_handlers = (struct iw_handler_def *)&wlcompat_handler_def;
257 return 0;
258 }
259
260 static void __exit wlcompat_exit()
261 {
262 dev->wireless_handlers = NULL;
263 #ifdef DEBUG
264 dev->do_ioctl = old_ioctl;
265 #endif
266 return;
267 }
268
269 EXPORT_NO_SYMBOLS;
270 MODULE_AUTHOR("openwrt.org");
271 MODULE_LICENSE("GPL");
272
273 module_init(wlcompat_init);
274 module_exit(wlcompat_exit);
This page took 0.052349 seconds and 5 git commands to generate.