]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mv-sheeva.git] / drivers / staging / rtl8187se / ieee80211 / ieee80211_softmac.c
1 /* IEEE 802.11 SoftMAC layer
2  * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
3  *
4  * Mostly extracted from the rtl8180-sa2400 driver for the
5  * in-kernel generic ieee802.11 stack.
6  *
7  * Few lines might be stolen from other part of the ieee80211
8  * stack. Copyright who own it's copyright
9  *
10  * WPA code stolen from the ipw2200 driver.
11  * Copyright who own it's copyright.
12  *
13  * released under the GPL
14  */
15
16
17 #include "ieee80211.h"
18
19 #include <linux/random.h>
20 #include <linux/delay.h>
21 #include <linux/slab.h>
22 #include <linux/version.h>
23 #include <asm/uaccess.h>
24
25 #include "dot11d.h"
26 u8 rsn_authen_cipher_suite[16][4] = {
27         {0x00,0x0F,0xAC,0x00}, //Use group key, //Reserved
28         {0x00,0x0F,0xAC,0x01}, //WEP-40         //RSNA default
29         {0x00,0x0F,0xAC,0x02}, //TKIP           //NONE          //{used just as default}
30         {0x00,0x0F,0xAC,0x03}, //WRAP-historical
31         {0x00,0x0F,0xAC,0x04}, //CCMP
32         {0x00,0x0F,0xAC,0x05}, //WEP-104
33 };
34
35 short ieee80211_is_54g(struct ieee80211_network net)
36 {
37         return ((net.rates_ex_len > 0) || (net.rates_len > 4));
38 }
39
40 short ieee80211_is_shortslot(struct ieee80211_network net)
41 {
42         return (net.capability & WLAN_CAPABILITY_SHORT_SLOT);
43 }
44
45 /* returns the total length needed for pleacing the RATE MFIE
46  * tag and the EXTENDED RATE MFIE tag if needed.
47  * It encludes two bytes per tag for the tag itself and its len
48  */
49 unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device *ieee)
50 {
51         unsigned int rate_len = 0;
52
53         if (ieee->modulation & IEEE80211_CCK_MODULATION)
54                 rate_len = IEEE80211_CCK_RATE_LEN + 2;
55
56         if (ieee->modulation & IEEE80211_OFDM_MODULATION)
57
58                 rate_len += IEEE80211_OFDM_RATE_LEN + 2;
59
60         return rate_len;
61 }
62
63 /* pleace the MFIE rate, tag to the memory (double) poined.
64  * Then it updates the pointer so that
65  * it points after the new MFIE tag added.
66  */
67 void ieee80211_MFIE_Brate(struct ieee80211_device *ieee, u8 **tag_p)
68 {
69         u8 *tag = *tag_p;
70
71         if (ieee->modulation & IEEE80211_CCK_MODULATION){
72                 *tag++ = MFIE_TYPE_RATES;
73                 *tag++ = 4;
74                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
75                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
76                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
77                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
78         }
79
80         /* We may add an option for custom rates that specific HW might support */
81         *tag_p = tag;
82 }
83
84 void ieee80211_MFIE_Grate(struct ieee80211_device *ieee, u8 **tag_p)
85 {
86         u8 *tag = *tag_p;
87
88                 if (ieee->modulation & IEEE80211_OFDM_MODULATION){
89
90                 *tag++ = MFIE_TYPE_RATES_EX;
91                 *tag++ = 8;
92                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
93                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
94                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
95                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
96                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
97                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
98                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
99                 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
100
101         }
102
103         /* We may add an option for custom rates that specific HW might support */
104         *tag_p = tag;
105 }
106
107
108 void ieee80211_WMM_Info(struct ieee80211_device *ieee, u8 **tag_p) {
109         u8 *tag = *tag_p;
110
111         *tag++ = MFIE_TYPE_GENERIC; //0
112         *tag++ = 7;
113         *tag++ = 0x00;
114         *tag++ = 0x50;
115         *tag++ = 0xf2;
116         *tag++ = 0x02;//5
117         *tag++ = 0x00;
118         *tag++ = 0x01;
119 #ifdef SUPPORT_USPD
120         if(ieee->current_network.wmm_info & 0x80) {
121                 *tag++ = 0x0f|MAX_SP_Len;
122         } else {
123                 *tag++ = MAX_SP_Len;
124         }
125 #else
126         *tag++ = MAX_SP_Len;
127 #endif
128         *tag_p = tag;
129 }
130
131 void ieee80211_TURBO_Info(struct ieee80211_device *ieee, u8 **tag_p) {
132         u8 *tag = *tag_p;
133
134         *tag++ = MFIE_TYPE_GENERIC; //0
135         *tag++ = 7;
136         *tag++ = 0x00;
137         *tag++ = 0xe0;
138         *tag++ = 0x4c;
139         *tag++ = 0x01;//5
140         *tag++ = 0x02;
141         *tag++ = 0x11;
142         *tag++ = 0x00;
143
144         *tag_p = tag;
145         printk(KERN_ALERT "This is enable turbo mode IE process\n");
146 }
147
148 void enqueue_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb)
149 {
150         int nh;
151         nh = (ieee->mgmt_queue_head +1) % MGMT_QUEUE_NUM;
152
153 /*
154  * if the queue is full but we have newer frames then
155  * just overwrites the oldest.
156  *
157  * if (nh == ieee->mgmt_queue_tail)
158  *              return -1;
159  */
160         ieee->mgmt_queue_head = nh;
161         ieee->mgmt_queue_ring[nh] = skb;
162
163         //return 0;
164 }
165
166 struct sk_buff *dequeue_mgmt(struct ieee80211_device *ieee)
167 {
168         struct sk_buff *ret;
169
170         if(ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
171                 return NULL;
172
173         ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
174
175         ieee->mgmt_queue_tail =
176                 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
177
178         return ret;
179 }
180
181 void init_mgmt_queue(struct ieee80211_device *ieee)
182 {
183         ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
184 }
185
186
187 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl);
188
189 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
190 {
191         unsigned long flags;
192         short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
193         struct ieee80211_hdr_3addr  *header=
194                 (struct ieee80211_hdr_3addr  *) skb->data;
195
196
197         spin_lock_irqsave(&ieee->lock, flags);
198
199         /* called with 2nd param 0, no mgmt lock required */
200         ieee80211_sta_wakeup(ieee,0);
201
202         if(single){
203                 if(ieee->queue_stop){
204
205                         enqueue_mgmt(ieee,skb);
206                 }else{
207                         header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
208
209                         if (ieee->seq_ctrl[0] == 0xFFF)
210                                 ieee->seq_ctrl[0] = 0;
211                         else
212                                 ieee->seq_ctrl[0]++;
213
214                         /* avoid watchdog triggers */
215                         ieee->dev->trans_start = jiffies;
216                         ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
217                 }
218
219                 spin_unlock_irqrestore(&ieee->lock, flags);
220         }else{
221                 spin_unlock_irqrestore(&ieee->lock, flags);
222                 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
223
224                 header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
225
226                 if (ieee->seq_ctrl[0] == 0xFFF)
227                         ieee->seq_ctrl[0] = 0;
228                 else
229                         ieee->seq_ctrl[0]++;
230
231                 /* avoid watchdog triggers */
232                 ieee->dev->trans_start = jiffies;
233                 ieee->softmac_hard_start_xmit(skb,ieee->dev);
234
235                 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
236         }
237 }
238
239
240 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
241 {
242
243         short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
244         struct ieee80211_hdr_3addr  *header =
245                 (struct ieee80211_hdr_3addr  *) skb->data;
246
247
248         if(single){
249
250                 header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
251
252                 if (ieee->seq_ctrl[0] == 0xFFF)
253                         ieee->seq_ctrl[0] = 0;
254                 else
255                         ieee->seq_ctrl[0]++;
256
257                 /* avoid watchdog triggers */
258                 ieee->dev->trans_start = jiffies;
259                 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
260
261         }else{
262
263                 header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
264
265                 if (ieee->seq_ctrl[0] == 0xFFF)
266                         ieee->seq_ctrl[0] = 0;
267                 else
268                         ieee->seq_ctrl[0]++;
269
270                 /* avoid watchdog triggers */
271                 ieee->dev->trans_start = jiffies;
272                 ieee->softmac_hard_start_xmit(skb,ieee->dev);
273
274         }
275 //      dev_kfree_skb_any(skb);//edit by thomas
276 }
277 //by amy for power save
278 inline struct sk_buff *ieee80211_disassociate_skb(
279                                                         struct ieee80211_network *beacon,
280                                                         struct ieee80211_device *ieee,
281                                                         u8      asRsn)
282 {
283         struct sk_buff *skb;
284         struct ieee80211_disassoc_frame *disass;
285
286         skb = dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame));
287         if (!skb)
288                 return NULL;
289
290         disass = (struct ieee80211_disassoc_frame *) skb_put(skb,sizeof(struct ieee80211_disassoc_frame));
291         disass->header.frame_control = cpu_to_le16(IEEE80211_STYPE_DISASSOC);
292         disass->header.duration_id = 0;
293
294         memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
295         memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
296         memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
297
298         disass->reasoncode = asRsn;
299         return skb;
300 }
301 void
302 SendDisassociation(
303         struct ieee80211_device *ieee,
304         u8*                     asSta,
305         u8                      asRsn
306 )
307 {
308         struct ieee80211_network *beacon = &ieee->current_network;
309         struct sk_buff *skb;
310         skb = ieee80211_disassociate_skb(beacon,ieee,asRsn);
311         if (skb){
312                 softmac_mgmt_xmit(skb, ieee);
313                 //dev_kfree_skb_any(skb);//edit by thomas
314         }
315 }
316
317 //by amy for power save
318 inline struct sk_buff *ieee80211_probe_req(struct ieee80211_device *ieee)
319 {
320         unsigned int len,rate_len;
321         u8 *tag;
322         struct sk_buff *skb;
323         struct ieee80211_probe_request *req;
324
325         len = ieee->current_network.ssid_len;
326
327         rate_len = ieee80211_MFIE_rate_len(ieee);
328
329         skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
330                             2 + len + rate_len);
331         if (!skb)
332                 return NULL;
333
334         req = (struct ieee80211_probe_request *) skb_put(skb,sizeof(struct ieee80211_probe_request));
335         req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
336         req->header.duration_id = 0; //FIXME: is this OK ?
337
338         memset(req->header.addr1, 0xff, ETH_ALEN);
339         memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
340         memset(req->header.addr3, 0xff, ETH_ALEN);
341
342         tag = (u8 *) skb_put(skb,len+2+rate_len);
343
344         *tag++ = MFIE_TYPE_SSID;
345         *tag++ = len;
346         memcpy(tag, ieee->current_network.ssid, len);
347         tag += len;
348         ieee80211_MFIE_Brate(ieee,&tag);
349         ieee80211_MFIE_Grate(ieee,&tag);
350
351         return skb;
352 }
353
354 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee);
355
356 void ext_ieee80211_send_beacon_wq(struct ieee80211_device *ieee)
357 {
358         struct sk_buff *skb;
359
360         //unsigned long flags;
361
362         skb = ieee80211_get_beacon_(ieee);
363
364         if (skb){
365                 softmac_mgmt_xmit(skb, ieee);
366                 ieee->softmac_stats.tx_beacons++;
367                 dev_kfree_skb_any(skb);//edit by thomas
368         }
369
370
371         //printk(KERN_WARNING "[1] beacon sending!\n");
372         ieee->beacon_timer.expires = jiffies +
373                 (MSECS( ieee->current_network.beacon_interval -5));
374
375         //spin_lock_irqsave(&ieee->beacon_lock,flags);
376         if(ieee->beacon_txing)
377                 add_timer(&ieee->beacon_timer);
378         //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
379 }
380
381 void ieee80211_send_beacon(struct ieee80211_device *ieee)
382 {
383         struct sk_buff *skb;
384
385         //unsigned long flags;
386
387         skb = ieee80211_get_beacon_(ieee);
388
389         if (skb){
390                 softmac_mgmt_xmit(skb, ieee);
391                 ieee->softmac_stats.tx_beacons++;
392                 dev_kfree_skb_any(skb);//edit by thomas
393         }
394
395         //printk(KERN_WARNING "[1] beacon sending!\n");
396         ieee->beacon_timer.expires = jiffies +
397                 (MSECS( ieee->current_network.beacon_interval -5));
398
399         //spin_lock_irqsave(&ieee->beacon_lock,flags);
400         if(ieee->beacon_txing)
401                 add_timer(&ieee->beacon_timer);
402         //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
403 }
404
405
406 void ieee80211_send_beacon_cb(unsigned long _ieee)
407 {
408         struct ieee80211_device *ieee =
409                 (struct ieee80211_device *) _ieee;
410         unsigned long flags;
411
412         spin_lock_irqsave(&ieee->beacon_lock, flags);
413         ieee80211_send_beacon(ieee);
414         spin_unlock_irqrestore(&ieee->beacon_lock, flags);
415 }
416
417 void ieee80211_send_probe(struct ieee80211_device *ieee)
418 {
419         struct sk_buff *skb;
420
421         skb = ieee80211_probe_req(ieee);
422         if (skb){
423                 softmac_mgmt_xmit(skb, ieee);
424                 ieee->softmac_stats.tx_probe_rq++;
425                 //dev_kfree_skb_any(skb);//edit by thomas
426         }
427 }
428
429 void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
430 {
431         if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)){
432                 ieee80211_send_probe(ieee);
433                 ieee80211_send_probe(ieee);
434         }
435 }
436
437 /* this performs syncro scan blocking the caller until all channels
438  * in the allowed channel map has been checked.
439  */
440 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
441 {
442         short ch = 0;
443         u8 channel_map[MAX_CHANNEL_NUMBER+1];
444         memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
445         down(&ieee->scan_sem);
446 //      printk("==================> Sync scan\n");
447
448         while(1)
449         {
450
451                 do{
452                         ch++;
453                         if (ch > MAX_CHANNEL_NUMBER)
454                                 goto out; /* scan completed */
455
456                 }while(!channel_map[ch]);
457                 /* this fuction can be called in two situations
458                  * 1- We have switched to ad-hoc mode and we are
459                  *    performing a complete syncro scan before conclude
460                  *    there are no interesting cell and to create a
461                  *    new one. In this case the link state is
462                  *    IEEE80211_NOLINK until we found an interesting cell.
463                  *    If so the ieee8021_new_net, called by the RX path
464                  *    will set the state to IEEE80211_LINKED, so we stop
465                  *    scanning
466                  * 2- We are linked and the root uses run iwlist scan.
467                  *    So we switch to IEEE80211_LINKED_SCANNING to remember
468                  *    that we are still logically linked (not interested in
469                  *    new network events, despite for updating the net list,
470                  *    but we are temporarly 'unlinked' as the driver shall
471                  *    not filter RX frames and the channel is changing.
472                  * So the only situation in witch are interested is to check
473                  * if the state become LINKED because of the #1 situation
474                  */
475
476                 if (ieee->state == IEEE80211_LINKED)
477                         goto out;
478
479                 ieee->set_chan(ieee->dev, ch);
480 //              printk("=====>channel=%d   ",ch);
481                 if(channel_map[ch] == 1)
482                 {
483 //                      printk("====send probe request\n");
484                         ieee80211_send_probe_requests(ieee);
485                 }
486                 /* this prevent excessive time wait when we
487                  * need to wait for a syncro scan to end..
488                  */
489                 if (ieee->sync_scan_hurryup)
490                         goto out;
491
492
493                 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
494
495         }
496 out:
497         ieee->sync_scan_hurryup = 0;
498         up(&ieee->scan_sem);
499         if(IS_DOT11D_ENABLE(ieee))
500                 DOT11D_ScanComplete(ieee);
501 }
502
503 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee)
504 {
505         int ch;
506         unsigned int watch_dog = 0;
507         u8 channel_map[MAX_CHANNEL_NUMBER+1];
508         memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
509         down(&ieee->scan_sem);
510         ch = ieee->current_network.channel;
511 //              if(ieee->sync_scan_hurryup)
512 //      {
513
514 //              printk("stop scan sync\n");
515 //              goto out;
516 //      }
517 //      printk("=======hh===============>ips scan\n");
518         while(1)
519         {
520                 /* this fuction can be called in two situations
521                  * 1- We have switched to ad-hoc mode and we are
522                  *    performing a complete syncro scan before conclude
523                  *    there are no interesting cell and to create a
524                  *    new one. In this case the link state is
525                  *    IEEE80211_NOLINK until we found an interesting cell.
526                  *    If so the ieee8021_new_net, called by the RX path
527                  *    will set the state to IEEE80211_LINKED, so we stop
528                  *    scanning
529                  * 2- We are linked and the root uses run iwlist scan.
530                  *    So we switch to IEEE80211_LINKED_SCANNING to remember
531                  *    that we are still logically linked (not interested in
532                  *    new network events, despite for updating the net list,
533                  *    but we are temporarly 'unlinked' as the driver shall
534                  *    not filter RX frames and the channel is changing.
535                  * So the only situation in witch are interested is to check
536                  * if the state become LINKED because of the #1 situation
537                  */
538                 if (ieee->state == IEEE80211_LINKED)
539                 {
540                         goto out;
541                 }
542                 if(channel_map[ieee->current_network.channel] > 0)
543                 {
544                         ieee->set_chan(ieee->dev, ieee->current_network.channel);
545 //                      printk("======>channel=%d  ",ieee->current_network.channel);
546                 }
547                 if(channel_map[ieee->current_network.channel] == 1)
548                 {
549 //                      printk("====send probe request\n");
550                         ieee80211_send_probe_requests(ieee);
551                 }
552                 /* this prevent excessive time wait when we
553                  * need to wait for a syncro scan to end..
554                  */
555 //                if (ieee->sync_scan_hurryup)
556 //                        goto out;
557
558                 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
559
560                 do{
561                         if (watch_dog++ >= MAX_CHANNEL_NUMBER)
562                 //      if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER)  //YJ,modified,080630
563                                 goto out; /* scan completed */
564
565                         ieee->current_network.channel = (ieee->current_network.channel + 1)%MAX_CHANNEL_NUMBER;
566                 }while(!channel_map[ieee->current_network.channel]);
567         }
568 out:
569         //ieee->sync_scan_hurryup = 0;
570         //ieee->set_chan(ieee->dev, ch);
571         //ieee->current_network.channel = ch;
572         ieee->actscanning = false;
573         up(&ieee->scan_sem);
574         if(IS_DOT11D_ENABLE(ieee))
575                 DOT11D_ScanComplete(ieee);
576 }
577
578 void ieee80211_softmac_scan_wq(struct work_struct *work)
579 {
580         struct delayed_work *dwork = to_delayed_work(work);
581         struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
582         static short watchdog = 0;
583         u8 channel_map[MAX_CHANNEL_NUMBER+1];
584         memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
585 //      printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
586 //      printk("in %s\n",__func__);
587         down(&ieee->scan_sem);
588
589         do{
590                 ieee->current_network.channel =
591                         (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
592                 if (watchdog++ > MAX_CHANNEL_NUMBER)
593                                 goto out; /* no good chans */
594
595         }while(!channel_map[ieee->current_network.channel]);
596
597         //printk("current_network.channel:%d\n", ieee->current_network.channel);
598         if (ieee->scanning == 0 )
599         {
600                 printk("error out, scanning = 0\n");
601                 goto out;
602         }
603         ieee->set_chan(ieee->dev, ieee->current_network.channel);
604         if(channel_map[ieee->current_network.channel] == 1)
605                 ieee80211_send_probe_requests(ieee);
606
607         queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
608         up(&ieee->scan_sem);
609         return;
610 out:
611         ieee->actscanning = false;
612         watchdog = 0;
613         ieee->scanning = 0;
614         up(&ieee->scan_sem);
615
616         if(IS_DOT11D_ENABLE(ieee))
617                 DOT11D_ScanComplete(ieee);
618         return;
619 }
620
621 void ieee80211_beacons_start(struct ieee80211_device *ieee)
622 {
623         unsigned long flags;
624
625         spin_lock_irqsave(&ieee->beacon_lock,flags);
626
627         ieee->beacon_txing = 1;
628         ieee80211_send_beacon(ieee);
629
630         spin_unlock_irqrestore(&ieee->beacon_lock,flags);
631 }
632
633 void ieee80211_beacons_stop(struct ieee80211_device *ieee)
634 {
635         unsigned long flags;
636
637         spin_lock_irqsave(&ieee->beacon_lock,flags);
638
639         ieee->beacon_txing = 0;
640         del_timer_sync(&ieee->beacon_timer);
641
642         spin_unlock_irqrestore(&ieee->beacon_lock,flags);
643
644 }
645
646
647 void ieee80211_stop_send_beacons(struct ieee80211_device *ieee)
648 {
649         if(ieee->stop_send_beacons)
650                 ieee->stop_send_beacons(ieee->dev);
651         if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
652                 ieee80211_beacons_stop(ieee);
653 }
654
655
656 void ieee80211_start_send_beacons(struct ieee80211_device *ieee)
657 {
658         if(ieee->start_send_beacons)
659                 ieee->start_send_beacons(ieee->dev);
660         if(ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
661                 ieee80211_beacons_start(ieee);
662 }
663
664
665 void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
666 {
667 //      unsigned long flags;
668
669         //ieee->sync_scan_hurryup = 1;
670
671         down(&ieee->scan_sem);
672 //      spin_lock_irqsave(&ieee->lock, flags);
673
674         if (ieee->scanning == 1){
675                 ieee->scanning = 0;
676                 //del_timer_sync(&ieee->scan_timer);
677                 cancel_delayed_work(&ieee->softmac_scan_wq);
678         }
679
680 //      spin_unlock_irqrestore(&ieee->lock, flags);
681         up(&ieee->scan_sem);
682 }
683
684 void ieee80211_stop_scan(struct ieee80211_device *ieee)
685 {
686         if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
687                 ieee80211_softmac_stop_scan(ieee);
688         else
689                 ieee->stop_scan(ieee->dev);
690 }
691
692 /* called with ieee->lock held */
693 void ieee80211_rtl_start_scan(struct ieee80211_device *ieee)
694 {
695         if(IS_DOT11D_ENABLE(ieee) )
696         {
697                 if(IS_COUNTRY_IE_VALID(ieee))
698                 {
699                         RESET_CIE_WATCHDOG(ieee);
700                 }
701         }
702         if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
703                 if (ieee->scanning == 0)
704                 {
705                         ieee->scanning = 1;
706                         //ieee80211_softmac_scan(ieee);
707                 //      queue_work(ieee->wq, &ieee->softmac_scan_wq);
708                 //care this,1203,2007,by lawrence
709 #if 1
710                         queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq,0);
711 #endif
712                 }
713         }else
714                 ieee->start_scan(ieee->dev);
715
716 }
717
718 /* called with wx_sem held */
719 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
720 {
721         if(IS_DOT11D_ENABLE(ieee) )
722         {
723                 if(IS_COUNTRY_IE_VALID(ieee))
724                 {
725                         RESET_CIE_WATCHDOG(ieee);
726                 }
727         }
728         ieee->sync_scan_hurryup = 0;
729
730         if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
731                 ieee80211_softmac_scan_syncro(ieee);
732         else
733                 ieee->scan_syncro(ieee->dev);
734
735 }
736
737 inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
738         struct ieee80211_device *ieee, int challengelen)
739 {
740         struct sk_buff *skb;
741         struct ieee80211_authentication *auth;
742
743         skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
744
745         if (!skb) return NULL;
746
747         auth = (struct ieee80211_authentication *)
748                 skb_put(skb, sizeof(struct ieee80211_authentication));
749
750         auth->header.frame_ctl = IEEE80211_STYPE_AUTH;
751         if (challengelen) auth->header.frame_ctl |= IEEE80211_FCTL_WEP;
752
753         auth->header.duration_id = 0x013a; //FIXME
754
755         memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
756         memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
757         memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
758
759         auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
760
761         auth->transaction = cpu_to_le16(ieee->associate_seq);
762         ieee->associate_seq++;
763
764         auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
765
766         return skb;
767
768 }
769
770 static struct sk_buff* ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *dest)
771 {
772         u8 *tag;
773         int beacon_size;
774         struct ieee80211_probe_response *beacon_buf;
775         struct sk_buff *skb;
776         int encrypt;
777         int atim_len,erp_len;
778         struct ieee80211_crypt_data* crypt;
779
780         char *ssid = ieee->current_network.ssid;
781         int ssid_len = ieee->current_network.ssid_len;
782         int rate_len = ieee->current_network.rates_len+2;
783         int rate_ex_len = ieee->current_network.rates_ex_len;
784         int wpa_ie_len = ieee->wpa_ie_len;
785         if(rate_ex_len > 0) rate_ex_len+=2;
786
787         if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
788                 atim_len = 4;
789         else
790                 atim_len = 0;
791
792         if(ieee80211_is_54g(ieee->current_network))
793                 erp_len = 3;
794         else
795                 erp_len = 0;
796
797         beacon_size = sizeof(struct ieee80211_probe_response)+
798                 ssid_len
799                 +3 //channel
800                 +rate_len
801                 +rate_ex_len
802                 +atim_len
803                 +wpa_ie_len
804                 +erp_len;
805
806         skb = dev_alloc_skb(beacon_size);
807
808         if (!skb)
809                 return NULL;
810
811         beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
812
813         memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
814         memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
815         memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
816
817         beacon_buf->header.duration_id = 0; //FIXME
818         beacon_buf->beacon_interval =
819                 cpu_to_le16(ieee->current_network.beacon_interval);
820         beacon_buf->capability =
821                 cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
822
823         if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
824                 cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
825
826         crypt = ieee->crypt[ieee->tx_keyidx];
827
828         encrypt = ieee->host_encrypt && crypt && crypt->ops &&
829                 ((0 == strcmp(crypt->ops->name, "WEP")) || wpa_ie_len);
830
831         if (encrypt)
832                 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
833
834
835         beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
836
837         beacon_buf->info_element.id = MFIE_TYPE_SSID;
838         beacon_buf->info_element.len = ssid_len;
839
840         tag = (u8*) beacon_buf->info_element.data;
841
842         memcpy(tag, ssid, ssid_len);
843
844         tag += ssid_len;
845
846         *(tag++) = MFIE_TYPE_RATES;
847         *(tag++) = rate_len-2;
848         memcpy(tag,ieee->current_network.rates,rate_len-2);
849         tag+=rate_len-2;
850
851         *(tag++) = MFIE_TYPE_DS_SET;
852         *(tag++) = 1;
853         *(tag++) = ieee->current_network.channel;
854
855         if(atim_len){
856                 *(tag++) = MFIE_TYPE_IBSS_SET;
857                 *(tag++) = 2;
858                 *((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window);
859                 tag+=2;
860         }
861
862         if(erp_len){
863                 *(tag++) = MFIE_TYPE_ERP;
864                 *(tag++) = 1;
865                 *(tag++) = 0;
866         }
867
868         if(rate_ex_len){
869                 *(tag++) = MFIE_TYPE_RATES_EX;
870                 *(tag++) = rate_ex_len-2;
871                 memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
872                 tag+=rate_ex_len-2;
873         }
874
875         if (wpa_ie_len)
876         {
877                 if (ieee->iw_mode == IW_MODE_ADHOC)
878                 {//as Windows will set pairwise key same as the group key which is not allowed in Linux, so set this for IOT issue. WB 2008.07.07
879                         memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
880                 }
881
882                 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
883         }
884
885         skb->dev = ieee->dev;
886         return skb;
887 }
888
889 struct sk_buff* ieee80211_assoc_resp(struct ieee80211_device *ieee, u8 *dest)
890 {
891         struct sk_buff *skb;
892         u8* tag;
893
894         struct ieee80211_crypt_data* crypt;
895         struct ieee80211_assoc_response_frame *assoc;
896         short encrypt;
897
898         unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
899         int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
900
901         skb = dev_alloc_skb(len);
902
903         if (!skb)
904                 return NULL;
905
906         assoc = (struct ieee80211_assoc_response_frame *)
907                 skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
908
909         assoc->header.frame_control = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP);
910         memcpy(assoc->header.addr1, dest,ETH_ALEN);
911         memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
912         memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
913         assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
914                 WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
915
916
917         if(ieee->short_slot)
918                 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
919
920         if (ieee->host_encrypt)
921                 crypt = ieee->crypt[ieee->tx_keyidx];
922         else crypt = NULL;
923
924         encrypt = ( crypt && crypt->ops);
925
926         if (encrypt)
927                 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
928
929         assoc->status = 0;
930         assoc->aid = cpu_to_le16(ieee->assoc_id);
931         if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
932         else ieee->assoc_id++;
933
934         tag = (u8*) skb_put(skb, rate_len);
935
936         ieee80211_MFIE_Brate(ieee, &tag);
937         ieee80211_MFIE_Grate(ieee, &tag);
938
939         return skb;
940 }
941
942 struct sk_buff* ieee80211_auth_resp(struct ieee80211_device *ieee,int status, u8 *dest)
943 {
944         struct sk_buff *skb;
945         struct ieee80211_authentication *auth;
946
947         skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
948
949         if (!skb)
950                 return NULL;
951
952         skb->len = sizeof(struct ieee80211_authentication);
953
954         auth = (struct ieee80211_authentication *)skb->data;
955
956         auth->status = cpu_to_le16(status);
957         auth->transaction = cpu_to_le16(2);
958         auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
959
960         memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
961         memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
962         memcpy(auth->header.addr1, dest, ETH_ALEN);
963         auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
964         return skb;
965
966
967 }
968
969 struct sk_buff* ieee80211_null_func(struct ieee80211_device *ieee,short pwr)
970 {
971         struct sk_buff *skb;
972         struct ieee80211_hdr_3addr* hdr;
973
974         skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
975
976         if (!skb)
977                 return NULL;
978
979         hdr = (struct ieee80211_hdr_3addr*)skb_put(skb,sizeof(struct ieee80211_hdr_3addr));
980
981         memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
982         memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
983         memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
984
985         hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
986                 IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
987                 (pwr ? IEEE80211_FCTL_PM:0));
988
989         return skb;
990
991
992 }
993
994
995 void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8* dest)
996 {
997         struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest);
998
999         if (buf){
1000                 softmac_mgmt_xmit(buf, ieee);
1001                 dev_kfree_skb_any(buf);//edit by thomas
1002         }
1003 }
1004
1005
1006 void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8* dest)
1007 {
1008         struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest);
1009
1010         if (buf){
1011                 softmac_mgmt_xmit(buf, ieee);
1012                 dev_kfree_skb_any(buf);//edit by thomas
1013         }
1014 }
1015
1016
1017 void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest)
1018 {
1019
1020         struct sk_buff *buf = ieee80211_probe_resp(ieee, dest);
1021
1022         if (buf) {
1023                 softmac_mgmt_xmit(buf, ieee);
1024                 dev_kfree_skb_any(buf);//edit by thomas
1025         }
1026 }
1027
1028
1029 inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beacon,struct ieee80211_device *ieee)
1030 {
1031         struct sk_buff *skb;
1032         //unsigned long flags;
1033
1034         struct ieee80211_assoc_request_frame *hdr;
1035         u8 *tag;
1036         //short info_addr = 0;
1037         //int i;
1038         //u16 suite_count = 0;
1039         //u8 suit_select = 0;
1040         unsigned int wpa_len = beacon->wpa_ie_len;
1041         //struct net_device *dev = ieee->dev;
1042         //union iwreq_data wrqu;
1043         //u8 *buff;
1044         //u8 *p;
1045 #if 1
1046         // for testing purpose
1047         unsigned int rsn_len = beacon->rsn_ie_len;
1048 #else
1049         unsigned int rsn_len = beacon->rsn_ie_len - 4;
1050 #endif
1051         unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1052         unsigned int wmm_info_len = beacon->QoS_Enable?9:0;
1053         unsigned int turbo_info_len = beacon->Turbo_Enable?9:0;
1054
1055         u8  encry_proto = ieee->wpax_type_notify & 0xff;
1056         //u8  pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1057         //u8  authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1058
1059         int len = 0;
1060
1061         //[0] Notify type of encryption: WPA/WPA2
1062         //[1] pair wise type
1063         //[2] authen type
1064         if(ieee->wpax_type_set) {
1065                 if (IEEE_PROTO_WPA == encry_proto) {
1066                         rsn_len = 0;
1067                 } else if (IEEE_PROTO_RSN == encry_proto) {
1068                         wpa_len = 0;
1069                 }
1070         }
1071         len = sizeof(struct ieee80211_assoc_request_frame)+
1072                 + beacon->ssid_len//essid tagged val
1073                 + rate_len//rates tagged val
1074                 + wpa_len
1075                 + rsn_len
1076                 + wmm_info_len
1077                 + turbo_info_len;
1078
1079         skb = dev_alloc_skb(len);
1080
1081         if (!skb)
1082                 return NULL;
1083
1084         hdr = (struct ieee80211_assoc_request_frame *)
1085                 skb_put(skb, sizeof(struct ieee80211_assoc_request_frame));
1086
1087
1088         hdr->header.frame_control = IEEE80211_STYPE_ASSOC_REQ;
1089         hdr->header.duration_id= 37; //FIXME
1090         memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1091         memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1092         memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1093         memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);//for HW security, John
1094
1095         hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS);
1096         if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1097                 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1098         if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1099                 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1100
1101         if(ieee->short_slot)
1102                 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1103
1104         hdr->listen_interval = 0xa; //FIXME
1105
1106         hdr->info_element.id = MFIE_TYPE_SSID;
1107
1108         hdr->info_element.len = beacon->ssid_len;
1109         tag = skb_put(skb, beacon->ssid_len);
1110         memcpy(tag, beacon->ssid, beacon->ssid_len);
1111
1112         tag = skb_put(skb, rate_len);
1113
1114         ieee80211_MFIE_Brate(ieee, &tag);
1115         ieee80211_MFIE_Grate(ieee, &tag);
1116
1117         //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1118         //choose AES encryption as default algorithm while using mixed mode
1119
1120         tag = skb_put(skb,ieee->wpa_ie_len);
1121         memcpy(tag,ieee->wpa_ie,ieee->wpa_ie_len);
1122
1123         tag = skb_put(skb,wmm_info_len);
1124         if(wmm_info_len) {
1125           ieee80211_WMM_Info(ieee, &tag);
1126         }
1127         tag = skb_put(skb,turbo_info_len);
1128         if(turbo_info_len) {
1129                 ieee80211_TURBO_Info(ieee, &tag);
1130         }
1131
1132         return skb;
1133 }
1134
1135 void ieee80211_associate_abort(struct ieee80211_device *ieee)
1136 {
1137
1138         unsigned long flags;
1139         spin_lock_irqsave(&ieee->lock, flags);
1140
1141         ieee->associate_seq++;
1142
1143         /* don't scan, and avoid to have the RX path possibily
1144          * try again to associate. Even do not react to AUTH or
1145          * ASSOC response. Just wait for the retry wq to be scheduled.
1146          * Here we will check if there are good nets to associate
1147          * with, so we retry or just get back to NO_LINK and scanning
1148          */
1149         if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING){
1150                 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1151                 ieee->softmac_stats.no_auth_rs++;
1152         }else{
1153                 IEEE80211_DEBUG_MGMT("Association failed\n");
1154                 ieee->softmac_stats.no_ass_rs++;
1155         }
1156
1157         ieee->state = IEEE80211_ASSOCIATING_RETRY;
1158
1159         queue_delayed_work(ieee->wq, &ieee->associate_retry_wq,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME);
1160
1161         spin_unlock_irqrestore(&ieee->lock, flags);
1162 }
1163
1164 void ieee80211_associate_abort_cb(unsigned long dev)
1165 {
1166         ieee80211_associate_abort((struct ieee80211_device *) dev);
1167 }
1168
1169
1170 void ieee80211_associate_step1(struct ieee80211_device *ieee)
1171 {
1172         struct ieee80211_network *beacon = &ieee->current_network;
1173         struct sk_buff *skb;
1174
1175         IEEE80211_DEBUG_MGMT("Stopping scan\n");
1176         ieee->softmac_stats.tx_auth_rq++;
1177         skb=ieee80211_authentication_req(beacon, ieee, 0);
1178         if (!skb){
1179
1180                 ieee80211_associate_abort(ieee);
1181         }
1182         else{
1183                 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
1184                 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1185                 //printk("---Sending authentication request\n");
1186                 softmac_mgmt_xmit(skb, ieee);
1187                 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1188                 if(!timer_pending(&ieee->associate_timer)){
1189                         ieee->associate_timer.expires = jiffies + (HZ / 2);
1190                         add_timer(&ieee->associate_timer);
1191                 }
1192                 //If call dev_kfree_skb_any,a warning will ocur....
1193                 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1194                 //So ... 1204 by lawrence.
1195                 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1196                 //dev_kfree_skb_any(skb);//edit by thomas
1197         }
1198 }
1199
1200 void ieee80211_rtl_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, int chlen)
1201 {
1202         u8 *c;
1203         struct sk_buff *skb;
1204         struct ieee80211_network *beacon = &ieee->current_network;
1205 //      int hlen = sizeof(struct ieee80211_authentication);
1206         del_timer_sync(&ieee->associate_timer);
1207         ieee->associate_seq++;
1208         ieee->softmac_stats.tx_auth_rq++;
1209
1210         skb = ieee80211_authentication_req(beacon, ieee, chlen+2);
1211         if (!skb)
1212                 ieee80211_associate_abort(ieee);
1213         else{
1214                 c = skb_put(skb, chlen+2);
1215                 *(c++) = MFIE_TYPE_CHALLENGE;
1216                 *(c++) = chlen;
1217                 memcpy(c, challenge, chlen);
1218
1219                 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1220
1221                 ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr  ));
1222
1223                 softmac_mgmt_xmit(skb, ieee);
1224                 if (!timer_pending(&ieee->associate_timer)){
1225                 //printk("=========>add timer again, to crash\n");
1226                 ieee->associate_timer.expires = jiffies + (HZ / 2);
1227                 add_timer(&ieee->associate_timer);
1228                 }
1229                 dev_kfree_skb_any(skb);//edit by thomas
1230         }
1231         kfree(challenge);
1232 }
1233
1234 void ieee80211_associate_step2(struct ieee80211_device *ieee)
1235 {
1236         struct sk_buff* skb;
1237         struct ieee80211_network *beacon = &ieee->current_network;
1238
1239         del_timer_sync(&ieee->associate_timer);
1240
1241         IEEE80211_DEBUG_MGMT("Sending association request\n");
1242         ieee->softmac_stats.tx_ass_rq++;
1243         skb=ieee80211_association_req(beacon, ieee);
1244         if (!skb)
1245                 ieee80211_associate_abort(ieee);
1246         else{
1247                 softmac_mgmt_xmit(skb, ieee);
1248                 if (!timer_pending(&ieee->associate_timer)){
1249                 ieee->associate_timer.expires = jiffies + (HZ / 2);
1250                 add_timer(&ieee->associate_timer);
1251                 }
1252                 //dev_kfree_skb_any(skb);//edit by thomas
1253         }
1254 }
1255
1256 void ieee80211_associate_complete_wq(struct work_struct *work)
1257 {
1258         struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq);
1259
1260         printk(KERN_INFO "Associated successfully\n");
1261         if(ieee80211_is_54g(ieee->current_network) &&
1262                 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1263
1264                 ieee->rate = 540;
1265                 printk(KERN_INFO"Using G rates\n");
1266         }else{
1267                 ieee->rate = 110;
1268                 printk(KERN_INFO"Using B rates\n");
1269         }
1270         ieee->link_change(ieee->dev);
1271         notify_wx_assoc_event(ieee);
1272         if (ieee->data_hard_resume)
1273                 ieee->data_hard_resume(ieee->dev);
1274         netif_carrier_on(ieee->dev);
1275 }
1276
1277 void ieee80211_associate_complete(struct ieee80211_device *ieee)
1278 {
1279         int i;
1280         del_timer_sync(&ieee->associate_timer);
1281
1282         for(i = 0; i < 6; i++) {
1283           //ieee->seq_ctrl[i] = 0;
1284         }
1285         ieee->state = IEEE80211_LINKED;
1286         IEEE80211_DEBUG_MGMT("Successfully associated\n");
1287
1288         queue_work(ieee->wq, &ieee->associate_complete_wq);
1289 }
1290
1291 void ieee80211_associate_procedure_wq(struct work_struct *work)
1292 {
1293         struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1294
1295         ieee->sync_scan_hurryup = 1;
1296         down(&ieee->wx_sem);
1297
1298         if (ieee->data_hard_stop)
1299                 ieee->data_hard_stop(ieee->dev);
1300
1301         ieee80211_stop_scan(ieee);
1302         ieee->set_chan(ieee->dev, ieee->current_network.channel);
1303
1304         ieee->associate_seq = 1;
1305         ieee80211_associate_step1(ieee);
1306
1307         up(&ieee->wx_sem);
1308 }
1309
1310 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
1311 {
1312         u8 tmp_ssid[IW_ESSID_MAX_SIZE+1];
1313         int tmp_ssid_len = 0;
1314
1315         short apset,ssidset,ssidbroad,apmatch,ssidmatch;
1316
1317         /* we are interested in new new only if we are not associated
1318          * and we are not associating / authenticating
1319          */
1320         if (ieee->state != IEEE80211_NOLINK)
1321                 return;
1322
1323         if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS))
1324                 return;
1325
1326         if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS))
1327                 return;
1328
1329
1330         if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC){
1331                 /* if the user specified the AP MAC, we need also the essid
1332                  * This could be obtained by beacons or, if the network does not
1333                  * broadcast it, it can be put manually.
1334                  */
1335                 apset = ieee->wap_set;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1336                 ssidset = ieee->ssid_set;//ieee->current_network.ssid[0] != '\0';
1337                 ssidbroad =  !(net->ssid_len == 0 || net->ssid[0]== '\0');
1338                 apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN)==0);
1339
1340                 if(ieee->current_network.ssid_len != net->ssid_len)
1341                         ssidmatch = 0;
1342                 else
1343                         ssidmatch = (0==strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len));
1344
1345                 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1346                 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1347
1348                 if (    /* if the user set the AP check if match.
1349                          * if the network does not broadcast essid we check the user supplyed ANY essid
1350                          * if the network does broadcast and the user does not set essid it is OK
1351                          * if the network does broadcast and the user did set essid chech if essid match
1352                          */
1353                                 ( apset && apmatch &&
1354                                   ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1355                                 /* if the ap is not set, check that the user set the bssid
1356                                  * and the network does bradcast and that those two bssid matches
1357                                  */
1358                                 (!apset && ssidset && ssidbroad && ssidmatch)
1359                    ){
1360
1361
1362                         /* if the essid is hidden replace it with the
1363                          * essid provided by the user.
1364                          */
1365                         if (!ssidbroad){
1366                                 strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
1367                                 tmp_ssid_len = ieee->current_network.ssid_len;
1368                         }
1369                         memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
1370
1371                         if (!ssidbroad){
1372                                 strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
1373                                 ieee->current_network.ssid_len = tmp_ssid_len;
1374                         }
1375                         printk(KERN_INFO"Linking with %s: channel is %d\n",ieee->current_network.ssid,ieee->current_network.channel);
1376
1377                         if (ieee->iw_mode == IW_MODE_INFRA){
1378                                 ieee->state = IEEE80211_ASSOCIATING;
1379                                 ieee->beinretry = false;
1380                                 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1381                         }else{
1382                                 if(ieee80211_is_54g(ieee->current_network) &&
1383                                                 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1384                                         ieee->rate = 540;
1385                                         printk(KERN_INFO"Using G rates\n");
1386                                 }else{
1387                                         ieee->rate = 110;
1388                                         printk(KERN_INFO"Using B rates\n");
1389                                 }
1390                                 ieee->state = IEEE80211_LINKED;
1391                                 ieee->beinretry = false;
1392                         }
1393
1394                 }
1395         }
1396
1397 }
1398
1399 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
1400 {
1401         unsigned long flags;
1402         struct ieee80211_network *target;
1403
1404         spin_lock_irqsave(&ieee->lock, flags);
1405         list_for_each_entry(target, &ieee->network_list, list) {
1406
1407                 /* if the state become different that NOLINK means
1408                  * we had found what we are searching for
1409                  */
1410
1411                 if (ieee->state != IEEE80211_NOLINK)
1412                         break;
1413
1414                 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
1415                         ieee80211_softmac_new_net(ieee, target);
1416         }
1417
1418         spin_unlock_irqrestore(&ieee->lock, flags);
1419
1420 }
1421
1422
1423 static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
1424 {
1425         struct ieee80211_authentication *a;
1426         u8 *t;
1427         if (skb->len <  (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1428                 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb->len);
1429                 return 0xcafe;
1430         }
1431         *challenge = NULL;
1432         a = (struct ieee80211_authentication*) skb->data;
1433         if(skb->len > (sizeof(struct ieee80211_authentication) +3)){
1434                 t = skb->data + sizeof(struct ieee80211_authentication);
1435
1436                 if(*(t++) == MFIE_TYPE_CHALLENGE){
1437                         *chlen = *(t++);
1438                         *challenge = (u8*)kmalloc(*chlen, GFP_ATOMIC);
1439                         memcpy(*challenge, t, *chlen);
1440                 }
1441         }
1442
1443         return cpu_to_le16(a->status);
1444
1445 }
1446
1447
1448 int auth_rq_parse(struct sk_buff *skb,u8* dest)
1449 {
1450         struct ieee80211_authentication *a;
1451
1452         if (skb->len <  (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1453                 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
1454                 return -1;
1455         }
1456         a = (struct ieee80211_authentication*) skb->data;
1457
1458         memcpy(dest,a->header.addr2, ETH_ALEN);
1459
1460         if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1461                 return  WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1462
1463         return WLAN_STATUS_SUCCESS;
1464 }
1465
1466 static short probe_rq_parse(struct ieee80211_device *ieee, struct sk_buff *skb, u8 *src)
1467 {
1468         u8 *tag;
1469         u8 *skbend;
1470         u8 *ssid=NULL;
1471         u8 ssidlen = 0;
1472
1473         struct ieee80211_hdr_3addr   *header =
1474                 (struct ieee80211_hdr_3addr   *) skb->data;
1475
1476         if (skb->len < sizeof (struct ieee80211_hdr_3addr  ))
1477                 return -1; /* corrupted */
1478
1479         memcpy(src,header->addr2, ETH_ALEN);
1480
1481         skbend = (u8*)skb->data + skb->len;
1482
1483         tag = skb->data + sizeof (struct ieee80211_hdr_3addr  );
1484
1485         while (tag+1 < skbend){
1486                 if (*tag == 0){
1487                         ssid = tag+2;
1488                         ssidlen = *(tag+1);
1489                         break;
1490                 }
1491                 tag++; /* point to the len field */
1492                 tag = tag + *(tag); /* point to the last data byte of the tag */
1493                 tag++; /* point to the next tag */
1494         }
1495
1496         //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1497         if (ssidlen == 0) return 1;
1498
1499         if (!ssid) return 1; /* ssid not found in tagged param */
1500         return (!strncmp(ssid, ieee->current_network.ssid, ssidlen));
1501
1502 }
1503
1504 int assoc_rq_parse(struct sk_buff *skb,u8* dest)
1505 {
1506         struct ieee80211_assoc_request_frame *a;
1507
1508         if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
1509                 sizeof(struct ieee80211_info_element))) {
1510
1511                 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb->len);
1512                 return -1;
1513         }
1514
1515         a = (struct ieee80211_assoc_request_frame*) skb->data;
1516
1517         memcpy(dest,a->header.addr2,ETH_ALEN);
1518
1519         return 0;
1520 }
1521
1522 static inline u16 assoc_parse(struct sk_buff *skb, int *aid)
1523 {
1524         struct ieee80211_assoc_response_frame *a;
1525         if (skb->len <  sizeof(struct ieee80211_assoc_response_frame)){
1526                 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1527                 return 0xcafe;
1528         }
1529
1530         a = (struct ieee80211_assoc_response_frame*) skb->data;
1531         *aid = le16_to_cpu(a->aid) & 0x3fff;
1532         return le16_to_cpu(a->status);
1533 }
1534
1535 static inline void
1536 ieee80211_rx_probe_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1537 {
1538         u8 dest[ETH_ALEN];
1539
1540         //IEEE80211DMESG("Rx probe");
1541         ieee->softmac_stats.rx_probe_rq++;
1542         //DMESG("Dest is "MACSTR, MAC2STR(dest));
1543         if (probe_rq_parse(ieee, skb, dest)){
1544                 //IEEE80211DMESG("Was for me!");
1545                 ieee->softmac_stats.tx_probe_rs++;
1546                 ieee80211_resp_to_probe(ieee, dest);
1547         }
1548 }
1549
1550 inline void
1551 ieee80211_rx_auth_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1552 {
1553         u8 dest[ETH_ALEN];
1554         int status;
1555         //IEEE80211DMESG("Rx probe");
1556         ieee->softmac_stats.rx_auth_rq++;
1557
1558         if ((status = auth_rq_parse(skb, dest))!= -1){
1559                 ieee80211_resp_to_auth(ieee, status, dest);
1560         }
1561         //DMESG("Dest is "MACSTR, MAC2STR(dest));
1562
1563 }
1564
1565  inline void
1566 ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1567 {
1568
1569         u8 dest[ETH_ALEN];
1570         //unsigned long flags;
1571
1572         ieee->softmac_stats.rx_ass_rq++;
1573         if (assoc_rq_parse(skb,dest) != -1){
1574                 ieee80211_resp_to_assoc_rq(ieee, dest);
1575         }
1576
1577         printk(KERN_INFO"New client associated: %pM\n", dest);
1578 }
1579
1580
1581
1582 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr)
1583 {
1584
1585         struct sk_buff *buf = ieee80211_null_func(ieee, pwr);
1586
1587         if (buf)
1588                 softmac_ps_mgmt_xmit(buf, ieee);
1589
1590 }
1591
1592
1593 short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, u32 *time_l)
1594 {
1595         int timeout = 0;
1596
1597         u8 dtim;
1598         /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1599                 ieee->iw_mode != IW_MODE_INFRA ||
1600                 ieee->state != IEEE80211_LINKED)
1601
1602                 return 0;
1603         */
1604         dtim = ieee->current_network.dtim_data;
1605         //printk("DTIM\n");
1606
1607         if(!(dtim & IEEE80211_DTIM_VALID))
1608                 return 0;
1609         else
1610                 timeout = ieee->current_network.beacon_interval;
1611
1612         //printk("VALID\n");
1613         ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
1614
1615         if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
1616                 return 2;
1617
1618         if(!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout)))
1619                 return 0;
1620
1621         if(!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout)))
1622                 return 0;
1623
1624         if((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE ) &&
1625                 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1626                 return 0;
1627
1628         if(time_l){
1629                 *time_l = ieee->current_network.last_dtim_sta_time[0]
1630                         + MSECS((ieee->current_network.beacon_interval));
1631                         //* ieee->current_network.dtim_period));
1632                         //printk("beacon_interval:%x, dtim_period:%x, totol to Msecs:%x, HZ:%x\n", ieee->current_network.beacon_interval, ieee->current_network.dtim_period, MSECS(((ieee->current_network.beacon_interval * ieee->current_network.dtim_period))), HZ);
1633         }
1634
1635         if(time_h){
1636                 *time_h = ieee->current_network.last_dtim_sta_time[1];
1637                 if(time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
1638                         *time_h += 1;
1639         }
1640
1641         return 1;
1642
1643
1644 }
1645
1646 inline void ieee80211_sta_ps(struct ieee80211_device *ieee)
1647 {
1648
1649         u32 th,tl;
1650         short sleep;
1651
1652         unsigned long flags,flags2;
1653
1654         spin_lock_irqsave(&ieee->lock, flags);
1655
1656         if((ieee->ps == IEEE80211_PS_DISABLED ||
1657
1658                 ieee->iw_mode != IW_MODE_INFRA ||
1659                 ieee->state != IEEE80211_LINKED)){
1660
1661                 //#warning CHECK_LOCK_HERE
1662                 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1663
1664                 ieee80211_sta_wakeup(ieee, 1);
1665
1666                 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1667         }
1668
1669         sleep = ieee80211_sta_ps_sleep(ieee,&th, &tl);
1670 //      printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
1671         /* 2 wake, 1 sleep, 0 do nothing */
1672         if(sleep == 0)
1673                 goto out;
1674
1675         if(sleep == 1){
1676
1677                 if(ieee->sta_sleep == 1)
1678                         ieee->enter_sleep_state(ieee->dev,th,tl);
1679
1680                 else if(ieee->sta_sleep == 0){
1681         //              printk("send null 1\n");
1682                         spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1683
1684                         if(ieee->ps_is_queue_empty(ieee->dev)){
1685
1686
1687                                 ieee->sta_sleep = 2;
1688
1689                                 ieee->ps_request_tx_ack(ieee->dev);
1690
1691                                 ieee80211_sta_ps_send_null_frame(ieee,1);
1692
1693                                 ieee->ps_th = th;
1694                                 ieee->ps_tl = tl;
1695                         }
1696                         spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1697
1698                 }
1699
1700
1701         }else if(sleep == 2){
1702 //#warning CHECK_LOCK_HERE
1703                 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1704
1705         //      printk("send wakeup packet\n");
1706                 ieee80211_sta_wakeup(ieee,1);
1707
1708                 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1709         }
1710
1711 out:
1712         spin_unlock_irqrestore(&ieee->lock, flags);
1713
1714 }
1715
1716 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl)
1717 {
1718         if(ieee->sta_sleep == 0){
1719                 if(nl){
1720                 //      printk("Warning: driver is probably failing to report TX ps error\n");
1721                         ieee->ps_request_tx_ack(ieee->dev);
1722                         ieee80211_sta_ps_send_null_frame(ieee, 0);
1723                 }
1724                 return;
1725
1726         }
1727
1728         if(ieee->sta_sleep == 1)
1729                 ieee->sta_wake_up(ieee->dev);
1730
1731         ieee->sta_sleep = 0;
1732
1733         if(nl){
1734                 ieee->ps_request_tx_ack(ieee->dev);
1735                 ieee80211_sta_ps_send_null_frame(ieee, 0);
1736         }
1737 }
1738
1739 void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success)
1740 {
1741         unsigned long flags,flags2;
1742
1743         spin_lock_irqsave(&ieee->lock, flags);
1744         if(ieee->sta_sleep == 2){
1745                 /* Null frame with PS bit set */
1746                 if(success){
1747
1748                 //      printk("==================> %s::enter sleep state\n",__func__);
1749                         ieee->sta_sleep = 1;
1750                         ieee->enter_sleep_state(ieee->dev,ieee->ps_th,ieee->ps_tl);
1751                 }
1752                 /* if the card report not success we can't be sure the AP
1753                  * has not RXed so we can't assume the AP believe us awake
1754                  */
1755         }
1756         /* 21112005 - tx again null without PS bit if lost */
1757         else {
1758
1759                 if((ieee->sta_sleep == 0) && !success){
1760                         spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1761                         ieee80211_sta_ps_send_null_frame(ieee, 0);
1762                         spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1763                 }
1764         }
1765         spin_unlock_irqrestore(&ieee->lock, flags);
1766 }
1767
1768 inline int
1769 ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1770                         struct ieee80211_rx_stats *rx_stats, u16 type,
1771                         u16 stype)
1772 {
1773         struct ieee80211_hdr_3addr *header = (struct ieee80211_hdr_3addr *) skb->data;
1774         u16 errcode;
1775         u8* challenge=NULL;
1776         int chlen=0;
1777         int aid=0;
1778         struct ieee80211_assoc_response_frame *assoc_resp;
1779         struct ieee80211_info_element *info_element;
1780
1781         if(!ieee->proto_started)
1782                 return 0;
1783
1784         if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
1785                 ieee->iw_mode == IW_MODE_INFRA &&
1786                 ieee->state == IEEE80211_LINKED))
1787
1788                 tasklet_schedule(&ieee->ps_task);
1789
1790         if (WLAN_FC_GET_STYPE(header->frame_control) != IEEE80211_STYPE_PROBE_RESP &&
1791                 WLAN_FC_GET_STYPE(header->frame_control) != IEEE80211_STYPE_BEACON)
1792                 ieee->last_rx_ps_time = jiffies;
1793
1794         switch (WLAN_FC_GET_STYPE(header->frame_control)) {
1795
1796                 case IEEE80211_STYPE_ASSOC_RESP:
1797                 case IEEE80211_STYPE_REASSOC_RESP:
1798
1799                         IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1800                                         WLAN_FC_GET_STYPE(header->frame_ctl));
1801                         if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1802                                 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
1803                                 ieee->iw_mode == IW_MODE_INFRA){
1804                                 if (0 == (errcode=assoc_parse(skb, &aid))){
1805                                         u16 left;
1806
1807                                         ieee->state=IEEE80211_LINKED;
1808                                         ieee->assoc_id = aid;
1809                                         ieee->softmac_stats.rx_ass_ok++;
1810
1811                                         //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
1812                                         if(1 == rx_stats->nic_type) //card type is 8187
1813                                         {
1814                                                 goto associate_complete;
1815                                         }
1816                                         assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data;
1817                                         info_element =  &assoc_resp->info_element;
1818                                         left = skb->len - ((void*)info_element - (void*)assoc_resp);
1819
1820                                         while (left >= sizeof(struct ieee80211_info_element_hdr)) {
1821                                                 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
1822                                                         printk(KERN_WARNING "[re]associate reeponse error!");
1823                                                         return 1;
1824                                                 }
1825                                                 switch (info_element->id) {
1826                                                   case MFIE_TYPE_GENERIC:
1827                                                          IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element->len);
1828                                                         if (info_element->len >= 8  &&
1829                                                             info_element->data[0] == 0x00 &&
1830                                                             info_element->data[1] == 0x50 &&
1831                                                             info_element->data[2] == 0xf2 &&
1832                                                             info_element->data[3] == 0x02 &&
1833                                                             info_element->data[4] == 0x01) {
1834                                                             // Not care about version at present.
1835                                                             //WMM Parameter Element
1836                                                             memcpy(ieee->current_network.wmm_param,(u8*)(info_element->data\
1837                                                                                     + 8),(info_element->len - 8));
1838
1839                                                             if (((ieee->current_network.wmm_info^info_element->data[6])& \
1840                                                                                     0x0f)||(!ieee->init_wmmparam_flag)) {
1841                                                               // refresh parameter element for current network
1842                                                               // update the register parameter for hardware
1843                                                               ieee->init_wmmparam_flag = 1;
1844                                                               queue_work(ieee->wq, &ieee->wmm_param_update_wq);
1845
1846                                                             }
1847                                                             //update info_element for current network
1848                                                             ieee->current_network.wmm_info  = info_element->data[6];
1849                                                         }
1850                                                         break;
1851                                                   default:
1852                                                         //nothing to do at present!!!
1853                                                         break;
1854                                                 }
1855
1856                                                 left -= sizeof(struct ieee80211_info_element_hdr) +
1857                                                         info_element->len;
1858                                                 info_element = (struct ieee80211_info_element *)
1859                                                         &info_element->data[info_element->len];
1860                                         }
1861                                         if(!ieee->init_wmmparam_flag) //legacy AP, reset the AC_xx_param register
1862                                         {
1863                                                 queue_work(ieee->wq,&ieee->wmm_param_update_wq);
1864                                                 ieee->init_wmmparam_flag = 1;//indicate AC_xx_param upated since last associate
1865                                         }
1866 associate_complete:
1867                                         ieee80211_associate_complete(ieee);
1868                                 }else{
1869                                         ieee->softmac_stats.rx_ass_err++;
1870                                         IEEE80211_DEBUG_MGMT(
1871                                                 "Association response status code 0x%x\n",
1872                                                 errcode);
1873                                         ieee80211_associate_abort(ieee);
1874                                 }
1875                         }
1876                         break;
1877
1878                 case IEEE80211_STYPE_ASSOC_REQ:
1879                 case IEEE80211_STYPE_REASSOC_REQ:
1880
1881                         if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1882                                 ieee->iw_mode == IW_MODE_MASTER)
1883
1884                                 ieee80211_rx_assoc_rq(ieee, skb);
1885                         break;
1886
1887                 case IEEE80211_STYPE_AUTH:
1888
1889                         if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
1890                                 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
1891                                 ieee->iw_mode == IW_MODE_INFRA){
1892
1893                                                 IEEE80211_DEBUG_MGMT("Received authentication response");
1894
1895                                                 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
1896                                                         if(ieee->open_wep || !challenge){
1897                                                                 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
1898                                                                 ieee->softmac_stats.rx_auth_rs_ok++;
1899
1900                                                                 ieee80211_associate_step2(ieee);
1901                                                         }else{
1902                                                                 ieee80211_rtl_auth_challenge(ieee, challenge, chlen);
1903                                                         }
1904                                                 }else{
1905                                                         ieee->softmac_stats.rx_auth_rs_err++;
1906                                                         IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode);
1907                                                         ieee80211_associate_abort(ieee);
1908                                                 }
1909
1910                                         }else if (ieee->iw_mode == IW_MODE_MASTER){
1911                                                 ieee80211_rx_auth_rq(ieee, skb);
1912                                         }
1913                                 }
1914                         break;
1915
1916                 case IEEE80211_STYPE_PROBE_REQ:
1917
1918                         if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
1919                                 ((ieee->iw_mode == IW_MODE_ADHOC ||
1920                                 ieee->iw_mode == IW_MODE_MASTER) &&
1921                                 ieee->state == IEEE80211_LINKED))
1922
1923                                 ieee80211_rx_probe_rq(ieee, skb);
1924                         break;
1925
1926                 case IEEE80211_STYPE_DISASSOC:
1927                 case IEEE80211_STYPE_DEAUTH:
1928                         /* FIXME for now repeat all the association procedure
1929                         * both for disassociation and deauthentication
1930                         */
1931                         if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1932                                 (ieee->state == IEEE80211_LINKED) &&
1933                                 (ieee->iw_mode == IW_MODE_INFRA) &&
1934                                 (!memcmp(header->addr2,ieee->current_network.bssid,ETH_ALEN))){
1935                                 ieee->state = IEEE80211_ASSOCIATING;
1936                                 ieee->softmac_stats.reassoc++;
1937
1938                                 //notify_wx_assoc_event(ieee);  //YJ,del,080828, do not notify os here
1939                                 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1940                         }
1941
1942                         break;
1943
1944                 default:
1945                         return -1;
1946                         break;
1947         }
1948
1949         //dev_kfree_skb_any(skb);
1950         return 0;
1951 }
1952
1953
1954
1955 /* following are for a simplier TX queue management.
1956  * Instead of using netif_[stop/wake]_queue the driver
1957  * will uses these two function (plus a reset one), that
1958  * will internally uses the kernel netif_* and takes
1959  * care of the ieee802.11 fragmentation.
1960  * So the driver receives a fragment per time and might
1961  * call the stop function when it want without take care
1962  * to have enough room to TX an entire packet.
1963  * This might be useful if each fragment need it's own
1964  * descriptor, thus just keep a total free memory > than
1965  * the max fragmentation threshold is not enough.. If the
1966  * ieee802.11 stack passed a TXB struct then you needed
1967  * to keep N free descriptors where
1968  * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
1969  * In this way you need just one and the 802.11 stack
1970  * will take care of buffering fragments and pass them to
1971  * to the driver later, when it wakes the queue.
1972  */
1973
1974 void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee)
1975 {
1976
1977
1978         unsigned long flags;
1979         int  i;
1980
1981         spin_lock_irqsave(&ieee->lock,flags);
1982
1983         /* called with 2nd parm 0, no tx mgmt lock required */
1984         ieee80211_sta_wakeup(ieee,0);
1985
1986         for(i = 0; i < txb->nr_frags; i++) {
1987
1988                 if (ieee->queue_stop){
1989                         ieee->tx_pending.txb = txb;
1990                         ieee->tx_pending.frag = i;
1991                         goto exit;
1992                 }else{
1993                         ieee->softmac_data_hard_start_xmit(
1994                                 txb->fragments[i],
1995                                 ieee->dev,ieee->rate);
1996                                 //(i+1)<txb->nr_frags);
1997                         ieee->stats.tx_packets++;
1998                         ieee->stats.tx_bytes += txb->fragments[i]->len;
1999                         ieee->dev->trans_start = jiffies;
2000                 }
2001         }
2002
2003         ieee80211_txb_free(txb);
2004
2005         exit:
2006         spin_unlock_irqrestore(&ieee->lock,flags);
2007
2008 }
2009
2010 /* called with ieee->lock acquired */
2011 void ieee80211_resume_tx(struct ieee80211_device *ieee)
2012 {
2013         int i;
2014         for(i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) {
2015
2016                 if (ieee->queue_stop){
2017                         ieee->tx_pending.frag = i;
2018                         return;
2019                 }else{
2020
2021                         ieee->softmac_data_hard_start_xmit(
2022                                 ieee->tx_pending.txb->fragments[i],
2023                                 ieee->dev,ieee->rate);
2024                                 //(i+1)<ieee->tx_pending.txb->nr_frags);
2025                         ieee->stats.tx_packets++;
2026                         ieee->dev->trans_start = jiffies;
2027                 }
2028         }
2029
2030
2031         ieee80211_txb_free(ieee->tx_pending.txb);
2032         ieee->tx_pending.txb = NULL;
2033 }
2034
2035
2036 void ieee80211_reset_queue(struct ieee80211_device *ieee)
2037 {
2038         unsigned long flags;
2039
2040         spin_lock_irqsave(&ieee->lock,flags);
2041         init_mgmt_queue(ieee);
2042         if (ieee->tx_pending.txb){
2043                 ieee80211_txb_free(ieee->tx_pending.txb);
2044                 ieee->tx_pending.txb = NULL;
2045         }
2046         ieee->queue_stop = 0;
2047         spin_unlock_irqrestore(&ieee->lock,flags);
2048
2049 }
2050
2051 void ieee80211_rtl_wake_queue(struct ieee80211_device *ieee)
2052 {
2053
2054         unsigned long flags;
2055         struct sk_buff *skb;
2056         struct ieee80211_hdr_3addr  *header;
2057
2058         spin_lock_irqsave(&ieee->lock,flags);
2059         if (! ieee->queue_stop) goto exit;
2060
2061         ieee->queue_stop = 0;
2062
2063         if(ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE){
2064                 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))){
2065
2066                         header = (struct ieee80211_hdr_3addr  *) skb->data;
2067
2068                         header->seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2069
2070                         if (ieee->seq_ctrl[0] == 0xFFF)
2071                                 ieee->seq_ctrl[0] = 0;
2072                         else
2073                                 ieee->seq_ctrl[0]++;
2074
2075                         //printk(KERN_ALERT "ieee80211_wake_queue \n");
2076                         ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
2077                         dev_kfree_skb_any(skb);//edit by thomas
2078                 }
2079         }
2080         if (!ieee->queue_stop && ieee->tx_pending.txb)
2081                 ieee80211_resume_tx(ieee);
2082
2083         if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)){
2084                 ieee->softmac_stats.swtxawake++;
2085                 netif_wake_queue(ieee->dev);
2086         }
2087
2088 exit :
2089         spin_unlock_irqrestore(&ieee->lock,flags);
2090 }
2091
2092
2093 void ieee80211_rtl_stop_queue(struct ieee80211_device *ieee)
2094 {
2095         //unsigned long flags;
2096         //spin_lock_irqsave(&ieee->lock,flags);
2097
2098         if (! netif_queue_stopped(ieee->dev)){
2099                 netif_stop_queue(ieee->dev);
2100                 ieee->softmac_stats.swtxstop++;
2101         }
2102         ieee->queue_stop = 1;
2103         //spin_unlock_irqrestore(&ieee->lock,flags);
2104
2105 }
2106
2107
2108 inline void ieee80211_randomize_cell(struct ieee80211_device *ieee)
2109 {
2110
2111         get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2112
2113         /* an IBSS cell address must have the two less significant
2114          * bits of the first byte = 2
2115          */
2116         ieee->current_network.bssid[0] &= ~0x01;
2117         ieee->current_network.bssid[0] |= 0x02;
2118 }
2119
2120 /* called in user context only */
2121 void ieee80211_start_master_bss(struct ieee80211_device *ieee)
2122 {
2123         ieee->assoc_id = 1;
2124
2125         if (ieee->current_network.ssid_len == 0){
2126                 strncpy(ieee->current_network.ssid,
2127                         IEEE80211_DEFAULT_TX_ESSID,
2128                         IW_ESSID_MAX_SIZE);
2129
2130                 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2131                 ieee->ssid_set = 1;
2132         }
2133
2134         memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2135
2136         ieee->set_chan(ieee->dev, ieee->current_network.channel);
2137         ieee->state = IEEE80211_LINKED;
2138         ieee->link_change(ieee->dev);
2139         notify_wx_assoc_event(ieee);
2140
2141         if (ieee->data_hard_resume)
2142                 ieee->data_hard_resume(ieee->dev);
2143
2144         netif_carrier_on(ieee->dev);
2145 }
2146
2147 void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
2148 {
2149         if(ieee->raw_tx){
2150
2151                 if (ieee->data_hard_resume)
2152                         ieee->data_hard_resume(ieee->dev);
2153
2154                 netif_carrier_on(ieee->dev);
2155         }
2156 }
2157
2158 void ieee80211_start_ibss_wq(struct work_struct *work)
2159 {
2160         struct delayed_work *dwork = to_delayed_work(work);
2161         struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
2162
2163         /* iwconfig mode ad-hoc will schedule this and return
2164          * on the other hand this will block further iwconfig SET
2165          * operations because of the wx_sem hold.
2166          * Anyway some most set operations set a flag to speed-up
2167          * (abort) this wq (when syncro scanning) before sleeping
2168          * on the semaphore
2169          */
2170
2171         down(&ieee->wx_sem);
2172
2173
2174         if (ieee->current_network.ssid_len == 0){
2175                 strcpy(ieee->current_network.ssid,IEEE80211_DEFAULT_TX_ESSID);
2176                 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2177                 ieee->ssid_set = 1;
2178         }
2179
2180         /* check if we have this cell in our network list */
2181         ieee80211_softmac_check_all_nets(ieee);
2182
2183         if(ieee->state == IEEE80211_NOLINK)
2184                 ieee->current_network.channel = 10;
2185         /* if not then the state is not linked. Maybe the user swithced to
2186          * ad-hoc mode just after being in monitor mode, or just after
2187          * being very few time in managed mode (so the card have had no
2188          * time to scan all the chans..) or we have just run up the iface
2189          * after setting ad-hoc mode. So we have to give another try..
2190          * Here, in ibss mode, should be safe to do this without extra care
2191          * (in bss mode we had to make sure no-one tryed to associate when
2192          * we had just checked the ieee->state and we was going to start the
2193          * scan) beacause in ibss mode the ieee80211_new_net function, when
2194          * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2195          * so, at worst, we waste a bit of time to initiate an unneeded syncro
2196          * scan, that will stop at the first round because it sees the state
2197          * associated.
2198          */
2199         if (ieee->state == IEEE80211_NOLINK)
2200                 ieee80211_start_scan_syncro(ieee);
2201
2202         /* the network definitively is not here.. create a new cell */
2203         if (ieee->state == IEEE80211_NOLINK){
2204                 printk("creating new IBSS cell\n");
2205                 if(!ieee->wap_set)
2206                         ieee80211_randomize_cell(ieee);
2207
2208                 if(ieee->modulation & IEEE80211_CCK_MODULATION){
2209
2210                         ieee->current_network.rates_len = 4;
2211
2212                         ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
2213                         ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
2214                         ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
2215                         ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
2216
2217                 }else
2218                         ieee->current_network.rates_len = 0;
2219
2220                 if(ieee->modulation & IEEE80211_OFDM_MODULATION){
2221                         ieee->current_network.rates_ex_len = 8;
2222
2223                         ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
2224                         ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
2225                         ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
2226                         ieee->current_network.rates_ex[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
2227                         ieee->current_network.rates_ex[4] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
2228                         ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
2229                         ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
2230                         ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
2231
2232                         ieee->rate = 540;
2233                 }else{
2234                         ieee->current_network.rates_ex_len = 0;
2235                         ieee->rate = 110;
2236                 }
2237
2238                 // By default, WMM function will be disabled in IBSS mode
2239                 ieee->current_network.QoS_Enable = 0;
2240
2241                 ieee->current_network.atim_window = 0;
2242                 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2243                 if(ieee->short_slot)
2244                         ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT;
2245
2246         }
2247
2248         ieee->state = IEEE80211_LINKED;
2249         ieee->set_chan(ieee->dev, ieee->current_network.channel);
2250         ieee->link_change(ieee->dev);
2251
2252         notify_wx_assoc_event(ieee);
2253
2254         ieee80211_start_send_beacons(ieee);
2255         printk(KERN_WARNING "after sending beacon packet!\n");
2256
2257         if (ieee->data_hard_resume)
2258                 ieee->data_hard_resume(ieee->dev);
2259
2260         netif_carrier_on(ieee->dev);
2261
2262         up(&ieee->wx_sem);
2263 }
2264 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
2265 {
2266         queue_delayed_work(ieee->wq, &ieee->start_ibss_wq, 100);
2267 }
2268
2269 /* this is called only in user context, with wx_sem held */
2270 void ieee80211_start_bss(struct ieee80211_device *ieee)
2271 {
2272         unsigned long flags;
2273         //
2274         // Ref: 802.11d 11.1.3.3
2275         // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2276         //
2277         if(IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee))
2278         {
2279                 if(! ieee->bGlobalDomain)
2280                 {
2281                         return;
2282                 }
2283         }
2284         /* check if we have already found the net we
2285          * are interested in (if any).
2286          * if not (we are disassociated and we are not
2287          * in associating / authenticating phase) start the background scanning.
2288          */
2289         ieee80211_softmac_check_all_nets(ieee);
2290
2291         /* ensure no-one start an associating process (thus setting
2292          * the ieee->state to ieee80211_ASSOCIATING) while we
2293          * have just cheked it and we are going to enable scan.
2294          * The ieee80211_new_net function is always called with
2295          * lock held (from both ieee80211_softmac_check_all_nets and
2296          * the rx path), so we cannot be in the middle of such function
2297          */
2298         spin_lock_irqsave(&ieee->lock, flags);
2299
2300 //#ifdef ENABLE_IPS
2301 //      printk("start bss ENABLE_IPS\n");
2302 //#else
2303         if (ieee->state == IEEE80211_NOLINK){
2304                 ieee->actscanning = true;
2305                 ieee80211_rtl_start_scan(ieee);
2306         }
2307 //#endif
2308         spin_unlock_irqrestore(&ieee->lock, flags);
2309 }
2310
2311 /* called only in userspace context */
2312 void ieee80211_disassociate(struct ieee80211_device *ieee)
2313 {
2314         netif_carrier_off(ieee->dev);
2315
2316         if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2317                         ieee80211_reset_queue(ieee);
2318
2319         if (ieee->data_hard_stop)
2320                         ieee->data_hard_stop(ieee->dev);
2321
2322         if(IS_DOT11D_ENABLE(ieee))
2323                 Dot11d_Reset(ieee);
2324         ieee->state = IEEE80211_NOLINK;
2325         ieee->link_change(ieee->dev);
2326         notify_wx_assoc_event(ieee);
2327
2328 }
2329 void ieee80211_associate_retry_wq(struct work_struct *work)
2330 {
2331         struct delayed_work *dwork = to_delayed_work(work);
2332         struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2333         unsigned long flags;
2334         down(&ieee->wx_sem);
2335         if(!ieee->proto_started)
2336                 goto exit;
2337         if(ieee->state != IEEE80211_ASSOCIATING_RETRY)
2338                 goto exit;
2339         /* until we do not set the state to IEEE80211_NOLINK
2340         * there are no possibility to have someone else trying
2341         * to start an association procdure (we get here with
2342         * ieee->state = IEEE80211_ASSOCIATING).
2343         * When we set the state to IEEE80211_NOLINK it is possible
2344         * that the RX path run an attempt to associate, but
2345         * both ieee80211_softmac_check_all_nets and the
2346         * RX path works with ieee->lock held so there are no
2347         * problems. If we are still disassociated then start a scan.
2348         * the lock here is necessary to ensure no one try to start
2349         * an association procedure when we have just checked the
2350         * state and we are going to start the scan.
2351         */
2352         ieee->state = IEEE80211_NOLINK;
2353         ieee->beinretry = true;
2354         ieee80211_softmac_check_all_nets(ieee);
2355
2356         spin_lock_irqsave(&ieee->lock, flags);
2357
2358         if(ieee->state == IEEE80211_NOLINK){
2359                 ieee->beinretry = false;
2360                 ieee->actscanning = true;
2361                 ieee80211_rtl_start_scan(ieee);
2362         }
2363         //YJ,add,080828, notify os here
2364         if(ieee->state == IEEE80211_NOLINK)
2365         {
2366                 notify_wx_assoc_event(ieee);
2367         }
2368         //YJ,add,080828,end
2369         spin_unlock_irqrestore(&ieee->lock, flags);
2370
2371 exit:
2372         up(&ieee->wx_sem);
2373 }
2374
2375 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
2376 {
2377         u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2378
2379         struct sk_buff *skb = NULL;
2380         struct ieee80211_probe_response *b;
2381
2382         skb = ieee80211_probe_resp(ieee, broadcast_addr);
2383         if (!skb)
2384                 return NULL;
2385
2386         b = (struct ieee80211_probe_response *) skb->data;
2387         b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON);
2388
2389         return skb;
2390
2391 }
2392
2393 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee)
2394 {
2395         struct sk_buff *skb;
2396         struct ieee80211_probe_response *b;
2397
2398         skb = ieee80211_get_beacon_(ieee);
2399         if(!skb)
2400                 return NULL;
2401
2402         b = (struct ieee80211_probe_response *) skb->data;
2403         b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2404
2405         if (ieee->seq_ctrl[0] == 0xFFF)
2406                 ieee->seq_ctrl[0] = 0;
2407         else
2408                 ieee->seq_ctrl[0]++;
2409
2410         return skb;
2411 }
2412
2413 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
2414 {
2415         ieee->sync_scan_hurryup = 1;
2416         down(&ieee->wx_sem);
2417         ieee80211_stop_protocol(ieee);
2418         up(&ieee->wx_sem);
2419 }
2420
2421
2422 void ieee80211_stop_protocol(struct ieee80211_device *ieee)
2423 {
2424         if (!ieee->proto_started)
2425                 return;
2426
2427         ieee->proto_started = 0;
2428
2429         ieee80211_stop_send_beacons(ieee);
2430         if((ieee->iw_mode == IW_MODE_INFRA)&&(ieee->state == IEEE80211_LINKED)) {
2431                 SendDisassociation(ieee,NULL,WLAN_REASON_DISASSOC_STA_HAS_LEFT);
2432         }
2433         del_timer_sync(&ieee->associate_timer);
2434         cancel_delayed_work(&ieee->associate_retry_wq);
2435         cancel_delayed_work(&ieee->start_ibss_wq);
2436         ieee80211_stop_scan(ieee);
2437
2438         ieee80211_disassociate(ieee);
2439 }
2440
2441 void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee)
2442 {
2443         ieee->sync_scan_hurryup = 0;
2444         down(&ieee->wx_sem);
2445         ieee80211_start_protocol(ieee);
2446         up(&ieee->wx_sem);
2447 }
2448
2449 void ieee80211_start_protocol(struct ieee80211_device *ieee)
2450 {
2451         short ch = 0;
2452         int i = 0;
2453
2454         if (ieee->proto_started)
2455                 return;
2456
2457         ieee->proto_started = 1;
2458
2459         if (ieee->current_network.channel == 0){
2460                 do{
2461                         ch++;
2462                         if (ch > MAX_CHANNEL_NUMBER)
2463                                 return; /* no channel found */
2464
2465                 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]);
2466
2467                 ieee->current_network.channel = ch;
2468         }
2469
2470         if (ieee->current_network.beacon_interval == 0)
2471                 ieee->current_network.beacon_interval = 100;
2472         ieee->set_chan(ieee->dev,ieee->current_network.channel);
2473
2474         for(i = 0; i < 17; i++) {
2475           ieee->last_rxseq_num[i] = -1;
2476           ieee->last_rxfrag_num[i] = -1;
2477           ieee->last_packet_time[i] = 0;
2478         }
2479
2480         ieee->init_wmmparam_flag = 0;//reinitialize AC_xx_PARAM registers.
2481
2482
2483         /* if the user set the MAC of the ad-hoc cell and then
2484          * switch to managed mode, shall we  make sure that association
2485          * attempts does not fail just because the user provide the essid
2486          * and the nic is still checking for the AP MAC ??
2487          */
2488         switch (ieee->iw_mode) {
2489                 case IW_MODE_AUTO:
2490                         ieee->iw_mode = IW_MODE_INFRA;
2491                         //not set break here intentionly
2492                 case IW_MODE_INFRA:
2493                         ieee80211_start_bss(ieee);
2494                         break;
2495
2496                 case IW_MODE_ADHOC:
2497                         ieee80211_start_ibss(ieee);
2498                         break;
2499
2500                 case IW_MODE_MASTER:
2501                         ieee80211_start_master_bss(ieee);
2502                 break;
2503
2504                 case IW_MODE_MONITOR:
2505                         ieee80211_start_monitor_mode(ieee);
2506                         break;
2507
2508                 default:
2509                         ieee->iw_mode = IW_MODE_INFRA;
2510                         ieee80211_start_bss(ieee);
2511                         break;
2512         }
2513 }
2514
2515
2516 #define DRV_NAME  "Ieee80211"
2517 void ieee80211_softmac_init(struct ieee80211_device *ieee)
2518 {
2519         int i;
2520         memset(&ieee->current_network, 0, sizeof(struct ieee80211_network));
2521
2522         ieee->state = IEEE80211_NOLINK;
2523         ieee->sync_scan_hurryup = 0;
2524         for(i = 0; i < 5; i++) {
2525           ieee->seq_ctrl[i] = 0;
2526         }
2527
2528         ieee->assoc_id = 0;
2529         ieee->queue_stop = 0;
2530         ieee->scanning = 0;
2531         ieee->softmac_features = 0; //so IEEE2100-like driver are happy
2532         ieee->wap_set = 0;
2533         ieee->ssid_set = 0;
2534         ieee->proto_started = 0;
2535         ieee->basic_rate = IEEE80211_DEFAULT_BASIC_RATE;
2536         ieee->rate = 3;
2537 //#ifdef ENABLE_LPS
2538         ieee->ps = IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST;
2539 //#else
2540 //      ieee->ps = IEEE80211_PS_DISABLED;
2541 //#endif
2542         ieee->sta_sleep = 0;
2543 //by amy
2544         ieee->bInactivePs = false;
2545         ieee->actscanning = false;
2546         ieee->ListenInterval = 2;
2547         ieee->NumRxDataInPeriod = 0; //YJ,add,080828
2548         ieee->NumRxBcnInPeriod = 0; //YJ,add,080828
2549         ieee->NumRxOkTotal = 0;//+by amy 080312
2550         ieee->NumRxUnicast = 0;//YJ,add,080828,for keep alive
2551         ieee->beinretry = false;
2552         ieee->bHwRadioOff = false;
2553 //by amy
2554
2555         init_mgmt_queue(ieee);
2556
2557         ieee->tx_pending.txb = NULL;
2558
2559         init_timer(&ieee->associate_timer);
2560         ieee->associate_timer.data = (unsigned long)ieee;
2561         ieee->associate_timer.function = ieee80211_associate_abort_cb;
2562
2563         init_timer(&ieee->beacon_timer);
2564         ieee->beacon_timer.data = (unsigned long) ieee;
2565         ieee->beacon_timer.function = ieee80211_send_beacon_cb;
2566
2567 #ifdef PF_SYNCTHREAD
2568         ieee->wq = create_workqueue(DRV_NAME,0);
2569 #else
2570         ieee->wq = create_workqueue(DRV_NAME);
2571 #endif
2572         INIT_DELAYED_WORK(&ieee->start_ibss_wq,(void*) ieee80211_start_ibss_wq);
2573         INIT_WORK(&ieee->associate_complete_wq,(void*) ieee80211_associate_complete_wq);
2574         INIT_WORK(&ieee->associate_procedure_wq,(void*) ieee80211_associate_procedure_wq);
2575         INIT_DELAYED_WORK(&ieee->softmac_scan_wq,(void*) ieee80211_softmac_scan_wq);
2576         INIT_DELAYED_WORK(&ieee->associate_retry_wq,(void*) ieee80211_associate_retry_wq);
2577         INIT_WORK(&ieee->wx_sync_scan_wq,(void*) ieee80211_wx_sync_scan_wq);
2578 //      INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2579
2580         sema_init(&ieee->wx_sem, 1);
2581         sema_init(&ieee->scan_sem, 1);
2582
2583         spin_lock_init(&ieee->mgmt_tx_lock);
2584         spin_lock_init(&ieee->beacon_lock);
2585
2586         tasklet_init(&ieee->ps_task,
2587              (void(*)(unsigned long)) ieee80211_sta_ps,
2588              (unsigned long)ieee);
2589         ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
2590 }
2591
2592 void ieee80211_softmac_free(struct ieee80211_device *ieee)
2593 {
2594         down(&ieee->wx_sem);
2595
2596         del_timer_sync(&ieee->associate_timer);
2597         cancel_delayed_work(&ieee->associate_retry_wq);
2598
2599
2600         //add for RF power on power of by lizhaoming 080512
2601         cancel_delayed_work(&ieee->GPIOChangeRFWorkItem);
2602
2603         destroy_workqueue(ieee->wq);
2604         if(NULL != ieee->pDot11dInfo)
2605                 kfree(ieee->pDot11dInfo);
2606         up(&ieee->wx_sem);
2607 }
2608
2609 /********************************************************
2610  * Start of WPA code.                                   *
2611  * this is stolen from the ipw2200 driver               *
2612  ********************************************************/
2613
2614
2615 static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
2616 {
2617         /* This is called when wpa_supplicant loads and closes the driver
2618          * interface. */
2619         printk("%s WPA\n",value ? "enabling" : "disabling");
2620         ieee->wpa_enabled = value;
2621         return 0;
2622 }
2623
2624
2625 void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, int wpa_ie_len)
2626 {
2627         /* make sure WPA is enabled */
2628         ieee80211_wpa_enable(ieee, 1);
2629
2630         ieee80211_disassociate(ieee);
2631 }
2632
2633
2634 static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, int reason)
2635 {
2636
2637         int ret = 0;
2638
2639         switch (command) {
2640         case IEEE_MLME_STA_DEAUTH:
2641                 // silently ignore
2642                 break;
2643
2644         case IEEE_MLME_STA_DISASSOC:
2645                 ieee80211_disassociate(ieee);
2646                 break;
2647
2648         default:
2649                 printk("Unknown MLME request: %d\n", command);
2650                 ret = -EOPNOTSUPP;
2651         }
2652
2653         return ret;
2654 }
2655
2656
2657 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
2658                               struct ieee_param *param, int plen)
2659 {
2660         u8 *buf;
2661
2662         if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
2663             (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
2664                 return -EINVAL;
2665
2666         if (param->u.wpa_ie.len) {
2667                 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
2668                 if (buf == NULL)
2669                         return -ENOMEM;
2670
2671                 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
2672                 kfree(ieee->wpa_ie);
2673                 ieee->wpa_ie = buf;
2674                 ieee->wpa_ie_len = param->u.wpa_ie.len;
2675         } else {
2676                 kfree(ieee->wpa_ie);
2677                 ieee->wpa_ie = NULL;
2678                 ieee->wpa_ie_len = 0;
2679         }
2680
2681         ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
2682         return 0;
2683 }
2684
2685 #define AUTH_ALG_OPEN_SYSTEM                    0x1
2686 #define AUTH_ALG_SHARED_KEY                     0x2
2687
2688 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
2689 {
2690
2691         struct ieee80211_security sec = {
2692                 .flags = SEC_AUTH_MODE,
2693         };
2694         int ret = 0;
2695
2696         if (value & AUTH_ALG_SHARED_KEY) {
2697                 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
2698                 ieee->open_wep = 0;
2699         } else {
2700                 sec.auth_mode = WLAN_AUTH_OPEN;
2701                 ieee->open_wep = 1;
2702         }
2703
2704         if (ieee->set_security)
2705                 ieee->set_security(ieee->dev, &sec);
2706         else
2707                 ret = -EOPNOTSUPP;
2708
2709         return ret;
2710 }
2711
2712 static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value)
2713 {
2714         int ret=0;
2715         unsigned long flags;
2716
2717         switch (name) {
2718         case IEEE_PARAM_WPA_ENABLED:
2719                 ret = ieee80211_wpa_enable(ieee, value);
2720                 break;
2721
2722         case IEEE_PARAM_TKIP_COUNTERMEASURES:
2723                 ieee->tkip_countermeasures=value;
2724                 break;
2725
2726         case IEEE_PARAM_DROP_UNENCRYPTED: {
2727                 /* HACK:
2728                  *
2729                  * wpa_supplicant calls set_wpa_enabled when the driver
2730                  * is loaded and unloaded, regardless of if WPA is being
2731                  * used.  No other calls are made which can be used to
2732                  * determine if encryption will be used or not prior to
2733                  * association being expected.  If encryption is not being
2734                  * used, drop_unencrypted is set to false, else true -- we
2735                  * can use this to determine if the CAP_PRIVACY_ON bit should
2736                  * be set.
2737                  */
2738                 struct ieee80211_security sec = {
2739                         .flags = SEC_ENABLED,
2740                         .enabled = value,
2741                 };
2742                 ieee->drop_unencrypted = value;
2743                 /* We only change SEC_LEVEL for open mode. Others
2744                  * are set by ipw_wpa_set_encryption.
2745                  */
2746                 if (!value) {
2747                         sec.flags |= SEC_LEVEL;
2748                         sec.level = SEC_LEVEL_0;
2749                 }
2750                 else {
2751                         sec.flags |= SEC_LEVEL;
2752                         sec.level = SEC_LEVEL_1;
2753                 }
2754                 if (ieee->set_security)
2755                         ieee->set_security(ieee->dev, &sec);
2756                 break;
2757         }
2758
2759         case IEEE_PARAM_PRIVACY_INVOKED:
2760                 ieee->privacy_invoked=value;
2761                 break;
2762
2763         case IEEE_PARAM_AUTH_ALGS:
2764                 ret = ieee80211_wpa_set_auth_algs(ieee, value);
2765                 break;
2766
2767         case IEEE_PARAM_IEEE_802_1X:
2768                 ieee->ieee802_1x=value;
2769                 break;
2770         case IEEE_PARAM_WPAX_SELECT:
2771                 // added for WPA2 mixed mode
2772                 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
2773                 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
2774                 ieee->wpax_type_set = 1;
2775                 ieee->wpax_type_notify = value;
2776                 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
2777                 break;
2778
2779         default:
2780                 printk("Unknown WPA param: %d\n",name);
2781                 ret = -EOPNOTSUPP;
2782         }
2783
2784         return ret;
2785 }
2786
2787 /* implementation borrowed from hostap driver */
2788
2789 static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
2790                                   struct ieee_param *param, int param_len)
2791 {
2792         int ret = 0;
2793
2794         struct ieee80211_crypto_ops *ops;
2795         struct ieee80211_crypt_data **crypt;
2796
2797         struct ieee80211_security sec = {
2798                 .flags = 0,
2799         };
2800
2801         param->u.crypt.err = 0;
2802         param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
2803
2804         if (param_len !=
2805             (int) ((char *) param->u.crypt.key - (char *) param) +
2806             param->u.crypt.key_len) {
2807                 printk("Len mismatch %d, %d\n", param_len,
2808                                param->u.crypt.key_len);
2809                 return -EINVAL;
2810         }
2811         if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
2812             param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
2813             param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
2814                 if (param->u.crypt.idx >= WEP_KEYS)
2815                         return -EINVAL;
2816                 crypt = &ieee->crypt[param->u.crypt.idx];
2817         } else {
2818                 return -EINVAL;
2819         }
2820
2821         if (strcmp(param->u.crypt.alg, "none") == 0) {
2822                 if (crypt) {
2823                         sec.enabled = 0;
2824                         // FIXME FIXME
2825                         //sec.encrypt = 0;
2826                         sec.level = SEC_LEVEL_0;
2827                         sec.flags |= SEC_ENABLED | SEC_LEVEL;
2828                         ieee80211_crypt_delayed_deinit(ieee, crypt);
2829                 }
2830                 goto done;
2831         }
2832         sec.enabled = 1;
2833 // FIXME FIXME
2834 //      sec.encrypt = 1;
2835         sec.flags |= SEC_ENABLED;
2836
2837         /* IPW HW cannot build TKIP MIC, host decryption still needed. */
2838         if (!(ieee->host_encrypt || ieee->host_decrypt) &&
2839             strcmp(param->u.crypt.alg, "TKIP"))
2840                 goto skip_host_crypt;
2841
2842         ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2843         if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0)
2844                 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2845         else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0)
2846                 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2847         else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0)
2848                 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2849         if (ops == NULL) {
2850                 printk("unknown crypto alg '%s'\n", param->u.crypt.alg);
2851                 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
2852                 ret = -EINVAL;
2853                 goto done;
2854         }
2855
2856         if (*crypt == NULL || (*crypt)->ops != ops) {
2857                 struct ieee80211_crypt_data *new_crypt;
2858
2859                 ieee80211_crypt_delayed_deinit(ieee, crypt);
2860
2861                 new_crypt = (struct ieee80211_crypt_data *)
2862                         kmalloc(sizeof(*new_crypt), GFP_KERNEL);
2863                 if (new_crypt == NULL) {
2864                         ret = -ENOMEM;
2865                         goto done;
2866                 }
2867                 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
2868                 new_crypt->ops = ops;
2869                 if (new_crypt->ops)
2870                         new_crypt->priv =
2871                                 new_crypt->ops->init(param->u.crypt.idx);
2872
2873                 if (new_crypt->priv == NULL) {
2874                         kfree(new_crypt);
2875                         param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
2876                         ret = -EINVAL;
2877                         goto done;
2878                 }
2879
2880                 *crypt = new_crypt;
2881         }
2882
2883         if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
2884             (*crypt)->ops->set_key(param->u.crypt.key,
2885                                    param->u.crypt.key_len, param->u.crypt.seq,
2886                                    (*crypt)->priv) < 0) {
2887                 printk("key setting failed\n");
2888                 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
2889                 ret = -EINVAL;
2890                 goto done;
2891         }
2892
2893  skip_host_crypt:
2894         if (param->u.crypt.set_tx) {
2895                 ieee->tx_keyidx = param->u.crypt.idx;
2896                 sec.active_key = param->u.crypt.idx;
2897                 sec.flags |= SEC_ACTIVE_KEY;
2898         } else
2899                 sec.flags &= ~SEC_ACTIVE_KEY;
2900
2901         if (param->u.crypt.alg != NULL) {
2902                 memcpy(sec.keys[param->u.crypt.idx],
2903                        param->u.crypt.key,
2904                        param->u.crypt.key_len);
2905                 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
2906                 sec.flags |= (1 << param->u.crypt.idx);
2907
2908                 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
2909                         sec.flags |= SEC_LEVEL;
2910                         sec.level = SEC_LEVEL_1;
2911                 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
2912                         sec.flags |= SEC_LEVEL;
2913                         sec.level = SEC_LEVEL_2;
2914                 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
2915                         sec.flags |= SEC_LEVEL;
2916                         sec.level = SEC_LEVEL_3;
2917                 }
2918         }
2919  done:
2920         if (ieee->set_security)
2921                 ieee->set_security(ieee->dev, &sec);
2922
2923         /* Do not reset port if card is in Managed mode since resetting will
2924          * generate new IEEE 802.11 authentication which may end up in looping
2925          * with IEEE 802.1X.  If your hardware requires a reset after WEP
2926          * configuration (for example... Prism2), implement the reset_port in
2927          * the callbacks structures used to initialize the 802.11 stack. */
2928         if (ieee->reset_on_keychange &&
2929             ieee->iw_mode != IW_MODE_INFRA &&
2930             ieee->reset_port &&
2931             ieee->reset_port(ieee->dev)) {
2932                 printk("reset_port failed\n");
2933                 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
2934                 return -EINVAL;
2935         }
2936
2937         return ret;
2938 }
2939
2940 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p)
2941 {
2942         struct ieee_param *param;
2943         int ret=0;
2944
2945         down(&ieee->wx_sem);
2946         //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
2947
2948         if (p->length < sizeof(struct ieee_param) || !p->pointer){
2949                 ret = -EINVAL;
2950                 goto out;
2951         }
2952
2953         param = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
2954         if (param == NULL){
2955                 ret = -ENOMEM;
2956                 goto out;
2957         }
2958         if (copy_from_user(param, p->pointer, p->length)) {
2959                 kfree(param);
2960                 ret = -EFAULT;
2961                 goto out;
2962         }
2963
2964         switch (param->cmd) {
2965
2966         case IEEE_CMD_SET_WPA_PARAM:
2967                 ret = ieee80211_wpa_set_param(ieee, param->u.wpa_param.name,
2968                                         param->u.wpa_param.value);
2969                 break;
2970
2971         case IEEE_CMD_SET_WPA_IE:
2972                 ret = ieee80211_wpa_set_wpa_ie(ieee, param, p->length);
2973                 break;
2974
2975         case IEEE_CMD_SET_ENCRYPTION:
2976                 ret = ieee80211_wpa_set_encryption(ieee, param, p->length);
2977                 break;
2978
2979         case IEEE_CMD_MLME:
2980                 ret = ieee80211_wpa_mlme(ieee, param->u.mlme.command,
2981                                    param->u.mlme.reason_code);
2982                 break;
2983
2984         default:
2985                 printk("Unknown WPA supplicant request: %d\n",param->cmd);
2986                 ret = -EOPNOTSUPP;
2987                 break;
2988         }
2989
2990         if (ret == 0 && copy_to_user(p->pointer, param, p->length))
2991                 ret = -EFAULT;
2992
2993         kfree(param);
2994 out:
2995         up(&ieee->wx_sem);
2996
2997         return ret;
2998 }
2999
3000 void notify_wx_assoc_event(struct ieee80211_device *ieee)
3001 {
3002         union iwreq_data wrqu;
3003         wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3004         if (ieee->state == IEEE80211_LINKED)
3005                 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN);
3006         else
3007                 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
3008         wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3009 }