1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
4 * Mostly extracted from the rtl8180-sa2400 driver for the
5 * in-kernel generic ieee802.11 stack.
7 * Few lines might be stolen from other part of the ieee80211
8 * stack. Copyright who own it's copyright
10 * WPA code stolen from the ipw2200 driver.
11 * Copyright who own it's copyright.
13 * released under the GPL
17 #include "ieee80211.h"
19 #include <linux/random.h>
20 #include <linux/delay.h>
21 #include <linux/version.h>
22 #include <asm/uaccess.h>
27 u8 rsn_authen_cipher_suite[16][4] = {
28 {0x00,0x0F,0xAC,0x00}, //Use group key, //Reserved
29 {0x00,0x0F,0xAC,0x01}, //WEP-40 //RSNA default
30 {0x00,0x0F,0xAC,0x02}, //TKIP //NONE //{used just as default}
31 {0x00,0x0F,0xAC,0x03}, //WRAP-historical
32 {0x00,0x0F,0xAC,0x04}, //CCMP
33 {0x00,0x0F,0xAC,0x05}, //WEP-104
36 short ieee80211_is_54g(struct ieee80211_network net)
38 return ((net.rates_ex_len > 0) || (net.rates_len > 4));
41 short ieee80211_is_shortslot(struct ieee80211_network net)
43 return (net.capability & WLAN_CAPABILITY_SHORT_SLOT);
46 /* returns the total length needed for pleacing the RATE MFIE
47 * tag and the EXTENDED RATE MFIE tag if needed.
48 * It encludes two bytes per tag for the tag itself and its len
50 unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device *ieee)
52 unsigned int rate_len = 0;
54 if (ieee->modulation & IEEE80211_CCK_MODULATION)
55 rate_len = IEEE80211_CCK_RATE_LEN + 2;
57 if (ieee->modulation & IEEE80211_OFDM_MODULATION)
59 rate_len += IEEE80211_OFDM_RATE_LEN + 2;
64 /* pleace the MFIE rate, tag to the memory (double) poined.
65 * Then it updates the pointer so that
66 * it points after the new MFIE tag added.
68 void ieee80211_MFIE_Brate(struct ieee80211_device *ieee, u8 **tag_p)
72 if (ieee->modulation & IEEE80211_CCK_MODULATION){
73 *tag++ = MFIE_TYPE_RATES;
75 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
76 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
77 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
78 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
81 /* We may add an option for custom rates that specific HW might support */
85 void ieee80211_MFIE_Grate(struct ieee80211_device *ieee, u8 **tag_p)
89 if (ieee->modulation & IEEE80211_OFDM_MODULATION){
91 *tag++ = MFIE_TYPE_RATES_EX;
93 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
94 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
95 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
96 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
97 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
98 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
99 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
100 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
104 /* We may add an option for custom rates that specific HW might support */
109 void ieee80211_WMM_Info(struct ieee80211_device *ieee, u8 **tag_p) {
112 *tag++ = MFIE_TYPE_GENERIC; //0
121 if(ieee->current_network.wmm_info & 0x80) {
122 *tag++ = 0x0f|MAX_SP_Len;
133 void ieee80211_TURBO_Info(struct ieee80211_device *ieee, u8 **tag_p) {
136 *tag++ = MFIE_TYPE_GENERIC; //0
147 printk(KERN_ALERT "This is enable turbo mode IE process\n");
151 void enqueue_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb)
154 nh = (ieee->mgmt_queue_head +1) % MGMT_QUEUE_NUM;
157 * if the queue is full but we have newer frames then
158 * just overwrites the oldest.
160 * if (nh == ieee->mgmt_queue_tail)
163 ieee->mgmt_queue_head = nh;
164 ieee->mgmt_queue_ring[nh] = skb;
169 struct sk_buff *dequeue_mgmt(struct ieee80211_device *ieee)
173 if(ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
176 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
178 ieee->mgmt_queue_tail =
179 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
184 void init_mgmt_queue(struct ieee80211_device *ieee)
186 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
190 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl);
192 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
195 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
196 struct ieee80211_hdr_3addr *header=
197 (struct ieee80211_hdr_3addr *) skb->data;
200 spin_lock_irqsave(&ieee->lock, flags);
202 /* called with 2nd param 0, no mgmt lock required */
203 ieee80211_sta_wakeup(ieee,0);
206 if(ieee->queue_stop){
208 enqueue_mgmt(ieee,skb);
210 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
212 if (ieee->seq_ctrl[0] == 0xFFF)
213 ieee->seq_ctrl[0] = 0;
217 /* avoid watchdog triggers */
218 ieee->dev->trans_start = jiffies;
219 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
222 spin_unlock_irqrestore(&ieee->lock, flags);
224 spin_unlock_irqrestore(&ieee->lock, flags);
225 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
227 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
229 if (ieee->seq_ctrl[0] == 0xFFF)
230 ieee->seq_ctrl[0] = 0;
234 /* avoid watchdog triggers */
235 ieee->dev->trans_start = jiffies;
236 ieee->softmac_hard_start_xmit(skb,ieee->dev);
238 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
243 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
246 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
247 struct ieee80211_hdr_3addr *header =
248 (struct ieee80211_hdr_3addr *) skb->data;
253 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
255 if (ieee->seq_ctrl[0] == 0xFFF)
256 ieee->seq_ctrl[0] = 0;
260 /* avoid watchdog triggers */
261 ieee->dev->trans_start = jiffies;
262 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
266 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
268 if (ieee->seq_ctrl[0] == 0xFFF)
269 ieee->seq_ctrl[0] = 0;
273 /* avoid watchdog triggers */
274 ieee->dev->trans_start = jiffies;
275 ieee->softmac_hard_start_xmit(skb,ieee->dev);
278 // dev_kfree_skb_any(skb);//edit by thomas
280 //by amy for power save
281 inline struct sk_buff *ieee80211_disassociate_skb(
282 struct ieee80211_network *beacon,
283 struct ieee80211_device *ieee,
287 struct ieee80211_disassoc_frame *disass;
289 skb = dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame));
293 disass = (struct ieee80211_disassoc_frame *) skb_put(skb,sizeof(struct ieee80211_disassoc_frame));
294 disass->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_DISASSOC);
295 disass->header.duration_id = 0;
297 memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
298 memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
299 memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
301 disass->reasoncode = asRsn;
306 struct ieee80211_device *ieee,
311 struct ieee80211_network *beacon = &ieee->current_network;
313 skb = ieee80211_disassociate_skb(beacon,ieee,asRsn);
315 softmac_mgmt_xmit(skb, ieee);
316 //dev_kfree_skb_any(skb);//edit by thomas
320 //by amy for power save
321 inline struct sk_buff *ieee80211_probe_req(struct ieee80211_device *ieee)
323 unsigned int len,rate_len;
326 struct ieee80211_probe_request *req;
328 #ifdef _RTL8187_EXT_PATCH_
330 if(ieee->ext_patch_ieee80211_probe_req_1)
331 extMore = ieee->ext_patch_ieee80211_probe_req_1(ieee);
334 len = ieee->current_network.ssid_len;
336 rate_len = ieee80211_MFIE_rate_len(ieee);
338 #ifdef _RTL8187_EXT_PATCH_
341 skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
343 #ifdef _RTL8187_EXT_PATCH_
345 skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
346 2 + len + rate_len+128); // MESHID + CAP
352 req = (struct ieee80211_probe_request *) skb_put(skb,sizeof(struct ieee80211_probe_request));
353 req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
354 req->header.duration_id = 0; //FIXME: is this OK ?
356 memset(req->header.addr1, 0xff, ETH_ALEN);
357 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
358 memset(req->header.addr3, 0xff, ETH_ALEN);
360 tag = (u8 *) skb_put(skb,len+2+rate_len);
362 *tag++ = MFIE_TYPE_SSID;
364 memcpy(tag, ieee->current_network.ssid, len);
366 ieee80211_MFIE_Brate(ieee,&tag);
367 ieee80211_MFIE_Grate(ieee,&tag);
369 #ifdef _RTL8187_EXT_PATCH_
371 ieee->ext_patch_ieee80211_probe_req_2(ieee, skb, tag);
376 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee);
378 void ext_ieee80211_send_beacon_wq(struct ieee80211_device *ieee)
382 //unsigned long flags;
384 skb = ieee80211_get_beacon_(ieee);
387 softmac_mgmt_xmit(skb, ieee);
388 ieee->softmac_stats.tx_beacons++;
389 dev_kfree_skb_any(skb);//edit by thomas
393 //printk(KERN_WARNING "[1] beacon sending!\n");
394 ieee->beacon_timer.expires = jiffies +
395 (MSECS( ieee->current_network.beacon_interval -5));
397 //spin_lock_irqsave(&ieee->beacon_lock,flags);
398 if(ieee->beacon_txing)
399 add_timer(&ieee->beacon_timer);
400 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
403 void ieee80211_send_beacon(struct ieee80211_device *ieee)
407 //unsigned long flags;
409 skb = ieee80211_get_beacon_(ieee);
412 softmac_mgmt_xmit(skb, ieee);
413 ieee->softmac_stats.tx_beacons++;
414 dev_kfree_skb_any(skb);//edit by thomas
417 //printk(KERN_WARNING "[1] beacon sending!\n");
418 ieee->beacon_timer.expires = jiffies +
419 (MSECS( ieee->current_network.beacon_interval -5));
421 //spin_lock_irqsave(&ieee->beacon_lock,flags);
422 if(ieee->beacon_txing)
423 add_timer(&ieee->beacon_timer);
424 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
428 void ieee80211_send_beacon_cb(unsigned long _ieee)
430 struct ieee80211_device *ieee =
431 (struct ieee80211_device *) _ieee;
434 spin_lock_irqsave(&ieee->beacon_lock, flags);
435 ieee80211_send_beacon(ieee);
436 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
439 #ifdef _RTL8187_EXT_PATCH_
441 inline struct sk_buff *ieee80211_probe_req_with_SSID(struct ieee80211_device *ieee, char *ssid, int len_ssid)
443 unsigned int len,rate_len;
446 struct ieee80211_probe_request *req;
448 #ifdef _RTL8187_EXT_PATCH_
450 if(ieee->ext_patch_ieee80211_probe_req_1)
451 extMore = ieee->ext_patch_ieee80211_probe_req_1(ieee);
456 rate_len = ieee80211_MFIE_rate_len(ieee);
458 #ifdef _RTL8187_EXT_PATCH_
461 skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
463 #ifdef _RTL8187_EXT_PATCH_
465 skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
466 2 + len + rate_len+128); // MESHID + CAP
472 req = (struct ieee80211_probe_request *) skb_put(skb,sizeof(struct ieee80211_probe_request));
473 req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
474 req->header.duration_id = 0; //FIXME: is this OK ?
476 memset(req->header.addr1, 0xff, ETH_ALEN);
477 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
478 memset(req->header.addr3, 0xff, ETH_ALEN);
480 tag = (u8 *) skb_put(skb,len+2+rate_len);
482 *tag++ = MFIE_TYPE_SSID;
486 memcpy(tag, ssid, len);
490 ieee80211_MFIE_Brate(ieee,&tag);
491 ieee80211_MFIE_Grate(ieee,&tag);
493 #ifdef _RTL8187_EXT_PATCH_
495 ieee->ext_patch_ieee80211_probe_req_2(ieee, skb, tag);
500 #endif // _RTL8187_EXT_PATCH_
503 void ieee80211_send_probe(struct ieee80211_device *ieee)
507 #ifdef _RTL8187_EXT_PATCH_
508 if(ieee->iw_mode == ieee->iw_ext_mode)
509 skb = ieee80211_probe_req_with_SSID(ieee, NULL, 0);
512 skb = ieee80211_probe_req(ieee);
514 softmac_mgmt_xmit(skb, ieee);
515 ieee->softmac_stats.tx_probe_rq++;
516 //dev_kfree_skb_any(skb);//edit by thomas
520 void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
522 if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)){
523 ieee80211_send_probe(ieee);
524 ieee80211_send_probe(ieee);
528 /* this performs syncro scan blocking the caller until all channels
529 * in the allowed channel map has been checked.
531 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
535 u8 channel_map[MAX_CHANNEL_NUMBER+1];
536 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
538 down(&ieee->scan_sem);
539 // printk("==================> Sync scan\n");
540 // dump_chnl_map(channel_map);
547 if (ch > MAX_CHANNEL_NUMBER)
548 goto out; /* scan completed */
551 }while(!channel_map[ch]);
553 }while(!ieee->channel_map[ch]);
555 /* this fuction can be called in two situations
556 * 1- We have switched to ad-hoc mode and we are
557 * performing a complete syncro scan before conclude
558 * there are no interesting cell and to create a
559 * new one. In this case the link state is
560 * IEEE80211_NOLINK until we found an interesting cell.
561 * If so the ieee8021_new_net, called by the RX path
562 * will set the state to IEEE80211_LINKED, so we stop
564 * 2- We are linked and the root uses run iwlist scan.
565 * So we switch to IEEE80211_LINKED_SCANNING to remember
566 * that we are still logically linked (not interested in
567 * new network events, despite for updating the net list,
568 * but we are temporarly 'unlinked' as the driver shall
569 * not filter RX frames and the channel is changing.
570 * So the only situation in witch are interested is to check
571 * if the state become LINKED because of the #1 situation
574 if (ieee->state == IEEE80211_LINKED)
577 ieee->set_chan(ieee->dev, ch);
578 // printk("=====>channel=%d ",ch);
580 if(channel_map[ch] == 1)
583 // printk("====send probe request\n");
584 ieee80211_send_probe_requests(ieee);
586 /* this prevent excessive time wait when we
587 * need to wait for a syncro scan to end..
589 if (ieee->sync_scan_hurryup)
593 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
597 ieee->sync_scan_hurryup = 0;
600 if(IS_DOT11D_ENABLE(ieee))
601 DOT11D_ScanComplete(ieee);
605 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee)
608 unsigned int watch_dog = 0;
610 u8 channel_map[MAX_CHANNEL_NUMBER+1];
611 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
613 down(&ieee->scan_sem);
614 ch = ieee->current_network.channel;
615 // if(ieee->sync_scan_hurryup)
618 // printk("stop scan sync\n");
621 // printk("=======hh===============>ips scan\n");
624 /* this fuction can be called in two situations
625 * 1- We have switched to ad-hoc mode and we are
626 * performing a complete syncro scan before conclude
627 * there are no interesting cell and to create a
628 * new one. In this case the link state is
629 * IEEE80211_NOLINK until we found an interesting cell.
630 * If so the ieee8021_new_net, called by the RX path
631 * will set the state to IEEE80211_LINKED, so we stop
633 * 2- We are linked and the root uses run iwlist scan.
634 * So we switch to IEEE80211_LINKED_SCANNING to remember
635 * that we are still logically linked (not interested in
636 * new network events, despite for updating the net list,
637 * but we are temporarly 'unlinked' as the driver shall
638 * not filter RX frames and the channel is changing.
639 * So the only situation in witch are interested is to check
640 * if the state become LINKED because of the #1 situation
642 if (ieee->state == IEEE80211_LINKED)
647 if(channel_map[ieee->current_network.channel] > 0)
650 ieee->set_chan(ieee->dev, ieee->current_network.channel);
651 // printk("======>channel=%d ",ieee->current_network.channel);
654 if(channel_map[ieee->current_network.channel] == 1)
657 // printk("====send probe request\n");
658 ieee80211_send_probe_requests(ieee);
660 /* this prevent excessive time wait when we
661 * need to wait for a syncro scan to end..
663 // if (ieee->sync_scan_hurryup)
666 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
669 if (watch_dog++ >= MAX_CHANNEL_NUMBER)
670 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
671 goto out; /* scan completed */
673 ieee->current_network.channel = (ieee->current_network.channel + 1)%MAX_CHANNEL_NUMBER;
675 }while(!channel_map[ieee->current_network.channel]);
677 }while(!ieee->channel_map[ieee->current_network.channel]);
681 //ieee->sync_scan_hurryup = 0;
682 //ieee->set_chan(ieee->dev, ch);
683 //ieee->current_network.channel = ch;
684 ieee->actscanning = false;
687 if(IS_DOT11D_ENABLE(ieee))
688 DOT11D_ScanComplete(ieee);
694 /* called both by wq with ieee->lock held */
695 void ieee80211_softmac_scan(struct ieee80211_device *ieee)
700 ieee->current_network.channel =
701 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
702 if (watchdog++ > MAX_CHANNEL_NUMBER)
703 return; /* no good chans */
705 }while(!ieee->channel_map[ieee->current_network.channel]);
708 schedule_work(&ieee->softmac_scan_wq);
712 void ieee80211_softmac_scan_wq(struct work_struct *work)
714 struct delayed_work *dwork = to_delayed_work(work);
715 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
716 static short watchdog = 0;
718 u8 channel_map[MAX_CHANNEL_NUMBER+1];
719 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
721 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
722 // printk("in %s\n",__func__);
723 down(&ieee->scan_sem);
726 ieee->current_network.channel =
727 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
728 if (watchdog++ > MAX_CHANNEL_NUMBER)
729 goto out; /* no good chans */
732 }while(!channel_map[ieee->current_network.channel]);
734 }while(!ieee->channel_map[ieee->current_network.channel]);
737 //printk("current_network.channel:%d\n", ieee->current_network.channel);
738 if (ieee->scanning == 0 )
740 printk("error out, scanning = 0\n");
743 ieee->set_chan(ieee->dev, ieee->current_network.channel);
745 if(channel_map[ieee->current_network.channel] == 1)
747 ieee80211_send_probe_requests(ieee);
749 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
753 ieee->actscanning = false;
759 if(IS_DOT11D_ENABLE(ieee))
760 DOT11D_ScanComplete(ieee);
765 void ieee80211_softmac_scan_wq(struct work_struct *work)
767 struct delayed_work *dwork = to_delayed_work(work);
768 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, softmac_scan_wq);
771 u8 channel_map[MAX_CHANNEL_NUMBER+1];
772 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
774 // printk("enter scan wq,watchdog is %d\n",watchdog);
775 down(&ieee->scan_sem);
778 ieee->current_network.channel =
779 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
780 if (watchdog++ > MAX_CHANNEL_NUMBER)
781 goto out; /* no good chans */
784 }while(!channel_map[ieee->current_network.channel]);
786 }while(!ieee->channel_map[ieee->current_network.channel]);
789 // printk("current_network.channel:%d\n", ieee->current_network.channel);
790 if (ieee->scanning == 0 )
792 printk("error out, scanning = 0\n");
795 ieee->set_chan(ieee->dev, ieee->current_network.channel);
797 if(channel_map[ieee->current_network.channel] == 1)
799 ieee80211_send_probe_requests(ieee);
801 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
805 if(IS_DOT11D_ENABLE(ieee))
806 DOT11D_ScanComplete(ieee);
812 void ieee80211_beacons_start(struct ieee80211_device *ieee)
816 spin_lock_irqsave(&ieee->beacon_lock,flags);
818 ieee->beacon_txing = 1;
819 ieee80211_send_beacon(ieee);
821 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
824 void ieee80211_beacons_stop(struct ieee80211_device *ieee)
828 spin_lock_irqsave(&ieee->beacon_lock,flags);
830 ieee->beacon_txing = 0;
831 del_timer_sync(&ieee->beacon_timer);
833 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
838 void ieee80211_stop_send_beacons(struct ieee80211_device *ieee)
840 if(ieee->stop_send_beacons)
841 ieee->stop_send_beacons(ieee->dev);
842 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
843 ieee80211_beacons_stop(ieee);
847 void ieee80211_start_send_beacons(struct ieee80211_device *ieee)
849 if(ieee->start_send_beacons)
850 ieee->start_send_beacons(ieee->dev);
851 if(ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
852 ieee80211_beacons_start(ieee);
856 void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
858 // unsigned long flags;
860 //ieee->sync_scan_hurryup = 1;
862 down(&ieee->scan_sem);
863 // spin_lock_irqsave(&ieee->lock, flags);
865 if (ieee->scanning == 1){
867 //del_timer_sync(&ieee->scan_timer);
868 cancel_delayed_work(&ieee->softmac_scan_wq);
871 // spin_unlock_irqrestore(&ieee->lock, flags);
875 void ieee80211_stop_scan(struct ieee80211_device *ieee)
877 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
878 ieee80211_softmac_stop_scan(ieee);
880 ieee->stop_scan(ieee->dev);
883 /* called with ieee->lock held */
884 void ieee80211_start_scan(struct ieee80211_device *ieee)
887 if(IS_DOT11D_ENABLE(ieee) )
889 if(IS_COUNTRY_IE_VALID(ieee))
891 RESET_CIE_WATCHDOG(ieee);
895 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
896 if (ieee->scanning == 0)
899 //ieee80211_softmac_scan(ieee);
900 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
901 //care this,1203,2007,by lawrence
903 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq,0);
907 ieee->start_scan(ieee->dev);
911 /* called with wx_sem held */
912 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
915 if(IS_DOT11D_ENABLE(ieee) )
917 if(IS_COUNTRY_IE_VALID(ieee))
919 RESET_CIE_WATCHDOG(ieee);
923 ieee->sync_scan_hurryup = 0;
925 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
926 ieee80211_softmac_scan_syncro(ieee);
928 ieee->scan_syncro(ieee->dev);
932 inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
933 struct ieee80211_device *ieee, int challengelen)
936 struct ieee80211_authentication *auth;
938 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
940 if (!skb) return NULL;
942 auth = (struct ieee80211_authentication *)
943 skb_put(skb, sizeof(struct ieee80211_authentication));
945 auth->header.frame_ctl = IEEE80211_STYPE_AUTH;
946 if (challengelen) auth->header.frame_ctl |= IEEE80211_FCTL_WEP;
948 auth->header.duration_id = 0x013a; //FIXME
950 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
951 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
952 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
954 auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
956 auth->transaction = cpu_to_le16(ieee->associate_seq);
957 ieee->associate_seq++;
959 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
965 static struct sk_buff* ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *dest)
969 struct ieee80211_probe_response *beacon_buf;
972 int atim_len,erp_len;
973 struct ieee80211_crypt_data* crypt;
975 char *ssid = ieee->current_network.ssid;
976 int ssid_len = ieee->current_network.ssid_len;
977 int rate_len = ieee->current_network.rates_len+2;
978 int rate_ex_len = ieee->current_network.rates_ex_len;
979 int wpa_ie_len = ieee->wpa_ie_len;
980 if(rate_ex_len > 0) rate_ex_len+=2;
982 if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
987 if(ieee80211_is_54g(ieee->current_network))
992 beacon_size = sizeof(struct ieee80211_probe_response)+
1001 skb = dev_alloc_skb(beacon_size);
1006 beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
1008 memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
1009 memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1010 memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
1012 beacon_buf->header.duration_id = 0; //FIXME
1013 beacon_buf->beacon_interval =
1014 cpu_to_le16(ieee->current_network.beacon_interval);
1015 beacon_buf->capability =
1016 cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
1018 if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
1019 cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
1021 crypt = ieee->crypt[ieee->tx_keyidx];
1023 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1024 ((0 == strcmp(crypt->ops->name, "WEP")) || wpa_ie_len);
1027 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1030 beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
1032 beacon_buf->info_element.id = MFIE_TYPE_SSID;
1033 beacon_buf->info_element.len = ssid_len;
1035 tag = (u8*) beacon_buf->info_element.data;
1037 memcpy(tag, ssid, ssid_len);
1041 *(tag++) = MFIE_TYPE_RATES;
1042 *(tag++) = rate_len-2;
1043 memcpy(tag,ieee->current_network.rates,rate_len-2);
1046 *(tag++) = MFIE_TYPE_DS_SET;
1048 *(tag++) = ieee->current_network.channel;
1051 *(tag++) = MFIE_TYPE_IBSS_SET;
1053 *((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window);
1058 *(tag++) = MFIE_TYPE_ERP;
1064 *(tag++) = MFIE_TYPE_RATES_EX;
1065 *(tag++) = rate_ex_len-2;
1066 memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
1072 if (ieee->iw_mode == IW_MODE_ADHOC)
1073 {//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
1074 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
1077 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1080 skb->dev = ieee->dev;
1083 #ifdef _RTL8187_EXT_PATCH_
1084 struct sk_buff* ieee80211_ext_probe_resp_by_net(struct ieee80211_device *ieee, u8 *dest, struct ieee80211_network *net)
1088 struct ieee80211_probe_response *beacon_buf;
1089 struct sk_buff *skb;
1091 int atim_len,erp_len;
1092 struct ieee80211_crypt_data* crypt;
1093 u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
1094 int wpa_ie_len = ieee->wpa_ie_len;
1095 char *ssid = net->ssid;
1096 int ssid_len = net->ssid_len;
1098 int rate_len = ieee->current_network.rates_len+2;
1099 int rate_ex_len = ieee->current_network.rates_ex_len;
1100 if(rate_ex_len > 0) rate_ex_len+=2;
1102 if( ieee->meshScanMode&4)
1103 ieee->current_network.channel = ieee->ext_patch_ieee80211_ext_stop_scan_wq_set_channel(ieee);
1104 if( ieee->meshScanMode&6)
1105 queue_work(ieee->wq, &ieee->ext_stop_scan_wq);
1107 if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS) // use current_network here
1112 if(ieee80211_is_54g(*net))
1117 beacon_size = sizeof(struct ieee80211_probe_response)+
1125 skb = dev_alloc_skb(beacon_size+196);
1130 beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
1132 memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
1133 memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1134 memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
1136 beacon_buf->header.duration_id = 0; //FIXME
1138 beacon_buf->beacon_interval =
1139 cpu_to_le16(ieee->current_network.beacon_interval); // use current_network here
1140 beacon_buf->capability =
1141 cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
1143 if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
1144 cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
1146 crypt = ieee->crypt[ieee->tx_keyidx];
1148 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
1149 ((0 == strcmp(crypt->ops->name, "WEP"))||wpa_ie_len);
1152 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1155 beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
1157 beacon_buf->info_element.id = MFIE_TYPE_SSID;
1158 beacon_buf->info_element.len = ssid_len;
1160 tag = (u8*) beacon_buf->info_element.data;
1162 // brocad cast / probe rsp
1163 if(memcmp(dest, broadcast_addr, ETH_ALEN ))
1164 memcpy(tag, ssid, ssid_len);
1170 //get_bssrate_set(priv, _SUPPORTEDRATES_IE_, &pbssrate, &bssrate_len);
1171 //pbuf = set_ie(pbuf, _SUPPORTEDRATES_IE_, bssrate_len, pbssrate, &frlen);
1173 *(tag++) = MFIE_TYPE_RATES;
1174 *(tag++) = rate_len-2;
1175 memcpy(tag,ieee->current_network.rates,rate_len-2);
1178 *(tag++) = MFIE_TYPE_DS_SET;
1180 *(tag++) = ieee->current_network.channel; // use current_network here
1184 *(tag++) = MFIE_TYPE_IBSS_SET;
1186 *((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window); // use current_network here
1191 *(tag++) = MFIE_TYPE_ERP;
1197 *(tag++) = MFIE_TYPE_RATES_EX;
1198 *(tag++) = rate_ex_len-2;
1199 memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
1203 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
1205 skb->dev = ieee->dev;
1208 #endif // _RTL8187_EXT_PATCH_
1210 struct sk_buff* ieee80211_assoc_resp(struct ieee80211_device *ieee, u8 *dest)
1212 struct sk_buff *skb;
1215 struct ieee80211_crypt_data* crypt;
1216 struct ieee80211_assoc_response_frame *assoc;
1219 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1220 int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
1222 skb = dev_alloc_skb(len);
1227 assoc = (struct ieee80211_assoc_response_frame *)
1228 skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
1230 assoc->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP);
1231 memcpy(assoc->header.addr1, dest,ETH_ALEN);
1232 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1233 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1234 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1235 WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
1238 if(ieee->short_slot)
1239 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1241 if (ieee->host_encrypt)
1242 crypt = ieee->crypt[ieee->tx_keyidx];
1245 encrypt = ( crypt && crypt->ops);
1248 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1251 assoc->aid = cpu_to_le16(ieee->assoc_id);
1252 if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
1253 else ieee->assoc_id++;
1255 tag = (u8*) skb_put(skb, rate_len);
1257 ieee80211_MFIE_Brate(ieee, &tag);
1258 ieee80211_MFIE_Grate(ieee, &tag);
1263 struct sk_buff* ieee80211_auth_resp(struct ieee80211_device *ieee,int status, u8 *dest)
1265 struct sk_buff *skb;
1266 struct ieee80211_authentication *auth;
1268 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
1273 skb->len = sizeof(struct ieee80211_authentication);
1275 auth = (struct ieee80211_authentication *)skb->data;
1277 auth->status = cpu_to_le16(status);
1278 auth->transaction = cpu_to_le16(2);
1279 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1281 #ifdef _RTL8187_EXT_PATCH_
1282 if(ieee->iw_mode == ieee->iw_ext_mode)
1283 memcpy(auth->header.addr3, dest, ETH_ALEN);
1285 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1287 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1288 memcpy(auth->header.addr1, dest, ETH_ALEN);
1289 auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
1295 struct sk_buff* ieee80211_null_func(struct ieee80211_device *ieee,short pwr)
1297 struct sk_buff *skb;
1298 struct ieee80211_hdr_3addr* hdr;
1300 skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
1305 hdr = (struct ieee80211_hdr_3addr*)skb_put(skb,sizeof(struct ieee80211_hdr_3addr));
1307 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1308 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1309 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1311 hdr->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
1312 IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
1313 (pwr ? IEEE80211_FCTL_PM:0));
1321 void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8* dest)
1323 struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest);
1326 softmac_mgmt_xmit(buf, ieee);
1327 dev_kfree_skb_any(buf);//edit by thomas
1332 void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8* dest)
1334 struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest);
1337 softmac_mgmt_xmit(buf, ieee);
1338 dev_kfree_skb_any(buf);//edit by thomas
1343 void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest)
1346 struct sk_buff *buf = ieee80211_probe_resp(ieee, dest);
1349 softmac_mgmt_xmit(buf, ieee);
1350 dev_kfree_skb_any(buf);//edit by thomas
1355 inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beacon,struct ieee80211_device *ieee)
1357 struct sk_buff *skb;
1358 //unsigned long flags;
1360 struct ieee80211_assoc_request_frame *hdr;
1362 //short info_addr = 0;
1364 //u16 suite_count = 0;
1365 //u8 suit_select = 0;
1366 unsigned int wpa_len = beacon->wpa_ie_len;
1367 //struct net_device *dev = ieee->dev;
1368 //union iwreq_data wrqu;
1372 // for testing purpose
1373 unsigned int rsn_len = beacon->rsn_ie_len;
1375 unsigned int rsn_len = beacon->rsn_ie_len - 4;
1377 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1378 unsigned int wmm_info_len = beacon->QoS_Enable?9:0;
1380 unsigned int turbo_info_len = beacon->Turbo_Enable?9:0;
1383 u8 encry_proto = ieee->wpax_type_notify & 0xff;
1384 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1385 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1389 //[0] Notify type of encryption: WPA/WPA2
1390 //[1] pair wise type
1392 if(ieee->wpax_type_set) {
1393 if (IEEE_PROTO_WPA == encry_proto) {
1395 } else if (IEEE_PROTO_RSN == encry_proto) {
1400 len = sizeof(struct ieee80211_assoc_request_frame)+
1401 + beacon->ssid_len//essid tagged val
1402 + rate_len//rates tagged val
1408 len = sizeof(struct ieee80211_assoc_request_frame)+
1409 + beacon->ssid_len//essid tagged val
1410 + rate_len//rates tagged val
1416 #ifdef _RTL8187_EXT_PATCH_
1417 if(ieee->iw_mode == ieee->iw_ext_mode)
1418 skb = dev_alloc_skb(len+256); // stanley
1421 skb = dev_alloc_skb(len);
1426 hdr = (struct ieee80211_assoc_request_frame *)
1427 skb_put(skb, sizeof(struct ieee80211_assoc_request_frame));
1430 hdr->header.frame_ctl = IEEE80211_STYPE_ASSOC_REQ;
1431 hdr->header.duration_id= 37; //FIXME
1432 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1433 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1434 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1435 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);//for HW security, John
1437 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS);
1438 if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1439 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1440 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1441 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1443 if(ieee->short_slot)
1444 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1446 #ifdef _RTL8187_EXT_PATCH_
1447 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_association_req_1)
1448 ieee->ext_patch_ieee80211_association_req_1(hdr);
1451 hdr->listen_interval = 0xa; //FIXME
1453 hdr->info_element.id = MFIE_TYPE_SSID;
1455 hdr->info_element.len = beacon->ssid_len;
1456 tag = skb_put(skb, beacon->ssid_len);
1457 memcpy(tag, beacon->ssid, beacon->ssid_len);
1459 tag = skb_put(skb, rate_len);
1461 ieee80211_MFIE_Brate(ieee, &tag);
1462 ieee80211_MFIE_Grate(ieee, &tag);
1464 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1465 //choose AES encryption as default algorithm while using mixed mode
1469 tag = skb_put(skb,wpa_len);
1474 //{add by david. 2006.8.31
1475 //fix linksys compatibility bug
1477 if(wpa_len > 24) {//22+2, mean include the capability
1478 beacon->wpa_ie[wpa_len - 2] = 0;
1480 //multicast cipher OUI
1481 if( beacon->wpa_ie[11]==0x2 ){ //0x0050f202 is the oui of tkip
1482 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1484 else if( beacon->wpa_ie[11]==0x4 ){//0x0050f204 is the oui of ccmp
1485 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1487 //unicast cipher OUI
1488 if( beacon->wpa_ie[14]==0
1489 && beacon->wpa_ie[15]==0x50
1490 && beacon->wpa_ie[16]==0xf2
1491 && beacon->wpa_ie[17]==0x2 ){ //0x0050f202 is the oui of tkip
1492 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1495 else if( beacon->wpa_ie[14]==0
1496 && beacon->wpa_ie[15]==0x50
1497 && beacon->wpa_ie[16]==0xf2
1498 && beacon->wpa_ie[17]==0x4 ){//0x0050f204 is the oui of ccmp
1499 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1501 //indicate the wpa_ie content to WPA_SUPPLICANT
1502 buff = kmalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
1503 memset(buff, 0, IW_CUSTOM_MAX);
1505 p += sprintf(p, "ASSOCINFO(ReqIEs=");
1506 for(i=0;i<wpa_len;i++){
1507 p += sprintf(p, "%02x", beacon->wpa_ie[i]);
1509 p += sprintf(p, ")");
1510 memset(&wrqu, 0, sizeof(wrqu) );
1511 wrqu.data.length = p - buff;
1513 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buff);
1514 memcpy(tag,beacon->wpa_ie,wpa_len);
1521 if( beacon->rsn_ie[4]==0x0 &&
1522 beacon->rsn_ie[5]==0xf &&
1523 beacon->rsn_ie[6]==0xac){
1525 switch(beacon->rsn_ie[7]){
1527 ieee->broadcast_key_type = KEY_TYPE_WEP40;
1530 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1533 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1536 ieee->broadcast_key_type = KEY_TYPE_WEP104;
1539 printk("fault suite type in RSN broadcast key\n");
1544 if( beacon->rsn_ie[10]==0x0 &&
1545 beacon->rsn_ie[11]==0xf &&
1546 beacon->rsn_ie[12]==0xac){
1547 if(beacon->rsn_ie[8]==1){//not mixed mode
1548 switch(beacon->rsn_ie[13]){
1550 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1553 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1556 printk("fault suite type in RSN pairwise key\n");
1560 else if(beacon->rsn_ie[8]==2){//mixed mode
1561 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1567 tag = skb_put(skb,22);
1568 memcpy(tag,(beacon->rsn_ie + info_addr),8);
1573 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
1574 for (i = 0; i < 2; i++) {
1578 suite_count = beacon->rsn_ie[info_addr] + \
1579 (beacon->rsn_ie[info_addr + 1] << 8);
1581 if(1 == suite_count) {
1582 memcpy(tag,(beacon->rsn_ie + info_addr),4);
1585 // if the wpax_type_notify has been set by the application,
1586 // just use it, otherwise just use the default one.
1587 if(ieee->wpax_type_set) {
1588 suit_select = ((0 == i) ? pairwise_type:authen_type)&0x0f ;
1589 memcpy(tag,rsn_authen_cipher_suite[suit_select],4);
1591 //default set as ccmp, or none authentication
1593 memcpy(tag,rsn_authen_cipher_suite[4],4);
1595 memcpy(tag,rsn_authen_cipher_suite[2],4);
1600 info_addr += (suite_count * 4);
1604 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
1607 tag[1] = beacon->rsn_ie[info_addr+1];
1610 tag = skb_put(skb,rsn_len);
1614 if( beacon->rsn_ie[4]==0x0 &&
1615 beacon->rsn_ie[5]==0xf &&
1616 beacon->rsn_ie[6]==0xac){
1617 switch(beacon->rsn_ie[7]){
1619 ieee->broadcast_key_type = KEY_TYPE_WEP40;
1622 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1625 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1628 ieee->broadcast_key_type = KEY_TYPE_WEP104;
1631 printk("fault suite type in RSN broadcast key\n");
1635 if( beacon->rsn_ie[10]==0x0 &&
1636 beacon->rsn_ie[11]==0xf &&
1637 beacon->rsn_ie[12]==0xac){
1638 if(beacon->rsn_ie[8]==1){//not mixed mode
1639 switch(beacon->rsn_ie[13]){
1641 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1644 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1647 printk("fault suite type in RSN pairwise key\n");
1652 else if(beacon->rsn_ie[8]==2){//mixed mode
1653 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1658 beacon->rsn_ie[rsn_len - 2] = 0;
1659 memcpy(tag,beacon->rsn_ie,rsn_len);
1663 tag = skb_put(skb,ieee->wpa_ie_len);
1664 memcpy(tag,ieee->wpa_ie,ieee->wpa_ie_len);
1666 tag = skb_put(skb,wmm_info_len);
1668 ieee80211_WMM_Info(ieee, &tag);
1671 tag = skb_put(skb,turbo_info_len);
1672 if(turbo_info_len) {
1673 ieee80211_TURBO_Info(ieee, &tag);
1677 #ifdef _RTL8187_EXT_PATCH_
1678 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_association_req_2)
1679 ieee->ext_patch_ieee80211_association_req_2(ieee, beacon, skb);
1685 void ieee80211_associate_abort(struct ieee80211_device *ieee)
1688 unsigned long flags;
1689 spin_lock_irqsave(&ieee->lock, flags);
1691 ieee->associate_seq++;
1693 /* don't scan, and avoid to have the RX path possibily
1694 * try again to associate. Even do not react to AUTH or
1695 * ASSOC response. Just wait for the retry wq to be scheduled.
1696 * Here we will check if there are good nets to associate
1697 * with, so we retry or just get back to NO_LINK and scanning
1699 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING){
1700 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1701 ieee->softmac_stats.no_auth_rs++;
1703 IEEE80211_DEBUG_MGMT("Association failed\n");
1704 ieee->softmac_stats.no_ass_rs++;
1707 ieee->state = IEEE80211_ASSOCIATING_RETRY;
1709 queue_delayed_work(ieee->wq, &ieee->associate_retry_wq,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME);
1711 spin_unlock_irqrestore(&ieee->lock, flags);
1714 void ieee80211_associate_abort_cb(unsigned long dev)
1716 ieee80211_associate_abort((struct ieee80211_device *) dev);
1720 void ieee80211_associate_step1(struct ieee80211_device *ieee)
1722 struct ieee80211_network *beacon = &ieee->current_network;
1723 struct sk_buff *skb;
1725 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1726 ieee->softmac_stats.tx_auth_rq++;
1727 skb=ieee80211_authentication_req(beacon, ieee, 0);
1728 #ifdef _RTL8187_EXT_PATCH_
1729 if(ieee->iw_mode == ieee->iw_ext_mode ) {
1731 softmac_mgmt_xmit(skb, ieee);
1737 ieee80211_associate_abort(ieee);
1740 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
1741 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1742 //printk("---Sending authentication request\n");
1743 softmac_mgmt_xmit(skb, ieee);
1744 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1745 if(!timer_pending(&ieee->associate_timer)){
1746 ieee->associate_timer.expires = jiffies + (HZ / 2);
1747 add_timer(&ieee->associate_timer);
1749 //If call dev_kfree_skb_any,a warning will ocur....
1750 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1751 //So ... 1204 by lawrence.
1752 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1753 //dev_kfree_skb_any(skb);//edit by thomas
1757 void ieee80211_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, int chlen)
1760 struct sk_buff *skb;
1761 struct ieee80211_network *beacon = &ieee->current_network;
1762 // int hlen = sizeof(struct ieee80211_authentication);
1763 del_timer_sync(&ieee->associate_timer);
1764 ieee->associate_seq++;
1765 ieee->softmac_stats.tx_auth_rq++;
1767 skb = ieee80211_authentication_req(beacon, ieee, chlen+2);
1769 ieee80211_associate_abort(ieee);
1771 c = skb_put(skb, chlen+2);
1772 *(c++) = MFIE_TYPE_CHALLENGE;
1774 memcpy(c, challenge, chlen);
1776 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1778 ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr ));
1780 softmac_mgmt_xmit(skb, ieee);
1781 if (!timer_pending(&ieee->associate_timer)){
1782 //printk("=========>add timer again, to crash\n");
1783 ieee->associate_timer.expires = jiffies + (HZ / 2);
1784 add_timer(&ieee->associate_timer);
1786 dev_kfree_skb_any(skb);//edit by thomas
1791 #ifdef _RTL8187_EXT_PATCH_
1793 // based on ieee80211_assoc_resp
1794 struct sk_buff* ieee80211_assoc_resp_by_net(struct ieee80211_device *ieee, u8 *dest, unsigned short status, struct ieee80211_network *pstat, int pkt_type)
1796 struct sk_buff *skb;
1799 struct ieee80211_crypt_data* crypt;
1800 struct ieee80211_assoc_response_frame *assoc;
1803 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1804 int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
1806 if(ieee->iw_mode == ieee->iw_ext_mode)
1807 skb = dev_alloc_skb(len+256); // stanley
1809 skb = dev_alloc_skb(len);
1814 assoc = (struct ieee80211_assoc_response_frame *)
1815 skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
1817 assoc->header.frame_ctl = cpu_to_le16(pkt_type);
1819 memcpy(assoc->header.addr1, dest,ETH_ALEN);
1820 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1821 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1822 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1823 WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
1825 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_assoc_resp_by_net_1)
1826 ieee->ext_patch_ieee80211_assoc_resp_by_net_1(assoc);
1828 if(ieee->short_slot)
1829 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1831 if (ieee->host_encrypt)
1832 crypt = ieee->crypt[ieee->tx_keyidx];
1835 encrypt = ( crypt && crypt->ops);
1838 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1841 assoc->aid = cpu_to_le16(ieee->assoc_id);
1842 if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
1843 else ieee->assoc_id++;
1845 assoc->info_element.id = 230; // Stanley, an unused id (just a hot fix)
1846 assoc->info_element.len = 0;
1848 tag = (u8*) skb_put(skb, rate_len);
1850 ieee80211_MFIE_Brate(ieee, &tag);
1851 ieee80211_MFIE_Grate(ieee, &tag);
1853 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_assoc_resp_by_net_2)
1854 ieee->ext_patch_ieee80211_assoc_resp_by_net_2(ieee, pstat, pkt_type, skb);
1859 // based on ieee80211_resp_to_assoc_rq
1860 void ieee80211_ext_issue_assoc_rsp(struct ieee80211_device *ieee, u8 *dest, unsigned short status, struct ieee80211_network *pstat, int pkt_type)
1862 struct sk_buff *buf = ieee80211_assoc_resp_by_net(ieee, dest, status, pstat, pkt_type);
1865 softmac_mgmt_xmit(buf, ieee);
1868 // based on ieee80211_associate_step2
1869 void ieee80211_ext_issue_assoc_req(struct ieee80211_device *ieee, struct ieee80211_network *pstat)
1872 struct sk_buff* skb;
1874 // printk("@@@@@ ieee80211_ext_issue_assoc_req on channel: %d\n", ieee->current_network.channel);
1876 ieee->softmac_stats.tx_ass_rq++;
1877 skb=ieee80211_association_req(pstat, ieee);
1879 softmac_mgmt_xmit(skb, ieee);
1882 void ieee80211_ext_issue_disassoc(struct ieee80211_device *ieee, struct ieee80211_network *pstat, int reason, unsigned char extReason)
1885 // printk("@@@@@ ieee80211_ext_issue_disassoc\n");
1888 #endif // _RTL8187_EXT_PATCH_
1890 void ieee80211_associate_step2(struct ieee80211_device *ieee)
1892 struct sk_buff* skb;
1893 struct ieee80211_network *beacon = &ieee->current_network;
1895 del_timer_sync(&ieee->associate_timer);
1897 IEEE80211_DEBUG_MGMT("Sending association request\n");
1898 ieee->softmac_stats.tx_ass_rq++;
1899 skb=ieee80211_association_req(beacon, ieee);
1901 ieee80211_associate_abort(ieee);
1903 softmac_mgmt_xmit(skb, ieee);
1904 if (!timer_pending(&ieee->associate_timer)){
1905 ieee->associate_timer.expires = jiffies + (HZ / 2);
1906 add_timer(&ieee->associate_timer);
1908 //dev_kfree_skb_any(skb);//edit by thomas
1912 void ieee80211_associate_complete_wq(struct work_struct *work)
1914 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq);
1916 printk(KERN_INFO "Associated successfully\n");
1917 if(ieee80211_is_54g(ieee->current_network) &&
1918 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1921 printk(KERN_INFO"Using G rates\n");
1924 printk(KERN_INFO"Using B rates\n");
1926 ieee->link_change(ieee->dev);
1927 notify_wx_assoc_event(ieee);
1928 if (ieee->data_hard_resume)
1929 ieee->data_hard_resume(ieee->dev);
1930 netif_carrier_on(ieee->dev);
1933 void ieee80211_associate_complete(struct ieee80211_device *ieee)
1936 del_timer_sync(&ieee->associate_timer);
1938 for(i = 0; i < 6; i++) {
1939 //ieee->seq_ctrl[i] = 0;
1941 ieee->state = IEEE80211_LINKED;
1942 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1944 queue_work(ieee->wq, &ieee->associate_complete_wq);
1947 void ieee80211_associate_procedure_wq(struct work_struct *work)
1949 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1951 ieee->sync_scan_hurryup = 1;
1952 down(&ieee->wx_sem);
1954 if (ieee->data_hard_stop)
1955 ieee->data_hard_stop(ieee->dev);
1957 ieee80211_stop_scan(ieee);
1958 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1960 ieee->associate_seq = 1;
1961 ieee80211_associate_step1(ieee);
1965 #ifdef _RTL8187_EXT_PATCH_
1966 // based on ieee80211_associate_procedure_wq
1968 void ieee80211_ext_stop_scan_wq(struct work_struct *work)
1970 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, ext_stop_scan_wq);
1972 if (ieee->scanning == 0) {
1973 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_ext_stop_scan_wq_set_channel
1974 && ( ieee->current_network.channel == ieee->ext_patch_ieee80211_ext_stop_scan_wq_set_channel(ieee) ) )
1978 ieee->sync_scan_hurryup = 1;
1980 down(&ieee->wx_sem);
1982 // printk("@@@@@@@@@@ ieee80211_ext_stop_scan_wq\n");
1983 if (ieee->data_hard_stop)
1984 ieee->data_hard_stop(ieee->dev);
1986 ieee80211_stop_scan(ieee);
1989 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_ext_stop_scan_wq_set_channel)
1990 ieee->set_chan(ieee->dev, ieee->ext_patch_ieee80211_ext_stop_scan_wq_set_channel(ieee));
1992 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1998 void ieee80211_ext_send_11s_beacon(struct ieee80211_device *ieee)
2000 queue_work(ieee->wq, &ieee->ext_send_beacon_wq);
2003 #endif // _RTL8187_EXT_PATCH_
2005 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
2007 u8 tmp_ssid[IW_ESSID_MAX_SIZE+1];
2008 int tmp_ssid_len = 0;
2010 short apset,ssidset,ssidbroad,apmatch,ssidmatch;
2012 /* we are interested in new new only if we are not associated
2013 * and we are not associating / authenticating
2015 if (ieee->state != IEEE80211_NOLINK)
2018 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS))
2021 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS))
2025 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC){
2026 /* if the user specified the AP MAC, we need also the essid
2027 * This could be obtained by beacons or, if the network does not
2028 * broadcast it, it can be put manually.
2030 apset = ieee->wap_set;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
2031 ssidset = ieee->ssid_set;//ieee->current_network.ssid[0] != '\0';
2032 ssidbroad = !(net->ssid_len == 0 || net->ssid[0]== '\0');
2033 apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN)==0);
2035 if(ieee->current_network.ssid_len != net->ssid_len)
2038 ssidmatch = (0==strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len));
2040 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
2041 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
2043 if ( /* if the user set the AP check if match.
2044 * if the network does not broadcast essid we check the user supplyed ANY essid
2045 * if the network does broadcast and the user does not set essid it is OK
2046 * if the network does broadcast and the user did set essid chech if essid match
2048 ( apset && apmatch &&
2049 ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
2050 /* if the ap is not set, check that the user set the bssid
2051 * and the network does bradcast and that those two bssid matches
2053 (!apset && ssidset && ssidbroad && ssidmatch)
2057 /* if the essid is hidden replace it with the
2058 * essid provided by the user.
2061 strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
2062 tmp_ssid_len = ieee->current_network.ssid_len;
2064 memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
2067 strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
2068 ieee->current_network.ssid_len = tmp_ssid_len;
2070 printk(KERN_INFO"Linking with %s: channel is %d\n",ieee->current_network.ssid,ieee->current_network.channel);
2072 if (ieee->iw_mode == IW_MODE_INFRA){
2073 ieee->state = IEEE80211_ASSOCIATING;
2074 ieee->beinretry = false;
2075 queue_work(ieee->wq, &ieee->associate_procedure_wq);
2077 if(ieee80211_is_54g(ieee->current_network) &&
2078 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
2080 printk(KERN_INFO"Using G rates\n");
2083 printk(KERN_INFO"Using B rates\n");
2085 ieee->state = IEEE80211_LINKED;
2086 ieee->beinretry = false;
2094 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
2096 unsigned long flags;
2097 struct ieee80211_network *target;
2099 spin_lock_irqsave(&ieee->lock, flags);
2100 list_for_each_entry(target, &ieee->network_list, list) {
2102 /* if the state become different that NOLINK means
2103 * we had found what we are searching for
2106 if (ieee->state != IEEE80211_NOLINK)
2109 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
2110 ieee80211_softmac_new_net(ieee, target);
2113 spin_unlock_irqrestore(&ieee->lock, flags);
2118 static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
2120 struct ieee80211_authentication *a;
2122 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
2123 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb->len);
2127 a = (struct ieee80211_authentication*) skb->data;
2128 if(skb->len > (sizeof(struct ieee80211_authentication) +3)){
2129 t = skb->data + sizeof(struct ieee80211_authentication);
2131 if(*(t++) == MFIE_TYPE_CHALLENGE){
2133 *challenge = (u8*)kmalloc(*chlen, GFP_ATOMIC);
2134 memcpy(*challenge, t, *chlen);
2138 return cpu_to_le16(a->status);
2143 int auth_rq_parse(struct sk_buff *skb,u8* dest)
2145 struct ieee80211_authentication *a;
2147 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
2148 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
2151 a = (struct ieee80211_authentication*) skb->data;
2153 memcpy(dest,a->header.addr2, ETH_ALEN);
2155 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
2156 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2158 return WLAN_STATUS_SUCCESS;
2161 static short probe_rq_parse(struct ieee80211_device *ieee, struct sk_buff *skb, u8 *src)
2168 struct ieee80211_hdr_3addr *header =
2169 (struct ieee80211_hdr_3addr *) skb->data;
2171 if (skb->len < sizeof (struct ieee80211_hdr_3addr ))
2172 return -1; /* corrupted */
2174 memcpy(src,header->addr2, ETH_ALEN);
2176 skbend = (u8*)skb->data + skb->len;
2178 tag = skb->data + sizeof (struct ieee80211_hdr_3addr );
2180 while (tag+1 < skbend){
2186 tag++; /* point to the len field */
2187 tag = tag + *(tag); /* point to the last data byte of the tag */
2188 tag++; /* point to the next tag */
2191 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
2192 if (ssidlen == 0) return 1;
2194 if (!ssid) return 1; /* ssid not found in tagged param */
2195 return (!strncmp(ssid, ieee->current_network.ssid, ssidlen));
2199 int assoc_rq_parse(struct sk_buff *skb,u8* dest)
2201 struct ieee80211_assoc_request_frame *a;
2203 if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
2204 sizeof(struct ieee80211_info_element))) {
2206 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb->len);
2210 a = (struct ieee80211_assoc_request_frame*) skb->data;
2212 memcpy(dest,a->header.addr2,ETH_ALEN);
2217 static inline u16 assoc_parse(struct sk_buff *skb, int *aid)
2219 struct ieee80211_assoc_response_frame *a;
2220 if (skb->len < sizeof(struct ieee80211_assoc_response_frame)){
2221 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
2225 a = (struct ieee80211_assoc_response_frame*) skb->data;
2226 *aid = le16_to_cpu(a->aid) & 0x3fff;
2227 return le16_to_cpu(a->status);
2231 ieee80211_rx_probe_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
2235 //IEEE80211DMESG("Rx probe");
2236 ieee->softmac_stats.rx_probe_rq++;
2237 //DMESG("Dest is "MACSTR, MAC2STR(dest));
2238 if (probe_rq_parse(ieee, skb, dest)){
2239 //IEEE80211DMESG("Was for me!");
2240 ieee->softmac_stats.tx_probe_rs++;
2241 ieee80211_resp_to_probe(ieee, dest);
2246 ieee80211_rx_auth_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
2250 //IEEE80211DMESG("Rx probe");
2251 ieee->softmac_stats.rx_auth_rq++;
2253 if ((status = auth_rq_parse(skb, dest))!= -1){
2254 ieee80211_resp_to_auth(ieee, status, dest);
2256 //DMESG("Dest is "MACSTR, MAC2STR(dest));
2261 ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
2265 //unsigned long flags;
2267 ieee->softmac_stats.rx_ass_rq++;
2268 if (assoc_rq_parse(skb,dest) != -1){
2269 ieee80211_resp_to_assoc_rq(ieee, dest);
2272 printk(KERN_INFO"New client associated: "MAC_FMT"\n", MAC_ARG(dest));
2275 spin_lock_irqsave(&ieee->lock,flags);
2276 add_associate(ieee,dest);
2277 spin_unlock_irqrestore(&ieee->lock,flags);
2283 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr)
2286 struct sk_buff *buf = ieee80211_null_func(ieee, pwr);
2289 softmac_ps_mgmt_xmit(buf, ieee);
2294 short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, u32 *time_l)
2297 int timeout = ieee->ps_timeout;
2302 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
2303 ieee->iw_mode != IW_MODE_INFRA ||
2304 ieee->state != IEEE80211_LINKED)
2308 dtim = ieee->current_network.dtim_data;
2311 if(!(dtim & IEEE80211_DTIM_VALID))
2314 timeout = ieee->current_network.beacon_interval;
2316 //printk("VALID\n");
2317 ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
2319 if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
2322 if(!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout)))
2325 if(!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout)))
2328 if((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE ) &&
2329 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
2333 *time_l = ieee->current_network.last_dtim_sta_time[0]
2334 + (ieee->current_network.beacon_interval
2335 * ieee->current_network.dtim_period) * 1000;
2339 *time_l = ieee->current_network.last_dtim_sta_time[0]
2340 + MSECS((ieee->current_network.beacon_interval));
2341 //* ieee->current_network.dtim_period));
2342 //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);
2347 *time_h = ieee->current_network.last_dtim_sta_time[1];
2348 if(time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
2357 inline void ieee80211_sta_ps(struct ieee80211_device *ieee)
2363 unsigned long flags,flags2;
2365 spin_lock_irqsave(&ieee->lock, flags);
2367 if((ieee->ps == IEEE80211_PS_DISABLED ||
2369 ieee->iw_mode != IW_MODE_INFRA ||
2370 ieee->state != IEEE80211_LINKED)){
2372 //#warning CHECK_LOCK_HERE
2373 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2375 ieee80211_sta_wakeup(ieee, 1);
2377 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2380 sleep = ieee80211_sta_ps_sleep(ieee,&th, &tl);
2381 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
2382 /* 2 wake, 1 sleep, 0 do nothing */
2388 if(ieee->sta_sleep == 1)
2389 ieee->enter_sleep_state(ieee->dev,th,tl);
2391 else if(ieee->sta_sleep == 0){
2392 // printk("send null 1\n");
2393 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2395 if(ieee->ps_is_queue_empty(ieee->dev)){
2398 ieee->sta_sleep = 2;
2400 ieee->ps_request_tx_ack(ieee->dev);
2402 ieee80211_sta_ps_send_null_frame(ieee,1);
2407 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2412 }else if(sleep == 2){
2413 //#warning CHECK_LOCK_HERE
2414 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2416 // printk("send wakeup packet\n");
2417 ieee80211_sta_wakeup(ieee,1);
2419 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2423 spin_unlock_irqrestore(&ieee->lock, flags);
2427 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl)
2429 if(ieee->sta_sleep == 0){
2431 // printk("Warning: driver is probably failing to report TX ps error\n");
2432 ieee->ps_request_tx_ack(ieee->dev);
2433 ieee80211_sta_ps_send_null_frame(ieee, 0);
2439 if(ieee->sta_sleep == 1)
2440 ieee->sta_wake_up(ieee->dev);
2442 ieee->sta_sleep = 0;
2445 ieee->ps_request_tx_ack(ieee->dev);
2446 ieee80211_sta_ps_send_null_frame(ieee, 0);
2450 void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success)
2452 unsigned long flags,flags2;
2454 spin_lock_irqsave(&ieee->lock, flags);
2455 if(ieee->sta_sleep == 2){
2456 /* Null frame with PS bit set */
2459 // printk("==================> %s::enter sleep state\n",__func__);
2460 ieee->sta_sleep = 1;
2461 ieee->enter_sleep_state(ieee->dev,ieee->ps_th,ieee->ps_tl);
2463 /* if the card report not success we can't be sure the AP
2464 * has not RXed so we can't assume the AP believe us awake
2467 /* 21112005 - tx again null without PS bit if lost */
2470 if((ieee->sta_sleep == 0) && !success){
2471 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2472 ieee80211_sta_ps_send_null_frame(ieee, 0);
2473 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2476 spin_unlock_irqrestore(&ieee->lock, flags);
2480 ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
2481 struct ieee80211_rx_stats *rx_stats, u16 type,
2484 struct ieee80211_hdr_3addr *header = (struct ieee80211_hdr_3addr *) skb->data;
2489 struct ieee80211_assoc_response_frame *assoc_resp;
2490 struct ieee80211_info_element *info_element;
2492 if(!ieee->proto_started)
2495 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2496 ieee->iw_mode == IW_MODE_INFRA &&
2497 ieee->state == IEEE80211_LINKED))
2499 tasklet_schedule(&ieee->ps_task);
2501 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2502 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2503 ieee->last_rx_ps_time = jiffies;
2505 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2507 case IEEE80211_STYPE_ASSOC_RESP:
2508 case IEEE80211_STYPE_REASSOC_RESP:
2510 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2511 WLAN_FC_GET_STYPE(header->frame_ctl));
2512 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2513 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
2514 ieee->iw_mode == IW_MODE_INFRA){
2515 if (0 == (errcode=assoc_parse(skb, &aid))){
2518 ieee->state=IEEE80211_LINKED;
2519 ieee->assoc_id = aid;
2520 ieee->softmac_stats.rx_ass_ok++;
2522 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
2523 if(1 == rx_stats->nic_type) //card type is 8187
2525 goto associate_complete;
2527 assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data;
2528 info_element = &assoc_resp->info_element;
2529 left = skb->len - ((void*)info_element - (void*)assoc_resp);
2531 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
2532 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
2533 printk(KERN_WARNING "[re]associate reeponse error!");
2536 switch (info_element->id) {
2537 case MFIE_TYPE_GENERIC:
2538 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element->len);
2539 if (info_element->len >= 8 &&
2540 info_element->data[0] == 0x00 &&
2541 info_element->data[1] == 0x50 &&
2542 info_element->data[2] == 0xf2 &&
2543 info_element->data[3] == 0x02 &&
2544 info_element->data[4] == 0x01) {
2545 // Not care about version at present.
2546 //WMM Parameter Element
2547 memcpy(ieee->current_network.wmm_param,(u8*)(info_element->data\
2548 + 8),(info_element->len - 8));
2550 if (((ieee->current_network.wmm_info^info_element->data[6])& \
2551 0x0f)||(!ieee->init_wmmparam_flag)) {
2552 //refresh paramete element for current network
2553 // update the register parameter for hardware
2554 ieee->init_wmmparam_flag = 1;
2555 queue_work(ieee->wq, &ieee->wmm_param_update_wq);
2558 //update info_element for current network
2559 ieee->current_network.wmm_info = info_element->data[6];
2563 //nothing to do at present!!!
2567 left -= sizeof(struct ieee80211_info_element_hdr) +
2569 info_element = (struct ieee80211_info_element *)
2570 &info_element->data[info_element->len];
2572 if(!ieee->init_wmmparam_flag) //legacy AP, reset the AC_xx_param register
2574 queue_work(ieee->wq,&ieee->wmm_param_update_wq);
2575 ieee->init_wmmparam_flag = 1;//indicate AC_xx_param upated since last associate
2578 ieee80211_associate_complete(ieee);
2580 ieee->softmac_stats.rx_ass_err++;
2581 IEEE80211_DEBUG_MGMT(
2582 "Association response status code 0x%x\n",
2584 ieee80211_associate_abort(ieee);
2587 #ifdef _RTL8187_EXT_PATCH_
2588 else if ((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_rx_frame_softmac_on_assoc_rsp)
2590 ieee->ext_patch_ieee80211_rx_frame_softmac_on_assoc_rsp(ieee, skb);
2595 case IEEE80211_STYPE_ASSOC_REQ:
2596 case IEEE80211_STYPE_REASSOC_REQ:
2598 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2599 ieee->iw_mode == IW_MODE_MASTER)
2601 ieee80211_rx_assoc_rq(ieee, skb);
2602 #ifdef _RTL8187_EXT_PATCH_
2603 else if ((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_rx_frame_softmac_on_assoc_req)
2605 ieee->ext_patch_ieee80211_rx_frame_softmac_on_assoc_req(ieee, skb);
2610 case IEEE80211_STYPE_AUTH:
2612 #ifdef _RTL8187_EXT_PATCH_
2613 printk("IEEE80211_STYPE_AUTH\n");
2614 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_rx_frame_softmac_on_auth)
2615 if( ieee->ext_patch_ieee80211_rx_frame_softmac_on_auth(ieee, skb, rx_stats) );
2617 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
2618 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
2619 ieee->iw_mode == IW_MODE_INFRA){
2621 IEEE80211_DEBUG_MGMT("Received authentication response");
2623 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
2624 if(ieee->open_wep || !challenge){
2625 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
2626 ieee->softmac_stats.rx_auth_rs_ok++;
2628 ieee80211_associate_step2(ieee);
2630 ieee80211_auth_challenge(ieee, challenge, chlen);
2633 ieee->softmac_stats.rx_auth_rs_err++;
2634 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode);
2635 ieee80211_associate_abort(ieee);
2638 }else if (ieee->iw_mode == IW_MODE_MASTER){
2639 ieee80211_rx_auth_rq(ieee, skb);
2644 case IEEE80211_STYPE_PROBE_REQ:
2646 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2647 ((ieee->iw_mode == IW_MODE_ADHOC ||
2648 ieee->iw_mode == IW_MODE_MASTER) &&
2649 ieee->state == IEEE80211_LINKED))
2651 ieee80211_rx_probe_rq(ieee, skb);
2654 case IEEE80211_STYPE_DISASSOC:
2655 case IEEE80211_STYPE_DEAUTH:
2656 #ifdef _RTL8187_EXT_PATCH_
2657 printk("IEEE80211_STYPE_DEAUTH\n");
2658 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_rx_frame_softmac_on_deauth)
2659 if( ieee->ext_patch_ieee80211_rx_frame_softmac_on_deauth(ieee, skb, rx_stats) ) ;
2661 /* FIXME for now repeat all the association procedure
2662 * both for disassociation and deauthentication
2664 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2665 (ieee->state == IEEE80211_LINKED) &&
2666 (ieee->iw_mode == IW_MODE_INFRA) &&
2667 (!memcmp(header->addr2,ieee->current_network.bssid,ETH_ALEN))){
2668 ieee->state = IEEE80211_ASSOCIATING;
2669 ieee->softmac_stats.reassoc++;
2671 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
2672 queue_work(ieee->wq, &ieee->associate_procedure_wq);
2682 //dev_kfree_skb_any(skb);
2688 /* following are for a simplier TX queue management.
2689 * Instead of using netif_[stop/wake]_queue the driver
2690 * will uses these two function (plus a reset one), that
2691 * will internally uses the kernel netif_* and takes
2692 * care of the ieee802.11 fragmentation.
2693 * So the driver receives a fragment per time and might
2694 * call the stop function when it want without take care
2695 * to have enought room to TX an entire packet.
2696 * This might be useful if each fragment need it's own
2697 * descriptor, thus just keep a total free memory > than
2698 * the max fragmentation treshold is not enought.. If the
2699 * ieee802.11 stack passed a TXB struct then you needed
2700 * to keep N free descriptors where
2701 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2702 * In this way you need just one and the 802.11 stack
2703 * will take care of buffering fragments and pass them to
2704 * to the driver later, when it wakes the queue.
2707 void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee)
2711 unsigned long flags;
2713 #ifdef _RTL8187_EXT_PATCH_
2714 int rate = ieee->rate;
2717 spin_lock_irqsave(&ieee->lock,flags);
2719 if(ieee->queue_stop){
2720 IEEE80211DMESG("EE: IEEE hard_start_xmit invoked when kernel queue should be stopped");
2721 netif_stop_queue(ieee->dev);
2722 ieee->ieee_stats.swtxstop++;
2723 //dev_kfree_skb_any(skb);
2728 ieee->stats.tx_bytes+=skb->len;
2731 txb=ieee80211_skb_to_txb(ieee,skb);
2735 IEEE80211DMESG("WW: IEEE stack failed to provide txb");
2736 //dev_kfree_skb_any(skb);
2742 #ifdef _RTL8187_EXT_PATCH_
2743 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_ieee80211_softmac_xmit_get_rate && txb->nr_frags)
2745 rate = ieee->ext_patch_ieee80211_softmac_xmit_get_rate(ieee, txb->fragments[0]);
2748 /* called with 2nd parm 0, no tx mgmt lock required */
2749 ieee80211_sta_wakeup(ieee,0);
2751 for(i = 0; i < txb->nr_frags; i++) {
2753 if (ieee->queue_stop){
2754 ieee->tx_pending.txb = txb;
2755 ieee->tx_pending.frag = i;
2758 ieee->softmac_data_hard_start_xmit(
2760 #ifdef _RTL8187_EXT_PATCH_
2763 ieee->dev,ieee->rate);
2765 //(i+1)<txb->nr_frags);
2766 ieee->stats.tx_packets++;
2767 ieee->stats.tx_bytes += txb->fragments[i]->len;
2768 ieee->dev->trans_start = jiffies;
2772 ieee80211_txb_free(txb);
2775 spin_unlock_irqrestore(&ieee->lock,flags);
2779 /* called with ieee->lock acquired */
2780 void ieee80211_resume_tx(struct ieee80211_device *ieee)
2783 for(i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) {
2785 if (ieee->queue_stop){
2786 ieee->tx_pending.frag = i;
2790 ieee->softmac_data_hard_start_xmit(
2791 ieee->tx_pending.txb->fragments[i],
2792 ieee->dev,ieee->rate);
2793 //(i+1)<ieee->tx_pending.txb->nr_frags);
2794 ieee->stats.tx_packets++;
2795 ieee->dev->trans_start = jiffies;
2800 ieee80211_txb_free(ieee->tx_pending.txb);
2801 ieee->tx_pending.txb = NULL;
2805 void ieee80211_reset_queue(struct ieee80211_device *ieee)
2807 unsigned long flags;
2809 spin_lock_irqsave(&ieee->lock,flags);
2810 init_mgmt_queue(ieee);
2811 if (ieee->tx_pending.txb){
2812 ieee80211_txb_free(ieee->tx_pending.txb);
2813 ieee->tx_pending.txb = NULL;
2815 ieee->queue_stop = 0;
2816 spin_unlock_irqrestore(&ieee->lock,flags);
2820 void ieee80211_wake_queue(struct ieee80211_device *ieee)
2823 unsigned long flags;
2824 struct sk_buff *skb;
2825 struct ieee80211_hdr_3addr *header;
2827 spin_lock_irqsave(&ieee->lock,flags);
2828 if (! ieee->queue_stop) goto exit;
2830 ieee->queue_stop = 0;
2832 if(ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE){
2833 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))){
2835 header = (struct ieee80211_hdr_3addr *) skb->data;
2837 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2839 if (ieee->seq_ctrl[0] == 0xFFF)
2840 ieee->seq_ctrl[0] = 0;
2842 ieee->seq_ctrl[0]++;
2844 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2845 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
2846 dev_kfree_skb_any(skb);//edit by thomas
2849 if (!ieee->queue_stop && ieee->tx_pending.txb)
2850 ieee80211_resume_tx(ieee);
2852 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)){
2853 ieee->softmac_stats.swtxawake++;
2854 netif_wake_queue(ieee->dev);
2858 spin_unlock_irqrestore(&ieee->lock,flags);
2862 void ieee80211_stop_queue(struct ieee80211_device *ieee)
2864 //unsigned long flags;
2865 //spin_lock_irqsave(&ieee->lock,flags);
2867 if (! netif_queue_stopped(ieee->dev)){
2868 netif_stop_queue(ieee->dev);
2869 ieee->softmac_stats.swtxstop++;
2871 ieee->queue_stop = 1;
2872 //spin_unlock_irqrestore(&ieee->lock,flags);
2877 inline void ieee80211_randomize_cell(struct ieee80211_device *ieee)
2880 get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2882 /* an IBSS cell address must have the two less significant
2883 * bits of the first byte = 2
2885 ieee->current_network.bssid[0] &= ~0x01;
2886 ieee->current_network.bssid[0] |= 0x02;
2889 /* called in user context only */
2890 void ieee80211_start_master_bss(struct ieee80211_device *ieee)
2894 if (ieee->current_network.ssid_len == 0){
2895 strncpy(ieee->current_network.ssid,
2896 IEEE80211_DEFAULT_TX_ESSID,
2899 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2903 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2905 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2906 ieee->state = IEEE80211_LINKED;
2907 ieee->link_change(ieee->dev);
2908 notify_wx_assoc_event(ieee);
2910 if (ieee->data_hard_resume)
2911 ieee->data_hard_resume(ieee->dev);
2913 netif_carrier_on(ieee->dev);
2916 void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
2920 if (ieee->data_hard_resume)
2921 ieee->data_hard_resume(ieee->dev);
2923 netif_carrier_on(ieee->dev);
2927 void ieee80211_start_ibss_wq(struct work_struct *work)
2929 struct delayed_work *dwork = to_delayed_work(work);
2930 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
2932 /* iwconfig mode ad-hoc will schedule this and return
2933 * on the other hand this will block further iwconfig SET
2934 * operations because of the wx_sem hold.
2935 * Anyway some most set operations set a flag to speed-up
2936 * (abort) this wq (when syncro scanning) before sleeping
2940 down(&ieee->wx_sem);
2943 if (ieee->current_network.ssid_len == 0){
2944 strcpy(ieee->current_network.ssid,IEEE80211_DEFAULT_TX_ESSID);
2945 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2949 /* check if we have this cell in our network list */
2950 ieee80211_softmac_check_all_nets(ieee);
2952 #ifdef ENABLE_DOT11D
2953 if(ieee->state == IEEE80211_NOLINK)
2954 ieee->current_network.channel = 10;
2956 /* if not then the state is not linked. Maybe the user swithced to
2957 * ad-hoc mode just after being in monitor mode, or just after
2958 * being very few time in managed mode (so the card have had no
2959 * time to scan all the chans..) or we have just run up the iface
2960 * after setting ad-hoc mode. So we have to give another try..
2961 * Here, in ibss mode, should be safe to do this without extra care
2962 * (in bss mode we had to make sure no-one tryed to associate when
2963 * we had just checked the ieee->state and we was going to start the
2964 * scan) beacause in ibss mode the ieee80211_new_net function, when
2965 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2966 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2967 * scan, that will stop at the first round because it sees the state
2970 if (ieee->state == IEEE80211_NOLINK)
2971 ieee80211_start_scan_syncro(ieee);
2973 /* the network definitively is not here.. create a new cell */
2974 if (ieee->state == IEEE80211_NOLINK){
2975 printk("creating new IBSS cell\n");
2977 ieee80211_randomize_cell(ieee);
2979 if(ieee->modulation & IEEE80211_CCK_MODULATION){
2981 ieee->current_network.rates_len = 4;
2983 ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
2984 ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
2985 ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
2986 ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
2989 ieee->current_network.rates_len = 0;
2991 if(ieee->modulation & IEEE80211_OFDM_MODULATION){
2992 ieee->current_network.rates_ex_len = 8;
2994 ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
2995 ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
2996 ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
2997 ieee->current_network.rates_ex[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
2998 ieee->current_network.rates_ex[4] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
2999 ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
3000 ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
3001 ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
3005 ieee->current_network.rates_ex_len = 0;
3009 // By default, WMM function will be disabled in IBSS mode
3010 ieee->current_network.QoS_Enable = 0;
3012 ieee->current_network.atim_window = 0;
3013 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
3014 if(ieee->short_slot)
3015 ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT;
3019 ieee->state = IEEE80211_LINKED;
3020 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3021 ieee->link_change(ieee->dev);
3023 notify_wx_assoc_event(ieee);
3025 ieee80211_start_send_beacons(ieee);
3026 printk(KERN_WARNING "after sending beacon packet!\n");
3028 if (ieee->data_hard_resume)
3029 ieee->data_hard_resume(ieee->dev);
3031 netif_carrier_on(ieee->dev);
3035 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
3037 queue_delayed_work(ieee->wq, &ieee->start_ibss_wq, 100);
3040 /* this is called only in user context, with wx_sem held */
3041 void ieee80211_start_bss(struct ieee80211_device *ieee)
3043 unsigned long flags;
3044 #ifdef ENABLE_DOT11D
3046 // Ref: 802.11d 11.1.3.3
3047 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
3049 if(IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee))
3051 if(! ieee->bGlobalDomain)
3057 /* check if we have already found the net we
3058 * are interested in (if any).
3059 * if not (we are disassociated and we are not
3060 * in associating / authenticating phase) start the background scanning.
3062 ieee80211_softmac_check_all_nets(ieee);
3064 /* ensure no-one start an associating process (thus setting
3065 * the ieee->state to ieee80211_ASSOCIATING) while we
3066 * have just cheked it and we are going to enable scan.
3067 * The ieee80211_new_net function is always called with
3068 * lock held (from both ieee80211_softmac_check_all_nets and
3069 * the rx path), so we cannot be in the middle of such function
3071 spin_lock_irqsave(&ieee->lock, flags);
3074 // printk("start bss ENABLE_IPS\n");
3076 if (ieee->state == IEEE80211_NOLINK){
3077 ieee->actscanning = true;
3078 ieee80211_start_scan(ieee);
3081 spin_unlock_irqrestore(&ieee->lock, flags);
3084 /* called only in userspace context */
3085 void ieee80211_disassociate(struct ieee80211_device *ieee)
3087 netif_carrier_off(ieee->dev);
3089 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
3090 ieee80211_reset_queue(ieee);
3092 if (ieee->data_hard_stop)
3093 ieee->data_hard_stop(ieee->dev);
3095 #ifdef ENABLE_DOT11D
3096 if(IS_DOT11D_ENABLE(ieee))
3099 ieee->state = IEEE80211_NOLINK;
3100 ieee->link_change(ieee->dev);
3101 notify_wx_assoc_event(ieee);
3104 void ieee80211_associate_retry_wq(struct work_struct *work)
3106 struct delayed_work *dwork = to_delayed_work(work);
3107 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
3108 unsigned long flags;
3109 down(&ieee->wx_sem);
3110 if(!ieee->proto_started)
3112 if(ieee->state != IEEE80211_ASSOCIATING_RETRY)
3114 /* until we do not set the state to IEEE80211_NOLINK
3115 * there are no possibility to have someone else trying
3116 * to start an association procdure (we get here with
3117 * ieee->state = IEEE80211_ASSOCIATING).
3118 * When we set the state to IEEE80211_NOLINK it is possible
3119 * that the RX path run an attempt to associate, but
3120 * both ieee80211_softmac_check_all_nets and the
3121 * RX path works with ieee->lock held so there are no
3122 * problems. If we are still disassociated then start a scan.
3123 * the lock here is necessary to ensure no one try to start
3124 * an association procedure when we have just checked the
3125 * state and we are going to start the scan.
3127 ieee->state = IEEE80211_NOLINK;
3128 ieee->beinretry = true;
3129 ieee80211_softmac_check_all_nets(ieee);
3131 spin_lock_irqsave(&ieee->lock, flags);
3133 if(ieee->state == IEEE80211_NOLINK){
3134 ieee->beinretry = false;
3135 ieee->actscanning = true;
3136 ieee80211_start_scan(ieee);
3138 //YJ,add,080828, notify os here
3139 if(ieee->state == IEEE80211_NOLINK)
3141 notify_wx_assoc_event(ieee);
3144 spin_unlock_irqrestore(&ieee->lock, flags);
3150 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
3152 u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
3154 struct sk_buff *skb = NULL;
3155 struct ieee80211_probe_response *b;
3158 #ifdef _RTL8187_EXT_PATCH_
3159 if((ieee->iw_mode == ieee->iw_ext_mode) && ieee->ext_patch_get_beacon_get_probersp )
3160 skb = ieee->ext_patch_get_beacon_get_probersp(ieee, broadcast_addr, &(ieee->current_network));
3162 skb = ieee80211_probe_resp(ieee, broadcast_addr);
3164 skb = ieee80211_probe_resp(ieee, broadcast_addr);
3170 b = (struct ieee80211_probe_response *) skb->data;
3171 b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON);
3177 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee)
3179 struct sk_buff *skb;
3180 struct ieee80211_probe_response *b;
3182 skb = ieee80211_get_beacon_(ieee);
3186 b = (struct ieee80211_probe_response *) skb->data;
3187 b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
3189 if (ieee->seq_ctrl[0] == 0xFFF)
3190 ieee->seq_ctrl[0] = 0;
3192 ieee->seq_ctrl[0]++;
3197 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
3199 ieee->sync_scan_hurryup = 1;
3200 down(&ieee->wx_sem);
3201 ieee80211_stop_protocol(ieee);
3206 void ieee80211_stop_protocol(struct ieee80211_device *ieee)
3208 if (!ieee->proto_started)
3211 ieee->proto_started = 0;
3213 #ifdef _RTL8187_EXT_PATCH_
3214 if(ieee->ext_patch_ieee80211_stop_protocol)
3215 ieee->ext_patch_ieee80211_stop_protocol(ieee);
3216 //if call queue_delayed_work,can call this,or do nothing..
3217 //edit by lawrence,20071118
3218 // cancel_delayed_work(&ieee->ext_stop_scan_wq);
3219 // cancel_delayed_work(&ieee->ext_send_beacon_wq);
3220 #endif // _RTL8187_EXT_PATCH_
3222 ieee80211_stop_send_beacons(ieee);
3223 if((ieee->iw_mode == IW_MODE_INFRA)&&(ieee->state == IEEE80211_LINKED)) {
3224 SendDisassociation(ieee,NULL,WLAN_REASON_DISASSOC_STA_HAS_LEFT);
3226 del_timer_sync(&ieee->associate_timer);
3227 cancel_delayed_work(&ieee->associate_retry_wq);
3228 cancel_delayed_work(&ieee->start_ibss_wq);
3229 ieee80211_stop_scan(ieee);
3231 ieee80211_disassociate(ieee);
3234 void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee)
3236 ieee->sync_scan_hurryup = 0;
3237 down(&ieee->wx_sem);
3238 ieee80211_start_protocol(ieee);
3242 void ieee80211_start_protocol(struct ieee80211_device *ieee)
3247 if (ieee->proto_started)
3250 ieee->proto_started = 1;
3252 if (ieee->current_network.channel == 0){
3255 if (ch > MAX_CHANNEL_NUMBER)
3256 return; /* no channel found */
3258 #ifdef ENABLE_DOT11D
3259 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]);
3261 }while(!ieee->channel_map[ch]);
3264 ieee->current_network.channel = ch;
3267 if (ieee->current_network.beacon_interval == 0)
3268 ieee->current_network.beacon_interval = 100;
3269 ieee->set_chan(ieee->dev,ieee->current_network.channel);
3271 for(i = 0; i < 17; i++) {
3272 ieee->last_rxseq_num[i] = -1;
3273 ieee->last_rxfrag_num[i] = -1;
3274 ieee->last_packet_time[i] = 0;
3277 ieee->init_wmmparam_flag = 0;//reinitialize AC_xx_PARAM registers.
3280 /* if the user set the MAC of the ad-hoc cell and then
3281 * switch to managed mode, shall we make sure that association
3282 * attempts does not fail just because the user provide the essid
3283 * and the nic is still checking for the AP MAC ??
3285 switch (ieee->iw_mode) {
3287 ieee->iw_mode = IW_MODE_INFRA;
3288 //not set break here intentionly
3290 ieee80211_start_bss(ieee);
3294 ieee80211_start_ibss(ieee);
3297 case IW_MODE_MASTER:
3298 ieee80211_start_master_bss(ieee);
3301 case IW_MODE_MONITOR:
3302 ieee80211_start_monitor_mode(ieee);
3306 #ifdef _RTL8187_EXT_PATCH_
3307 if((ieee->iw_mode == ieee->iw_ext_mode) &&\
3308 ieee->ext_patch_ieee80211_start_protocol &&\
3309 ieee->ext_patch_ieee80211_start_protocol(ieee)) {
3310 queue_work(ieee->wq, &ieee->ext_stop_scan_wq);
3312 // By default, WMM function will be disabled in
3314 ieee->current_network.QoS_Enable = 0;
3316 if(ieee->modulation & IEEE80211_CCK_MODULATION){
3317 ieee->current_network.rates_len = 4;
3318 ieee->current_network.rates[0] = \
3319 IEEE80211_BASIC_RATE_MASK | \
3320 IEEE80211_CCK_RATE_1MB;
3321 ieee->current_network.rates[1] = \
3322 IEEE80211_BASIC_RATE_MASK |\
3323 IEEE80211_CCK_RATE_2MB;
3324 ieee->current_network.rates[2] = \
3325 IEEE80211_BASIC_RATE_MASK |\
3326 IEEE80211_CCK_RATE_5MB;
3327 ieee->current_network.rates[3] = \
3328 IEEE80211_BASIC_RATE_MASK |\
3329 IEEE80211_CCK_RATE_11MB;
3331 ieee->current_network.rates_len = 0;
3333 if(ieee->modulation & IEEE80211_OFDM_MODULATION){
3334 ieee->current_network.rates_ex_len = 8;
3335 ieee->current_network.rates_ex[0] = \
3336 IEEE80211_BASIC_RATE_MASK |\
3337 IEEE80211_OFDM_RATE_6MB;
3338 ieee->current_network.rates_ex[1] = \
3339 IEEE80211_BASIC_RATE_MASK |\
3340 IEEE80211_OFDM_RATE_9MB;
3341 ieee->current_network.rates_ex[2] = \
3342 IEEE80211_BASIC_RATE_MASK |\
3343 IEEE80211_OFDM_RATE_12MB;
3344 ieee->current_network.rates_ex[3] = \
3345 IEEE80211_BASIC_RATE_MASK | \
3346 IEEE80211_OFDM_RATE_18MB;
3347 ieee->current_network.rates_ex[4] =\
3348 IEEE80211_BASIC_RATE_MASK |\
3349 IEEE80211_OFDM_RATE_24MB;
3350 ieee->current_network.rates_ex[5] =\
3351 IEEE80211_BASIC_RATE_MASK |\
3352 IEEE80211_OFDM_RATE_36MB;
3353 ieee->current_network.rates_ex[6] = \
3354 IEEE80211_BASIC_RATE_MASK |\
3355 IEEE80211_OFDM_RATE_48MB;
3356 ieee->current_network.rates_ex[7] =\
3357 IEEE80211_BASIC_RATE_MASK |\
3358 IEEE80211_OFDM_RATE_54MB;
3361 ieee->current_network.rates_ex_len = 0;
3366 spin_lock_irqsave(&ieee->lock, flags);
3367 if (ieee->state == IEEE80211_NOLINK)
3368 ieee80211_start_scan(ieee);
3369 // ieee->set_chan(ieee->dev, 8);
3371 spin_unlock_irqrestore(&ieee->lock, flags);
3373 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr,\
3375 ieee->link_change(ieee->dev);
3376 notify_wx_assoc_event(ieee);
3378 if (ieee->data_hard_resume)
3379 ieee->data_hard_resume(ieee->dev);
3381 netif_carrier_on(ieee->dev);
3383 ieee->iw_mode = IW_MODE_INFRA;
3384 ieee80211_start_bss(ieee);
3387 ieee->iw_mode = IW_MODE_INFRA;
3388 ieee80211_start_bss(ieee);
3396 #define DRV_NAME "Ieee80211"
3397 void ieee80211_softmac_init(struct ieee80211_device *ieee)
3400 memset(&ieee->current_network, 0, sizeof(struct ieee80211_network));
3402 ieee->state = IEEE80211_NOLINK;
3403 ieee->sync_scan_hurryup = 0;
3404 for(i = 0; i < 5; i++) {
3405 ieee->seq_ctrl[i] = 0;
3409 ieee->queue_stop = 0;
3411 ieee->softmac_features = 0; //so IEEE2100-like driver are happy
3414 ieee->proto_started = 0;
3415 ieee->basic_rate = IEEE80211_DEFAULT_BASIC_RATE;
3418 ieee->ps = IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST;
3420 // ieee->ps = IEEE80211_PS_DISABLED;
3422 ieee->sta_sleep = 0;
3424 ieee->bInactivePs = false;
3425 ieee->actscanning = false;
3426 ieee->ListenInterval = 2;
3427 ieee->NumRxDataInPeriod = 0; //YJ,add,080828
3428 ieee->NumRxBcnInPeriod = 0; //YJ,add,080828
3429 ieee->NumRxOkTotal = 0;//+by amy 080312
3430 ieee->NumRxUnicast = 0;//YJ,add,080828,for keep alive
3431 ieee->beinretry = false;
3432 ieee->bHwRadioOff = false;
3434 #ifdef _RTL8187_EXT_PATCH_
3435 ieee->iw_ext_mode = 999;
3438 init_mgmt_queue(ieee);
3440 init_timer(&ieee->scan_timer);
3441 ieee->scan_timer.data = (unsigned long)ieee;
3442 ieee->scan_timer.function = ieee80211_softmac_scan_cb;
3444 ieee->tx_pending.txb = NULL;
3446 init_timer(&ieee->associate_timer);
3447 ieee->associate_timer.data = (unsigned long)ieee;
3448 ieee->associate_timer.function = ieee80211_associate_abort_cb;
3450 init_timer(&ieee->beacon_timer);
3451 ieee->beacon_timer.data = (unsigned long) ieee;
3452 ieee->beacon_timer.function = ieee80211_send_beacon_cb;
3454 #ifdef PF_SYNCTHREAD
3455 ieee->wq = create_workqueue(DRV_NAME,0);
3457 ieee->wq = create_workqueue(DRV_NAME);
3459 INIT_DELAYED_WORK(&ieee->start_ibss_wq,(void*) ieee80211_start_ibss_wq);
3460 INIT_WORK(&ieee->associate_complete_wq,(void*) ieee80211_associate_complete_wq);
3461 INIT_WORK(&ieee->associate_procedure_wq,(void*) ieee80211_associate_procedure_wq);
3462 INIT_DELAYED_WORK(&ieee->softmac_scan_wq,(void*) ieee80211_softmac_scan_wq);
3463 INIT_DELAYED_WORK(&ieee->associate_retry_wq,(void*) ieee80211_associate_retry_wq);
3464 INIT_WORK(&ieee->wx_sync_scan_wq,(void*) ieee80211_wx_sync_scan_wq);
3465 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
3466 //added by lawrence,20071118
3467 #ifdef _RTL8187_EXT_PATCH_
3468 INIT_WORK(&ieee->ext_stop_scan_wq,(void*) ieee80211_ext_stop_scan_wq);
3469 //INIT_WORK(&ieee->ext_send_beacon_wq,(void*) ieee80211_beacons_start,ieee);
3470 INIT_WORK(&ieee->ext_send_beacon_wq,(void*) ext_ieee80211_send_beacon_wq);
3471 #endif //_RTL8187_EXT_PATCH_
3473 sema_init(&ieee->wx_sem, 1);
3474 sema_init(&ieee->scan_sem, 1);
3476 spin_lock_init(&ieee->mgmt_tx_lock);
3477 spin_lock_init(&ieee->beacon_lock);
3479 tasklet_init(&ieee->ps_task,
3480 (void(*)(unsigned long)) ieee80211_sta_ps,
3481 (unsigned long)ieee);
3482 #ifdef ENABLE_DOT11D
3483 ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
3487 void ieee80211_softmac_free(struct ieee80211_device *ieee)
3489 down(&ieee->wx_sem);
3491 del_timer_sync(&ieee->associate_timer);
3492 cancel_delayed_work(&ieee->associate_retry_wq);
3495 //add for RF power on power of by lizhaoming 080512
3496 cancel_delayed_work(&ieee->GPIOChangeRFWorkItem);
3498 #ifdef _RTL8187_EXT_PATCH_
3499 cancel_delayed_work(&ieee->ext_stop_scan_wq);
3500 cancel_delayed_work(&ieee->ext_send_beacon_wq);
3502 destroy_workqueue(ieee->wq);
3503 #ifdef ENABLE_DOT11D
3504 if(NULL != ieee->pDot11dInfo)
3505 kfree(ieee->pDot11dInfo);
3510 /********************************************************
3511 * Start of WPA code. *
3512 * this is stolen from the ipw2200 driver *
3513 ********************************************************/
3516 static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
3518 /* This is called when wpa_supplicant loads and closes the driver
3520 printk("%s WPA\n",value ? "enabling" : "disabling");
3521 ieee->wpa_enabled = value;
3526 void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, int wpa_ie_len)
3528 /* make sure WPA is enabled */
3529 ieee80211_wpa_enable(ieee, 1);
3531 ieee80211_disassociate(ieee);
3535 static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, int reason)
3541 case IEEE_MLME_STA_DEAUTH:
3545 case IEEE_MLME_STA_DISASSOC:
3546 ieee80211_disassociate(ieee);
3550 printk("Unknown MLME request: %d\n", command);
3558 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
3559 struct ieee_param *param, int plen)
3563 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3564 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3567 if (param->u.wpa_ie.len) {
3568 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
3572 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
3573 kfree(ieee->wpa_ie);
3575 ieee->wpa_ie_len = param->u.wpa_ie.len;
3577 kfree(ieee->wpa_ie);
3578 ieee->wpa_ie = NULL;
3579 ieee->wpa_ie_len = 0;
3582 ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3586 #define AUTH_ALG_OPEN_SYSTEM 0x1
3587 #define AUTH_ALG_SHARED_KEY 0x2
3589 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
3592 struct ieee80211_security sec = {
3593 .flags = SEC_AUTH_MODE,
3597 if (value & AUTH_ALG_SHARED_KEY) {
3598 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3601 sec.auth_mode = WLAN_AUTH_OPEN;
3605 if (ieee->set_security)
3606 ieee->set_security(ieee->dev, &sec);
3613 static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value)
3616 unsigned long flags;
3619 case IEEE_PARAM_WPA_ENABLED:
3620 ret = ieee80211_wpa_enable(ieee, value);
3623 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3624 ieee->tkip_countermeasures=value;
3627 case IEEE_PARAM_DROP_UNENCRYPTED: {
3630 * wpa_supplicant calls set_wpa_enabled when the driver
3631 * is loaded and unloaded, regardless of if WPA is being
3632 * used. No other calls are made which can be used to
3633 * determine if encryption will be used or not prior to
3634 * association being expected. If encryption is not being
3635 * used, drop_unencrypted is set to false, else true -- we
3636 * can use this to determine if the CAP_PRIVACY_ON bit should
3639 struct ieee80211_security sec = {
3640 .flags = SEC_ENABLED,
3643 ieee->drop_unencrypted = value;
3644 /* We only change SEC_LEVEL for open mode. Others
3645 * are set by ipw_wpa_set_encryption.
3648 sec.flags |= SEC_LEVEL;
3649 sec.level = SEC_LEVEL_0;
3652 sec.flags |= SEC_LEVEL;
3653 sec.level = SEC_LEVEL_1;
3655 if (ieee->set_security)
3656 ieee->set_security(ieee->dev, &sec);
3660 case IEEE_PARAM_PRIVACY_INVOKED:
3661 ieee->privacy_invoked=value;
3664 case IEEE_PARAM_AUTH_ALGS:
3665 ret = ieee80211_wpa_set_auth_algs(ieee, value);
3668 case IEEE_PARAM_IEEE_802_1X:
3669 ieee->ieee802_1x=value;
3671 case IEEE_PARAM_WPAX_SELECT:
3672 // added for WPA2 mixed mode
3673 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
3674 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
3675 ieee->wpax_type_set = 1;
3676 ieee->wpax_type_notify = value;
3677 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
3681 printk("Unknown WPA param: %d\n",name);
3688 /* implementation borrowed from hostap driver */
3690 static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
3691 struct ieee_param *param, int param_len)
3695 struct ieee80211_crypto_ops *ops;
3696 struct ieee80211_crypt_data **crypt;
3698 struct ieee80211_security sec = {
3702 param->u.crypt.err = 0;
3703 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3706 (int) ((char *) param->u.crypt.key - (char *) param) +
3707 param->u.crypt.key_len) {
3708 printk("Len mismatch %d, %d\n", param_len,
3709 param->u.crypt.key_len);
3712 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3713 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3714 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3715 if (param->u.crypt.idx >= WEP_KEYS)
3717 crypt = &ieee->crypt[param->u.crypt.idx];
3722 if (strcmp(param->u.crypt.alg, "none") == 0) {
3727 sec.level = SEC_LEVEL_0;
3728 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3729 ieee80211_crypt_delayed_deinit(ieee, crypt);
3736 sec.flags |= SEC_ENABLED;
3738 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3739 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3740 strcmp(param->u.crypt.alg, "TKIP"))
3741 goto skip_host_crypt;
3743 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3744 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3745 request_module("ieee80211_crypt_wep");
3746 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3747 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3748 request_module("ieee80211_crypt_tkip");
3749 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3750 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3751 request_module("ieee80211_crypt_ccmp");
3752 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3755 printk("unknown crypto alg '%s'\n", param->u.crypt.alg);
3756 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3761 if (*crypt == NULL || (*crypt)->ops != ops) {
3762 struct ieee80211_crypt_data *new_crypt;
3764 ieee80211_crypt_delayed_deinit(ieee, crypt);
3766 new_crypt = (struct ieee80211_crypt_data *)
3767 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
3768 if (new_crypt == NULL) {
3772 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3773 new_crypt->ops = ops;
3774 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
3776 new_crypt->ops->init(param->u.crypt.idx);
3778 if (new_crypt->priv == NULL) {
3780 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3788 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3789 (*crypt)->ops->set_key(param->u.crypt.key,
3790 param->u.crypt.key_len, param->u.crypt.seq,
3791 (*crypt)->priv) < 0) {
3792 printk("key setting failed\n");
3793 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3799 if (param->u.crypt.set_tx) {
3800 ieee->tx_keyidx = param->u.crypt.idx;
3801 sec.active_key = param->u.crypt.idx;
3802 sec.flags |= SEC_ACTIVE_KEY;
3804 sec.flags &= ~SEC_ACTIVE_KEY;
3806 if (param->u.crypt.alg != NULL) {
3807 memcpy(sec.keys[param->u.crypt.idx],
3809 param->u.crypt.key_len);
3810 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3811 sec.flags |= (1 << param->u.crypt.idx);
3813 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
3814 sec.flags |= SEC_LEVEL;
3815 sec.level = SEC_LEVEL_1;
3816 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
3817 sec.flags |= SEC_LEVEL;
3818 sec.level = SEC_LEVEL_2;
3819 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
3820 sec.flags |= SEC_LEVEL;
3821 sec.level = SEC_LEVEL_3;
3825 if (ieee->set_security)
3826 ieee->set_security(ieee->dev, &sec);
3828 /* Do not reset port if card is in Managed mode since resetting will
3829 * generate new IEEE 802.11 authentication which may end up in looping
3830 * with IEEE 802.1X. If your hardware requires a reset after WEP
3831 * configuration (for example... Prism2), implement the reset_port in
3832 * the callbacks structures used to initialize the 802.11 stack. */
3833 if (ieee->reset_on_keychange &&
3834 ieee->iw_mode != IW_MODE_INFRA &&
3836 ieee->reset_port(ieee->dev)) {
3837 printk("reset_port failed\n");
3838 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3845 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p)
3847 struct ieee_param *param;
3850 down(&ieee->wx_sem);
3851 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
3853 if (p->length < sizeof(struct ieee_param) || !p->pointer){
3858 param = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
3863 if (copy_from_user(param, p->pointer, p->length)) {
3869 switch (param->cmd) {
3871 case IEEE_CMD_SET_WPA_PARAM:
3872 ret = ieee80211_wpa_set_param(ieee, param->u.wpa_param.name,
3873 param->u.wpa_param.value);
3876 case IEEE_CMD_SET_WPA_IE:
3877 ret = ieee80211_wpa_set_wpa_ie(ieee, param, p->length);
3880 case IEEE_CMD_SET_ENCRYPTION:
3881 ret = ieee80211_wpa_set_encryption(ieee, param, p->length);
3885 ret = ieee80211_wpa_mlme(ieee, param->u.mlme.command,
3886 param->u.mlme.reason_code);
3890 printk("Unknown WPA supplicant request: %d\n",param->cmd);
3895 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3905 void notify_wx_assoc_event(struct ieee80211_device *ieee)
3907 union iwreq_data wrqu;
3908 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3909 if (ieee->state == IEEE80211_LINKED)
3910 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN);
3912 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
3913 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3918 EXPORT_SYMBOL(ieee80211_get_beacon);
3919 EXPORT_SYMBOL(ieee80211_wake_queue);
3920 EXPORT_SYMBOL(ieee80211_stop_queue);
3921 EXPORT_SYMBOL(ieee80211_reset_queue);
3922 EXPORT_SYMBOL(ieee80211_softmac_stop_protocol);
3923 EXPORT_SYMBOL(ieee80211_softmac_start_protocol);
3924 EXPORT_SYMBOL(ieee80211_is_shortslot);
3925 EXPORT_SYMBOL(ieee80211_is_54g);
3926 EXPORT_SYMBOL(ieee80211_wpa_supplicant_ioctl);
3927 EXPORT_SYMBOL(ieee80211_ps_tx_ack);
3928 EXPORT_SYMBOL(ieee80211_start_protocol);
3929 EXPORT_SYMBOL(ieee80211_stop_protocol);
3930 EXPORT_SYMBOL(notify_wx_assoc_event);
3931 EXPORT_SYMBOL(ieee80211_stop_send_beacons);
3932 EXPORT_SYMBOL(SendDisassociation);
3933 EXPORT_SYMBOL(ieee80211_disassociate);
3934 EXPORT_SYMBOL(ieee80211_start_scan);
3935 EXPORT_SYMBOL(ieee80211_softmac_ips_scan_syncro);
3936 #ifdef _RTL8187_EXT_PATCH_
3937 EXPORT_SYMBOL(ieee80211_ext_issue_assoc_req);
3938 EXPORT_SYMBOL(ieee80211_ext_issue_disassoc);
3939 EXPORT_SYMBOL(ieee80211_ext_issue_assoc_rsp);
3940 EXPORT_SYMBOL(softmac_mgmt_xmit);
3941 EXPORT_SYMBOL(ieee80211_ext_probe_resp_by_net);
3942 EXPORT_SYMBOL(ieee80211_start_scan);
3943 EXPORT_SYMBOL(ieee80211_stop_scan);
3944 EXPORT_SYMBOL(ieee80211_ext_send_11s_beacon);
3945 EXPORT_SYMBOL(ieee80211_rx_auth_rq);
3946 EXPORT_SYMBOL(ieee80211_associate_step1);
3947 #endif // _RTL8187_EXT_PATCH_
3948 EXPORT_SYMBOL(ieee80211_sta_ps_send_null_frame);