1 /*
2  *   Driver for KeyStream 11b/g wireless LAN
3  *
4  *   Copyright (C) 2005-2008 KeyStream Corp.
5  *   Copyright (C) 2009 Renesas Technology Corp.
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License version 2 as
9  *   published by the Free Software Foundation.
10  */
11 
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/compiler.h>
15 #include <linux/init.h>
16 #include <linux/ioport.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_arp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/delay.h>
22 #include <linux/completion.h>
23 #include <linux/mii.h>
24 #include <linux/pci.h>
25 #include <linux/ctype.h>
26 #include <linux/timer.h>
27 #include <linux/atomic.h>
28 #include <linux/io.h>
29 #include <linux/uaccess.h>
30 
31 static int wep_on_off;
32 #define	WEP_OFF		0
33 #define	WEP_ON_64BIT	1
34 #define	WEP_ON_128BIT	2
35 
36 #include "ks_wlan.h"
37 #include "ks_hostif.h"
38 #include "ks_wlan_ioctl.h"
39 
40 /* Include Wireless Extension definition and check version */
41 #include <linux/wireless.h>
42 #define WIRELESS_SPY	/* enable iwspy support */
43 #include <net/iw_handler.h>	/* New driver API */
44 
45 /* Frequency list (map channels to frequencies) */
46 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
47 	2447, 2452, 2457, 2462, 2467, 2472, 2484
48 };
49 
50 /* A few details needed for WEP (Wireless Equivalent Privacy) */
51 #define MAX_KEY_SIZE 13	/* 128 (?) bits */
52 #define MIN_KEY_SIZE  5	/* 40 bits RC4 - WEP */
53 struct wep_key {
54 	u16 len;
55 	u8 key[16];	/* 40-bit and 104-bit keys */
56 };
57 
58 /* Backward compatibility */
59 #ifndef IW_ENCODE_NOKEY
60 #define IW_ENCODE_NOKEY 0x0800	/* Key is write only, so not present */
61 #define IW_ENCODE_MODE  (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
62 #endif /* IW_ENCODE_NOKEY */
63 
64 /* List of Wireless Handlers (new API) */
65 static const struct iw_handler_def ks_wlan_handler_def;
66 
67 #define KSC_OPNOTSUPP	/* Operation Not Support */
68 
69 /*
70  *	function prototypes
71  */
72 static int ks_wlan_open(struct net_device *dev);
73 static void ks_wlan_tx_timeout(struct net_device *dev);
74 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
75 static int ks_wlan_close(struct net_device *dev);
76 static void ks_wlan_set_multicast_list(struct net_device *dev);
77 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
78 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
79 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
80 				int cmd);
81 
82 static atomic_t update_phyinfo;
83 static struct timer_list update_phyinfo_timer;
84 static
85 int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
86 {
87 	struct iw_statistics *wstats = &priv->wstats;
88 
89 	DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
90 
91 	if (priv->dev_state < DEVICE_STATE_READY)
92 		return -EBUSY;	/* not finished initialize */
93 
94 	if (atomic_read(&update_phyinfo))
95 		return -EPERM;
96 
97 	/* The status */
98 	wstats->status = priv->reg.operation_mode;	/* Operation mode */
99 
100 	/* Signal quality and co. But where is the noise level ??? */
101 	hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
102 
103 	/* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
104 	if (!wait_for_completion_interruptible_timeout
105 	    (&priv->confirm_wait, HZ / 2)) {
106 		DPRINTK(1, "wait time out!!\n");
107 	}
108 
109 	atomic_inc(&update_phyinfo);
110 	update_phyinfo_timer.expires = jiffies + HZ;	/* 1sec */
111 	add_timer(&update_phyinfo_timer);
112 
113 	return 0;
114 }
115 
116 static
117 void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
118 {
119 	DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
120 	atomic_set(&update_phyinfo, 0);
121 }
122 
123 int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
124 			    unsigned int commit_flag)
125 {
126 	DPRINTK(2, "\n");
127 
128 	hostif_sme_enqueue(priv, SME_STOP_REQUEST);
129 
130 	if (commit_flag & SME_RTS)
131 		hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
132 	if (commit_flag & SME_FRAG)
133 		hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
134 
135 	if (commit_flag & SME_WEP_INDEX)
136 		hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
137 	if (commit_flag & SME_WEP_VAL1)
138 		hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
139 	if (commit_flag & SME_WEP_VAL2)
140 		hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
141 	if (commit_flag & SME_WEP_VAL3)
142 		hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
143 	if (commit_flag & SME_WEP_VAL4)
144 		hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
145 	if (commit_flag & SME_WEP_FLAG)
146 		hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
147 
148 	if (commit_flag & SME_RSN) {
149 		hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
150 		hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
151 	}
152 	if (commit_flag & SME_RSN_MULTICAST)
153 		hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
154 	if (commit_flag & SME_RSN_UNICAST)
155 		hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
156 	if (commit_flag & SME_RSN_AUTH)
157 		hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
158 
159 	hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
160 
161 	hostif_sme_enqueue(priv, SME_START_REQUEST);
162 
163 	return 0;
164 }
165 
166 /*
167  * Initial Wireless Extension code for Ks_Wlannet driver by :
168  *	Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
169  * Conversion to new driver API by :
170  *	Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
171  * Javier also did a good amount of work here, adding some new extensions
172  * and fixing my code. Let's just say that without him this code just
173  * would not work at all... - Jean II
174  */
175 
176 static int ks_wlan_get_name(struct net_device *dev,
177 			    struct iw_request_info *info, char *cwrq,
178 			    char *extra)
179 {
180 	struct ks_wlan_private *priv = netdev_priv(dev);
181 
182 	if (priv->sleep_mode == SLP_SLEEP)
183 		return -EPERM;
184 
185 	/* for SLEEP MODE */
186 	if (priv->dev_state < DEVICE_STATE_READY)
187 		strcpy(cwrq, "NOT READY!");
188 	else if (priv->reg.phy_type == D_11B_ONLY_MODE)
189 		strcpy(cwrq, "IEEE 802.11b");
190 	else if (priv->reg.phy_type == D_11G_ONLY_MODE)
191 		strcpy(cwrq, "IEEE 802.11g");
192 	else
193 		strcpy(cwrq, "IEEE 802.11b/g");
194 
195 	return 0;
196 }
197 
198 static int ks_wlan_set_freq(struct net_device *dev,
199 			    struct iw_request_info *info, struct iw_freq *fwrq,
200 			    char *extra)
201 {
202 	struct ks_wlan_private *priv = netdev_priv(dev);
203 	int channel;
204 
205 	if (priv->sleep_mode == SLP_SLEEP)
206 		return -EPERM;
207 
208 	/* for SLEEP MODE */
209 	/* If setting by frequency, convert to a channel */
210 	if ((fwrq->e == 1) &&
211 	    (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
212 		int f = fwrq->m / 100000;
213 		int c = 0;
214 
215 		while ((c < 14) && (f != frequency_list[c]))
216 			c++;
217 		/* Hack to fall through... */
218 		fwrq->e = 0;
219 		fwrq->m = c + 1;
220 	}
221 	/* Setting by channel number */
222 	if ((fwrq->m > 1000) || (fwrq->e > 0))
223 		return -EOPNOTSUPP;
224 
225 	channel = fwrq->m;
226 	/* We should do a better check than that,
227 	 * based on the card capability !!!
228 	 */
229 	if ((channel < 1) || (channel > 14)) {
230 		netdev_dbg(dev, "%s: New channel value of %d is invalid!\n",
231 			   dev->name, fwrq->m);
232 		return -EINVAL;
233 	}
234 
235 	/* Yes ! We can set it !!! */
236 	priv->reg.channel = (u8)(channel);
237 	priv->need_commit |= SME_MODE_SET;
238 
239 	return -EINPROGRESS;	/* Call commit handler */
240 }
241 
242 static int ks_wlan_get_freq(struct net_device *dev,
243 			    struct iw_request_info *info, struct iw_freq *fwrq,
244 			    char *extra)
245 {
246 	struct ks_wlan_private *priv = netdev_priv(dev);
247 	int f;
248 
249 	if (priv->sleep_mode == SLP_SLEEP)
250 		return -EPERM;
251 
252 	/* for SLEEP MODE */
253 	if (is_connect_status(priv->connect_status))
254 		f = (int)priv->current_ap.channel;
255 	else
256 		f = (int)priv->reg.channel;
257 
258 	fwrq->m = frequency_list[f - 1] * 100000;
259 	fwrq->e = 1;
260 
261 	return 0;
262 }
263 
264 static int ks_wlan_set_essid(struct net_device *dev,
265 			     struct iw_request_info *info,
266 			     struct iw_point *dwrq, char *extra)
267 {
268 	struct ks_wlan_private *priv = netdev_priv(dev);
269 	size_t len;
270 
271 	DPRINTK(2, " %d\n", dwrq->flags);
272 
273 	if (priv->sleep_mode == SLP_SLEEP)
274 		return -EPERM;
275 
276 	/* for SLEEP MODE */
277 	/* Check if we asked for `any' */
278 	if (!dwrq->flags) {
279 		/* Just send an empty SSID list */
280 		memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
281 		priv->reg.ssid.size = 0;
282 	} else {
283 #if 1
284 		len = dwrq->length;
285 		/* iwconfig uses nul termination in SSID.. */
286 		if (len > 0 && extra[len - 1] == '\0')
287 			len--;
288 
289 		/* Check the size of the string */
290 		if (len > IW_ESSID_MAX_SIZE)
291 			return -EINVAL;
292 
293 #else
294 		/* Check the size of the string */
295 		if (dwrq->length > IW_ESSID_MAX_SIZE + 1)
296 			return -E2BIG;
297 
298 #endif
299 
300 		/* Set the SSID */
301 		memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
302 
303 #if 1
304 		memcpy(priv->reg.ssid.body, extra, len);
305 		priv->reg.ssid.size = len;
306 #else
307 		memcpy(priv->reg.ssid.body, extra, dwrq->length);
308 		priv->reg.ssid.size = dwrq->length;
309 #endif
310 	}
311 	/* Write it to the card */
312 	priv->need_commit |= SME_MODE_SET;
313 
314 //      return  -EINPROGRESS;   /* Call commit handler */
315 	ks_wlan_setup_parameter(priv, priv->need_commit);
316 	priv->need_commit = 0;
317 	return 0;
318 }
319 
320 static int ks_wlan_get_essid(struct net_device *dev,
321 			     struct iw_request_info *info,
322 			     struct iw_point *dwrq, char *extra)
323 {
324 	struct ks_wlan_private *priv = netdev_priv(dev);
325 
326 	if (priv->sleep_mode == SLP_SLEEP)
327 		return -EPERM;
328 
329 	/* for SLEEP MODE */
330 	/* Note : if dwrq->flags != 0, we should
331 	 * get the relevant SSID from the SSID list...
332 	 */
333 	if (priv->reg.ssid.size != 0) {
334 		/* Get the current SSID */
335 		memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
336 
337 		/* If none, we may want to get the one that was set */
338 
339 		/* Push it out ! */
340 		dwrq->length = priv->reg.ssid.size;
341 		dwrq->flags = 1;	/* active */
342 	} else {
343 		dwrq->length = 0;
344 		dwrq->flags = 0;	/* ANY */
345 	}
346 
347 	return 0;
348 }
349 
350 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
351 			   struct sockaddr *ap_addr, char *extra)
352 {
353 	struct ks_wlan_private *priv = netdev_priv(dev);
354 
355 	DPRINTK(2, "\n");
356 
357 	if (priv->sleep_mode == SLP_SLEEP)
358 		return -EPERM;
359 
360 	/* for SLEEP MODE */
361 	if (priv->reg.operation_mode == MODE_ADHOC ||
362 	    priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
363 		memcpy(priv->reg.bssid, &ap_addr->sa_data, ETH_ALEN);
364 
365 		if (is_valid_ether_addr((u8 *)priv->reg.bssid))
366 			priv->need_commit |= SME_MODE_SET;
367 
368 	} else {
369 		eth_zero_addr(priv->reg.bssid);
370 		return -EOPNOTSUPP;
371 	}
372 
373 	DPRINTK(2, "bssid = %pM\n", priv->reg.bssid);
374 
375 	/* Write it to the card */
376 	if (priv->need_commit) {
377 		priv->need_commit |= SME_MODE_SET;
378 		return -EINPROGRESS;	/* Call commit handler */
379 	}
380 	return 0;
381 }
382 
383 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
384 			   struct sockaddr *awrq, char *extra)
385 {
386 	struct ks_wlan_private *priv = netdev_priv(dev);
387 
388 	if (priv->sleep_mode == SLP_SLEEP)
389 		return -EPERM;
390 
391 	/* for SLEEP MODE */
392 	if (is_connect_status(priv->connect_status))
393 		memcpy(awrq->sa_data, priv->current_ap.bssid, ETH_ALEN);
394 	else
395 		eth_zero_addr(awrq->sa_data);
396 
397 	awrq->sa_family = ARPHRD_ETHER;
398 
399 	return 0;
400 }
401 
402 static int ks_wlan_set_nick(struct net_device *dev,
403 			    struct iw_request_info *info, struct iw_point *dwrq,
404 			    char *extra)
405 {
406 	struct ks_wlan_private *priv = netdev_priv(dev);
407 
408 	if (priv->sleep_mode == SLP_SLEEP)
409 		return -EPERM;
410 
411 	/* for SLEEP MODE */
412 	/* Check the size of the string */
413 	if (dwrq->length > 16 + 1)
414 		return -E2BIG;
415 
416 	memset(priv->nick, 0, sizeof(priv->nick));
417 	memcpy(priv->nick, extra, dwrq->length);
418 
419 	return -EINPROGRESS;	/* Call commit handler */
420 }
421 
422 static int ks_wlan_get_nick(struct net_device *dev,
423 			    struct iw_request_info *info, struct iw_point *dwrq,
424 			    char *extra)
425 {
426 	struct ks_wlan_private *priv = netdev_priv(dev);
427 
428 	if (priv->sleep_mode == SLP_SLEEP)
429 		return -EPERM;
430 
431 	/* for SLEEP MODE */
432 	strncpy(extra, priv->nick, 16);
433 	extra[16] = '\0';
434 	dwrq->length = strlen(extra) + 1;
435 
436 	return 0;
437 }
438 
439 static int ks_wlan_set_rate(struct net_device *dev,
440 			    struct iw_request_info *info, struct iw_param *vwrq,
441 			    char *extra)
442 {
443 	struct ks_wlan_private *priv = netdev_priv(dev);
444 	int i = 0;
445 
446 	if (priv->sleep_mode == SLP_SLEEP)
447 		return -EPERM;
448 
449 	/* for SLEEP MODE */
450 	if (priv->reg.phy_type == D_11B_ONLY_MODE) {
451 		if (vwrq->fixed == 1) {
452 			switch (vwrq->value) {
453 			case 11000000:
454 			case 5500000:
455 				priv->reg.rate_set.body[0] =
456 				    (uint8_t)(vwrq->value / 500000);
457 				break;
458 			case 2000000:
459 			case 1000000:
460 				priv->reg.rate_set.body[0] =
461 				    ((uint8_t)(vwrq->value / 500000)) |
462 				    BASIC_RATE;
463 				break;
464 			default:
465 				return -EINVAL;
466 			}
467 			priv->reg.tx_rate = TX_RATE_FIXED;
468 			priv->reg.rate_set.size = 1;
469 		} else {	/* vwrq->fixed == 0 */
470 			if (vwrq->value > 0) {
471 				switch (vwrq->value) {
472 				case 11000000:
473 					priv->reg.rate_set.body[3] =
474 					    TX_RATE_11M;
475 					i++;
476 				case 5500000:
477 					priv->reg.rate_set.body[2] = TX_RATE_5M;
478 					i++;
479 				case 2000000:
480 					priv->reg.rate_set.body[1] =
481 					    TX_RATE_2M | BASIC_RATE;
482 					i++;
483 				case 1000000:
484 					priv->reg.rate_set.body[0] =
485 					    TX_RATE_1M | BASIC_RATE;
486 					i++;
487 					break;
488 				default:
489 					return -EINVAL;
490 				}
491 				priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
492 				priv->reg.rate_set.size = i;
493 			} else {
494 				priv->reg.rate_set.body[3] = TX_RATE_11M;
495 				priv->reg.rate_set.body[2] = TX_RATE_5M;
496 				priv->reg.rate_set.body[1] =
497 				    TX_RATE_2M | BASIC_RATE;
498 				priv->reg.rate_set.body[0] =
499 				    TX_RATE_1M | BASIC_RATE;
500 				priv->reg.tx_rate = TX_RATE_FULL_AUTO;
501 				priv->reg.rate_set.size = 4;
502 			}
503 		}
504 	} else {	/* D_11B_ONLY_MODE or  D_11BG_COMPATIBLE_MODE */
505 		if (vwrq->fixed == 1) {
506 			switch (vwrq->value) {
507 			case 54000000:
508 			case 48000000:
509 			case 36000000:
510 			case 18000000:
511 			case 9000000:
512 				priv->reg.rate_set.body[0] =
513 				    (uint8_t)(vwrq->value / 500000);
514 				break;
515 			case 24000000:
516 			case 12000000:
517 			case 11000000:
518 			case 6000000:
519 			case 5500000:
520 			case 2000000:
521 			case 1000000:
522 				priv->reg.rate_set.body[0] =
523 				    ((uint8_t)(vwrq->value / 500000)) |
524 				    BASIC_RATE;
525 				break;
526 			default:
527 				return -EINVAL;
528 			}
529 			priv->reg.tx_rate = TX_RATE_FIXED;
530 			priv->reg.rate_set.size = 1;
531 		} else {	/* vwrq->fixed == 0 */
532 			if (vwrq->value > 0) {
533 				switch (vwrq->value) {
534 				case 54000000:
535 					priv->reg.rate_set.body[11] =
536 					    TX_RATE_54M;
537 					i++;
538 				case 48000000:
539 					priv->reg.rate_set.body[10] =
540 					    TX_RATE_48M;
541 					i++;
542 				case 36000000:
543 					priv->reg.rate_set.body[9] =
544 					    TX_RATE_36M;
545 					i++;
546 				case 24000000:
547 				case 18000000:
548 				case 12000000:
549 				case 11000000:
550 				case 9000000:
551 				case 6000000:
552 					if (vwrq->value == 24000000) {
553 						priv->reg.rate_set.body[8] =
554 						    TX_RATE_18M;
555 						i++;
556 						priv->reg.rate_set.body[7] =
557 						    TX_RATE_9M;
558 						i++;
559 						priv->reg.rate_set.body[6] =
560 						    TX_RATE_24M | BASIC_RATE;
561 						i++;
562 						priv->reg.rate_set.body[5] =
563 						    TX_RATE_12M | BASIC_RATE;
564 						i++;
565 						priv->reg.rate_set.body[4] =
566 						    TX_RATE_6M | BASIC_RATE;
567 						i++;
568 						priv->reg.rate_set.body[3] =
569 						    TX_RATE_11M | BASIC_RATE;
570 						i++;
571 					} else if (vwrq->value == 18000000) {
572 						priv->reg.rate_set.body[7] =
573 						    TX_RATE_18M;
574 						i++;
575 						priv->reg.rate_set.body[6] =
576 						    TX_RATE_9M;
577 						i++;
578 						priv->reg.rate_set.body[5] =
579 						    TX_RATE_12M | BASIC_RATE;
580 						i++;
581 						priv->reg.rate_set.body[4] =
582 						    TX_RATE_6M | BASIC_RATE;
583 						i++;
584 						priv->reg.rate_set.body[3] =
585 						    TX_RATE_11M | BASIC_RATE;
586 						i++;
587 					} else if (vwrq->value == 12000000) {
588 						priv->reg.rate_set.body[6] =
589 						    TX_RATE_9M;
590 						i++;
591 						priv->reg.rate_set.body[5] =
592 						    TX_RATE_12M | BASIC_RATE;
593 						i++;
594 						priv->reg.rate_set.body[4] =
595 						    TX_RATE_6M | BASIC_RATE;
596 						i++;
597 						priv->reg.rate_set.body[3] =
598 						    TX_RATE_11M | BASIC_RATE;
599 						i++;
600 					} else if (vwrq->value == 11000000) {
601 						priv->reg.rate_set.body[5] =
602 						    TX_RATE_9M;
603 						i++;
604 						priv->reg.rate_set.body[4] =
605 						    TX_RATE_6M | BASIC_RATE;
606 						i++;
607 						priv->reg.rate_set.body[3] =
608 						    TX_RATE_11M | BASIC_RATE;
609 						i++;
610 					} else if (vwrq->value == 9000000) {
611 						priv->reg.rate_set.body[4] =
612 						    TX_RATE_9M;
613 						i++;
614 						priv->reg.rate_set.body[3] =
615 						    TX_RATE_6M | BASIC_RATE;
616 						i++;
617 					} else {	/* vwrq->value == 6000000 */
618 						priv->reg.rate_set.body[3] =
619 						    TX_RATE_6M | BASIC_RATE;
620 						i++;
621 					}
622 				case 5500000:
623 					priv->reg.rate_set.body[2] =
624 					    TX_RATE_5M | BASIC_RATE;
625 					i++;
626 				case 2000000:
627 					priv->reg.rate_set.body[1] =
628 					    TX_RATE_2M | BASIC_RATE;
629 					i++;
630 				case 1000000:
631 					priv->reg.rate_set.body[0] =
632 					    TX_RATE_1M | BASIC_RATE;
633 					i++;
634 					break;
635 				default:
636 					return -EINVAL;
637 				}
638 				priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
639 				priv->reg.rate_set.size = i;
640 			} else {
641 				priv->reg.rate_set.body[11] = TX_RATE_54M;
642 				priv->reg.rate_set.body[10] = TX_RATE_48M;
643 				priv->reg.rate_set.body[9] = TX_RATE_36M;
644 				priv->reg.rate_set.body[8] = TX_RATE_18M;
645 				priv->reg.rate_set.body[7] = TX_RATE_9M;
646 				priv->reg.rate_set.body[6] =
647 				    TX_RATE_24M | BASIC_RATE;
648 				priv->reg.rate_set.body[5] =
649 				    TX_RATE_12M | BASIC_RATE;
650 				priv->reg.rate_set.body[4] =
651 				    TX_RATE_6M | BASIC_RATE;
652 				priv->reg.rate_set.body[3] =
653 				    TX_RATE_11M | BASIC_RATE;
654 				priv->reg.rate_set.body[2] =
655 				    TX_RATE_5M | BASIC_RATE;
656 				priv->reg.rate_set.body[1] =
657 				    TX_RATE_2M | BASIC_RATE;
658 				priv->reg.rate_set.body[0] =
659 				    TX_RATE_1M | BASIC_RATE;
660 				priv->reg.tx_rate = TX_RATE_FULL_AUTO;
661 				priv->reg.rate_set.size = 12;
662 			}
663 		}
664 	}
665 
666 	priv->need_commit |= SME_MODE_SET;
667 
668 	return -EINPROGRESS;	/* Call commit handler */
669 }
670 
671 static int ks_wlan_get_rate(struct net_device *dev,
672 			    struct iw_request_info *info, struct iw_param *vwrq,
673 			    char *extra)
674 {
675 	struct ks_wlan_private *priv = netdev_priv(dev);
676 
677 	DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
678 		in_interrupt(), atomic_read(&update_phyinfo));
679 
680 	if (priv->sleep_mode == SLP_SLEEP)
681 		return -EPERM;
682 
683 	/* for SLEEP MODE */
684 	if (!atomic_read(&update_phyinfo))
685 		ks_wlan_update_phy_information(priv);
686 
687 	vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
688 	if (priv->reg.tx_rate == TX_RATE_FIXED)
689 		vwrq->fixed = 1;
690 	else
691 		vwrq->fixed = 0;
692 
693 	return 0;
694 }
695 
696 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
697 			   struct iw_param *vwrq, char *extra)
698 {
699 	struct ks_wlan_private *priv = netdev_priv(dev);
700 	int rthr = vwrq->value;
701 
702 	if (priv->sleep_mode == SLP_SLEEP)
703 		return -EPERM;
704 
705 	/* for SLEEP MODE */
706 	if (vwrq->disabled)
707 		rthr = 2347;
708 	if ((rthr < 0) || (rthr > 2347))
709 		return -EINVAL;
710 
711 	priv->reg.rts = rthr;
712 	priv->need_commit |= SME_RTS;
713 
714 	return -EINPROGRESS;	/* Call commit handler */
715 }
716 
717 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
718 			   struct iw_param *vwrq, char *extra)
719 {
720 	struct ks_wlan_private *priv = netdev_priv(dev);
721 
722 	if (priv->sleep_mode == SLP_SLEEP)
723 		return -EPERM;
724 
725 	/* for SLEEP MODE */
726 	vwrq->value = priv->reg.rts;
727 	vwrq->disabled = (vwrq->value >= 2347);
728 	vwrq->fixed = 1;
729 
730 	return 0;
731 }
732 
733 static int ks_wlan_set_frag(struct net_device *dev,
734 			    struct iw_request_info *info, struct iw_param *vwrq,
735 			    char *extra)
736 {
737 	struct ks_wlan_private *priv = netdev_priv(dev);
738 	int fthr = vwrq->value;
739 
740 	if (priv->sleep_mode == SLP_SLEEP)
741 		return -EPERM;
742 
743 	/* for SLEEP MODE */
744 	if (vwrq->disabled)
745 		fthr = 2346;
746 	if ((fthr < 256) || (fthr > 2346))
747 		return -EINVAL;
748 
749 	fthr &= ~0x1;	/* Get an even value - is it really needed ??? */
750 	priv->reg.fragment = fthr;
751 	priv->need_commit |= SME_FRAG;
752 
753 	return -EINPROGRESS;	/* Call commit handler */
754 }
755 
756 static int ks_wlan_get_frag(struct net_device *dev,
757 			    struct iw_request_info *info, struct iw_param *vwrq,
758 			    char *extra)
759 {
760 	struct ks_wlan_private *priv = netdev_priv(dev);
761 
762 	if (priv->sleep_mode == SLP_SLEEP)
763 		return -EPERM;
764 
765 	/* for SLEEP MODE */
766 	vwrq->value = priv->reg.fragment;
767 	vwrq->disabled = (vwrq->value >= 2346);
768 	vwrq->fixed = 1;
769 
770 	return 0;
771 }
772 
773 static int ks_wlan_set_mode(struct net_device *dev,
774 			    struct iw_request_info *info, __u32 *uwrq,
775 			    char *extra)
776 {
777 	struct ks_wlan_private *priv = netdev_priv(dev);
778 
779 	DPRINTK(2, "mode=%d\n", *uwrq);
780 
781 	if (priv->sleep_mode == SLP_SLEEP)
782 		return -EPERM;
783 
784 	/* for SLEEP MODE */
785 	switch (*uwrq) {
786 	case IW_MODE_ADHOC:
787 		priv->reg.operation_mode = MODE_ADHOC;
788 		priv->need_commit |= SME_MODE_SET;
789 		break;
790 	case IW_MODE_INFRA:
791 		priv->reg.operation_mode = MODE_INFRASTRUCTURE;
792 		priv->need_commit |= SME_MODE_SET;
793 		break;
794 	case IW_MODE_AUTO:
795 	case IW_MODE_MASTER:
796 	case IW_MODE_REPEAT:
797 	case IW_MODE_SECOND:
798 	case IW_MODE_MONITOR:
799 	default:
800 		return -EINVAL;
801 	}
802 
803 	return -EINPROGRESS;	/* Call commit handler */
804 }
805 
806 static int ks_wlan_get_mode(struct net_device *dev,
807 			    struct iw_request_info *info, __u32 *uwrq,
808 			    char *extra)
809 {
810 	struct ks_wlan_private *priv = netdev_priv(dev);
811 
812 	if (priv->sleep_mode == SLP_SLEEP)
813 		return -EPERM;
814 
815 	/* for SLEEP MODE */
816 	/* If not managed, assume it's ad-hoc */
817 	switch (priv->reg.operation_mode) {
818 	case MODE_INFRASTRUCTURE:
819 		*uwrq = IW_MODE_INFRA;
820 		break;
821 	case MODE_ADHOC:
822 		*uwrq = IW_MODE_ADHOC;
823 		break;
824 	default:
825 		*uwrq = IW_MODE_ADHOC;
826 	}
827 
828 	return 0;
829 }
830 
831 static int ks_wlan_set_encode(struct net_device *dev,
832 			      struct iw_request_info *info,
833 			      struct iw_point *dwrq, char *extra)
834 {
835 	struct ks_wlan_private *priv = netdev_priv(dev);
836 
837 	struct wep_key key;
838 	int index = (dwrq->flags & IW_ENCODE_INDEX);
839 	int current_index = priv->reg.wep_index;
840 	int i;
841 
842 	DPRINTK(2, "flags=%04X\n", dwrq->flags);
843 
844 	if (priv->sleep_mode == SLP_SLEEP)
845 		return -EPERM;
846 
847 	/* for SLEEP MODE */
848 	/* index check */
849 	if ((index < 0) || (index > 4))
850 		return -EINVAL;
851 	else if (index == 0)
852 		index = current_index;
853 	else
854 		index--;
855 
856 	/* Is WEP supported ? */
857 	/* Basic checking: do we have a key to set ? */
858 	if (dwrq->length > 0) {
859 		if (dwrq->length > MAX_KEY_SIZE) {	/* Check the size of the key */
860 			return -EINVAL;
861 		}
862 		if (dwrq->length > MIN_KEY_SIZE) {	/* Set the length */
863 			key.len = MAX_KEY_SIZE;
864 			priv->reg.privacy_invoked = 0x01;
865 			priv->need_commit |= SME_WEP_FLAG;
866 			wep_on_off = WEP_ON_128BIT;
867 		} else {
868 			if (dwrq->length > 0) {
869 				key.len = MIN_KEY_SIZE;
870 				priv->reg.privacy_invoked = 0x01;
871 				priv->need_commit |= SME_WEP_FLAG;
872 				wep_on_off = WEP_ON_64BIT;
873 			} else {	/* Disable the key */
874 				key.len = 0;
875 			}
876 		}
877 		/* Check if the key is not marked as invalid */
878 		if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
879 			/* Cleanup */
880 			memset(key.key, 0, MAX_KEY_SIZE);
881 			/* Copy the key in the driver */
882 			if (copy_from_user
883 			    (key.key, dwrq->pointer, dwrq->length)) {
884 				key.len = 0;
885 				return -EFAULT;
886 			}
887 			/* Send the key to the card */
888 			priv->reg.wep_key[index].size = key.len;
889 			for (i = 0; i < (priv->reg.wep_key[index].size); i++)
890 				priv->reg.wep_key[index].val[i] = key.key[i];
891 
892 			priv->need_commit |= (SME_WEP_VAL1 << index);
893 			priv->reg.wep_index = index;
894 			priv->need_commit |= SME_WEP_INDEX;
895 		}
896 	} else {
897 		if (dwrq->flags & IW_ENCODE_DISABLED) {
898 			priv->reg.wep_key[0].size = 0;
899 			priv->reg.wep_key[1].size = 0;
900 			priv->reg.wep_key[2].size = 0;
901 			priv->reg.wep_key[3].size = 0;
902 			priv->reg.privacy_invoked = 0x00;
903 			if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
904 				priv->need_commit |= SME_MODE_SET;
905 
906 			priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
907 			wep_on_off = WEP_OFF;
908 			priv->need_commit |= SME_WEP_FLAG;
909 		} else {
910 			/* Do we want to just set the transmit key index ? */
911 			if ((index >= 0) && (index < 4)) {
912 				/* set_wep_key(priv, index, 0, 0, 1);   xxx */
913 				if (priv->reg.wep_key[index].size != 0) {
914 					priv->reg.wep_index = index;
915 					priv->need_commit |= SME_WEP_INDEX;
916 				} else {
917 					return -EINVAL;
918 				}
919 			}
920 		}
921 	}
922 
923 	/* Commit the changes if needed */
924 	if (dwrq->flags & IW_ENCODE_MODE)
925 		priv->need_commit |= SME_WEP_FLAG;
926 
927 	if (dwrq->flags & IW_ENCODE_OPEN) {
928 		if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY)
929 			priv->need_commit |= SME_MODE_SET;
930 
931 		priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
932 	} else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
933 		if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM)
934 			priv->need_commit |= SME_MODE_SET;
935 
936 		priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
937 	}
938 //      return -EINPROGRESS;            /* Call commit handler */
939 	if (priv->need_commit) {
940 		ks_wlan_setup_parameter(priv, priv->need_commit);
941 		priv->need_commit = 0;
942 	}
943 	return 0;
944 }
945 
946 static int ks_wlan_get_encode(struct net_device *dev,
947 			      struct iw_request_info *info,
948 			      struct iw_point *dwrq, char *extra)
949 {
950 	struct ks_wlan_private *priv = netdev_priv(dev);
951 	char zeros[16];
952 	int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
953 
954 	if (priv->sleep_mode == SLP_SLEEP)
955 		return -EPERM;
956 
957 	/* for SLEEP MODE */
958 	dwrq->flags = IW_ENCODE_DISABLED;
959 
960 	/* Check encryption mode */
961 	switch (priv->reg.authenticate_type) {
962 	case AUTH_TYPE_OPEN_SYSTEM:
963 		dwrq->flags = IW_ENCODE_OPEN;
964 		break;
965 	case AUTH_TYPE_SHARED_KEY:
966 		dwrq->flags = IW_ENCODE_RESTRICTED;
967 		break;
968 	}
969 
970 	memset(zeros, 0, sizeof(zeros));
971 
972 	/* Which key do we want ? -1 -> tx index */
973 	if ((index < 0) || (index >= 4))
974 		index = priv->reg.wep_index;
975 	if (priv->reg.privacy_invoked) {
976 		dwrq->flags &= ~IW_ENCODE_DISABLED;
977 		/* dwrq->flags |= IW_ENCODE_NOKEY; */
978 	}
979 	dwrq->flags |= index + 1;
980 	DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
981 	/* Copy the key to the user buffer */
982 	if ((index >= 0) && (index < 4))
983 		dwrq->length = priv->reg.wep_key[index].size;
984 	if (dwrq->length > 16)
985 		dwrq->length = 0;
986 #if 1	/* IW_ENCODE_NOKEY; */
987 	if (dwrq->length) {
988 		if ((index >= 0) && (index < 4))
989 			memcpy(extra, priv->reg.wep_key[index].val,
990 			       dwrq->length);
991 	} else {
992 		memcpy(extra, zeros, dwrq->length);
993 	}
994 #endif
995 	return 0;
996 }
997 
998 #ifndef KSC_OPNOTSUPP
999 static int ks_wlan_set_txpow(struct net_device *dev,
1000 			     struct iw_request_info *info,
1001 			     struct iw_param *vwrq, char *extra)
1002 {
1003 	return -EOPNOTSUPP;	/* Not Support */
1004 }
1005 
1006 static int ks_wlan_get_txpow(struct net_device *dev,
1007 			     struct iw_request_info *info,
1008 			     struct iw_param *vwrq, char *extra)
1009 {
1010 	if (priv->sleep_mode == SLP_SLEEP)
1011 		return -EPERM;
1012 
1013 	/* for SLEEP MODE */
1014 	/* Not Support */
1015 	vwrq->value = 0;
1016 	vwrq->disabled = (vwrq->value == 0);
1017 	vwrq->fixed = 1;
1018 	return 0;
1019 }
1020 
1021 static int ks_wlan_set_retry(struct net_device *dev,
1022 			     struct iw_request_info *info,
1023 			     struct iw_param *vwrq, char *extra)
1024 {
1025 	return -EOPNOTSUPP;	/* Not Support */
1026 }
1027 
1028 static int ks_wlan_get_retry(struct net_device *dev,
1029 			     struct iw_request_info *info,
1030 			     struct iw_param *vwrq, char *extra)
1031 {
1032 	if (priv->sleep_mode == SLP_SLEEP)
1033 		return -EPERM;
1034 
1035 	/* for SLEEP MODE */
1036 	/* Not Support */
1037 	vwrq->value = 0;
1038 	vwrq->disabled = (vwrq->value == 0);
1039 	vwrq->fixed = 1;
1040 	return 0;
1041 }
1042 #endif /* KSC_OPNOTSUPP */
1043 
1044 static int ks_wlan_get_range(struct net_device *dev,
1045 			     struct iw_request_info *info,
1046 			     struct iw_point *dwrq, char *extra)
1047 {
1048 	struct ks_wlan_private *priv = netdev_priv(dev);
1049 	struct iw_range *range = (struct iw_range *)extra;
1050 	int i, k;
1051 
1052 	DPRINTK(2, "\n");
1053 
1054 	if (priv->sleep_mode == SLP_SLEEP)
1055 		return -EPERM;
1056 
1057 	/* for SLEEP MODE */
1058 	dwrq->length = sizeof(struct iw_range);
1059 	memset(range, 0, sizeof(*range));
1060 	range->min_nwid = 0x0000;
1061 	range->max_nwid = 0x0000;
1062 	range->num_channels = 14;
1063 	/* Should be based on cap_rid.country to give only
1064 	 * what the current card support
1065 	 */
1066 	k = 0;
1067 	for (i = 0; i < 13; i++) {	/* channel 1 -- 13 */
1068 		range->freq[k].i = i + 1;	/* List index */
1069 		range->freq[k].m = frequency_list[i] * 100000;
1070 		range->freq[k++].e = 1;	/* Values in table in MHz -> * 10^5 * 10 */
1071 	}
1072 	range->num_frequency = k;
1073 	if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {	/* channel 14 */
1074 		range->freq[13].i = 14;	/* List index */
1075 		range->freq[13].m = frequency_list[13] * 100000;
1076 		range->freq[13].e = 1;	/* Values in table in MHz -> * 10^5 * 10 */
1077 		range->num_frequency = 14;
1078 	}
1079 
1080 	/* Hum... Should put the right values there */
1081 	range->max_qual.qual = 100;
1082 	range->max_qual.level = 256 - 128;	/* 0 dBm? */
1083 	range->max_qual.noise = 256 - 128;
1084 	range->sensitivity = 1;
1085 
1086 	if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1087 		range->bitrate[0] = 1e6;
1088 		range->bitrate[1] = 2e6;
1089 		range->bitrate[2] = 5.5e6;
1090 		range->bitrate[3] = 11e6;
1091 		range->num_bitrates = 4;
1092 	} else {	/* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1093 		range->bitrate[0] = 1e6;
1094 		range->bitrate[1] = 2e6;
1095 		range->bitrate[2] = 5.5e6;
1096 		range->bitrate[3] = 11e6;
1097 
1098 		range->bitrate[4] = 6e6;
1099 		range->bitrate[5] = 9e6;
1100 		range->bitrate[6] = 12e6;
1101 		if (IW_MAX_BITRATES < 9) {
1102 			range->bitrate[7] = 54e6;
1103 			range->num_bitrates = 8;
1104 		} else {
1105 			range->bitrate[7] = 18e6;
1106 			range->bitrate[8] = 24e6;
1107 			range->bitrate[9] = 36e6;
1108 			range->bitrate[10] = 48e6;
1109 			range->bitrate[11] = 54e6;
1110 
1111 			range->num_bitrates = 12;
1112 		}
1113 	}
1114 
1115 	/* Set an indication of the max TCP throughput
1116 	 * in bit/s that we can expect using this interface.
1117 	 * May be use for QoS stuff... Jean II
1118 	 */
1119 	if (i > 2)
1120 		range->throughput = 5000 * 1000;
1121 	else
1122 		range->throughput = 1500 * 1000;
1123 
1124 	range->min_rts = 0;
1125 	range->max_rts = 2347;
1126 	range->min_frag = 256;
1127 	range->max_frag = 2346;
1128 
1129 	range->encoding_size[0] = 5;	/* WEP: RC4 40 bits */
1130 	range->encoding_size[1] = 13;	/* WEP: RC4 ~128 bits */
1131 	range->num_encoding_sizes = 2;
1132 	range->max_encoding_tokens = 4;
1133 
1134 	/* power management not support */
1135 	range->pmp_flags = IW_POWER_ON;
1136 	range->pmt_flags = IW_POWER_ON;
1137 	range->pm_capa = 0;
1138 
1139 	/* Transmit Power - values are in dBm( or mW) */
1140 	range->txpower[0] = -256;
1141 	range->num_txpower = 1;
1142 	range->txpower_capa = IW_TXPOW_DBM;
1143 	/* range->txpower_capa = IW_TXPOW_MWATT; */
1144 
1145 	range->we_version_source = 21;
1146 	range->we_version_compiled = WIRELESS_EXT;
1147 
1148 	range->retry_capa = IW_RETRY_ON;
1149 	range->retry_flags = IW_RETRY_ON;
1150 	range->r_time_flags = IW_RETRY_ON;
1151 
1152 	/* Experimental measurements - boundary 11/5.5 Mb/s
1153 	 *
1154 	 * Note : with or without the (local->rssi), results
1155 	 * are somewhat different. - Jean II
1156 	 */
1157 	range->avg_qual.qual = 50;
1158 	range->avg_qual.level = 186;	/* -70 dBm */
1159 	range->avg_qual.noise = 0;
1160 
1161 	/* Event capability (kernel + driver) */
1162 	range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1163 				IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1164 				IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1165 	range->event_capa[1] = IW_EVENT_CAPA_K_1;
1166 	range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1167 				IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1168 
1169 	/* encode extension (WPA) capability */
1170 	range->enc_capa = (IW_ENC_CAPA_WPA |
1171 			   IW_ENC_CAPA_WPA2 |
1172 			   IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1173 	return 0;
1174 }
1175 
1176 static int ks_wlan_set_power(struct net_device *dev,
1177 			     struct iw_request_info *info,
1178 			     struct iw_param *vwrq, char *extra)
1179 {
1180 	struct ks_wlan_private *priv = netdev_priv(dev);
1181 
1182 	if (priv->sleep_mode == SLP_SLEEP)
1183 		return -EPERM;
1184 
1185 	if (vwrq->disabled) {
1186 		priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
1187 	} else {
1188 		if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1189 			priv->reg.power_mgmt = POWER_MGMT_SAVE1;
1190 		else
1191 			return -EINVAL;
1192 	}
1193 
1194 	hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1195 
1196 	return 0;
1197 }
1198 
1199 static int ks_wlan_get_power(struct net_device *dev,
1200 			     struct iw_request_info *info,
1201 			     struct iw_param *vwrq, char *extra)
1202 {
1203 	struct ks_wlan_private *priv = netdev_priv(dev);
1204 
1205 	if (priv->sleep_mode == SLP_SLEEP)
1206 		return -EPERM;
1207 	/* for SLEEP MODE */
1208 	if (priv->reg.power_mgmt > 0)
1209 		vwrq->disabled = 0;
1210 	else
1211 		vwrq->disabled = 1;
1212 
1213 	return 0;
1214 }
1215 
1216 static int ks_wlan_get_iwstats(struct net_device *dev,
1217 			       struct iw_request_info *info,
1218 			       struct iw_quality *vwrq, char *extra)
1219 {
1220 	struct ks_wlan_private *priv = netdev_priv(dev);
1221 
1222 	if (priv->sleep_mode == SLP_SLEEP)
1223 		return -EPERM;
1224 	/* for SLEEP MODE */
1225 	vwrq->qual = 0;	/* not supported */
1226 	vwrq->level = priv->wstats.qual.level;
1227 	vwrq->noise = 0;	/* not supported */
1228 	vwrq->updated = 0;
1229 
1230 	return 0;
1231 }
1232 
1233 #ifndef KSC_OPNOTSUPP
1234 
1235 static int ks_wlan_set_sens(struct net_device *dev,
1236 			    struct iw_request_info *info, struct iw_param *vwrq,
1237 			    char *extra)
1238 {
1239 	return -EOPNOTSUPP;	/* Not Support */
1240 }
1241 
1242 static int ks_wlan_get_sens(struct net_device *dev,
1243 			    struct iw_request_info *info, struct iw_param *vwrq,
1244 			    char *extra)
1245 {
1246 	/* Not Support */
1247 	vwrq->value = 0;
1248 	vwrq->disabled = (vwrq->value == 0);
1249 	vwrq->fixed = 1;
1250 	return 0;
1251 }
1252 #endif /* KSC_OPNOTSUPP */
1253 
1254 /* Note : this is deprecated in favor of IWSCAN */
1255 static int ks_wlan_get_aplist(struct net_device *dev,
1256 			      struct iw_request_info *info,
1257 			      struct iw_point *dwrq, char *extra)
1258 {
1259 	struct ks_wlan_private *priv = netdev_priv(dev);
1260 	struct sockaddr *address = (struct sockaddr *)extra;
1261 	struct iw_quality qual[LOCAL_APLIST_MAX];
1262 
1263 	int i;
1264 
1265 	if (priv->sleep_mode == SLP_SLEEP)
1266 		return -EPERM;
1267 	/* for SLEEP MODE */
1268 	for (i = 0; i < priv->aplist.size; i++) {
1269 		memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1270 		       ETH_ALEN);
1271 		address[i].sa_family = ARPHRD_ETHER;
1272 		qual[i].level = 256 - priv->aplist.ap[i].rssi;
1273 		qual[i].qual = priv->aplist.ap[i].sq;
1274 		qual[i].noise = 0;	/* invalid noise value */
1275 		qual[i].updated = 7;
1276 	}
1277 	if (i) {
1278 		dwrq->flags = 1;	/* Should be define'd */
1279 		memcpy(extra + sizeof(struct sockaddr) * i,
1280 		       &qual, sizeof(struct iw_quality) * i);
1281 	}
1282 	dwrq->length = i;
1283 
1284 	return 0;
1285 }
1286 
1287 static int ks_wlan_set_scan(struct net_device *dev,
1288 			    struct iw_request_info *info,
1289 			    union iwreq_data *wrqu, char *extra)
1290 {
1291 	struct ks_wlan_private *priv = netdev_priv(dev);
1292 	struct iw_scan_req *req = NULL;
1293 
1294 	DPRINTK(2, "\n");
1295 
1296 	if (priv->sleep_mode == SLP_SLEEP)
1297 		return -EPERM;
1298 
1299 	/* for SLEEP MODE */
1300 	/* specified SSID SCAN */
1301 	if (wrqu->data.length == sizeof(struct iw_scan_req) &&
1302 	    wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1303 		req = (struct iw_scan_req *)extra;
1304 		priv->scan_ssid_len = req->essid_len;
1305 		memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1306 	} else {
1307 		priv->scan_ssid_len = 0;
1308 	}
1309 
1310 	priv->sme_i.sme_flag |= SME_AP_SCAN;
1311 	hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1312 
1313 	/* At this point, just return to the user. */
1314 
1315 	return 0;
1316 }
1317 
1318 /*
1319  * Translate scan data returned from the card to a card independent
1320  * format that the Wireless Tools will understand - Jean II
1321  */
1322 static inline char *ks_wlan_translate_scan(struct net_device *dev,
1323 					   struct iw_request_info *info,
1324 					   char *current_ev, char *end_buf,
1325 					   struct local_ap_t *ap)
1326 {
1327 	/* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1328 	struct iw_event iwe;	/* Temporary buffer */
1329 	u16 capabilities;
1330 	char *current_val;	/* For rates */
1331 	int i;
1332 	static const char rsn_leader[] = "rsn_ie=";
1333 	static const char wpa_leader[] = "wpa_ie=";
1334 	char buf0[RSN_IE_BODY_MAX * 2 + 30];
1335 	char buf1[RSN_IE_BODY_MAX * 2 + 30];
1336 	char *pbuf;
1337 	/* First entry *MUST* be the AP MAC address */
1338 	iwe.cmd = SIOCGIWAP;
1339 	iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1340 	memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1341 	current_ev =
1342 	    iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1343 				 IW_EV_ADDR_LEN);
1344 
1345 	/* Other entries will be displayed in the order we give them */
1346 
1347 	/* Add the ESSID */
1348 	iwe.u.data.length = ap->ssid.size;
1349 	if (iwe.u.data.length > 32)
1350 		iwe.u.data.length = 32;
1351 	iwe.cmd = SIOCGIWESSID;
1352 	iwe.u.data.flags = 1;
1353 	current_ev =
1354 	    iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1355 				 ap->ssid.body);
1356 
1357 	/* Add mode */
1358 	iwe.cmd = SIOCGIWMODE;
1359 	capabilities = ap->capability;
1360 	if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1361 		if (capabilities & BSS_CAP_ESS)
1362 			iwe.u.mode = IW_MODE_INFRA;
1363 		else
1364 			iwe.u.mode = IW_MODE_ADHOC;
1365 		current_ev =
1366 		    iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1367 					 IW_EV_UINT_LEN);
1368 	}
1369 
1370 	/* Add frequency */
1371 	iwe.cmd = SIOCGIWFREQ;
1372 	iwe.u.freq.m = ap->channel;
1373 	iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1374 	iwe.u.freq.e = 1;
1375 	current_ev =
1376 	    iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1377 				 IW_EV_FREQ_LEN);
1378 
1379 	/* Add quality statistics */
1380 	iwe.cmd = IWEVQUAL;
1381 	iwe.u.qual.level = 256 - ap->rssi;
1382 	iwe.u.qual.qual = ap->sq;
1383 	iwe.u.qual.noise = 0;	/* invalid noise value */
1384 	current_ev =
1385 	    iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1386 				 IW_EV_QUAL_LEN);
1387 
1388 	/* Add encryption capability */
1389 	iwe.cmd = SIOCGIWENCODE;
1390 	if (capabilities & BSS_CAP_PRIVACY)
1391 		iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1392 	else
1393 		iwe.u.data.flags = IW_ENCODE_DISABLED;
1394 	iwe.u.data.length = 0;
1395 	current_ev =
1396 	    iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1397 				 ap->ssid.body);
1398 
1399 	/* Rate : stuffing multiple values in a single event require a bit
1400 	 * more of magic - Jean II
1401 	 */
1402 	current_val = current_ev + IW_EV_LCP_LEN;
1403 
1404 	iwe.cmd = SIOCGIWRATE;
1405 
1406 	/* These two flags are ignored... */
1407 	iwe.u.bitrate.fixed = 0;
1408 	iwe.u.bitrate.disabled = 0;
1409 
1410 	/* Max 16 values */
1411 	for (i = 0; i < 16; i++) {
1412 		/* NULL terminated */
1413 		if (i >= ap->rate_set.size)
1414 			break;
1415 		/* Bit rate given in 500 kb/s units (+ 0x80) */
1416 		iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1417 		/* Add new value to event */
1418 		current_val =
1419 		    iwe_stream_add_value(info, current_ev, current_val, end_buf,
1420 					 &iwe, IW_EV_PARAM_LEN);
1421 	}
1422 	/* Check if we added any event */
1423 	if ((current_val - current_ev) > IW_EV_LCP_LEN)
1424 		current_ev = current_val;
1425 
1426 #define GENERIC_INFO_ELEM_ID 0xdd
1427 #define RSN_INFO_ELEM_ID 0x30
1428 	if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1429 		pbuf = &buf0[0];
1430 		memset(&iwe, 0, sizeof(iwe));
1431 		iwe.cmd = IWEVCUSTOM;
1432 		memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1433 		iwe.u.data.length += sizeof(rsn_leader) - 1;
1434 		pbuf += sizeof(rsn_leader) - 1;
1435 
1436 		pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1437 		pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1438 		iwe.u.data.length += 4;
1439 
1440 		for (i = 0; i < ap->rsn_ie.size; i++)
1441 			pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1442 		iwe.u.data.length += (ap->rsn_ie.size) * 2;
1443 
1444 		DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1445 
1446 		current_ev =
1447 		    iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1448 					 &buf0[0]);
1449 	}
1450 	if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1451 		pbuf = &buf1[0];
1452 		memset(&iwe, 0, sizeof(iwe));
1453 		iwe.cmd = IWEVCUSTOM;
1454 		memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1455 		iwe.u.data.length += sizeof(wpa_leader) - 1;
1456 		pbuf += sizeof(wpa_leader) - 1;
1457 
1458 		pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1459 		pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1460 		iwe.u.data.length += 4;
1461 
1462 		for (i = 0; i < ap->wpa_ie.size; i++)
1463 			pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1464 		iwe.u.data.length += (ap->wpa_ie.size) * 2;
1465 
1466 		DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1467 		DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1468 
1469 		current_ev =
1470 		    iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1471 					 &buf1[0]);
1472 	}
1473 
1474 	/* The other data in the scan result are not really
1475 	 * interesting, so for now drop it - Jean II
1476 	 */
1477 	return current_ev;
1478 }
1479 
1480 static int ks_wlan_get_scan(struct net_device *dev,
1481 			    struct iw_request_info *info, struct iw_point *dwrq,
1482 			    char *extra)
1483 {
1484 	struct ks_wlan_private *priv = netdev_priv(dev);
1485 	int i;
1486 	char *current_ev = extra;
1487 
1488 	DPRINTK(2, "\n");
1489 
1490 	if (priv->sleep_mode == SLP_SLEEP)
1491 		return -EPERM;
1492 	/* for SLEEP MODE */
1493 	if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1494 		DPRINTK(2, "flag AP_SCAN\n");
1495 		return -EAGAIN;
1496 	}
1497 
1498 	if (priv->aplist.size == 0) {
1499 		/* Client error, no scan results...
1500 		 * The caller need to restart the scan.
1501 		 */
1502 		DPRINTK(2, "aplist 0\n");
1503 		return -ENODATA;
1504 	}
1505 
1506 	/* Read and parse all entries */
1507 	for (i = 0; i < priv->aplist.size; i++) {
1508 		if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1509 			dwrq->length = 0;
1510 			return -E2BIG;
1511 		}
1512 		/* Translate to WE format this entry */
1513 		current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1514 						    extra + dwrq->length,
1515 						    &priv->aplist.ap[i]);
1516 	}
1517 	/* Length of data */
1518 	dwrq->length = (current_ev - extra);
1519 	dwrq->flags = 0;
1520 
1521 	return 0;
1522 }
1523 
1524 /* called after a bunch of SET operations */
1525 static int ks_wlan_config_commit(struct net_device *dev,
1526 				 struct iw_request_info *info, void *zwrq,
1527 				 char *extra)
1528 {
1529 	struct ks_wlan_private *priv = netdev_priv(dev);
1530 
1531 	if (!priv->need_commit)
1532 		return 0;
1533 
1534 	ks_wlan_setup_parameter(priv, priv->need_commit);
1535 	priv->need_commit = 0;
1536 	return 0;
1537 }
1538 
1539 /* set association ie params */
1540 static int ks_wlan_set_genie(struct net_device *dev,
1541 			     struct iw_request_info *info,
1542 			     struct iw_point *dwrq, char *extra)
1543 {
1544 	struct ks_wlan_private *priv = netdev_priv(dev);
1545 
1546 	DPRINTK(2, "\n");
1547 
1548 	if (priv->sleep_mode == SLP_SLEEP)
1549 		return -EPERM;
1550 	/* for SLEEP MODE */
1551 	return 0;
1552 //      return -EOPNOTSUPP;
1553 }
1554 
1555 static int ks_wlan_set_auth_mode(struct net_device *dev,
1556 				 struct iw_request_info *info,
1557 				 struct iw_param *vwrq, char *extra)
1558 {
1559 	struct ks_wlan_private *priv = netdev_priv(dev);
1560 	int index = (vwrq->flags & IW_AUTH_INDEX);
1561 	int value = vwrq->value;
1562 
1563 	DPRINTK(2, "index=%d:value=%08X\n", index, value);
1564 
1565 	if (priv->sleep_mode == SLP_SLEEP)
1566 		return -EPERM;
1567 	/* for SLEEP MODE */
1568 	switch (index) {
1569 	case IW_AUTH_WPA_VERSION:	/* 0 */
1570 		switch (value) {
1571 		case IW_AUTH_WPA_VERSION_DISABLED:
1572 			priv->wpa.version = value;
1573 			if (priv->wpa.rsn_enabled)
1574 				priv->wpa.rsn_enabled = 0;
1575 			priv->need_commit |= SME_RSN;
1576 			break;
1577 		case IW_AUTH_WPA_VERSION_WPA:
1578 		case IW_AUTH_WPA_VERSION_WPA2:
1579 			priv->wpa.version = value;
1580 			if (!(priv->wpa.rsn_enabled))
1581 				priv->wpa.rsn_enabled = 1;
1582 			priv->need_commit |= SME_RSN;
1583 			break;
1584 		default:
1585 			return -EOPNOTSUPP;
1586 		}
1587 		break;
1588 	case IW_AUTH_CIPHER_PAIRWISE:	/* 1 */
1589 		switch (value) {
1590 		case IW_AUTH_CIPHER_NONE:
1591 			if (priv->reg.privacy_invoked) {
1592 				priv->reg.privacy_invoked = 0x00;
1593 				priv->need_commit |= SME_WEP_FLAG;
1594 			}
1595 			break;
1596 		case IW_AUTH_CIPHER_WEP40:
1597 		case IW_AUTH_CIPHER_TKIP:
1598 		case IW_AUTH_CIPHER_CCMP:
1599 		case IW_AUTH_CIPHER_WEP104:
1600 			if (!priv->reg.privacy_invoked) {
1601 				priv->reg.privacy_invoked = 0x01;
1602 				priv->need_commit |= SME_WEP_FLAG;
1603 			}
1604 			priv->wpa.pairwise_suite = value;
1605 			priv->need_commit |= SME_RSN_UNICAST;
1606 			break;
1607 		default:
1608 			return -EOPNOTSUPP;
1609 		}
1610 		break;
1611 	case IW_AUTH_CIPHER_GROUP:	/* 2 */
1612 		switch (value) {
1613 		case IW_AUTH_CIPHER_NONE:
1614 			if (priv->reg.privacy_invoked) {
1615 				priv->reg.privacy_invoked = 0x00;
1616 				priv->need_commit |= SME_WEP_FLAG;
1617 			}
1618 			break;
1619 		case IW_AUTH_CIPHER_WEP40:
1620 		case IW_AUTH_CIPHER_TKIP:
1621 		case IW_AUTH_CIPHER_CCMP:
1622 		case IW_AUTH_CIPHER_WEP104:
1623 			if (!priv->reg.privacy_invoked) {
1624 				priv->reg.privacy_invoked = 0x01;
1625 				priv->need_commit |= SME_WEP_FLAG;
1626 			}
1627 			priv->wpa.group_suite = value;
1628 			priv->need_commit |= SME_RSN_MULTICAST;
1629 			break;
1630 		default:
1631 			return -EOPNOTSUPP;
1632 		}
1633 		break;
1634 	case IW_AUTH_KEY_MGMT:	/* 3 */
1635 		switch (value) {
1636 		case IW_AUTH_KEY_MGMT_802_1X:
1637 		case IW_AUTH_KEY_MGMT_PSK:
1638 		case 0:	/* NONE or 802_1X_NO_WPA */
1639 		case 4:	/* WPA_NONE */
1640 			priv->wpa.key_mgmt_suite = value;
1641 			priv->need_commit |= SME_RSN_AUTH;
1642 			break;
1643 		default:
1644 			return -EOPNOTSUPP;
1645 		}
1646 		break;
1647 	case IW_AUTH_80211_AUTH_ALG:	/* 6 */
1648 		switch (value) {
1649 		case IW_AUTH_ALG_OPEN_SYSTEM:
1650 			priv->wpa.auth_alg = value;
1651 			priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1652 			break;
1653 		case IW_AUTH_ALG_SHARED_KEY:
1654 			priv->wpa.auth_alg = value;
1655 			priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1656 			break;
1657 		case IW_AUTH_ALG_LEAP:
1658 		default:
1659 			return -EOPNOTSUPP;
1660 		}
1661 		priv->need_commit |= SME_MODE_SET;
1662 		break;
1663 	case IW_AUTH_WPA_ENABLED:	/* 7 */
1664 		priv->wpa.wpa_enabled = value;
1665 		break;
1666 	case IW_AUTH_PRIVACY_INVOKED:	/* 10 */
1667 		if ((value && !priv->reg.privacy_invoked) ||
1668 		    (!value && priv->reg.privacy_invoked)) {
1669 			priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1670 			priv->need_commit |= SME_WEP_FLAG;
1671 		}
1672 		break;
1673 	case IW_AUTH_RX_UNENCRYPTED_EAPOL:	/* 4 */
1674 	case IW_AUTH_TKIP_COUNTERMEASURES:	/* 5 */
1675 	case IW_AUTH_DROP_UNENCRYPTED:	/* 8 */
1676 	case IW_AUTH_ROAMING_CONTROL:	/* 9 */
1677 	default:
1678 		break;
1679 	}
1680 
1681 	/* return -EINPROGRESS; */
1682 	if (priv->need_commit) {
1683 		ks_wlan_setup_parameter(priv, priv->need_commit);
1684 		priv->need_commit = 0;
1685 	}
1686 	return 0;
1687 }
1688 
1689 static int ks_wlan_get_auth_mode(struct net_device *dev,
1690 				 struct iw_request_info *info,
1691 				 struct iw_param *vwrq, char *extra)
1692 {
1693 	struct ks_wlan_private *priv = netdev_priv(dev);
1694 	int index = (vwrq->flags & IW_AUTH_INDEX);
1695 
1696 	DPRINTK(2, "index=%d\n", index);
1697 
1698 	if (priv->sleep_mode == SLP_SLEEP)
1699 		return -EPERM;
1700 
1701 	/* for SLEEP MODE */
1702 	/*  WPA (not used ?? wpa_supplicant) */
1703 	switch (index) {
1704 	case IW_AUTH_WPA_VERSION:
1705 		vwrq->value = priv->wpa.version;
1706 		break;
1707 	case IW_AUTH_CIPHER_PAIRWISE:
1708 		vwrq->value = priv->wpa.pairwise_suite;
1709 		break;
1710 	case IW_AUTH_CIPHER_GROUP:
1711 		vwrq->value = priv->wpa.group_suite;
1712 		break;
1713 	case IW_AUTH_KEY_MGMT:
1714 		vwrq->value = priv->wpa.key_mgmt_suite;
1715 		break;
1716 	case IW_AUTH_80211_AUTH_ALG:
1717 		vwrq->value = priv->wpa.auth_alg;
1718 		break;
1719 	case IW_AUTH_WPA_ENABLED:
1720 		vwrq->value = priv->wpa.rsn_enabled;
1721 		break;
1722 	case IW_AUTH_RX_UNENCRYPTED_EAPOL:	/* OK??? */
1723 	case IW_AUTH_TKIP_COUNTERMEASURES:
1724 	case IW_AUTH_DROP_UNENCRYPTED:
1725 	default:
1726 		/* return -EOPNOTSUPP; */
1727 		break;
1728 	}
1729 	return 0;
1730 }
1731 
1732 /* set encoding token & mode (WPA)*/
1733 static int ks_wlan_set_encode_ext(struct net_device *dev,
1734 				  struct iw_request_info *info,
1735 				  struct iw_point *dwrq, char *extra)
1736 {
1737 	struct ks_wlan_private *priv = netdev_priv(dev);
1738 	struct iw_encode_ext *enc;
1739 	int index = dwrq->flags & IW_ENCODE_INDEX;
1740 	unsigned int commit = 0;
1741 	struct wpa_key_t *key;
1742 
1743 	enc = (struct iw_encode_ext *)extra;
1744 	if (!enc)
1745 		return -EINVAL;
1746 
1747 	DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1748 		enc->ext_flags);
1749 
1750 	if (priv->sleep_mode == SLP_SLEEP)
1751 		return -EPERM;
1752 
1753 	/* for SLEEP MODE */
1754 	if (index < 1 || index > 4)
1755 		return -EINVAL;
1756 	index--;
1757 	key = &priv->wpa.key[index];
1758 
1759 	if (dwrq->flags & IW_ENCODE_DISABLED)
1760 		key->key_len = 0;
1761 
1762 	key->ext_flags = enc->ext_flags;
1763 	if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1764 		priv->wpa.txkey = index;
1765 		commit |= SME_WEP_INDEX;
1766 	} else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1767 		memcpy(&key->rx_seq[0], &enc->rx_seq[0], IW_ENCODE_SEQ_MAX_SIZE);
1768 	}
1769 
1770 	memcpy(&key->addr.sa_data[0], &enc->addr.sa_data[0], ETH_ALEN);
1771 
1772 	switch (enc->alg) {
1773 	case IW_ENCODE_ALG_NONE:
1774 		if (priv->reg.privacy_invoked) {
1775 			priv->reg.privacy_invoked = 0x00;
1776 			commit |= SME_WEP_FLAG;
1777 		}
1778 		key->key_len = 0;
1779 
1780 		break;
1781 	case IW_ENCODE_ALG_WEP:
1782 	case IW_ENCODE_ALG_CCMP:
1783 		if (!priv->reg.privacy_invoked) {
1784 			priv->reg.privacy_invoked = 0x01;
1785 			commit |= SME_WEP_FLAG;
1786 		}
1787 		if (enc->key_len) {
1788 			memcpy(&key->key_val[0], &enc->key[0], enc->key_len);
1789 			key->key_len = enc->key_len;
1790 			commit |= (SME_WEP_VAL1 << index);
1791 		}
1792 		break;
1793 	case IW_ENCODE_ALG_TKIP:
1794 		if (!priv->reg.privacy_invoked) {
1795 			priv->reg.privacy_invoked = 0x01;
1796 			commit |= SME_WEP_FLAG;
1797 		}
1798 		if (enc->key_len == 32) {
1799 			memcpy(&key->key_val[0], &enc->key[0], enc->key_len - 16);
1800 			key->key_len = enc->key_len - 16;
1801 			if (priv->wpa.key_mgmt_suite == 4) {	/* WPA_NONE */
1802 				memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1803 				memcpy(&key->rx_mic_key[0], &enc->key[16], 8);
1804 			} else {
1805 				memcpy(&key->tx_mic_key[0], &enc->key[16], 8);
1806 				memcpy(&key->rx_mic_key[0], &enc->key[24], 8);
1807 			}
1808 			commit |= (SME_WEP_VAL1 << index);
1809 		}
1810 		break;
1811 	default:
1812 		return -EINVAL;
1813 	}
1814 	key->alg = enc->alg;
1815 
1816 	if (commit) {
1817 		if (commit & SME_WEP_INDEX)
1818 			hostif_sme_enqueue(priv, SME_SET_TXKEY);
1819 		if (commit & SME_WEP_VAL_MASK)
1820 			hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1821 		if (commit & SME_WEP_FLAG)
1822 			hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1823 	}
1824 
1825 	return 0;
1826 }
1827 
1828 /* get encoding token & mode (WPA)*/
1829 static int ks_wlan_get_encode_ext(struct net_device *dev,
1830 				  struct iw_request_info *info,
1831 				  struct iw_point *dwrq, char *extra)
1832 {
1833 	struct ks_wlan_private *priv = netdev_priv(dev);
1834 
1835 	if (priv->sleep_mode == SLP_SLEEP)
1836 		return -EPERM;
1837 
1838 	/* for SLEEP MODE */
1839 	/* WPA (not used ?? wpa_supplicant)
1840 	 * struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
1841 	 * struct iw_encode_ext *enc;
1842 	 * enc = (struct iw_encode_ext *)extra;
1843 	 * int index = dwrq->flags & IW_ENCODE_INDEX;
1844 	 * WPA (not used ?? wpa_supplicant)
1845 	 */
1846 	return 0;
1847 }
1848 
1849 static int ks_wlan_set_pmksa(struct net_device *dev,
1850 			     struct iw_request_info *info,
1851 			     struct iw_point *dwrq, char *extra)
1852 {
1853 	struct ks_wlan_private *priv = netdev_priv(dev);
1854 	struct iw_pmksa *pmksa;
1855 	int i;
1856 	struct pmk_t *pmk;
1857 	struct list_head *ptr;
1858 
1859 	DPRINTK(2, "\n");
1860 
1861 	if (priv->sleep_mode == SLP_SLEEP)
1862 		return -EPERM;
1863 
1864 	/* for SLEEP MODE */
1865 	if (!extra)
1866 		return -EINVAL;
1867 
1868 	pmksa = (struct iw_pmksa *)extra;
1869 	DPRINTK(2, "cmd=%d\n", pmksa->cmd);
1870 
1871 	switch (pmksa->cmd) {
1872 	case IW_PMKSA_ADD:
1873 		if (list_empty(&priv->pmklist.head)) {	/* new list */
1874 			for (i = 0; i < PMK_LIST_MAX; i++) {
1875 				pmk = &priv->pmklist.pmk[i];
1876 				if (memcmp("\x00\x00\x00\x00\x00\x00",
1877 					   pmk->bssid, ETH_ALEN) == 0)
1878 					break; /* loop */
1879 			}
1880 			memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1881 			memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1882 			list_add(&pmk->list, &priv->pmklist.head);
1883 			priv->pmklist.size++;
1884 			break;	/* case */
1885 		}
1886 		/* search cache data */
1887 		list_for_each(ptr, &priv->pmklist.head) {
1888 			pmk = list_entry(ptr, struct pmk_t, list);
1889 			if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1890 				memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1891 				list_move(&pmk->list, &priv->pmklist.head);
1892 				break; /* list_for_each */
1893 			}
1894 		}
1895 		if (ptr != &priv->pmklist.head)	/* not find address. */
1896 			break;	/* case */
1897 
1898 		if (priv->pmklist.size < PMK_LIST_MAX) {	/* new cache data */
1899 			for (i = 0; i < PMK_LIST_MAX; i++) {
1900 				pmk = &priv->pmklist.pmk[i];
1901 				if (memcmp("\x00\x00\x00\x00\x00\x00",
1902 					   pmk->bssid, ETH_ALEN) == 0)
1903 					break; /* loop */
1904 			}
1905 			memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1906 			memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1907 			list_add(&pmk->list, &priv->pmklist.head);
1908 			priv->pmklist.size++;
1909 		} else {	/* overwrite old cache data */
1910 			pmk = list_entry(priv->pmklist.head.prev, struct pmk_t,
1911 					 list);
1912 			memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
1913 			memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
1914 			list_move(&pmk->list, &priv->pmklist.head);
1915 		}
1916 		break;
1917 	case IW_PMKSA_REMOVE:
1918 		if (list_empty(&priv->pmklist.head)) {	/* list empty */
1919 			return -EINVAL;
1920 		}
1921 		/* search cache data */
1922 		list_for_each(ptr, &priv->pmklist.head) {
1923 			pmk = list_entry(ptr, struct pmk_t, list);
1924 			if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) {
1925 				eth_zero_addr(pmk->bssid);
1926 				memset(pmk->pmkid, 0, IW_PMKID_LEN);
1927 				list_del_init(&pmk->list);
1928 				break;
1929 			}
1930 		}
1931 		if (ptr == &priv->pmklist.head) {	/* not find address. */
1932 			return 0;
1933 		}
1934 
1935 		break;
1936 	case IW_PMKSA_FLUSH:
1937 		memset(&priv->pmklist, 0, sizeof(priv->pmklist));
1938 		INIT_LIST_HEAD(&priv->pmklist.head);
1939 		for (i = 0; i < PMK_LIST_MAX; i++)
1940 			INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
1941 		break;
1942 	default:
1943 		return -EINVAL;
1944 	}
1945 
1946 	hostif_sme_enqueue(priv, SME_SET_PMKSA);
1947 	return 0;
1948 }
1949 
1950 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
1951 {
1952 	struct ks_wlan_private *priv = netdev_priv(dev);
1953 	struct iw_statistics *wstats = &priv->wstats;
1954 
1955 	if (!atomic_read(&update_phyinfo)) {
1956 		if (priv->dev_state < DEVICE_STATE_READY)
1957 			return NULL;	/* not finished initialize */
1958 		else
1959 			return wstats;
1960 	}
1961 
1962 	/* Packets discarded in the wireless adapter due to wireless
1963 	 * specific problems
1964 	 */
1965 	wstats->discard.nwid = 0;	/* Rx invalid nwid      */
1966 	wstats->discard.code = 0;	/* Rx invalid crypt     */
1967 	wstats->discard.fragment = 0;	/* Rx invalid frag      */
1968 	wstats->discard.retries = 0;	/* Tx excessive retries */
1969 	wstats->discard.misc = 0;	/* Invalid misc         */
1970 	wstats->miss.beacon = 0;	/* Missed beacon        */
1971 
1972 	return wstats;
1973 }
1974 
1975 static int ks_wlan_set_stop_request(struct net_device *dev,
1976 				    struct iw_request_info *info, __u32 *uwrq,
1977 				    char *extra)
1978 {
1979 	struct ks_wlan_private *priv = netdev_priv(dev);
1980 
1981 	DPRINTK(2, "\n");
1982 
1983 	if (priv->sleep_mode == SLP_SLEEP)
1984 		return -EPERM;
1985 
1986 	/* for SLEEP MODE */
1987 	if (!(*uwrq))
1988 		return -EINVAL;
1989 
1990 	hostif_sme_enqueue(priv, SME_STOP_REQUEST);
1991 	return 0;
1992 }
1993 
1994 #include <linux/ieee80211.h>
1995 static int ks_wlan_set_mlme(struct net_device *dev,
1996 			    struct iw_request_info *info, struct iw_point *dwrq,
1997 			    char *extra)
1998 {
1999 	struct ks_wlan_private *priv = netdev_priv(dev);
2000 	struct iw_mlme *mlme = (struct iw_mlme *)extra;
2001 	__u32 mode;
2002 
2003 	DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2004 
2005 	if (priv->sleep_mode == SLP_SLEEP)
2006 		return -EPERM;
2007 
2008 	/* for SLEEP MODE */
2009 	switch (mlme->cmd) {
2010 	case IW_MLME_DEAUTH:
2011 		if (mlme->reason_code == WLAN_REASON_MIC_FAILURE)
2012 			return 0;
2013 	case IW_MLME_DISASSOC:
2014 		mode = 1;
2015 		return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2016 	default:
2017 		return -EOPNOTSUPP;	/* Not Support */
2018 	}
2019 }
2020 
2021 static int ks_wlan_get_firmware_version(struct net_device *dev,
2022 					struct iw_request_info *info,
2023 					struct iw_point *dwrq, char *extra)
2024 {
2025 	struct ks_wlan_private *priv = netdev_priv(dev);
2026 
2027 	strcpy(extra, priv->firmware_version);
2028 	dwrq->length = priv->version_size + 1;
2029 	return 0;
2030 }
2031 
2032 static int ks_wlan_set_preamble(struct net_device *dev,
2033 				struct iw_request_info *info, __u32 *uwrq,
2034 				char *extra)
2035 {
2036 	struct ks_wlan_private *priv = netdev_priv(dev);
2037 
2038 	if (priv->sleep_mode == SLP_SLEEP)
2039 		return -EPERM;
2040 
2041 	/* for SLEEP MODE */
2042 	if (*uwrq == LONG_PREAMBLE) {	/* 0 */
2043 		priv->reg.preamble = LONG_PREAMBLE;
2044 	} else if (*uwrq == SHORT_PREAMBLE) {	/* 1 */
2045 		priv->reg.preamble = SHORT_PREAMBLE;
2046 	} else {
2047 		return -EINVAL;
2048 	}
2049 
2050 	priv->need_commit |= SME_MODE_SET;
2051 	return -EINPROGRESS;	/* Call commit handler */
2052 }
2053 
2054 static int ks_wlan_get_preamble(struct net_device *dev,
2055 				struct iw_request_info *info, __u32 *uwrq,
2056 				char *extra)
2057 {
2058 	struct ks_wlan_private *priv = netdev_priv(dev);
2059 
2060 	if (priv->sleep_mode == SLP_SLEEP)
2061 		return -EPERM;
2062 
2063 	/* for SLEEP MODE */
2064 	*uwrq = priv->reg.preamble;
2065 	return 0;
2066 }
2067 
2068 static int ks_wlan_set_power_mgmt(struct net_device *dev,
2069 				  struct iw_request_info *info, __u32 *uwrq,
2070 				  char *extra)
2071 {
2072 	struct ks_wlan_private *priv = netdev_priv(dev);
2073 
2074 	if (priv->sleep_mode == SLP_SLEEP)
2075 		return -EPERM;
2076 
2077 	/* for SLEEP MODE */
2078 	if (*uwrq == POWER_MGMT_ACTIVE) {	/* 0 */
2079 		priv->reg.power_mgmt = POWER_MGMT_ACTIVE;
2080 	} else if (*uwrq == POWER_MGMT_SAVE1) {	/* 1 */
2081 		if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2082 			priv->reg.power_mgmt = POWER_MGMT_SAVE1;
2083 		else
2084 			return -EINVAL;
2085 	} else if (*uwrq == POWER_MGMT_SAVE2) {	/* 2 */
2086 		if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2087 			priv->reg.power_mgmt = POWER_MGMT_SAVE2;
2088 		else
2089 			return -EINVAL;
2090 	} else {
2091 		return -EINVAL;
2092 	}
2093 
2094 	hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2095 
2096 	return 0;
2097 }
2098 
2099 static int ks_wlan_get_power_mgmt(struct net_device *dev,
2100 				  struct iw_request_info *info, __u32 *uwrq,
2101 				  char *extra)
2102 {
2103 	struct ks_wlan_private *priv = netdev_priv(dev);
2104 
2105 	if (priv->sleep_mode == SLP_SLEEP)
2106 		return -EPERM;
2107 
2108 	/* for SLEEP MODE */
2109 	*uwrq = priv->reg.power_mgmt;
2110 	return 0;
2111 }
2112 
2113 static int ks_wlan_set_scan_type(struct net_device *dev,
2114 				 struct iw_request_info *info, __u32 *uwrq,
2115 				 char *extra)
2116 {
2117 	struct ks_wlan_private *priv = netdev_priv(dev);
2118 
2119 	if (priv->sleep_mode == SLP_SLEEP)
2120 		return -EPERM;
2121 	/* for SLEEP MODE */
2122 	if (*uwrq == ACTIVE_SCAN) {	/* 0 */
2123 		priv->reg.scan_type = ACTIVE_SCAN;
2124 	} else if (*uwrq == PASSIVE_SCAN) {	/* 1 */
2125 		priv->reg.scan_type = PASSIVE_SCAN;
2126 	} else {
2127 		return -EINVAL;
2128 	}
2129 
2130 	return 0;
2131 }
2132 
2133 static int ks_wlan_get_scan_type(struct net_device *dev,
2134 				 struct iw_request_info *info, __u32 *uwrq,
2135 				 char *extra)
2136 {
2137 	struct ks_wlan_private *priv = netdev_priv(dev);
2138 
2139 	if (priv->sleep_mode == SLP_SLEEP)
2140 		return -EPERM;
2141 	/* for SLEEP MODE */
2142 	*uwrq = priv->reg.scan_type;
2143 	return 0;
2144 }
2145 
2146 static int ks_wlan_set_beacon_lost(struct net_device *dev,
2147 				   struct iw_request_info *info, __u32 *uwrq,
2148 				   char *extra)
2149 {
2150 	struct ks_wlan_private *priv = netdev_priv(dev);
2151 
2152 	if (priv->sleep_mode == SLP_SLEEP)
2153 		return -EPERM;
2154 	/* for SLEEP MODE */
2155 	if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX)
2156 		priv->reg.beacon_lost_count = *uwrq;
2157 	else
2158 		return -EINVAL;
2159 
2160 	if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2161 		priv->need_commit |= SME_MODE_SET;
2162 		return -EINPROGRESS;	/* Call commit handler */
2163 	} else {
2164 		return 0;
2165 	}
2166 }
2167 
2168 static int ks_wlan_get_beacon_lost(struct net_device *dev,
2169 				   struct iw_request_info *info, __u32 *uwrq,
2170 				   char *extra)
2171 {
2172 	struct ks_wlan_private *priv = netdev_priv(dev);
2173 
2174 	if (priv->sleep_mode == SLP_SLEEP)
2175 		return -EPERM;
2176 	/* for SLEEP MODE */
2177 	*uwrq = priv->reg.beacon_lost_count;
2178 	return 0;
2179 }
2180 
2181 static int ks_wlan_set_phy_type(struct net_device *dev,
2182 				struct iw_request_info *info, __u32 *uwrq,
2183 				char *extra)
2184 {
2185 	struct ks_wlan_private *priv = netdev_priv(dev);
2186 
2187 	if (priv->sleep_mode == SLP_SLEEP)
2188 		return -EPERM;
2189 	/* for SLEEP MODE */
2190 	if (*uwrq == D_11B_ONLY_MODE) {	/* 0 */
2191 		priv->reg.phy_type = D_11B_ONLY_MODE;
2192 	} else if (*uwrq == D_11G_ONLY_MODE) {	/* 1 */
2193 		priv->reg.phy_type = D_11G_ONLY_MODE;
2194 	} else if (*uwrq == D_11BG_COMPATIBLE_MODE) {	/* 2 */
2195 		priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2196 	} else {
2197 		return -EINVAL;
2198 	}
2199 
2200 	priv->need_commit |= SME_MODE_SET;
2201 	return -EINPROGRESS;	/* Call commit handler */
2202 }
2203 
2204 static int ks_wlan_get_phy_type(struct net_device *dev,
2205 				struct iw_request_info *info, __u32 *uwrq,
2206 				char *extra)
2207 {
2208 	struct ks_wlan_private *priv = netdev_priv(dev);
2209 
2210 	if (priv->sleep_mode == SLP_SLEEP)
2211 		return -EPERM;
2212 	/* for SLEEP MODE */
2213 	*uwrq = priv->reg.phy_type;
2214 	return 0;
2215 }
2216 
2217 static int ks_wlan_set_cts_mode(struct net_device *dev,
2218 				struct iw_request_info *info, __u32 *uwrq,
2219 				char *extra)
2220 {
2221 	struct ks_wlan_private *priv = netdev_priv(dev);
2222 
2223 	if (priv->sleep_mode == SLP_SLEEP)
2224 		return -EPERM;
2225 	/* for SLEEP MODE */
2226 	if (*uwrq == CTS_MODE_FALSE) {	/* 0 */
2227 		priv->reg.cts_mode = CTS_MODE_FALSE;
2228 	} else if (*uwrq == CTS_MODE_TRUE) {	/* 1 */
2229 		if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2230 		    priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {
2231 			priv->reg.cts_mode = CTS_MODE_TRUE;
2232 		} else {
2233 			priv->reg.cts_mode = CTS_MODE_FALSE;
2234 		}
2235 	} else {
2236 		return -EINVAL;
2237 	}
2238 
2239 	priv->need_commit |= SME_MODE_SET;
2240 	return -EINPROGRESS;	/* Call commit handler */
2241 }
2242 
2243 static int ks_wlan_get_cts_mode(struct net_device *dev,
2244 				struct iw_request_info *info, __u32 *uwrq,
2245 				char *extra)
2246 {
2247 	struct ks_wlan_private *priv = netdev_priv(dev);
2248 
2249 	if (priv->sleep_mode == SLP_SLEEP)
2250 		return -EPERM;
2251 	/* for SLEEP MODE */
2252 	*uwrq = priv->reg.cts_mode;
2253 	return 0;
2254 }
2255 
2256 static int ks_wlan_set_sleep_mode(struct net_device *dev,
2257 				  struct iw_request_info *info,
2258 				  __u32 *uwrq, char *extra)
2259 {
2260 	struct ks_wlan_private *priv = netdev_priv(dev);
2261 
2262 	DPRINTK(2, "\n");
2263 
2264 	if (*uwrq == SLP_SLEEP) {
2265 		priv->sleep_mode = *uwrq;
2266 		netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2267 
2268 		hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2269 		hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2270 
2271 	} else if (*uwrq == SLP_ACTIVE) {
2272 		priv->sleep_mode = *uwrq;
2273 		netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode);
2274 		hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2275 	} else {
2276 		netdev_err(dev, "SET_SLEEP_MODE %d error\n", *uwrq);
2277 		return -EINVAL;
2278 	}
2279 
2280 	return 0;
2281 }
2282 
2283 static int ks_wlan_get_sleep_mode(struct net_device *dev,
2284 				  struct iw_request_info *info,
2285 				  __u32 *uwrq, char *extra)
2286 {
2287 	struct ks_wlan_private *priv = netdev_priv(dev);
2288 
2289 	DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2290 	*uwrq = priv->sleep_mode;
2291 
2292 	return 0;
2293 }
2294 
2295 #ifdef WPS
2296 
2297 static int ks_wlan_set_wps_enable(struct net_device *dev,
2298 				  struct iw_request_info *info, __u32 *uwrq,
2299 				  char *extra)
2300 {
2301 	struct ks_wlan_private *priv = netdev_priv(dev);
2302 
2303 	DPRINTK(2, "\n");
2304 
2305 	if (priv->sleep_mode == SLP_SLEEP)
2306 		return -EPERM;
2307 	/* for SLEEP MODE */
2308 	if (*uwrq == 0 || *uwrq == 1)
2309 		priv->wps.wps_enabled = *uwrq;
2310 	else
2311 		return -EINVAL;
2312 
2313 	hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2314 
2315 	return 0;
2316 }
2317 
2318 static int ks_wlan_get_wps_enable(struct net_device *dev,
2319 				  struct iw_request_info *info, __u32 *uwrq,
2320 				  char *extra)
2321 {
2322 	struct ks_wlan_private *priv = netdev_priv(dev);
2323 
2324 	DPRINTK(2, "\n");
2325 
2326 	if (priv->sleep_mode == SLP_SLEEP)
2327 		return -EPERM;
2328 	/* for SLEEP MODE */
2329 	*uwrq = priv->wps.wps_enabled;
2330 	netdev_info(dev, "return=%d\n", *uwrq);
2331 
2332 	return 0;
2333 }
2334 
2335 static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2336 				     struct iw_request_info *info,
2337 				     struct iw_point *dwrq, char *extra)
2338 {
2339 	u8 *p = extra;
2340 	unsigned char len;
2341 	struct ks_wlan_private *priv = netdev_priv(dev);
2342 
2343 	DPRINTK(2, "\n");
2344 
2345 	if (priv->sleep_mode == SLP_SLEEP)
2346 		return -EPERM;
2347 	/* for SLEEP MODE */
2348 	DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2349 
2350 	/* length check */
2351 	if (p[1] + 2 != dwrq->length || dwrq->length > 256)
2352 		return -EINVAL;
2353 
2354 	priv->wps.ielen = p[1] + 2 + 1;	/* IE header + IE + sizeof(len) */
2355 	len = p[1] + 2;	/* IE header + IE */
2356 
2357 	memcpy(priv->wps.ie, &len, sizeof(len));
2358 	p = memcpy(priv->wps.ie + 1, p, len);
2359 
2360 	DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2361 		priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2362 		p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2363 		p[priv->wps.ielen - 1]);
2364 
2365 	hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2366 
2367 	return 0;
2368 }
2369 #endif /* WPS */
2370 
2371 static int ks_wlan_set_tx_gain(struct net_device *dev,
2372 			       struct iw_request_info *info, __u32 *uwrq,
2373 			       char *extra)
2374 {
2375 	struct ks_wlan_private *priv = netdev_priv(dev);
2376 
2377 	if (priv->sleep_mode == SLP_SLEEP)
2378 		return -EPERM;
2379 	/* for SLEEP MODE */
2380 	if (*uwrq >= 0 && *uwrq <= 0xFF)	/* 0-255 */
2381 		priv->gain.tx_gain = (uint8_t)*uwrq;
2382 	else
2383 		return -EINVAL;
2384 
2385 	if (priv->gain.tx_gain < 0xFF)
2386 		priv->gain.tx_mode = 1;
2387 	else
2388 		priv->gain.tx_mode = 0;
2389 
2390 	hostif_sme_enqueue(priv, SME_SET_GAIN);
2391 	return 0;
2392 }
2393 
2394 static int ks_wlan_get_tx_gain(struct net_device *dev,
2395 			       struct iw_request_info *info, __u32 *uwrq,
2396 			       char *extra)
2397 {
2398 	struct ks_wlan_private *priv = netdev_priv(dev);
2399 
2400 	if (priv->sleep_mode == SLP_SLEEP)
2401 		return -EPERM;
2402 	/* for SLEEP MODE */
2403 	*uwrq = priv->gain.tx_gain;
2404 	hostif_sme_enqueue(priv, SME_GET_GAIN);
2405 	return 0;
2406 }
2407 
2408 static int ks_wlan_set_rx_gain(struct net_device *dev,
2409 			       struct iw_request_info *info, __u32 *uwrq,
2410 			       char *extra)
2411 {
2412 	struct ks_wlan_private *priv = netdev_priv(dev);
2413 
2414 	if (priv->sleep_mode == SLP_SLEEP)
2415 		return -EPERM;
2416 	/* for SLEEP MODE */
2417 	if (*uwrq >= 0 && *uwrq <= 0xFF)	/* 0-255 */
2418 		priv->gain.rx_gain = (uint8_t)*uwrq;
2419 	else
2420 		return -EINVAL;
2421 
2422 	if (priv->gain.rx_gain < 0xFF)
2423 		priv->gain.rx_mode = 1;
2424 	else
2425 		priv->gain.rx_mode = 0;
2426 
2427 	hostif_sme_enqueue(priv, SME_SET_GAIN);
2428 	return 0;
2429 }
2430 
2431 static int ks_wlan_get_rx_gain(struct net_device *dev,
2432 			       struct iw_request_info *info, __u32 *uwrq,
2433 			       char *extra)
2434 {
2435 	struct ks_wlan_private *priv = netdev_priv(dev);
2436 
2437 	if (priv->sleep_mode == SLP_SLEEP)
2438 		return -EPERM;
2439 	/* for SLEEP MODE */
2440 	*uwrq = priv->gain.rx_gain;
2441 	hostif_sme_enqueue(priv, SME_GET_GAIN);
2442 	return 0;
2443 }
2444 
2445 static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2446 				    struct iw_request_info *info, __u32 *uwrq,
2447 				    char *extra)
2448 {
2449 	struct ks_wlan_private *priv = netdev_priv(dev);
2450 
2451 	*uwrq = priv->eeprom_checksum;
2452 	return 0;
2453 }
2454 
2455 static void print_hif_event(struct net_device *dev, int event)
2456 {
2457 	switch (event) {
2458 	case HIF_DATA_REQ:
2459 		netdev_info(dev, "HIF_DATA_REQ\n");
2460 		break;
2461 	case HIF_DATA_IND:
2462 		netdev_info(dev, "HIF_DATA_IND\n");
2463 		break;
2464 	case HIF_MIB_GET_REQ:
2465 		netdev_info(dev, "HIF_MIB_GET_REQ\n");
2466 		break;
2467 	case HIF_MIB_GET_CONF:
2468 		netdev_info(dev, "HIF_MIB_GET_CONF\n");
2469 		break;
2470 	case HIF_MIB_SET_REQ:
2471 		netdev_info(dev, "HIF_MIB_SET_REQ\n");
2472 		break;
2473 	case HIF_MIB_SET_CONF:
2474 		netdev_info(dev, "HIF_MIB_SET_CONF\n");
2475 		break;
2476 	case HIF_POWER_MGMT_REQ:
2477 		netdev_info(dev, "HIF_POWER_MGMT_REQ\n");
2478 		break;
2479 	case HIF_POWER_MGMT_CONF:
2480 		netdev_info(dev, "HIF_POWER_MGMT_CONF\n");
2481 		break;
2482 	case HIF_START_REQ:
2483 		netdev_info(dev, "HIF_START_REQ\n");
2484 		break;
2485 	case HIF_START_CONF:
2486 		netdev_info(dev, "HIF_START_CONF\n");
2487 		break;
2488 	case HIF_CONNECT_IND:
2489 		netdev_info(dev, "HIF_CONNECT_IND\n");
2490 		break;
2491 	case HIF_STOP_REQ:
2492 		netdev_info(dev, "HIF_STOP_REQ\n");
2493 		break;
2494 	case HIF_STOP_CONF:
2495 		netdev_info(dev, "HIF_STOP_CONF\n");
2496 		break;
2497 	case HIF_PS_ADH_SET_REQ:
2498 		netdev_info(dev, "HIF_PS_ADH_SET_REQ\n");
2499 		break;
2500 	case HIF_PS_ADH_SET_CONF:
2501 		netdev_info(dev, "HIF_PS_ADH_SET_CONF\n");
2502 		break;
2503 	case HIF_INFRA_SET_REQ:
2504 		netdev_info(dev, "HIF_INFRA_SET_REQ\n");
2505 		break;
2506 	case HIF_INFRA_SET_CONF:
2507 		netdev_info(dev, "HIF_INFRA_SET_CONF\n");
2508 		break;
2509 	case HIF_ADH_SET_REQ:
2510 		netdev_info(dev, "HIF_ADH_SET_REQ\n");
2511 		break;
2512 	case HIF_ADH_SET_CONF:
2513 		netdev_info(dev, "HIF_ADH_SET_CONF\n");
2514 		break;
2515 	case HIF_AP_SET_REQ:
2516 		netdev_info(dev, "HIF_AP_SET_REQ\n");
2517 		break;
2518 	case HIF_AP_SET_CONF:
2519 		netdev_info(dev, "HIF_AP_SET_CONF\n");
2520 		break;
2521 	case HIF_ASSOC_INFO_IND:
2522 		netdev_info(dev, "HIF_ASSOC_INFO_IND\n");
2523 		break;
2524 	case HIF_MIC_FAILURE_REQ:
2525 		netdev_info(dev, "HIF_MIC_FAILURE_REQ\n");
2526 		break;
2527 	case HIF_MIC_FAILURE_CONF:
2528 		netdev_info(dev, "HIF_MIC_FAILURE_CONF\n");
2529 		break;
2530 	case HIF_SCAN_REQ:
2531 		netdev_info(dev, "HIF_SCAN_REQ\n");
2532 		break;
2533 	case HIF_SCAN_CONF:
2534 		netdev_info(dev, "HIF_SCAN_CONF\n");
2535 		break;
2536 	case HIF_PHY_INFO_REQ:
2537 		netdev_info(dev, "HIF_PHY_INFO_REQ\n");
2538 		break;
2539 	case HIF_PHY_INFO_CONF:
2540 		netdev_info(dev, "HIF_PHY_INFO_CONF\n");
2541 		break;
2542 	case HIF_SLEEP_REQ:
2543 		netdev_info(dev, "HIF_SLEEP_REQ\n");
2544 		break;
2545 	case HIF_SLEEP_CONF:
2546 		netdev_info(dev, "HIF_SLEEP_CONF\n");
2547 		break;
2548 	case HIF_PHY_INFO_IND:
2549 		netdev_info(dev, "HIF_PHY_INFO_IND\n");
2550 		break;
2551 	case HIF_SCAN_IND:
2552 		netdev_info(dev, "HIF_SCAN_IND\n");
2553 		break;
2554 	case HIF_INFRA_SET2_REQ:
2555 		netdev_info(dev, "HIF_INFRA_SET2_REQ\n");
2556 		break;
2557 	case HIF_INFRA_SET2_CONF:
2558 		netdev_info(dev, "HIF_INFRA_SET2_CONF\n");
2559 		break;
2560 	case HIF_ADH_SET2_REQ:
2561 		netdev_info(dev, "HIF_ADH_SET2_REQ\n");
2562 		break;
2563 	case HIF_ADH_SET2_CONF:
2564 		netdev_info(dev, "HIF_ADH_SET2_CONF\n");
2565 	}
2566 }
2567 
2568 /* get host command history */
2569 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
2570 			 __u32 *uwrq, char *extra)
2571 {
2572 	int i, event;
2573 	struct ks_wlan_private *priv = netdev_priv(dev);
2574 
2575 	for (i = 63; i >= 0; i--) {
2576 		event =
2577 		    priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
2578 				     SME_EVENT_BUFF_SIZE];
2579 		print_hif_event(dev, event);
2580 	}
2581 	return 0;
2582 }
2583 
2584 /* Structures to export the Wireless Handlers */
2585 
2586 static const struct iw_priv_args ks_wlan_private_args[] = {
2587 /*{ cmd, set_args, get_args, name[16] } */
2588 	{KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
2589 	 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
2590 #ifdef WPS
2591 	{KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2592 	 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
2593 	{KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
2594 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
2595 	{KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
2596 	 "SetWPSProbeReq"},
2597 #endif /* WPS */
2598 	{KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2599 	 IW_PRIV_TYPE_NONE, "SetPreamble"},
2600 	{KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
2601 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
2602 	{KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2603 	 IW_PRIV_TYPE_NONE, "SetPowerSave"},
2604 	{KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
2605 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
2606 	{KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2607 	 IW_PRIV_TYPE_NONE, "SetScanType"},
2608 	{KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
2609 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
2610 	{KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2611 	 IW_PRIV_TYPE_NONE, "SetRxGain"},
2612 	{KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
2613 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
2614 	{KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
2615 	 "hostt"},
2616 	{KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2617 	 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
2618 	{KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
2619 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
2620 	{KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2621 	 IW_PRIV_TYPE_NONE, "SetSleepMode"},
2622 	{KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
2623 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
2624 	{KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2625 	 IW_PRIV_TYPE_NONE, "SetTxGain"},
2626 	{KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
2627 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
2628 	{KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2629 	 IW_PRIV_TYPE_NONE, "SetPhyType"},
2630 	{KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
2631 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
2632 	{KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2633 	 IW_PRIV_TYPE_NONE, "SetCtsMode"},
2634 	{KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
2635 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
2636 	{KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
2637 	 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
2638 };
2639 
2640 static const iw_handler ks_wlan_handler[] = {
2641 	(iw_handler)ks_wlan_config_commit,	/* SIOCSIWCOMMIT */
2642 	(iw_handler)ks_wlan_get_name,	/* SIOCGIWNAME */
2643 	(iw_handler)NULL,	/* SIOCSIWNWID */
2644 	(iw_handler)NULL,	/* SIOCGIWNWID */
2645 	(iw_handler)ks_wlan_set_freq,	/* SIOCSIWFREQ */
2646 	(iw_handler)ks_wlan_get_freq,	/* SIOCGIWFREQ */
2647 	(iw_handler)ks_wlan_set_mode,	/* SIOCSIWMODE */
2648 	(iw_handler)ks_wlan_get_mode,	/* SIOCGIWMODE */
2649 #ifndef KSC_OPNOTSUPP
2650 	(iw_handler)ks_wlan_set_sens,	/* SIOCSIWSENS */
2651 	(iw_handler)ks_wlan_get_sens,	/* SIOCGIWSENS */
2652 #else /* KSC_OPNOTSUPP */
2653 	(iw_handler)NULL,	/* SIOCSIWSENS */
2654 	(iw_handler)NULL,	/* SIOCGIWSENS */
2655 #endif /* KSC_OPNOTSUPP */
2656 	(iw_handler)NULL,	/* SIOCSIWRANGE */
2657 	(iw_handler)ks_wlan_get_range,	/* SIOCGIWRANGE */
2658 	(iw_handler)NULL,	/* SIOCSIWPRIV */
2659 	(iw_handler)NULL,	/* SIOCGIWPRIV */
2660 	(iw_handler)NULL,	/* SIOCSIWSTATS */
2661 	(iw_handler)ks_wlan_get_iwstats,	/* SIOCGIWSTATS */
2662 	(iw_handler)NULL,	/* SIOCSIWSPY */
2663 	(iw_handler)NULL,	/* SIOCGIWSPY */
2664 	(iw_handler)NULL,	/* SIOCSIWTHRSPY */
2665 	(iw_handler)NULL,	/* SIOCGIWTHRSPY */
2666 	(iw_handler)ks_wlan_set_wap,	/* SIOCSIWAP */
2667 	(iw_handler)ks_wlan_get_wap,	/* SIOCGIWAP */
2668 //      (iw_handler)NULL,                      /* SIOCSIWMLME */
2669 	(iw_handler)ks_wlan_set_mlme,	/* SIOCSIWMLME */
2670 	(iw_handler)ks_wlan_get_aplist,	/* SIOCGIWAPLIST */
2671 	(iw_handler)ks_wlan_set_scan,	/* SIOCSIWSCAN */
2672 	(iw_handler)ks_wlan_get_scan,	/* SIOCGIWSCAN */
2673 	(iw_handler)ks_wlan_set_essid,	/* SIOCSIWESSID */
2674 	(iw_handler)ks_wlan_get_essid,	/* SIOCGIWESSID */
2675 	(iw_handler)ks_wlan_set_nick,	/* SIOCSIWNICKN */
2676 	(iw_handler)ks_wlan_get_nick,	/* SIOCGIWNICKN */
2677 	(iw_handler)NULL,	/* -- hole -- */
2678 	(iw_handler)NULL,	/* -- hole -- */
2679 	(iw_handler)ks_wlan_set_rate,	/* SIOCSIWRATE */
2680 	(iw_handler)ks_wlan_get_rate,	/* SIOCGIWRATE */
2681 	(iw_handler)ks_wlan_set_rts,	/* SIOCSIWRTS */
2682 	(iw_handler)ks_wlan_get_rts,	/* SIOCGIWRTS */
2683 	(iw_handler)ks_wlan_set_frag,	/* SIOCSIWFRAG */
2684 	(iw_handler)ks_wlan_get_frag,	/* SIOCGIWFRAG */
2685 #ifndef KSC_OPNOTSUPP
2686 	(iw_handler)ks_wlan_set_txpow,	/* SIOCSIWTXPOW */
2687 	(iw_handler)ks_wlan_get_txpow,	/* SIOCGIWTXPOW */
2688 	(iw_handler)ks_wlan_set_retry,	/* SIOCSIWRETRY */
2689 	(iw_handler)ks_wlan_get_retry,	/* SIOCGIWRETRY */
2690 #else /* KSC_OPNOTSUPP */
2691 	(iw_handler)NULL,	/* SIOCSIWTXPOW */
2692 	(iw_handler)NULL,	/* SIOCGIWTXPOW */
2693 	(iw_handler)NULL,	/* SIOCSIWRETRY */
2694 	(iw_handler)NULL,	/* SIOCGIWRETRY */
2695 #endif /* KSC_OPNOTSUPP */
2696 	(iw_handler)ks_wlan_set_encode,	/* SIOCSIWENCODE */
2697 	(iw_handler)ks_wlan_get_encode,	/* SIOCGIWENCODE */
2698 	(iw_handler)ks_wlan_set_power,	/* SIOCSIWPOWER */
2699 	(iw_handler)ks_wlan_get_power,	/* SIOCGIWPOWER */
2700 	(iw_handler)NULL,	/* -- hole -- */
2701 	(iw_handler)NULL,	/* -- hole -- */
2702 //      (iw_handler)NULL,                      /* SIOCSIWGENIE */
2703 	(iw_handler)ks_wlan_set_genie,	/* SIOCSIWGENIE */
2704 	(iw_handler)NULL,	/* SIOCGIWGENIE */
2705 	(iw_handler)ks_wlan_set_auth_mode,	/* SIOCSIWAUTH */
2706 	(iw_handler)ks_wlan_get_auth_mode,	/* SIOCGIWAUTH */
2707 	(iw_handler)ks_wlan_set_encode_ext,	/* SIOCSIWENCODEEXT */
2708 	(iw_handler)ks_wlan_get_encode_ext,	/* SIOCGIWENCODEEXT */
2709 	(iw_handler)ks_wlan_set_pmksa,	/* SIOCSIWPMKSA */
2710 	(iw_handler)NULL,	/* -- hole -- */
2711 };
2712 
2713 /* private_handler */
2714 static const iw_handler ks_wlan_private_handler[] = {
2715 	(iw_handler)NULL,	/*  0 */
2716 	(iw_handler)NULL,	/*  1, used to be: KS_WLAN_GET_DRIVER_VERSION */
2717 	(iw_handler)NULL,	/*  2 */
2718 	(iw_handler)ks_wlan_get_firmware_version,	/*  3 KS_WLAN_GET_FIRM_VERSION */
2719 #ifdef WPS
2720 	(iw_handler)ks_wlan_set_wps_enable,	/*  4 KS_WLAN_SET_WPS_ENABLE  */
2721 	(iw_handler)ks_wlan_get_wps_enable,	/*  5 KS_WLAN_GET_WPS_ENABLE  */
2722 	(iw_handler)ks_wlan_set_wps_probe_req,	/*  6 KS_WLAN_SET_WPS_PROBE_REQ */
2723 #else
2724 	(iw_handler)NULL,	/*  4 */
2725 	(iw_handler)NULL,	/*  5 */
2726 	(iw_handler)NULL,	/*  6 */
2727 #endif /* WPS */
2728 
2729 	(iw_handler)ks_wlan_get_eeprom_cksum,	/*  7 KS_WLAN_GET_CONNECT */
2730 	(iw_handler)ks_wlan_set_preamble,	/*  8 KS_WLAN_SET_PREAMBLE */
2731 	(iw_handler)ks_wlan_get_preamble,	/*  9 KS_WLAN_GET_PREAMBLE */
2732 	(iw_handler)ks_wlan_set_power_mgmt,	/* 10 KS_WLAN_SET_POWER_SAVE */
2733 	(iw_handler)ks_wlan_get_power_mgmt,	/* 11 KS_WLAN_GET_POWER_SAVE */
2734 	(iw_handler)ks_wlan_set_scan_type,	/* 12 KS_WLAN_SET_SCAN_TYPE */
2735 	(iw_handler)ks_wlan_get_scan_type,	/* 13 KS_WLAN_GET_SCAN_TYPE */
2736 	(iw_handler)ks_wlan_set_rx_gain,	/* 14 KS_WLAN_SET_RX_GAIN */
2737 	(iw_handler)ks_wlan_get_rx_gain,	/* 15 KS_WLAN_GET_RX_GAIN */
2738 	(iw_handler)ks_wlan_hostt,	/* 16 KS_WLAN_HOSTT */
2739 	(iw_handler)NULL,	/* 17 */
2740 	(iw_handler)ks_wlan_set_beacon_lost,	/* 18 KS_WLAN_SET_BECAN_LOST */
2741 	(iw_handler)ks_wlan_get_beacon_lost,	/* 19 KS_WLAN_GET_BECAN_LOST */
2742 	(iw_handler)ks_wlan_set_tx_gain,	/* 20 KS_WLAN_SET_TX_GAIN */
2743 	(iw_handler)ks_wlan_get_tx_gain,	/* 21 KS_WLAN_GET_TX_GAIN */
2744 	(iw_handler)ks_wlan_set_phy_type,	/* 22 KS_WLAN_SET_PHY_TYPE */
2745 	(iw_handler)ks_wlan_get_phy_type,	/* 23 KS_WLAN_GET_PHY_TYPE */
2746 	(iw_handler)ks_wlan_set_cts_mode,	/* 24 KS_WLAN_SET_CTS_MODE */
2747 	(iw_handler)ks_wlan_get_cts_mode,	/* 25 KS_WLAN_GET_CTS_MODE */
2748 	(iw_handler)NULL,	/* 26 */
2749 	(iw_handler)NULL,	/* 27 */
2750 	(iw_handler)ks_wlan_set_sleep_mode,	/* 28 KS_WLAN_SET_SLEEP_MODE */
2751 	(iw_handler)ks_wlan_get_sleep_mode,	/* 29 KS_WLAN_GET_SLEEP_MODE */
2752 	(iw_handler)NULL,	/* 30 */
2753 	(iw_handler)NULL,	/* 31 */
2754 };
2755 
2756 static const struct iw_handler_def ks_wlan_handler_def = {
2757 	.num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
2758 	.num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
2759 	.num_private_args =
2760 	    sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
2761 	.standard = (iw_handler *)ks_wlan_handler,
2762 	.private = (iw_handler *)ks_wlan_private_handler,
2763 	.private_args = (struct iw_priv_args *)ks_wlan_private_args,
2764 	.get_wireless_stats = ks_get_wireless_stats,
2765 };
2766 
2767 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
2768 				int cmd)
2769 {
2770 	int ret;
2771 	struct iwreq *wrq = (struct iwreq *)rq;
2772 
2773 	switch (cmd) {
2774 	case SIOCIWFIRSTPRIV + 20:	/* KS_WLAN_SET_STOP_REQ */
2775 		ret = ks_wlan_set_stop_request(dev, NULL, &wrq->u.mode, NULL);
2776 		break;
2777 		// All other calls are currently unsupported
2778 	default:
2779 		ret = -EOPNOTSUPP;
2780 	}
2781 
2782 	DPRINTK(5, "return=%d\n", ret);
2783 	return ret;
2784 }
2785 
2786 static
2787 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
2788 {
2789 	struct ks_wlan_private *priv = netdev_priv(dev);
2790 
2791 	if (priv->dev_state < DEVICE_STATE_READY)
2792 		return NULL;	/* not finished initialize */
2793 
2794 	return &priv->nstats;
2795 }
2796 
2797 static
2798 int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
2799 {
2800 	struct ks_wlan_private *priv = netdev_priv(dev);
2801 	struct sockaddr *mac_addr = (struct sockaddr *)addr;
2802 
2803 	if (netif_running(dev))
2804 		return -EBUSY;
2805 	memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
2806 	memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
2807 
2808 	priv->mac_address_valid = 0;
2809 	hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
2810 	netdev_info(dev, "ks_wlan:  MAC ADDRESS = %pM\n", priv->eth_addr);
2811 	return 0;
2812 }
2813 
2814 static
2815 void ks_wlan_tx_timeout(struct net_device *dev)
2816 {
2817 	struct ks_wlan_private *priv = netdev_priv(dev);
2818 
2819 	DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
2820 		priv->tx_dev.qtail);
2821 	if (!netif_queue_stopped(dev))
2822 		netif_stop_queue(dev);
2823 	priv->nstats.tx_errors++;
2824 	netif_wake_queue(dev);
2825 }
2826 
2827 static
2828 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
2829 {
2830 	struct ks_wlan_private *priv = netdev_priv(dev);
2831 	int ret;
2832 
2833 	DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
2834 
2835 	if (!skb) {
2836 		netdev_err(dev, "ks_wlan:  skb == NULL!!!\n");
2837 		return 0;
2838 	}
2839 	if (priv->dev_state < DEVICE_STATE_READY) {
2840 		dev_kfree_skb(skb);
2841 		return 0;	/* not finished initialize */
2842 	}
2843 
2844 	if (netif_running(dev))
2845 		netif_stop_queue(dev);
2846 
2847 	ret = hostif_data_request(priv, skb);
2848 	netif_trans_update(dev);
2849 
2850 	if (ret)
2851 		DPRINTK(4, "hostif_data_request error: =%d\n", ret);
2852 
2853 	return 0;
2854 }
2855 
2856 void send_packet_complete(struct ks_wlan_private *priv, struct sk_buff *skb)
2857 {
2858 	DPRINTK(3, "\n");
2859 
2860 	priv->nstats.tx_packets++;
2861 
2862 	if (netif_queue_stopped(priv->net_dev))
2863 		netif_wake_queue(priv->net_dev);
2864 
2865 	if (skb) {
2866 		priv->nstats.tx_bytes += skb->len;
2867 		dev_kfree_skb(skb);
2868 	}
2869 }
2870 
2871 /*
2872  * Set or clear the multicast filter for this adaptor.
2873  * This routine is not state sensitive and need not be SMP locked.
2874  */
2875 static
2876 void ks_wlan_set_multicast_list(struct net_device *dev)
2877 {
2878 	struct ks_wlan_private *priv = netdev_priv(dev);
2879 
2880 	DPRINTK(4, "\n");
2881 	if (priv->dev_state < DEVICE_STATE_READY)
2882 		return;	/* not finished initialize */
2883 	hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
2884 }
2885 
2886 static
2887 int ks_wlan_open(struct net_device *dev)
2888 {
2889 	struct ks_wlan_private *priv = netdev_priv(dev);
2890 
2891 	priv->cur_rx = 0;
2892 
2893 	if (!priv->mac_address_valid) {
2894 		netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name);
2895 		return -EBUSY;
2896 	}
2897 	netif_start_queue(dev);
2898 
2899 	return 0;
2900 }
2901 
2902 static
2903 int ks_wlan_close(struct net_device *dev)
2904 {
2905 	netif_stop_queue(dev);
2906 
2907 	DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
2908 		dev->name, 0x00);
2909 
2910 	return 0;
2911 }
2912 
2913 /* Operational parameters that usually are not changed. */
2914 /* Time in jiffies before concluding the transmitter is hung. */
2915 #define TX_TIMEOUT  (3 * HZ)
2916 static const unsigned char dummy_addr[] = {
2917 	0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
2918 };
2919 
2920 static const struct net_device_ops ks_wlan_netdev_ops = {
2921 	.ndo_start_xmit = ks_wlan_start_xmit,
2922 	.ndo_open = ks_wlan_open,
2923 	.ndo_stop = ks_wlan_close,
2924 	.ndo_do_ioctl = ks_wlan_netdev_ioctl,
2925 	.ndo_set_mac_address = ks_wlan_set_mac_address,
2926 	.ndo_get_stats = ks_wlan_get_stats,
2927 	.ndo_tx_timeout = ks_wlan_tx_timeout,
2928 	.ndo_set_rx_mode = ks_wlan_set_multicast_list,
2929 };
2930 
2931 int ks_wlan_net_start(struct net_device *dev)
2932 {
2933 	struct ks_wlan_private *priv;
2934 	/* int rc; */
2935 
2936 	priv = netdev_priv(dev);
2937 	priv->mac_address_valid = 0;
2938 	priv->need_commit = 0;
2939 
2940 	priv->device_open_status = 1;
2941 
2942 	/* phy information update timer */
2943 	atomic_set(&update_phyinfo, 0);
2944 	setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout,
2945 		    (unsigned long)priv);
2946 
2947 	/* dummy address set */
2948 	memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
2949 	dev->dev_addr[0] = priv->eth_addr[0];
2950 	dev->dev_addr[1] = priv->eth_addr[1];
2951 	dev->dev_addr[2] = priv->eth_addr[2];
2952 	dev->dev_addr[3] = priv->eth_addr[3];
2953 	dev->dev_addr[4] = priv->eth_addr[4];
2954 	dev->dev_addr[5] = priv->eth_addr[5];
2955 	dev->dev_addr[6] = 0x00;
2956 	dev->dev_addr[7] = 0x00;
2957 
2958 	/* The ks_wlan-specific entries in the device structure. */
2959 	dev->netdev_ops = &ks_wlan_netdev_ops;
2960 	dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
2961 	dev->watchdog_timeo = TX_TIMEOUT;
2962 
2963 	netif_carrier_off(dev);
2964 
2965 	return 0;
2966 }
2967 
2968 int ks_wlan_net_stop(struct net_device *dev)
2969 {
2970 	struct ks_wlan_private *priv = netdev_priv(dev);
2971 
2972 	priv->device_open_status = 0;
2973 	del_timer_sync(&update_phyinfo_timer);
2974 
2975 	if (netif_running(dev))
2976 		netif_stop_queue(dev);
2977 
2978 	return 0;
2979 }
2980 
2981 /**
2982  * is_connect_status() - return true if status is 'connected'
2983  * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2984  * 	connect status.
2985  */
2986 bool is_connect_status(u32 status)
2987 {
2988 	return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
2989 }
2990 
2991 /**
2992  * is_disconnect_status() - return true if status is 'disconnected'
2993  * @status: high bit is used as FORCE_DISCONNECT, low bits used for
2994  * 	disconnect status.
2995  */
2996 bool is_disconnect_status(u32 status)
2997 {
2998 	return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;
2999 }
3000