• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/staging/rtl8187se/
1/*
2   This file contains wireless extension handlers.
3
4   This is part of rtl8180 OpenSource driver.
5   Copyright (C) Andrea Merello 2004-2005  <andreamrl@tiscali.it>
6   Released under the terms of GPL (General Public Licence)
7
8   Parts of this driver are based on the GPL part
9   of the official realtek driver.
10
11   Parts of this driver are based on the rtl8180 driver skeleton
12   from Patric Schenke & Andres Salomon.
13
14   Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
15
16   We want to tanks the Authors of those projects and the Ndiswrapper
17   project Authors.
18*/
19
20
21#include "r8180.h"
22#include "r8180_hw.h"
23
24#include "ieee80211/dot11d.h"
25
26//#define RATE_COUNT 4
27u32 rtl8180_rates[] = {1000000,2000000,5500000,11000000,
28	6000000,9000000,12000000,18000000,24000000,36000000,48000000,54000000};
29
30#define RATE_COUNT ARRAY_SIZE(rtl8180_rates)
31
32static CHANNEL_LIST DefaultChannelPlan[] = {
33//	{{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14},			//Default channel plan
34	{{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19},  		//FCC
35	{{1,2,3,4,5,6,7,8,9,10,11},11},                    				//IC
36	{{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21},  	//ETSI
37	{{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21},    //Spain. Change to ETSI.
38	{{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21},  	//France. Change to ETSI.
39	{{14,36,40,44,48,52,56,60,64},9},						//MKK
40	{{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},//MKK1
41	{{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21},	//Israel.
42	{{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17},			// For 11a , TELEC
43	{{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14}					//For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626
44};
45static int r8180_wx_get_freq(struct net_device *dev,
46			     struct iw_request_info *a,
47			     union iwreq_data *wrqu, char *b)
48{
49	struct r8180_priv *priv = ieee80211_priv(dev);
50
51	return ieee80211_wx_get_freq(priv->ieee80211, a, wrqu, b);
52}
53
54
55int r8180_wx_set_key(struct net_device *dev, struct iw_request_info *info,
56		     union iwreq_data *wrqu, char *key)
57{
58	struct r8180_priv *priv = ieee80211_priv(dev);
59	struct iw_point *erq = &(wrqu->encoding);
60
61	if(priv->ieee80211->bHwRadioOff)
62		return 0;
63
64	if (erq->flags & IW_ENCODE_DISABLED) {
65	}
66
67
68/*	i = erq->flags & IW_ENCODE_INDEX;
69	if (i < 1 || i > 4)
70*/
71
72	if (erq->length > 0) {
73
74		//int len = erq->length <= 5 ? 5 : 13;
75
76		u32* tkey= (u32*) key;
77		priv->key0[0] = tkey[0];
78		priv->key0[1] = tkey[1];
79		priv->key0[2] = tkey[2];
80		priv->key0[3] = tkey[3] &0xff;
81		DMESG("Setting wep key to %x %x %x %x",
82		      tkey[0],tkey[1],tkey[2],tkey[3]);
83		rtl8180_set_hw_wep(dev);
84	}
85	return 0;
86}
87
88
89static int r8180_wx_set_beaconinterval(struct net_device *dev, struct iw_request_info *aa,
90			  union iwreq_data *wrqu, char *b)
91{
92	int *parms = (int *)b;
93	int bi = parms[0];
94
95	struct r8180_priv *priv = ieee80211_priv(dev);
96
97	if(priv->ieee80211->bHwRadioOff)
98		return 0;
99
100	down(&priv->wx_sem);
101	DMESG("setting beacon interval to %x",bi);
102
103	priv->ieee80211->current_network.beacon_interval=bi;
104	rtl8180_commit(dev);
105	up(&priv->wx_sem);
106
107	return 0;
108}
109
110
111
112static int r8180_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
113			     union iwreq_data *wrqu, char *b)
114{
115	struct r8180_priv *priv = ieee80211_priv(dev);
116	return ieee80211_wx_get_mode(priv->ieee80211,a,wrqu,b);
117}
118
119
120
121static int r8180_wx_get_rate(struct net_device *dev,
122			     struct iw_request_info *info,
123			     union iwreq_data *wrqu, char *extra)
124{
125	struct r8180_priv *priv = ieee80211_priv(dev);
126	return ieee80211_wx_get_rate(priv->ieee80211,info,wrqu,extra);
127}
128
129
130
131static int r8180_wx_set_rate(struct net_device *dev,
132			     struct iw_request_info *info,
133			     union iwreq_data *wrqu, char *extra)
134{
135	int ret;
136	struct r8180_priv *priv = ieee80211_priv(dev);
137
138
139	if(priv->ieee80211->bHwRadioOff)
140		return 0;
141
142	down(&priv->wx_sem);
143
144	ret = ieee80211_wx_set_rate(priv->ieee80211,info,wrqu,extra);
145
146	up(&priv->wx_sem);
147
148	return ret;
149}
150
151
152static int r8180_wx_set_crcmon(struct net_device *dev,
153			       struct iw_request_info *info,
154			       union iwreq_data *wrqu, char *extra)
155{
156	struct r8180_priv *priv = ieee80211_priv(dev);
157	int *parms = (int *)extra;
158	int enable = (parms[0] > 0);
159	short prev = priv->crcmon;
160
161
162	if(priv->ieee80211->bHwRadioOff)
163		return 0;
164
165	down(&priv->wx_sem);
166
167	if(enable)
168		priv->crcmon=1;
169	else
170		priv->crcmon=0;
171
172	DMESG("bad CRC in monitor mode are %s",
173	      priv->crcmon ? "accepted" : "rejected");
174
175	if(prev != priv->crcmon && priv->up){
176		rtl8180_down(dev);
177		rtl8180_up(dev);
178	}
179
180	up(&priv->wx_sem);
181
182	return 0;
183}
184
185
186static int r8180_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
187			     union iwreq_data *wrqu, char *b)
188{
189	struct r8180_priv *priv = ieee80211_priv(dev);
190	int ret;
191
192
193	if(priv->ieee80211->bHwRadioOff)
194		return 0;
195
196	down(&priv->wx_sem);
197//	printk("set mode ENABLE_IPS\n");
198	if(priv->bInactivePs){
199		if(wrqu->mode == IW_MODE_ADHOC)
200			IPSLeave(dev);
201	}
202	ret = ieee80211_wx_set_mode(priv->ieee80211,a,wrqu,b);
203
204	//rtl8180_commit(dev);
205
206	up(&priv->wx_sem);
207	return ret;
208}
209
210//YJ,add,080819,for hidden ap
211struct  iw_range_with_scan_capa
212{
213        /* Informative stuff (to choose between different interface) */
214        __u32           throughput;     /* To give an idea... */
215        /* In theory this value should be the maximum benchmarked
216         * TCP/IP throughput, because with most of these devices the
217         * bit rate is meaningless (overhead an co) to estimate how
218         * fast the connection will go and pick the fastest one.
219         * I suggest people to play with Netperf or any benchmark...
220         */
221
222        /* NWID (or domain id) */
223        __u32           min_nwid;       /* Minimal NWID we are able to set */
224        __u32           max_nwid;       /* Maximal NWID we are able to set */
225
226        /* Old Frequency (backward compat - moved lower ) */
227        __u16           old_num_channels;
228        __u8            old_num_frequency;
229
230        /* Scan capabilities */
231        __u8            scan_capa;
232};
233//YJ,add,080819,for hidden ap
234
235
236static int rtl8180_wx_get_range(struct net_device *dev,
237				struct iw_request_info *info,
238				union iwreq_data *wrqu, char *extra)
239{
240	struct iw_range *range = (struct iw_range *)extra;
241	struct r8180_priv *priv = ieee80211_priv(dev);
242	u16 val;
243	int i;
244	//struct iw_range_with_scan_capa* tmp = (struct iw_range_with_scan_capa*)range; //YJ,add,080819,for hidden ap
245
246	wrqu->data.length = sizeof(*range);
247	memset(range, 0, sizeof(*range));
248
249	/* Let's try to keep this struct in the same order as in
250	 * linux/include/wireless.h
251	 */
252
253	/* TODO: See what values we can set, and remove the ones we can't
254	 * set, or fill them with some default data.
255	 */
256
257	/* ~5 Mb/s real (802.11b) */
258	range->throughput = 5 * 1000 * 1000;
259
260	// TODO: Not used in 802.11b?
261//	range->min_nwid;	/* Minimal NWID we are able to set */
262	// TODO: Not used in 802.11b?
263//	range->max_nwid;	/* Maximal NWID we are able to set */
264
265        /* Old Frequency (backward compat - moved lower ) */
266//	range->old_num_channels;
267//	range->old_num_frequency;
268//	range->old_freq[6]; /* Filler to keep "version" at the same offset */
269	if(priv->rf_set_sens != NULL)
270		range->sensitivity = priv->max_sens;	/* signal level threshold range */
271
272	range->max_qual.qual = 100;
273	/* TODO: Find real max RSSI and stick here */
274	range->max_qual.level = 0;
275	range->max_qual.noise = -98;
276	range->max_qual.updated = 7; /* Updated all three */
277
278	range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
279	/* TODO: Find real 'good' to 'bad' threshold value for RSSI */
280	range->avg_qual.level = 20 + -98;
281	range->avg_qual.noise = 0;
282	range->avg_qual.updated = 7; /* Updated all three */
283
284	range->num_bitrates = RATE_COUNT;
285
286	for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
287		range->bitrate[i] = rtl8180_rates[i];
288	}
289
290	range->min_frag = MIN_FRAG_THRESHOLD;
291	range->max_frag = MAX_FRAG_THRESHOLD;
292
293	range->pm_capa = 0;
294
295	range->we_version_compiled = WIRELESS_EXT;
296	range->we_version_source = 16;
297
298//	range->retry_capa;	/* What retry options are supported */
299//	range->retry_flags;	/* How to decode max/min retry limit */
300//	range->r_time_flags;	/* How to decode max/min retry life */
301//	range->min_retry;	/* Minimal number of retries */
302//	range->max_retry;	/* Maximal number of retries */
303//	range->min_r_time;	/* Minimal retry lifetime */
304//	range->max_r_time;	/* Maximal retry lifetime */
305
306        range->num_channels = 14;
307
308	for (i = 0, val = 0; i < 14; i++) {
309
310		// Include only legal frequencies for some countries
311		if ((GET_DOT11D_INFO(priv->ieee80211)->channel_map)[i+1]) {
312		        range->freq[val].i = i + 1;
313			range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000;
314			range->freq[val].e = 1;
315			val++;
316		} else {
317			// we don't use ?
318		}
319
320		if (val == IW_MAX_FREQUENCIES)
321		break;
322	}
323
324	range->num_frequency = val;
325	range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
326                          IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
327
328	//tmp->scan_capa = 0x01; //YJ,add,080819,for hidden ap
329
330	return 0;
331}
332
333
334static int r8180_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
335			     union iwreq_data *wrqu, char *b)
336{
337	struct r8180_priv *priv = ieee80211_priv(dev);
338	int ret;
339	struct ieee80211_device* ieee = priv->ieee80211;
340
341
342	if(priv->ieee80211->bHwRadioOff)
343		return 0;
344
345//YJ,add,080819, for hidden ap
346	//printk("==*&*&*&==>%s in\n", __func__);
347	//printk("=*&*&*&*===>flag:%x, %x\n", wrqu->data.flags, IW_SCAN_THIS_ESSID);
348	if (wrqu->data.flags & IW_SCAN_THIS_ESSID)
349	{
350		struct iw_scan_req* req = (struct iw_scan_req*)b;
351		if (req->essid_len)
352		{
353			//printk("==**&*&*&**===>scan set ssid:%s\n", req->essid);
354			ieee->current_network.ssid_len = req->essid_len;
355			memcpy(ieee->current_network.ssid, req->essid, req->essid_len);
356			//printk("=====>network ssid:%s\n", ieee->current_network.ssid);
357		}
358	}
359//YJ,add,080819, for hidden ap, end
360
361	down(&priv->wx_sem);
362	if(priv->up){
363//		printk("set scan ENABLE_IPS\n");
364		priv->ieee80211->actscanning = true;
365		if(priv->bInactivePs && (priv->ieee80211->state != IEEE80211_LINKED)){
366			IPSLeave(dev);
367//			down(&priv->ieee80211->wx_sem);
368
369//			if (priv->ieee80211->iw_mode == IW_MODE_MONITOR || !(priv->ieee80211->proto_started)){
370//				ret = -1;
371//				up(&priv->ieee80211->wx_sem);
372//				up(&priv->wx_sem);
373//				return ret;
374//			}
375
376	//	queue_work(priv->ieee80211->wq, &priv->ieee80211->wx_sync_scan_wq);
377		//printk("start scan============================>\n");
378		ieee80211_softmac_ips_scan_syncro(priv->ieee80211);
379//ieee80211_rtl_start_scan(priv->ieee80211);
380		/* intentionally forget to up sem */
381//			up(&priv->ieee80211->wx_sem);
382			ret = 0;
383		}
384		else
385		{
386			//YJ,add,080828, prevent scan in BusyTraffic
387			if ((priv->link_detect.bBusyTraffic) && (true))
388			{
389				ret = 0;
390				printk("Now traffic is busy, please try later!\n");
391			}
392			else
393			//YJ,add,080828, prevent scan in BusyTraffic,end
394				ret = ieee80211_wx_set_scan(priv->ieee80211,a,wrqu,b);
395		}
396	}
397	else
398		ret = -1;
399
400	up(&priv->wx_sem);
401
402	return ret;
403}
404
405
406static int r8180_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
407			     union iwreq_data *wrqu, char *b)
408{
409
410	int ret;
411	struct r8180_priv *priv = ieee80211_priv(dev);
412
413	down(&priv->wx_sem);
414	if(priv->up)
415		ret = ieee80211_wx_get_scan(priv->ieee80211,a,wrqu,b);
416	else
417		ret = -1;
418
419	up(&priv->wx_sem);
420	return ret;
421}
422
423
424static int r8180_wx_set_essid(struct net_device *dev,
425			      struct iw_request_info *a,
426			      union iwreq_data *wrqu, char *b)
427{
428	struct r8180_priv *priv = ieee80211_priv(dev);
429
430	int ret;
431
432	if(priv->ieee80211->bHwRadioOff)
433		return 0;
434
435	down(&priv->wx_sem);
436	//printk("set essid ENABLE_IPS\n");
437	if(priv->bInactivePs)
438		IPSLeave(dev);
439//	printk("haha:set essid %s essid_len = %d essid_flgs = %d\n",b,  wrqu->essid.length, wrqu->essid.flags);
440
441	ret = ieee80211_wx_set_essid(priv->ieee80211,a,wrqu,b);
442
443	up(&priv->wx_sem);
444	return ret;
445}
446
447
448static int r8180_wx_get_essid(struct net_device *dev,
449			      struct iw_request_info *a,
450			      union iwreq_data *wrqu, char *b)
451{
452	int ret;
453	struct r8180_priv *priv = ieee80211_priv(dev);
454
455	down(&priv->wx_sem);
456
457	ret = ieee80211_wx_get_essid(priv->ieee80211, a, wrqu, b);
458
459	up(&priv->wx_sem);
460
461	return ret;
462}
463
464
465static int r8180_wx_set_freq(struct net_device *dev, struct iw_request_info *a,
466			     union iwreq_data *wrqu, char *b)
467{
468	int ret;
469	struct r8180_priv *priv = ieee80211_priv(dev);
470
471
472	if(priv->ieee80211->bHwRadioOff)
473		return 0;
474
475	down(&priv->wx_sem);
476
477	ret = ieee80211_wx_set_freq(priv->ieee80211, a, wrqu, b);
478
479	up(&priv->wx_sem);
480	return ret;
481}
482
483
484static int r8180_wx_get_name(struct net_device *dev,
485			     struct iw_request_info *info,
486			     union iwreq_data *wrqu, char *extra)
487{
488	struct r8180_priv *priv = ieee80211_priv(dev);
489	return ieee80211_wx_get_name(priv->ieee80211, info, wrqu, extra);
490}
491
492static int r8180_wx_set_frag(struct net_device *dev,
493			     struct iw_request_info *info,
494			     union iwreq_data *wrqu, char *extra)
495{
496	struct r8180_priv *priv = ieee80211_priv(dev);
497
498	if(priv->ieee80211->bHwRadioOff)
499		return 0;
500
501	if (wrqu->frag.disabled)
502		priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
503	else {
504		if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
505		    wrqu->frag.value > MAX_FRAG_THRESHOLD)
506			return -EINVAL;
507
508		priv->ieee80211->fts = wrqu->frag.value & ~0x1;
509	}
510
511	return 0;
512}
513
514
515static int r8180_wx_get_frag(struct net_device *dev,
516			     struct iw_request_info *info,
517			     union iwreq_data *wrqu, char *extra)
518{
519	struct r8180_priv *priv = ieee80211_priv(dev);
520
521	wrqu->frag.value = priv->ieee80211->fts;
522	wrqu->frag.fixed = 0;	/* no auto select */
523	wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD);
524
525	return 0;
526}
527
528
529static int r8180_wx_set_wap(struct net_device *dev,
530			 struct iw_request_info *info,
531			 union iwreq_data *awrq,
532			 char *extra)
533{
534	int ret;
535	struct r8180_priv *priv = ieee80211_priv(dev);
536
537	if(priv->ieee80211->bHwRadioOff)
538		return 0;
539
540	down(&priv->wx_sem);
541
542	ret = ieee80211_wx_set_wap(priv->ieee80211,info,awrq,extra);
543
544	up(&priv->wx_sem);
545	return ret;
546
547}
548
549
550static int r8180_wx_get_wap(struct net_device *dev,
551			    struct iw_request_info *info,
552			    union iwreq_data *wrqu, char *extra)
553{
554	struct r8180_priv *priv = ieee80211_priv(dev);
555
556	return ieee80211_wx_get_wap(priv->ieee80211,info,wrqu,extra);
557}
558
559
560static int r8180_wx_set_enc(struct net_device *dev,
561			    struct iw_request_info *info,
562			    union iwreq_data *wrqu, char *key)
563{
564	struct r8180_priv *priv = ieee80211_priv(dev);
565	int ret;
566
567	if(priv->ieee80211->bHwRadioOff)
568		return 0;
569
570
571	down(&priv->wx_sem);
572
573	if(priv->hw_wep) ret = r8180_wx_set_key(dev,info,wrqu,key);
574	else{
575		DMESG("Setting SW wep key");
576		ret = ieee80211_wx_set_encode(priv->ieee80211,info,wrqu,key);
577	}
578
579	up(&priv->wx_sem);
580	return ret;
581}
582
583
584static int r8180_wx_get_enc(struct net_device *dev,
585			    struct iw_request_info *info,
586			    union iwreq_data *wrqu, char *key)
587{
588	struct r8180_priv *priv = ieee80211_priv(dev);
589
590	return ieee80211_wx_get_encode(priv->ieee80211, info, wrqu, key);
591}
592
593
594static int r8180_wx_set_scan_type(struct net_device *dev, struct iw_request_info *aa, union
595 iwreq_data *wrqu, char *p){
596
597 	struct r8180_priv *priv = ieee80211_priv(dev);
598	int *parms=(int*)p;
599	int mode=parms[0];
600
601	if(priv->ieee80211->bHwRadioOff)
602		return 0;
603
604	priv->ieee80211->active_scan = mode;
605
606	return 1;
607}
608
609
610/* added by christian */
611/*
612static int r8180_wx_set_monitor_type(struct net_device *dev, struct iw_request_info *aa, union
613 iwreq_data *wrqu, char *p){
614
615 	struct r8180_priv *priv = ieee80211_priv(dev);
616	int *parms=(int*)p;
617	int mode=parms[0];
618
619	if(priv->ieee80211->iw_mode != IW_MODE_MONITOR) return -1;
620  	priv->prism_hdr = mode;
621	if(!mode)dev->type=ARPHRD_IEEE80211;
622	else dev->type=ARPHRD_IEEE80211_PRISM;
623	DMESG("using %s RX encap", mode ? "AVS":"80211");
624	return 0;
625
626}
627*/
628//of         r8180_wx_set_monitor_type
629/* end added christian */
630
631static int r8180_wx_set_retry(struct net_device *dev,
632				struct iw_request_info *info,
633				union iwreq_data *wrqu, char *extra)
634{
635	struct r8180_priv *priv = ieee80211_priv(dev);
636	int err = 0;
637
638	if(priv->ieee80211->bHwRadioOff)
639		return 0;
640
641	down(&priv->wx_sem);
642
643	if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
644	    wrqu->retry.disabled){
645		err = -EINVAL;
646		goto exit;
647	}
648	if (!(wrqu->retry.flags & IW_RETRY_LIMIT)){
649		err = -EINVAL;
650		goto exit;
651	}
652
653	if(wrqu->retry.value > R8180_MAX_RETRY){
654		err= -EINVAL;
655		goto exit;
656	}
657	if (wrqu->retry.flags & IW_RETRY_MAX) {
658		priv->retry_rts = wrqu->retry.value;
659		DMESG("Setting retry for RTS/CTS data to %d", wrqu->retry.value);
660
661	}else {
662		priv->retry_data = wrqu->retry.value;
663		DMESG("Setting retry for non RTS/CTS data to %d", wrqu->retry.value);
664	}
665
666
667 	rtl8180_commit(dev);
668	/*
669	if(priv->up){
670		rtl8180_rtx_disable(dev);
671		rtl8180_rx_enable(dev);
672		rtl8180_tx_enable(dev);
673
674	}
675	*/
676exit:
677	up(&priv->wx_sem);
678
679	return err;
680}
681
682static int r8180_wx_get_retry(struct net_device *dev,
683				struct iw_request_info *info,
684				union iwreq_data *wrqu, char *extra)
685{
686	struct r8180_priv *priv = ieee80211_priv(dev);
687
688
689	wrqu->retry.disabled = 0; /* can't be disabled */
690
691	if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
692	    IW_RETRY_LIFETIME)
693		return -EINVAL;
694
695	if (wrqu->retry.flags & IW_RETRY_MAX) {
696		wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
697		wrqu->retry.value = priv->retry_rts;
698	} else {
699		wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MIN;
700		wrqu->retry.value = priv->retry_data;
701	}
702	//DMESG("returning %d",wrqu->retry.value);
703
704
705	return 0;
706}
707
708static int r8180_wx_get_sens(struct net_device *dev,
709				struct iw_request_info *info,
710				union iwreq_data *wrqu, char *extra)
711{
712	struct r8180_priv *priv = ieee80211_priv(dev);
713	if(priv->rf_set_sens == NULL)
714		return -1; /* we have not this support for this radio */
715	wrqu->sens.value = priv->sens;
716	return 0;
717}
718
719
720static int r8180_wx_set_sens(struct net_device *dev,
721				struct iw_request_info *info,
722				union iwreq_data *wrqu, char *extra)
723{
724
725	struct r8180_priv *priv = ieee80211_priv(dev);
726
727	short err = 0;
728
729	if(priv->ieee80211->bHwRadioOff)
730		return 0;
731
732	down(&priv->wx_sem);
733	//DMESG("attempt to set sensivity to %ddb",wrqu->sens.value);
734	if(priv->rf_set_sens == NULL) {
735		err= -1; /* we have not this support for this radio */
736		goto exit;
737	}
738	if(priv->rf_set_sens(dev, wrqu->sens.value) == 0)
739		priv->sens = wrqu->sens.value;
740	else
741		err= -EINVAL;
742
743exit:
744	up(&priv->wx_sem);
745
746	return err;
747}
748
749
750static int r8180_wx_set_rawtx(struct net_device *dev,
751			       struct iw_request_info *info,
752			       union iwreq_data *wrqu, char *extra)
753{
754	struct r8180_priv *priv = ieee80211_priv(dev);
755	int ret;
756
757	if(priv->ieee80211->bHwRadioOff)
758		return 0;
759
760	down(&priv->wx_sem);
761
762	ret = ieee80211_wx_set_rawtx(priv->ieee80211, info, wrqu, extra);
763
764	up(&priv->wx_sem);
765
766	return ret;
767
768}
769
770static int r8180_wx_get_power(struct net_device *dev,
771			       struct iw_request_info *info,
772			       union iwreq_data *wrqu, char *extra)
773{
774	int ret;
775	struct r8180_priv *priv = ieee80211_priv(dev);
776
777	down(&priv->wx_sem);
778
779	ret = ieee80211_wx_get_power(priv->ieee80211, info, wrqu, extra);
780
781	up(&priv->wx_sem);
782
783	return ret;
784}
785
786static int r8180_wx_set_power(struct net_device *dev,
787			       struct iw_request_info *info,
788			       union iwreq_data *wrqu, char *extra)
789{
790	int ret;
791	struct r8180_priv *priv = ieee80211_priv(dev);
792
793
794	if(priv->ieee80211->bHwRadioOff)
795		return 0;
796
797	down(&priv->wx_sem);
798	printk("=>>>>>>>>>>=============================>set power:%d,%d!\n",wrqu->power.disabled, wrqu->power.flags);
799	if (wrqu->power.disabled==0) {
800		wrqu->power.flags|=IW_POWER_ALL_R;
801		wrqu->power.flags|=IW_POWER_TIMEOUT;
802		wrqu->power.value =1000;
803	}
804
805	ret = ieee80211_wx_set_power(priv->ieee80211, info, wrqu, extra);
806
807	up(&priv->wx_sem);
808
809	return ret;
810}
811
812static int r8180_wx_set_rts(struct net_device *dev,
813			     struct iw_request_info *info,
814			     union iwreq_data *wrqu, char *extra)
815{
816	struct r8180_priv *priv = ieee80211_priv(dev);
817
818
819	if(priv->ieee80211->bHwRadioOff)
820		return 0;
821
822	if (wrqu->rts.disabled)
823		priv->rts = DEFAULT_RTS_THRESHOLD;
824	else {
825		if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
826		    wrqu->rts.value > MAX_RTS_THRESHOLD)
827			return -EINVAL;
828
829		priv->rts = wrqu->rts.value;
830	}
831
832	return 0;
833}
834static int r8180_wx_get_rts(struct net_device *dev,
835			     struct iw_request_info *info,
836			     union iwreq_data *wrqu, char *extra)
837{
838	struct r8180_priv *priv = ieee80211_priv(dev);
839
840
841
842	wrqu->rts.value = priv->rts;
843	wrqu->rts.fixed = 0;	/* no auto select */
844	wrqu->rts.disabled = (wrqu->rts.value == 0);
845
846	return 0;
847}
848static int dummy(struct net_device *dev, struct iw_request_info *a,
849		 union iwreq_data *wrqu,char *b)
850{
851	return -1;
852}
853
854/*
855static int r8180_wx_get_psmode(struct net_device *dev,
856			       struct iw_request_info *info,
857			       union iwreq_data *wrqu, char *extra)
858{
859	struct r8180_priv *priv = ieee80211_priv(dev);
860	struct ieee80211_device *ieee;
861	int ret = 0;
862
863
864
865	down(&priv->wx_sem);
866
867	if(priv) {
868		ieee = priv->ieee80211;
869		if(ieee->ps == IEEE80211_PS_DISABLED) {
870			*((unsigned int *)extra) = IEEE80211_PS_DISABLED;
871			goto exit;
872		}
873		*((unsigned int *)extra) = IW_POWER_TIMEOUT;
874 	if (ieee->ps & IEEE80211_PS_MBCAST)
875			*((unsigned int *)extra) |= IW_POWER_ALL_R;
876		else
877			*((unsigned int *)extra) |= IW_POWER_UNICAST_R;
878	} else
879		ret = -1;
880exit:
881	up(&priv->wx_sem);
882
883	return ret;
884}
885static int r8180_wx_set_psmode(struct net_device *dev,
886			       struct iw_request_info *info,
887			       union iwreq_data *wrqu, char *extra)
888{
889	struct r8180_priv *priv = ieee80211_priv(dev);
890	//struct ieee80211_device *ieee;
891	int ret = 0;
892
893
894
895	down(&priv->wx_sem);
896
897	ret = ieee80211_wx_set_power(priv->ieee80211, info, wrqu, extra);
898
899	up(&priv->wx_sem);
900
901	return ret;
902
903}
904*/
905
906static int r8180_wx_get_iwmode(struct net_device *dev,
907			       struct iw_request_info *info,
908			       union iwreq_data *wrqu, char *extra)
909{
910	struct r8180_priv *priv = ieee80211_priv(dev);
911	struct ieee80211_device *ieee;
912	int ret = 0;
913
914
915
916	down(&priv->wx_sem);
917
918	ieee = priv->ieee80211;
919
920	strcpy(extra, "802.11");
921	if(ieee->modulation & IEEE80211_CCK_MODULATION) {
922		strcat(extra, "b");
923		if(ieee->modulation & IEEE80211_OFDM_MODULATION)
924			strcat(extra, "/g");
925	} else if(ieee->modulation & IEEE80211_OFDM_MODULATION)
926		strcat(extra, "g");
927
928	up(&priv->wx_sem);
929
930	return ret;
931}
932static int r8180_wx_set_iwmode(struct net_device *dev,
933			       struct iw_request_info *info,
934			       union iwreq_data *wrqu, char *extra)
935{
936	struct r8180_priv *priv = ieee80211_priv(dev);
937	struct ieee80211_device *ieee = priv->ieee80211;
938	int *param = (int *)extra;
939	int ret = 0;
940	int modulation = 0, mode = 0;
941
942
943	if(priv->ieee80211->bHwRadioOff)
944		return 0;
945
946	down(&priv->wx_sem);
947
948	if (*param == 1) {
949		modulation |= IEEE80211_CCK_MODULATION;
950		mode = IEEE_B;
951	printk(KERN_INFO "B mode!\n");
952	} else if (*param == 2) {
953		modulation |= IEEE80211_OFDM_MODULATION;
954		mode = IEEE_G;
955	printk(KERN_INFO "G mode!\n");
956	} else if (*param == 3) {
957		modulation |= IEEE80211_CCK_MODULATION;
958		modulation |= IEEE80211_OFDM_MODULATION;
959		mode = IEEE_B|IEEE_G;
960	printk(KERN_INFO "B/G mode!\n");
961	}
962
963	if(ieee->proto_started) {
964		ieee80211_stop_protocol(ieee);
965		ieee->mode = mode;
966		ieee->modulation = modulation;
967		ieee80211_start_protocol(ieee);
968	} else {
969		ieee->mode = mode;
970		ieee->modulation = modulation;
971//		ieee80211_start_protocol(ieee);
972	}
973
974	up(&priv->wx_sem);
975
976	return ret;
977}
978static int r8180_wx_get_preamble(struct net_device *dev,
979			     struct iw_request_info *info,
980			     union iwreq_data *wrqu, char *extra)
981{
982	struct r8180_priv *priv = ieee80211_priv(dev);
983
984
985
986	down(&priv->wx_sem);
987
988
989
990	*extra = (char) priv->plcp_preamble_mode; 	// 0:auto 1:short 2:long
991	up(&priv->wx_sem);
992
993	return 0;
994}
995static int r8180_wx_set_preamble(struct net_device *dev,
996			     struct iw_request_info *info,
997			     union iwreq_data *wrqu, char *extra)
998{
999	struct r8180_priv *priv = ieee80211_priv(dev);
1000	int ret = 0;
1001
1002
1003	if(priv->ieee80211->bHwRadioOff)
1004		return 0;
1005
1006	down(&priv->wx_sem);
1007	if (*extra<0||*extra>2)
1008		ret = -1;
1009	else
1010		priv->plcp_preamble_mode = *((short *)extra) ;
1011
1012
1013
1014	up(&priv->wx_sem);
1015
1016	return ret;
1017}
1018static int r8180_wx_get_siglevel(struct net_device *dev,
1019			       struct iw_request_info *info,
1020			       union iwreq_data *wrqu, char *extra)
1021{
1022	struct r8180_priv *priv = ieee80211_priv(dev);
1023	//struct ieee80211_network *network = &(priv->ieee80211->current_network);
1024	int ret = 0;
1025
1026
1027
1028	down(&priv->wx_sem);
1029	// Modify by hikaru 6.5
1030	*((int *)extra) = priv->wstats.qual.level;//for interface test ,it should be the priv->wstats.qual.level;
1031
1032
1033
1034	up(&priv->wx_sem);
1035
1036	return ret;
1037}
1038static int r8180_wx_get_sigqual(struct net_device *dev,
1039			       struct iw_request_info *info,
1040			       union iwreq_data *wrqu, char *extra)
1041{
1042	struct r8180_priv *priv = ieee80211_priv(dev);
1043	//struct ieee80211_network *network = &(priv->ieee80211->current_network);
1044	int ret = 0;
1045
1046
1047
1048	down(&priv->wx_sem);
1049	// Modify by hikaru 6.5
1050	*((int *)extra) = priv->wstats.qual.qual;//for interface test ,it should be the priv->wstats.qual.qual;
1051
1052
1053
1054	up(&priv->wx_sem);
1055
1056	return ret;
1057}
1058static int r8180_wx_reset_stats(struct net_device *dev,
1059				struct iw_request_info *info,
1060				union iwreq_data *wrqu, char *extra)
1061{
1062	struct r8180_priv *priv =ieee80211_priv(dev);
1063	down(&priv->wx_sem);
1064
1065	priv->stats.txrdu = 0;
1066	priv->stats.rxrdu = 0;
1067	priv->stats.rxnolast = 0;
1068	priv->stats.rxnodata = 0;
1069	priv->stats.rxnopointer = 0;
1070	priv->stats.txnperr = 0;
1071	priv->stats.txresumed = 0;
1072	priv->stats.rxerr = 0;
1073	priv->stats.rxoverflow = 0;
1074	priv->stats.rxint = 0;
1075
1076	priv->stats.txnpokint = 0;
1077	priv->stats.txhpokint = 0;
1078	priv->stats.txhperr = 0;
1079	priv->stats.ints = 0;
1080	priv->stats.shints = 0;
1081	priv->stats.txoverflow = 0;
1082	priv->stats.rxdmafail = 0;
1083	priv->stats.txbeacon = 0;
1084	priv->stats.txbeaconerr = 0;
1085	priv->stats.txlpokint = 0;
1086	priv->stats.txlperr = 0;
1087	priv->stats.txretry =0;//20060601
1088	priv->stats.rxcrcerrmin=0;
1089	priv->stats.rxcrcerrmid=0;
1090	priv->stats.rxcrcerrmax=0;
1091	priv->stats.rxicverr=0;
1092
1093	up(&priv->wx_sem);
1094
1095	return 0;
1096
1097}
1098static int r8180_wx_radio_on(struct net_device *dev,
1099				struct iw_request_info *info,
1100				union iwreq_data *wrqu, char *extra)
1101{
1102	struct r8180_priv *priv =ieee80211_priv(dev);
1103
1104	if(priv->ieee80211->bHwRadioOff)
1105		return 0;
1106
1107
1108	down(&priv->wx_sem);
1109	priv->rf_wakeup(dev);
1110
1111	up(&priv->wx_sem);
1112
1113	return 0;
1114
1115}
1116
1117static int r8180_wx_radio_off(struct net_device *dev,
1118				struct iw_request_info *info,
1119				union iwreq_data *wrqu, char *extra)
1120{
1121	struct r8180_priv *priv =ieee80211_priv(dev);
1122
1123	if(priv->ieee80211->bHwRadioOff)
1124		return 0;
1125
1126
1127	down(&priv->wx_sem);
1128	priv->rf_sleep(dev);
1129
1130	up(&priv->wx_sem);
1131
1132	return 0;
1133
1134}
1135static int r8180_wx_get_channelplan(struct net_device *dev,
1136			     struct iw_request_info *info,
1137			     union iwreq_data *wrqu, char *extra)
1138{
1139	struct r8180_priv *priv = ieee80211_priv(dev);
1140
1141
1142
1143	down(&priv->wx_sem);
1144	*extra = priv->channel_plan;
1145
1146
1147
1148	up(&priv->wx_sem);
1149
1150	return 0;
1151}
1152static int r8180_wx_set_channelplan(struct net_device *dev,
1153			     struct iw_request_info *info,
1154			     union iwreq_data *wrqu, char *extra)
1155{
1156	struct r8180_priv *priv = ieee80211_priv(dev);
1157	//struct ieee80211_device *ieee = netdev_priv(dev);
1158	int *val = (int *)extra;
1159	int i;
1160	printk("-----in fun %s\n", __func__);
1161
1162	if(priv->ieee80211->bHwRadioOff)
1163		return 0;
1164
1165	//unsigned long flags;
1166	down(&priv->wx_sem);
1167	if (DefaultChannelPlan[*val].Len != 0){
1168		priv ->channel_plan = *val;
1169		// Clear old channel map
1170		for (i=1;i<=MAX_CHANNEL_NUMBER;i++)
1171		{
1172			GET_DOT11D_INFO(priv->ieee80211)->channel_map[i] = 0;
1173		}
1174		// Set new channel map
1175		for (i=1;i<=DefaultChannelPlan[*val].Len;i++)
1176		{
1177			GET_DOT11D_INFO(priv->ieee80211)->channel_map[DefaultChannelPlan[*val].Channel[i-1]] = 1;
1178		}
1179	}
1180	up(&priv->wx_sem);
1181
1182	return 0;
1183}
1184
1185static int r8180_wx_get_version(struct net_device *dev,
1186			       struct iw_request_info *info,
1187			       union iwreq_data *wrqu, char *extra)
1188{
1189	struct r8180_priv *priv = ieee80211_priv(dev);
1190	//struct ieee80211_device *ieee;
1191
1192	down(&priv->wx_sem);
1193	strcpy(extra, "1020.0808");
1194	up(&priv->wx_sem);
1195
1196	return 0;
1197}
1198
1199//added by amy 080818
1200//receive datarate from user typing valid rate is from 2 to 108 (1 - 54M), if input 0, return to normal rate adaptive.
1201static int r8180_wx_set_forcerate(struct net_device *dev,
1202			     struct iw_request_info *info,
1203			     union iwreq_data *wrqu, char *extra)
1204{
1205	struct r8180_priv *priv = ieee80211_priv(dev);
1206	u8 forcerate = *extra;
1207
1208	down(&priv->wx_sem);
1209
1210	printk("==============>%s(): forcerate is %d\n",__func__,forcerate);
1211	if((forcerate == 2) || (forcerate == 4) || (forcerate == 11) || (forcerate == 22) || (forcerate == 12) ||
1212		(forcerate == 18) || (forcerate == 24) || (forcerate == 36) || (forcerate == 48) || (forcerate == 72) ||
1213		(forcerate == 96) || (forcerate == 108))
1214	{
1215		priv->ForcedDataRate = 1;
1216		priv->ieee80211->rate = forcerate * 5;
1217	}
1218	else if(forcerate == 0)
1219	{
1220		priv->ForcedDataRate = 0;
1221		printk("OK! return rate adaptive\n");
1222	}
1223	else
1224		printk("ERR: wrong rate\n");
1225	up(&priv->wx_sem);
1226	return 0;
1227}
1228
1229static int r8180_wx_set_enc_ext(struct net_device *dev,
1230                                        struct iw_request_info *info,
1231                                        union iwreq_data *wrqu, char *extra)
1232{
1233
1234	struct r8180_priv *priv = ieee80211_priv(dev);
1235	//printk("===>%s()\n", __func__);
1236
1237	int ret=0;
1238
1239	if(priv->ieee80211->bHwRadioOff)
1240		return 0;
1241
1242	down(&priv->wx_sem);
1243	ret = ieee80211_wx_set_encode_ext(priv->ieee80211, info, wrqu, extra);
1244	up(&priv->wx_sem);
1245	return ret;
1246
1247}
1248static int r8180_wx_set_auth(struct net_device *dev,
1249			     struct iw_request_info *info,
1250			     union iwreq_data *wrqu, char *extra)
1251{
1252	//printk("====>%s()\n", __func__);
1253	struct r8180_priv *priv = ieee80211_priv(dev);
1254	int ret=0;
1255
1256	if(priv->ieee80211->bHwRadioOff)
1257		return 0;
1258
1259	down(&priv->wx_sem);
1260	ret = ieee80211_wx_set_auth(priv->ieee80211, info, &wrqu->param, extra);
1261	up(&priv->wx_sem);
1262	return ret;
1263}
1264
1265static int r8180_wx_set_mlme(struct net_device *dev,
1266                                        struct iw_request_info *info,
1267                                        union iwreq_data *wrqu, char *extra)
1268{
1269	//printk("====>%s()\n", __func__);
1270
1271	int ret=0;
1272	struct r8180_priv *priv = ieee80211_priv(dev);
1273
1274
1275	if(priv->ieee80211->bHwRadioOff)
1276		return 0;
1277
1278
1279	down(&priv->wx_sem);
1280	ret = ieee80211_wx_set_mlme(priv->ieee80211, info, wrqu, extra);
1281	up(&priv->wx_sem);
1282	return ret;
1283}
1284static int r8180_wx_set_gen_ie(struct net_device *dev,
1285			       struct iw_request_info *info,
1286			       union iwreq_data *wrqu, char *extra)
1287{
1288//	printk("====>%s(), len:%d\n", __func__, data->length);
1289	int ret=0;
1290        struct r8180_priv *priv = ieee80211_priv(dev);
1291
1292
1293	if(priv->ieee80211->bHwRadioOff)
1294		return 0;
1295
1296        down(&priv->wx_sem);
1297        ret = ieee80211_wx_set_gen_ie(priv->ieee80211, extra, wrqu->data.length);
1298        up(&priv->wx_sem);
1299	//printk("<======%s(), ret:%d\n", __func__, ret);
1300        return ret;
1301
1302
1303}
1304static iw_handler r8180_wx_handlers[] =
1305{
1306        NULL,                     /* SIOCSIWCOMMIT */
1307        r8180_wx_get_name,   	  /* SIOCGIWNAME */
1308        dummy,                    /* SIOCSIWNWID */
1309        dummy,                    /* SIOCGIWNWID */
1310        r8180_wx_set_freq,        /* SIOCSIWFREQ */
1311        r8180_wx_get_freq,        /* SIOCGIWFREQ */
1312        r8180_wx_set_mode,        /* SIOCSIWMODE */
1313        r8180_wx_get_mode,        /* SIOCGIWMODE */
1314        r8180_wx_set_sens,        /* SIOCSIWSENS */
1315        r8180_wx_get_sens,        /* SIOCGIWSENS */
1316        NULL,                     /* SIOCSIWRANGE */
1317        rtl8180_wx_get_range,	  /* SIOCGIWRANGE */
1318        NULL,                     /* SIOCSIWPRIV */
1319        NULL,                     /* SIOCGIWPRIV */
1320        NULL,                     /* SIOCSIWSTATS */
1321        NULL,                     /* SIOCGIWSTATS */
1322        dummy,                    /* SIOCSIWSPY */
1323        dummy,                    /* SIOCGIWSPY */
1324        NULL,                     /* SIOCGIWTHRSPY */
1325        NULL,                     /* SIOCWIWTHRSPY */
1326        r8180_wx_set_wap,      	  /* SIOCSIWAP */
1327        r8180_wx_get_wap,         /* SIOCGIWAP */
1328	r8180_wx_set_mlme,        /* SIOCSIWMLME*/
1329        dummy,                    /* SIOCGIWAPLIST -- depricated */
1330        r8180_wx_set_scan,        /* SIOCSIWSCAN */
1331        r8180_wx_get_scan,        /* SIOCGIWSCAN */
1332        r8180_wx_set_essid,       /* SIOCSIWESSID */
1333        r8180_wx_get_essid,       /* SIOCGIWESSID */
1334        dummy,                    /* SIOCSIWNICKN */
1335        dummy,                    /* SIOCGIWNICKN */
1336        NULL,                     /* -- hole -- */
1337        NULL,                     /* -- hole -- */
1338        r8180_wx_set_rate,        /* SIOCSIWRATE */
1339        r8180_wx_get_rate,        /* SIOCGIWRATE */
1340        r8180_wx_set_rts,         /* SIOCSIWRTS */
1341        r8180_wx_get_rts,         /* SIOCGIWRTS */
1342        r8180_wx_set_frag,        /* SIOCSIWFRAG */
1343        r8180_wx_get_frag,        /* SIOCGIWFRAG */
1344        dummy,                    /* SIOCSIWTXPOW */
1345        dummy,                    /* SIOCGIWTXPOW */
1346        r8180_wx_set_retry,       /* SIOCSIWRETRY */
1347        r8180_wx_get_retry,       /* SIOCGIWRETRY */
1348        r8180_wx_set_enc,         /* SIOCSIWENCODE */
1349        r8180_wx_get_enc,         /* SIOCGIWENCODE */
1350        r8180_wx_set_power,       /* SIOCSIWPOWER */
1351        r8180_wx_get_power,       /* SIOCGIWPOWER */
1352        NULL,			  /*---hole---*/
1353	NULL, 			  /*---hole---*/
1354	r8180_wx_set_gen_ie,      /* SIOCSIWGENIE */
1355	NULL, 			  /* SIOCSIWGENIE */
1356	r8180_wx_set_auth,	  /* SIOCSIWAUTH */
1357	NULL,                     /* SIOCSIWAUTH */
1358	r8180_wx_set_enc_ext, 	  /* SIOCSIWENCODEEXT */
1359	NULL,                  	  /* SIOCSIWENCODEEXT */
1360	NULL, 			 /* SIOCSIWPMKSA */
1361	NULL, 			  /*---hole---*/
1362};
1363
1364
1365static const struct iw_priv_args r8180_private_args[] = {
1366	{
1367		SIOCIWFIRSTPRIV + 0x0,
1368		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "badcrc"
1369	},
1370	{	SIOCIWFIRSTPRIV + 0x1,
1371		0, 0, "dummy"
1372
1373	},
1374	{
1375		SIOCIWFIRSTPRIV + 0x2,
1376		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beaconint"
1377	},
1378	{	SIOCIWFIRSTPRIV + 0x3,
1379		0, 0, "dummy"
1380
1381	},
1382	/* added by christian */
1383	//{
1384	//	SIOCIWFIRSTPRIV + 0x2,
1385	//	IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "prismhdr"
1386	//},
1387	/* end added by christian */
1388	{
1389		SIOCIWFIRSTPRIV + 0x4,
1390		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "activescan"
1391
1392	},
1393	{	SIOCIWFIRSTPRIV + 0x5,
1394		0, 0, "dummy"
1395
1396	},
1397	{
1398		SIOCIWFIRSTPRIV + 0x6,
1399		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "rawtx"
1400
1401	},
1402	{	SIOCIWFIRSTPRIV + 0x7,
1403		0, 0, "dummy"
1404
1405	},
1406//	{
1407//		SIOCIWFIRSTPRIV + 0x5,
1408//		0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpsmode"
1409//	},
1410//	{
1411//		SIOCIWFIRSTPRIV + 0x6,
1412//		IW_PRIV_SIZE_FIXED, 0, "setpsmode"
1413//	},
1414//set/get mode have been realized in public handlers
1415
1416	{
1417		SIOCIWFIRSTPRIV + 0x8,
1418		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setiwmode"
1419	},
1420	{
1421		SIOCIWFIRSTPRIV + 0x9,
1422		0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 32, "getiwmode"
1423	},
1424	{
1425		SIOCIWFIRSTPRIV + 0xA,
1426		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setpreamble"
1427	},
1428	{
1429		SIOCIWFIRSTPRIV + 0xB,
1430		0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpreamble"
1431	},
1432	{	SIOCIWFIRSTPRIV + 0xC,
1433		0, 0, "dummy"
1434	},
1435	{
1436		SIOCIWFIRSTPRIV + 0xD,
1437		0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getrssi"
1438	},
1439	{	SIOCIWFIRSTPRIV + 0xE,
1440		0, 0, "dummy"
1441	},
1442	{
1443		SIOCIWFIRSTPRIV + 0xF,
1444		0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getlinkqual"
1445 	},
1446	{
1447		SIOCIWFIRSTPRIV + 0x10,
1448		0, 0, "resetstats"
1449 	},
1450	{
1451		SIOCIWFIRSTPRIV + 0x11,
1452		0,0, "dummy"
1453 	},
1454	{
1455		SIOCIWFIRSTPRIV + 0x12,
1456		0, 0, "radioon"
1457 	},
1458	{
1459		SIOCIWFIRSTPRIV + 0x13,
1460		0, 0, "radiooff"
1461 	},
1462 	{
1463		SIOCIWFIRSTPRIV + 0x14,
1464		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setchannel"
1465 	},
1466	{
1467		SIOCIWFIRSTPRIV + 0x15,
1468		0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getchannel"
1469 	},
1470	{
1471		SIOCIWFIRSTPRIV + 0x16,
1472		0,0, "dummy"
1473 	},
1474	{
1475		SIOCIWFIRSTPRIV + 0x17,
1476		0,IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 32, "getversion"
1477 	},
1478	{
1479		SIOCIWFIRSTPRIV + 0x18,
1480		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setrate"
1481	},
1482};
1483
1484
1485static iw_handler r8180_private_handler[] = {
1486	r8180_wx_set_crcmon,   /*SIOCIWSECONDPRIV*/
1487	dummy,
1488	r8180_wx_set_beaconinterval,
1489	dummy,
1490	//r8180_wx_set_monitor_type,
1491	r8180_wx_set_scan_type,
1492	dummy,
1493	r8180_wx_set_rawtx,
1494	dummy,
1495	r8180_wx_set_iwmode,
1496	r8180_wx_get_iwmode,
1497	r8180_wx_set_preamble,
1498	r8180_wx_get_preamble,
1499	dummy,
1500	r8180_wx_get_siglevel,
1501	dummy,
1502	r8180_wx_get_sigqual,
1503	r8180_wx_reset_stats,
1504	dummy,//r8180_wx_get_stats
1505	r8180_wx_radio_on,
1506	r8180_wx_radio_off,
1507	r8180_wx_set_channelplan,
1508	r8180_wx_get_channelplan,
1509	dummy,
1510	r8180_wx_get_version,
1511	r8180_wx_set_forcerate,
1512};
1513
1514static inline int is_same_network(struct ieee80211_network *src,
1515                                  struct ieee80211_network *dst,
1516				  struct ieee80211_device *ieee)
1517{
1518        /* A network is only a duplicate if the channel, BSSID, ESSID
1519         * and the capability field (in particular IBSS and BSS) all match.
1520         * We treat all <hidden> with the same BSSID and channel
1521         * as one network */
1522        return (((src->ssid_len == dst->ssid_len)||(ieee->iw_mode == IW_MODE_INFRA)) &&  //YJ,mod, 080819,for hidden ap
1523			//((src->ssid_len == dst->ssid_len) &&
1524			(src->channel == dst->channel) &&
1525			!memcmp(src->bssid, dst->bssid, ETH_ALEN) &&
1526			(!memcmp(src->ssid, dst->ssid, src->ssid_len)||(ieee->iw_mode == IW_MODE_INFRA)) &&  //YJ,mod, 080819,for hidden ap
1527			//!memcmp(src->ssid, dst->ssid, src->ssid_len) &&
1528			((src->capability & WLAN_CAPABILITY_IBSS) ==
1529			(dst->capability & WLAN_CAPABILITY_IBSS)) &&
1530			((src->capability & WLAN_CAPABILITY_BSS) ==
1531			(dst->capability & WLAN_CAPABILITY_BSS)));
1532}
1533
1534//WB modefied to show signal to GUI on 18-01-2008
1535static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev)
1536{
1537       struct r8180_priv *priv = ieee80211_priv(dev);
1538	struct ieee80211_device* ieee = priv->ieee80211;
1539	struct iw_statistics* wstats = &priv->wstats;
1540	//struct ieee80211_network* target = NULL;
1541	int tmp_level = 0;
1542	int tmp_qual = 0;
1543	int tmp_noise = 0;
1544	//unsigned long flag;
1545
1546	if (ieee->state < IEEE80211_LINKED)
1547	{
1548		wstats->qual.qual = 0;
1549		wstats->qual.level = 0;
1550		wstats->qual.noise = 0;
1551		wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1552		return wstats;
1553	}
1554
1555	tmp_level = (&ieee->current_network)->stats.signal;
1556	tmp_qual = (&ieee->current_network)->stats.signalstrength;
1557	tmp_noise = (&ieee->current_network)->stats.noise;
1558	//printk("level:%d, qual:%d, noise:%d\n", tmp_level, tmp_qual, tmp_noise);
1559
1560//	printk("level:%d\n", tmp_level);
1561	wstats->qual.level = tmp_level;
1562	wstats->qual.qual = tmp_qual;
1563	wstats->qual.noise = tmp_noise;
1564	wstats->qual.updated = IW_QUAL_ALL_UPDATED| IW_QUAL_DBM;
1565	return wstats;
1566}
1567
1568struct iw_handler_def  r8180_wx_handlers_def={
1569	.standard = r8180_wx_handlers,
1570	.num_standard = ARRAY_SIZE(r8180_wx_handlers),
1571	.private = r8180_private_handler,
1572	.num_private = ARRAY_SIZE(r8180_private_handler),
1573 	.num_private_args = sizeof(r8180_private_args) / sizeof(struct iw_priv_args),
1574	.get_wireless_stats = r8180_get_wireless_stats,
1575	.private_args = (struct iw_priv_args *)r8180_private_args,
1576};
1577