1diff -Naur r8187_orig/ieee80211/ieee80211_crypt.c r8187_rawtx/ieee80211/ieee80211_crypt.c
2--- r8187_orig/ieee80211/ieee80211_crypt.c	2007-01-15 03:00:37.000000000 +0100
3+++ r8187_rawtx/ieee80211/ieee80211_crypt.c	2007-05-16 22:00:07.000000000 +0200
4@@ -11,7 +11,6 @@
5  *
6  */
7
8-#include <linux/config.h>
9 #include <linux/version.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12@@ -19,6 +18,12 @@
13 #include <asm/string.h>
14 #include <asm/errno.h>
15
16+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
17+#include <linux/config.h>
18+#else
19+#include <linux/autoconf.h>
20+#endif
21+
22 #include "ieee80211.h"
23
24 MODULE_AUTHOR("Jouni Malinen");
25diff -Naur r8187_orig/ieee80211/ieee80211_crypt_ccmp.c r8187_rawtx/ieee80211/ieee80211_crypt_ccmp.c
26--- r8187_orig/ieee80211/ieee80211_crypt_ccmp.c	2007-01-15 03:00:37.000000000 +0100
27+++ r8187_rawtx/ieee80211/ieee80211_crypt_ccmp.c	2007-05-16 22:00:07.000000000 +0200
28@@ -9,7 +9,6 @@
29  * more details.
30  */
31
32-#include <linux/config.h>
33 #include <linux/version.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36@@ -22,11 +21,22 @@
37 #include <asm/string.h>
38 #include <linux/wireless.h>
39
40+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
41+#include <linux/config.h>
42+#else
43+#include <linux/autoconf.h>
44+#endif
45+
46 #include "ieee80211.h"
47
48
49 #include <linux/crypto.h>
50-#include <asm/scatterlist.h>
51+
52+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
53+    #include <asm/scatterlist.h>
54+#else
55+    #include <linux/scatterlist.h>
56+#endif
57
58 MODULE_AUTHOR("Jouni Malinen");
59 MODULE_DESCRIPTION("Host AP crypt: CCMP");
60diff -Naur r8187_orig/ieee80211/ieee80211_crypt_tkip.c r8187_rawtx/ieee80211/ieee80211_crypt_tkip.c
61--- r8187_orig/ieee80211/ieee80211_crypt_tkip.c	2007-01-15 03:00:37.000000000 +0100
62+++ r8187_rawtx/ieee80211/ieee80211_crypt_tkip.c	2007-05-16 22:00:07.000000000 +0200
63@@ -9,7 +9,6 @@
64  * more details.
65  */
66
67-#include <linux/config.h>
68 #include <linux/version.h>
69 #include <linux/module.h>
70 #include <linux/init.h>
71@@ -21,11 +20,21 @@
72 #include <linux/if_arp.h>
73 #include <asm/string.h>
74
75+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
76+#include <linux/config.h>
77+#else
78+#include <linux/autoconf.h>
79+#endif
80+
81 #include "ieee80211.h"
82
83+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
84+    #include <asm/scatterlist.h>
85+#else
86+    #include <linux/scatterlist.h>
87+#endif
88
89 #include <linux/crypto.h>
90-#include <asm/scatterlist.h>
91 #include <linux/crc32.h>
92
93 MODULE_AUTHOR("Jouni Malinen");
94@@ -431,7 +440,11 @@
95 static int michael_mic(struct ieee80211_tkip_data *tkey, u8 *key, u8 *hdr,
96 		       u8 *data, size_t data_len, u8 *mic)
97 {
98+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
99+	struct hash_desc desc;
100+#endif
101 	struct scatterlist sg[2];
102+	int ret = 0;
103
104 	if (tkey->tfm_michael == NULL) {
105 		printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
106@@ -445,12 +458,20 @@
107 	sg[1].offset = offset_in_page(data);
108 	sg[1].length = data_len;
109
110+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
111 	crypto_digest_init(tkey->tfm_michael);
112 	crypto_digest_setkey(tkey->tfm_michael, key, 8);
113 	crypto_digest_update(tkey->tfm_michael, sg, 2);
114 	crypto_digest_final(tkey->tfm_michael, mic);
115+#else
116+	if (crypto_hash_setkey(tkey->tfm_michael, key, 8))
117+		return -1;
118+	desc.tfm = tkey->tfm_michael;
119+	desc.flags = 0;
120+	ret = crypto_hash_digest(&desc, sg, data_len + 16, mic);
121+#endif
122
123-	return 0;
124+	return ret;
125 }
126
127 static void michael_mic_hdr(struct sk_buff *skb, u8 *hdr)
128diff -Naur r8187_orig/ieee80211/ieee80211_crypt_wep.c r8187_rawtx/ieee80211/ieee80211_crypt_wep.c
129--- r8187_orig/ieee80211/ieee80211_crypt_wep.c	2007-01-15 03:00:37.000000000 +0100
130+++ r8187_rawtx/ieee80211/ieee80211_crypt_wep.c	2007-05-16 22:00:07.000000000 +0200
131@@ -9,7 +9,6 @@
132  * more details.
133  */
134
135-#include <linux/config.h>
136 #include <linux/version.h>
137 #include <linux/module.h>
138 #include <linux/init.h>
139@@ -18,11 +17,21 @@
140 #include <linux/skbuff.h>
141 #include <asm/string.h>
142
143+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
144+#include <linux/config.h>
145+#else
146+#include <linux/autoconf.h>
147+#endif
148+
149 #include "ieee80211.h"
150
151+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
152+    #include <asm/scatterlist.h>
153+#else
154+    #include <linux/scatterlist.h>
155+#endif
156
157 #include <linux/crypto.h>
158-#include <asm/scatterlist.h>
159 #include <linux/crc32.h>
160
161 MODULE_AUTHOR("Jouni Malinen");
162diff -Naur r8187_orig/ieee80211/ieee80211.h r8187_rawtx/ieee80211/ieee80211.h
163--- r8187_orig/ieee80211/ieee80211.h	2007-12-05 09:27:45.000000000 +0100
164+++ r8187_rawtx/ieee80211/ieee80211.h	2007-05-16 22:00:11.000000000 +0200
165@@ -108,6 +108,8 @@
166 #define	ieee80211_start_protocol	ieee80211_start_protocol_rtl
167 #define	ieee80211_stop_protocol		ieee80211_stop_protocol_rtl
168 #define	ieee80211_rx_mgt		ieee80211_rx_mgt_rtl
169+#define	ieee80211_stop_queue		ieee80211_stop_queue_rtl
170+#define	ieee80211_wake_queue		ieee80211_wake_queue_rtl
171
172
173 typedef struct ieee_param {
174@@ -193,6 +195,22 @@
175 	struct list_head list;
176 };
177
178+#define LWNG_CAP_DID_BASE   (4 | (1 << 6)) /* section 4, group 1 */
179+/* ARPHRD_IEEE80211_PRISM uses a bloated version of Prism2 RX frame header
180+ * (from linux-wlan-ng) */
181+struct linux_wlan_ng_val {
182+	u32 did;
183+	u16 status, len;
184+	u32 data;
185+} __attribute__ ((packed));
186+
187+struct linux_wlan_ng_prism_hdr {
188+	u32 msgcode, msglen;
189+	char devname[16];
190+	struct linux_wlan_ng_val hosttime, mactime, channel, rssi, sq, signal,
191+		noise, rate, istx, frmlen;
192+} __attribute__ ((packed));
193+
194 struct ieee80211_hdr {
195 	u16 frame_ctl;
196 	u16 duration_id;
197@@ -1064,10 +1082,15 @@
198 	struct timer_list beacon_timer;
199
200 	struct work_struct associate_complete_wq;
201+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
202+	struct delayed_work associate_retry_wq;
203+	struct delayed_work softmac_scan_wq;
204+#else
205 	struct work_struct associate_retry_wq;
206+	struct work_struct softmac_scan_wq;
207+#endif
208 	struct work_struct start_ibss_wq;
209 	struct work_struct associate_procedure_wq;
210-	struct work_struct softmac_scan_wq;
211 	struct work_struct wx_sync_scan_wq;
212 	struct work_struct ps_request_tx_ack_wq;//for ps
213 	struct work_struct hw_wakeup_wq;
214@@ -1390,7 +1413,11 @@
215 extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
216 			     union iwreq_data *wrqu, char *b);
217
218+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
219+extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
220+#else
221 extern void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee);
222+#endif
223
224 extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
225 			       struct iw_request_info *info,
226diff -Naur r8187_orig/ieee80211/ieee80211_module.c r8187_rawtx/ieee80211/ieee80211_module.c
227--- r8187_orig/ieee80211/ieee80211_module.c	2007-12-03 10:07:33.000000000 +0100
228+++ r8187_rawtx/ieee80211/ieee80211_module.c	2007-05-16 22:00:07.000000000 +0200
229@@ -31,7 +31,6 @@
230 *******************************************************************************/
231
232 #include <linux/compiler.h>
233-#include <linux/config.h>
234 #include <linux/errno.h>
235 #include <linux/if_arp.h>
236 #include <linux/in6.h>
237@@ -52,6 +51,12 @@
238 #include <asm/uaccess.h>
239 #include <net/arp.h>
240
241+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
242+#include <linux/config.h>
243+#else
244+#include <linux/autoconf.h>
245+#endif
246+
247 #include "ieee80211.h"
248
249 MODULE_DESCRIPTION("802.11 data/management/control stack");
250diff -Naur r8187_orig/ieee80211/ieee80211_rx.c r8187_rawtx/ieee80211/ieee80211_rx.c
251--- r8187_orig/ieee80211/ieee80211_rx.c	2007-01-15 03:00:37.000000000 +0100
252+++ r8187_rawtx/ieee80211/ieee80211_rx.c	2007-05-16 22:00:07.000000000 +0200
253@@ -22,7 +22,6 @@
254
255
256 #include <linux/compiler.h>
257-#include <linux/config.h>
258 #include <linux/errno.h>
259 #include <linux/if_arp.h>
260 #include <linux/in6.h>
261@@ -43,18 +42,85 @@
262 #include <asm/uaccess.h>
263 #include <linux/ctype.h>
264
265+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
266+#include <linux/config.h>
267+#else
268+#include <linux/autoconf.h>
269+#endif
270+
271 #include "ieee80211.h"
272
273 static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
274 					struct sk_buff *skb,
275 					struct ieee80211_rx_stats *rx_stats)
276 {
277-	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
278-	u16 fc = le16_to_cpu(hdr->frame_ctl);
279+	struct ieee80211_hdr *hdr1 = (struct ieee80211_hdr *)skb->data;
280+	u16 fc = le16_to_cpu(hdr1->frame_ctl);
281+//begin prism header code
282+	int prism_header;
283+	int hdrlen, phdrlen, head_need, tail_need;
284+
285+	if (ieee->dev->type == ARPHRD_IEEE80211_PRISM) {
286+		prism_header = 1;
287+		phdrlen = sizeof(struct linux_wlan_ng_prism_hdr);
288+	} else {
289+		prism_header = 0;
290+		phdrlen = 0;
291+	}
292
293+	hdrlen = ieee80211_get_hdrlen(fc);
294+
295+	/* check if there is enough room for extra data; if not, expand skb
296+	 * buffer to be large enough for the changes */
297+	head_need = phdrlen;
298+	tail_need = 0;
299+#ifdef PRISM2_ADD_BOGUS_CRC
300+	tail_need += 4;
301+#endif /* PRISM2_ADD_BOGUS_CRC */
302+
303+	head_need -= skb_headroom(skb);
304+	tail_need -= skb_tailroom(skb);
305+
306+	if (head_need > 0 || tail_need > 0) {
307+		if (pskb_expand_head(skb, head_need > 0 ? head_need : 0,
308+				     tail_need > 0 ? tail_need : 0,
309+				     GFP_ATOMIC)) {
310+			printk(KERN_DEBUG "%s: ieee80211_rx failed to "
311+			       "reallocate skb buffer\n", ieee->dev->name);
312+			dev_kfree_skb_any(skb);
313+			return;
314+		}
315+	}
316+
317+	if (prism_header == 1) {
318+		struct linux_wlan_ng_prism_hdr *hdr;
319+		hdr = (struct linux_wlan_ng_prism_hdr *)
320+			skb_push(skb, phdrlen);
321+		memset(hdr, 0, phdrlen);
322+		hdr->msgcode = LWNG_CAP_DID_BASE;
323+		hdr->msglen = sizeof(*hdr);
324+		memcpy(hdr->devname, ieee->dev->name, sizeof(hdr->devname));
325+#define LWNG_SETVAL(f,i,s,l,d) \
326+hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \
327+hdr->f.status = s; hdr->f.len = l; hdr->f.data = d
328+		LWNG_SETVAL(hosttime, 1, 0, 4, jiffies);
329+		LWNG_SETVAL(mactime, 2, 0, 4, ((u32)rx_stats->mac_time));
330+		LWNG_SETVAL(channel, 3, 1 /* no value */, 4, 0);
331+		LWNG_SETVAL(rssi, 4, 1 /* no value */, 4, 0);
332+		LWNG_SETVAL(sq, 5, 1 /* no value */, 4, 0);
333+		LWNG_SETVAL(signal, 6, 0, 4, rx_stats->signal);
334+		LWNG_SETVAL(noise, 7, 0, 4, rx_stats->noise);
335+		LWNG_SETVAL(rate, 8, 0, 4, rx_stats->rate / 5);
336+		LWNG_SETVAL(istx, 9, 0, 4, 0);
337+		LWNG_SETVAL(frmlen, 10, 0, 4, skb->len - phdrlen);
338+#undef LWNG_SETVAL
339+	}
340+//end prism header code
341 	skb->dev = ieee->dev;
342 	skb->mac.raw = skb->data;
343-	skb_pull(skb, ieee80211_get_hdrlen(fc));
344+	skb_pull(skb, hdrlen);
345+	if (prism_header)
346+		skb_pull(skb, phdrlen);
347 	skb->pkt_type = PACKET_OTHERHOST;
348 	skb->protocol = __constant_htons(ETH_P_80211_RAW);
349 	memset(skb->cb, 0, sizeof(skb->cb));
350diff -Naur r8187_orig/ieee80211/ieee80211_softmac.c r8187_rawtx/ieee80211/ieee80211_softmac.c
351--- r8187_orig/ieee80211/ieee80211_softmac.c	2007-12-05 09:26:56.000000000 +0100
352+++ r8187_rawtx/ieee80211/ieee80211_softmac.c	2007-05-16 22:00:07.000000000 +0200
353@@ -1,14 +1,14 @@
354 /* IEEE 802.11 SoftMAC layer
355  * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
356  *
357- * Mostly extracted from the rtl8180-sa2400 driver for the
358+ * Mostly extracted from the rtl8180-sa2400 driver for the
359  * in-kernel generic ieee802.11 stack.
360  *
361  * Few lines might be stolen from other part of the ieee80211
362  * stack. Copyright who own it's copyright
363  *
364  * WPA code stolen from the ipw2200 driver.
365- * Copyright who own it's copyright.
366+ * Copyright who own it's copyright.
367  *
368  * released under the GPL
369  */
370@@ -37,25 +37,25 @@
371 unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device *ieee)
372 {
373 	unsigned int rate_len = 0;
374-
375+
376 	if (ieee->modulation & IEEE80211_CCK_MODULATION)
377 		rate_len = IEEE80211_CCK_RATE_LEN + 2;
378-
379+
380 	if (ieee->modulation & IEEE80211_OFDM_MODULATION)
381-
382+
383 		rate_len += IEEE80211_OFDM_RATE_LEN + 2;
384-
385+
386 	return rate_len;
387 }
388
389-/* pleace the MFIE rate, tag to the memory (double) poined.
390+/* pleace the MFIE rate, tag to the memory (double) poined.
391  * Then it updates the pointer so that
392  * it points after the new MFIE tag added.
393- */
394+ */
395 void ieee80211_MFIE_Brate(struct ieee80211_device *ieee, u8 **tag_p)
396 {
397-	u8 *tag = *tag_p;
398-
399+	u8 *tag = *tag_p;
400+
401 	if (ieee->modulation & IEEE80211_CCK_MODULATION){
402 		*tag++ = MFIE_TYPE_RATES;
403 		*tag++ = 4;
404@@ -64,17 +64,17 @@
405 		*tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
406 		*tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
407 	}
408-
409+
410 	/* We may add an option for custom rates that specific HW might support */
411 	*tag_p = tag;
412 }
413
414 void ieee80211_MFIE_Grate(struct ieee80211_device *ieee, u8 **tag_p)
415-{
416-	u8 *tag = *tag_p;
417-
418+{
419+	u8 *tag = *tag_p;
420+
421 		if (ieee->modulation & IEEE80211_OFDM_MODULATION){
422-
423+
424 		*tag++ = MFIE_TYPE_RATES_EX;
425 		*tag++ = 8;
426 		*tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
427@@ -85,9 +85,9 @@
428 		*tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
429 		*tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
430 		*tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
431-
432+
433 	}
434-
435+
436 	/* We may add an option for custom rates that specific HW might support */
437 	*tag_p = tag;
438 }
439@@ -96,11 +96,11 @@
440 {
441 	int nh;
442 	nh = (ieee->mgmt_queue_head +1) % MGMT_QUEUE_NUM;
443-
444+
445 /*
446  * if the queue is full but we have newer frames then
447  * just overwrites the oldest.
448- *
449+ *
450  * if (nh == ieee->mgmt_queue_tail)
451  *		return -1;
452  */	//david, 2007.1.23
453@@ -110,22 +110,22 @@
454 		ieee->mgmt_queue_head = nh;
455 		ieee->mgmt_queue_ring[nh] = skb;
456 	}
457-
458+
459 	//return 0;
460 }
461
462 struct sk_buff *dequeue_mgmt(struct ieee80211_device *ieee)
463 {
464 	struct sk_buff *ret;
465-
466+
467 	if(ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
468 		return NULL;
469-
470+
471 	ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
472-
473-	ieee->mgmt_queue_tail =
474+
475+	ieee->mgmt_queue_tail =
476 		(ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
477-
478+
479 	return ret;
480 }
481
482@@ -143,19 +143,19 @@
483 	short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
484 	struct ieee80211_hdr_3addr  *header=
485 		(struct ieee80211_hdr_3addr  *) skb->data;
486-
487-
488+
489+
490 	spin_lock_irqsave(&ieee->lock, flags);
491-
492+
493 	/* called with 2nd param 0, no mgmt lock required */
494 	ieee80211_sta_wakeup(ieee,0);
495-
496+
497 	if(single){
498-
499+
500 		if(ieee->queue_stop){
501-
502+
503 			enqueue_mgmt(ieee,skb);
504-
505+
506 		}else{
507 			header->seq_ctl = cpu_to_le16(ieee->seq_ctrl << 4);
508
509@@ -163,28 +163,28 @@
510 				ieee->seq_ctrl = 0;
511 			else
512 				ieee->seq_ctrl++;
513-
514+
515 			/* avoid watchdog triggers */
516 			ieee->dev->trans_start = jiffies;
517 			ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
518 			//added by david, 2007.1.23
519 			dev_kfree_skb_any(skb);
520 		}
521-
522+
523 		spin_unlock_irqrestore(&ieee->lock, flags);
524 	}else{
525 		spin_unlock_irqrestore(&ieee->lock, flags);
526 		spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
527-
528+
529 		header->seq_ctl = cpu_to_le16(ieee->seq_ctrl << 4);
530-
531+
532 		if (ieee->seq_ctrl == 0xFFF)
533 			ieee->seq_ctrl = 0;
534 		else
535 			ieee->seq_ctrl++;
536-
537+
538 		ieee->softmac_hard_start_xmit(skb,ieee->dev);
539-
540+
541 		spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
542 	}
543 }
544@@ -192,36 +192,36 @@
545
546 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
547 {
548-
549+
550 	short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
551 	struct ieee80211_hdr_3addr  *header =
552 		(struct ieee80211_hdr_3addr  *) skb->data;
553-
554-
555+
556+
557 	if(single){
558-
559+
560 		header->seq_ctl = cpu_to_le16(ieee->seq_ctrl << 4);
561
562 		if (ieee->seq_ctrl == 0xFFF)
563 			ieee->seq_ctrl = 0;
564 		else
565 			ieee->seq_ctrl++;
566-
567+
568 		/* avoid watchdog triggers */
569 		ieee->dev->trans_start = jiffies;
570 		ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
571-
572+
573 	}else{
574-
575+
576 		header->seq_ctl = cpu_to_le16(ieee->seq_ctrl << 4);
577-
578+
579 		if (ieee->seq_ctrl == 0xFFF)
580 			ieee->seq_ctrl = 0;
581 		else
582 			ieee->seq_ctrl++;
583
584 		ieee->softmac_hard_start_xmit(skb,ieee->dev);
585-
586+
587 	}
588 }
589
590@@ -231,35 +231,35 @@
591 	u8 *tag;
592 	struct sk_buff *skb;
593 	struct ieee80211_probe_request *req;
594-
595+
596 	len = ieee->current_network.ssid_len;
597-
598+
599 	rate_len = ieee80211_MFIE_rate_len(ieee);
600-
601+
602 	skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
603 			    2 + len + rate_len);
604-
605-	if (!skb)
606+
607+	if (!skb)
608 		return NULL;
609-
610+
611 	req = (struct ieee80211_probe_request *) skb_put(skb,sizeof(struct ieee80211_probe_request));
612-	if (ieee->ps == IEEE80211_PS_DISABLED)
613+	if (ieee->ps == IEEE80211_PS_DISABLED)
614 		req->header.frame_ctl = IEEE80211_STYPE_PROBE_REQ;//changed!!
615-	else
616+	else
617 		req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ|IEEE80211_FCTL_PM);//tony ,for ps ctl bit
618-	req->header.duration_id = 0; //FIXME: is this OK ?
619-
620+	req->header.duration_id = 0; //FIXME: is this OK ?
621+
622 	memset(req->header.addr1, 0xff, ETH_ALEN);
623 	memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
624 	memset(req->header.addr3, 0xff, ETH_ALEN);
625-
626+
627 	tag = (u8 *) skb_put(skb,len+2+rate_len);
628-
629+
630 	*tag++ = MFIE_TYPE_SSID;
631 	*tag++ = len;
632 	memcpy(tag, ieee->current_network.ssid, len);
633 	tag += len;
634-
635+
636 	ieee80211_MFIE_Brate(ieee,&tag);
637 	ieee80211_MFIE_Grate(ieee,&tag);
638 	return skb;
639@@ -269,18 +269,18 @@
640 void ieee80211_send_beacon(struct ieee80211_device *ieee)
641 {
642 	struct sk_buff *skb;
643-
644-	unsigned long flags;
645-
646+
647+	unsigned long flags;
648+
649 	skb = ieee80211_get_beacon_(ieee);
650 	if (skb){
651 		softmac_mgmt_xmit(skb, ieee);
652 		ieee->softmac_stats.tx_beacons++;
653 	}
654
655-	ieee->beacon_timer.expires = jiffies +
656+	ieee->beacon_timer.expires = jiffies +
657 		(MSECS( ieee->current_network.beacon_interval -5));
658-
659+
660 	spin_lock_irqsave(&ieee->beacon_lock,flags);
661 	if(ieee->beacon_txing)
662 		add_timer(&ieee->beacon_timer);
663@@ -299,7 +299,7 @@
664 void ieee80211_send_probe(struct ieee80211_device *ieee)
665 {
666 	struct sk_buff *skb;
667-
668+
669 	skb = ieee80211_probe_req(ieee);
670 	if (skb){
671 		softmac_mgmt_xmit(skb, ieee);
672@@ -316,29 +316,29 @@
673 }
674
675 /* this performs syncro scan blocking the caller until all channels
676- * in the allowed channel map has been checked.
677+ * in the allowed channel map has been checked.
678  */
679 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
680 {
681 	short ch = 0;
682-
683+
684 	down(&ieee->scan_sem);
685-
686+
687 	while(1)
688 	{
689-
690+
691 		do{
692 			ch++;
693-			if (ch > MAX_CHANNEL_NUMBER)
694+			if (ch > MAX_CHANNEL_NUMBER)
695 				goto out; /* scan completed */
696-
697+
698 		}while(!ieee->channel_map[ch]);
699-
700+
701 		/* this fuction can be called in two situations
702 		 * 1- We have switched to ad-hoc mode and we are
703 		 *    performing a complete syncro scan before conclude
704-		 *    there are no interesting cell and to create a
705-		 *    new one. In this case the link state is
706+		 *    there are no interesting cell and to create a
707+		 *    new one. In this case the link state is
708 		 *    IEEE80211_NOLINK until we found an interesting cell.
709 		 *    If so the ieee8021_new_net, called by the RX path
710 		 *    will set the state to IEEE80211_LINKED, so we stop
711@@ -351,24 +351,24 @@
712 		 *    not filter RX frames and the channel is changing.
713 		 * So the only situation in witch are interested is to check
714 		 * if the state become LINKED because of the #1 situation
715-		 */
716-
717+		 */
718+
719 		if (ieee->state == IEEE80211_LINKED)
720 			goto out;
721-
722+
723 		ieee->set_chan(ieee->dev, ch);
724 	//	printk(KERN_INFO "current probe channel is %d!\n",ch);
725 		ieee80211_send_probe_requests(ieee);
726-
727+
728 		/* this prevent excessive time wait when we
729 		 * need to wait for a syncro scan to end..
730-		 */
731+		 */
732 		if (ieee->sync_scan_hurryup)
733 			goto out;
734
735
736 		msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
737-
738+
739 	}
740 out:
741 	ieee->sync_scan_hurryup = 0;
742@@ -379,43 +379,50 @@
743 void ieee80211_softmac_scan(struct ieee80211_device *ieee)
744 {
745 	short watchdog = 0;
746-
747+
748 	do{
749-		ieee->current_network.channel =
750+		ieee->current_network.channel =
751 			(ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
752-		if (watchdog++ > MAX_CHANNEL_NUMBER)
753+		if (watchdog++ > MAX_CHANNEL_NUMBER)
754 				return; /* no good chans */
755-
756+
757 	}while(!ieee->channel_map[ieee->current_network.channel]);
758-
759+
760
761 	schedule_work(&ieee->softmac_scan_wq);
762 }
763 #endif
764
765+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
766+void ieee80211_softmac_scan_wq(struct work_struct *work)
767+{
768+	struct delayed_work *dwork = container_of(work, struct delayed_work, work);
769+	struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
770+#else
771 void ieee80211_softmac_scan_wq(struct ieee80211_device *ieee)
772-{
773+{
774+#endif
775 	short watchdog = 0;
776 	down(&ieee->scan_sem);
777-
778-
779+
780+
781 	do{
782-		ieee->current_network.channel =
783+		ieee->current_network.channel =
784 			(ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
785-		if (watchdog++ > MAX_CHANNEL_NUMBER)
786+		if (watchdog++ > MAX_CHANNEL_NUMBER)
787 				goto out; /* no good chans */
788-
789+
790 	}while(!ieee->channel_map[ieee->current_network.channel]);
791-
792+
793 	if (ieee->scanning == 0 )
794 		goto out;
795-
796+
797 	ieee->set_chan(ieee->dev, ieee->current_network.channel);
798 	ieee80211_send_probe_requests(ieee);
799
800-#if 0
801+#if 0
802 	ieee->.expires = jiffies + (IEEE80211_SOFTMAC_SCAN_TIME);
803-	if (ieee->scanning == 1)
804+	if (ieee->scanning == 1)
805 		add_timer(&ieee->scan_timer);
806 #endif
807 	queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
808@@ -428,7 +435,7 @@
809 {
810 	unsigned long flags;
811 	struct ieee80211_device *ieee = (struct ieee80211_device *)_dev;
812-
813+
814 	spin_lock_irqsave(&ieee->lock, flags);
815 	ieee80211_softmac_scan(ieee);
816 	spin_unlock_irqrestore(&ieee->lock, flags);
817@@ -438,13 +445,13 @@
818
819 void ieee80211_beacons_start(struct ieee80211_device *ieee)
820 {
821-	unsigned long flags;
822+	unsigned long flags;
823
824 	spin_lock_irqsave(&ieee->beacon_lock,flags);
825
826 	ieee->beacon_txing = 1;
827 	ieee80211_send_beacon(ieee);
828-
829+
830 	spin_unlock_irqrestore(&ieee->beacon_lock,flags);
831 }
832
833@@ -476,25 +483,25 @@
834 	if(ieee->start_send_beacons)
835 		ieee->start_send_beacons(ieee->dev);
836 	if(ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
837-		ieee80211_beacons_start(ieee);
838+		ieee80211_beacons_start(ieee);
839 }
840
841
842 void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
843 {
844-//	unsigned long flags;
845-
846+//	unsigned long flags;
847+
848 	//ieee->sync_scan_hurryup = 1;
849-
850+
851 	down(&ieee->scan_sem);
852 //	spin_lock_irqsave(&ieee->lock, flags);
853-
854+
855 	if (ieee->scanning == 1){
856 		ieee->scanning = 0;
857 		//del_timer_sync(&ieee->scan_timer);
858 		cancel_delayed_work(&ieee->softmac_scan_wq);
859 	}
860-
861+
862 //	spin_unlock_irqrestore(&ieee->lock, flags);
863 	up(&ieee->scan_sem);
864 }
865@@ -510,62 +517,66 @@
866 /* called with ieee->lock held */
867 void ieee80211_start_scan(struct ieee80211_device *ieee)
868 {
869-	if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
870+	if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
871 		if (ieee->scanning == 0){
872 			ieee->scanning = 1;
873 			//ieee80211_softmac_scan(ieee);
874+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
875 			queue_work(ieee->wq, &ieee->softmac_scan_wq);
876+#else
877+			queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, 0);
878+#endif
879 		}
880 	}else
881 		ieee->start_scan(ieee->dev);
882-
883+
884 }
885
886 /* called with wx_sem held */
887 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
888 {
889 	ieee->sync_scan_hurryup = 0;
890-
891+
892 	if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
893 		ieee80211_softmac_scan_syncro(ieee);
894 	else
895 		ieee->scan_syncro(ieee->dev);
896-
897+
898 }
899
900-inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
901+inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
902 	struct ieee80211_device *ieee, int challengelen)
903 {
904-	struct sk_buff *skb;
905+	struct sk_buff *skb;
906 	struct ieee80211_authentication *auth;
907-
908-	skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
909-
910+
911+	skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
912+
913 	if (!skb) return NULL;
914-
915+
916 	auth = (struct ieee80211_authentication *)
917 		skb_put(skb, sizeof(struct ieee80211_authentication));
918-
919+
920 	auth->header.frame_ctl = IEEE80211_STYPE_AUTH;
921 	if (challengelen) auth->header.frame_ctl |= IEEE80211_FCTL_WEP;
922 	if (ieee->ps != IEEE80211_PS_DISABLED) auth->header.frame_ctl |= IEEE80211_FCTL_PM;//tony 060624
923
924-
925+
926 	auth->header.duration_id = 0x013a; //FIXME
927-
928+
929 	memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
930 	memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
931 	memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
932-
933+
934 	auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
935-
936+
937 	auth->transaction = cpu_to_le16(ieee->associate_seq);
938 	ieee->associate_seq++;
939-
940+
941 	auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
942-
943+
944 	return skb;
945-
946+
947 }
948
949 static struct sk_buff* ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *dest)
950@@ -577,23 +588,23 @@
951 	int encrypt;
952 	int atim_len,erp_len;
953 	struct ieee80211_crypt_data* crypt;
954-
955+
956 	char *ssid = ieee->current_network.ssid;
957 	int ssid_len = ieee->current_network.ssid_len;
958 	int rate_len = ieee->current_network.rates_len+2;
959 	int rate_ex_len = ieee->current_network.rates_ex_len;
960 	if(rate_ex_len > 0) rate_ex_len+=2;
961-
962+
963 	if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
964 		atim_len = 4;
965 	else
966 		atim_len = 0;
967-
968-	if(ieee80211_is_54g(ieee->current_network))
969+
970+	if(ieee80211_is_54g(ieee->current_network))
971 		erp_len = 3;
972 	else
973 		erp_len = 0;
974-
975+
976 	beacon_size = sizeof(struct ieee80211_probe_response)+
977 		ssid_len
978 		+3 //channel
979@@ -601,72 +612,72 @@
980 		+rate_ex_len
981 		+atim_len
982 		+erp_len;
983-
984+
985 	skb = dev_alloc_skb(beacon_size);
986-
987-	if (!skb)
988+
989+	if (!skb)
990 		return NULL;
991-
992+
993 	beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
994-
995+
996 	memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
997 	memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
998 	memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
999
1000 	beacon_buf->header.duration_id = 0; //FIXME
1001-	beacon_buf->beacon_interval =
1002+	beacon_buf->beacon_interval =
1003 		cpu_to_le16(ieee->current_network.beacon_interval);
1004-	beacon_buf->capability =
1005+	beacon_buf->capability =
1006 		cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
1007-
1008+
1009 	if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
1010-		cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
1011-
1012+		cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
1013+
1014 	crypt = ieee->crypt[ieee->tx_keyidx];
1015
1016-	encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1017+	encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1018 		(0 == strcmp(crypt->ops->name, "WEP"));
1019
1020-	if (encrypt)
1021+	if (encrypt)
1022 		beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1023-
1024-
1025+
1026+
1027 	beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
1028-
1029-	beacon_buf->info_element.id = MFIE_TYPE_SSID;
1030+
1031+	beacon_buf->info_element.id = MFIE_TYPE_SSID;
1032 	beacon_buf->info_element.len = ssid_len;
1033-
1034+
1035 	tag = (u8*) beacon_buf->info_element.data;
1036-
1037+
1038 	memcpy(tag, ssid, ssid_len);
1039-
1040+
1041 	tag += ssid_len;
1042-
1043+
1044 	*(tag++) = MFIE_TYPE_RATES;
1045-	*(tag++) = rate_len-2;
1046+	*(tag++) = rate_len-2;
1047 	memcpy(tag,ieee->current_network.rates,rate_len-2);
1048 	tag+=rate_len-2;
1049-
1050+
1051 	*(tag++) = MFIE_TYPE_DS_SET;
1052 	*(tag++) = 1;
1053 	*(tag++) = ieee->current_network.channel;
1054-
1055+
1056 	if(atim_len){
1057 		*(tag++) = MFIE_TYPE_IBSS_SET;
1058 		*(tag++) = 2;
1059 		*((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window);
1060 		tag+=2;
1061 	}
1062-
1063+
1064 	if(erp_len){
1065 		*(tag++) = MFIE_TYPE_ERP;
1066 		*(tag++) = 1;
1067-		*(tag++) = 0;
1068+		*(tag++) = 0;
1069 	}
1070-
1071+
1072 	if(rate_ex_len){
1073 		*(tag++) = MFIE_TYPE_RATES_EX;
1074-		*(tag++) = rate_ex_len-2;
1075+		*(tag++) = rate_ex_len-2;
1076 		memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
1077 		tag+=rate_ex_len-2;
1078 	}
1079@@ -679,52 +690,52 @@
1080 {
1081 	struct sk_buff *skb;
1082 	u8* tag;
1083-
1084+
1085 	struct ieee80211_crypt_data* crypt;
1086 	struct ieee80211_assoc_response_frame *assoc;
1087 	short encrypt;
1088-
1089+
1090 	unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1091 	int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
1092-
1093-	skb = dev_alloc_skb(len);
1094-
1095-	if (!skb)
1096+
1097+	skb = dev_alloc_skb(len);
1098+
1099+	if (!skb)
1100 		return NULL;
1101-
1102+
1103 	assoc = (struct ieee80211_assoc_response_frame *)
1104 		skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
1105-
1106+
1107 	assoc->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP);
1108 	memcpy(assoc->header.addr1, dest,ETH_ALEN);
1109 	memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1110 	memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1111-	assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1112+	assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1113 		WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
1114-
1115-
1116+
1117+
1118 	if(ieee->short_slot)
1119 		assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1120-
1121+
1122 	if (ieee->host_encrypt)
1123 		crypt = ieee->crypt[ieee->tx_keyidx];
1124 	else crypt = NULL;
1125-
1126+
1127 	encrypt = ( crypt && crypt->ops);
1128-
1129+
1130 	if (encrypt)
1131 		assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1132-
1133+
1134 	assoc->status = 0;
1135 	assoc->aid = cpu_to_le16(ieee->assoc_id);
1136 	if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
1137 	else ieee->assoc_id++;
1138-
1139+
1140 	tag = (u8*) skb_put(skb, rate_len);
1141-
1142+
1143 	ieee80211_MFIE_Brate(ieee, &tag);
1144 	ieee80211_MFIE_Grate(ieee, &tag);
1145-
1146+
1147 	return skb;
1148 }
1149
1150@@ -732,59 +743,59 @@
1151 {
1152 	struct sk_buff *skb;
1153 	struct ieee80211_authentication *auth;
1154-
1155-	skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
1156-
1157-	if (!skb)
1158+
1159+	skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
1160+
1161+	if (!skb)
1162 		return NULL;
1163-
1164+
1165 	skb->len = sizeof(struct ieee80211_authentication);
1166-
1167+
1168 	auth = (struct ieee80211_authentication *)skb->data;
1169-
1170+
1171 	auth->status = cpu_to_le16(status);
1172 	auth->transaction = cpu_to_le16(2);
1173 	auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1174-
1175+
1176 	memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1177 	memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1178 	memcpy(auth->header.addr1, dest, ETH_ALEN);
1179-	auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
1180+	auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
1181 	return skb;
1182-
1183-
1184+
1185+
1186 }
1187
1188 struct sk_buff* ieee80211_null_func(struct ieee80211_device *ieee,short pwr)
1189 {
1190 	struct sk_buff *skb;
1191 	struct ieee80211_hdr_3addr* hdr;
1192-
1193-	skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
1194-
1195-	if (!skb)
1196+
1197+	skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
1198+
1199+	if (!skb)
1200 		return NULL;
1201-
1202+
1203 	hdr = (struct ieee80211_hdr_3addr*)skb_put(skb,sizeof(struct ieee80211_hdr_3addr));
1204-
1205+
1206 	memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1207 	memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1208 	memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1209-
1210-	hdr->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
1211-		IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
1212-		(pwr ? IEEE80211_FCTL_PM:0));
1213-
1214+
1215+	hdr->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
1216+		IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
1217+		(pwr ? IEEE80211_FCTL_PM:0));
1218+
1219 	return skb;
1220-
1221-
1222+
1223+
1224 }
1225
1226
1227 void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8* dest)
1228 {
1229 	struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest);
1230-
1231+
1232 	if (buf)
1233 		softmac_mgmt_xmit(buf, ieee);
1234 }
1235@@ -793,7 +804,7 @@
1236 void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8* dest)
1237 {
1238 	struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest);
1239-
1240+
1241 	if (buf)
1242 		softmac_mgmt_xmit(buf, ieee);
1243 }
1244@@ -801,10 +812,10 @@
1245
1246 void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest)
1247 {
1248-
1249+
1250 	struct sk_buff *buf = ieee80211_probe_resp(ieee, dest);
1251-
1252-	if (buf)
1253+
1254+	if (buf)
1255 		softmac_mgmt_xmit(buf, ieee);
1256 }
1257
1258@@ -812,72 +823,72 @@
1259 inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beacon,struct ieee80211_device *ieee)
1260 {
1261 	struct sk_buff *skb;
1262-
1263+
1264 	struct ieee80211_assoc_request_frame *hdr;
1265 	u8 *tag;
1266-
1267+
1268 	unsigned int wpa_len = beacon->wpa_ie_len;
1269 	unsigned int rsn_len = beacon->rsn_ie_len;
1270-
1271+
1272 	unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1273-
1274-
1275-
1276+
1277+
1278+
1279 	int len=sizeof(struct ieee80211_assoc_request_frame)+
1280 				+ beacon->ssid_len//essid tagged val
1281 				+ rate_len//rates tagged val
1282 				+ rsn_len
1283 				+ wpa_len;
1284-
1285+
1286 	skb = dev_alloc_skb(len);
1287-
1288-	if (!skb)
1289+
1290+	if (!skb)
1291 		return NULL;
1292-
1293+
1294 	hdr = (struct ieee80211_assoc_request_frame *)
1295 		skb_put(skb, sizeof(struct ieee80211_assoc_request_frame));
1296-
1297-
1298+
1299+
1300 	hdr->header.frame_ctl = IEEE80211_STYPE_ASSOC_REQ;
1301 	if (ieee->ps != IEEE80211_PS_DISABLED) hdr->header.frame_ctl |= IEEE80211_FCTL_PM; //tony
1302 	hdr->header.duration_id= 37; //FIXME
1303 	memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1304 	memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1305 	memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1306-
1307+
1308 	hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS);
1309-	if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1310+	if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1311 		hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1312 	if(beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1313 		hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); //tony 20060606
1314-
1315+
1316 	if(ieee->short_slot)
1317 		hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1318-
1319+
1320 	hdr->listen_interval = 0xa; //FIXME
1321-
1322+
1323 	hdr->info_element.id = MFIE_TYPE_SSID;
1324
1325 	hdr->info_element.len = beacon->ssid_len;
1326 	tag = skb_put(skb, beacon->ssid_len);
1327 	memcpy(tag, beacon->ssid, beacon->ssid_len);
1328-
1329-	tag = skb_put(skb, rate_len);
1330-
1331+
1332+	tag = skb_put(skb, rate_len);
1333+
1334 	ieee80211_MFIE_Brate(ieee, &tag);
1335 	ieee80211_MFIE_Grate(ieee, &tag);
1336-
1337+
1338 	tag = skb_put(skb,wpa_len);
1339-
1340+
1341 	if(wpa_len) {
1342 		if(wpa_len > (22 + 2) )
1343 		{
1344 			beacon->wpa_ie[wpa_len - 2] = 0;
1345 		}
1346-
1347+
1348 	}
1349 	memcpy(tag,beacon->wpa_ie,wpa_len);
1350-
1351+
1352 	tag = skb_put(skb,rsn_len);
1353
1354 	if(rsn_len) {
1355@@ -890,12 +901,12 @@
1356
1357 void ieee80211_associate_abort(struct ieee80211_device *ieee)
1358 {
1359-
1360+
1361 	unsigned long flags;
1362 	spin_lock_irqsave(&ieee->lock, flags);
1363-
1364+
1365 	ieee->associate_seq++;
1366-
1367+
1368 	/* don't scan, and avoid to have the RX path possibily
1369 	 * try again to associate. Even do not react to AUTH or
1370 	 * ASSOC response. Just wait for the retry wq to be scheduled.
1371@@ -903,17 +914,17 @@
1372 	 * with, so we retry or just get back to NO_LINK and scanning
1373 	 */
1374 	if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING){
1375-		IEEE80211_DEBUG_MGMT("Authentication failed\n");
1376+		IEEE80211_DEBUG_MGMT("Authentication failed\n");
1377 		ieee->softmac_stats.no_auth_rs++;
1378 	}else{
1379-		IEEE80211_DEBUG_MGMT("Association failed\n");
1380+		IEEE80211_DEBUG_MGMT("Association failed\n");
1381 		ieee->softmac_stats.no_ass_rs++;
1382 	}
1383-
1384+
1385 	ieee->state = IEEE80211_ASSOCIATING_RETRY;
1386-
1387+
1388 	queue_delayed_work(ieee->wq, &ieee->associate_retry_wq, IEEE80211_SOFTMAC_ASSOC_RETRY_TIME);
1389-
1390+
1391 	spin_unlock_irqrestore(&ieee->lock, flags);
1392 }
1393
1394@@ -927,50 +938,50 @@
1395 {
1396 	struct ieee80211_network *beacon = &ieee->current_network;
1397 	struct sk_buff *skb;
1398-
1399+
1400 	IEEE80211_DEBUG_MGMT("Stopping scan\n");
1401-
1402+
1403 	ieee->softmac_stats.tx_auth_rq++;
1404 	skb=ieee80211_authentication_req(beacon, ieee, 0);
1405-
1406-	if (!skb)
1407+
1408+	if (!skb)
1409 		ieee80211_associate_abort(ieee);
1410-	else{
1411+	else{
1412 		ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
1413 		IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1414 		softmac_mgmt_xmit(skb, ieee);
1415 		ieee->associate_timer.expires = jiffies + (HZ / 2);
1416 		add_timer(&ieee->associate_timer);
1417-	}
1418+	}
1419 }
1420
1421 void ieee80211_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, int chlen)
1422 {
1423-	u8 *c;
1424+	u8 *c;
1425 	struct sk_buff *skb;
1426 	struct ieee80211_network *beacon = &ieee->current_network;
1427 //	int hlen = sizeof(struct ieee80211_authentication);
1428-
1429+
1430 	ieee->associate_seq++;
1431 	ieee->softmac_stats.tx_auth_rq++;
1432-
1433+
1434 	skb = ieee80211_authentication_req(beacon, ieee, chlen+2);
1435-	if (!skb)
1436+	if (!skb)
1437 		ieee80211_associate_abort(ieee);
1438 	else{
1439 		c = skb_put(skb, chlen+2);
1440 		*(c++) = MFIE_TYPE_CHALLENGE;
1441 		*(c++) = chlen;
1442 		memcpy(c, challenge, chlen);
1443-
1444+
1445 		IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1446-
1447+
1448 		ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr  ));
1449-
1450+
1451 		softmac_mgmt_xmit(skb, ieee);
1452 		ieee->associate_timer.expires = jiffies + (HZ / 2);
1453 		add_timer(&ieee->associate_timer);
1454-	}
1455+	}
1456 	kfree(challenge);
1457 }
1458
1459@@ -978,28 +989,34 @@
1460 {
1461 	struct sk_buff* skb;
1462 	struct ieee80211_network *beacon = &ieee->current_network;
1463-
1464+
1465 	del_timer_sync(&ieee->associate_timer);
1466-
1467+
1468 	IEEE80211_DEBUG_MGMT("Sending association request\n");
1469-
1470+
1471 	ieee->softmac_stats.tx_ass_rq++;
1472 	skb=ieee80211_association_req(beacon, ieee);
1473-	if (!skb)
1474+	if (!skb)
1475 		ieee80211_associate_abort(ieee);
1476 	else{
1477 		softmac_mgmt_xmit(skb, ieee);
1478 		ieee->associate_timer.expires = jiffies + (HZ / 2);
1479 		add_timer(&ieee->associate_timer);
1480-	}
1481+	}
1482 }
1483
1484+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
1485+void ieee80211_associate_complete_wq(struct work_struct *work)
1486+{
1487+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq);
1488+#else
1489 void ieee80211_associate_complete_wq(struct ieee80211_device *ieee)
1490 {
1491+#endif
1492 	printk(KERN_INFO "Associated successfully\n");
1493-	if(ieee80211_is_54g(ieee->current_network) &&
1494+	if(ieee80211_is_54g(ieee->current_network) &&
1495 		(ieee->modulation & IEEE80211_OFDM_MODULATION)){
1496-
1497+
1498 		ieee->rate = 540;
1499 		printk(KERN_INFO"Using G rates\n");
1500 	}else{
1501@@ -1007,7 +1024,7 @@
1502 		printk(KERN_INFO"Using B rates\n");
1503 	}
1504 	ieee->link_change(ieee->dev);
1505-	notify_wx_assoc_event(ieee);
1506+	notify_wx_assoc_event(ieee);
1507 	if (ieee->data_hard_resume)
1508 		ieee->data_hard_resume(ieee->dev);
1509 	netif_carrier_on(ieee->dev);
1510@@ -1017,52 +1034,58 @@
1511 {
1512
1513 	del_timer_sync(&ieee->associate_timer);
1514-
1515+
1516 	ieee->seq_ctrl = 0;
1517 	ieee->state = IEEE80211_LINKED;
1518 	IEEE80211_DEBUG_MGMT("Successfully associated\n");
1519-
1520+
1521 	queue_work(ieee->wq, &ieee->associate_complete_wq);
1522 }
1523
1524+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
1525+void ieee80211_associate_procedure_wq(struct work_struct *work)
1526+{
1527+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1528+#else
1529 void ieee80211_associate_procedure_wq(struct ieee80211_device *ieee)
1530 {
1531+#endif
1532 	ieee->sync_scan_hurryup = 1;
1533 	down(&ieee->wx_sem);
1534-
1535+
1536 	if (ieee->data_hard_stop)
1537 		ieee->data_hard_stop(ieee->dev);
1538-
1539+
1540 	ieee80211_stop_scan(ieee);
1541 	ieee->set_chan(ieee->dev, ieee->current_network.channel);
1542-
1543+
1544 	ieee->associate_seq = 1;
1545 	ieee80211_associate_step1(ieee);
1546-
1547+
1548 	up(&ieee->wx_sem);
1549 }
1550
1551 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
1552 {
1553-
1554+
1555 	u8 tmp_ssid[IW_ESSID_MAX_SIZE+1];
1556 	int tmp_ssid_len = 0;
1557-
1558+
1559 	short apset,ssidset,ssidbroad,apmatch,ssidmatch;
1560-
1561-	/* we are interested in new new only if we are not associated
1562+
1563+	/* we are interested in new new only if we are not associated
1564 	 * and we are not associating / authenticating
1565 	 */
1566 	if (ieee->state != IEEE80211_NOLINK)
1567-		return;
1568-
1569+		return;
1570+
1571 	if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS))
1572 		return;
1573-
1574+
1575 	if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS))
1576 		return;
1577
1578-
1579+
1580 	if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC){
1581 		/* if the user specified the AP MAC, we need also the essid
1582 		 * This could be obtained by beacons or, if the network does not
1583@@ -1073,23 +1096,23 @@
1584 		ssidbroad =  !(net->ssid_len == 0 || net->ssid[0]== '\0');
1585 		apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN)==0);
1586 		ssidmatch = (0==strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len));
1587-
1588-
1589-
1590+
1591+
1592+
1593 		if (	/* if the user set the AP check if match.
1594 		         * if the network does not broadcast essid we check the user supplyed ANY essid
1595 			 * if the network does broadcast and the user does not set essid it is OK
1596 			 * if the network does broadcast and the user did set essid chech if essid match
1597 			 */
1598-			( apset && apmatch &&
1599-				((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1600+			( apset && apmatch &&
1601+				((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1602 			/* if the ap is not set, check that the user set the bssid
1603 			 * and the network does bradcast and that those two bssid matches
1604-			 */
1605-			(!apset && ssidset && ssidbroad && ssidmatch)
1606+			 */
1607+			(!apset && ssidset && ssidbroad && ssidmatch)
1608 			){
1609-
1610-
1611+
1612+
1613 				/* if the essid is hidden replace it with the
1614 				* essid provided by the user.
1615 				*/
1616@@ -1098,18 +1121,18 @@
1617 					tmp_ssid_len = ieee->current_network.ssid_len;
1618 				}
1619 				memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
1620-
1621+
1622 				if (!ssidbroad){
1623 					strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
1624 					ieee->current_network.ssid_len = tmp_ssid_len;
1625 				}
1626 				printk(KERN_INFO"Linking with %s\n",ieee->current_network.ssid);
1627-
1628+
1629 				if (ieee->iw_mode == IW_MODE_INFRA){
1630 					ieee->state = IEEE80211_ASSOCIATING;
1631 					queue_work(ieee->wq, &ieee->associate_procedure_wq);
1632 				}else{
1633-					if(ieee80211_is_54g(ieee->current_network) &&
1634+					if(ieee80211_is_54g(ieee->current_network) &&
1635 						(ieee->modulation & IEEE80211_OFDM_MODULATION)){
1636 						ieee->rate = 540;
1637 						printk(KERN_INFO"Using G rates\n");
1638@@ -1119,7 +1142,7 @@
1639 					}
1640 					ieee->state = IEEE80211_LINKED;
1641 				}
1642-
1643+
1644 		}
1645 	}
1646
1647@@ -1127,26 +1150,26 @@
1648
1649 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
1650 {
1651-
1652+
1653 	unsigned long flags;
1654 	struct ieee80211_network *target;
1655-
1656+
1657 	spin_lock_irqsave(&ieee->lock, flags);
1658-
1659+
1660 	list_for_each_entry(target, &ieee->network_list, list) {
1661-
1662+
1663 		/* if the state become different that NOLINK means
1664 		 * we had found what we are searching for
1665 		 */
1666-		if (ieee->state != IEEE80211_NOLINK)
1667+		if (ieee->state != IEEE80211_NOLINK)
1668 			break;
1669-
1670+
1671 		//if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
1672 			ieee80211_softmac_new_net(ieee, target);
1673 	}
1674-
1675+
1676 	spin_unlock_irqrestore(&ieee->lock, flags);
1677-
1678+
1679 }
1680
1681
1682@@ -1154,7 +1177,7 @@
1683 {
1684 	struct ieee80211_authentication *a;
1685 	u8 *t;
1686-	if (skb->len <  (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1687+	if (skb->len <  (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1688 		IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb->len);
1689 		return 0xcafe;
1690 	}
1691@@ -1162,34 +1185,34 @@
1692 	a = (struct ieee80211_authentication*) skb->data;
1693 	if(skb->len > (sizeof(struct ieee80211_authentication) +3)){
1694 		t = skb->data + sizeof(struct ieee80211_authentication);
1695-
1696+
1697 		if(*(t++) == MFIE_TYPE_CHALLENGE){
1698 			*chlen = *(t++);
1699 			*challenge = (u8*)kmalloc(*chlen, GFP_ATOMIC);
1700 			memcpy(*challenge, t, *chlen);
1701 		}
1702 	}
1703-
1704+
1705 	return cpu_to_le16(a->status);
1706-
1707+
1708 }
1709
1710
1711 int auth_rq_parse(struct sk_buff *skb,u8* dest)
1712 {
1713 	struct ieee80211_authentication *a;
1714-
1715-	if (skb->len <  (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1716-		IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
1717+
1718+	if (skb->len <  (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1719+		IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
1720 		return -1;
1721 	}
1722 	a = (struct ieee80211_authentication*) skb->data;
1723-
1724+
1725 	memcpy(dest,a->header.addr2, ETH_ALEN);
1726-
1727-	if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1728+
1729+	if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1730 		return  WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1731-
1732+
1733 	return WLAN_STATUS_SUCCESS;
1734 }
1735
1736@@ -1199,21 +1222,21 @@
1737 	u8 *skbend;
1738 	u8 *ssid=NULL;
1739 	u8 ssidlen = 0;
1740-
1741+
1742 	struct ieee80211_hdr_3addr   *header =
1743 		(struct ieee80211_hdr_3addr   *) skb->data;
1744-
1745-	if (skb->len < sizeof (struct ieee80211_hdr_3addr  ))
1746+
1747+	if (skb->len < sizeof (struct ieee80211_hdr_3addr  ))
1748 		return -1; /* corrupted */
1749-
1750+
1751 	memcpy(src,header->addr2, ETH_ALEN);
1752-
1753+
1754 	skbend = (u8*)skb->data + skb->len;
1755-
1756+
1757 	tag = skb->data + sizeof (struct ieee80211_hdr_3addr  );
1758-
1759+
1760 	while (tag+1 < skbend){
1761-		if (*tag == 0){
1762+		if (*tag == 0){
1763 			ssid = tag+2;
1764 			ssidlen = *(tag+1);
1765 			break;
1766@@ -1222,41 +1245,41 @@
1767 		tag = tag + *(tag); /* point to the last data byte of the tag */
1768 		tag++; /* point to the next tag */
1769 	}
1770-
1771+
1772 	//IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1773 	if (ssidlen == 0) return 1;
1774-
1775+
1776 	if (!ssid) return 1; /* ssid not found in tagged param */
1777 	return (!strncmp(ssid, ieee->current_network.ssid, ssidlen));
1778-
1779+
1780 }
1781
1782 int assoc_rq_parse(struct sk_buff *skb,u8* dest)
1783 {
1784 	struct ieee80211_assoc_request_frame *a;
1785-
1786-	if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
1787-		sizeof(struct ieee80211_info_element))) {
1788-
1789+
1790+	if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
1791+		sizeof(struct ieee80211_info_element))) {
1792+
1793 		IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb->len);
1794 		return -1;
1795 	}
1796-
1797+
1798 	a = (struct ieee80211_assoc_request_frame*) skb->data;
1799-
1800+
1801 	memcpy(dest,a->header.addr2,ETH_ALEN);
1802-
1803+
1804 	return 0;
1805 }
1806
1807 static inline u16 assoc_parse(struct sk_buff *skb, int *aid)
1808 {
1809 	struct ieee80211_assoc_response_frame *a;
1810-	if (skb->len <  sizeof(struct ieee80211_assoc_response_frame)){
1811+	if (skb->len <  sizeof(struct ieee80211_assoc_response_frame)){
1812 		IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1813 		return 0xcafe;
1814 	}
1815-
1816+
1817 	a = (struct ieee80211_assoc_response_frame*) skb->data;
1818 	*aid = le16_to_cpu(a->aid) & 0x3fff;
1819 	return le16_to_cpu(a->status);
1820@@ -1266,7 +1289,7 @@
1821 ieee80211_rx_probe_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1822 {
1823 	u8 dest[ETH_ALEN];
1824-
1825+
1826 	//IEEE80211DMESG("Rx probe");
1827 	ieee->softmac_stats.rx_probe_rq++;
1828 	//DMESG("Dest is "MACSTR, MAC2STR(dest));
1829@@ -1284,26 +1307,26 @@
1830 	int status;
1831 	//IEEE80211DMESG("Rx probe");
1832 	ieee->softmac_stats.rx_auth_rq++;
1833-
1834+
1835 	if ((status = auth_rq_parse(skb, dest))!= -1){
1836 		ieee80211_resp_to_auth(ieee, status, dest);
1837 	}
1838 	//DMESG("Dest is "MACSTR, MAC2STR(dest));
1839-
1840+
1841 }
1842
1843 static inline void
1844 ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1845 {
1846-
1847+
1848 	u8 dest[ETH_ALEN];
1849 	//unsigned long flags;
1850-
1851+
1852 	ieee->softmac_stats.rx_ass_rq++;
1853 	if (assoc_rq_parse(skb,dest) != -1){
1854 		ieee80211_resp_to_assoc_rq(ieee, dest);
1855 	}
1856-
1857+
1858 	printk(KERN_INFO"New client associated: "MAC_FMT"\n", MAC_ARG(dest));
1859 	//FIXME
1860 	#if 0
1861@@ -1317,24 +1340,24 @@
1862
1863 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr)
1864 {
1865-
1866+
1867 	struct sk_buff *buf = ieee80211_null_func(ieee, pwr);
1868-
1869+
1870 	if (buf)
1871 		softmac_ps_mgmt_xmit(buf, ieee);
1872 //	printk(KERN_INFO "ieee80211_sta_ps_send_null_frame!\n");
1873
1874-}
1875+}
1876
1877
1878 short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, u32 *time_l)
1879-{
1880+{
1881 	int timeout = ieee->ps_timeout;
1882 	u8 dtim;
1883 	/*if(ieee->ps == IEEE80211_PS_DISABLED ||
1884-		ieee->iw_mode != IW_MODE_INFRA ||
1885+		ieee->iw_mode != IW_MODE_INFRA ||
1886 		ieee->state != IEEE80211_LINKED)
1887-
1888+
1889 		return 0;
1890 	*/
1891 	dtim = ieee->current_network.dtim_data;
1892@@ -1343,7 +1366,7 @@
1893 		return 0;
1894 	printk(KERN_INFO "VALID\n");
1895 	ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
1896-
1897+
1898 	if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
1899 		return 2;
1900 	printk(KERN_INFO "no UCAST\n");
1901@@ -1358,11 +1381,11 @@
1902 		return 0;
1903 	printk(KERN_INFO "cc\n");
1904 	if(time_l){
1905-		*time_l = ieee->current_network.last_dtim_sta_time[0]
1906-			+ (ieee->current_network.beacon_interval
1907+		*time_l = ieee->current_network.last_dtim_sta_time[0]
1908+			+ (ieee->current_network.beacon_interval
1909 			* ieee->current_network.dtim_period) * 1000;
1910 	}
1911-
1912+
1913 	if(time_h){
1914 		*time_h = ieee->current_network.last_dtim_sta_time[1];
1915 		if(time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
1916@@ -1372,8 +1395,8 @@
1917 	ieee->ps_tl=*time_l;
1918 //	printk(KERN_INFO "ieee->ps_tl %lu!\n",ieee->ps_tl);
1919 	return 1;
1920-
1921-
1922+
1923+
1924 }
1925
1926 inline void ieee80211_sta_ps(struct ieee80211_device *ieee)
1927@@ -1381,72 +1404,72 @@
1928
1929 	u32 th,tl;
1930 	short sleep;
1931-
1932+
1933 	unsigned long flags,flags2;
1934 ////	printk(KERN_INFO "enter ieee80211_sta_ps!\n");
1935 	spin_lock_irqsave(&ieee->lock, flags);
1936-
1937+
1938 	if((ieee->ps == IEEE80211_PS_DISABLED ||
1939-		ieee->iw_mode != IW_MODE_INFRA ||
1940+		ieee->iw_mode != IW_MODE_INFRA ||
1941 		ieee->state != IEEE80211_LINKED)){
1942-
1943+
1944 //		#warning CHECK_LOCK_HERE
1945 		spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1946-
1947-		ieee80211_sta_wakeup(ieee, 1);
1948+
1949+		ieee80211_sta_wakeup(ieee, 1);
1950 		printk(KERN_WARNING "wakeup 1!\n" );
1951 		spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1952 	}
1953-
1954+
1955 	sleep = ieee80211_sta_ps_sleep(ieee,&th, &tl);
1956 	/* 2 wake, 1 sleep, 0 do nothing */
1957 	//printk(KERN_INFO "sleep %d,th %lu, tl %lu,sta_sleep %d\n",sleep,th,tl,ieee->sta_sleep);
1958 	if(sleep == 0)
1959 		goto out;
1960-
1961+
1962 	if(sleep == 1){
1963-
1964+
1965 		if(ieee->sta_sleep == 1)
1966 			//ieee->enter_sleep_state(ieee->dev,th,tl);
1967 			queue_work(ieee->wq,&ieee->hw_sleep_wq);
1968-
1969+
1970 		else if(ieee->sta_sleep == 0){
1971 		//	printk("send null 1\n");
1972 			spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1973-
1974+
1975 			if(ieee->ps_is_queue_empty(ieee->dev)){
1976-
1977-
1978+
1979+
1980 				ieee->sta_sleep = 2;
1981-
1982+
1983 			//	ieee->ps_request_tx_ack(ieee->dev);
1984 			//	printk(KERN_INFO "ps request address %lu!\n",ieee->ps_request_tx_ack);
1985-			//	queue_work(ieee->wq,&ieee->ps_request_tx_ack_wq);
1986+			//	queue_work(ieee->wq,&ieee->ps_request_tx_ack_wq);
1987 				ieee80211_sta_ps_send_null_frame(ieee,1);
1988 				ieee80211_sta_ps_send_null_frame(ieee,1);
1989-
1990+
1991 				ieee->ps_th = th;
1992 				ieee->ps_tl = tl;
1993 			//	udelay(100);
1994 				ieee80211_ps_tx_ack(ieee,1);//add without interrupt like 8185
1995-			}
1996+			}
1997 			spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1998-
1999+
2000 		}
2001-
2002-
2003+
2004+
2005 	}else if(sleep == 2){
2006 //	#warning CHECK_LOCK_HERE
2007 		spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2008-
2009+
2010 		ieee80211_sta_wakeup(ieee,1);
2011 		printk(KERN_WARNING "wakeup 2!\n" );
2012 		spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2013 	}
2014
2015-out:
2016+out:
2017 	spin_unlock_irqrestore(&ieee->lock, flags);
2018-
2019+
2020 }
2021
2022 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl)
2023@@ -1460,14 +1483,14 @@
2024 			ieee80211_sta_ps_send_null_frame(ieee, 0);
2025 		}
2026 		return;
2027-
2028+
2029 	}
2030-	if(ieee->sta_sleep == 1)
2031+	if(ieee->sta_sleep == 1)
2032 		//ieee->sta_wake_up(ieee->dev);
2033 		queue_work(ieee->wq,&ieee->hw_wakeup_wq);
2034-
2035+
2036 	ieee->sta_sleep = 0;
2037-
2038+
2039 	if(nl){
2040 		//ieee->ps_request_tx_ack(ieee->dev);
2041 		//queue_work(ieee->wq,&ieee->ps_request_tx_ack_wq);
2042@@ -1480,7 +1503,7 @@
2043 	unsigned long flags,flags2;
2044 //	printk(KERN_INFO "ieee80211_ps_tx_ack,success %d,sta_sleep %d!\n",success,ieee->sta_sleep);
2045 	spin_lock_irqsave(&ieee->lock, flags);
2046-
2047+
2048 	if(ieee->sta_sleep == 2){
2049 		/* Null frame with PS bit set */
2050 		if(success){
2051@@ -1495,7 +1518,7 @@
2052 	}
2053 	/* 21112005 - tx again null without PS bit if lost */
2054 	else {
2055-
2056+
2057 		if((ieee->sta_sleep == 0) && !success){
2058 			spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2059 			ieee80211_sta_ps_send_null_frame(ieee, 0);
2060@@ -1519,66 +1542,66 @@
2061 	header = (struct ieee80211_hdr_3addr *) skb->data;
2062 	if(!ieee->proto_started)
2063 		return 0;
2064-
2065+
2066 	if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2067-		ieee->iw_mode == IW_MODE_INFRA &&
2068+		ieee->iw_mode == IW_MODE_INFRA &&
2069 		ieee->state == IEEE80211_LINKED)) {
2070 ////		printk(KERN_INFO "schedule ps task!\n");
2071 		tasklet_schedule(&ieee->ps_task);}
2072-
2073+
2074 	if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2075 		WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2076 		ieee->last_rx_ps_time = jiffies;
2077-
2078+
2079 	switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2080-
2081+
2082 		case IEEE80211_STYPE_ASSOC_RESP:
2083 		case IEEE80211_STYPE_REASSOC_RESP:
2084-
2085+
2086 			IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2087 					WLAN_FC_GET_STYPE(header->frame_ctl));
2088 			if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2089-				ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
2090+				ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
2091 				ieee->iw_mode == IW_MODE_INFRA){
2092 				if (0 == (errcode=assoc_parse(skb, &aid))){
2093-
2094+
2095 					ieee->state=IEEE80211_LINKED;
2096 					ieee->assoc_id = aid;
2097 					ieee->softmac_stats.rx_ass_ok++;
2098-
2099+
2100 					ieee80211_associate_complete(ieee);
2101 				}else{
2102 					ieee->softmac_stats.rx_ass_err++;
2103 					IEEE80211_DEBUG_MGMT(
2104 						"Association response status code 0x%x\n",
2105 						errcode);
2106-					ieee80211_associate_abort(ieee);
2107+					ieee80211_associate_abort(ieee);
2108 				}
2109 			}
2110 			break;
2111-
2112+
2113 		case IEEE80211_STYPE_ASSOC_REQ:
2114 		case IEEE80211_STYPE_REASSOC_REQ:
2115-
2116+
2117 			if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2118 				ieee->iw_mode == IW_MODE_MASTER)
2119-
2120+
2121 				ieee80211_rx_assoc_rq(ieee, skb);
2122 			break;
2123-
2124+
2125 		case IEEE80211_STYPE_AUTH:
2126-
2127+
2128 			if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
2129-				if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
2130+				if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
2131 				ieee->iw_mode == IW_MODE_INFRA){
2132-
2133+
2134 						IEEE80211_DEBUG_MGMT("Received authentication response");
2135-
2136+
2137 						if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
2138 							if(ieee->open_wep || !challenge){
2139 								ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
2140 								ieee->softmac_stats.rx_auth_rs_ok++;
2141-
2142+
2143 								ieee80211_associate_step2(ieee);
2144 							}else{
2145 								ieee80211_auth_challenge(ieee, challenge, chlen);
2146@@ -1588,47 +1611,47 @@
2147 							IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode);
2148 							ieee80211_associate_abort(ieee);
2149 						}
2150-
2151+
2152 					}else if (ieee->iw_mode == IW_MODE_MASTER){
2153 						ieee80211_rx_auth_rq(ieee, skb);
2154 					}
2155 				}
2156 			break;
2157-
2158+
2159 		case IEEE80211_STYPE_PROBE_REQ:
2160-
2161-			if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2162-				((ieee->iw_mode == IW_MODE_ADHOC ||
2163+
2164+			if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2165+				((ieee->iw_mode == IW_MODE_ADHOC ||
2166 				ieee->iw_mode == IW_MODE_MASTER) &&
2167 				ieee->state == IEEE80211_LINKED))
2168-
2169+
2170 				ieee80211_rx_probe_rq(ieee, skb);
2171 			break;
2172-
2173+
2174 		case IEEE80211_STYPE_DISASSOC:
2175 		case IEEE80211_STYPE_DEAUTH:
2176-			/* FIXME for now repeat all the association procedure
2177+			/* FIXME for now repeat all the association procedure
2178 			* both for disassociation and deauthentication
2179 			*/
2180 			if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2181-				ieee->state == IEEE80211_LINKED &&
2182+				ieee->state == IEEE80211_LINKED &&
2183 				ieee->iw_mode == IW_MODE_INFRA){
2184-
2185+
2186 				ieee->state = IEEE80211_ASSOCIATING;
2187 				ieee->softmac_stats.reassoc++;
2188-
2189+
2190 				notify_wx_assoc_event(ieee);
2191-
2192+
2193 				queue_work(ieee->wq, &ieee->associate_procedure_wq);
2194 			}
2195-
2196+
2197 			break;
2198-
2199-		default:
2200+
2201+		default:
2202 			return -1;
2203 			break;
2204 	}
2205-
2206+
2207 	//dev_kfree_skb_any(skb);
2208 	return 0;
2209 }
2210@@ -1646,21 +1669,20 @@
2211  * This might be useful if each fragment need it's own
2212  * descriptor, thus just keep a total free memory > than
2213  * the max fragmentation treshold is not enought.. If the
2214- * ieee802.11 stack passed a TXB struct then you needed
2215- * to keep N free descriptors where
2216+ * ieee802.11 stack passed a TXB struct then you needed
2217+ * to keep N free descriptors where
2218  * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2219  * In this way you need just one and the 802.11 stack
2220- * will take care of buffering fragments and pass them to
2221+ * will take care of buffering fragments and pass them to
2222  * to the driver later, when it wakes the queue.
2223- */
2224-
2225+ */
2226+
2227 void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee)
2228 {
2229-
2230-
2231+
2232+
2233 	unsigned long flags;
2234 	int  i;
2235-
2236 	spin_lock_irqsave(&ieee->lock,flags);
2237 	#if 0
2238 	if(ieee->queue_stop){
2239@@ -1671,13 +1693,13 @@
2240 		err = 1;
2241 		goto exit;
2242 	}
2243-
2244+
2245 	ieee->stats.tx_bytes+=skb->len;
2246-
2247-
2248+
2249+
2250 	txb=ieee80211_skb_to_txb(ieee,skb);
2251-
2252-
2253+
2254+
2255 	if(txb==NULL){
2256 		IEEE80211DMESG("WW: IEEE stack failed to provide txb");
2257 		//dev_kfree_skb_any(skb);
2258@@ -1691,9 +1713,8 @@
2259 	}
2260 	/* called with 2nd parm 0, no tx mgmt lock required */
2261 	ieee80211_sta_wakeup(ieee,0);
2262-
2263 	for(i = 0; i < txb->nr_frags; i++) {
2264-
2265+
2266 		if (ieee->queue_stop){
2267 			//added by david. 2007.1.23
2268 			if(ieee->tx_pending.txb != NULL) {
2269@@ -1709,16 +1730,16 @@
2270 				//(i+1)<txb->nr_frags);
2271 			ieee->stats.tx_packets++;
2272 			ieee->stats.tx_bytes += txb->fragments[i]->len;
2273-			ieee->dev->trans_start = jiffies;
2274+			ieee->dev->trans_start = jiffies;
2275 		}
2276-	}
2277+	}
2278 	lost:
2279 	//ieee80211_txb_free(txb);
2280-
2281+
2282 	exit:
2283 	atomic_dec(&ieee->tx_pending_txb);
2284 	spin_unlock_irqrestore(&ieee->lock,flags);
2285-
2286+
2287 }
2288
2289 /* called with ieee->lock acquired */
2290@@ -1726,13 +1747,13 @@
2291 {
2292 	int i;
2293 	for(i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) {
2294-
2295+
2296 		if (ieee->queue_stop){
2297 			ieee->tx_pending.frag = i;
2298 			return;
2299 		}else{
2300-
2301-			ieee->softmac_data_hard_start_xmit(
2302+
2303+			ieee->softmac_data_hard_start_xmit(
2304 				ieee->tx_pending.txb->fragments[i],
2305 				ieee->dev,ieee->rate);
2306 				//(i+1)<ieee->tx_pending.txb->nr_frags);
2307@@ -1740,8 +1761,8 @@
2308 			ieee->dev->trans_start = jiffies;
2309 		}
2310 	}
2311-
2312-
2313+
2314+
2315 	//ieee80211_txb_free(ieee->tx_pending.txb);
2316 	ieee->tx_pending.txb = NULL;
2317 }
2318@@ -1751,7 +1772,7 @@
2319 {
2320 	unsigned long flags;
2321 	struct sk_buff *ret;
2322-
2323+
2324 	spin_lock_irqsave(&ieee->lock,flags);
2325 	// added by david, 2007.1.23
2326 	while((ret = dequeue_mgmt(ieee)) != NULL) {
2327@@ -1773,17 +1794,17 @@
2328 	unsigned long flags;
2329 	struct sk_buff *skb;
2330 	struct ieee80211_hdr_3addr  *header;
2331-
2332+
2333 	spin_lock_irqsave(&ieee->lock,flags);
2334 	if (! ieee->queue_stop) goto exit;
2335-
2336+
2337 	ieee->queue_stop = 0;
2338-
2339+
2340 	if(ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE){
2341 		while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))){
2342-
2343+
2344 			header = (struct ieee80211_hdr_3addr  *) skb->data;
2345-
2346+
2347 			header->seq_ctl = cpu_to_le16(ieee->seq_ctrl << 4);
2348
2349 			if (ieee->seq_ctrl == 0xFFF)
2350@@ -1799,12 +1820,12 @@
2351 	}
2352 	if (!ieee->queue_stop && ieee->tx_pending.txb)
2353 		ieee80211_resume_tx(ieee);
2354-
2355+
2356 	if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)){
2357 		ieee->softmac_stats.swtxawake++;
2358 		netif_wake_queue(ieee->dev);
2359 	}
2360-
2361+
2362 exit :
2363 	spin_unlock_irqrestore(&ieee->lock,flags);
2364 }
2365@@ -1821,17 +1842,17 @@
2366 	}
2367 	ieee->queue_stop = 1;
2368 	//spin_unlock_irqrestore(&ieee->lock,flags);
2369-
2370+
2371 }
2372
2373
2374 inline void ieee80211_randomize_cell(struct ieee80211_device *ieee)
2375 {
2376-
2377+
2378 	get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2379-
2380+
2381 	/* an IBSS cell address must have the two less significant
2382-	 * bits of the first byte = 2
2383+	 * bits of the first byte = 2
2384 	 */
2385 	ieee->current_network.bssid[0] &= ~0x01;
2386 	ieee->current_network.bssid[0] |= 0x02;
2387@@ -1841,61 +1862,68 @@
2388 void ieee80211_start_master_bss(struct ieee80211_device *ieee)
2389 {
2390 	ieee->assoc_id = 1;
2391-
2392+
2393 	if (ieee->current_network.ssid_len == 0){
2394-		strncpy(ieee->current_network.ssid,
2395+		strncpy(ieee->current_network.ssid,
2396 			IEEE80211_DEFAULT_TX_ESSID,
2397 			IW_ESSID_MAX_SIZE);
2398-
2399+
2400 		ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2401 		ieee->ssid_set = 1;
2402 	}
2403-
2404+
2405 	memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2406-
2407+
2408 	ieee->set_chan(ieee->dev, ieee->current_network.channel);
2409 	ieee->state = IEEE80211_LINKED;
2410 	ieee->link_change(ieee->dev);
2411 	notify_wx_assoc_event(ieee);
2412-
2413+
2414 	if (ieee->data_hard_resume)
2415 		ieee->data_hard_resume(ieee->dev);
2416-
2417+
2418 	netif_carrier_on(ieee->dev);
2419 }
2420
2421 void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
2422 {
2423 	if(ieee->raw_tx){
2424-
2425+
2426 		if (ieee->data_hard_resume)
2427 			ieee->data_hard_resume(ieee->dev);
2428-
2429+
2430 		netif_carrier_on(ieee->dev);
2431 	}
2432 }
2433+
2434+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
2435+void ieee80211_start_ibss_wq(struct work_struct *work)
2436+{
2437+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, start_ibss_wq);
2438+#else
2439 void ieee80211_start_ibss_wq(struct ieee80211_device *ieee)
2440 {
2441-
2442+#endif
2443+
2444 	/* iwconfig mode ad-hoc will schedule this and return
2445 	 * on the other hand this will block further iwconfig SET
2446 	 * operations because of the wx_sem hold.
2447 	 * Anyway some most set operations set a flag to speed-up
2448-	 * (abort) this wq (when syncro scanning) before sleeping
2449+	 * (abort) this wq (when syncro scanning) before sleeping
2450 	 * on the semaphore
2451 	 */
2452-
2453+
2454 	down(&ieee->wx_sem);
2455-
2456+
2457 	if (ieee->current_network.ssid_len == 0){
2458 		strcpy(ieee->current_network.ssid,IEEE80211_DEFAULT_TX_ESSID);
2459 		ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2460 		ieee->ssid_set = 1;
2461-	}
2462-
2463+	}
2464+
2465 	/* check if we have this cell in our network list */
2466 	ieee80211_softmac_check_all_nets(ieee);
2467-
2468+
2469 	/* if not then the state is not linked. Maybe the user swithced to
2470 	 * ad-hoc mode just after being in monitor mode, or just after
2471 	 * being very few time in managed mode (so the card have had no
2472@@ -1915,25 +1943,25 @@
2473
2474 	/* the network definitively is not here.. create a new cell */
2475 	if (ieee->state == IEEE80211_NOLINK){
2476-		printk("creating new IBSS cell\n");
2477+		printk("creating new IBSS cell\n");
2478 		if(!ieee->wap_set)
2479 			ieee80211_randomize_cell(ieee);
2480-
2481+
2482 		if(ieee->modulation & IEEE80211_CCK_MODULATION){
2483-
2484+
2485 			ieee->current_network.rates_len = 4;
2486-
2487+
2488 			ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
2489 			ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
2490 			ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
2491 			ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
2492-
2493+
2494 		}else
2495 			ieee->current_network.rates_len = 0;
2496-
2497+
2498 		if(ieee->modulation & IEEE80211_OFDM_MODULATION){
2499 			ieee->current_network.rates_ex_len = 8;
2500-
2501+
2502 			ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
2503 			ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
2504 			ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
2505@@ -1942,34 +1970,34 @@
2506 			ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
2507 			ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
2508 			ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
2509-
2510+
2511 			ieee->rate = 540;
2512 		}else{
2513 			ieee->current_network.rates_ex_len = 0;
2514 			ieee->rate = 110;
2515 		}
2516-
2517+
2518 		ieee->current_network.atim_window = 0;
2519 		ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2520 		if(ieee->short_slot)
2521 			ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT;
2522-
2523+
2524 	}
2525-
2526+
2527 	ieee->state = IEEE80211_LINKED;
2528-
2529+
2530 	ieee->set_chan(ieee->dev, ieee->current_network.channel);
2531 	ieee->link_change(ieee->dev);
2532-
2533+
2534 	notify_wx_assoc_event(ieee);
2535-
2536+
2537 	ieee80211_start_send_beacons(ieee);
2538-
2539+
2540 	if (ieee->data_hard_resume)
2541 		ieee->data_hard_resume(ieee->dev);
2542-
2543+
2544 	netif_carrier_on(ieee->dev);
2545-
2546+
2547 	up(&ieee->wx_sem);
2548 }
2549
2550@@ -1988,7 +2016,7 @@
2551 	 * in associating / authenticating phase) start the background scanning.
2552 	 */
2553 	ieee80211_softmac_check_all_nets(ieee);
2554-
2555+
2556 	/* ensure no-one start an associating process (thus setting
2557 	 * the ieee->state to ieee80211_ASSOCIATING) while we
2558 	 * have just cheked it and we are going to enable scan.
2559@@ -1997,10 +2025,10 @@
2560 	 * the rx path), so we cannot be in the middle of such function
2561 	 */
2562 	spin_lock_irqsave(&ieee->lock, flags);
2563-
2564+
2565 	if (ieee->state == IEEE80211_NOLINK)
2566 		ieee80211_start_scan(ieee);
2567-
2568+
2569 	spin_unlock_irqrestore(&ieee->lock, flags);
2570 }
2571
2572@@ -2008,30 +2036,38 @@
2573 void ieee80211_disassociate(struct ieee80211_device *ieee)
2574 {
2575 	netif_carrier_off(ieee->dev);
2576-
2577+
2578 	if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2579 			ieee80211_reset_queue(ieee);
2580-
2581+
2582 	if (ieee->data_hard_stop)
2583 			ieee->data_hard_stop(ieee->dev);
2584-
2585+
2586 	ieee->state = IEEE80211_NOLINK;
2587 	ieee->link_change(ieee->dev);
2588 	notify_wx_assoc_event(ieee);
2589-
2590+
2591 }
2592+
2593+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
2594+void ieee80211_associate_retry_wq(struct work_struct *work)
2595+{
2596+	struct delayed_work *dwork = container_of(work, struct delayed_work, work);
2597+	struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2598+#else
2599 void ieee80211_associate_retry_wq(struct ieee80211_device *ieee)
2600 {
2601+#endif
2602 	unsigned long flags;
2603-
2604+
2605 	down(&ieee->wx_sem);
2606 	if(!ieee->proto_started)
2607 		goto exit;
2608-
2609+
2610 	if(ieee->state != IEEE80211_ASSOCIATING_RETRY)
2611 		goto exit;
2612-
2613-	/* until we do not set the state to IEEE80211_NOLINK
2614+
2615+	/* until we do not set the state to IEEE80211_NOLINK
2616 	* there are no possibility to have someone else trying
2617 	* to start an association procdure (we get here with
2618 	* ieee->state = IEEE80211_ASSOCIATING).
2619@@ -2041,18 +2077,18 @@
2620 	* RX path works with ieee->lock held so there are no
2621 	* problems. If we are still disassociated then start a scan.
2622 	* the lock here is necessary to ensure no one try to start
2623-	* an association procedure when we have just checked the
2624+	* an association procedure when we have just checked the
2625 	* state and we are going to start the scan.
2626 	*/
2627 	ieee->state = IEEE80211_NOLINK;
2628
2629 	ieee80211_softmac_check_all_nets(ieee);
2630-
2631+
2632 	spin_lock_irqsave(&ieee->lock, flags);
2633-
2634+
2635 	if(ieee->state == IEEE80211_NOLINK)
2636 		ieee80211_start_scan(ieee);
2637-
2638+
2639 	spin_unlock_irqrestore(&ieee->lock, flags);
2640
2641 exit:
2642@@ -2062,39 +2098,39 @@
2643 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
2644 {
2645 	u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2646-
2647+
2648 	struct sk_buff *skb;
2649 	struct ieee80211_probe_response *b;
2650-
2651+
2652 	skb = ieee80211_probe_resp(ieee, broadcast_addr);
2653-
2654-	if (!skb)
2655+
2656+	if (!skb)
2657 		return NULL;
2658-
2659+
2660 	b = (struct ieee80211_probe_response *) skb->data;
2661 	b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON);
2662-
2663+
2664 	return skb;
2665-
2666+
2667 }
2668
2669 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee)
2670 {
2671 	struct sk_buff *skb;
2672 	struct ieee80211_probe_response *b;
2673-
2674+
2675 	skb = ieee80211_get_beacon_(ieee);
2676-	if(!skb)
2677+	if(!skb)
2678 		return NULL;
2679-
2680-	b = (struct ieee80211_probe_response *) skb->data;
2681+
2682+	b = (struct ieee80211_probe_response *) skb->data;
2683 	b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl << 4);
2684-
2685+
2686 	if (ieee->seq_ctrl == 0xFFF)
2687 		ieee->seq_ctrl = 0;
2688 	else
2689 		ieee->seq_ctrl++;
2690-
2691+
2692 	return skb;
2693 }
2694
2695@@ -2111,14 +2147,14 @@
2696 {
2697 	if (!ieee->proto_started)
2698 		return;
2699-
2700+
2701 	ieee->proto_started = 0;
2702-
2703+
2704 	ieee80211_stop_send_beacons(ieee);
2705-
2706+
2707 	del_timer_sync(&ieee->associate_timer);
2708-	cancel_delayed_work(&ieee->associate_retry_wq);
2709-
2710+	cancel_delayed_work(&ieee->associate_retry_wq);
2711+
2712 	ieee80211_stop_scan(ieee);
2713
2714 	ieee80211_disassociate(ieee);
2715@@ -2135,28 +2171,28 @@
2716 void ieee80211_start_protocol(struct ieee80211_device *ieee)
2717 {
2718 	short ch = 0;
2719-
2720+
2721 	if (ieee->proto_started)
2722 		return;
2723-
2724+
2725 	ieee->proto_started = 1;
2726-
2727+
2728 	if (ieee->current_network.channel == 0){
2729 		do{
2730 			ch++;
2731-			if (ch > MAX_CHANNEL_NUMBER)
2732+			if (ch > MAX_CHANNEL_NUMBER)
2733 				return; /* no channel found */
2734-
2735+
2736 		}while(!ieee->channel_map[ch]);
2737-
2738+
2739 		ieee->current_network.channel = ch;
2740 	}
2741-
2742+
2743 	if (ieee->current_network.beacon_interval == 0)
2744 		ieee->current_network.beacon_interval = 100;
2745-
2746+
2747 	ieee->set_chan(ieee->dev,ieee->current_network.channel);
2748-
2749+
2750 	ieee->last_seq_num = -1;
2751 	ieee->last_frag_num = -1;
2752 	ieee->last_packet_time = 0;
2753@@ -2167,18 +2203,18 @@
2754 	 * attempts does not fail just because the user provide the essid
2755 	 * and the nic is still checking for the AP MAC ??
2756 	 */
2757-
2758+
2759 	if (ieee->iw_mode == IW_MODE_INFRA)
2760 		ieee80211_start_bss(ieee);
2761-
2762+
2763 	else if (ieee->iw_mode == IW_MODE_ADHOC)
2764 		ieee80211_start_ibss(ieee);
2765-
2766+
2767 	else if (ieee->iw_mode == IW_MODE_MASTER)
2768 		ieee80211_start_master_bss(ieee);
2769-
2770+
2771 	else if(ieee->iw_mode == IW_MODE_MONITOR)
2772-		ieee80211_start_monitor_mode(ieee);
2773+		ieee80211_start_monitor_mode(ieee);
2774 }
2775
2776
2777@@ -2186,11 +2222,11 @@
2778 void ieee80211_softmac_init(struct ieee80211_device *ieee)
2779 {
2780 	memset(&ieee->current_network, 0, sizeof(struct ieee80211_network));
2781-
2782+
2783 	ieee->state = IEEE80211_NOLINK;
2784 	ieee->sync_scan_hurryup = 0;
2785 	ieee->seq_ctrl = 0;
2786-
2787+
2788 	ieee->assoc_id = 0;
2789 	ieee->queue_stop = 0;
2790 	ieee->scanning = 0;
2791@@ -2203,7 +2239,7 @@
2792 	ieee->ps = IEEE80211_PS_DISABLED;
2793 	ieee->sta_sleep = 0;
2794
2795-
2796+
2797 	init_mgmt_queue(ieee);
2798 #if 0
2799 	init_timer(&ieee->scan_timer);
2800@@ -2211,7 +2247,7 @@
2801 	ieee->scan_timer.function = ieee80211_softmac_scan_cb;
2802 #endif
2803 	ieee->tx_pending.txb = NULL;
2804-
2805+
2806 	init_timer(&ieee->associate_timer);
2807 	ieee->associate_timer.data = (unsigned long)ieee;
2808 	ieee->associate_timer.function = ieee80211_associate_abort_cb;
2809@@ -2219,28 +2255,37 @@
2810 	init_timer(&ieee->beacon_timer);
2811 	ieee->beacon_timer.data = (unsigned long) ieee;
2812 	ieee->beacon_timer.function = ieee80211_send_beacon_cb;
2813-
2814+
2815 #ifdef PF_SYNCTHREAD
2816 	ieee->wq = create_workqueue(DRV_NAME,0);
2817-#else
2818+#else
2819 	ieee->wq = create_workqueue(DRV_NAME);
2820 #endif
2821-
2822+
2823+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
2824 	INIT_WORK(&ieee->start_ibss_wq,(void(*)(void*)) ieee80211_start_ibss_wq,ieee);
2825 	INIT_WORK(&ieee->associate_retry_wq,(void(*)(void*)) ieee80211_associate_retry_wq,ieee);
2826 	INIT_WORK(&ieee->associate_complete_wq,(void(*)(void*)) ieee80211_associate_complete_wq,ieee);
2827 	INIT_WORK(&ieee->associate_procedure_wq,(void(*)(void*)) ieee80211_associate_procedure_wq,ieee);
2828 	INIT_WORK(&ieee->softmac_scan_wq,(void(*)(void*)) ieee80211_softmac_scan_wq,ieee);
2829 	INIT_WORK(&ieee->wx_sync_scan_wq,(void(*)(void*)) ieee80211_wx_sync_scan_wq,ieee);
2830+#else
2831+	INIT_WORK(&ieee->start_ibss_wq, ieee80211_start_ibss_wq);
2832+	INIT_DELAYED_WORK(&ieee->associate_retry_wq, ieee80211_associate_retry_wq);
2833+	INIT_WORK(&ieee->associate_complete_wq, ieee80211_associate_complete_wq);
2834+	INIT_WORK(&ieee->associate_procedure_wq, ieee80211_associate_procedure_wq);
2835+	INIT_DELAYED_WORK(&ieee->softmac_scan_wq, ieee80211_softmac_scan_wq);
2836+	INIT_WORK(&ieee->wx_sync_scan_wq, ieee80211_wx_sync_scan_wq);
2837+#endif
2838 ///	INIT_WORK(&ieee->ps_request_tx_ack_wq,(void(*)(void*))ieee->ps_request_tx_ack,ieee->dev);//for ps 07.26
2839-
2840+
2841
2842 	sema_init(&ieee->wx_sem, 1);
2843 	sema_init(&ieee->scan_sem, 1);
2844-
2845+
2846 	spin_lock_init(&ieee->mgmt_tx_lock);
2847 	spin_lock_init(&ieee->beacon_lock);
2848-
2849+
2850 	tasklet_init(&ieee->ps_task,
2851 	     (void(*)(unsigned long)) ieee80211_sta_ps,
2852 	     (unsigned long)ieee);
2853@@ -2250,20 +2295,20 @@
2854 void ieee80211_softmac_free(struct ieee80211_device *ieee)
2855 {
2856 	down(&ieee->wx_sem);
2857-
2858+
2859 	del_timer_sync(&ieee->associate_timer);
2860 	cancel_delayed_work(&ieee->associate_retry_wq);
2861 	destroy_workqueue(ieee->wq);
2862-
2863+
2864 	up(&ieee->wx_sem);
2865 }
2866
2867-/********************************************************
2868+/********************************************************
2869  * Start of WPA code.                                   *
2870  * this is stolen from the ipw2200 driver               *
2871  ********************************************************/
2872
2873-
2874+
2875 static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
2876 {
2877 	/* This is called when wpa_supplicant loads and closes the driver
2878@@ -2273,7 +2318,7 @@
2879 	return 0;
2880 }
2881
2882-
2883+
2884 void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, int wpa_ie_len)
2885 {
2886 	/* make sure WPA is enabled */
2887@@ -2285,7 +2330,7 @@
2888
2889 static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, int reason)
2890 {
2891-
2892+
2893 	int ret = 0;
2894
2895 	switch (command) {
2896@@ -2339,7 +2384,7 @@
2897
2898 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
2899 {
2900-
2901+
2902 	struct ieee80211_security sec = {
2903 		.flags = SEC_AUTH_MODE,
2904 	};
2905@@ -2435,7 +2480,7 @@
2906 				  struct ieee_param *param, int param_len)
2907 {
2908 	int ret = 0;
2909-
2910+
2911 	struct ieee80211_crypto_ops *ops;
2912 	struct ieee80211_crypt_data **crypt;
2913
2914@@ -2600,7 +2645,7 @@
2915 		ret = -EINVAL;
2916 		goto out;
2917 	}
2918-
2919+
2920 	param = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
2921 	if (param == NULL){
2922 		ret = -ENOMEM;
2923@@ -2644,7 +2689,7 @@
2924 	kfree(param);
2925 out:
2926 	up(&ieee->wx_sem);
2927-
2928+
2929 	return ret;
2930 }
2931
2932diff -Naur r8187_orig/ieee80211/ieee80211_softmac_wx.c r8187_rawtx/ieee80211/ieee80211_softmac_wx.c
2933--- r8187_orig/ieee80211/ieee80211_softmac_wx.c	2007-01-15 03:00:37.000000000 +0100
2934+++ r8187_rawtx/ieee80211/ieee80211_softmac_wx.c	2007-05-16 22:00:07.000000000 +0200
2935@@ -236,7 +236,7 @@
2936 int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
2937 			     union iwreq_data *wrqu, char *b)
2938 {
2939-
2940+	short prev = ieee->raw_tx;
2941 	ieee->sync_scan_hurryup = 1;
2942
2943 	down(&ieee->wx_sem);
2944@@ -246,7 +246,7 @@
2945
2946 	if (wrqu->mode == IW_MODE_MONITOR){
2947
2948-		ieee->dev->type = ARPHRD_IEEE80211;
2949+		ieee->dev->type = ARPHRD_IEEE80211_PRISM;
2950 	}else{
2951 		ieee->dev->type = ARPHRD_ETHER;
2952 	}
2953@@ -259,13 +259,37 @@
2954 		ieee80211_start_protocol(ieee);
2955 	}
2956
2957+	if(ieee->iw_mode == IW_MODE_MONITOR)
2958+	{
2959+		ieee->raw_tx = 1;
2960+		if(prev == 0 && ieee->raw_tx){
2961+			if (ieee->data_hard_resume)
2962+				ieee->data_hard_resume(ieee->dev);
2963+
2964+			netif_carrier_on(ieee->dev);
2965+		}
2966+
2967+		netif_carrier_on(ieee->dev);
2968+	}
2969+	else
2970+	{
2971+		ieee->raw_tx = 0;
2972+	}
2973+
2974+
2975 out:
2976 	up(&ieee->wx_sem);
2977 	return 0;
2978 }
2979
2980+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
2981+void ieee80211_wx_sync_scan_wq(struct work_struct *work)
2982+{
2983+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wx_sync_scan_wq);
2984+#else
2985 void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee)
2986 {
2987+#endif
2988 	short chan;
2989
2990 	chan = ieee->current_network.channel;
2991@@ -356,7 +380,11 @@
2992 	spin_lock_irqsave(&ieee->lock, flags);
2993
2994 	if (wrqu->essid.flags && wrqu->essid.length) {
2995+#if WIRELESS_EXT > 20
2996+		len = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
2997+#else
2998 		len = ((wrqu->essid.length-1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length-1) : IW_ESSID_MAX_SIZE;
2999+#endif
3000
3001 		strncpy(ieee->current_network.ssid, extra, len);
3002 		ieee->current_network.ssid_len = len;
3003diff -Naur r8187_orig/ieee80211/ieee80211_tx.c r8187_rawtx/ieee80211/ieee80211_tx.c
3004--- r8187_orig/ieee80211/ieee80211_tx.c	2007-12-05 09:53:21.000000000 +0100
3005+++ r8187_rawtx/ieee80211/ieee80211_tx.c	2007-05-16 22:00:07.000000000 +0200
3006@@ -32,7 +32,6 @@
3007 ******************************************************************************/
3008
3009 #include <linux/compiler.h>
3010-#include <linux/config.h>
3011 #include <linux/errno.h>
3012 #include <linux/if_arp.h>
3013 #include <linux/in6.h>
3014@@ -52,6 +51,12 @@
3015 #include <linux/etherdevice.h>
3016 #include <asm/uaccess.h>
3017
3018+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
3019+#include <linux/config.h>
3020+#else
3021+#include <linux/autoconf.h>
3022+#endif
3023+
3024 #include "ieee80211.h"
3025
3026
3027@@ -481,19 +486,19 @@
3028 			ieee->seq_ctrl++;
3029 		//---
3030 	}else{
3031-		if (unlikely(skb->len < sizeof(struct ieee80211_hdr_3addr))) {
3032+		if (unlikely(skb->len < 14)) {
3033 			printk(KERN_WARNING "%s: skb too small (%d).\n",
3034 			ieee->dev->name, skb->len);
3035 			goto success;
3036 		}
3037-
3038+
3039 		txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC);
3040 		if(!txb){
3041 			printk(KERN_WARNING "%s: Could not allocate TXB\n",
3042 			ieee->dev->name);
3043 			goto failed;
3044 		}
3045-
3046+		txb->nr_frags = 1;
3047 		txb->encrypted = 0;
3048 		txb->payload_size = skb->len;
3049 		memcpy(skb_put(txb->fragments[0],skb->len), skb->data, skb->len);
3050diff -Naur r8187_orig/Makefile r8187_rawtx/Makefile
3051--- r8187_orig/Makefile	1970-01-01 01:00:00.000000000 +0100
3052+++ r8187_rawtx/Makefile	2007-05-13 09:54:38.000000000 +0200
3053@@ -0,0 +1,36 @@
3054+prefix        = /lib/modules/$(shell uname -r)/kernel/drivers/net/wireless
3055+r8187dir      = $(prefix)/rtl8187
3056+ieeedir       = $(prefix)/rtl_ieee80211
3057+
3058+default: all
3059+
3060+all:
3061+	$(MAKE) -C ieee80211 $(@)
3062+	-chmod +x symvers
3063+	-./symvers
3064+	$(MAKE) -C rtl8187 $(@)
3065+
3066+install:
3067+	install -d $(ieeedir)
3068+	install -d $(r8187dir)
3069+	install -m 644 ./ieee80211/*.ko $(ieeedir)
3070+	install -m 644 ./rtl8187/*.ko $(r8187dir)
3071+	-depmod -ae
3072+
3073+uninstall:
3074+	-rm -f $(ieeedir)/ieee80211-rtl.ko
3075+	-rm -f $(ieeedir)/ieee80211_crypt-rtl.ko
3076+	-rm -f $(ieeedir)/ieee80211_crypt_ccmp-rtl.ko
3077+	-rm -f $(ieeedir)/ieee80211_crypt_tkip-rtl.ko
3078+	-rm -f $(ieeedir)/ieee80211_crypt_wep-rtl.ko
3079+	-rm -f $(r8187dir)/r8187.ko
3080+	-rm -fr $(ieeedir)
3081+	-rm -fr $(r8187dir)
3082+	-depmod -ae
3083+
3084+clean:
3085+	$(MAKE) -C ieee80211 $(@)
3086+	$(MAKE) -C rtl8187 $(@)
3087+
3088+distclean: clean
3089+
3090diff -Naur r8187_orig/rtl8187/ieee80211.h r8187_rawtx/rtl8187/ieee80211.h
3091--- r8187_orig/rtl8187/ieee80211.h	2007-12-05 09:50:41.000000000 +0100
3092+++ r8187_rawtx/rtl8187/ieee80211.h	2007-05-16 21:51:38.000000000 +0200
3093@@ -108,6 +108,8 @@
3094 #define	ieee80211_start_protocol	ieee80211_start_protocol_rtl
3095 #define	ieee80211_stop_protocol		ieee80211_stop_protocol_rtl
3096 #define	ieee80211_rx_mgt		ieee80211_rx_mgt_rtl
3097+#define	ieee80211_stop_queue		ieee80211_stop_queue_rtl
3098+#define	ieee80211_wake_queue		ieee80211_wake_queue_rtl
3099
3100
3101 typedef struct ieee_param {
3102@@ -193,6 +195,22 @@
3103 	struct list_head list;
3104 };
3105
3106+#define LWNG_CAP_DID_BASE   (4 | (1 << 6)) /* section 4, group 1 */
3107+/* ARPHRD_IEEE80211_PRISM uses a bloated version of Prism2 RX frame header
3108+ * (from linux-wlan-ng) */
3109+struct linux_wlan_ng_val {
3110+	u32 did;
3111+	u16 status, len;
3112+	u32 data;
3113+} __attribute__ ((packed));
3114+
3115+struct linux_wlan_ng_prism_hdr {
3116+	u32 msgcode, msglen;
3117+	char devname[16];
3118+	struct linux_wlan_ng_val hosttime, mactime, channel, rssi, sq, signal,
3119+		noise, rate, istx, frmlen;
3120+} __attribute__ ((packed));
3121+
3122 struct ieee80211_hdr {
3123 	u16 frame_ctl;
3124 	u16 duration_id;
3125@@ -1064,10 +1082,15 @@
3126 	struct timer_list beacon_timer;
3127
3128 	struct work_struct associate_complete_wq;
3129+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3130+	struct delayed_work associate_retry_wq;
3131+	struct delayed_work softmac_scan_wq;
3132+#else
3133 	struct work_struct associate_retry_wq;
3134+	struct work_struct softmac_scan_wq;
3135+#endif
3136 	struct work_struct start_ibss_wq;
3137 	struct work_struct associate_procedure_wq;
3138-	struct work_struct softmac_scan_wq;
3139 	struct work_struct wx_sync_scan_wq;
3140 	struct work_struct ps_request_tx_ack_wq;//for ps
3141 	struct work_struct hw_wakeup_wq;
3142@@ -1390,7 +1413,11 @@
3143 extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
3144 			     union iwreq_data *wrqu, char *b);
3145
3146+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3147+extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
3148+#else
3149 extern void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee);
3150+#endif
3151
3152 extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
3153 			       struct iw_request_info *info,
3154diff -Naur r8187_orig/rtl8187/r8180_hw.h r8187_rawtx/rtl8187/r8180_hw.h
3155--- r8187_orig/rtl8187/r8180_hw.h	2007-12-03 12:30:10.000000000 +0100
3156+++ r8187_rawtx/rtl8187/r8180_hw.h	2007-05-16 21:51:38.000000000 +0200
3157@@ -1,16 +1,16 @@
3158-/*
3159+/*
3160 	This is part of rtl8187 OpenSource driver.
3161-	Copyright (C) Andrea Merello 2004-2005  <andreamrl@tiscali.it>
3162+	Copyright (C) Andrea Merello 2004-2005  <andreamrl@tiscali.it>
3163 	Released under the terms of GPL (General Public Licence)
3164-
3165-	Parts of this driver are based on the GPL part of the
3166+
3167+	Parts of this driver are based on the GPL part of the
3168 	official Realtek driver.
3169-	Parts of this driver are based on the rtl8180 driver skeleton
3170+	Parts of this driver are based on the rtl8180 driver skeleton
3171 	from Patric Schenke & Andres Salomon.
3172-	Parts of this driver are based on the Intel Pro Wireless
3173+	Parts of this driver are based on the Intel Pro Wireless
3174 	2100 GPL driver.
3175-
3176-	We want to tanks the Authors of those projects
3177+
3178+	We want to tanks the Authors of those projects
3179 	and the Ndiswrapper project Authors.
3180 */
3181
3182@@ -20,7 +20,7 @@
3183 #ifndef R8180_HW
3184 #define R8180_HW
3185
3186-#define MAX_SLEEP_TIME (10000000)
3187+#define MAX_SLEEP_TIME (10000000)
3188 #define MIN_SLEEP_TIME (50000)
3189
3190 #define	RTL8187_RF_INDEX	0x8225
3191@@ -80,7 +80,7 @@
3192 #define EPROM_CMD_OPERATING_MODE_SHIFT 6
3193 #define EPROM_CMD_OPERATING_MODE_MASK ((1<<7)|(1<<6))
3194 #define EPROM_CMD_CONFIG 0x3
3195-#define EPROM_CMD_NORMAL 0
3196+#define EPROM_CMD_NORMAL 0
3197 #define EPROM_CMD_LOAD 1
3198 #define EPROM_CMD_PROGRAM 2
3199 #define EPROM_CS_SHIFT 3
3200@@ -193,8 +193,8 @@
3201
3202
3203
3204-/*
3205- * Operational registers offsets in PCI (I/O) space.
3206+/*
3207+ * Operational registers offsets in PCI (I/O) space.
3208  * RealTek names are used.
3209  */
3210
3211@@ -310,7 +310,7 @@
3212 /* following are for rtl8185 */
3213 #define RFPinsOutput 0x80
3214 #define RFPinsEnable 0x82
3215-#define RF_TIMING 0x8c
3216+#define RF_TIMING 0x8c
3217 #define RFPinsSelect 0x84
3218 #define ANAPARAM2 0x60
3219 #define RF_PARA 0x88
3220@@ -339,7 +339,7 @@
3221 #define MIN_RESP_RATE_SHIFT 0
3222 #define RATE_FALLBACK 0xbe
3223 /*
3224- *  0x0084 - 0x00D3 is selected to page 1 when PSEn bit (bit0, PSR)
3225+ *  0x0084 - 0x00D3 is selected to page 1 when PSEn bit (bit0, PSR)
3226  *  is set to 1
3227  */
3228
3229@@ -380,7 +380,7 @@
3230
3231
3232 /*
3233- *  0x0084 - 0x00D3 is selected to page 0 when PSEn bit (bit0, PSR)
3234+ *  0x0084 - 0x00D3 is selected to page 0 when PSEn bit (bit0, PSR)
3235  *  is set to 0
3236  */
3237
3238@@ -437,7 +437,7 @@
3239
3240
3241 /*
3242- * Bitmasks for specific register functions.
3243+ * Bitmasks for specific register functions.
3244  * Names are derived from the register name and function name.
3245  *
3246  * <REGISTER>_<FUNCTION>[<bit>]
3247@@ -501,7 +501,7 @@
3248 #define TCR_HWVERID_SHIFT 25
3249 #define TCR_SWPLCPLEN     ((1<<24))
3250 #define TCR_PLCP_LEN TCR_SAT // rtl8180
3251-#define TCR_MXDMA_MASK   ((1<<23)|(1<<22)|(1<<21))
3252+#define TCR_MXDMA_MASK   ((1<<23)|(1<<22)|(1<<21))
3253 #define TCR_MXDMA_1024 6
3254 #define TCR_MXDMA_2048 7
3255 #define TCR_MXDMA_SHIFT  21
3256diff -Naur r8187_orig/rtl8187/r8180_rtl8225.h r8187_rawtx/rtl8187/r8180_rtl8225.h
3257--- r8187_orig/rtl8187/r8180_rtl8225.h	2007-01-15 03:00:37.000000000 +0100
3258+++ r8187_rawtx/rtl8187/r8180_rtl8225.h	2007-05-16 21:51:38.000000000 +0200
3259@@ -48,4 +48,5 @@
3260
3261 extern u32 rtl8225_chan[];
3262
3263+void rtl8225z2_SetTXPowerLevel(struct net_device *dev, short ch);
3264 #endif
3265diff -Naur r8187_orig/rtl8187/r8180_wx.c r8187_rawtx/rtl8187/r8180_wx.c
3266--- r8187_orig/rtl8187/r8180_wx.c	2007-03-02 04:22:29.000000000 +0100
3267+++ r8187_rawtx/rtl8187/r8180_wx.c	2007-05-16 21:51:33.000000000 +0200
3268@@ -21,7 +21,7 @@
3269
3270 #include "r8187.h"
3271 #include "r8180_hw.h"
3272-
3273+#include "r8180_rtl8225.h"
3274
3275 //#define RATE_COUNT 4
3276 u32 rtl8180_rates[] = {1000000,2000000,5500000,11000000,
3277@@ -121,22 +121,72 @@
3278 	return ret;
3279 }
3280
3281-static int r8180_wx_set_rawtx(struct net_device *dev,
3282-			       struct iw_request_info *info,
3283-			       union iwreq_data *wrqu, char *extra)
3284+static int r8180_wx_get_txpow(struct net_device *dev,
3285+			      struct iw_request_info *info,
3286+			      union iwreq_data *wrqu, char *extra)
3287 {
3288 	struct r8180_priv *priv = ieee80211_priv(dev);
3289-	int ret;
3290-
3291+	int i=0;
3292 	down(&priv->wx_sem);
3293-
3294-	ret = ieee80211_wx_set_rawtx(priv->ieee80211, info, wrqu, extra);
3295-
3296+	wrqu->power.value = 0;
3297+	for(i=0; i<15; i++)
3298+	{
3299+		if(priv->chtxpwr[i] > wrqu->power.value) wrqu->power.value = priv->chtxpwr[i];
3300+		if(priv->chtxpwr_ofdm[i] > wrqu->power.value) wrqu->power.value = priv->chtxpwr_ofdm[i];
3301+	}
3302+	wrqu->power.fixed = 1;
3303+	wrqu->power.flags = IW_TXPOW_DBM;
3304+	wrqu->power.disabled = 0;
3305 	up(&priv->wx_sem);
3306-
3307+
3308+	return 0;
3309+}
3310+
3311+#if 1
3312+static int r8180_wx_set_txpow(struct net_device *dev,
3313+			      struct iw_request_info *info,
3314+			      union iwreq_data *wrqu, char *extra)
3315+{
3316+	int ret = 0, i=0;
3317+	struct r8180_priv *priv = ieee80211_priv(dev);
3318+
3319+	down(&priv->wx_sem);
3320+
3321+	if (wrqu->power.flags != IW_TXPOW_DBM)
3322+	{
3323+		ret = -EINVAL;
3324+		goto out;
3325+	}
3326+
3327+	if(wrqu->power.value > priv->txpwr_max)
3328+	{
3329+		ret = -EINVAL;
3330+		goto out;
3331+	}
3332+
3333+	if(wrqu->power.value < 0)
3334+	{
3335+		ret = -EINVAL;
3336+		goto out;
3337+	}
3338+
3339+	for(i=1;i<15;i++)
3340+	{
3341+		priv->chtxpwr[i] = priv->chtxpwr_orig[i] - (priv->txpwr_max - wrqu->power.value);
3342+		if(priv->chtxpwr[i] > priv->chtxpwr_orig[i]) priv->chtxpwr[i] = 0;
3343+
3344+		priv->chtxpwr_ofdm[i] = priv->chtxpwr_ofdm_orig[i] - (priv->txpwr_max - wrqu->power.value);
3345+		if(priv->chtxpwr_ofdm[i] > priv->chtxpwr_ofdm_orig[i]) priv->chtxpwr_ofdm[i] = 0;
3346+	}
3347+	rtl8225z2_SetTXPowerLevel(dev, 1);
3348+
3349+	out:
3350+	up(&priv->wx_sem);
3351+
3352 	return ret;
3353
3354 }
3355+#endif
3356
3357 static int r8180_wx_set_rts(struct net_device *dev,
3358 			     struct iw_request_info *info,
3359@@ -836,6 +886,7 @@
3360
3361 }
3362
3363+#if 0
3364 static int r8180_wx_radio_on(struct net_device *dev,
3365 				struct iw_request_info *info,
3366 				union iwreq_data *wrqu, char *extra)
3367@@ -871,6 +922,7 @@
3368 	return 0;
3369
3370 }
3371+#endif
3372
3373 static int r8180_wx_set_channelplan(struct net_device *dev,
3374 			     struct iw_request_info *info,
3375@@ -965,8 +1017,8 @@
3376         r8180_wx_get_rts,                    /* SIOCGIWRTS */
3377         r8180_wx_set_frag,        /* SIOCSIWFRAG */
3378         r8180_wx_get_frag,        /* SIOCGIWFRAG */
3379-        dummy,                    /* SIOCSIWTXPOW */
3380-        dummy,                    /* SIOCGIWTXPOW */
3381+        r8180_wx_set_txpow,       /* SIOCSIWTXPOW */
3382+        r8180_wx_get_txpow,       /* SIOCGIWTXPOW */
3383         r8180_wx_set_retry,       /* SIOCSIWRETRY */
3384         r8180_wx_get_retry,       /* SIOCGIWRETRY */
3385         r8180_wx_set_enc,         /* SIOCSIWENCODE */
3386@@ -1007,7 +1059,7 @@
3387 	},
3388 	{
3389 		SIOCIWFIRSTPRIV + 0x6,
3390-		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "rawtx"
3391+		0, 0, "dummy"
3392 	},
3393 	{	SIOCIWFIRSTPRIV + 0x7,
3394 		0, 0, "dummy"
3395@@ -1053,11 +1105,11 @@
3396  	},
3397 	{
3398 		SIOCIWFIRSTPRIV + 0x12,
3399-		0, 0, "radioon"
3400+		0, 0, "dummy"
3401  	},
3402 	{
3403 		SIOCIWFIRSTPRIV + 0x13,
3404-		0, 0, "radiooff"
3405+		0, 0, "dummy"
3406  	},
3407 	{
3408 		SIOCIWFIRSTPRIV + 0x14,
3409@@ -1089,7 +1141,7 @@
3410 	dummy,
3411 	r8180_wx_set_scan_type,
3412 	dummy,
3413-	r8180_wx_set_rawtx,
3414+	dummy,
3415 	dummy,
3416 	r8180_wx_set_iwmode,
3417 	r8180_wx_get_iwmode,
3418@@ -1101,8 +1153,8 @@
3419 	r8180_wx_get_sigqual,
3420 	r8180_wx_reset_stats,
3421 	dummy,
3422-	r8180_wx_radio_on,
3423-	r8180_wx_radio_off,
3424+	dummy,
3425+	dummy,
3426 	r8180_wx_set_channelplan,
3427 	r8180_wx_get_channelplan,
3428 	dummy,
3429diff -Naur r8187_orig/rtl8187/r8187_core.c r8187_rawtx/rtl8187/r8187_core.c
3430--- r8187_orig/rtl8187/r8187_core.c	2007-03-28 08:39:13.000000000 +0200
3431+++ r8187_rawtx/rtl8187/r8187_core.c	2007-05-16 21:51:33.000000000 +0200
3432@@ -1,27 +1,27 @@
3433 /*
3434    This is part of rtl8187 OpenSource driver - v 0.1
3435-   Copyright (C) Andrea Merello 2005  <andreamrl@tiscali.it>
3436+   Copyright (C) Andrea Merello 2005  <andreamrl@tiscali.it>
3437    Released under the terms of GPL (General Public License)
3438-
3439-
3440-   Parts of this driver are based on the rtl8180 driver skeleton
3441+
3442+
3443+   Parts of this driver are based on the rtl8180 driver skeleton
3444    from Patric Schenke & Andres Salomon.
3445
3446    Parts of this driver are based on the Intel Pro Wireless 2*00 GPL drivers.
3447-
3448+
3449    some ideas might be derived from David Young rtl8180 netbsd driver.
3450-
3451+
3452    Parts of the usb code are from the r8150.c driver in linux kernel
3453-
3454+
3455    Some ideas borrowed from the 8139too.c driver included in linux kernel.
3456-
3457-   We (I?) want to thanks the Authors of those projecs and also the
3458+
3459+   We (I?) want to thanks the Authors of those projecs and also the
3460    Ndiswrapper's project Authors.
3461-
3462-   A special big thanks goes also to Realtek corp. for their help in my
3463-   attempt to add RTL8187 and RTL8225 support, and to David Young also.
3464
3465-	- Please note that this file is a modified version from rtl8180-sa2400
3466+   A special big thanks goes also to Realtek corp. for their help in my
3467+   attempt to add RTL8187 and RTL8225 support, and to David Young also.
3468+
3469+	- Please note that this file is a modified version from rtl8180-sa2400
3470 	drv. So some other people have contributed to this project, and they are
3471 	thanked in the rtl8180-sa2400 CHANGELOG.
3472 */
3473@@ -83,6 +83,10 @@
3474 #define USB_VENDOR_ID_NETGEAR		0x0846
3475 #endif
3476
3477+#if !(defined(CONFIG_USB_EHCI_HCD) || defined (CONFIG_USB_EHCI_HCD_MODULE))
3478+	#error	Build your kernel with ehci_hcd support!
3479+#endif
3480+
3481 static struct usb_device_id rtl8187_usb_id_tbl[] = {
3482 	{USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8187)},
3483 	{USB_DEVICE(USB_VENDOR_ID_NETGEAR, 0x6100)},
3484@@ -137,7 +141,7 @@
3485
3486 static int __devinit rtl8187_usb_probe(struct usb_interface *intf,
3487 			 const struct usb_device_id *id);
3488-
3489+
3490 static void __devexit rtl8187_usb_disconnect(struct usb_interface *intf);
3491
3492 static struct usb_driver rtl8187_usb_driver = {
3493@@ -161,10 +165,10 @@
3494
3495 void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
3496 {
3497-
3498+
3499 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3500 	struct usb_device *udev = priv->udev;
3501-
3502+
3503 	usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3504 			       RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
3505 			       indx|0xfe00, 0, &data, 1, HZ / 2);
3506@@ -173,10 +177,10 @@
3507
3508 void write_nic_byte(struct net_device *dev, int indx, u8 data)
3509 {
3510-
3511+
3512 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3513 	struct usb_device *udev = priv->udev;
3514-
3515+
3516 	usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3517 			       RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
3518 			       indx|0xff00, 0, &data, 1, HZ / 2);
3519@@ -185,10 +189,10 @@
3520
3521 void write_nic_word(struct net_device *dev, int indx, u16 data)
3522 {
3523-
3524+
3525 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3526 	struct usb_device *udev = priv->udev;
3527-
3528+
3529 	usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3530 			       RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
3531 			       indx|0xff00, 0, &data, 2, HZ / 2);
3532@@ -197,23 +201,23 @@
3533
3534 void write_nic_dword(struct net_device *dev, int indx, u32 data)
3535 {
3536-
3537+
3538 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3539 	struct usb_device *udev = priv->udev;
3540-
3541+
3542 	usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3543 			       RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
3544 			       indx|0xff00, 0, &data, 4, HZ / 2);
3545 }
3546-
3547-
3548-
3549+
3550+
3551+
3552 u8 read_nic_byte(struct net_device *dev, int indx)
3553 {
3554 	u8 data;
3555 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3556 	struct usb_device *udev = priv->udev;
3557-
3558+
3559 	usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
3560 			       RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
3561 			       indx|0xff00, 0, &data, 1, HZ / 2);
3562@@ -225,20 +229,20 @@
3563 	u8 data;
3564 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3565 	struct usb_device *udev = priv->udev;
3566-
3567+
3568 	usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
3569 			       RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
3570 			       indx|0xfe00, 0, &data, 1, HZ / 2);
3571 	return data;
3572 }
3573
3574-
3575+
3576 u16 read_nic_word(struct net_device *dev, int indx)
3577 {
3578 	u16 data;
3579 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3580 	struct usb_device *udev = priv->udev;
3581-
3582+
3583 	usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
3584 			       RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
3585 			       indx|0xff00, 0, &data, 2, HZ / 2);
3586@@ -251,14 +255,14 @@
3587 	u32 data;
3588 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3589 	struct usb_device *udev = priv->udev;
3590-
3591+
3592 	usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
3593 			       RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
3594 			       indx|0xff00, 0, &data, 4, HZ / 2);
3595 	return data;
3596 }
3597
3598-/* this might still called in what was the PHY rtl8185/rtl8187 common code
3599+/* this might still called in what was the PHY rtl8185/rtl8187 common code
3600  * plans are to possibilty turn it again in one common code...
3601  */
3602 inline void force_pci_posting(struct net_device *dev)
3603@@ -271,8 +275,17 @@
3604 //void set_nic_txring(struct net_device *dev);
3605 static struct net_device_stats *rtl8180_stats(struct net_device *dev);
3606 void rtl8180_commit(struct net_device *dev);
3607-void rtl8180_restart(struct net_device *dev);
3608+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3609+void rtl8180_rq_tx_ack(struct work_struct *work);
3610+#else
3611 void rtl8180_rq_tx_ack(struct net_device *dev);
3612+#endif
3613+
3614+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3615+void rtl8180_restart(struct work_struct *work);
3616+#else
3617+void rtl8180_restart(struct net_device *dev);
3618+#endif
3619
3620 /****************************************************************************
3621    -----------------------------PROCFS STUFF-------------------------
3622@@ -286,12 +299,12 @@
3623 {
3624 	struct net_device *dev = data;
3625 //	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3626-
3627+
3628 	int len = 0;
3629 	int i,n;
3630-
3631+
3632 	int max=0xff;
3633-
3634+
3635 	/* This dump the current register page */
3636 	for(n=0;n<=max;)
3637 	{
3638@@ -308,7 +321,7 @@
3639 	len += snprintf(page + len, count - len,"\n");
3640
3641
3642-
3643+
3644 	*eof = 1;
3645 	return len;
3646
3647@@ -321,15 +334,15 @@
3648 {
3649 	struct net_device *dev = data;
3650 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3651-
3652+
3653 	int len = 0;
3654-
3655+
3656 	len += snprintf(page + len, count - len,
3657 		"NIC int: %lu\n"
3658 		"Total int: %lu\n",
3659 		priv->stats.ints,
3660 		priv->stats.shints);
3661-
3662+
3663 	*eof = 1;
3664 	return len;
3665 }
3666@@ -341,12 +354,12 @@
3667 {
3668 	struct net_device *dev = data;
3669 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3670-
3671+
3672 	int len = 0;
3673 	unsigned long totalOK;
3674 	totalOK=priv->stats.txnpokint+priv->stats.txhpokint+priv->stats.txlpokint;
3675
3676-
3677+
3678 	len += snprintf(page + len, count - len,
3679 	/*	"TX normal priority ok int: %lu\n"
3680 		"TX normal priority error int: %lu\n"
3681@@ -363,7 +376,7 @@
3682 		"TX HW queue: %d\n"
3683 		"TX lp dropped: %lu\n"
3684 		"TX np dropped: %lu\n"
3685-		"TX total data packets %lu\n",
3686+		"TX total data packets %lu\n",
3687 //		"TX beacon aborted: %lu\n",
3688 		priv->stats.txnpokint,
3689 		priv->stats.txnperr,
3690@@ -391,13 +404,13 @@
3691 		priv->stats.txerr,
3692 		priv->stats.txretry,
3693 		priv->stats.txbeaconok,
3694-		priv->stats.txbeaconerr
3695+		priv->stats.txbeaconerr
3696
3697 		);
3698-
3699+
3700 	*eof = 1;
3701 	return len;
3702-}
3703+}
3704
3705
3706
3707@@ -407,9 +420,9 @@
3708 {
3709 	struct net_device *dev = data;
3710 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3711-
3712+
3713 	int len = 0;
3714-
3715+
3716 	len += snprintf(page + len, count - len,
3717 		/*"RX packets: %lu\n"
3718 		"RX urb status error: %lu\n"
3719@@ -431,21 +444,22 @@
3720 		priv->stats.rxicverr
3721
3722 	);
3723-
3724+
3725 	*eof = 1;
3726 	return len;
3727-}
3728-
3729+}
3730
3731+#if WIRELESS_EXT < 17
3732 static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev)
3733 {
3734        struct r8180_priv *priv = ieee80211_priv(dev);
3735
3736        return &priv->wstats;
3737 }
3738+#endif
3739
3740 void rtl8180_proc_module_init(void)
3741-{
3742+{
3743 	DMESG("Initializing proc filesystem");
3744 	rtl8180_proc=create_proc_entry(RTL8187_MODULE_NAME, S_IFDIR, proc_net);
3745 }
3746@@ -477,8 +491,8 @@
3747 {
3748 	struct proc_dir_entry *e;
3749 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3750-	priv->dir_dev = create_proc_entry(dev->name,
3751-					  S_IFDIR | S_IRUGO | S_IXUGO,
3752+	priv->dir_dev = create_proc_entry(dev->name,
3753+					  S_IFDIR | S_IRUGO | S_IXUGO,
3754 					  rtl8180_proc);
3755 	if (!priv->dir_dev) {
3756 		DMESGE("Unable to initialize /proc/net/rtl8187/%s\n",
3757@@ -488,7 +502,7 @@
3758 	#if 0
3759 	e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
3760 				   priv->dir_dev, proc_get_stats_hw, dev);
3761-
3762+
3763 	if (!e) {
3764 		DMESGE("Unable to initialize "
3765 		      "/proc/net/rtl8187/%s/stats-hw\n",
3766@@ -497,17 +511,17 @@
3767 	#endif
3768 	e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
3769 				   priv->dir_dev, proc_get_stats_rx, dev);
3770-
3771+
3772 	if (!e) {
3773 		DMESGE("Unable to initialize "
3774 		      "/proc/net/rtl8187/%s/stats-rx\n",
3775 		      dev->name);
3776 	}
3777-
3778-
3779+
3780+
3781 	e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
3782 				   priv->dir_dev, proc_get_stats_tx, dev);
3783-
3784+
3785 	if (!e) {
3786 		DMESGE("Unable to initialize "
3787 		      "/proc/net/rtl8187/%s/stats-tx\n",
3788@@ -516,27 +530,27 @@
3789 	#if 0
3790 	e = create_proc_read_entry("stats-ieee", S_IFREG | S_IRUGO,
3791 				   priv->dir_dev, proc_get_stats_ieee, dev);
3792-
3793+
3794 	if (!e) {
3795 		DMESGE("Unable to initialize "
3796 		      "/proc/net/rtl8187/%s/stats-ieee\n",
3797 		      dev->name);
3798 	}
3799-
3800-
3801+
3802+
3803 	e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
3804 				   priv->dir_dev, proc_get_stats_ap, dev);
3805-
3806+
3807 	if (!e) {
3808 		DMESGE("Unable to initialize "
3809 		      "/proc/net/rtl8187/%s/stats-ap\n",
3810 		      dev->name);
3811 	}
3812 	#endif
3813-
3814+
3815 	e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
3816 				   priv->dir_dev, proc_get_registers, dev);
3817-
3818+
3819 	if (!e) {
3820 		DMESGE("Unable to initialize "
3821 		      "/proc/net/rtl8187/%s/registers\n",
3822@@ -552,14 +566,14 @@
3823 {
3824 	int i;
3825 	u8 *buf =(u8*)buffer;
3826-
3827+
3828 	printk("ASCII BUFFER DUMP (len: %x):\n",len);
3829-
3830+
3831 	for(i=0;i<len;i++)
3832 		printk("%c",buf[i]);
3833-
3834+
3835 	printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
3836-
3837+
3838 	for(i=0;i<len;i++)
3839 		printk("%x",buf[i]);
3840
3841@@ -569,10 +583,10 @@
3842 short check_nic_enought_desc(struct net_device *dev, priority_t priority)
3843 {
3844 	struct r8180_priv *priv = ieee80211_priv(dev);
3845-
3846-	int used = atomic_read((priority == NORM_PRIORITY) ?
3847+
3848+	int used = atomic_read((priority == NORM_PRIORITY) ?
3849 		&priv->tx_np_pending : &priv->tx_lp_pending);
3850-
3851+
3852 	return (used < MAX_TX_URB);
3853 }
3854
3855@@ -600,9 +614,9 @@
3856 	int i;
3857 	int n;
3858 	int max=0xff;
3859-
3860-	DMESG("Dumping NIC register map");
3861-
3862+
3863+	DMESG("Dumping NIC register map");
3864+
3865 	for(n=0;n<=max;)
3866 	{
3867 		printk( "\nD: %2x> ", n);
3868@@ -619,11 +633,11 @@
3869
3870 void rtl8180_irq_enable(struct net_device *dev)
3871 {
3872-	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3873+	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3874 	//priv->irq_enabled = 1;
3875 /*
3876-	write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
3877-	INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
3878+	write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
3879+	INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
3880 	INTA_NORMPRIORITYDESCERR | INTA_NORMPRIORITYDESCOK |\
3881 	INTA_LOWPRIORITYDESCERR | INTA_LOWPRIORITYDESCOK | INTA_TIMEOUT);
3882 */
3883@@ -633,7 +647,7 @@
3884
3885 void rtl8180_irq_disable(struct net_device *dev)
3886 {
3887-//	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3888+//	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3889
3890 	write_nic_word(dev,INTA_MASK,0);
3891 	force_pci_posting(dev);
3892@@ -657,27 +671,27 @@
3893 {
3894 	struct r8180_priv *priv = ieee80211_priv(dev);
3895 	u8 msr;
3896-
3897+
3898 	msr  = read_nic_byte(dev, MSR);
3899 	msr &= ~ MSR_LINK_MASK;
3900-
3901+
3902 	/* do not change in link_state != WLAN_LINK_ASSOCIATED.
3903-	 * msr must be updated if the state is ASSOCIATING.
3904+	 * msr must be updated if the state is ASSOCIATING.
3905 	 * this is intentional and make sense for ad-hoc and
3906 	 * master (see the create BSS/IBSS func)
3907 	 */
3908-	if (priv->ieee80211->state == IEEE80211_LINKED){
3909-
3910+	if (priv->ieee80211->state == IEEE80211_LINKED){
3911+
3912 		if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
3913 			msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
3914 		else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3915 			msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
3916 		else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
3917 			msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
3918-
3919+
3920 	}else
3921 		msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
3922-
3923+
3924 	write_nic_byte(dev, MSR, msr);
3925 }
3926
3927@@ -687,20 +701,20 @@
3928 	u32 tx;
3929 	priv->chan=ch;
3930 	#if 0
3931-	if(priv->ieee80211->iw_mode == IW_MODE_ADHOC ||
3932+	if(priv->ieee80211->iw_mode == IW_MODE_ADHOC ||
3933 		priv->ieee80211->iw_mode == IW_MODE_MASTER){
3934-
3935-			priv->ieee80211->link_state = WLAN_LINK_ASSOCIATED;
3936+
3937+			priv->ieee80211->link_state = WLAN_LINK_ASSOCIATED;
3938 			priv->ieee80211->master_chan = ch;
3939-			rtl8180_update_beacon_ch(dev);
3940+			rtl8180_update_beacon_ch(dev);
3941 		}
3942 	#endif
3943-
3944+
3945 	/* this hack should avoid frame TX during channel setting*/
3946 	tx = read_nic_dword(dev,TX_CONF);
3947 	tx &= ~TX_LOOPBACK_MASK;
3948
3949-#ifndef LOOP_TEST
3950+#ifndef LOOP_TEST
3951 	write_nic_dword(dev,TX_CONF, tx |( TX_LOOPBACK_MAC<<TX_LOOPBACK_SHIFT));
3952
3953 	priv->rf_set_chan(dev,priv->chan);
3954@@ -715,25 +729,25 @@
3955 {
3956 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3957 	int err;
3958-
3959+
3960 //	u8 *rx;
3961-
3962+
3963 	//DMESG("starting RX");
3964 	/*rx = kmalloc(RX_URB_SIZE*sizeof(u8),GFP_ATOMIC);
3965-	if(!rx){
3966+	if(!rx){
3967 		DMESGE("unable to allocate RX buffer");
3968 		return;
3969 	}*/
3970-
3971+
3972 	usb_fill_bulk_urb(rx_urb,priv->udev,
3973 		usb_rcvbulkpipe(priv->udev,0x81), rx_urb->transfer_buffer,
3974-			RX_URB_SIZE,rtl8187_rx_isr,dev);
3975-	err = usb_submit_urb(rx_urb, GFP_ATOMIC);
3976+			RX_URB_SIZE,rtl8187_rx_isr, dev);
3977+	err = usb_submit_urb(rx_urb, GFP_ATOMIC);
3978 	if(err && err != -EPERM){
3979 		DMESGE("cannot submit RX command. URB_STATUS %x",rx_urb->status);
3980-
3981+
3982 	}
3983-
3984+
3985 }
3986
3987
3988@@ -741,30 +755,30 @@
3989 {
3990 	int i;
3991 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3992-
3993+
3994 	if(!priv->rx_urb)
3995 		DMESGE("Cannot intiate RX urb mechanism");
3996-	for(i=0;i<MAX_RX_URB;i++) // RX_MAX_URB is 1
3997+	for(i=0;i<MAX_RX_URB;i++) // RX_MAX_URB is 1
3998 		rtl8187_rx_urbsubmit(dev,priv->rx_urb[i]);
3999 	priv->tx_urb_index = 0;
4000-
4001+
4002 }
4003
4004 void rtl8187_set_rxconf(struct net_device *dev)
4005 {
4006 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4007 	u32 rxconf;
4008-
4009+
4010 	rxconf=read_nic_dword(dev,RX_CONF);
4011 	rxconf = rxconf &~ MAC_FILTER_MASK;
4012 	rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
4013 	rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
4014 	rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
4015 	rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
4016-	rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
4017+	rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
4018
4019 	if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
4020-
4021+
4022 	if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
4023 	   dev->flags & IFF_PROMISC){
4024 		rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
4025@@ -772,40 +786,40 @@
4026 		rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
4027 		rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
4028 	}
4029-
4030+
4031 	/*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
4032 		rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
4033 		rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
4034 	}*/
4035-
4036+
4037 	if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
4038 		rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
4039 		rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
4040 	}
4041-
4042+
4043 	if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
4044 		rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
4045-
4046-
4047+
4048+
4049 	rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
4050 	rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
4051-
4052-
4053+
4054+
4055 	rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
4056-
4057+
4058 	rxconf = rxconf &~ MAX_RX_DMA_MASK;
4059 	rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
4060-
4061+
4062 	rxconf = rxconf | RCR_ONLYERLPKT;
4063-
4064+
4065 //	rxconf = rxconf &~ RCR_CS_MASK;
4066 //	rxconf = rxconf | (1<<RCR_CS_SHIFT);
4067
4068-	write_nic_dword(dev, RX_CONF, rxconf);
4069-
4070+	write_nic_dword(dev, RX_CONF, rxconf);
4071+
4072 	// V rtl suggested V //
4073 //	write_nic_dword(dev, RX_CONF, 0x901ce70e);
4074-
4075+
4076 	//fix_rx_fifo(dev);
4077 // 	//set_nic_rxring(dev);
4078 	#ifdef DEBUG_RX
4079@@ -816,23 +830,23 @@
4080 void rtl8180_rx_enable(struct net_device *dev)
4081 {
4082 	u8 cmd;
4083-
4084-
4085+
4086+
4087 	rtl8187_rx_initiate(dev);
4088
4089-	rtl8187_set_rxconf(dev);
4090+	rtl8187_set_rxconf(dev);
4091
4092 	cmd=read_nic_byte(dev,CMD);
4093 	write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
4094 #if 0
4095-	/* In rtl8139 driver seems that DMA threshold has to be written
4096-	 *  after enabling RX, so we rewrite RX_CONFIG register
4097+	/* In rtl8139 driver seems that DMA threshold has to be written
4098+	 *  after enabling RX, so we rewrite RX_CONFIG register
4099 	 */
4100 	//mdelay(100);
4101-	write_nic_dword(dev, RX_CONF, rxconf);
4102-
4103+	write_nic_dword(dev, RX_CONF, rxconf);
4104+
4105 #endif
4106-
4107+
4108 }
4109
4110
4111@@ -842,36 +856,36 @@
4112 	u8 byte;
4113 	u32 txconf;
4114 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4115-
4116+
4117 	byte = read_nic_byte(dev,CW_CONF);
4118 	byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
4119 	byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
4120 	write_nic_byte(dev, CW_CONF, byte);
4121-
4122+
4123 	byte = read_nic_byte(dev, TX_AGC_CTL);
4124 	byte &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
4125 	byte &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
4126 	byte &= ~(1<<TX_AGC_CTL_FEEDBACK_ANT);
4127 	write_nic_byte(dev, TX_AGC_CTL, byte);
4128-
4129+
4130 	txconf= read_nic_dword(dev,TX_CONF);
4131-
4132+
4133 	#if 0
4134 	if(priv->card_8185){
4135-
4136+
4137 		txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
4138-
4139+
4140 	}else{
4141-
4142-		if(priv->ieee80211->hw_seq)
4143+
4144+		if(priv->ieee80211->hw_seq)
4145 			txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
4146-		else
4147+		else
4148 			txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
4149 	}
4150 	#endif
4151
4152 	txconf = txconf &~ TX_LOOPBACK_MASK;
4153-
4154+
4155 #ifndef LOOP_TEST
4156 	txconf = txconf | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT);
4157 #else
4158@@ -879,23 +893,26 @@
4159 #endif
4160 	txconf = txconf &~ TCR_DPRETRY_MASK;
4161 	txconf = txconf &~ TCR_RTSRETRY_MASK;
4162-
4163-	txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT); // long
4164-	txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT); // short
4165-
4166+
4167+	if(priv->ieee80211->iw_mode != IW_MODE_MONITOR)
4168+	{
4169+		txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT); // long
4170+		txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT); // short
4171+	}
4172+
4173 	txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
4174-
4175+
4176 	txconf = txconf &~ TCR_MXDMA_MASK;
4177 	txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
4178-
4179+
4180 	txconf = txconf | TCR_CWMIN;
4181 	txconf = txconf | TCR_DISCW;
4182 	txconf = txconf &~ TCR_SWPLCPLEN;
4183-
4184+
4185 	txconf=txconf | (1<<TX_NOICV_SHIFT);
4186-
4187+
4188 	write_nic_dword(dev,TX_CONF,txconf);
4189-
4190+
4191 	// V RTL suggested V //
4192 //	write_nic_dword(dev,TX_CONF,0x00e00707);
4193
4194@@ -903,9 +920,9 @@
4195 #ifdef DEBUG_TX
4196 	DMESG("txconf: %x %x",txconf,read_nic_dword(dev,TX_CONF));
4197 #endif
4198-
4199+
4200 	cmd=read_nic_byte(dev,CMD);
4201-	write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
4202+	write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
4203
4204 //	mdelay(100);
4205 	//write_nic_dword(dev,TX_CONF,txconf);
4206@@ -923,13 +940,13 @@
4207 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4208 	priv->dma_poll_mask &=~(1<<TX_DMA_STOP_BEACON_SHIFT);
4209 	rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
4210-	write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
4211+	write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
4212 	rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
4213 }
4214
4215
4216 void rtl8180_
4217-_disable(struct net_device *dev)
4218+_disable(struct net_device *dev)
4219 {
4220 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4221 	priv->dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
4222@@ -946,7 +963,7 @@
4223 	u8 cmd;
4224 	int i;
4225 	struct r8180_priv *priv = ieee80211_priv(dev);
4226-
4227+
4228 	cmd=read_nic_byte(dev,CMD);
4229 	write_nic_byte(dev, CMD, cmd &~ \
4230 		       ((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
4231@@ -957,9 +974,9 @@
4232 		usb_kill_urb(priv->rx_urb[i]);
4233 	}
4234 	/*while (read_nic_byte(dev,CMD) & (1<<CMD_RX_ENABLE_SHIFT))
4235-	  udelay(10);
4236+	  udelay(10);
4237 	*/
4238-
4239+
4240 //	if(!priv->rx_skb_complete)
4241 //		dev_kfree_skb_any(priv->rx_skb);
4242 }
4243@@ -971,13 +988,13 @@
4244 	int i;
4245 	u32 *tmp;
4246 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4247-
4248+
4249 	priv->txbeaconring = (u32*)pci_alloc_consistent(priv->pdev,
4250-					  sizeof(u32)*8*count,
4251+					  sizeof(u32)*8*count,
4252 					  &priv->txbeaconringdma);
4253 	if (!priv->txbeaconring) return -1;
4254 	for (tmp=priv->txbeaconring,i=0;i<count;i++){
4255-		*tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
4256+		*tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
4257 		/*
4258 		*(tmp+2) = (u32)dma_tmp;
4259 		*(tmp+3) = bufsize;
4260@@ -986,7 +1003,7 @@
4261 			*(tmp+4) = (u32)priv->txbeaconringdma+((i+1)*8*4);
4262 		else
4263 			*(tmp+4) = (u32)priv->txbeaconringdma;
4264-
4265+
4266 		tmp=tmp+8;
4267 	}
4268 	#endif
4269@@ -996,15 +1013,15 @@
4270
4271 void rtl8180_reset(struct net_device *dev)
4272 {
4273-
4274+
4275 	u8 cr;
4276-
4277+
4278 	/* make sure the analog power is on before
4279 	 * reset, otherwise reset may fail
4280 	 */
4281 	rtl8180_set_anaparam(dev, RTL8225_ANAPARAM_ON);
4282 	rtl8185_set_anaparam2(dev, RTL8225_ANAPARAM2_ON);
4283-
4284+
4285 	rtl8180_irq_disable(dev);
4286
4287 	mdelay(200);
4288@@ -1012,19 +1029,19 @@
4289 	write_nic_byte_E(dev,0x18,0x11);
4290 	write_nic_byte_E(dev,0x18,0x00);
4291 	mdelay(200);
4292-
4293+
4294 	cr=read_nic_byte(dev,CMD);
4295 	cr = cr & 2;
4296 	cr = cr | (1<<CMD_RST_SHIFT);
4297 	write_nic_byte(dev,CMD,cr);
4298-
4299+
4300 	force_pci_posting(dev);
4301-
4302+
4303 	mdelay(200);
4304-
4305-	if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
4306+
4307+	if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
4308 		DMESGW("Card reset timeout!");
4309-	else
4310+	else
4311 		DMESG("Card successfully reset");
4312
4313 	rtl8180_set_mode(dev,EPROM_CMD_LOAD);
4314@@ -1036,13 +1053,13 @@
4315 	 */
4316 	rtl8180_set_anaparam(dev, RTL8225_ANAPARAM_ON);
4317 	rtl8185_set_anaparam2(dev, RTL8225_ANAPARAM2_ON);
4318-
4319+
4320 }
4321
4322 inline u16 ieeerate2rtlrate(int rate)
4323 {
4324 	switch(rate){
4325-	case 10:
4326+	case 10:
4327 	return 0;
4328 	case 20:
4329 	return 1;
4330@@ -1068,14 +1085,14 @@
4331 	return 11;
4332 	default:
4333 	return 3;
4334-
4335+
4336 	}
4337 }
4338 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
4339 inline u16 rtl8180_rate2rate(short rate)
4340 {
4341 	if (rate >11) return 0;
4342-	return rtl_rate[rate];
4343+	return rtl_rate[rate];
4344 }
4345
4346
4347@@ -1089,49 +1106,49 @@
4348 u16 N_DBPSOfRate(u16 DataRate)
4349 {
4350 	 u16 N_DBPS = 24;
4351-
4352+
4353 	 switch(DataRate)
4354 	 {
4355 	 case 60:
4356 	  N_DBPS = 24;
4357 	  break;
4358-
4359+
4360 	 case 90:
4361 	  N_DBPS = 36;
4362 	  break;
4363-
4364+
4365 	 case 120:
4366 	  N_DBPS = 48;
4367 	  break;
4368-
4369+
4370 	 case 180:
4371 	  N_DBPS = 72;
4372 	  break;
4373-
4374+
4375 	 case 240:
4376 	  N_DBPS = 96;
4377 	  break;
4378-
4379+
4380 	 case 360:
4381 	  N_DBPS = 144;
4382 	  break;
4383-
4384+
4385 	 case 480:
4386 	  N_DBPS = 192;
4387 	  break;
4388-
4389+
4390 	 case 540:
4391 	  N_DBPS = 216;
4392 	  break;
4393-
4394+
4395 	 default:
4396 	  break;
4397 	 }
4398-
4399+
4400 	 return N_DBPS;
4401 }
4402
4403-u16 ComputeTxTime(
4404+u16 ComputeTxTime(
4405 	u16		FrameLength,
4406 	u16		DataRate,
4407 	u8		bManagementFrame,
4408@@ -1146,7 +1163,7 @@
4409 	{
4410 		if( bManagementFrame || !bShortPreamble || DataRate == 10 )
4411 		{	// long preamble
4412-			FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
4413+			FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
4414 		}
4415 		else
4416 		{	// Short preamble
4417@@ -1156,14 +1173,14 @@
4418 				FrameTime ++;
4419 	} else {	//802.11g DSSS-OFDM PLCP length field calculation.
4420 		N_DBPS = N_DBPSOfRate(DataRate);
4421-		Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
4422+		Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
4423 				+ (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
4424 		FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
4425 	}
4426 	return FrameTime;
4427 }
4428
4429-
4430+
4431 #if 0
4432 void rtl8187_rx_isr(struct urb *rx_urb, struct pt_regs *regs)
4433 {
4434@@ -1172,7 +1189,7 @@
4435
4436 	priv->rxurb_task = rx_urb;
4437 //	DMESGW("David: Rx tasklet start!");
4438-	tasklet_schedule(&priv->irq_rx_tasklet);
4439+	tasklet_schedule(&priv->irq_rx_tasklet);
4440 //	DMESGW("=David: Rx tasklet finish!");
4441 }
4442 #endif
4443@@ -1223,13 +1240,14 @@
4444 void rtl8180_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
4445 {
4446 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4447-
4448-	short morefrag = 0;
4449+
4450+	short morefrag = 0;
4451 	unsigned long flags;
4452 	struct ieee80211_hdr *h = (struct ieee80211_hdr  *) skb->data;
4453
4454-	if (le16_to_cpu(h->frame_ctl) & IEEE80211_FCTL_MOREFRAGS)
4455-		morefrag = 1;
4456+	if(priv->ieee80211->iw_mode != IW_MODE_MONITOR)
4457+		if (le16_to_cpu(h->frame_ctl) & IEEE80211_FCTL_MOREFRAGS)
4458+			morefrag = 1;
4459 //	DMESG("%x %x", h->frame_ctl, h->seq_ctl);
4460 	/*
4461 	* This function doesn't require lock because we make
4462@@ -1238,25 +1256,24 @@
4463 	* the ieee stack, or from the try_wake_queue (again trought
4464 	* the ieee stack.
4465 	*/
4466-	spin_lock_irqsave(&priv->tx_lock,flags);
4467-
4468+	spin_lock_irqsave(&priv->tx_lock,flags);
4469+
4470 	//DMESG("TX");
4471 	if (!check_nic_enought_desc(dev, LOW_PRIORITY)){
4472 		DMESG("Error: no TX slot ");
4473 		ieee80211_stop_queue(priv->ieee80211);
4474 	}
4475-
4476-
4477+
4478 	rtl8180_tx(dev, skb->data, skb->len, LOW_PRIORITY, morefrag,
4479 		ieeerate2rtlrate(rate));
4480
4481 	priv->stats.txdatapkt++;
4482-
4483+
4484 	if (!check_nic_enought_desc(dev, LOW_PRIORITY))
4485 		ieee80211_stop_queue(priv->ieee80211);
4486-
4487-	spin_unlock_irqrestore(&priv->tx_lock,flags);
4488-
4489+
4490+	spin_unlock_irqrestore(&priv->tx_lock,flags);
4491+
4492 }
4493 #if 0
4494 /* This is a rough attempt to TX a frame
4495@@ -1269,9 +1286,9 @@
4496 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4497 	int ret;
4498 	unsigned long flags;
4499-
4500+
4501 	spin_lock_irqsave(&priv->tx_lock,flags);
4502-
4503+
4504 	ret = rtl8180_tx(dev, (u32*)skb->data, skb->len, NORM_PRIORITY, 0,DEFAULT_BASICRATE);
4505 /*
4506 	int i;
4507@@ -1281,9 +1298,9 @@
4508 */
4509 	priv->ieee80211->stats.tx_bytes+=skb->len;
4510 	priv->ieee80211->stats.tx_packets++;
4511-
4512-	spin_unlock_irqrestore(&priv->tx_lock,flags);
4513-
4514+
4515+	spin_unlock_irqrestore(&priv->tx_lock,flags);
4516+
4517 	dev_kfree_skb_any(skb);
4518 	return ret;
4519 }
4520@@ -1296,7 +1313,7 @@
4521 	u16 duration;
4522 	u16 drift;
4523 	*ext=0;
4524-
4525+
4526 	switch(rate){
4527 	case 0://1mbps
4528 		*ext=0;
4529@@ -1305,7 +1322,7 @@
4530 		if(drift ==0 ) break;
4531 		duration++;
4532 		break;
4533-
4534+
4535 	case 1://2mbps
4536 		*ext=0;
4537 		duration = ((len+4)<<4) /0x4;
4538@@ -1313,30 +1330,30 @@
4539 		if(drift ==0 ) break;
4540 		duration++;
4541 		break;
4542-
4543+
4544 	case 2: //5.5mbps
4545 		*ext=0;
4546 		duration = ((len+4)<<4) /0xb;
4547 		drift = ((len+4)<<4) % 0xb;
4548-		if(drift ==0 )
4549+		if(drift ==0 )
4550 			break;
4551 		duration++;
4552 		break;
4553-
4554+
4555 	default:
4556-	case 3://11mbps
4557+	case 3://11mbps
4558 		*ext=0;
4559 		duration = ((len+4)<<4) /0x16;
4560 		drift = ((len+4)<<4) % 0x16;
4561-		if(drift ==0 )
4562+		if(drift ==0 )
4563 			break;
4564 		duration++;
4565-		if(drift > 6)
4566+		if(drift > 6)
4567 			break;
4568 		*ext=1;
4569 		break;
4570 	}
4571-
4572+
4573 	return duration;
4574 }
4575 #endif
4576@@ -1369,10 +1386,10 @@
4577 	if ((msrm == (MSR_LINK_ADHOC<<MSR_LINK_SHIFT) ||
4578 		(msrm == (MSR_LINK_MASTER<<MSR_LINK_SHIFT)))){
4579 		write_nic_byte(dev, MSR, msr2 | MSR_LINK_NONE);
4580-		write_nic_byte(dev, MSR, msr);
4581+		write_nic_byte(dev, MSR, msr);
4582 	}
4583-
4584-
4585+
4586+
4587 }
4588
4589
4590@@ -1382,21 +1399,21 @@
4591 	struct r8180_priv *priv = ieee80211_priv(dev);
4592 	struct ieee80211_network *net;
4593 	net = & priv->ieee80211->current_network;
4594-
4595-
4596+
4597+
4598 	write_nic_dword(dev,BSSID,((u32*)net->bssid)[0]);
4599 	write_nic_word(dev,BSSID+4,((u16*)net->bssid)[2]);
4600 	//for(i=0;i<ETH_ALEN;i++)
4601 	//	write_nic_byte(dev,BSSID+i,net->bssid[i]);
4602
4603 	rtl8180_update_msr(dev);
4604-
4605+
4606 //	rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
4607 	write_nic_word(dev, AtimWnd, 2);
4608-	write_nic_word(dev, AtimtrItv, 100);
4609+	write_nic_word(dev, AtimtrItv, 100);
4610 	write_nic_word(dev, BEACON_INTERVAL, net->beacon_interval);
4611 	write_nic_word(dev, BcnIntTime, 100);
4612-
4613+
4614
4615 }
4616
4617@@ -1406,18 +1423,18 @@
4618 	struct r8180_priv *priv = ieee80211_priv(dev);
4619 	struct sk_buff *skb;
4620 	int i = 0;
4621-
4622+
4623 	rtl8187_net_update(dev);
4624-
4625+
4626 	skb = ieee80211_get_beacon(priv->ieee80211);
4627-
4628-
4629-	if(!skb){
4630+
4631+
4632+	if(!skb){
4633 		DMESG("not enought memory for allocating beacon");
4634 		return;
4635 	}
4636-
4637-#if 0
4638+
4639+#if 0
4640 	while(MAX_TX_URB!=atomic_read(&priv->tx_np_pending)){
4641 		msleep_interruptible_rtl(HZ/2);
4642 		if(i++ > 20){
4643@@ -1427,7 +1444,7 @@
4644 	}
4645 #endif
4646 	write_nic_byte(dev, BQREQ, read_nic_byte(dev, BQREQ) | (1<<7));
4647-
4648+
4649 	i=0;
4650 	//while(!read_nic_byte(dev,BQREQ & (1<<7)))
4651 	while( (read_nic_byte(dev, BQREQ) & (1<<7)) == 0 )
4652@@ -1438,7 +1455,7 @@
4653 			return ;
4654 		}
4655 	}
4656-
4657+
4658 	rtl8180_tx(dev, skb->data, skb->len, NORM_PRIORITY,
4659 		0, priv->ieee80211->basic_rate);
4660
4661@@ -1461,15 +1478,15 @@
4662 }
4663
4664
4665-/* This function do the real dirty work: it sends a TX command
4666- * descriptor plus data URB
4667+/* This function do the real dirty work: it sends a TX command
4668+ * descriptor plus data URB
4669  */
4670-
4671+
4672 short rtl8180_tx(struct net_device *dev, u8* txbuf, int len, priority_t priority,
4673 		 short morefrag, short rate)
4674 {
4675 	//u32 *tx;
4676-	u8 *tx;
4677+	u8 *tx;
4678 	u8 *pdata;
4679 	u8 seg = ((u32)txbuf % 4);
4680 	u32 *pdata32;
4681@@ -1480,7 +1497,7 @@
4682 	int pend;
4683 	int status;
4684 	struct urb *tx_urb;
4685-	int urb_len;
4686+	int urb_len;
4687 	u16	AckCtsTime;
4688 	u16	FrameTime;
4689 	u16 duration;
4690@@ -1498,20 +1515,20 @@
4691 			priv->stats.txlpdrop++;
4692 		return -1;
4693 	}
4694-
4695-#if 0
4696+
4697+#if 0
4698 	//tx = kmalloc((len + 4*3), GFP_ATOMIC);
4699 	urb_len = len + 4*3;
4700 	if((0 == urb_len%64)||(0 == urb_len%512)) {
4701-	  urb_len += 1;
4702+	  urb_len += 1;
4703 	}
4704 	tx = kmalloc(urb_len, GFP_ATOMIC);
4705 	if(!tx) return -ENOMEM;
4706-	//printk(KERN_WARNING "urb_len = %d\n", urb_len);
4707+	//printk(KERN_WARNING "urb_len = %d\n", urb_len);
4708 	tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
4709-
4710+
4711 	if(!tx_urb){
4712-
4713+
4714 		kfree(tx);
4715 		return -ENOMEM;
4716 	}
4717@@ -1519,7 +1536,7 @@
4718 	//urb_len = TX_URB_SIZE;
4719 	urb_len = len + 4*3;
4720 	if((0 == urb_len%64)||(0 == urb_len%512)) {
4721-	  urb_len += 1;
4722+	  urb_len += 1;
4723 	}
4724
4725 	tx_urb = priv->tx_context[priv->tx_urb_index].tx_urb;
4726@@ -1527,7 +1544,7 @@
4727 	pdata = tx + 12;
4728 	priv->tx_urb_index = (priv->tx_urb_index + 1) % MAX_TX_URB;
4729 #endif
4730-#if 0
4731+#if 0
4732 	memcpy(tx+3,txbuf,len);
4733 	tx[0] = 0;
4734 	tx[0] |= len & 0xfff;
4735@@ -1535,7 +1552,7 @@
4736 //	printk(KERN_INFO "preamble mode %d,rate %d!\n",priv->plcp_preamble_mode,rate);
4737 	if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
4738 		if (priv->plcp_preamble_mode==1 && rate!=0) {	//  short mode now, not long!
4739-			tx[0] |= (1<<16);
4740+			tx[0] |= (1<<16);
4741 //			printk(KERN_INFO "use short preamble!\n");
4742 		}			// enable short preamble mode.
4743
4744@@ -1548,11 +1565,11 @@
4745 			AckCtsTime = ComputeTxTime(14, 10,0, 0);	// AckCTSLng = 14 use 1M bps send
4746 			FrameTime = ComputeTxTime(len + 4, rtl8180_rate2rate(rate), 0, tx[0]&(1<<16));
4747 			// RTS/CTS time is calculate as follow
4748-			duration = FrameTime + 3*10 + 2*AckCtsTime;	//10us is the SifsTime;
4749+			duration = FrameTime + 3*10 + 2*AckCtsTime;	//10us is the SifsTime;
4750 			tx[1] |= duration; 	//Need to edit here!  ----hikaru
4751 			printk(KERN_INFO "duration %d!\n",duration);
4752 	}
4753-	else
4754+	else
4755 		tx[1]=0;
4756 	//if(len > priv->rts_threshold){
4757 //		tx[0] |= (1<<23); //ENABLE RTS
4758@@ -1562,18 +1579,18 @@
4759 	tx[0] |= (ieeerate2rtlrate(priv->ieee80211->basic_rate) << 19); /* RTS RATE - should be basic rate */
4760 	tx[0] |= (rate << 24);
4761 //	tx[1] = 0;
4762-
4763+
4764 //	duration = rtl8180_len2duration(len,
4765-//		rate,&ext);
4766+//		rate,&ext);
4767 //	tx[1] |= (duration & 0x7fff) <<16;
4768 //	if(ext) tx[1] |= (1<<31);
4769
4770-
4771+
4772 //	tx[2] = 0x303020;
4773 	tx[2] = 3;  // CW min
4774 	tx[2] |= (7<<4); //CW max
4775 	tx[2] |= (11<<8);//(priv->retry_data<<8); //retry lim
4776-
4777+
4778 //	printk("%x\n%x\n",tx[0],tx[1]);
4779
4780 	#ifdef DUMP_TX
4781@@ -1601,12 +1618,12 @@
4782 	}
4783 #endif
4784 	//memcpy(pdata, txbuf, len);
4785-
4786+
4787 	//tx[0] = 0;
4788 	//tx[1] = 0;
4789 	tx[2] = 0;
4790 	tx[3] = 0;
4791-
4792+
4793 	//tx[0] |= len & 0xfff;
4794 	tx[0] = len & 0xff;
4795 	tx[1] = (len & 0x0f00) >> 8;
4796@@ -1614,25 +1631,25 @@
4797
4798 	if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
4799 		if (priv->plcp_preamble_mode==1 && rate!=0) {	//  short mode now, not long!
4800-			tx[2] |= 1;
4801+			tx[2] |= 1;
4802
4803-		}
4804+		}
4805
4806 	if ( (len>priv->rts) && priv->rts && priority==LOW_PRIORITY){
4807 			tx[2] |= (1<<7);	//enalbe RTS function
4808 			AckCtsTime = ComputeTxTime(14, 10,0, 0);	// AckCTSLng = 14 use 1M bps send
4809 			FrameTime = ComputeTxTime(len + 4, rtl8180_rate2rate(rate), 0, tx[2]&1);
4810 			// RTS/CTS time is calculate as follow
4811-			duration = FrameTime + 3*10 + 2*AckCtsTime;	//10us is the SifsTime;
4812+			duration = FrameTime + 3*10 + 2*AckCtsTime;	//10us is the SifsTime;
4813 			tx[4] |= duration & 0xff; 	//Need to edit here!  ----hikaru
4814-			tx[5] |= (duration & 0xff00) >> 8;
4815+			tx[5] |= (duration & 0xff00) >> 8;
4816 			printk(KERN_INFO "duration %d!\n",duration);
4817 	}
4818 	else {
4819 		tx[4] = 0;
4820 		tx[5] = 0;
4821 	}
4822-
4823+
4824 	if(morefrag) tx[2] |= (1<<1);
4825 	tx[2] |= (ieeerate2rtlrate(priv->ieee80211->basic_rate) << 3); /* RTS RATE - should be basic rate */
4826 	tx[3] |= rate;
4827@@ -1640,7 +1657,7 @@
4828 	tx[8] = 3;  // CW min
4829 	tx[8] |= (7<<4); //CW max
4830 	tx[9] |= 11;//(priv->retry_data<<8); //retry lim
4831-
4832+
4833
4834 	/* FIXME check what EP is for low/norm PRI */
4835 	usb_fill_bulk_urb(tx_urb,priv->udev,
4836@@ -1662,7 +1679,7 @@
4837 	}
4838 }
4839
4840-
4841+
4842
4843 //void rtl8180_irq_rx_tasklet(struct r8180_priv * priv);
4844
4845@@ -1671,70 +1688,70 @@
4846 {
4847 	struct r8180_priv *priv = ieee80211_priv(dev);
4848 	int i,j;
4849-
4850+
4851 	priv->rx_urb = (struct urb**) kmalloc (sizeof(struct urb*) * MAX_RX_URB, GFP_KERNEL);
4852-
4853+
4854 	for(i=0;i<MAX_RX_URB;i++){
4855 		priv->rx_urb[i] = usb_alloc_urb(0,GFP_KERNEL);
4856-		if(!priv->rx_urb[i])
4857+		if(!priv->rx_urb[i])
4858 			goto destroy;
4859-
4860+
4861 		priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL);
4862-		if(!priv->rx_urb[i]->transfer_buffer)
4863+		if(!priv->rx_urb[i]->transfer_buffer)
4864 			goto destroy1;
4865-
4866+
4867 		priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE;
4868 	}
4869
4870 	for(j=0; j < MAX_TX_URB; j++){
4871 		struct tx_urb_context *ptrcontext = &priv->tx_context[j];
4872 		u8 seg_size;
4873-
4874+
4875 		ptrcontext->tx_urb = usb_alloc_urb(0,GFP_KERNEL);
4876-		if(!ptrcontext->tx_urb)
4877+		if(!ptrcontext->tx_urb)
4878 			goto destroy_tx;
4879-
4880+
4881 		ptrcontext->transfer_buffer = kmalloc(TX_URB_SIZE, GFP_KERNEL);
4882-		if(!ptrcontext->transfer_buffer)
4883+		if(!ptrcontext->transfer_buffer)
4884 			goto destroy1_tx;
4885 		// set tx_urb 4 byte align
4886 		seg_size = (u32)ptrcontext->transfer_buffer % 4;
4887 		ptrcontext->ptalign_buf = ptrcontext->transfer_buffer + ((seg_size > 0)? (4 - seg_size):0);
4888 	}
4889-
4890+
4891 	return 0;
4892
4893 destroy1_tx:
4894 	usb_free_urb(priv->tx_context[j].tx_urb);
4895-
4896+
4897 destroy_tx:
4898 	while (--j >= 0){
4899 		kfree(priv->tx_context[j].transfer_buffer);
4900 		usb_free_urb(priv->tx_context[j].tx_urb);
4901 	}
4902-
4903+
4904 destroy1:
4905 	usb_free_urb(priv->rx_urb[i]);
4906-
4907+
4908 destroy:
4909 	while (--i >= 0){
4910 		kfree(priv->rx_urb[i]->transfer_buffer);
4911 		usb_free_urb(priv->rx_urb[i]);
4912 	}
4913-
4914+
4915 	kfree(priv->rx_urb);
4916-
4917+
4918 	priv->rx_urb = NULL;
4919 	DMESGE("Endpoint Alloc Failure");
4920 	return -ENOMEM;
4921-
4922+
4923 }
4924
4925 void rtl8187_usb_deleteendpoints(struct net_device *dev)
4926 {
4927 	struct r8180_priv *priv = ieee80211_priv(dev);
4928 	int i,j;
4929-
4930+
4931 	if(priv->rx_urb){
4932 		for(i=0;i<MAX_RX_URB;i++){
4933 			usb_kill_urb(priv->rx_urb[i]);
4934@@ -1743,12 +1760,12 @@
4935 		}
4936 		kfree(priv->rx_urb);
4937 		priv->rx_urb = NULL;
4938-
4939+
4940 	}
4941 	//added by david. 2007.1.30
4942 	for(j=0; j < MAX_TX_URB; j++){
4943 		struct tx_urb_context *ptrcontext = &priv->tx_context[j];
4944-
4945+
4946 		usb_kill_urb(ptrcontext->tx_urb);
4947 		kfree(ptrcontext->transfer_buffer);
4948 		ptrcontext->transfer_buffer = NULL;
4949@@ -1763,16 +1780,16 @@
4950 	int i;
4951 	u16 word;
4952 	int basic_rate,min_rr_rate,max_rr_rate;
4953-
4954+
4955 //	struct r8180_priv *priv = ieee80211_priv(dev);
4956-
4957-	//if (ieee80211_is_54g(priv->ieee80211->current_network) &&
4958+
4959+	//if (ieee80211_is_54g(priv->ieee80211->current_network) &&
4960 //		priv->ieee80211->state == IEEE80211_LINKED){
4961 	basic_rate = ieeerate2rtlrate(240);
4962 	min_rr_rate = ieeerate2rtlrate(60);
4963 	max_rr_rate = ieeerate2rtlrate(240);
4964-
4965-//
4966+
4967+//
4968 //	}else{
4969 //		basic_rate = ieeerate2rtlrate(20);
4970 //		min_rr_rate = ieeerate2rtlrate(10);
4971@@ -1784,7 +1801,7 @@
4972
4973 	word  = read_nic_word(dev, BRSR);
4974 	word &= ~BRSR_MBR_8185;
4975-
4976+
4977
4978 	for(i=0;i<=basic_rate;i++)
4979 		word |= (1<<i);
4980@@ -1797,7 +1814,7 @@
4981 void rtl8187_link_change(struct net_device *dev)
4982 {
4983 //	int i;
4984-
4985+
4986 	struct r8180_priv *priv = ieee80211_priv(dev);
4987 	//write_nic_word(dev, BintrItv, net->beacon_interval);
4988 	rtl8187_net_update(dev);
4989@@ -1813,10 +1830,15 @@
4990
4991 #define HW_WAKE_DELAY 5
4992
4993+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4994+void rtl8180_hw_wakeup(struct work_struct *work)
4995+{
4996+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, hw_wakeup_wq);
4997+	struct net_device *dev = ieee->dev;
4998+#else
4999 void rtl8180_hw_wakeup(struct net_device *dev)
5000 {
5001-	//unsigned long flags;
5002-
5003+#endif
5004 	struct r8180_priv *priv = ieee80211_priv(dev);
5005 	printk(KERN_INFO "enter rtl8180_hw_wakeup!\n");
5006 	if (!priv->ps_sleep_finish) {
5007@@ -1829,7 +1851,7 @@
5008 //	spin_lock_irqsave(&priv->ps_lock,flags);
5009 	//DMESG("Waken up!");
5010 //	write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)&~CONFIG4_PWRMGT);
5011-
5012+
5013 		if(priv->rf_wakeup)
5014 			priv->rf_wakeup(dev);
5015 		priv->ps_sleep_finish=0;
5016@@ -1853,19 +1875,32 @@
5017 	schedule_work(&priv->rtl8180_hw_wakeup_wq);
5018 	printk(KERN_INFO "timer wakup schedule!\n");
5019 }
5020-void rtl8180_rq_tx_ack(struct net_device *dev){
5021-
5022+
5023+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5024+void rtl8180_rq_tx_ack(struct work_struct *work)
5025+{
5026+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, ps_request_tx_ack_wq);
5027+	struct net_device *dev = ieee->dev;
5028+#else
5029+void rtl8180_rq_tx_ack(struct net_device *dev)
5030+{
5031+#endif
5032 	struct r8180_priv *priv = ieee80211_priv(dev);
5033 //	write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)|CONFIG4_PWRMGT);
5034 	priv->ack_tx_to_ieee = 1;
5035 //	printk(KERN_INFO "rtl8180_rq_tx_ack!\n");
5036 }
5037
5038+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5039+void rtl8180_hw_sleep(struct work_struct *work)
5040+{
5041+	struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, hw_sleep_wq);
5042+	struct net_device *dev = ieee->dev;
5043+#else
5044 void rtl8180_hw_sleep(struct net_device *dev)
5045 {
5046-
5047+#endif
5048 	struct r8180_priv *priv = ieee80211_priv(dev);
5049-
5050 	u32 rb,tl;
5051 	//unsigned long flags;
5052 	u32  timeout;
5053@@ -1886,27 +1921,27 @@
5054 	rb = read_nic_dword(dev, TSFTR);
5055 ////	printk(KERN_INFO "enter rtl8180_hw_sleep!\n");
5056 //	spin_lock_irqsave(&priv->ps_lock,flags);
5057-
5058+
5059 	/* Writing HW register with 0 equals to disable
5060 	 * the timer, that is not really what we want
5061 	 */
5062 	tl = priv->ieee80211->ps_tl;
5063 //	printk(KERN_INFO "tl is %lu!\n",tl);
5064 	tl -= HW_WAKE_DELAY*1000;
5065-
5066+
5067 	if(tl == 0) tl = 1;
5068-
5069+
5070 	/* FIXME HACK FIXME HACK */
5071 //	force_pci_posting(dev);
5072 //	mdelay(1);
5073-
5074+
5075 //	rb = read_nic_dword(dev, TSFTR);
5076 #ifdef TONY_PS
5077 	printk(KERN_INFO "tl %lu, rb %lu!\n",tl,rb);
5078 #endif
5079-
5080+
5081 	//DMESG("sleep until %x, hw @:%x",tl,rb);
5082-
5083+
5084 	/* If the interval in witch we are requested to sleep is too
5085 	 * short then give up and remain awake
5086 	 */
5087@@ -1914,12 +1949,12 @@
5088 	if(((rb<tl)&& (tl-rb) < MIN_SLEEP_TIME)
5089 		||((rb>tl)&& (rb-tl) < MIN_SLEEP_TIME))
5090 		return;
5091-
5092+
5093 //	write_nic_dword(dev, TimerInt, tl);
5094 	//DMESG("sleep..");
5095 //	rb = read_nic_dword(dev, TSFTR);
5096-
5097-	/* if we suspect the TimerInt is gone beyond tl
5098+
5099+	/* if we suspect the TimerInt is gone beyond tl
5100 	 * while setting it, then give up
5101 	 */
5102 	if(((tl > rb) && ((tl-rb) > MAX_SLEEP_TIME))||
5103@@ -1927,29 +1962,29 @@
5104 		return;
5105
5106 	if (rb>tl)
5107-		timeout = (rb-tl)>>10;//divide by 1024
5108+		timeout = (rb-tl)>>10;//divide by 1024
5109 	else
5110-		timeout = (tl-rb)>>10;
5111+		timeout = (tl-rb)>>10;
5112
5113 //	if(priv->rf_sleep)
5114 //		priv->rf_sleep(dev);
5115 	priv->ps_timer.expires = jiffies+timeout;
5116 ////	printk(KERN_INFO "jiffies %lu, timeout %lu!\n",jiffies,timeout);
5117 	add_timer(&priv->ps_timer);
5118-
5119+
5120 	if(priv->rf_sleep)
5121 		priv->rf_sleep(dev);
5122 	priv->ps_sleep_finish=1;
5123 //	}
5124 //	up(&priv->power_sem);
5125-//	spin_unlock_irqrestore(&priv->ps_lock,flags);
5126+//	spin_unlock_irqrestore(&priv->ps_lock,flags);
5127 	printk(KERN_INFO "leave sleep!\n");
5128 }
5129
5130 short rtl8180_is_tx_queue_empty(struct net_device *dev){
5131-
5132+
5133 	struct r8180_priv *priv = ieee80211_priv(dev);
5134-
5135+
5136 	int used;
5137 #ifdef TONY_TRACK
5138 	DMESG("enter rtl8180_is_tx_queue_empty!\n");
5139@@ -1957,11 +1992,11 @@
5140
5141 	used = atomic_read(&priv->tx_np_pending);
5142 ////	printk(KERN_INFO "np used %d!\n",used);
5143-	if (used) return 0;
5144+	if (used) return 0;
5145 	used = atomic_read(&priv->tx_lp_pending);
5146 ////	printk(KERN_INFO "lp used %d!\n",used);
5147 	if (used) return 0;
5148-
5149+
5150 	return 1;
5151 }
5152
5153@@ -1969,7 +2004,7 @@
5154
5155 short rtl8180_init(struct net_device *dev)
5156 {
5157-
5158+
5159 	struct r8180_priv *priv = ieee80211_priv(dev);
5160 	int i, j;
5161 	u16 word;
5162@@ -1977,16 +2012,16 @@
5163 	//u16 version;
5164 	//u8 hw_version;
5165 	//u8 config3;
5166-
5167+
5168 	//FIXME: these constants are placed in a bad pleace.
5169
5170 //	priv->txbuffsize = 1024;
5171 //	priv->txringcount = 32;
5172 //	priv->rxbuffersize = 1024;
5173-//	priv->rxringcount = 32;
5174+//	priv->rxringcount = 32;
5175 //	priv->txbeaconcount = 3;
5176 //	priv->rx_skb_complete = 1;
5177-	//priv->txnp_pending.ispending=0;
5178+	//priv->txnp_pending.ispending=0;
5179 	/* ^^ the SKB does not containt a partial RXed
5180 	 * packet (is empty)
5181 	 */
5182@@ -2004,9 +2039,9 @@
5183 		ch >>= 1;
5184 	}
5185 	//memcpy(priv->stats,0,sizeof(struct Stats));
5186-
5187+
5188 	//priv->irq_enabled=0;
5189-
5190+
5191 //	priv->stats.rxdmafail=0;
5192 	priv->stats.txrdu=0;
5193 //	priv->stats.rxrdu=0;
5194@@ -2042,7 +2077,7 @@
5195
5196 	priv->ps_sleep_finish=0;
5197 	priv->ieee80211->iw_mode = IW_MODE_INFRA;
5198-
5199+
5200 	priv->retry_rts = DEFAULT_RETRY_RTS;
5201 	priv->retry_data = DEFAULT_RETRY_DATA;
5202 	priv->ieee80211->rate = 110; //11 mbps
5203@@ -2050,11 +2085,19 @@
5204 	priv->ieee80211->mode = IEEE_G|IEEE_B; //2007.1.25
5205 	priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5206 	spin_lock_init(&priv->tx_lock);
5207+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
5208 	INIT_WORK(&priv->reset_wq,(void(*)(void*)) rtl8180_restart,dev);
5209 	INIT_WORK(&priv->rtl8180_hw_wakeup_wq,(void(*)(void*))rtl8180_hw_wakeup,dev);
5210 	INIT_WORK(&priv->ieee80211->ps_request_tx_ack_wq,(void(*)(void*))rtl8180_rq_tx_ack,dev);
5211 	INIT_WORK(&priv->ieee80211->hw_wakeup_wq,(void(*)(void*))rtl8180_hw_wakeup,dev);
5212 	INIT_WORK(&priv->ieee80211->hw_sleep_wq,(void(*)(void*))rtl8180_hw_sleep,dev);
5213+#else
5214+	INIT_WORK(&priv->reset_wq, rtl8180_restart);
5215+	INIT_WORK(&priv->rtl8180_hw_wakeup_wq, rtl8180_hw_wakeup);
5216+	INIT_WORK(&priv->ieee80211->ps_request_tx_ack_wq, rtl8180_rq_tx_ack);
5217+	INIT_WORK(&priv->ieee80211->hw_wakeup_wq, rtl8180_hw_wakeup);
5218+	INIT_WORK(&priv->ieee80211->hw_sleep_wq, rtl8180_hw_sleep);
5219+#endif
5220 //	INIT_WORK(&priv->ps_request_tx_ack_wq,(void(*)(void*))rtl8180_rq_tx_ack,dev);
5221 	sema_init(&priv->wx_sem,1);
5222 	sema_init(&priv->power_sem,1);
5223@@ -2068,17 +2111,17 @@
5224 	priv->ps_timer.data = (unsigned long)dev;
5225 	priv->ps_timer.function = timer_hw_wakeup_wq;
5226
5227-	//priv->ieee80211->func =
5228+	//priv->ieee80211->func =
5229 	//	kmalloc(sizeof(struct ieee80211_helper_functions),GFP_KERNEL);
5230 	//memset(priv->ieee80211->func, 0,
5231 	  //     sizeof(struct ieee80211_helper_functions));
5232-	priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
5233+	priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
5234 	priv->ieee80211->iw_mode = IW_MODE_INFRA;
5235-	priv->ieee80211->softmac_features  = IEEE_SOFTMAC_SCAN |
5236-		IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
5237+	priv->ieee80211->softmac_features  = IEEE_SOFTMAC_SCAN |
5238+		IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
5239 		IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
5240 		/*IEEE_SOFTMAC_BEACONS | */IEEE_SOFTMAC_SINGLE_QUEUE;
5241-
5242+
5243 	priv->ieee80211->active_scan = 1;
5244 	priv->ieee80211->rate = 110; //11 mbps
5245 	priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
5246@@ -2100,51 +2143,51 @@
5247 	priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
5248 	//priv->ieee80211->start_send_beacons = NULL;
5249 	//priv->ieee80211->stop_send_beacons = NULL;
5250-
5251+
5252 	priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
5253-
5254+
5255 	priv->card_8185 = 2;
5256 	priv->phy_ver = 2;
5257 	priv->card_type = USB;
5258-
5259+
5260 	#if 0
5261 	hw_version =( read_nic_dword(dev, TCR) & TCR_HWVERID_MASK)>>TCR_HWVERID_SHIFT;
5262-
5263+
5264 	switch (hw_version){
5265 		case HW_VERID_R8185_ABC:
5266-			DMESG("MAC controller is a RTL8185 b/g");
5267+			DMESG("MAC controller is a RTL8185 b/g");
5268 			priv->card_8185 = 1;
5269 			/* you should not find a card with 8225 PHY ver < C*/
5270 			priv->phy_ver = 2;
5271 			break;
5272-
5273+
5274 		case HW_VERID_R8185_D:
5275-			DMESG("MAC controller is a RTL8185 b/g (V. D)");
5276+			DMESG("MAC controller is a RTL8185 b/g (V. D)");
5277 			priv->card_8185 = 2;
5278 			/* you should not find a card with 8225 PHY ver < C*/
5279 			priv->phy_ver = 2;
5280 			break;
5281-
5282+
5283 		case HW_VERID_R8180_ABCD:
5284 			DMESG("MAC controller is a RTL8180");
5285 			priv->card_8185 = 0;
5286 			break;
5287-
5288+
5289 		case HW_VERID_R8180_F:
5290 			DMESG("MAC controller is a RTL8180 (v. F)");
5291 			priv->card_8185 = 0;
5292 			break;
5293-
5294+
5295 		default:
5296 			DMESGW("MAC chip not recognized: version %x. Assuming RTL8180",hw_version);
5297 			priv->card_8185 = 0;
5298 			break;
5299 	}
5300-
5301-
5302+
5303+
5304 	/* you should not found any 8185 Ver B Card */
5305 	priv->card_8185_Bversion = 0;
5306-
5307+
5308 	config3 = read_nic_byte(dev, CONFIG3);
5309 	if(config3 & 0x8){
5310 		priv->card_type = CARDBUS;
5311@@ -2162,13 +2205,13 @@
5312 	priv->plcp_preamble_mode = 2;
5313
5314
5315-
5316+
5317 	/* commented out just because we already do
5318 	   this when resetting the card
5319 	   andrea 20050924
5320 	 */
5321 	#if 0
5322-
5323+
5324 	u8 txcr, txreg50;
5325 	u32 txreg54, txreg60;
5326
5327@@ -2204,8 +2247,8 @@
5328        // DMESG("<<txcr:%x>>", txcr);
5329
5330 #endif
5331-
5332-	/*the eeprom type is stored in RCR register bit #6 */
5333+
5334+	/*the eeprom type is stored in RCR register bit #6 */
5335 	if (RCR_9356SEL & read_nic_dword(dev, RCR)){
5336 		priv->epromtype=EPROM_93c56;
5337 		DMESG("Reported EEPROM chip is a 93c56 (2Kbit)");
5338@@ -2213,58 +2256,67 @@
5339 		priv->epromtype=EPROM_93c46;
5340 		DMESG("Reported EEPROM chip is a 93c46 (1Kbit)");
5341 	}
5342-
5343+
5344 	dev->get_stats = rtl8180_stats;
5345-
5346+
5347 	dev->dev_addr[0]=eprom_read(dev,MAC_ADR) & 0xff;
5348 	dev->dev_addr[1]=(eprom_read(dev,MAC_ADR) & 0xff00)>>8;
5349 	dev->dev_addr[2]=eprom_read(dev,MAC_ADR+1) & 0xff;
5350 	dev->dev_addr[3]=(eprom_read(dev,MAC_ADR+1) & 0xff00)>>8;
5351 	dev->dev_addr[4]=eprom_read(dev,MAC_ADR+2) & 0xff;
5352 	dev->dev_addr[5]=(eprom_read(dev,MAC_ADR+2) & 0xff00)>>8;
5353-
5354+
5355 	DMESG("Card MAC address is "MAC_FMT, MAC_ARG(dev->dev_addr));
5356-
5357+
5358 	for(i=1,j=0; i<6; i+=2,j++){
5359-
5360+
5361 		word = eprom_read(dev,EPROM_TXPW0 + j);
5362 		priv->chtxpwr[i]=word & 0xf;
5363 		priv->chtxpwr_ofdm[i]=(word & 0xf0)>>4;
5364 		priv->chtxpwr[i+1]=(word & 0xf00)>>8;
5365 		priv->chtxpwr_ofdm[i+1]=(word & 0xf000)>>12;
5366 	}
5367-
5368+
5369 	for(i=1,j=0; i<4; i+=2,j++){
5370-
5371+
5372 		word = eprom_read(dev,EPROM_TXPW1 + j);
5373 		priv->chtxpwr[i+6]=word & 0xf;
5374 		priv->chtxpwr_ofdm[i+6]=(word & 0xf0)>>4;
5375 		priv->chtxpwr[i+6+1]=(word & 0xf00)>>8;
5376 		priv->chtxpwr_ofdm[i+6+1]=(word & 0xf000)>>12;
5377 	}
5378-
5379+
5380 	for(i=1,j=0; i<4; i+=2,j++){
5381-
5382+
5383 		word = eprom_read(dev,EPROM_TXPW2 + j);
5384 		priv->chtxpwr[i+6+4]=word & 0xf;
5385 		priv->chtxpwr_ofdm[i+6+4]=(word & 0xf0)>>4;
5386 		priv->chtxpwr[i+6+4+1]=(word & 0xf00)>>8;
5387 		priv->chtxpwr_ofdm[i+6+4+1]=(word & 0xf000)>>12;
5388 	}
5389-
5390-
5391+
5392+
5393 	priv->rf_chip = 0xff & eprom_read(dev,EPROM_RFCHIPID);
5394-
5395+
5396 	word = eprom_read(dev,EPROM_TXPW_BASE);
5397 	priv->cck_txpwr_base = word & 0xf;
5398 	priv->ofdm_txpwr_base = (word>>4) & 0xf;
5399-
5400+
5401+	priv->txpwr_max = 0;
5402+	for(i=1; i<15; i++)
5403+	{
5404+		if(priv->chtxpwr[i] > priv->txpwr_max) priv->txpwr_max = priv->chtxpwr[i];
5405+		if(priv->chtxpwr_ofdm[i] > priv->txpwr_max) priv->txpwr_max = priv->chtxpwr_ofdm[i];
5406+		priv->chtxpwr_orig[i] = priv->chtxpwr[i];
5407+		priv->chtxpwr_ofdm_orig[i] = priv->chtxpwr_ofdm[i];
5408+	}
5409+
5410 	/* check RF frontend chipset */
5411-
5412+
5413 	switch (priv->rf_chip) {
5414-
5415+
5416 		case EPROM_RFCHIPID_RTL8225U:
5417-
5418+
5419 		DMESG("Card reports RF frontend Realtek 8225");
5420 		DMESGW("This driver has EXPERIMENTAL support for this chipset.");
5421 		DMESGW("use it with care and at your own risk and");
5422@@ -2283,30 +2335,30 @@
5423 			DMESG("This seems a legacy 1st version radio");
5424 		}
5425 		priv->rf_close = rtl8225_rf_close;
5426-
5427+
5428 		priv->max_sens = RTL8225_RF_MAX_SENS;
5429 		priv->sens = RTL8225_RF_DEF_SENS;
5430 		break;
5431-
5432+
5433 		default:
5434 		DMESGW("Unknown RF module %x",priv->rf_chip);
5435 		DMESGW("Exiting...");
5436 		return -1;
5437-
5438+
5439 	}
5440
5441 	InitSwLeds(dev);
5442-
5443+
5444 //	DMESG("Energy threshold: %x",priv->cs_treshold);
5445 	DMESG("PAPE from CONFIG2: %x",read_nic_byte(dev,CONFIG2)&0x7);
5446 	//DMESG("CONFIG2: %x ECONFIG2: %x",read_nic_byte(dev,CONFIG2),eprom_read(dev,EPROM_CONFIG2));
5447-
5448-	if(rtl8187_usb_initendpoints(dev)!=0){
5449+
5450+	if(rtl8187_usb_initendpoints(dev)!=0){
5451 		DMESG("Endopoints initialization failed");
5452 		return -ENOMEM;
5453 	}
5454-#if 0
5455-	if (0!=alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
5456+#if 0
5457+	if (0!=alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
5458 		return -ENOMEM;
5459
5460 	if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
5461@@ -2320,16 +2372,16 @@
5462 	if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
5463 				  TX_LOWPRIORITY_RING_ADDR))
5464 		return -ENOMEM;
5465-
5466-
5467+
5468+
5469 	if (0!=alloc_tx_beacon_desc_ring(dev, priv->txbeaconcount))
5470 		return -ENOMEM;
5471 #endif
5472-
5473+
5474
5475 #ifdef DEBUG_EPROM
5476 	dump_eprom(dev);
5477-#endif
5478+#endif
5479 	return 0;
5480
5481 }
5482@@ -2349,7 +2401,7 @@
5483 	rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5484
5485 	conf3 = read_nic_byte(dev, CONFIG3);
5486-	write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
5487+	write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
5488
5489 	write_nic_dword(dev, ANAPARAM2, a);
5490
5491@@ -2369,23 +2421,23 @@
5492
5493 	conf3 = read_nic_byte(dev, CONFIG3);
5494 	write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
5495-
5496+
5497 	write_nic_dword(dev, ANAPARAM, a);
5498
5499 	conf3 = read_nic_byte(dev, CONFIG3);
5500 	write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
5501
5502 	rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5503-
5504+
5505 }
5506
5507
5508 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
5509 {
5510-	write_nic_byte(dev, TX_ANTENNA, ant);
5511+	write_nic_byte(dev, TX_ANTENNA, ant);
5512 	force_pci_posting(dev);
5513 	mdelay(1);
5514-}
5515+}
5516
5517
5518 void rtl8187_write_phy(struct net_device *dev, u8 adr, u32 data)
5519@@ -2393,26 +2445,26 @@
5520 	//u8 phyr;
5521 	u32 phyw;
5522 //	int i;
5523-
5524+
5525 	adr |= 0x80;
5526-
5527+
5528 	phyw= ((data<<8) | adr);
5529-
5530-
5531-
5532-	// Note that, we must write 0xff7c after 0x7d-0x7f to write BB register.
5533+
5534+
5535+
5536+	// Note that, we must write 0xff7c after 0x7d-0x7f to write BB register.
5537 	write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
5538 	write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
5539 	write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
5540 	write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff) ));
5541
5542 	//read_nic_dword(dev, PHY_ADR);
5543-#if 0
5544+#if 0
5545 	for(i=0;i<10;i++){
5546 		write_nic_dword(dev, PHY_ADR, 0xffffff7f & phyw);
5547 		phyr = read_nic_byte(dev, PHY_READ);
5548 		if(phyr == (data&0xff)) break;
5549-
5550+
5551 	}
5552 #endif
5553 	/* this is ok to fail when we write AGC table. check for AGC table might be
5554@@ -2442,26 +2494,26 @@
5555         struct r8180_priv *priv = ieee80211_priv(dev);
5556 	//u32 anaparam;
5557 	//u8 config3;
5558-
5559+
5560 	//rtl8180_rtx_disable(dev);
5561 	rtl8180_reset(dev);
5562
5563 	write_nic_byte(dev,0x85,0);
5564 	write_nic_byte(dev,0x91,0);
5565-
5566+
5567 	/* light blink! */
5568 	write_nic_byte(dev,0x85,4);
5569 	LedControl8187(dev, LED_CTL_POWER_ON);
5570 	//write_nic_byte(dev,0x91,1);
5571 	//write_nic_byte(dev,0x90,0);
5572-
5573+
5574 	priv->irq_mask = 0xffff;
5575 /*
5576 	priv->dma_poll_mask = 0;
5577 	priv->dma_poll_mask|= (1<<TX_DMA_STOP_BEACON_SHIFT);
5578-*/
5579+*/
5580 //	rtl8180_beacon_tx_disable(dev);
5581-
5582+
5583 	rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5584 	write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
5585 	write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
5586@@ -2469,32 +2521,32 @@
5587 	rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5588 	rtl8180_update_msr(dev);
5589
5590-/*
5591+/*
5592 	rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5593-
5594+
5595 	write_nic_word(dev,0xf4,0xffff);
5596 	write_nic_byte(dev,
5597-		       CONFIG1, (read_nic_byte(dev,CONFIG1) & 0x3f) | 0x80);
5598+		       CONFIG1, (read_nic_byte(dev,CONFIG1) & 0x3f) | 0x80);
5599
5600 	rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5601 */
5602-	write_nic_dword(dev,INT_TIMEOUT,0);
5603+	write_nic_dword(dev,INT_TIMEOUT,0);
5604
5605 #ifdef DEBUG_REGISTERS
5606-	rtl8180_dump_reg(dev);
5607+	rtl8180_dump_reg(dev);
5608 #endif
5609-
5610-
5611-	write_nic_byte(dev, WPA_CONFIG, 0);
5612+
5613+
5614+	write_nic_byte(dev, WPA_CONFIG, 0);
5615
5616 	write_nic_byte(dev, RATE_FALLBACK, 0x81);
5617 	rtl8187_set_rate(dev);
5618-
5619-	priv->rf_init(dev);
5620+
5621+	priv->rf_init(dev);
5622
5623 	if(priv->rf_set_sens != NULL)
5624-		priv->rf_set_sens(dev,priv->sens);
5625-
5626+		priv->rf_set_sens(dev,priv->sens);
5627+
5628 	write_nic_word(dev,0x5e,1);
5629
5630 	#if 1
5631@@ -2510,13 +2562,13 @@
5632
5633 	//add for Led controll
5634 	write_nic_byte(dev,0x85,4);
5635-
5636-
5637+
5638+
5639 	rtl8180_irq_enable(dev);
5640 	/*DMESG ("lfree %d",get_curr_tx_free_desc(dev,LOW_PRIORITY));
5641-
5642+
5643 	DMESG ("nfree %d",get_curr_tx_free_desc(dev,NORM_PRIORITY));
5644-
5645+
5646 	DMESG ("hfree %d",get_curr_tx_free_desc(dev,HI_PRIORITY));
5647 	if(check_nic_enought_desc(dev,NORM_PRIORITY)) DMESG("NORM OK");
5648 	if(check_nic_enought_desc(dev,HI_PRIORITY)) DMESG("HI OK");
5649@@ -2534,7 +2586,7 @@
5650 {
5651 	int i;
5652 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5653-	u16 word;
5654+	u16 word;
5655 	DMESG("Enabling beacon TX");
5656 	//write_nic_byte(dev, 0x42,0xe6);// TCR
5657 	//rtl8180_init_beacon(dev);
5658@@ -2547,41 +2599,41 @@
5659 	//write_nic_word(dev,0x7a,0);
5660 	//write_nic_word(dev,0x7a,0x8000);
5661
5662-
5663+
5664 	word  = read_nic_word(dev, BcnItv);
5665 	word &= ~BcnItv_BcnItv; // clear Bcn_Itv
5666 	write_nic_word(dev, BcnItv, word);
5667
5668-	write_nic_word(dev, AtimWnd,
5669+	write_nic_word(dev, AtimWnd,
5670 		       read_nic_word(dev, AtimWnd) &~ AtimWnd_AtimWnd);
5671-
5672+
5673 	word  = read_nic_word(dev, BintrItv);
5674 	word &= ~BintrItv_BintrItv;
5675-
5676-	//word |= priv->ieee80211->beacon_interval *
5677+
5678+	//word |= priv->ieee80211->beacon_interval *
5679 	//	((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
5680 	// FIXME:FIXME check if correct ^^ worked with 0x3e8;
5681-
5682+
5683 	write_nic_word(dev, BintrItv, word);
5684-
5685+
5686 	//write_nic_word(dev,0x2e,0xe002);
5687 	//write_nic_dword(dev,0x30,0xb8c7832e);
5688 	for(i=0; i<ETH_ALEN; i++)
5689 		write_nic_byte(dev, BSSID+i, priv->ieee80211->beacon_cell_ssid[i]);
5690-
5691+
5692 //	rtl8180_update_msr(dev);
5693
5694-
5695+
5696 	//write_nic_byte(dev,CONFIG4,3); /* !!!!!!!!!! */
5697-
5698+
5699 	rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5700-
5701+
5702 	rtl8180_irq_enable(dev);
5703-
5704+
5705 	/* VV !!!!!!!!!! VV*/
5706 	/*
5707 	rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5708-	write_nic_byte(dev,0x9d,0x00);
5709+	write_nic_byte(dev,0x9d,0x00);
5710 	rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5711 */
5712 }
5713@@ -2592,7 +2644,7 @@
5714 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
5715 {
5716 	struct r8180_priv *priv = ieee80211_priv(dev);
5717-
5718+
5719 	return &priv->ieee80211->stats;
5720 }
5721
5722@@ -2602,20 +2654,20 @@
5723 	struct r8180_priv *priv = ieee80211_priv(dev);
5724
5725 	priv->up=1;
5726-
5727+
5728 	//DMESG("Bringing up iface");
5729
5730 	rtl8180_adapter_start(dev);
5731
5732-
5733+
5734 	rtl8180_rx_enable(dev);
5735
5736 	rtl8180_tx_enable(dev);
5737-
5738+
5739 	ieee80211_softmac_start_protocol(priv->ieee80211);
5740
5741 	//LedControl8187(dev, LED_CTL_SITE_SURVEY);
5742-
5743+
5744 	ieee80211_reset_queue(priv->ieee80211);
5745 	if(!netif_queue_stopped(dev))
5746 		netif_start_queue(dev);
5747@@ -2630,12 +2682,12 @@
5748 {
5749 	struct r8180_priv *priv = ieee80211_priv(dev);
5750 	int ret;
5751-
5752+
5753 	down(&priv->wx_sem);
5754 	ret = rtl8180_up(dev);
5755 	up(&priv->wx_sem);
5756 	return ret;
5757-
5758+
5759 }
5760
5761
5762@@ -2644,7 +2696,7 @@
5763 	struct r8180_priv *priv = ieee80211_priv(dev);
5764
5765 	if (priv->up == 1) return -1;
5766-
5767+
5768 	return _rtl8180_up(dev);
5769 }
5770
5771@@ -2653,15 +2705,15 @@
5772 {
5773 	struct r8180_priv *priv = ieee80211_priv(dev);
5774 	int ret;
5775-
5776+
5777 	down(&priv->wx_sem);
5778-
5779+
5780 	ret = rtl8180_down(dev);
5781-
5782+
5783 	LedControl8187(dev, LED_CTL_NO_LINK);
5784-
5785+
5786 	up(&priv->wx_sem);
5787-
5788+
5789 	return ret;
5790
5791 }
5792@@ -2671,18 +2723,18 @@
5793 	struct r8180_priv *priv = ieee80211_priv(dev);
5794
5795 	if (priv->up == 0) return -1;
5796-
5797+
5798 	priv->up=0;
5799
5800 /* FIXME */
5801 	if (!netif_queue_stopped(dev))
5802 		netif_stop_queue(dev);
5803-
5804+
5805 	rtl8180_rtx_disable(dev);
5806 	rtl8180_irq_disable(dev);
5807
5808 	ieee80211_softmac_stop_protocol(priv->ieee80211);
5809-
5810+
5811 	return 0;
5812 }
5813
5814@@ -2692,7 +2744,7 @@
5815 	struct r8180_priv *priv = ieee80211_priv(dev);
5816
5817 	if (priv->up == 0) return ;
5818-
5819+
5820 	ieee80211_softmac_stop_protocol(priv->ieee80211);
5821 	sema_init(&priv->power_sem,1);
5822 	//printk(KERN_WARNING "priv->power_semb %d!\n",priv->power_sem);
5823@@ -2701,14 +2753,20 @@
5824 	_rtl8180_up(dev);
5825 }
5826
5827+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5828+void rtl8180_restart(struct work_struct *work)
5829+{
5830+	struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
5831+	struct net_device *dev = priv->dev;
5832+#else
5833 void rtl8180_restart(struct net_device *dev)
5834 {
5835 	struct r8180_priv *priv = ieee80211_priv(dev);
5836-
5837+#endif
5838 	down(&priv->wx_sem);
5839-
5840+
5841 	rtl8180_commit(dev);
5842-
5843+
5844 	up(&priv->wx_sem);
5845 }
5846
5847@@ -2718,16 +2776,16 @@
5848 	short promisc;
5849
5850 	//down(&priv->wx_sem);
5851-
5852+
5853 	/* FIXME FIXME */
5854-
5855+
5856 	promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5857-
5858+
5859 	if (promisc != priv->promisc)
5860 	//	rtl8180_commit(dev);
5861-
5862+
5863 	priv->promisc = promisc;
5864-
5865+
5866 	//schedule_work(&priv->reset_wq);
5867 	//up(&priv->wx_sem);
5868 }
5869@@ -2737,15 +2795,15 @@
5870 {
5871 	struct r8180_priv *priv = ieee80211_priv(dev);
5872 	struct sockaddr *addr = mac;
5873-
5874+
5875 	down(&priv->wx_sem);
5876-
5877+
5878 	memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5879-
5880+
5881 	schedule_work(&priv->reset_wq);
5882-
5883+
5884 	up(&priv->wx_sem);
5885-
5886+
5887 	return 0;
5888 }
5889
5890@@ -2758,8 +2816,8 @@
5891 	int ret=-1;
5892
5893 	down(&priv->wx_sem);
5894-
5895-
5896+
5897+
5898 	switch (cmd) {
5899 	    case RTL_IOCTL_WPA_SUPPLICANT:
5900 		ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5901@@ -2771,7 +2829,7 @@
5902 	}
5903
5904 	up(&priv->wx_sem);
5905-
5906+
5907 	return ret;
5908 }
5909
5910@@ -2792,9 +2850,9 @@
5911 	//u32 *desc;
5912 	u8 *desc;
5913 	u8 signal,quality,rate;
5914-
5915+
5916 	//DMESG("rtl8187_rx_isr");
5917-
5918+
5919 	struct ieee80211_rx_stats stats = {
5920 		.signal = 0,
5921 		.noise = -98,
5922@@ -2803,31 +2861,31 @@
5923 		.freq = IEEE80211_24GHZ_BAND,
5924 	};
5925
5926-
5927+
5928 	//DMESG("RX %d ",rx_urb->status);
5929 	status = rx_urb->status;
5930 	if(status == 0){
5931-
5932+
5933 		len = rx_urb->actual_length;
5934-	//	len = len - 4 - 15 - 1; /* CRC, DESC, SEPARATOR*/
5935+	//	len = len - 4 - 15 - 1; /* CRC, DESC, SEPARATOR*/
5936 		len -= 4*4;/* 4 dword and 4 byte CRC */
5937-#if 0
5938+#if 0
5939 		desc = (u32*)(rx_urb->transfer_buffer + len);
5940-
5941+
5942 		flen = desc[0] & 0xfff;
5943-
5944+
5945 		if( flen <= rx_urb->actual_length){
5946-
5947+
5948 			//stats.signal = (desc[1] & 0x7f00)>>8;
5949 			//stats.noise = desc[1] &0xff;
5950 			signal=(desc[1]& (0xff0000))>>16;
5951 			signal=(signal&0xfe)>>1;	// Modify by hikaru 6.6
5952-
5953+
5954 			quality=(desc[1] & (0xff));
5955-
5956+
5957 			rate=(desc[0] &((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
5958-		//	printk(KERN_INFO "rate is %d!\n",rate);
5959-			stats.rate = rtl8180_rate2rate(rate);
5960+		//	printk(KERN_INFO "rate is %d!\n",rate);
5961+			stats.rate = rtl8180_rate2rate(rate);
5962 		//	printk(KERN_INFO "stats.rate is %d!\n",stats.rate);
5963 			//stats.rate = desc[0] >> 20 & 0xf;
5964 			stats.mac_time[0] = desc[2];
5965@@ -2835,35 +2893,35 @@
5966 #endif
5967
5968 		desc = rx_urb->transfer_buffer + len;
5969-
5970+
5971 		flen = ((desc[1] & 0x0f) << 8) + (desc[0] & 0xff);
5972-
5973+
5974 		if( flen <= rx_urb->actual_length){
5975-
5976+
5977 			//stats.signal = (desc[1] & 0x7f00)>>8;
5978 			//stats.noise = desc[1] &0xff;
5979 			signal=(desc[6]& 0xfe)>>1;
5980 			//signal=(signal&0xfe)>>1;	// Modify by hikaru 6.6
5981-
5982+
5983 			quality=desc[4] & 0xff;
5984-
5985+
5986 			//rate=(desc[2] &((1<<7)|(1<<6)|(1<<5)|(1<<4)))>>4;
5987 			rate=(desc[2] & 0xf0)>>4;
5988-		//	printk(KERN_INFO "rate is %d!\n",rate);
5989-			stats.rate = rtl8180_rate2rate(rate);
5990+		//	printk(KERN_INFO "rate is %d!\n",rate);
5991+			stats.rate = rtl8180_rate2rate(rate);
5992 		//	printk(KERN_INFO "stats.rate is %d!\n",stats.rate);
5993 			//stats.rate = desc[0] >> 20 & 0xf;
5994-			stats.mac_time[0] = desc[8] + (desc[9]<<8) + (desc[10]<<16) + (desc[11]<<24);
5995-			stats.mac_time[1] = desc[12] + (desc[13]<<8) + (desc[14]<<16) + (desc[15]<<24);
5996+			stats.mac_time[0] = desc[8] + (desc[9]<<8) + (desc[10]<<16) + (desc[11]<<24);
5997+			stats.mac_time[1] = desc[12] + (desc[13]<<8) + (desc[14]<<16) + (desc[15]<<24);
5998+
5999
6000-
6001 			//calculate link quality begin
6002-			if(!rtl8180_IsWirelessBMode(stats.rate) )
6003+			if(!rtl8180_IsWirelessBMode(stats.rate) )
6004 			{ // OFDM rate.
6005 				if(signal>90)
6006 					signal=90;
6007 				else if(signal<25)
6008-					signal=25;
6009+					signal=25;
6010 				signal = (90-signal)*100/65;
6011 			}
6012 			else
6013@@ -2871,7 +2929,7 @@
6014 				if(signal>95)
6015 					signal = 95;
6016 				else if(signal<30)
6017-					signal = 30;
6018+					signal = 30;
6019 				signal =(95-signal )*100/65;
6020 			}
6021 			priv->wstats.qual.level = signal;
6022@@ -2879,30 +2937,35 @@
6023 			if(quality > 64)
6024 				priv ->wstats.qual.qual = 0;
6025 			else
6026-				priv ->wstats.qual.qual = ((64-quality) * 100) / 64;  // SQ value is the SIGNAL_QUALITY returned to IORequest,
6027-						//and this value only appear when STA is associated to AP or
6028+				priv ->wstats.qual.qual = ((64-quality) * 100) / 64;  // SQ value is the SIGNAL_QUALITY returned to IORequest,
6029+						//and this value only appear when STA is associated to AP or
6030 						// STA is in IBSS mode
6031 		//	printk(KERN_INFO "quality is %d!\n",priv->wstats.qual.qual);
6032 			priv->wstats.qual.noise = 100 - priv ->wstats.qual.qual;
6033 			priv->wstats.qual.updated = 7;
6034-			//calculate link quality end
6035+			if(priv->ieee80211->iw_mode == IW_MODE_MONITOR)
6036+			{
6037+				stats.signal = priv->wstats.qual.level;
6038+				stats.noise = priv->wstats.qual.noise;
6039+			}
6040+			//calculate link quality end
6041 			skb = dev_alloc_skb(flen-4);
6042-			if(skb){
6043+			if(skb){
6044 			memcpy(skb_put(skb,flen-4),
6045 				rx_urb->transfer_buffer,flen -4);
6046-
6047+
6048 			#ifdef DUMP_RX
6049 			int i;
6050 			for(i=0;i<flen-4;i++)
6051 				printk("%2x ",((u8*)(rx_urb->transfer_buffer))[i]);
6052 			printk("------RATE %x:w---------------\n",stats.rate);
6053-
6054+
6055 			#endif
6056 			priv->stats.rxok++;
6057 		//	priv->rxskb = skb;
6058 		//	priv->tempstats = &stats;
6059
6060-			if(!ieee80211_rx(priv->ieee80211,
6061+			if(!ieee80211_rx(priv->ieee80211,
6062 				skb, &stats))
6063 			dev_kfree_skb_any(skb);
6064 			}
6065@@ -2913,7 +2976,7 @@
6066 	}
6067
6068 	//LedControl8187(dev, LED_CTL_RX);
6069-
6070+
6071 	if(status != -ENOENT)rtl8187_rx_urbsubmit(dev,rx_urb);
6072 	else DMESG("RX process aborted due to explicit shutdown");
6073 }
6074@@ -2931,20 +2994,20 @@
6075 	struct r8180_priv *priv= NULL;
6076 	struct usb_device *udev = interface_to_usbdev(intf);
6077
6078-printk(KERN_WARNING "===> rtl8187_usb_probe()\n");
6079-
6080+printk(KERN_WARNING "===> rtl8187_usb_probe()\n");
6081+
6082 	dev = alloc_ieee80211(sizeof(struct r8180_priv));
6083-
6084+
6085 	SET_MODULE_OWNER(dev);
6086-	usb_set_intfdata(intf, dev);
6087-
6088+	usb_set_intfdata(intf, dev);
6089+
6090 	SET_NETDEV_DEV(dev, &intf->dev);
6091
6092 	priv = ieee80211_priv(dev);
6093 	priv->ieee80211 = netdev_priv(dev);
6094-
6095+
6096 	priv->udev=udev;
6097-
6098+
6099 	dev->open = rtl8180_open;
6100 	dev->stop = rtl8180_close;
6101 	//dev->hard_start_xmit = rtl8180_8023_hard_start_xmit;
6102@@ -2953,41 +3016,46 @@
6103 	dev->do_ioctl = rtl8180_ioctl;
6104 	dev->set_multicast_list = r8180_set_multicast;
6105 	dev->set_mac_address = r8180_set_mac_adr;
6106+#if WIRELESS_EXT >= 12
6107+#if WIRELESS_EXT < 17
6108 	dev->get_wireless_stats = r8180_get_wireless_stats;
6109+#endif
6110+	dev->wireless_handlers = (struct iw_handler_def *) &r8180_wx_handlers_def;
6111+#endif
6112 	dev->type=ARPHRD_ETHER;
6113-
6114+
6115 	if (dev_alloc_name(dev, ifname) < 0){
6116                 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
6117 		ifname = "wlan%d";
6118 		dev_alloc_name(dev, ifname);
6119         }
6120-
6121+
6122 //	dev->open=rtl8180_init;
6123-
6124-	if(rtl8180_init(dev)!=0){
6125+
6126+	if(rtl8180_init(dev)!=0){
6127 		DMESG("Initialization failed");
6128 		goto fail;
6129 	}
6130-
6131+
6132 	netif_carrier_off(dev);
6133 	netif_stop_queue(dev);
6134-
6135+
6136 	register_netdev(dev);
6137-
6138+
6139 	rtl8180_proc_init_one(dev);
6140
6141-
6142+
6143 	DMESG("Driver probe completed\n");
6144-	return 0;
6145+	return 0;
6146+
6147
6148-
6149 fail:
6150 	free_ieee80211(dev);
6151-
6152+
6153 	DMESG("wlan driver load failed\n");
6154-
6155+
6156 	return -ENODEV;
6157-
6158+
6159 }
6160
6161
6162@@ -2996,13 +3064,13 @@
6163 	struct r8180_priv *priv;
6164 	struct net_device *dev = usb_get_intfdata(intf);
6165  	if(dev){
6166-
6167+
6168 		unregister_netdev(dev);
6169-
6170+
6171 		priv=ieee80211_priv(dev);
6172-
6173+
6174 		rtl8180_proc_remove_one(dev);
6175-
6176+
6177 		rtl8180_down(dev);
6178 		priv->rf_close(dev);
6179 		//rtl8180_rtx_disable(dev);
6180@@ -3046,11 +3114,11 @@
6181 	unsigned long flags;
6182 	short enough_desc;
6183 	struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6184-
6185+
6186 	spin_lock_irqsave(&priv->tx_lock,flags);
6187 	enough_desc = check_nic_enought_desc(dev,pri);
6188-        spin_unlock_irqrestore(&priv->tx_lock,flags);
6189-
6190+        spin_unlock_irqrestore(&priv->tx_lock,flags);
6191+
6192 	if(enough_desc)
6193 		ieee80211_wake_queue(priv->ieee80211);
6194 }
6195diff -Naur r8187_orig/rtl8187/r8187.h r8187_rawtx/rtl8187/r8187.h
6196--- r8187_orig/rtl8187/r8187.h	2007-12-05 04:22:20.000000000 +0100
6197+++ r8187_rawtx/rtl8187/r8187.h	2007-05-16 21:51:38.000000000 +0200
6198@@ -1,17 +1,17 @@
6199-/*
6200+/*
6201    This is part of rtl8187 OpenSource driver.
6202-   Copyright (C) Andrea Merello 2004-2005  <andreamrl@tiscali.it>
6203+   Copyright (C) Andrea Merello 2004-2005  <andreamrl@tiscali.it>
6204    Released under the terms of GPL (General Public Licence)
6205-
6206-   Parts of this driver are based on the GPL part of the
6207+
6208+   Parts of this driver are based on the GPL part of the
6209    official realtek driver
6210-
6211-   Parts of this driver are based on the rtl8180 driver skeleton
6212+
6213+   Parts of this driver are based on the rtl8180 driver skeleton
6214    from Patric Schenke & Andres Salomon
6215-
6216+
6217    Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
6218-
6219-   We want to tanks the Authors of those projects and the Ndiswrapper
6220+
6221+   We want to tanks the Authors of those projects and the Ndiswrapper
6222    project Authors.
6223 */
6224
6225@@ -26,7 +26,6 @@
6226
6227 #include <linux/module.h>
6228 #include <linux/kernel.h>
6229-#include <linux/config.h>
6230 #include <linux/init.h>
6231 #include <linux/ioport.h>
6232 #include <linux/sched.h>
6233@@ -47,6 +46,12 @@
6234 #include <asm/io.h>
6235 #include <asm/semaphore.h>
6236
6237+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
6238+#include <linux/config.h>
6239+#else
6240+#include <linux/autoconf.h>
6241+#endif
6242+
6243 #include "ieee80211.h"
6244 #include "r8187_led.h"
6245 #include "r8180_hw.h"
6246@@ -74,7 +79,7 @@
6247 {
6248 	struct buffer *next;
6249 	u32 *buf;
6250-
6251+
6252 } buffer;
6253
6254 #if 0
6255@@ -123,7 +128,7 @@
6256 	unsigned long txdatapkt;
6257 	unsigned long rxok;
6258 	unsigned long rxretry;//retry number  tony 20060601
6259-	unsigned long rxcrcerrmin;//crc error (0-500)
6260+	unsigned long rxcrcerrmin;//crc error (0-500)
6261 	unsigned long rxcrcerrmid;//crc error (500-1000)
6262 	unsigned long rxcrcerrmax;//crc error (>1000)
6263 	unsigned long rxicverr;//ICV error
6264@@ -142,7 +147,7 @@
6265 	short epromtype;
6266 	int irq;
6267 	struct ieee80211_device *ieee80211;
6268-
6269+
6270 	short card_8185; /* O: rtl8180, 1:rtl8185 V B/C, 2:rtl8185 V D */
6271 	short card_8185_Bversion; /* if TCR reports card V B/C this discriminates */
6272 	short phy_ver; /* meaningful for rtl8225 1:A 2:B 3:C */
6273@@ -151,12 +156,12 @@
6274 	short hw_plcp_len;
6275 	short plcp_preamble_mode; // 0:auto 1:short 2:long
6276
6277-
6278+
6279 //	spinlock_t irq_lock;
6280 //	spinlock_t irq_th_lock;
6281 	spinlock_t tx_lock;
6282 	spinlock_t ps_lock;
6283-
6284+
6285 	u16 irq_mask;
6286 //	short irq_enabled;
6287 	struct net_device *dev;
6288@@ -165,17 +170,20 @@
6289 	short max_sens;
6290 	u8 chtxpwr[15]; //channels from 1 to 14, 0 not used
6291 	u8 chtxpwr_ofdm[15]; //channels from 1 to 14, 0 not used
6292+	u8 chtxpwr_orig[15]; //channels from 1 to 14, 0 not used
6293+	u8 chtxpwr_ofdm_orig[15]; //channels from 1 to 14, 0 not used
6294 	u8 cck_txpwr_base;
6295 	u8 ofdm_txpwr_base;
6296+	u8 txpwr_max;
6297 	u8 challow[15]; //channels from 1 to 14, 0 not used
6298 	u8 channel_plan;  // it's the channel plan index
6299
6300 	short up;
6301 	short crcmon; //if 1 allow bad crc frame reception in monitor mode
6302-//	short prism_hdr;
6303+	short prism_hdr;
6304 	struct timer_list ps_timer;
6305 	short PS_timeout;//when ps set on ,if tx timeout ,this will be set 1
6306-
6307+
6308 //	struct timer_list scan_timer;
6309 	/*short scanpending;
6310 	short stopscan;*/
6311@@ -185,7 +193,7 @@
6312 	struct semaphore wx_sem;
6313 	struct semaphore power_sem;
6314 //	short hw_wep;
6315-
6316+
6317 //	short digphy;
6318 //	short antb;
6319 //	short diversity;
6320@@ -200,12 +208,12 @@
6321 	void (*rf_wakeup)(struct net_device *dev);
6322 	void (*rf_sleep)(struct net_device *dev);
6323 	//short rate;
6324-	short promisc;
6325+	short promisc;
6326 	/*stats*/
6327 	struct Stats stats;
6328 	struct iw_statistics wstats;
6329 	struct proc_dir_entry *dir_dev;
6330-
6331+
6332 	/*RX stuff*/
6333 //	u32 *rxring;
6334 //	u32 *rxringtail;
6335@@ -213,20 +221,20 @@
6336 	struct urb **rx_urb;
6337 	struct tx_urb_context tx_context[MAX_TX_URB];
6338 	short  tx_urb_index;
6339-
6340+
6341 	//struct buffer *rxbuffer;
6342 	//struct buffer *rxbufferhead;
6343 	//int rxringcount;
6344 	//u16 rxbuffersize;
6345-
6346-	//struct sk_buff *rx_skb;
6347+
6348+	//struct sk_buff *rx_skb;
6349
6350 	//short rx_skb_complete;
6351
6352 	//u32 rx_prevlen;
6353 	atomic_t tx_lp_pending;
6354 	atomic_t tx_np_pending;
6355-#if 0
6356+#if 0
6357 	/*TX stuff*/
6358 	u32 *txlpring;
6359 	u32 *txhpring;
6360@@ -256,7 +264,7 @@
6361 	struct urb *rxurb_task;
6362 //	u8 dma_poll_mask;
6363 	//short tx_suspend;
6364-
6365+
6366 	/* adhoc/master mode stuff */
6367 #if 0
6368 	u32 *txbeacontail;
6369@@ -270,15 +278,20 @@
6370 	//u16 master_beaconinterval;
6371 //	u32 master_beaconsize;
6372 	//u16 beacon_interval;
6373-
6374+
6375 	u8 retry_data;
6376 	u8 retry_rts;
6377 	u16 rts;
6378 	u8 ps_sleep_finish;//1, finish hw sleep ,0 finish hw wakeup
6379
6380-
6381+
6382 	struct work_struct reset_wq;
6383 	struct work_struct rtl8180_hw_wakeup_wq;
6384+//        struct work_struct rtl8180_rq_tx_ack_wq;
6385+//         struct work_struct rtl8180_hw_sleep_wq;
6386+
6387+        struct work_struct SwLed0WorkItemCallback_wq;
6388+
6389 	short ack_tx_to_ieee;
6390
6391
6392@@ -292,15 +305,15 @@
6393 	LED_STRATEGY_8187	LedStrategy;
6394 	u8			PsrValue;
6395 	struct work_struct		Gpio0LedWorkItem;
6396-	struct work_struct		SwLed0WorkItem;
6397-	struct work_struct		SwLed1WorkItem;
6398-
6399+	struct work_struct		SwLed0WorkItem;
6400+	struct work_struct		SwLed1WorkItem;
6401+
6402 }r8180_priv;
6403
6404
6405-typedef enum{
6406+typedef enum{
6407 	LOW_PRIORITY ,
6408-	NORM_PRIORITY
6409+	NORM_PRIORITY
6410 	} priority_t;
6411
6412
6413diff -Naur r8187_orig/rtl8187/r8187_led.c r8187_rawtx/rtl8187/r8187_led.c
6414--- r8187_orig/rtl8187/r8187_led.c	2007-01-15 03:00:37.000000000 +0100
6415+++ r8187_rawtx/rtl8187/r8187_led.c	2007-05-16 21:51:33.000000000 +0200
6416@@ -3,35 +3,35 @@
6417
6418 Module Name:
6419  	r8187_led.c
6420-
6421+
6422 Abstract:
6423  	RTL8187 LED control functions
6424-
6425+
6426 Major Change History:
6427 	When        Who      What
6428 	----------    ---------------   -------------------------------
6429 	2006-09-07    Xiong		Created
6430-
6431-Notes:
6432-
6433+
6434+Notes:
6435+
6436 --*/
6437
6438 /*--------------------------Include File------------------------------------*/
6439 #include "r8180_hw.h"
6440 #include "r8187.h"
6441-#include "r8180_93cx6.h"
6442+#include "r8180_93cx6.h"
6443 #include "r8187_led.h"
6444
6445
6446 /**
6447 *
6448-* Initialization function for Sw Leds controll.
6449-*
6450+* Initialization function for Sw Leds controll.
6451+*
6452 * \param dev      The net device for this driver.
6453 * \return void.
6454 *
6455-* Note:
6456-*
6457+* Note:
6458+*
6459 */
6460 void
6461 InitSwLeds(
6462@@ -49,7 +49,7 @@
6463 	DMESG("EEPROM Customer ID: %02X\n", priv->EEPROMCustomerID);
6464
6465 	if(priv->CustomerID == RT_CID_DEFAULT)
6466-	{ // If we have not yet change priv->CustomerID in register,
6467+	{ // If we have not yet change priv->CustomerID in register,
6468 	  // we initialzie it from that of EEPROM with proper translation, 2006.07.03, by rcnjko.
6469 		switch(priv->EEPROMCustomerID)
6470 		{
6471@@ -57,19 +57,19 @@
6472 		case EEPROM_CID_RSVD1:
6473 			priv->CustomerID = RT_CID_DEFAULT;
6474 			break;
6475-
6476+
6477 		case EEPROM_CID_ALPHA0:
6478 			priv->CustomerID = RT_CID_8187_ALPHA0;
6479 			break;
6480-
6481+
6482 		case EEPROM_CID_SERCOMM_PS:
6483 			priv->CustomerID = RT_CID_8187_SERCOMM_PS;
6484 			break;
6485-
6486+
6487 		case EEPROM_CID_HW_LED:
6488 			priv->CustomerID = RT_CID_8187_HW_LED;
6489 			break;
6490-
6491+
6492 		default:
6493 			// Invalid value, so, we use default value instead.
6494 			priv->CustomerID = RT_CID_DEFAULT;
6495@@ -78,13 +78,13 @@
6496 	}
6497 	switch(priv->CustomerID)
6498 	{
6499-	case RT_CID_DEFAULT:
6500+	case RT_CID_DEFAULT:
6501 		priv->LedStrategy = SW_LED_MODE0;
6502 		break;
6503-
6504+
6505 	case RT_CID_8187_ALPHA0:
6506 		priv->LedStrategy = SW_LED_MODE1;
6507-		break;
6508+		break;
6509
6510 	case RT_CID_8187_SERCOMM_PS:
6511 		priv->LedStrategy = SW_LED_MODE3;
6512@@ -98,27 +98,39 @@
6513 		priv->LedStrategy = SW_LED_MODE0;
6514 		break;
6515 	}
6516-
6517-	InitLed8187(dev,
6518-				&(priv->Gpio0Led),
6519-				LED_PIN_GPIO0,
6520+
6521+	InitLed8187(dev,
6522+				&(priv->Gpio0Led),
6523+				LED_PIN_GPIO0,
6524 				Gpio0LedBlinkTimerCallback);
6525-	INIT_WORK(&priv->Gpio0LedWorkItem,
6526+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6527+	INIT_WORK(&priv->Gpio0LedWorkItem,
6528 				(void(*)(void*))Gpio0LedWorkItemCallback, dev);
6529+#else
6530+	INIT_WORK(&priv->Gpio0LedWorkItem, Gpio0LedWorkItemCallback);
6531+#endif
6532
6533 	InitLed8187(dev,
6534-				&(priv->SwLed0),
6535-				LED_PIN_LED0,
6536+				&(priv->SwLed0),
6537+				LED_PIN_LED0,
6538 				SwLed0BlinkTimerCallback);
6539-	INIT_WORK(&priv->SwLed0WorkItem,
6540+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6541+	INIT_WORK(&priv->SwLed0WorkItem,
6542 				(void(*)(void*))SwLed0WorkItemCallback, dev);
6543+#else
6544+	INIT_WORK(&priv->SwLed0WorkItem, SwLed0WorkItemCallback);
6545+#endif
6546
6547 	InitLed8187(dev,
6548-				&(priv->SwLed1),
6549-				LED_PIN_LED1,
6550+				&(priv->SwLed1),
6551+				LED_PIN_LED1,
6552 				SwLed1BlinkTimerCallback);
6553-	INIT_WORK(&priv->SwLed1WorkItem,
6554+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6555+	INIT_WORK(&priv->SwLed1WorkItem,
6556 				(void(*)(void*))SwLed1WorkItemCallback, dev);
6557+#else
6558+	INIT_WORK(&priv->SwLed1WorkItem, SwLed1WorkItemCallback);
6559+#endif
6560 }
6561
6562 void
6563@@ -135,7 +147,7 @@
6564
6565 void
6566 InitLed8187(
6567-	struct net_device *dev,
6568+	struct net_device *dev,
6569 	PLED_8187		pLed,
6570 	LED_PIN_8187		LedPin,
6571 	void	* 		BlinkCallBackFunc)
6572@@ -157,7 +169,7 @@
6573
6574 void
6575 DeInitLed8187(
6576-	struct net_device *dev,
6577+	struct net_device *dev,
6578 	PLED_8187			pLed)
6579 {
6580 	//PlatformCancelTimer(dev, &(pLed->BlinkTimer));
6581@@ -178,10 +190,10 @@
6582 		return;
6583
6584 /*
6585-	if(	priv->eRFPowerState != eRfOn &&
6586-		(LedAction == LED_CTL_TX || LedAction == LED_CTL_RX ||
6587-		 LedAction == LED_CTL_SITE_SURVEY ||
6588-		 LedAction == LED_CTL_LINK ||
6589+	if(	priv->eRFPowerState != eRfOn &&
6590+		(LedAction == LED_CTL_TX || LedAction == LED_CTL_RX ||
6591+		 LedAction == LED_CTL_SITE_SURVEY ||
6592+		 LedAction == LED_CTL_LINK ||
6593 		 LedAction == LED_CTL_NO_LINK) )
6594 	{
6595 		return;
6596@@ -213,7 +225,7 @@
6597
6598
6599 //
6600-//	Description:
6601+//	Description:
6602 //		Implement each led action for SW_LED_MODE0.
6603 //		This is default strategy.
6604 //
6605@@ -261,7 +273,7 @@
6606 	case LED_CTL_NO_LINK:
6607 		pLed->CurrLedState = LED_OFF;
6608 		break;
6609-
6610+
6611 	case LED_CTL_POWER_ON:
6612 		pLed->CurrLedState = LED_POWER_ON_BLINK;
6613 		break;
6614@@ -297,10 +309,10 @@
6615 		{
6616 			pLed->bLedBlinkInProgress = 1;
6617 			if( pLed->bLedOn )
6618-				pLed->BlinkingLedState = LED_OFF;
6619+				pLed->BlinkingLedState = LED_OFF;
6620 			else
6621-				pLed->BlinkingLedState = LED_ON;
6622-
6623+				pLed->BlinkingLedState = LED_ON;
6624+
6625 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_NORMAL_INTERVAL;
6626 			add_timer(&(pLed->BlinkTimer));
6627 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
6628@@ -312,10 +324,10 @@
6629 		{
6630 			pLed->bLedBlinkInProgress = 1;
6631 			if( pLed->bLedOn )
6632-				pLed->BlinkingLedState = LED_OFF;
6633+				pLed->BlinkingLedState = LED_OFF;
6634 			else
6635 				pLed->BlinkingLedState = LED_ON;
6636-
6637+
6638 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_SLOWLY_INTERVAL;
6639 			add_timer(&(pLed->BlinkTimer));
6640 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
6641@@ -334,7 +346,7 @@
6642 }
6643
6644 //
6645-//	Description:
6646+//	Description:
6647 //		Implement each led action for SW_LED_MODE1.
6648 //		For example, this is applied by ALPHA.
6649 //
6650@@ -357,9 +369,9 @@
6651 			pLed0->BlinkTimes = 2;
6652 			pLed0->bLedBlinkInProgress = 1;
6653 			if( pLed0->bLedOn )
6654-				pLed0->BlinkingLedState = LED_OFF;
6655+				pLed0->BlinkingLedState = LED_OFF;
6656 			else
6657-				pLed0->BlinkingLedState = LED_ON;
6658+				pLed0->BlinkingLedState = LED_ON;
6659
6660 			pLed0->BlinkTimer.expires = jiffies + LED_BLINK_NORMAL_INTERVAL;
6661 			add_timer(&(pLed0->BlinkTimer));
6662@@ -382,7 +394,7 @@
6663 			SwLedOff(dev, pLed0);
6664 		}
6665 		break;
6666-
6667+
6668 	case LED_CTL_POWER_ON:
6669 		pLed0->CurrLedState = LED_OFF;
6670 		SwLedOff(dev, pLed0);
6671@@ -407,7 +419,7 @@
6672 			pLed0->BlinkTimes = 10;
6673 			pLed0->bLedBlinkInProgress = 1;
6674 			if( pLed0->bLedOn )
6675-				pLed0->BlinkingLedState = LED_OFF;
6676+				pLed0->BlinkingLedState = LED_OFF;
6677 			else
6678 				pLed0->BlinkingLedState = LED_ON;
6679
6680@@ -423,9 +435,9 @@
6681 }
6682
6683 //
6684-//	Description:
6685-//		Implement each led action for SW_LED_MODE2,
6686-//		which is customized for AzWave 8187 minicard.
6687+//	Description:
6688+//		Implement each led action for SW_LED_MODE2,
6689+//		which is customized for AzWave 8187 minicard.
6690 //		2006.04.03, by rcnjko.
6691 //
6692 void
6693@@ -450,9 +462,9 @@
6694 			pLed->BlinkTimes = 2;
6695
6696 			if( pLed->bLedOn )
6697-				pLed->BlinkingLedState = LED_OFF;
6698+				pLed->BlinkingLedState = LED_OFF;
6699 			else
6700-				pLed->BlinkingLedState = LED_ON;
6701+				pLed->BlinkingLedState = LED_ON;
6702
6703 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_NORMAL_INTERVAL;
6704 			add_timer(&(pLed->BlinkTimer));
6705@@ -465,7 +477,7 @@
6706 		{
6707 			pLed->bLedBlinkInProgress = 1;
6708
6709-			//if(	dev->MgntInfo.mAssoc ||
6710+			//if(	dev->MgntInfo.mAssoc ||
6711 			//	dev->MgntInfo.mIbss )
6712 			//{
6713 				pLed->CurrLedState = LED_SCAN_BLINK;
6714@@ -486,7 +498,7 @@
6715 			}
6716 			else
6717 			{
6718-				pLed->BlinkingLedState = LED_ON;
6719+				pLed->BlinkingLedState = LED_ON;
6720 				pLed->BlinkTimer.expires = jiffies + LED_CM2_BLINK_OFF_INTERVAL;
6721 				add_timer(&(pLed->BlinkTimer));
6722 				//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_CM2_BLINK_OFF_INTERVAL);
6723@@ -498,7 +510,7 @@
6724 			{
6725 				pLed->CurrLedState = LED_SCAN_BLINK;
6726 				/*
6727-				if(	dev->MgntInfo.mAssoc ||
6728+				if(	dev->MgntInfo.mAssoc ||
6729 					dev->MgntInfo.mIbss )
6730 				{
6731 					pLed->CurrLedState = LED_SCAN_BLINK;
6732@@ -522,14 +534,14 @@
6733
6734 			if( pLed->bLedOn )
6735 			{
6736-				pLed->BlinkingLedState = LED_OFF;
6737+				pLed->BlinkingLedState = LED_OFF;
6738 				pLed->BlinkTimer.expires = jiffies + LED_CM2_BLINK_ON_INTERVAL;
6739 				add_timer(&(pLed->BlinkTimer));
6740 				//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_CM2_BLINK_ON_INTERVAL);
6741 			}
6742 			else
6743 			{
6744-				pLed->BlinkingLedState = LED_ON;
6745+				pLed->BlinkingLedState = LED_ON;
6746 				pLed->BlinkTimer.expires = jiffies + LED_CM2_BLINK_OFF_INTERVAL;
6747 				add_timer(&(pLed->BlinkTimer));
6748 				//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_CM2_BLINK_OFF_INTERVAL);
6749@@ -564,9 +576,9 @@
6750
6751
6752 //
6753-//	Description:
6754-//		Implement each led action for SW_LED_MODE3,
6755-//		which is customized for Sercomm Printer Server case.
6756+//	Description:
6757+//		Implement each led action for SW_LED_MODE3,
6758+//		which is customized for Sercomm Printer Server case.
6759 //		2006.04.21, by rcnjko.
6760 //
6761 void
6762@@ -591,9 +603,9 @@
6763 			pLed->BlinkTimes = 2;
6764
6765 			if( pLed->bLedOn )
6766-				pLed->BlinkingLedState = LED_OFF;
6767+				pLed->BlinkingLedState = LED_OFF;
6768 			else
6769-				pLed->BlinkingLedState = LED_ON;
6770+				pLed->BlinkingLedState = LED_ON;
6771
6772 			pLed->BlinkTimer.expires = jiffies + LED_CM3_BLINK_INTERVAL;
6773 			add_timer(&(pLed->BlinkTimer));
6774@@ -610,9 +622,9 @@
6775 			pLed->BlinkTimes = 10;
6776
6777 			if( pLed->bLedOn )
6778-				pLed->BlinkingLedState = LED_OFF;
6779+				pLed->BlinkingLedState = LED_OFF;
6780 			else
6781-				pLed->BlinkingLedState = LED_ON;
6782+				pLed->BlinkingLedState = LED_ON;
6783
6784 			pLed->BlinkTimer.expires = jiffies + LED_CM3_BLINK_INTERVAL;
6785 			add_timer(&(pLed->BlinkTimer));
6786@@ -729,18 +741,21 @@
6787 	}
6788 }
6789
6790-//
6791+//
6792 // Callback fucntion of the workitem for SW LEDs.
6793 // 2006.03.01, by rcnjko.
6794 //
6795-void
6796-Gpio0LedWorkItemCallback(
6797-	void *			Context
6798-	)
6799+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6800+void Gpio0LedWorkItemCallback(struct work_struct *work)
6801+{
6802+	struct r8180_priv *priv = container_of(work, struct r8180_priv, Gpio0LedWorkItem);
6803+	struct net_device *dev = priv->dev;
6804+#else
6805+void Gpio0LedWorkItemCallback(struct net_device *dev)
6806 {
6807-	struct net_device *dev = (struct net_device *)Context;
6808 	struct r8180_priv *priv = ieee80211_priv(dev);
6809-	PLED_8187	pLed = &(priv->Gpio0Led);
6810+#endif
6811+	PLED_8187	pLed = &(priv->Gpio0Led);
6812
6813 	if(priv->LedStrategy == SW_LED_MODE2)
6814 		SwLedCm2Blink(dev, pLed);
6815@@ -750,27 +765,31 @@
6816 	//LeaveCallbackOfRtWorkItem( &(usbdevice->Gpio0LedWorkItem) );
6817 }
6818
6819-void
6820-SwLed0WorkItemCallback(
6821-	void *			Context
6822-	)
6823+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6824+void SwLed0WorkItemCallback(struct work_struct *work)
6825+{
6826+	struct r8180_priv *priv = container_of(work, struct r8180_priv, SwLed0WorkItem);
6827+	struct net_device *dev = priv->dev;
6828+#else
6829+void SwLed0WorkItemCallback(struct net_device *dev)
6830 {
6831-	struct net_device *dev = (struct net_device *)Context;
6832 	struct r8180_priv *priv = ieee80211_priv(dev);
6833-
6834+#endif
6835 	SwLedBlink(dev, &(priv->SwLed0));
6836
6837 	//LeaveCallbackOfRtWorkItem( &(usbdevice->SwLed0WorkItem) );
6838 }
6839
6840-void
6841-SwLed1WorkItemCallback(
6842-	void *			Context
6843-	)
6844+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6845+void SwLed1WorkItemCallback(struct work_struct *work)
6846+{
6847+	struct r8180_priv *priv = container_of(work, struct r8180_priv, SwLed1WorkItem);
6848+	struct net_device *dev = priv->dev;
6849+#else
6850+void SwLed1WorkItemCallback(struct net_device *dev)
6851 {
6852-	struct net_device *dev = (struct net_device *)Context;
6853 	struct r8180_priv *priv = ieee80211_priv(dev);
6854-
6855+#endif
6856 	SwLedBlink(dev, &(priv->SwLed1));
6857
6858 	//LeaveCallbackOfRtWorkItem( &(usbdevice->SwLed1WorkItem) );
6859@@ -782,19 +801,19 @@
6860 //
6861 void
6862 SwLedBlink(
6863-	struct net_device *dev,
6864+	struct net_device *dev,
6865 	PLED_8187			pLed
6866 	)
6867 {
6868 	u8 bStopBlinking = 0;
6869
6870 	// Change LED according to BlinkingLedState specified.
6871-	if( pLed->BlinkingLedState == LED_ON )
6872+	if( pLed->BlinkingLedState == LED_ON )
6873 	{
6874 		SwLedOn(dev, pLed);
6875 		//DMESG("Blinktimes (%d): turn on\n", pLed->BlinkTimes);
6876-	}
6877-	else
6878+	}
6879+	else
6880 	{
6881 		SwLedOff(dev, pLed);
6882 		//DMESG("Blinktimes (%d): turn off\n", pLed->BlinkTimes);
6883@@ -828,40 +847,40 @@
6884 		}
6885
6886 		pLed->BlinkTimes = 0;
6887-		pLed->bLedBlinkInProgress = 0;
6888+		pLed->bLedBlinkInProgress = 0;
6889 	}
6890 	else
6891 	{
6892 		// Assign LED state to toggle.
6893-		if( pLed->BlinkingLedState == LED_ON )
6894+		if( pLed->BlinkingLedState == LED_ON )
6895 			pLed->BlinkingLedState = LED_OFF;
6896-		else
6897+		else
6898 			pLed->BlinkingLedState = LED_ON;
6899
6900-		// Schedule a timer to toggle LED state.
6901+		// Schedule a timer to toggle LED state.
6902 		switch( pLed->CurrLedState )
6903 		{
6904 		case LED_BLINK_NORMAL:
6905 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_NORMAL_INTERVAL;
6906-			add_timer(&(pLed->BlinkTimer));
6907+			add_timer(&(pLed->BlinkTimer));
6908 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
6909 			break;
6910
6911 		case LED_BLINK_SLOWLY:
6912 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_SLOWLY_INTERVAL;
6913-			add_timer(&(pLed->BlinkTimer));
6914+			add_timer(&(pLed->BlinkTimer));
6915 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
6916 			break;
6917
6918 		case LED_BLINK_CM3:
6919 			pLed->BlinkTimer.expires = jiffies + LED_CM3_BLINK_INTERVAL;
6920-			add_timer(&(pLed->BlinkTimer));
6921+			add_timer(&(pLed->BlinkTimer));
6922 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_CM3_BLINK_INTERVAL);
6923 			break;
6924
6925 		default:
6926 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_SLOWLY_INTERVAL;
6927-			add_timer(&(pLed->BlinkTimer));
6928+			add_timer(&(pLed->BlinkTimer));
6929 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
6930 			break;
6931 		}
6932@@ -871,11 +890,11 @@
6933
6934
6935 //
6936-//	Implementation of LED blinking behavior for SwLedControlMode2.
6937+//	Implementation of LED blinking behavior for SwLedControlMode2.
6938 //
6939 void
6940 SwLedCm2Blink(
6941-	struct net_device *dev,
6942+	struct net_device *dev,
6943 	PLED_8187			pLed
6944 	)
6945 {
6946@@ -884,12 +903,12 @@
6947 	u8 bStopBlinking = 0;
6948
6949 	// Change LED according to BlinkingLedState specified.
6950-	if( pLed->BlinkingLedState == LED_ON )
6951+	if( pLed->BlinkingLedState == LED_ON )
6952 	{
6953 		SwLedOn(dev, pLed);
6954 		//DMESG("Blinktimes (%d): turn on\n", pLed->BlinkTimes);
6955-	}
6956-	else
6957+	}
6958+	else
6959 	{
6960 		SwLedOff(dev, pLed);
6961 		//DMESG("Blinktimes (%d): turn off\n", pLed->BlinkTimes);
6962@@ -899,13 +918,13 @@
6963 	pLed->BlinkTimes--;
6964 	switch(pLed->CurrLedState)
6965 	{
6966-	case LED_BLINK_NORMAL:
6967+	case LED_BLINK_NORMAL:
6968 		if(pLed->BlinkTimes == 0)
6969 		{
6970 			bStopBlinking = 1;
6971 		}
6972 		break;
6973-/* CM2 scan blink and no link blind now not be supported
6974+/* CM2 scan blink and no link blind now not be supported
6975 	case LED_SCAN_BLINK:
6976 		if( (priv->mAssoc || priv->mIbss) &&  // Linked.
6977 			(!priv->bScanInProgress) && // Not in scan stage.
6978@@ -916,9 +935,9 @@
6979 		break;
6980
6981 	case LED_NO_LINK_BLINK:
6982-		//Revised miniCard Ad-hoc mode "Slow Blink" by Isaiah 2006-08-03
6983+		//Revised miniCard Ad-hoc mode "Slow Blink" by Isaiah 2006-08-03
6984 		//if( (priv->mAssoc || priv->mIbss) ) // Linked.
6985-		if( priv->mAssoc)
6986+		if( priv->mAssoc)
6987 		{
6988 			bStopBlinking = 1;
6989 		}
6990@@ -950,28 +969,28 @@
6991 		}
6992 */
6993 		pLed->BlinkTimes = 0;
6994-		pLed->bLedBlinkInProgress = 0;
6995+		pLed->bLedBlinkInProgress = 0;
6996 	}
6997 	else
6998 	{
6999 		// Assign LED state to toggle.
7000-		if( pLed->BlinkingLedState == LED_ON )
7001+		if( pLed->BlinkingLedState == LED_ON )
7002 			pLed->BlinkingLedState = LED_OFF;
7003-		else
7004+		else
7005 			pLed->BlinkingLedState = LED_ON;
7006
7007-		// Schedule a timer to toggle LED state.
7008+		// Schedule a timer to toggle LED state.
7009 		switch( pLed->CurrLedState )
7010 		{
7011 		case LED_BLINK_NORMAL:
7012 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_NORMAL_INTERVAL;
7013-			add_timer(&(pLed->BlinkTimer));
7014+			add_timer(&(pLed->BlinkTimer));
7015 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_NORMAL_INTERVAL);
7016 			break;
7017
7018 		case LED_BLINK_SLOWLY:
7019 			pLed->BlinkTimer.expires = jiffies + LED_BLINK_SLOWLY_INTERVAL;
7020-			add_timer(&(pLed->BlinkTimer));
7021+			add_timer(&(pLed->BlinkTimer));
7022 			//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_BLINK_SLOWLY_INTERVAL);
7023 			break;
7024
7025@@ -979,11 +998,11 @@
7026 		case LED_NO_LINK_BLINK:
7027 			if( pLed->bLedOn ) {
7028 				pLed->BlinkTimer.expires = jiffies + LED_CM2_BLINK_ON_INTERVAL;
7029-				add_timer(&(pLed->BlinkTimer));
7030+				add_timer(&(pLed->BlinkTimer));
7031 				//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_CM2_BLINK_ON_INTERVAL);
7032 			} else {
7033 				pLed->BlinkTimer.expires = jiffies + LED_CM2_BLINK_OFF_INTERVAL;
7034-				add_timer(&(pLed->BlinkTimer));
7035+				add_timer(&(pLed->BlinkTimer));
7036 				//PlatformSetTimer(dev, &(pLed->BlinkTimer), LED_CM2_BLINK_OFF_INTERVAL);
7037 			}
7038 			break;
7039@@ -1000,7 +1019,7 @@
7040
7041 void
7042 SwLedOn(
7043-	struct net_device *dev,
7044+	struct net_device *dev,
7045 	PLED_8187			pLed
7046 )
7047 {
7048@@ -1032,7 +1051,7 @@
7049
7050 void
7051 SwLedOff(
7052-	struct net_device *dev,
7053+	struct net_device *dev,
7054 	PLED_8187			pLed
7055 )
7056 {
7057@@ -1060,5 +1079,5 @@
7058 	}
7059
7060 	pLed->bLedOn = 0;
7061-}
7062+}
7063
7064diff -Naur r8187_orig/rtl8187/r8187_led.h r8187_rawtx/rtl8187/r8187_led.h
7065--- r8187_orig/rtl8187/r8187_led.h	2007-01-15 03:00:37.000000000 +0100
7066+++ r8187_rawtx/rtl8187/r8187_led.h	2007-05-16 21:51:38.000000000 +0200
7067@@ -7,7 +7,7 @@
7068
7069 Abstract:
7070     definitions and stuctures for rtl8187 led control.
7071-
7072+
7073 Major Change History:
7074       When        Who	What
7075     ----------	------	----------------------------------------------
7076@@ -127,14 +127,14 @@
7077
7078 void
7079 InitLed8187(
7080-	struct net_device *dev,
7081+	struct net_device *dev,
7082 	PLED_8187		pLed,
7083 	LED_PIN_8187		LedPin,
7084 	void	* 		BlinkCallBackFunc);
7085
7086 void
7087 DeInitLed8187(
7088-	struct net_device *dev,
7089+	struct net_device *dev,
7090 	PLED_8187			pLed);
7091
7092 void
7093@@ -188,42 +188,37 @@
7094 	PLED_8187		pLed
7095 	);
7096
7097-void
7098-Gpio0LedWorkItemCallback(
7099-	void *			Context
7100-	);
7101-
7102-void
7103-SwLed0WorkItemCallback(
7104-	void *			Context
7105-	);
7106-
7107-void
7108-SwLed1WorkItemCallback(
7109-	void *			Context
7110-	);
7111+# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
7112+void SwLed0WorkItemCallback(struct work_struct *work);
7113+void SwLed1WorkItemCallback(struct work_struct *work);
7114+void Gpio0LedWorkItemCallback(struct work_struct *work);
7115+#else
7116+void SwLed0WorkItemCallback(struct net_device *dev);
7117+void SwLed1WorkItemCallback(struct net_device *dev);
7118+void Gpio0LedWorkItemCallback(struct net_device *dev);
7119+#endif
7120
7121 void
7122 SwLedBlink(
7123-	struct net_device *dev,
7124+	struct net_device *dev,
7125 	PLED_8187			pLed
7126 	);
7127
7128 void
7129 SwLedCm2Blink(
7130-	struct net_device *dev,
7131+	struct net_device *dev,
7132 	PLED_8187			pLed
7133 	);
7134
7135 void
7136 SwLedOn(
7137-	struct net_device *dev,
7138+	struct net_device *dev,
7139 	PLED_8187			pLed
7140 );
7141
7142 void
7143 SwLedOff(
7144-	struct net_device *dev,
7145+	struct net_device *dev,
7146 	PLED_8187			pLed
7147 );
7148
7149diff -Naur r8187_orig/symvers r8187_rawtx/symvers
7150--- r8187_orig/symvers	1970-01-01 01:00:00.000000000 +0100
7151+++ r8187_rawtx/symvers	2007-05-13 09:54:44.000000000 +0200
7152@@ -0,0 +1,25 @@
7153+#!/bin/sh
7154+
7155+cd rtl8187
7156+
7157+if [ -e Module.symvers ]
7158+then
7159+	rm Module.symvers
7160+fi
7161+
7162+if [ -e Modules.symvers ]
7163+then
7164+	rm Modules.symvers
7165+fi
7166+
7167+if [ -e ../ieee80211/Module.symvers ]
7168+then
7169+	ln -sf ../ieee80211/Module.symvers ./
7170+fi
7171+
7172+if [ -e ../ieee80211/Modules.symvers ]
7173+then
7174+	ln -sf ../ieee80211/Modules.symvers ./
7175+fi
7176+
7177+cd ..
7178\ Kein Zeilenumbruch am Dateiende.
7179