blob: ce04218253dd63cf37b81c449d628ddaf99c17d1 [file] [log] [blame]
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001/*
2 * Copyright (c) 2007-2008 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/* */
17/* Module Name : ioctl.c */
18/* */
19/* Abstract */
20/* This module contains Linux wireless extension related functons. */
21/* */
22/* NOTES */
23/* Platform dependent. */
24/* */
25/************************************************************************/
26#include <linux/module.h>
27#include <linux/if_arp.h>
Dragoslav Zaricaef911a2009-03-16 23:17:47 +010028#include <linux/uaccess.h>
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -070029
30#include "usbdrv.h"
31
32#define ZD_IOCTL_WPA (SIOCDEVPRIVATE + 1)
33#define ZD_IOCTL_PARAM (SIOCDEVPRIVATE + 2)
34#define ZD_IOCTL_GETWPAIE (SIOCDEVPRIVATE + 3)
35#ifdef ZM_ENABLE_CENC
36#define ZM_IOCTL_CENC (SIOCDEVPRIVATE + 4)
Dragoslav Zaricaef911a2009-03-16 23:17:47 +010037#endif /* ZM_ENABLE_CENC */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -070038#define ZD_PARAM_ROAMING 0x0001
39#define ZD_PARAM_PRIVACY 0x0002
40#define ZD_PARAM_WPA 0x0003
41#define ZD_PARAM_COUNTERMEASURES 0x0004
42#define ZD_PARAM_DROPUNENCRYPTED 0x0005
43#define ZD_PARAM_AUTH_ALGS 0x0006
44#define ZD_PARAM_WPS_FILTER 0x0007
45
46#ifdef ZM_ENABLE_CENC
47#define P80211_PACKET_CENCFLAG 0x0001
Dragoslav Zaricaef911a2009-03-16 23:17:47 +010048#endif /* ZM_ENABLE_CENC */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -070049#define P80211_PACKET_SETKEY 0x0003
50
51#define ZD_CMD_SET_ENCRYPT_KEY 0x0001
52#define ZD_CMD_SET_MLME 0x0002
53#define ZD_CMD_SCAN_REQ 0x0003
54#define ZD_CMD_SET_GENERIC_ELEMENT 0x0004
55#define ZD_CMD_GET_TSC 0x0005
56
57#define ZD_CRYPT_ALG_NAME_LEN 16
58#define ZD_MAX_KEY_SIZE 32
59#define ZD_MAX_GENERIC_SIZE 64
60
61#if WIRELESS_EXT > 12
62#include <net/iw_handler.h>
63#endif
64
Dragoslav Zaricaef911a2009-03-16 23:17:47 +010065extern u16_t zfLnxGetVapId(zdev_t *dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -070066
67static const u32_t channel_frequency_11A[] =
68{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +010069 /* Even element for Channel Number, Odd for Frequency */
70 36, 5180,
71 40, 5200,
72 44, 5220,
73 48, 5240,
74 52, 5260,
75 56, 5280,
76 60, 5300,
77 64, 5320,
78 100, 5500,
79 104, 5520,
80 108, 5540,
81 112, 5560,
82 116, 5580,
83 120, 5600,
84 124, 5620,
85 128, 5640,
86 132, 5660,
87 136, 5680,
88 140, 5700,
89 /**/
90 184, 4920,
91 188, 4940,
92 192, 4960,
93 196, 4980,
94 8, 5040,
95 12, 5060,
96 16, 5080,
97 34, 5170,
98 38, 5190,
99 42, 5210,
100 46, 5230,
101 /**/
102 149, 5745,
103 153, 5765,
104 157, 5785,
105 161, 5805,
106 165, 5825
107 /**/
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700108};
109
110int usbdrv_freq2chan(u32_t freq)
111{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100112 /* 2.4G Hz */
113 if (freq > 2400 && freq < 3000) {
114 return ((freq-2412)/5) + 1;
115 } else {
116 u16_t ii;
117 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700118
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100119 for (ii = 1; ii < num_chan; ii += 2) {
120 if (channel_frequency_11A[ii] == freq)
121 return channel_frequency_11A[ii-1];
122 }
123 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700124
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100125 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700126}
127
128int usbdrv_chan2freq(int chan)
129{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100130 int freq;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700131
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100132 /* If channel number is out of range */
133 if (chan > 165 || chan <= 0)
134 return -1;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700135
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100136 /* 2.4G band */
137 if (chan >= 1 && chan <= 13) {
138 freq = (2412 + (chan - 1) * 5);
139 return freq;
140 } else if (chan >= 36 && chan <= 165) {
141 u16_t ii;
142 u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700143
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100144 for (ii = 0; ii < num_chan; ii += 2) {
145 if (channel_frequency_11A[ii] == chan)
146 return channel_frequency_11A[ii+1];
147 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700148
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100149 /* Can't find desired frequency */
150 if (ii == num_chan)
151 return -1;
152 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700153
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100154 /* Can't find deisred frequency */
155 return -1;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700156}
157
158int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
159{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100160 #ifdef ZM_HOSTAPD_SUPPORT
161 /* struct usbdrv_private *macp = dev->ml_priv; */
162 char essidbuf[IW_ESSID_MAX_SIZE+1];
163 int i;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700164
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100165 if (!netif_running(dev))
166 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700167
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100168 memset(essidbuf, 0, sizeof(essidbuf));
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700169
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100170 printk(KERN_ERR "usbdrv_ioctl_setessid\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700171
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100172 /* printk("ssidlen=%d\n", erq->length); //for any, it is 1. */
173 if (erq->flags) {
174 if (erq->length > (IW_ESSID_MAX_SIZE+1))
175 return -E2BIG;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700176
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100177 if (copy_from_user(essidbuf, erq->pointer, erq->length))
178 return -EFAULT;
179 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700180
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100181 /* zd_DisasocAll(2); */
182 /* wait_ms(100); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700183
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100184 printk(KERN_ERR "essidbuf: ");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700185
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100186 for (i = 0; i < erq->length; i++)
187 printk(KERN_ERR "%02x ", essidbuf[i]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700188
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100189 printk(KERN_ERR "\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700190
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100191 essidbuf[erq->length] = '\0';
192 /* memcpy(macp->wd.ws.ssid, essidbuf, erq->length); */
193 /* macp->wd.ws.ssidLen = strlen(essidbuf)+2; */
194 /* macp->wd.ws.ssid[1] = strlen(essidbuf); Update ssid length */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700195
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100196 zfiWlanSetSSID(dev, essidbuf, erq->length);
197 #if 0
198 printk(KERN_ERR "macp->wd.ws.ssid: ");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700199
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100200 for (i = 0; i < macp->wd.ws.ssidLen; i++)
201 printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700202
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100203 printk(KERN_ERR "\n");
204 #endif
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700205
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100206 zfiWlanDisable(dev, 0);
207 zfiWlanEnable(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700208
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100209 #endif
210
211 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700212}
213
214int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
215{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100216 /* struct usbdrv_private *macp = dev->ml_priv; */
217 u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
218 u8_t len;
219 u8_t i;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700220
221
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100222 /* len = macp->wd.ws.ssidLen; */
223 /* memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen); */
224 zfiWlanQuerySSID(dev, essidbuf, &len);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700225
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100226 essidbuf[len] = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700227
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100228 printk(KERN_ERR "ESSID: ");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700229
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100230 for (i = 0; i < len; i++)
231 printk(KERN_ERR "%c", essidbuf[i]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700232
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100233 printk(KERN_ERR "\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700234
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100235 erq->flags = 1;
236 erq->length = strlen(essidbuf) + 1;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700237
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100238 if (erq->pointer) {
239 if (copy_to_user(erq->pointer, essidbuf, erq->length))
240 return -EFAULT;
241 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700242
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100243 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700244}
245
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700246int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
247{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100248 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700249}
250
251#if WIRELESS_EXT > 14
252/*
253 * Encode a WPA or RSN information element as a custom
254 * element using the hostap format.
255 */
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100256u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen,
257 const u8 *leader, u32 leader_len)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700258{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100259 u8 *p;
260 u32 i;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700261
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100262 if (bufsize < leader_len)
263 return 0;
264 p = buf;
265 memcpy(p, leader, leader_len);
266 bufsize -= leader_len;
267 p += leader_len;
268 for (i = 0; i < ielen && bufsize > 2; i++)
269 p += sprintf(p, "%02x", ie[i]);
270 return (i == ielen ? p - (u8 *)buf:0);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700271}
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100272#endif /* WIRELESS_EXT > 14 */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700273
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700274/*
275 * Translate scan data returned from the card to a card independent
276 * format that the Wireless Tools will understand
277 */
278char *usbdrv_translate_scan(struct net_device *dev,
279 struct iw_request_info *info, char *current_ev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100280 char *end_buf, struct zsBssInfo *list)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700281{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100282 struct iw_event iwe; /* Temporary buffer */
283 u16_t capabilities;
284 char *current_val; /* For rates */
285 char *last_ev;
286 int i;
287 #if WIRELESS_EXT > 14
288 char buf[64*2 + 30];
289 #endif
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700290
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100291 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700292
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100293 /* First entry *MUST* be the AP MAC address */
294 iwe.cmd = SIOCGIWAP;
295 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
296 memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
297 current_ev = iwe_stream_add_event(info, current_ev,
298 end_buf, &iwe, IW_EV_ADDR_LEN);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700299
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100300 /* Ran out of buffer */
301 if (last_ev == current_ev)
302 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700303
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100304 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700305
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100306 /* Other entries will be displayed in the order we give them */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700307
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100308 /* Add the ESSID */
309 iwe.u.data.length = list->ssid[1];
310 if (iwe.u.data.length > 32)
311 iwe.u.data.length = 32;
312 iwe.cmd = SIOCGIWESSID;
313 iwe.u.data.flags = 1;
314 current_ev = iwe_stream_add_point(info, current_ev,
315 end_buf, &iwe, &list->ssid[2]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700316
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100317 /* Ran out of buffer */
318 if (last_ev == current_ev)
319 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700320
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100321 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700322
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100323 /* Add mode */
324 iwe.cmd = SIOCGIWMODE;
325 capabilities = (list->capability[1] << 8) + list->capability[0];
326 if (capabilities & (0x01 | 0x02)) {
327 if (capabilities & 0x01)
328 iwe.u.mode = IW_MODE_MASTER;
329 else
330 iwe.u.mode = IW_MODE_ADHOC;
331 current_ev = iwe_stream_add_event(info, current_ev,
332 end_buf, &iwe, IW_EV_UINT_LEN);
333 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700334
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100335 /* Ran out of buffer */
336 if (last_ev == current_ev)
337 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700338
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100339 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700340
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100341 /* Add frequency */
342 iwe.cmd = SIOCGIWFREQ;
343 iwe.u.freq.m = list->channel;
344 /* Channel frequency in KHz */
345 if (iwe.u.freq.m > 14) {
346 if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m <= 196))
347 iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
348 else
349 iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
350 } else {
351 if (iwe.u.freq.m == 14)
352 iwe.u.freq.m = 2484;
353 else
354 iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
355 }
356 iwe.u.freq.e = 6;
357 current_ev = iwe_stream_add_event(info, current_ev,
358 end_buf, &iwe, IW_EV_FREQ_LEN);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700359
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100360 /* Ran out of buffer */
361 if (last_ev == current_ev)
362 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700363
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100364 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700365
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100366 /* Add quality statistics */
367 iwe.cmd = IWEVQUAL;
368 #if WIRELESS_EXT > 18
369 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
370 | IW_QUAL_NOISE_UPDATED;
371 #endif
372 iwe.u.qual.level = list->signalStrength;
373 iwe.u.qual.noise = 0;
374 iwe.u.qual.qual = list->signalQuality;
375 current_ev = iwe_stream_add_event(info, current_ev,
376 end_buf, &iwe, IW_EV_QUAL_LEN);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700377
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100378 /* Ran out of buffer */
379 if (last_ev == current_ev)
380 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700381
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100382 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700383
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100384 /* Add encryption capability */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700385
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100386 iwe.cmd = SIOCGIWENCODE;
387 if (capabilities & 0x10)
388 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
389 else
390 iwe.u.data.flags = IW_ENCODE_DISABLED;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700391
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100392 iwe.u.data.length = 0;
393 current_ev = iwe_stream_add_point(info, current_ev,
394 end_buf, &iwe, list->ssid);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700395
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100396 /* Ran out of buffer */
397 if (last_ev == current_ev)
398 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700399
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100400 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700401
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100402 /* Rate : stuffing multiple values in a single event require a bit
403 * more of magic
404 */
405 current_val = current_ev + IW_EV_LCP_LEN;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700406
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100407 iwe.cmd = SIOCGIWRATE;
408 /* Those two flags are ignored... */
409 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700410
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100411 for (i = 0 ; i < list->supportedRates[1] ; i++) {
412 /* Bit rate given in 500 kb/s units (+ 0x80) */
413 iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f)
414 * 500000);
415 /* Add new value to event */
416 current_val = iwe_stream_add_value(info, current_ev,
417 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700418
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100419 /* Ran out of buffer */
420 if (last_ev == current_val)
421 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700422
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100423 last_ev = current_val;
424 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700425
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100426 for (i = 0 ; i < list->extSupportedRates[1] ; i++) {
427 /* Bit rate given in 500 kb/s units (+ 0x80) */
428 iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f)
429 * 500000);
430 /* Add new value to event */
431 current_val = iwe_stream_add_value(info, current_ev,
432 current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700433
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100434 /* Ran out of buffer */
435 if (last_ev == current_val)
436 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700437
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100438 last_ev = current_ev;
439 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700440
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100441 /* Check if we added any event */
442 if ((current_val - current_ev) > IW_EV_LCP_LEN)
443 current_ev = current_val;
444 #if WIRELESS_EXT > 14
445 #define IEEE80211_ELEMID_RSN 0x30
446 memset(&iwe, 0, sizeof(iwe));
447 iwe.cmd = IWEVCUSTOM;
448 snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8)
449 + list->beaconInterval[0]);
450 iwe.u.data.length = strlen(buf);
451 current_ev = iwe_stream_add_point(info, current_ev,
452 end_buf, &iwe, buf);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700453
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100454 /* Ran out of buffer */
455 if (last_ev == current_ev)
456 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700457
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100458 last_ev = current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700459
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100460 if (list->wpaIe[1] != 0) {
461 static const char rsn_leader[] = "rsn_ie=";
462 static const char wpa_leader[] = "wpa_ie=";
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700463
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100464 memset(&iwe, 0, sizeof(iwe));
465 iwe.cmd = IWEVCUSTOM;
466 if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
467 iwe.u.data.length = encode_ie(buf, sizeof(buf),
468 list->wpaIe, list->wpaIe[1]+2,
469 rsn_leader, sizeof(rsn_leader)-1);
470 else
471 iwe.u.data.length = encode_ie(buf, sizeof(buf),
472 list->wpaIe, list->wpaIe[1]+2,
473 wpa_leader, sizeof(wpa_leader)-1);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700474
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100475 if (iwe.u.data.length != 0)
476 current_ev = iwe_stream_add_point(info, current_ev,
477 end_buf, &iwe, buf);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700478
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100479 /* Ran out of buffer */
480 if (last_ev == current_ev)
481 return end_buf;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700482
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100483 last_ev = current_ev;
484 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700485
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100486 if (list->rsnIe[1] != 0) {
487 static const char rsn_leader[] = "rsn_ie=";
488 memset(&iwe, 0, sizeof(iwe));
489 iwe.cmd = IWEVCUSTOM;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700490
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100491 if (list->rsnIe[0] == IEEE80211_ELEMID_RSN) {
492 iwe.u.data.length = encode_ie(buf, sizeof(buf),
493 list->rsnIe, list->rsnIe[1]+2,
494 rsn_leader, sizeof(rsn_leader)-1);
495 if (iwe.u.data.length != 0)
496 current_ev = iwe_stream_add_point(info,
497 current_ev, end_buf, &iwe, buf);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700498
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100499 /* Ran out of buffer */
500 if (last_ev == current_ev)
501 return end_buf;
502
503 last_ev = current_ev;
504 }
505 }
506 #endif
507 /* The other data in the scan result are not really
508 * interesting, so for now drop it
509 */
510 return current_ev;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700511}
512
513int usbdrvwext_giwname(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100514 struct iw_request_info *info,
515 union iwreq_data *wrq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700516{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100517 /* struct usbdrv_private *macp = dev->ml_priv; */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700518
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100519 strcpy(wrq->name, "IEEE 802.11-MIMO");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700520
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100521 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700522}
523
524int usbdrvwext_siwfreq(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100525 struct iw_request_info *info,
526 struct iw_freq *freq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700527{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100528 u32_t FreqKHz;
529 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700530
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100531 if (!netif_running(dev))
532 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700533
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100534 if (freq->e > 1)
535 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700536
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100537 if (freq->e == 1) {
538 FreqKHz = (freq->m / 100000);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700539
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100540 if (FreqKHz > 4000000) {
541 if (FreqKHz > 5825000)
542 FreqKHz = 5825000;
543 else if (FreqKHz < 4920000)
544 FreqKHz = 4920000;
545 else if (FreqKHz < 5000000)
546 FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000)
547 + 4000000;
548 else
549 FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000)
550 + 5000000;
551 } else {
552 if (FreqKHz > 2484000)
553 FreqKHz = 2484000;
554 else if (FreqKHz < 2412000)
555 FreqKHz = 2412000;
556 else
557 FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000)
558 + 2412000;
559 }
560 } else {
561 FreqKHz = usbdrv_chan2freq(freq->m);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700562
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100563 if (FreqKHz != -1)
564 FreqKHz *= 1000;
565 else
566 FreqKHz = 2412000;
567 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700568
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100569 /* printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e); */
570 /* printk("FreqKHz: %d\n", FreqKHz); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700571
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100572 if (macp->DeviceOpened == 1) {
573 zfiWlanSetFrequency(dev, FreqKHz, 0); /* Immediate */
574 /* u8_t wpaieLen,wpaie[50]; */
575 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
576 zfiWlanDisable(dev, 0);
577 zfiWlanEnable(dev);
578 /* if (wpaieLen > 2) */
579 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
580 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700581
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100582 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700583}
584
585int usbdrvwext_giwfreq(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100586 struct iw_request_info *info,
587 struct iw_freq *freq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700588{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100589 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700590
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100591 if (macp->DeviceOpened != 1)
592 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700593
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100594 freq->m = zfiWlanQueryFrequency(dev);
595 freq->e = 3;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700596
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100597 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700598}
599
600int usbdrvwext_siwmode(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100601 struct iw_request_info *info,
602 union iwreq_data *wrq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700603{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100604 struct usbdrv_private *macp = dev->ml_priv;
605 u8_t WlanMode;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700606
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100607 if (!netif_running(dev))
608 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700609
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100610 if (macp->DeviceOpened != 1)
611 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700612
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100613 switch (wrq->mode) {
614 case IW_MODE_MASTER:
615 WlanMode = ZM_MODE_AP;
616 break;
617 case IW_MODE_INFRA:
618 WlanMode = ZM_MODE_INFRASTRUCTURE;
619 break;
620 case IW_MODE_ADHOC:
621 WlanMode = ZM_MODE_IBSS;
622 break;
623 default:
624 WlanMode = ZM_MODE_IBSS;
625 break;
626 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700627
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100628 zfiWlanSetWlanMode(dev, WlanMode);
629 zfiWlanDisable(dev, 1);
630 zfiWlanEnable(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700631
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100632 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700633}
634
635int usbdrvwext_giwmode(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100636 struct iw_request_info *info,
637 __u32 *mode, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700638{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100639 unsigned long irqFlag;
640 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700641
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100642 if (!netif_running(dev))
643 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700644
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100645 if (macp->DeviceOpened != 1)
646 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700647
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100648 spin_lock_irqsave(&macp->cs_lock, irqFlag);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700649
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100650 switch (zfiWlanQueryWlanMode(dev)) {
651 case ZM_MODE_AP:
652 *mode = IW_MODE_MASTER;
653 break;
654 case ZM_MODE_INFRASTRUCTURE:
655 *mode = IW_MODE_INFRA;
656 break;
657 case ZM_MODE_IBSS:
658 *mode = IW_MODE_ADHOC;
659 break;
660 default:
661 *mode = IW_MODE_ADHOC;
662 break;
663 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700664
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100665 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700666
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100667 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700668}
669
670int usbdrvwext_siwsens(struct net_device *dev,
671 struct iw_request_info *info,
672 struct iw_param *sens, char *extra)
673{
674 return 0;
675}
676
677int usbdrvwext_giwsens(struct net_device *dev,
678 struct iw_request_info *info,
679 struct iw_param *sens, char *extra)
680{
681 sens->value = 0;
682 sens->fixed = 1;
683
684 return 0;
685}
686
687int usbdrvwext_giwrange(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100688 struct iw_request_info *info,
689 struct iw_point *data, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700690{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100691 struct iw_range *range = (struct iw_range *) extra;
692 int i, val;
693 /* int num_band_a; */
694 u16_t channels[60];
695 u16_t channel_num;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700696
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100697 if (!netif_running(dev))
698 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700699
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100700 #if WIRELESS_EXT > 9
701 range->txpower_capa = IW_TXPOW_DBM;
702 /* XXX what about min/max_pmp, min/max_pmt, etc. */
703 #endif
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700704
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100705 #if WIRELESS_EXT > 10
706 range->we_version_compiled = WIRELESS_EXT;
707 range->we_version_source = 13;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700708
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100709 range->retry_capa = IW_RETRY_LIMIT;
710 range->retry_flags = IW_RETRY_LIMIT;
711 range->min_retry = 0;
712 range->max_retry = 255;
713 #endif /* WIRELESS_EXT > 10 */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700714
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100715 channel_num = zfiWlanQueryAllowChannels(dev, channels);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700716
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100717 /* Gurantee reported channel numbers is less
718 * or equal to IW_MAX_FREQUENCIES
719 */
720 if (channel_num > IW_MAX_FREQUENCIES)
721 channel_num = IW_MAX_FREQUENCIES;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700722
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100723 val = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700724
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100725 for (i = 0; i < channel_num; i++) {
726 range->freq[val].i = usbdrv_freq2chan(channels[i]);
727 range->freq[val].m = channels[i];
728 range->freq[val].e = 6;
729 val++;
730 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700731
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100732 range->num_channels = channel_num;
733 range->num_frequency = channel_num;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700734
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100735 #if 0
736 range->num_channels = 14; /* Only 2.4G */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700737
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100738 /* XXX need to filter against the regulatory domain &| active set */
739 val = 0;
740 /* B,G Bands */
741 for (i = 1; i <= 14; i++) {
742 range->freq[val].i = i;
743 if (i == 14)
744 range->freq[val].m = 2484000;
745 else
746 range->freq[val].m = (2412+(i-1)*5)*1000;
747 range->freq[val].e = 3;
748 val++;
749 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700750
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100751 num_band_a = (IW_MAX_FREQUENCIES - val);
752 /* A Bands */
753 for (i = 0; i < num_band_a; i++) {
754 range->freq[val].i = channel_frequency_11A[2 * i];
755 range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
756 range->freq[val].e = 3;
757 val++;
758 }
759 /* MIMO Rate Not Defined Now
760 * For 802.11a, there are too more frequency.
761 * We can't return them all.
762 */
763 range->num_frequency = val;
764 #endif
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700765
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100766 /* Max of /proc/net/wireless */
767 range->max_qual.qual = 100; /* ?? 92; */
768 range->max_qual.level = 154; /* ?? */
769 range->max_qual.noise = 154; /* ?? */
770 range->sensitivity = 3; /* ?? */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700771
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100772 /* XXX these need to be nsd-specific! */
773 range->min_rts = 0;
774 range->max_rts = 2347;
775 range->min_frag = 256;
776 range->max_frag = 2346;
777 range->max_encoding_tokens = 4 /* NUM_WEPKEYS ?? */;
778 range->num_encoding_sizes = 2; /* ?? */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700779
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100780 range->encoding_size[0] = 5; /* ?? WEP Key Encoding Size */
781 range->encoding_size[1] = 13; /* ?? */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700782
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100783 /* XXX what about num_bitrates/throughput? */
784 range->num_bitrates = 0; /* ?? */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700785
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100786 /* estimated max throughput
787 * XXX need to cap it if we're running at ~2Mbps..
788 */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700789
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100790 range->throughput = 300000000;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700791
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100792 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700793}
794
795int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100796 struct sockaddr *MacAddr, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700797{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100798 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700799
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100800 if (!netif_running(dev))
801 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700802
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100803 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
804 /* AP Mode */
805 zfiWlanSetMacAddress(dev, (u16_t *)&MacAddr->sa_data[0]);
806 } else {
807 /* STA Mode */
808 zfiWlanSetBssid(dev, &MacAddr->sa_data[0]);
809 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700810
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100811 if (macp->DeviceOpened == 1) {
812 /* u8_t wpaieLen,wpaie[80]; */
813 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
814 zfiWlanDisable(dev, 0);
815 zfiWlanEnable(dev);
816 /* if (wpaieLen > 2) */
817 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
818 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700819
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100820 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700821}
822
823int usbdrvwext_giwap(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100824 struct iw_request_info *info,
825 struct sockaddr *MacAddr, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700826{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100827 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700828
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100829 if (macp->DeviceOpened != 1)
830 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700831
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100832 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
833 /* AP Mode */
834 zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
835 } else {
836 /* STA Mode */
837 if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT) {
838 zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
839 } else {
840 u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00,
841 0x00, 0x00 };
842 memcpy(&MacAddr->sa_data[0], zero_addr,
843 sizeof(zero_addr));
844 }
845 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700846
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100847 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700848}
849
850int usbdrvwext_iwaplist(struct net_device *dev,
851 struct iw_request_info *info,
852 struct iw_point *data, char *extra)
853{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100854 /* Don't know how to do yet--CWYang(+) */
855 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700856
857}
858
859int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100860 struct iw_point *data, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700861{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100862 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700863
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100864 if (macp->DeviceOpened != 1)
865 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700866
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100867 printk(KERN_WARNING "CWY - usbdrvwext_siwscan\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700868
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100869 zfiWlanScan(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700870
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100871 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700872}
873
874int usbdrvwext_giwscan(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100875 struct iw_request_info *info,
876 struct iw_point *data, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700877{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100878 struct usbdrv_private *macp = dev->ml_priv;
879 /* struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev); */
880 char *current_ev = extra;
881 char *end_buf;
882 int i;
883 /* struct zsBssList BssList; */
884 struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1),
885 GFP_KERNEL);
886 /* BssList = wd->sta.pBssList; */
887 /* zmw_get_wlan_dev(dev); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700888
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100889 if (macp->DeviceOpened != 1)
890 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700891
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100892 if (data->length == 0)
893 end_buf = extra + IW_SCAN_MAX_DATA;
894 else
895 end_buf = extra + data->length;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700896
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100897 printk(KERN_WARNING "giwscan - Report Scan Results\n");
898 /* printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
899 * printk("giwscan - BssList Count : %d\n",
900 * wd->sta.pBssList->bssCount);
901 * printk("giwscan - UpdateBssList Count : %d\n",
902 * wd->sta.pUpdateBssList->bssCount);
903 */
904 zfiWlanQueryBssListV1(dev, pBssList);
905 /* zfiWlanQueryBssList(dev, &BssList); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700906
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100907 /* Read and parse all entries */
908 printk(KERN_WARNING "giwscan - pBssList->bssCount : %d\n",
909 pBssList->bssCount);
910 /* printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700911
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100912 for (i = 0; i < pBssList->bssCount; i++) {
913 /* Translate to WE format this entry
914 * current_ev = usbdrv_translate_scan(dev, info, current_ev,
915 * extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
916 */
917 current_ev = usbdrv_translate_scan(dev, info, current_ev,
918 end_buf, &pBssList->bssInfo[i]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700919
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100920 #if WIRELESS_EXT > 16
921 if (current_ev == end_buf) {
922 kfree(pBssList);
923 data->length = current_ev - extra;
924 return -E2BIG;
925 }
926 #endif
927 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700928
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100929 /* Length of data */
930 data->length = (current_ev - extra);
931 data->flags = 0; /* todo */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700932
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100933 kfree(pBssList);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700934
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100935 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700936}
937
938int usbdrvwext_siwessid(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100939 struct iw_request_info *info,
940 struct iw_point *essid, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700941{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100942 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
943 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700944
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100945 if (!netif_running(dev))
946 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700947
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100948 if (essid->flags == 1) {
949 if (essid->length > (IW_ESSID_MAX_SIZE + 1))
950 return -E2BIG;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700951
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100952 if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
953 return -EFAULT;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700954
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100955 EssidBuf[essid->length] = '\0';
956 /* printk("siwessid - Set Essid : %s\n",EssidBuf); */
957 /* printk("siwessid - Essid Len : %d\n",essid->length); */
958 /* printk("siwessid - Essid Flag : %x\n",essid->flags); */
959 if (macp->DeviceOpened == 1) {
960 zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
961 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev),
962 FALSE);
963 zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
964 /* u8_t wpaieLen,wpaie[50]; */
965 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
966 zfiWlanDisable(dev, 0);
967 zfiWlanEnable(dev);
968 /* if (wpaieLen > 2) */
969 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
970 }
971 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700972
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100973 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700974}
975
976int usbdrvwext_giwessid(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100977 struct iw_request_info *info,
978 struct iw_point *essid, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700979{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100980 struct usbdrv_private *macp = dev->ml_priv;
981 u8_t EssidLen;
982 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
983 int ssid_len;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700984
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100985 if (!netif_running(dev))
986 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700987
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100988 if (macp->DeviceOpened != 1)
989 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700990
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100991 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700992
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100993 /* Convert type from unsigned char to char */
994 ssid_len = (int)EssidLen;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700995
Dragoslav Zaricaef911a2009-03-16 23:17:47 +0100996 /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
997 if (ssid_len > IW_ESSID_MAX_SIZE)
998 ssid_len = IW_ESSID_MAX_SIZE;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -0700999
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001000 EssidBuf[ssid_len] = '\0';
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001001
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001002 essid->flags = 1;
1003 essid->length = strlen(EssidBuf);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001004
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001005 memcpy(extra, EssidBuf, essid->length);
1006 /* wireless.c in Kernel would handle copy_to_user -- line 679 */
1007 /* if (essid->pointer) {
1008 * if (copy_to_user(essid->pointer, EssidBuf, essid->length)) {
1009 * printk("giwessid - copy_to_user Fail\n");
1010 * return -EFAULT;
1011 * }
1012 * }
1013 */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001014
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001015 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001016}
1017
1018int usbdrvwext_siwnickn(struct net_device *dev,
1019 struct iw_request_info *info,
1020 struct iw_point *data, char *nickname)
1021{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001022 /* Exist but junk--CWYang(+) */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001023 return 0;
1024}
1025
1026int usbdrvwext_giwnickn(struct net_device *dev,
1027 struct iw_request_info *info,
1028 struct iw_point *data, char *nickname)
1029{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001030 struct usbdrv_private *macp = dev->ml_priv;
1031 u8_t EssidLen;
1032 char EssidBuf[IW_ESSID_MAX_SIZE + 1];
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001033
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001034 if (macp->DeviceOpened != 1)
1035 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001036
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001037 zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1038 EssidBuf[EssidLen] = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001039
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001040 data->flags = 1;
1041 data->length = strlen(EssidBuf);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001042
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001043 memcpy(nickname, EssidBuf, data->length);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001044
1045 return 0;
1046}
1047
1048int usbdrvwext_siwrate(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001049 struct iw_request_info *info,
1050 struct iw_param *frq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001051{
Greg Kroah-Hartmanda3e8902009-01-05 13:44:36 -08001052 struct usbdrv_private *macp = dev->ml_priv;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001053 /* Array to Define Rate Number that Send to Driver */
1054 u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0,
1055 48000, 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1056 u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1057 0x8, 0xc};
1058 u8_t i, RateIndex = 4;
1059 u16_t RateKbps;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001060
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001061 /* printk("frq->disabled : 0x%x\n",frq->disabled); */
1062 /* printk("frq->value : 0x%x\n",frq->value); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001063
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001064 RateKbps = frq->value / 1000;
1065 /* printk("RateKbps : %d\n", RateKbps); */
1066 for (i = 0; i < 16; i++) {
1067 if (RateKbps == zcIndextoRateBG[i])
1068 RateIndex = i;
1069 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001070
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001071 if (zcIndextoRateBG[RateIndex] == 0)
1072 RateIndex = 0xff;
1073 /* printk("RateIndex : %x\n", RateIndex); */
1074 for (i = 0; i < 13; i++)
1075 if (RateIndex == zcRateToMCS[i])
1076 break;
1077 /* printk("Index : %x\n", i); */
1078 if (RateKbps == 65000) {
1079 RateIndex = 20;
1080 printk(KERN_WARNING "RateIndex : %d\n", RateIndex);
1081 }
1082
1083 if (macp->DeviceOpened == 1) {
1084 zfiWlanSetTxRate(dev, i);
1085 /* zfiWlanDisable(dev); */
1086 /* zfiWlanEnable(dev); */
1087 }
1088
1089 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001090}
1091
1092int usbdrvwext_giwrate(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001093 struct iw_request_info *info,
1094 struct iw_param *frq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001095{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001096 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001097
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001098 if (!netif_running(dev))
1099 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001100
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001101 if (macp->DeviceOpened != 1)
1102 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001103
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001104 frq->fixed = 0;
1105 frq->disabled = 0;
1106 frq->value = zfiWlanQueryRxRate(dev) * 1000;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001107
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001108 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001109}
1110
1111int usbdrvwext_siwrts(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001112 struct iw_request_info *info,
1113 struct iw_param *rts, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001114{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001115 struct usbdrv_private *macp = dev->ml_priv;
1116 int val = rts->value;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001117
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001118 if (macp->DeviceOpened != 1)
1119 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001120
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001121 if (rts->disabled)
1122 val = 2347;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001123
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001124 if ((val < 0) || (val > 2347))
1125 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001126
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001127 zfiWlanSetRtsThreshold(dev, val);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001128
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001129 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001130}
1131
1132int usbdrvwext_giwrts(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001133 struct iw_request_info *info,
1134 struct iw_param *rts, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001135{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001136 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001137
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001138 if (!netif_running(dev))
1139 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001140
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001141 if (macp->DeviceOpened != 1)
1142 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001143
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001144 rts->value = zfiWlanQueryRtsThreshold(dev);
1145 rts->disabled = (rts->value >= 2347);
1146 rts->fixed = 1;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001147
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001148 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001149}
1150
1151int usbdrvwext_siwfrag(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001152 struct iw_request_info *info,
1153 struct iw_param *frag, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001154{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001155 struct usbdrv_private *macp = dev->ml_priv;
1156 u16_t fragThreshold;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001157
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001158 if (macp->DeviceOpened != 1)
1159 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001160
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001161 if (frag->disabled)
1162 fragThreshold = 0;
1163 else
1164 fragThreshold = frag->value;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001165
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001166 zfiWlanSetFragThreshold(dev, fragThreshold);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001167
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001168 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001169}
1170
1171int usbdrvwext_giwfrag(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001172 struct iw_request_info *info,
1173 struct iw_param *frag, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001174{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001175 struct usbdrv_private *macp = dev->ml_priv;
1176 u16 val;
1177 unsigned long irqFlag;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001178
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001179 if (!netif_running(dev))
1180 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001181
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001182 if (macp->DeviceOpened != 1)
1183 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001184
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001185 spin_lock_irqsave(&macp->cs_lock, irqFlag);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001186
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001187 val = zfiWlanQueryFragThreshold(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001188
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001189 frag->value = val;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001190
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001191 frag->disabled = (val >= 2346);
1192 frag->fixed = 1;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001193
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001194 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001195
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001196 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001197}
1198
1199int usbdrvwext_siwtxpow(struct net_device *dev,
1200 struct iw_request_info *info,
1201 struct iw_param *rrq, char *extra)
1202{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001203 /* Not support yet--CWYng(+) */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001204 return 0;
1205}
1206
1207int usbdrvwext_giwtxpow(struct net_device *dev,
1208 struct iw_request_info *info,
1209 struct iw_param *rrq, char *extra)
1210{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001211 /* Not support yet--CWYng(+) */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001212 return 0;
1213}
1214
1215int usbdrvwext_siwretry(struct net_device *dev,
1216 struct iw_request_info *info,
1217 struct iw_param *rrq, char *extra)
1218{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001219 /* Do nothing--CWYang(+) */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001220 return 0;
1221}
1222
1223int usbdrvwext_giwretry(struct net_device *dev,
1224 struct iw_request_info *info,
1225 struct iw_param *rrq, char *extra)
1226{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001227 /* Do nothing--CWYang(+) */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001228 return 0;
1229}
1230
1231int usbdrvwext_siwencode(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001232 struct iw_request_info *info,
1233 struct iw_point *erq, char *key)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001234{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001235 struct zsKeyInfo keyInfo;
1236 int i;
1237 int WepState = ZM_ENCRYPTION_WEP_DISABLED;
1238 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001239
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001240 if (!netif_running(dev))
1241 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001242
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001243 if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
1244 keyInfo.key = key;
1245 keyInfo.keyLength = erq->length;
1246 keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1247 if (keyInfo.keyIndex >= 4)
1248 keyInfo.keyIndex = 0;
1249 keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001250
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001251 zfiWlanSetKey(dev, keyInfo);
1252 WepState = ZM_ENCRYPTION_WEP_ENABLED;
1253 } else {
1254 for (i = 1; i < 4; i++)
1255 zfiWlanRemoveKey(dev, 0, i);
1256 WepState = ZM_ENCRYPTION_WEP_DISABLED;
1257 /* zfiWlanSetEncryMode(dev, ZM_NO_WEP); */
1258 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001259
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001260 if (macp->DeviceOpened == 1) {
1261 zfiWlanSetWepStatus(dev, WepState);
1262 zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1263 /* zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev)); */
1264 /* u8_t wpaieLen,wpaie[50]; */
1265 /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
1266 zfiWlanDisable(dev, 0);
1267 zfiWlanEnable(dev);
1268 /* if (wpaieLen > 2) */
1269 /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
1270 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001271
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001272 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001273}
1274
1275int usbdrvwext_giwencode(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001276 struct iw_request_info *info,
1277 struct iw_point *erq, char *key)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001278{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001279 struct usbdrv_private *macp = dev->ml_priv;
1280 u8_t EncryptionMode;
1281 u8_t keyLen = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001282
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001283 if (macp->DeviceOpened != 1)
1284 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001285
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001286 EncryptionMode = zfiWlanQueryEncryMode(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001287
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001288 if (EncryptionMode)
1289 erq->flags = IW_ENCODE_ENABLED;
1290 else
1291 erq->flags = IW_ENCODE_DISABLED;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001292
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001293 /* We can't return the key, so set the proper flag and return zero */
1294 erq->flags |= IW_ENCODE_NOKEY;
1295 memset(key, 0, 16);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001296
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001297 /* Copy the key to the user buffer */
1298 switch (EncryptionMode) {
1299 case ZM_WEP64:
1300 keyLen = 5;
1301 break;
1302 case ZM_WEP128:
1303 keyLen = 13;
1304 break;
1305 case ZM_WEP256:
1306 keyLen = 29;
1307 break;
1308 case ZM_AES:
1309 keyLen = 16;
1310 break;
1311 case ZM_TKIP:
1312 keyLen = 32;
1313 break;
1314 #ifdef ZM_ENABLE_CENC
1315 case ZM_CENC:
1316 /* ZM_ENABLE_CENC */
1317 keyLen = 32;
1318 break;
1319 #endif
1320 case ZM_NO_WEP:
1321 keyLen = 0;
1322 break;
1323 default:
1324 keyLen = 0;
1325 printk(KERN_ERR "Unknown EncryMode\n");
1326 break;
1327 }
1328 erq->length = keyLen;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001329
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001330 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001331}
1332
1333int usbdrvwext_siwpower(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001334 struct iw_request_info *info,
1335 struct iw_param *frq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001336{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001337 struct usbdrv_private *macp = dev->ml_priv;
1338 u8_t PSMode;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001339
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001340 if (macp->DeviceOpened != 1)
1341 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001342
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001343 if (frq->disabled)
1344 PSMode = ZM_STA_PS_NONE;
1345 else
1346 PSMode = ZM_STA_PS_MAX;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001347
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001348 zfiWlanSetPowerSaveMode(dev, PSMode);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001349
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001350 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001351}
1352
1353int usbdrvwext_giwpower(struct net_device *dev,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001354 struct iw_request_info *info,
1355 struct iw_param *frq, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001356{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001357 unsigned long irqFlag;
1358 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001359
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001360 if (macp->DeviceOpened != 1)
1361 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001362
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001363 spin_lock_irqsave(&macp->cs_lock, irqFlag);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001364
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001365 if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1366 frq->disabled = 1;
1367 else
1368 frq->disabled = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001369
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001370 spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001371
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001372 return 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001373}
1374
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001375/*int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1376* void *w, char *extra)
1377*{
1378* struct ieee80211vap *vap = dev->ml_priv;
1379* struct ieee80211com *ic = vap->iv_ic;
1380* struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1381* int *i = (int *) extra;
1382* int param = i[0]; // parameter id is 1st
1383* int value = i[1]; // NB: most values are TYPE_INT
1384* int retv = 0;
1385* int j, caps;
1386* const struct ieee80211_authenticator *auth;
1387* const struct ieee80211_aclator *acl;
1388*
1389* switch (param) {
1390* case IEEE80211_PARAM_AUTHMODE:
1391* switch (value) {
1392* case IEEE80211_AUTH_WPA: // WPA
1393* case IEEE80211_AUTH_8021X: // 802.1x
1394* case IEEE80211_AUTH_OPEN: // open
1395* case IEEE80211_AUTH_SHARED: // shared-key
1396* case IEEE80211_AUTH_AUTO: // auto
1397* auth = ieee80211_authenticator_get(value);
1398* if (auth == NULL)
1399* return -EINVAL;
1400* break;
1401* default:
1402* return -EINVAL;
1403* }
1404* switch (value) {
1405* case IEEE80211_AUTH_WPA: // WPA w/ 802.1x
1406* vap->iv_flags |= IEEE80211_F_PRIVACY;
1407* value = IEEE80211_AUTH_8021X;
1408* break;
1409* case IEEE80211_AUTH_OPEN: // open
1410* vap->iv_flags &= ~(IEEE80211_F_WPA | IEEE80211_F_PRIVACY);
1411* break;
1412* case IEEE80211_AUTH_SHARED: // shared-key
1413* case IEEE80211_AUTH_AUTO: // auto
1414* case IEEE80211_AUTH_8021X: // 802.1x
1415* vap->iv_flags &= ~IEEE80211_F_WPA;
1416* // both require a key so mark the PRIVACY capability
1417* vap->iv_flags |= IEEE80211_F_PRIVACY;
1418* break;
1419* }
1420* // NB: authenticator attach/detach happens on state change
1421* vap->iv_bss->ni_authmode = value;
1422* // XXX mixed/mode/usage?
1423* vap->iv_auth = auth;
1424* retv = ENETRESET;
1425* break;
1426* case IEEE80211_PARAM_PROTMODE:
1427* if (value > IEEE80211_PROT_RTSCTS)
1428* return -EINVAL;
1429* ic->ic_protmode = value;
1430* // NB: if not operating in 11g this can wait
1431* if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1432* IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1433* retv = ENETRESET;
1434* break;
1435* case IEEE80211_PARAM_MCASTCIPHER:
1436* if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1437* !ieee80211_crypto_available(value))
1438* return -EINVAL;
1439* rsn->rsn_mcastcipher = value;
1440* if (vap->iv_flags & IEEE80211_F_WPA)
1441* retv = ENETRESET;
1442* break;
1443* case IEEE80211_PARAM_MCASTKEYLEN:
1444* if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1445* return -EINVAL;
1446* // XXX no way to verify driver capability
1447* rsn->rsn_mcastkeylen = value;
1448* if (vap->iv_flags & IEEE80211_F_WPA)
1449* retv = ENETRESET;
1450* break;
1451* case IEEE80211_PARAM_UCASTCIPHERS:
1452*
1453* // Convert cipher set to equivalent capabilities.
1454* // NB: this logic intentionally ignores unknown and
1455* // unsupported ciphers so folks can specify 0xff or
1456* // similar and get all available ciphers.
1457*
1458* caps = 0;
1459* for (j = 1; j < 32; j++) // NB: skip WEP
1460* if ((value & (1<<j)) &&
1461* ((vap->iv_caps & cipher2cap(j)) ||
1462* ieee80211_crypto_available(j)))
1463* caps |= 1<<j;
1464* if (caps == 0) // nothing available
1465* return -EINVAL;
1466* // XXX verify ciphers ok for unicast use?
1467* // XXX disallow if running as it'll have no effect
1468* rsn->rsn_ucastcipherset = caps;
1469* if (vap->iv_flags & IEEE80211_F_WPA)
1470* retv = ENETRESET;
1471* break;
1472* case IEEE80211_PARAM_UCASTCIPHER:
1473* if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1474* return -EINVAL;
1475* rsn->rsn_ucastcipher = value;
1476* break;
1477* case IEEE80211_PARAM_UCASTKEYLEN:
1478* if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1479* return -EINVAL;
1480* // XXX no way to verify driver capability
1481* rsn->rsn_ucastkeylen = value;
1482* break;
1483* case IEEE80211_PARAM_KEYMGTALGS:
1484* // XXX check
1485* rsn->rsn_keymgmtset = value;
1486* if (vap->iv_flags & IEEE80211_F_WPA)
1487* retv = ENETRESET;
1488* break;
1489* case IEEE80211_PARAM_RSNCAPS:
1490* // XXX check
1491* rsn->rsn_caps = value;
1492* if (vap->iv_flags & IEEE80211_F_WPA)
1493* retv = ENETRESET;
1494* break;
1495* case IEEE80211_PARAM_WPA:
1496* if (value > 3)
1497* return -EINVAL;
1498* // XXX verify ciphers available
1499* vap->iv_flags &= ~IEEE80211_F_WPA;
1500* switch (value) {
1501* case 1:
1502* vap->iv_flags |= IEEE80211_F_WPA1;
1503* break;
1504* case 2:
1505* vap->iv_flags |= IEEE80211_F_WPA2;
1506* break;
1507* case 3:
1508* vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1509* break;
1510* }
1511* retv = ENETRESET; // XXX?
1512* break;
1513* case IEEE80211_PARAM_ROAMING:
1514* if (!(IEEE80211_ROAMING_DEVICE <= value &&
1515* value <= IEEE80211_ROAMING_MANUAL))
1516* return -EINVAL;
1517* ic->ic_roaming = value;
1518* break;
1519* case IEEE80211_PARAM_PRIVACY:
1520* if (value) {
1521* // XXX check for key state?
1522* vap->iv_flags |= IEEE80211_F_PRIVACY;
1523* } else
1524* vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1525* break;
1526* case IEEE80211_PARAM_DROPUNENCRYPTED:
1527* if (value)
1528* vap->iv_flags |= IEEE80211_F_DROPUNENC;
1529* else
1530* vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1531* break;
1532* case IEEE80211_PARAM_COUNTERMEASURES:
1533* if (value) {
1534* if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1535* return -EINVAL;
1536* vap->iv_flags |= IEEE80211_F_COUNTERM;
1537* } else
1538* vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1539* break;
1540* case IEEE80211_PARAM_DRIVER_CAPS:
1541* vap->iv_caps = value; // NB: for testing
1542* break;
1543* case IEEE80211_PARAM_MACCMD:
1544* acl = vap->iv_acl;
1545* switch (value) {
1546* case IEEE80211_MACCMD_POLICY_OPEN:
1547* case IEEE80211_MACCMD_POLICY_ALLOW:
1548* case IEEE80211_MACCMD_POLICY_DENY:
1549* if (acl == NULL) {
1550* acl = ieee80211_aclator_get("mac");
1551* if (acl == NULL || !acl->iac_attach(vap))
1552* return -EINVAL;
1553* vap->iv_acl = acl;
1554* }
1555* acl->iac_setpolicy(vap, value);
1556* break;
1557* case IEEE80211_MACCMD_FLUSH:
1558* if (acl != NULL)
1559* acl->iac_flush(vap);
1560* // NB: silently ignore when not in use
1561* break;
1562* case IEEE80211_MACCMD_DETACH:
1563* if (acl != NULL) {
1564* vap->iv_acl = NULL;
1565* acl->iac_detach(vap);
1566* }
1567* break;
1568* }
1569* break;
1570* case IEEE80211_PARAM_WMM:
1571* if (ic->ic_caps & IEEE80211_C_WME){
1572* if (value) {
1573* vap->iv_flags |= IEEE80211_F_WME;
1574* *//* XXX needed by ic_reset *//*
1575* vap->iv_ic->ic_flags |= IEEE80211_F_WME;
1576* }
1577* else {
1578* *//* XXX needed by ic_reset *//*
1579* vap->iv_flags &= ~IEEE80211_F_WME;
1580* vap->iv_ic->ic_flags &= ~IEEE80211_F_WME;
1581* }
1582* retv = ENETRESET; // Renegotiate for capabilities
1583* }
1584* break;
1585* case IEEE80211_PARAM_HIDESSID:
1586* if (value)
1587* vap->iv_flags |= IEEE80211_F_HIDESSID;
1588* else
1589* vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1590* retv = ENETRESET;
1591* break;
1592* case IEEE80211_PARAM_APBRIDGE:
1593* if (value == 0)
1594* vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1595* else
1596* vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1597* break;
1598* case IEEE80211_PARAM_INACT:
1599* vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1600* break;
1601* case IEEE80211_PARAM_INACT_AUTH:
1602* vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1603* break;
1604* case IEEE80211_PARAM_INACT_INIT:
1605* vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1606* break;
1607* case IEEE80211_PARAM_ABOLT:
1608* caps = 0;
1609*
1610* // Map abolt settings to capability bits;
1611* // this also strips unknown/unwanted bits.
1612*
1613* if (value & IEEE80211_ABOLT_TURBO_PRIME)
1614* caps |= IEEE80211_ATHC_TURBOP;
1615* if (value & IEEE80211_ABOLT_COMPRESSION)
1616* caps |= IEEE80211_ATHC_COMP;
1617* if (value & IEEE80211_ABOLT_FAST_FRAME)
1618* caps |= IEEE80211_ATHC_FF;
1619* if (value & IEEE80211_ABOLT_XR)
1620* caps |= IEEE80211_ATHC_XR;
1621* if (value & IEEE80211_ABOLT_AR)
1622* caps |= IEEE80211_ATHC_AR;
1623* if (value & IEEE80211_ABOLT_BURST)
1624* caps |= IEEE80211_ATHC_BURST;
1625* if (value & IEEE80211_ABOLT_WME_ELE)
1626* caps |= IEEE80211_ATHC_WME;
1627* // verify requested capabilities are supported
1628* if ((caps & ic->ic_ath_cap) != caps)
1629* return -EINVAL;
1630* if (vap->iv_ath_cap != caps) {
1631* if ((vap->iv_ath_cap ^ caps) & IEEE80211_ATHC_TURBOP) {
1632* if (ieee80211_set_turbo(dev,
1633* caps & IEEE80211_ATHC_TURBOP))
1634* return -EINVAL;
1635* ieee80211_scan_flush(ic);
1636* }
1637* vap->iv_ath_cap = caps;
1638* ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1639* retv = ENETRESET;
1640* }
1641* break;
1642* case IEEE80211_PARAM_DTIM_PERIOD:
1643* if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1644* vap->iv_opmode != IEEE80211_M_IBSS)
1645* return -EINVAL;
1646* if (IEEE80211_DTIM_MIN <= value &&
1647* value <= IEEE80211_DTIM_MAX) {
1648* vap->iv_dtim_period = value;
1649* retv = ENETRESET; // requires restart
1650* } else
1651* retv = EINVAL;
1652* break;
1653* case IEEE80211_PARAM_BEACON_INTERVAL:
1654* if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1655* vap->iv_opmode != IEEE80211_M_IBSS)
1656* return -EINVAL;
1657* if (IEEE80211_BINTVAL_MIN <= value &&
1658* value <= IEEE80211_BINTVAL_MAX) {
1659* ic->ic_lintval = value; // XXX multi-bss
1660* retv = ENETRESET; // requires restart
1661* } else
1662* retv = EINVAL;
1663* break;
1664* case IEEE80211_PARAM_DOTH:
1665* if (value) {
1666* ic->ic_flags |= IEEE80211_F_DOTH;
1667* }
1668* else
1669* ic->ic_flags &= ~IEEE80211_F_DOTH;
1670* retv = ENETRESET; // XXX: need something this drastic?
1671* break;
1672* case IEEE80211_PARAM_PWRTARGET:
1673* ic->ic_curchanmaxpwr = value;
1674* break;
1675* case IEEE80211_PARAM_GENREASSOC:
1676* IEEE80211_SEND_MGMT(vap->iv_bss,
1677* IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1678* break;
1679* case IEEE80211_PARAM_COMPRESSION:
1680* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1681* break;
1682* case IEEE80211_PARAM_WMM_AGGRMODE:
1683* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1684* break;
1685* case IEEE80211_PARAM_FF:
1686* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1687* break;
1688* case IEEE80211_PARAM_TURBO:
1689* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_TURBOP, value);
1690* if (retv == ENETRESET) {
1691* if(ieee80211_set_turbo(dev,value))
1692* return -EINVAL;
1693* ieee80211_scan_flush(ic);
1694* }
1695* break;
1696* case IEEE80211_PARAM_XR:
1697* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1698* break;
1699* case IEEE80211_PARAM_BURST:
1700* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1701* break;
1702* case IEEE80211_PARAM_AR:
1703* retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1704* break;
1705* case IEEE80211_PARAM_PUREG:
1706* if (value)
1707* vap->iv_flags |= IEEE80211_F_PUREG;
1708* else
1709* vap->iv_flags &= ~IEEE80211_F_PUREG;
1710* // NB: reset only if we're operating on an 11g channel
1711* if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1712* IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1713* retv = ENETRESET;
1714* break;
1715* case IEEE80211_PARAM_WDS:
1716* if (value)
1717* vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1718* else
1719* vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1720* break;
1721* case IEEE80211_PARAM_BGSCAN:
1722* if (value) {
1723* if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1724* return -EINVAL;
1725* vap->iv_flags |= IEEE80211_F_BGSCAN;
1726* } else {
1727* // XXX racey?
1728* vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1729* ieee80211_cancel_scan(vap); // anything current
1730* }
1731* break;
1732* case IEEE80211_PARAM_BGSCAN_IDLE:
1733* if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1734* vap->iv_bgscanidle = value*HZ/1000;
1735* else
1736* retv = EINVAL;
1737* break;
1738* case IEEE80211_PARAM_BGSCAN_INTERVAL:
1739* if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1740* vap->iv_bgscanintvl = value*HZ;
1741* else
1742* retv = EINVAL;
1743* break;
1744* case IEEE80211_PARAM_MCAST_RATE:
1745* // units are in KILObits per second
1746* if (value >= 256 && value <= 54000)
1747* vap->iv_mcast_rate = value;
1748* else
1749* retv = EINVAL;
1750* break;
1751* case IEEE80211_PARAM_COVERAGE_CLASS:
1752* if (value >= 0 && value <= IEEE80211_COVERAGE_CLASS_MAX) {
1753* ic->ic_coverageclass = value;
1754* if (IS_UP_AUTO(vap))
1755* ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1756* retv = 0;
1757* }
1758* else
1759* retv = EINVAL;
1760* break;
1761* case IEEE80211_PARAM_COUNTRY_IE:
1762* if (value)
1763* ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1764* else
1765* ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1766* retv = ENETRESET;
1767* break;
1768* case IEEE80211_PARAM_REGCLASS:
1769* if (value)
1770* ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1771* else
1772* ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1773* retv = ENETRESET;
1774* break;
1775* case IEEE80211_PARAM_SCANVALID:
1776* vap->iv_scanvalid = value*HZ;
1777* break;
1778* case IEEE80211_PARAM_ROAM_RSSI_11A:
1779* vap->iv_roam.rssi11a = value;
1780* break;
1781* case IEEE80211_PARAM_ROAM_RSSI_11B:
1782* vap->iv_roam.rssi11bOnly = value;
1783* break;
1784* case IEEE80211_PARAM_ROAM_RSSI_11G:
1785* vap->iv_roam.rssi11b = value;
1786* break;
1787* case IEEE80211_PARAM_ROAM_RATE_11A:
1788* vap->iv_roam.rate11a = value;
1789* break;
1790* case IEEE80211_PARAM_ROAM_RATE_11B:
1791* vap->iv_roam.rate11bOnly = value;
1792* break;
1793* case IEEE80211_PARAM_ROAM_RATE_11G:
1794* vap->iv_roam.rate11b = value;
1795* break;
1796* case IEEE80211_PARAM_UAPSDINFO:
1797* if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1798* if (ic->ic_caps & IEEE80211_C_UAPSD) {
1799* if (value)
1800* IEEE80211_VAP_UAPSD_ENABLE(vap);
1801* else
1802* IEEE80211_VAP_UAPSD_DISABLE(vap);
1803* retv = ENETRESET;
1804* }
1805* }
1806* else if (vap->iv_opmode == IEEE80211_M_STA) {
1807* vap->iv_uapsdinfo = value;
1808* IEEE80211_VAP_UAPSD_ENABLE(vap);
1809* retv = ENETRESET;
1810* }
1811* break;
1812* case IEEE80211_PARAM_SLEEP:
1813* // XXX: Forced sleep for testing. Does not actually place the
1814* // HW in sleep mode yet. this only makes sense for STAs.
1815*
1816* if (value) {
1817* // goto sleep
1818* IEEE80211_VAP_GOTOSLEEP(vap);
1819* }
1820* else {
1821* // wakeup
1822* IEEE80211_VAP_WAKEUP(vap);
1823* }
1824* ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1825* break;
1826* case IEEE80211_PARAM_QOSNULL:
1827* // Force a QoS Null for testing.
1828* ieee80211_send_qosnulldata(vap->iv_bss, value);
1829* break;
1830* case IEEE80211_PARAM_PSPOLL:
1831* // Force a PS-POLL for testing.
1832* ieee80211_send_pspoll(vap->iv_bss);
1833* break;
1834* case IEEE80211_PARAM_EOSPDROP:
1835* if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1836* if (value) IEEE80211_VAP_EOSPDROP_ENABLE(vap);
1837* else IEEE80211_VAP_EOSPDROP_DISABLE(vap);
1838* }
1839* break;
1840* case IEEE80211_PARAM_MARKDFS:
1841* if (value)
1842* ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1843* else
1844* ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1845* break;
1846* case IEEE80211_PARAM_CHANBW:
1847* switch (value) {
1848* case 0:
1849* ic->ic_chanbwflag = 0;
1850* break;
1851* case 1:
1852* ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1853* break;
1854* case 2:
1855* ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1856* break;
1857* default:
1858* retv = EINVAL;
1859* break;
1860* }
1861* break;
1862* case IEEE80211_PARAM_SHORTPREAMBLE:
1863* if (value) {
1864* ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1865* } else {
1866* ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1867* }
1868* retv = ENETRESET;
1869* break;
1870* default:
1871* retv = EOPNOTSUPP;
1872* break;
1873* }
1874* // XXX should any of these cause a rescan?
1875* if (retv == ENETRESET)
1876* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
1877* return -retv;
1878*}
1879*/
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001880
1881int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001882 void *w, char *extra)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001883{
1884 return 0;
1885}
1886
1887int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1888 void *w, char *extra)
1889{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001890 /* struct usbdrv_private *macp = dev->ml_priv; */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001891 struct iw_point *wri = (struct iw_point *)extra;
1892 char mode[8];
1893
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001894 strcpy(mode, "11g");
1895 return copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001896}
1897
1898int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1899{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001900 /* void* regp = macp->regp; */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001901 u16_t cmd;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001902 /* u32_t temp; */
1903 u32_t *p;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001904 u32_t i;
1905
1906 cmd = zdreq->cmd;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001907 switch (cmd) {
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001908 case ZM_IOCTL_REG_READ:
1909 zfiDbgReadReg(dev, zdreq->addr);
1910 break;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001911 case ZM_IOCTL_REG_WRITE:
1912 zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1913 break;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001914 case ZM_IOCTL_MEM_READ:
1915 p = (u32_t *) bus_to_virt(zdreq->addr);
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001916 printk(KERN_WARNING
1917 "usbdrv: read memory addr: 0x%08x value:"
1918 " 0x%08x\n", zdreq->addr, *p);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001919 break;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001920 case ZM_IOCTL_MEM_WRITE:
1921 p = (u32_t *) bus_to_virt(zdreq->addr);
1922 *p = zdreq->value;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001923 printk(KERN_WARNING
1924 "usbdrv : write value : 0x%08x to memory addr :"
1925 " 0x%08x\n", zdreq->value, zdreq->addr);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001926 break;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001927 case ZM_IOCTL_TALLY:
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001928 zfiWlanShowTally(dev);
1929 if (zdreq->addr)
1930 zfiWlanResetTally(dev);
1931 break;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001932 case ZM_IOCTL_TEST:
1933 printk(KERN_WARNING
1934 "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1935 /* zfiWlanReadReg(dev, 0x10f400); */
1936 /* zfiWlanReadReg(dev, 0x10f404); */
1937 printk(KERN_WARNING "IOCTL TEST\n");
1938 #if 1
1939 /* print packet */
1940 for (i = 0; i < zdreq->addr; i++) {
1941 if ((i&0x7) == 0)
1942 printk(KERN_WARNING "\n");
1943 printk(KERN_WARNING "%02X ",
1944 (unsigned char)zdreq->data[i]);
1945 }
1946 printk(KERN_WARNING "\n");
1947 #endif
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001948
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001949 /* For Test?? 1 to 0 by CWYang(-) */
1950 #if 0
1951 struct sk_buff *s;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001952
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001953 /* Allocate a skb */
1954 s = alloc_skb(2000, GFP_ATOMIC);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001955
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001956 /* Copy data to skb */
1957 for (i = 0; i < zdreq->addr; i++)
1958 s->data[i] = zdreq->data[i];
1959 s->len = zdreq->addr;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001960
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001961 /* Call zfIdlRecv() */
1962 zfiRecv80211(dev, s, NULL);
1963 #endif
1964 break;
1965 /************************* ZDCONFIG ***************************/
1966 case ZM_IOCTL_FRAG:
1967 zfiWlanSetFragThreshold(dev, zdreq->addr);
1968 break;
1969 case ZM_IOCTL_RTS:
1970 zfiWlanSetRtsThreshold(dev, zdreq->addr);
1971 break;
1972 case ZM_IOCTL_SCAN:
1973 zfiWlanScan(dev);
1974 break;
1975 case ZM_IOCTL_KEY: {
1976 u8_t key[29];
1977 struct zsKeyInfo keyInfo;
1978 u32_t i;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001979
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001980 for (i = 0; i < 29; i++)
1981 key[i] = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001982
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001983 for (i = 0; i < zdreq->addr; i++)
1984 key[i] = zdreq->data[i];
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001985
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001986 printk(KERN_WARNING
1987 "key len=%d, key=%02x%02x%02x%02x%02x...\n",
1988 zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07001989
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01001990 keyInfo.keyLength = zdreq->addr;
1991 keyInfo.keyIndex = 0;
1992 keyInfo.flag = 0;
1993 keyInfo.key = key;
1994 zfiWlanSetKey(dev, keyInfo);
1995 }
1996 break;
1997 case ZM_IOCTL_RATE:
1998 zfiWlanSetTxRate(dev, zdreq->addr);
1999 break;
2000 case ZM_IOCTL_ENCRYPTION_MODE:
2001 zfiWlanSetEncryMode(dev, zdreq->addr);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002002
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002003 zfiWlanDisable(dev, 0);
2004 zfiWlanEnable(dev);
2005 break;
2006 /* CWYang(+) */
2007 case ZM_IOCTL_SIGNAL_STRENGTH: {
2008 u8_t buffer[2];
2009 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2010 printk(KERN_WARNING
2011 "Current Signal Strength : %02d\n", buffer[0]);
2012 }
2013 break;
2014 /* CWYang(+) */
2015 case ZM_IOCTL_SIGNAL_QUALITY: {
2016 u8_t buffer[2];
2017 zfiWlanQuerySignalInfo(dev, &buffer[0]);
2018 printk(KERN_WARNING
2019 "Current Signal Quality : %02d\n", buffer[1]);
2020 }
2021 break;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002022 case ZM_IOCTL_SET_PIBSS_MODE:
2023 if (zdreq->addr == 1)
2024 zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2025 else
2026 zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2027
2028 zfiWlanDisable(dev, 0);
2029 zfiWlanEnable(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002030 break;
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002031 /********************* ZDCONFIG ***********************/
2032 default:
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002033 printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2034 break;
2035 }
2036
2037 return 0;
2038}
2039
2040int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2041{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002042 int ret = 0;
2043 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2044 u8_t mac_addr[80];
2045 struct zsKeyInfo keyInfo;
2046 struct usbdrv_private *macp = dev->ml_priv;
2047 u16_t vapId = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002048
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002049 /* zmw_get_wlan_dev(dev); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002050
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002051 switch (zdparm->cmd) {
2052 case ZD_CMD_SET_ENCRYPT_KEY:
2053 /* Set up key information */
2054 keyInfo.keyLength = zdparm->u.crypt.key_len;
2055 keyInfo.keyIndex = zdparm->u.crypt.idx;
2056 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2057 /* AP Mode */
2058 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2059 } else
2060 keyInfo.flag = 0;
2061 keyInfo.key = zdparm->u.crypt.key;
2062 keyInfo.initIv = zdparm->u.crypt.seq;
2063 keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002064
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002065 /* Identify the MAC address information */
2066 if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2067 keyInfo.flag |= ZM_KEY_FLAG_GK;
2068 else
2069 keyInfo.flag |= ZM_KEY_FLAG_PK;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002070
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002071 if (!strcmp(zdparm->u.crypt.alg, "NONE")) {
2072 /* u8_t zero_mac[]={0,0,0,0,0,0}; */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002073
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002074 /* Set key length to zero */
2075 keyInfo.keyLength = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002076
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002077 /* del group key */
2078 if (zdparm->sta_addr[0] & 1) {
2079 /* if (macp->cardSetting.WPAIeLen==0)
2080 * { 802.1x dynamic WEP
2081 * mDynKeyMode = 0;
2082 * mKeyFormat[0] = 0;
2083 * mPrivacyInvoked[0]=FALSE;
2084 * mCap[0] &= ~CAP_PRIVACY;
2085 * macp->cardSetting.EncryOnOff[0]=0;
2086 * }
2087 * mWpaBcKeyLen = mGkInstalled = 0;
2088 */
2089 } else {
2090 /* if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2091 * {
2092 * mDynKeyMode=0;
2093 * mKeyFormat[0]=0;
2094 * pSetting->DynKeyMode=0;
2095 * pSetting->EncryMode[0]=0;
2096 * mDynKeyMode=0;
2097 * }
2098 */
2099 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002100
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002101 printk(KERN_ERR "Set Encryption Type NONE\n");
2102 return ret;
2103 } else if (!strcmp(zdparm->u.crypt.alg, "TKIP")) {
2104 zfiWlanSetEncryMode(dev, ZM_TKIP);
2105 /* //Linux Supplicant will inverse Tx/Rx key
2106 * //So we inverse it back, CWYang(+)
2107 * zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2108 * zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2109 * zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2110 * u8_t temp;
2111 * int k;
2112 * for (k = 0; k < 8; k++)
2113 * {
2114 * temp = keyInfo.key[16 + k];
2115 * keyInfo.key[16 + k] = keyInfo.key[24 + k];
2116 * keyInfo.key[24 + k] = temp;
2117 * }
2118 * CamEncryType = ZM_TKIP;
2119 * if (idx == 0)
2120 * { // Pairwise key
2121 * mKeyFormat[0] = CamEncryType;
2122 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2123 * }
2124 */
2125 } else if (!strcmp(zdparm->u.crypt.alg, "CCMP")) {
2126 zfiWlanSetEncryMode(dev, ZM_AES);
2127 /* CamEncryType = ZM_AES;
2128 * if (idx == 0)
2129 * { // Pairwise key
2130 * mKeyFormat[0] = CamEncryType;
2131 * mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2132 * }
2133 */
2134 } else if (!strcmp(zdparm->u.crypt.alg, "WEP")) {
2135 if (keyInfo.keyLength == 5) {
2136 /* WEP 64 */
2137 zfiWlanSetEncryMode(dev, ZM_WEP64);
2138 /* CamEncryType = ZM_WEP64; */
2139 /* tmpDynKeyMode=DYN_KEY_WEP64; */
2140 } else if (keyInfo.keyLength == 13) {
2141 /* keylen=13, WEP 128 */
2142 zfiWlanSetEncryMode(dev, ZM_WEP128);
2143 /* CamEncryType = ZM_WEP128; */
2144 /* tmpDynKeyMode=DYN_KEY_WEP128; */
2145 } else {
2146 zfiWlanSetEncryMode(dev, ZM_WEP256);
2147 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002148
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002149 /* For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2150 * In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2151 * For WEP key setting: we set mDynKeyMode and mKeyFormat in following
2152 * case:
2153 * 1. For 802.1x dynamically generated WEP key method.
2154 * 2. For WPA/RSN mode, but key id == 0.
2155 * (But this is an impossible case)
2156 * So, only check case 1.
2157 * if (macp->cardSetting.WPAIeLen==0)
2158 * {
2159 * mKeyFormat[0] = CamEncryType;
2160 * mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2161 * mPrivacyInvoked[0]=TRUE;
2162 * mCap[0] |= CAP_PRIVACY;
2163 * macp->cardSetting.EncryOnOff[0]=1;
2164 * }
2165 */
2166 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002167
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002168 /* DUMP key context */
2169 /* #ifdef WPA_DEBUG */
2170 if (keyInfo.keyLength > 0) {
2171 int ii;
2172 printk(KERN_WARNING
2173 "Otus: Key Context:\n");
2174 for (ii = 0; ii < keyInfo.keyLength; ) {
2175 printk(KERN_WARNING
2176 "0x%02x ", keyInfo.key[ii]);
2177 if ((++ii % 16) == 0)
2178 printk(KERN_WARNING "\n");
2179 }
2180 printk(KERN_WARNING "\n");
2181 }
2182 /* #endif */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002183
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002184 /* Set encrypt mode */
2185 /* zfiWlanSetEncryMode(dev, CamEncryType); */
2186 vapId = zfLnxGetVapId(dev);
2187 if (vapId == 0xffff)
2188 keyInfo.vapId = 0;
2189 else
2190 keyInfo.vapId = vapId + 1;
2191 keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2192 keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2193 keyInfo.vapAddr[2] = keyInfo.macAddr[2];
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002194
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002195 zfiWlanSetKey(dev, keyInfo);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002196
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002197 /* zfiWlanDisable(dev); */
2198 /* zfiWlanEnable(dev); */
2199 break;
2200 case ZD_CMD_SET_MLME:
2201 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002202
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002203 /* Translate STA's address */
2204 sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x",
2205 zdparm->sta_addr[0], zdparm->sta_addr[1],
2206 zdparm->sta_addr[2], zdparm->sta_addr[3],
2207 zdparm->sta_addr[4], zdparm->sta_addr[5]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002208
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002209 switch (zdparm->u.mlme.cmd) {
2210 case MLME_STA_DEAUTH:
2211 printk(KERN_WARNING
2212 " -------Call zfiWlanDeauth, reason:%d\n",
2213 zdparm->u.mlme.reason_code);
2214 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2215 zdparm->u.mlme.reason_code) != 0)
2216 printk(KERN_ERR "Can't deauthencate STA: %s\n",
2217 mac_addr);
2218 else
2219 printk(KERN_ERR "Deauthenticate STA: %s"
2220 "with reason code: %d\n",
2221 mac_addr, zdparm->u.mlme.reason_code);
2222 break;
2223 case MLME_STA_DISASSOC:
2224 printk(KERN_WARNING
2225 " -------Call zfiWlanDeauth, reason:%d\n",
2226 zdparm->u.mlme.reason_code);
2227 if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2228 zdparm->u.mlme.reason_code) != 0)
2229 printk(KERN_ERR "Can't disassociate STA: %s\n",
2230 mac_addr);
2231 else
2232 printk(KERN_ERR "Disassociate STA: %s"
2233 "with reason code: %d\n",
2234 mac_addr, zdparm->u.mlme.reason_code);
2235 break;
2236 default:
2237 printk(KERN_ERR "MLME command: 0x%04x not support\n",
2238 zdparm->u.mlme.cmd);
2239 break;
2240 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002241
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002242 break;
2243 case ZD_CMD_SCAN_REQ:
2244 printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2245 break;
2246 case ZD_CMD_SET_GENERIC_ELEMENT:
2247 printk(KERN_ERR "usbdrv_wpa_ioctl:"
2248 " ZD_CMD_SET_GENERIC_ELEMENT\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002249
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002250 /* Copy the WPA IE
2251 * zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ",
2252 * zdparm->u.generic_elem.len);
2253 */
2254 printk(KERN_ERR "wpaie Length : % d\n",
2255 zdparm->u.generic_elem.len);
2256 if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2257 /* AP Mode */
2258 zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2259 zdparm->u.generic_elem.len);
2260 } else {
2261 macp->supLen = zdparm->u.generic_elem.len;
2262 memcpy(macp->supIe, zdparm->u.generic_elem.data,
2263 zdparm->u.generic_elem.len);
2264 }
2265 zfiWlanSetWpaSupport(dev, 1);
2266 /* zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2267 * zdparm->u.generic_elem.len);
2268 */
2269 int ii;
2270 u8_t len = zdparm->u.generic_elem.len;
2271 u8_t *wpaie = (u8_t *)zdparm->u.generic_elem.data;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002272
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002273 printk(KERN_ERR "wd->ap.wpaLen : % d\n", len);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002274
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002275 /* DUMP WPA IE */
2276 for(ii = 0; ii < len;) {
2277 printk(KERN_ERR "0x%02x ", wpaie[ii]);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002278
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002279 if((++ii % 16) == 0)
2280 printk(KERN_ERR "\n");
2281 }
2282 printk(KERN_ERR "\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002283
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002284 /* #ifdef ZM_HOSTAPD_SUPPORT
2285 * if (wd->wlanMode == ZM_MODE_AP)
2286 * {// Update Beacon FIFO in the next TBTT.
2287 * memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2288 * printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2289 * }
2290 * #endif
2291 */
2292 break;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002293
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002294 /* #ifdef ZM_HOSTAPD_SUPPORT */
2295 case ZD_CMD_GET_TSC:
2296 printk(KERN_ERR "usbdrv_wpa_ioctl : ZD_CMD_GET_TSC\n");
2297 break;
2298 /* #endif */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002299
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002300 default:
2301 printk(KERN_ERR "usbdrv_wpa_ioctl default : 0x%04x\n",
2302 zdparm->cmd);
2303 ret = -EINVAL;
2304 break;
2305 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002306
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002307 return ret;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002308}
2309
2310#ifdef ZM_ENABLE_CENC
2311int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2312{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002313 /* struct usbdrv_private *macp = dev->ml_priv; */
2314 struct zsKeyInfo keyInfo;
2315 u16_t apId;
2316 u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2317 int ret = 0;
2318 int ii;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002319
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002320 /* Get the AP Id */
2321 apId = zfLnxGetVapId(dev);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002322
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002323 if (apId == 0xffff) {
2324 apId = 0;
2325 } else {
2326 apId = apId + 1;
2327 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002328
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002329 switch (zdparm->cmd) {
2330 case ZM_CMD_CENC_SETCENC:
2331 printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2332 printk(KERN_ERR "length : % d\n", zdparm->len);
2333 printk(KERN_ERR "policy : % d\n", zdparm->u.info.cenc_policy);
2334 break;
2335 case ZM_CMD_CENC_SETKEY:
2336 /* ret = wai_ioctl_setkey(vap, ioctl_msg); */
2337 printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002338
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002339 printk(KERN_ERR "MAC address = ");
2340 for (ii = 0; ii < 6; ii++) {
2341 printk(KERN_ERR "0x%02x ",
2342 zdparm->u.crypt.sta_addr[ii]);
2343 }
2344 printk(KERN_ERR "\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002345
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002346 printk(KERN_ERR "Key Index : % d\n", zdparm->u.crypt.keyid);
2347 printk(KERN_ERR "Encryption key = ");
2348 for (ii = 0; ii < 16; ii++) {
2349 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2350 }
2351 printk(KERN_ERR "\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002352
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002353 printk(KERN_ERR "MIC key = ");
2354 for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++) {
2355 printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2356 }
2357 printk(KERN_ERR "\n");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002358
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002359 /* Set up key information */
2360 keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2361 keyInfo.keyIndex = zdparm->u.crypt.keyid;
2362 keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2363 keyInfo.key = zdparm->u.crypt.key;
2364 keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002365
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002366 /* Identify the MAC address information */
2367 if (memcmp(zdparm->u.crypt.sta_addr, bc_addr,
2368 sizeof(bc_addr)) == 0) {
2369 keyInfo.flag |= ZM_KEY_FLAG_GK;
2370 keyInfo.vapId = apId;
2371 memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2372 } else {
2373 keyInfo.flag |= ZM_KEY_FLAG_PK;
2374 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002375
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002376 zfiWlanSetKey(dev, keyInfo);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002377
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002378 break;
2379 case ZM_CMD_CENC_REKEY:
2380 /* ret = wai_ioctl_rekey(vap, ioctl_msg); */
2381 printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2382 break;
2383 default:
2384 ret = -EOPNOTSUPP;
2385 break;
2386 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002387
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002388 /* if (retv == ENETRESET) */
2389 /* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0; */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002390
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002391 return ret;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002392}
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002393#endif /* ZM_ENABLE_CENC */
2394
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002395int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2396{
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002397 /* struct usbdrv_private *macp; */
2398 /* void *regp; */
2399 struct zdap_ioctl zdreq;
2400 struct iwreq *wrq = (struct iwreq *)ifr;
2401 struct athr_wlan_param zdparm;
2402 struct usbdrv_private *macp = dev->ml_priv;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002403
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002404 int err = 0;
2405 int changed = 0;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002406
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002407 /* regp = macp->regp; */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002408
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002409 if (!netif_running(dev))
2410 return -EINVAL;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002411
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002412 switch (cmd) {
2413 case SIOCGIWNAME:
2414 strcpy(wrq->u.name, "IEEE 802.11-DS");
2415 break;
2416 case SIOCGIWAP:
2417 err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2418 break;
2419 case SIOCSIWAP:
2420 err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2421 break;
2422 case SIOCGIWMODE:
2423 err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2424 break;
2425 case SIOCSIWESSID:
2426 printk(KERN_ERR "CWY - usbdrvwext_siwessid\n");
2427 /* err = usbdrv_ioctl_setessid(dev, &wrq->u.essid); */
2428 err = usbdrvwext_siwessid(dev, NULL, &wrq->u.essid, NULL);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002429
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002430 if (!err)
2431 changed = 1;
2432 break;
2433 case SIOCGIWESSID:
2434 err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2435 break;
2436 case SIOCSIWRTS:
2437 err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2438 if (! err)
2439 changed = 1;
2440 break;
2441 /* set_auth */
2442 case SIOCIWFIRSTPRIV + 0x2: {
2443 /* printk("CWY - SIOCIWFIRSTPRIV + 0x2(set_auth)\n"); */
2444 if (!capable(CAP_NET_ADMIN)) {
2445 err = -EPERM;
2446 break;
2447 }
2448 int val = *((int *) wrq->u.name);
2449 if ((val < 0) || (val > 2)) {
2450 err = -EINVAL;
2451 break;
2452 } else {
2453 zfiWlanSetAuthenticationMode(dev, val);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002454
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002455 if (macp->DeviceOpened == 1) {
2456 zfiWlanDisable(dev, 0);
2457 zfiWlanEnable(dev);
2458 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002459
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002460 err = 0;
2461 changed = 1;
2462 }
2463 }
2464 break;
2465 /* get_auth */
2466 case SIOCIWFIRSTPRIV + 0x3: {
2467 int AuthMode = ZM_AUTH_MODE_OPEN;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002468
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002469 /* printk("CWY - SIOCIWFIRSTPRIV + 0x3(get_auth)\n"); */
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002470
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002471 if (wrq->u.data.pointer) {
2472 wrq->u.data.flags = 1;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002473
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002474 AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2475 if (AuthMode == ZM_AUTH_MODE_OPEN) {
2476 wrq->u.data.length = 12;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002477
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002478 if (copy_to_user(wrq->u.data.pointer,
2479 "open system", 12)) {
2480 return -EFAULT;
2481 }
2482 } else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY) {
2483 wrq->u.data.length = 11;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002484
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002485 if (copy_to_user(wrq->u.data.pointer,
2486 "shared key", 11)) {
2487 return -EFAULT;
2488 }
2489 } else if (AuthMode == ZM_AUTH_MODE_AUTO) {
2490 wrq->u.data.length = 10;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002491
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002492 if (copy_to_user(wrq->u.data.pointer,
2493 "auto mode", 10)) {
2494 return -EFAULT;
2495 }
2496 } else {
2497 return -EFAULT;
2498 }
2499 }
2500 }
2501 break;
2502 /* debug command */
2503 case ZDAPIOCTL:
2504 if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))) {
2505 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2506 return -EFAULT;
2507 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002508
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002509 /* printk(KERN_WARNING
2510 * "usbdrv : cmd = % 2x, reg = 0x%04lx,
2511 *value = 0x%08lx\n",
2512 * zdreq.cmd, zdreq.addr, zdreq.value);
2513 */
2514 zfLnxPrivateIoctl(dev, &zdreq);
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002515
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002516 err = 0;
2517 break;
2518 case ZD_IOCTL_WPA:
2519 if (copy_from_user(&zdparm, ifr->ifr_data,
2520 sizeof(struct athr_wlan_param))) {
2521 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2522 return -EFAULT;
2523 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002524
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002525 usbdrv_wpa_ioctl(dev, &zdparm);
2526 err = 0;
2527 break;
2528 case ZD_IOCTL_PARAM: {
2529 int *p;
2530 int op;
2531 int arg;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002532
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002533 /* Point to the name field and retrieve the
2534 * op and arg elements.
2535 */
2536 p = (int *)wrq->u.name;
2537 op = *p++;
2538 arg = *p;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002539
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002540 if (op == ZD_PARAM_ROAMING) {
2541 printk(KERN_ERR
2542 "*************ZD_PARAM_ROAMING : % d\n", arg);
2543 /* macp->cardSetting.ap_scan=(U8)arg; */
2544 }
2545 if (op == ZD_PARAM_PRIVACY) {
2546 printk(KERN_ERR "ZD_IOCTL_PRIVACY : ");
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002547
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002548 /* Turn on the privacy invoke flag */
2549 if (arg) {
2550 /* mCap[0] |= CAP_PRIVACY; */
2551 /* macp->cardSetting.EncryOnOff[0] = 1; */
2552 printk(KERN_ERR "enable\n");
2553
2554 } else {
2555 /* mCap[0] &= ~CAP_PRIVACY; */
2556 /* macp->cardSetting.EncryOnOff[0] = 0; */
2557 printk(KERN_ERR "disable\n");
2558 }
2559 /* changed=1; */
2560 }
2561 if (op == ZD_PARAM_WPA) {
2562
2563 printk(KERN_ERR "ZD_PARAM_WPA : ");
2564
2565 if (arg) {
2566 printk(KERN_ERR "enable\n");
2567
2568 if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP) {
2569 printk(KERN_ERR "Station Mode\n");
2570 /* zfiWlanQueryWpaIe(dev, (u8_t *)
2571 &wpaIe, &wpalen); */
2572 /* printk("wpaIe : % 2x, % 2x, % 2x\n",
2573 wpaIe[21], wpaIe[22], wpaIe[23]); */
2574 /* printk("rsnIe : % 2x, % 2x, % 2x\n",
2575 wpaIe[17], wpaIe[18], wpaIe[19]); */
2576 if ((macp->supIe[21] == 0x50) &&
2577 (macp->supIe[22] == 0xf2) &&
2578 (macp->supIe[23] == 0x2)) {
2579 printk(KERN_ERR
2580 "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2581 /* wd->sta.authMode = ZM_AUTH_MODE_WPAPSK; */
2582 /* wd->ws.authMode = ZM_AUTH_MODE_WPAPSK; */
2583 zfiWlanSetAuthenticationMode(dev,
2584 ZM_AUTH_MODE_WPAPSK);
2585 } else if ((macp->supIe[21] == 0x50) &&
2586 (macp->supIe[22] == 0xf2) &&
2587 (macp->supIe[23] == 0x1)) {
2588 printk(KERN_ERR
2589 "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2590 /* wd->sta.authMode = ZM_AUTH_MODE_WPA; */
2591 /* wd->ws.authMode = ZM_AUTH_MODE_WPA; */
2592 zfiWlanSetAuthenticationMode(dev,
2593 ZM_AUTH_MODE_WPA);
2594 } else if ((macp->supIe[17] == 0xf) &&
2595 (macp->supIe[18] == 0xac) &&
2596 (macp->supIe[19] == 0x2))
2597 {
2598 printk(KERN_ERR
2599 "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2600 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK; */
2601 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK; */
2602 zfiWlanSetAuthenticationMode(dev,
2603 ZM_AUTH_MODE_WPA2PSK);
2604 } else if ((macp->supIe[17] == 0xf) &&
2605 (macp->supIe[18] == 0xac) &&
2606 (macp->supIe[19] == 0x1))
2607 {
2608 printk(KERN_ERR
2609 "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2610 /* wd->sta.authMode = ZM_AUTH_MODE_WPA2; */
2611 /* wd->ws.authMode = ZM_AUTH_MODE_WPA2; */
2612 zfiWlanSetAuthenticationMode(dev,
2613 ZM_AUTH_MODE_WPA2);
2614 }
2615 /* WPA or WPAPSK */
2616 if ((macp->supIe[21] == 0x50) ||
2617 (macp->supIe[22] == 0xf2)) {
2618 if (macp->supIe[11] == 0x2) {
2619 printk(KERN_ERR
2620 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2621 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2622 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2623 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2624 } else {
2625 printk(KERN_ERR
2626 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2627 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2628 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2629 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2630 }
2631 }
2632 //WPA2 or WPA2PSK
2633 if ((macp->supIe[17] == 0xf) ||
2634 (macp->supIe[18] == 0xac)) {
2635 if (macp->supIe[13] == 0x2) {
2636 printk(KERN_ERR
2637 "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2638 /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2639 /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2640 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2641 } else {
2642 printk(KERN_ERR
2643 "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2644 /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2645 /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2646 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2647 }
2648 }
2649 }
2650 zfiWlanSetWpaSupport(dev, 1);
2651 } else {
2652 /* Reset the WPA related variables */
2653 printk(KERN_ERR "disable\n");
2654
2655 zfiWlanSetWpaSupport(dev, 0);
2656 zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2657 zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2658
2659 /* Now we only set the length in the WPA IE
2660 * field to zero.
2661 *macp->cardSetting.WPAIe[1] = 0;
2662 */
2663 }
2664 }
2665
2666 if (op == ZD_PARAM_COUNTERMEASURES) {
2667 printk(KERN_ERR
2668 "****************ZD_PARAM_COUNTERMEASURES : ");
2669
2670 if(arg) {
2671 /* mCounterMeasureState=1; */
2672 printk(KERN_ERR "enable\n");
2673 } else {
2674 /* mCounterMeasureState=0; */
2675 printk(KERN_ERR "disable\n");
2676 }
2677 }
2678 if (op == ZD_PARAM_DROPUNENCRYPTED) {
2679 printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED : ");
2680
2681 if(arg) {
2682 printk(KERN_ERR "enable\n");
2683 } else {
2684 printk(KERN_ERR "disable\n");
2685 }
2686 }
2687 if (op == ZD_PARAM_AUTH_ALGS) {
2688 printk(KERN_ERR "ZD_PARAM_AUTH_ALGS : ");
2689
2690 if (arg == 0) {
2691 printk(KERN_ERR "OPEN_SYSTEM\n");
2692 } else {
2693 printk(KERN_ERR "SHARED_KEY\n");
2694 }
2695 }
2696 if (op == ZD_PARAM_WPS_FILTER) {
2697 printk(KERN_ERR "ZD_PARAM_WPS_FILTER : ");
2698
2699 if (arg) {
2700 /* mCounterMeasureState=1; */
2701 macp->forwardMgmt = 1;
2702 printk(KERN_ERR "enable\n");
2703 } else {
2704 /* mCounterMeasureState=0; */
2705 macp->forwardMgmt = 0;
2706 printk(KERN_ERR "disable\n");
2707 }
2708 }
2709 }
2710 err = 0;
2711 break;
2712 case ZD_IOCTL_GETWPAIE: {
2713 struct ieee80211req_wpaie req_wpaie;
2714 u16_t apId, i, j;
2715
2716 /* Get the AP Id */
2717 apId = zfLnxGetVapId(dev);
2718
2719 if (apId == 0xffff) {
2720 apId = 0;
2721 } else {
2722 apId = apId + 1;
2723 }
2724
2725 if (copy_from_user(&req_wpaie, ifr->ifr_data,
2726 sizeof(struct ieee80211req_wpaie))) {
2727 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2728 return -EFAULT;
2729 }
2730
2731 for (i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++) {
2732 for (j = 0; j < IEEE80211_ADDR_LEN; j++) {
2733 if (macp->stawpaie[i].wpa_macaddr[j] !=
2734 req_wpaie.wpa_macaddr[j])
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002735 break;
2736 }
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002737 if (j == 6)
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002738 break;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002739 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002740
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002741 if (i < ZM_OAL_MAX_STA_SUPPORT) {
2742 /* printk("ZD_IOCTL_GETWPAIE - sta index = % d\n", i); */
2743 memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie,
2744 IEEE80211_MAX_IE_SIZE);
2745 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002746
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002747 if (copy_to_user(wrq->u.data.pointer, &req_wpaie,
2748 sizeof(struct ieee80211req_wpaie))) {
2749 return -EFAULT;
2750 }
2751 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002752
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002753 err = 0;
2754 break;
2755 #ifdef ZM_ENABLE_CENC
2756 case ZM_IOCTL_CENC:
2757 if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data,
2758 sizeof(struct athr_wlan_param))) {
2759 printk(KERN_ERR "usbdrv : copy_from_user error\n");
2760 return -EFAULT;
2761 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002762
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002763 usbdrv_cenc_ioctl(dev,
2764 (struct zydas_cenc_param *)&macp->zd_wpa_req);
2765 err = 0;
2766 break;
2767 #endif /* ZM_ENABLE_CENC */
2768 default:
2769 err = -EOPNOTSUPP;
2770 break;
2771 }
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002772
Dragoslav Zaricaef911a2009-03-16 23:17:47 +01002773 return err;
Luis R. Rodriguez4bd43f52008-10-27 22:44:22 -07002774}