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 len = ieee->current_network.ssid_len;
330 rate_len = ieee80211_MFIE_rate_len(ieee);
332 skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
337 req = (struct ieee80211_probe_request *) skb_put(skb,sizeof(struct ieee80211_probe_request));
338 req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
339 req->header.duration_id = 0; //FIXME: is this OK ?
341 memset(req->header.addr1, 0xff, ETH_ALEN);
342 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
343 memset(req->header.addr3, 0xff, ETH_ALEN);
345 tag = (u8 *) skb_put(skb,len+2+rate_len);
347 *tag++ = MFIE_TYPE_SSID;
349 memcpy(tag, ieee->current_network.ssid, len);
351 ieee80211_MFIE_Brate(ieee,&tag);
352 ieee80211_MFIE_Grate(ieee,&tag);
357 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee);
359 void ext_ieee80211_send_beacon_wq(struct ieee80211_device *ieee)
363 //unsigned long flags;
365 skb = ieee80211_get_beacon_(ieee);
368 softmac_mgmt_xmit(skb, ieee);
369 ieee->softmac_stats.tx_beacons++;
370 dev_kfree_skb_any(skb);//edit by thomas
374 //printk(KERN_WARNING "[1] beacon sending!\n");
375 ieee->beacon_timer.expires = jiffies +
376 (MSECS( ieee->current_network.beacon_interval -5));
378 //spin_lock_irqsave(&ieee->beacon_lock,flags);
379 if(ieee->beacon_txing)
380 add_timer(&ieee->beacon_timer);
381 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
384 void ieee80211_send_beacon(struct ieee80211_device *ieee)
388 //unsigned long flags;
390 skb = ieee80211_get_beacon_(ieee);
393 softmac_mgmt_xmit(skb, ieee);
394 ieee->softmac_stats.tx_beacons++;
395 dev_kfree_skb_any(skb);//edit by thomas
398 //printk(KERN_WARNING "[1] beacon sending!\n");
399 ieee->beacon_timer.expires = jiffies +
400 (MSECS( ieee->current_network.beacon_interval -5));
402 //spin_lock_irqsave(&ieee->beacon_lock,flags);
403 if(ieee->beacon_txing)
404 add_timer(&ieee->beacon_timer);
405 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
409 void ieee80211_send_beacon_cb(unsigned long _ieee)
411 struct ieee80211_device *ieee =
412 (struct ieee80211_device *) _ieee;
415 spin_lock_irqsave(&ieee->beacon_lock, flags);
416 ieee80211_send_beacon(ieee);
417 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
420 void ieee80211_send_probe(struct ieee80211_device *ieee)
424 skb = ieee80211_probe_req(ieee);
426 softmac_mgmt_xmit(skb, ieee);
427 ieee->softmac_stats.tx_probe_rq++;
428 //dev_kfree_skb_any(skb);//edit by thomas
432 void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
434 if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)){
435 ieee80211_send_probe(ieee);
436 ieee80211_send_probe(ieee);
440 /* this performs syncro scan blocking the caller until all channels
441 * in the allowed channel map has been checked.
443 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
447 u8 channel_map[MAX_CHANNEL_NUMBER+1];
448 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
450 down(&ieee->scan_sem);
451 // printk("==================> Sync scan\n");
458 if (ch > MAX_CHANNEL_NUMBER)
459 goto out; /* scan completed */
462 }while(!channel_map[ch]);
464 }while(!ieee->channel_map[ch]);
466 /* this fuction can be called in two situations
467 * 1- We have switched to ad-hoc mode and we are
468 * performing a complete syncro scan before conclude
469 * there are no interesting cell and to create a
470 * new one. In this case the link state is
471 * IEEE80211_NOLINK until we found an interesting cell.
472 * If so the ieee8021_new_net, called by the RX path
473 * will set the state to IEEE80211_LINKED, so we stop
475 * 2- We are linked and the root uses run iwlist scan.
476 * So we switch to IEEE80211_LINKED_SCANNING to remember
477 * that we are still logically linked (not interested in
478 * new network events, despite for updating the net list,
479 * but we are temporarly 'unlinked' as the driver shall
480 * not filter RX frames and the channel is changing.
481 * So the only situation in witch are interested is to check
482 * if the state become LINKED because of the #1 situation
485 if (ieee->state == IEEE80211_LINKED)
488 ieee->set_chan(ieee->dev, ch);
489 // printk("=====>channel=%d ",ch);
491 if(channel_map[ch] == 1)
494 // printk("====send probe request\n");
495 ieee80211_send_probe_requests(ieee);
497 /* this prevent excessive time wait when we
498 * need to wait for a syncro scan to end..
500 if (ieee->sync_scan_hurryup)
504 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
508 ieee->sync_scan_hurryup = 0;
511 if(IS_DOT11D_ENABLE(ieee))
512 DOT11D_ScanComplete(ieee);
516 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee)
519 unsigned int watch_dog = 0;
521 u8 channel_map[MAX_CHANNEL_NUMBER+1];
522 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
524 down(&ieee->scan_sem);
525 ch = ieee->current_network.channel;
526 // if(ieee->sync_scan_hurryup)
529 // printk("stop scan sync\n");
532 // printk("=======hh===============>ips scan\n");
535 /* this fuction can be called in two situations
536 * 1- We have switched to ad-hoc mode and we are
537 * performing a complete syncro scan before conclude
538 * there are no interesting cell and to create a
539 * new one. In this case the link state is
540 * IEEE80211_NOLINK until we found an interesting cell.
541 * If so the ieee8021_new_net, called by the RX path
542 * will set the state to IEEE80211_LINKED, so we stop
544 * 2- We are linked and the root uses run iwlist scan.
545 * So we switch to IEEE80211_LINKED_SCANNING to remember
546 * that we are still logically linked (not interested in
547 * new network events, despite for updating the net list,
548 * but we are temporarly 'unlinked' as the driver shall
549 * not filter RX frames and the channel is changing.
550 * So the only situation in witch are interested is to check
551 * if the state become LINKED because of the #1 situation
553 if (ieee->state == IEEE80211_LINKED)
558 if(channel_map[ieee->current_network.channel] > 0)
561 ieee->set_chan(ieee->dev, ieee->current_network.channel);
562 // printk("======>channel=%d ",ieee->current_network.channel);
565 if(channel_map[ieee->current_network.channel] == 1)
568 // printk("====send probe request\n");
569 ieee80211_send_probe_requests(ieee);
571 /* this prevent excessive time wait when we
572 * need to wait for a syncro scan to end..
574 // if (ieee->sync_scan_hurryup)
577 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
580 if (watch_dog++ >= MAX_CHANNEL_NUMBER)
581 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
582 goto out; /* scan completed */
584 ieee->current_network.channel = (ieee->current_network.channel + 1)%MAX_CHANNEL_NUMBER;
586 }while(!channel_map[ieee->current_network.channel]);
588 }while(!ieee->channel_map[ieee->current_network.channel]);
592 //ieee->sync_scan_hurryup = 0;
593 //ieee->set_chan(ieee->dev, ch);
594 //ieee->current_network.channel = ch;
595 ieee->actscanning = false;
598 if(IS_DOT11D_ENABLE(ieee))
599 DOT11D_ScanComplete(ieee);
605 /* called both by wq with ieee->lock held */
606 void ieee80211_softmac_scan(struct ieee80211_device *ieee)
611 ieee->current_network.channel =
612 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
613 if (watchdog++ > MAX_CHANNEL_NUMBER)
614 return; /* no good chans */
616 }while(!ieee->channel_map[ieee->current_network.channel]);
619 schedule_work(&ieee->softmac_scan_wq);
623 void ieee80211_softmac_scan_wq(struct work_struct *work)
625 struct delayed_work *dwork = to_delayed_work(work);
626 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
627 static short watchdog = 0;
629 u8 channel_map[MAX_CHANNEL_NUMBER+1];
630 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
632 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
633 // printk("in %s\n",__func__);
634 down(&ieee->scan_sem);
637 ieee->current_network.channel =
638 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
639 if (watchdog++ > MAX_CHANNEL_NUMBER)
640 goto out; /* no good chans */
643 }while(!channel_map[ieee->current_network.channel]);
645 }while(!ieee->channel_map[ieee->current_network.channel]);
648 //printk("current_network.channel:%d\n", ieee->current_network.channel);
649 if (ieee->scanning == 0 )
651 printk("error out, scanning = 0\n");
654 ieee->set_chan(ieee->dev, ieee->current_network.channel);
656 if(channel_map[ieee->current_network.channel] == 1)
658 ieee80211_send_probe_requests(ieee);
660 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
664 ieee->actscanning = false;
670 if(IS_DOT11D_ENABLE(ieee))
671 DOT11D_ScanComplete(ieee);
676 void ieee80211_softmac_scan_wq(struct work_struct *work)
678 struct delayed_work *dwork = to_delayed_work(work);
679 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, softmac_scan_wq);
682 u8 channel_map[MAX_CHANNEL_NUMBER+1];
683 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
685 // printk("enter scan wq,watchdog is %d\n",watchdog);
686 down(&ieee->scan_sem);
689 ieee->current_network.channel =
690 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
691 if (watchdog++ > MAX_CHANNEL_NUMBER)
692 goto out; /* no good chans */
695 }while(!channel_map[ieee->current_network.channel]);
697 }while(!ieee->channel_map[ieee->current_network.channel]);
700 // printk("current_network.channel:%d\n", ieee->current_network.channel);
701 if (ieee->scanning == 0 )
703 printk("error out, scanning = 0\n");
706 ieee->set_chan(ieee->dev, ieee->current_network.channel);
708 if(channel_map[ieee->current_network.channel] == 1)
710 ieee80211_send_probe_requests(ieee);
712 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
716 if(IS_DOT11D_ENABLE(ieee))
717 DOT11D_ScanComplete(ieee);
723 void ieee80211_beacons_start(struct ieee80211_device *ieee)
727 spin_lock_irqsave(&ieee->beacon_lock,flags);
729 ieee->beacon_txing = 1;
730 ieee80211_send_beacon(ieee);
732 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
735 void ieee80211_beacons_stop(struct ieee80211_device *ieee)
739 spin_lock_irqsave(&ieee->beacon_lock,flags);
741 ieee->beacon_txing = 0;
742 del_timer_sync(&ieee->beacon_timer);
744 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
749 void ieee80211_stop_send_beacons(struct ieee80211_device *ieee)
751 if(ieee->stop_send_beacons)
752 ieee->stop_send_beacons(ieee->dev);
753 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
754 ieee80211_beacons_stop(ieee);
758 void ieee80211_start_send_beacons(struct ieee80211_device *ieee)
760 if(ieee->start_send_beacons)
761 ieee->start_send_beacons(ieee->dev);
762 if(ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
763 ieee80211_beacons_start(ieee);
767 void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
769 // unsigned long flags;
771 //ieee->sync_scan_hurryup = 1;
773 down(&ieee->scan_sem);
774 // spin_lock_irqsave(&ieee->lock, flags);
776 if (ieee->scanning == 1){
778 //del_timer_sync(&ieee->scan_timer);
779 cancel_delayed_work(&ieee->softmac_scan_wq);
782 // spin_unlock_irqrestore(&ieee->lock, flags);
786 void ieee80211_stop_scan(struct ieee80211_device *ieee)
788 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
789 ieee80211_softmac_stop_scan(ieee);
791 ieee->stop_scan(ieee->dev);
794 /* called with ieee->lock held */
795 void ieee80211_start_scan(struct ieee80211_device *ieee)
798 if(IS_DOT11D_ENABLE(ieee) )
800 if(IS_COUNTRY_IE_VALID(ieee))
802 RESET_CIE_WATCHDOG(ieee);
806 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
807 if (ieee->scanning == 0)
810 //ieee80211_softmac_scan(ieee);
811 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
812 //care this,1203,2007,by lawrence
814 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq,0);
818 ieee->start_scan(ieee->dev);
822 /* called with wx_sem held */
823 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
826 if(IS_DOT11D_ENABLE(ieee) )
828 if(IS_COUNTRY_IE_VALID(ieee))
830 RESET_CIE_WATCHDOG(ieee);
834 ieee->sync_scan_hurryup = 0;
836 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
837 ieee80211_softmac_scan_syncro(ieee);
839 ieee->scan_syncro(ieee->dev);
843 inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
844 struct ieee80211_device *ieee, int challengelen)
847 struct ieee80211_authentication *auth;
849 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
851 if (!skb) return NULL;
853 auth = (struct ieee80211_authentication *)
854 skb_put(skb, sizeof(struct ieee80211_authentication));
856 auth->header.frame_ctl = IEEE80211_STYPE_AUTH;
857 if (challengelen) auth->header.frame_ctl |= IEEE80211_FCTL_WEP;
859 auth->header.duration_id = 0x013a; //FIXME
861 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
862 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
863 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
865 auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
867 auth->transaction = cpu_to_le16(ieee->associate_seq);
868 ieee->associate_seq++;
870 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
876 static struct sk_buff* ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *dest)
880 struct ieee80211_probe_response *beacon_buf;
883 int atim_len,erp_len;
884 struct ieee80211_crypt_data* crypt;
886 char *ssid = ieee->current_network.ssid;
887 int ssid_len = ieee->current_network.ssid_len;
888 int rate_len = ieee->current_network.rates_len+2;
889 int rate_ex_len = ieee->current_network.rates_ex_len;
890 int wpa_ie_len = ieee->wpa_ie_len;
891 if(rate_ex_len > 0) rate_ex_len+=2;
893 if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
898 if(ieee80211_is_54g(ieee->current_network))
903 beacon_size = sizeof(struct ieee80211_probe_response)+
912 skb = dev_alloc_skb(beacon_size);
917 beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
919 memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
920 memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
921 memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
923 beacon_buf->header.duration_id = 0; //FIXME
924 beacon_buf->beacon_interval =
925 cpu_to_le16(ieee->current_network.beacon_interval);
926 beacon_buf->capability =
927 cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
929 if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
930 cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
932 crypt = ieee->crypt[ieee->tx_keyidx];
934 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
935 ((0 == strcmp(crypt->ops->name, "WEP")) || wpa_ie_len);
938 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
941 beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
943 beacon_buf->info_element.id = MFIE_TYPE_SSID;
944 beacon_buf->info_element.len = ssid_len;
946 tag = (u8*) beacon_buf->info_element.data;
948 memcpy(tag, ssid, ssid_len);
952 *(tag++) = MFIE_TYPE_RATES;
953 *(tag++) = rate_len-2;
954 memcpy(tag,ieee->current_network.rates,rate_len-2);
957 *(tag++) = MFIE_TYPE_DS_SET;
959 *(tag++) = ieee->current_network.channel;
962 *(tag++) = MFIE_TYPE_IBSS_SET;
964 *((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window);
969 *(tag++) = MFIE_TYPE_ERP;
975 *(tag++) = MFIE_TYPE_RATES_EX;
976 *(tag++) = rate_ex_len-2;
977 memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
983 if (ieee->iw_mode == IW_MODE_ADHOC)
984 {//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
985 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
988 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
991 skb->dev = ieee->dev;
995 struct sk_buff* ieee80211_assoc_resp(struct ieee80211_device *ieee, u8 *dest)
1000 struct ieee80211_crypt_data* crypt;
1001 struct ieee80211_assoc_response_frame *assoc;
1004 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1005 int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
1007 skb = dev_alloc_skb(len);
1012 assoc = (struct ieee80211_assoc_response_frame *)
1013 skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
1015 assoc->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP);
1016 memcpy(assoc->header.addr1, dest,ETH_ALEN);
1017 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1018 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1019 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1020 WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
1023 if(ieee->short_slot)
1024 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1026 if (ieee->host_encrypt)
1027 crypt = ieee->crypt[ieee->tx_keyidx];
1030 encrypt = ( crypt && crypt->ops);
1033 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1036 assoc->aid = cpu_to_le16(ieee->assoc_id);
1037 if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
1038 else ieee->assoc_id++;
1040 tag = (u8*) skb_put(skb, rate_len);
1042 ieee80211_MFIE_Brate(ieee, &tag);
1043 ieee80211_MFIE_Grate(ieee, &tag);
1048 struct sk_buff* ieee80211_auth_resp(struct ieee80211_device *ieee,int status, u8 *dest)
1050 struct sk_buff *skb;
1051 struct ieee80211_authentication *auth;
1053 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
1058 skb->len = sizeof(struct ieee80211_authentication);
1060 auth = (struct ieee80211_authentication *)skb->data;
1062 auth->status = cpu_to_le16(status);
1063 auth->transaction = cpu_to_le16(2);
1064 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1066 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1067 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1068 memcpy(auth->header.addr1, dest, ETH_ALEN);
1069 auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
1075 struct sk_buff* ieee80211_null_func(struct ieee80211_device *ieee,short pwr)
1077 struct sk_buff *skb;
1078 struct ieee80211_hdr_3addr* hdr;
1080 skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
1085 hdr = (struct ieee80211_hdr_3addr*)skb_put(skb,sizeof(struct ieee80211_hdr_3addr));
1087 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1088 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1089 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1091 hdr->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
1092 IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
1093 (pwr ? IEEE80211_FCTL_PM:0));
1101 void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8* dest)
1103 struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest);
1106 softmac_mgmt_xmit(buf, ieee);
1107 dev_kfree_skb_any(buf);//edit by thomas
1112 void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8* dest)
1114 struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest);
1117 softmac_mgmt_xmit(buf, ieee);
1118 dev_kfree_skb_any(buf);//edit by thomas
1123 void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest)
1126 struct sk_buff *buf = ieee80211_probe_resp(ieee, dest);
1129 softmac_mgmt_xmit(buf, ieee);
1130 dev_kfree_skb_any(buf);//edit by thomas
1135 inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beacon,struct ieee80211_device *ieee)
1137 struct sk_buff *skb;
1138 //unsigned long flags;
1140 struct ieee80211_assoc_request_frame *hdr;
1142 //short info_addr = 0;
1144 //u16 suite_count = 0;
1145 //u8 suit_select = 0;
1146 unsigned int wpa_len = beacon->wpa_ie_len;
1147 //struct net_device *dev = ieee->dev;
1148 //union iwreq_data wrqu;
1152 // for testing purpose
1153 unsigned int rsn_len = beacon->rsn_ie_len;
1155 unsigned int rsn_len = beacon->rsn_ie_len - 4;
1157 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1158 unsigned int wmm_info_len = beacon->QoS_Enable?9:0;
1160 unsigned int turbo_info_len = beacon->Turbo_Enable?9:0;
1163 u8 encry_proto = ieee->wpax_type_notify & 0xff;
1164 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1165 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1169 //[0] Notify type of encryption: WPA/WPA2
1170 //[1] pair wise type
1172 if(ieee->wpax_type_set) {
1173 if (IEEE_PROTO_WPA == encry_proto) {
1175 } else if (IEEE_PROTO_RSN == encry_proto) {
1180 len = sizeof(struct ieee80211_assoc_request_frame)+
1181 + beacon->ssid_len//essid tagged val
1182 + rate_len//rates tagged val
1188 len = sizeof(struct ieee80211_assoc_request_frame)+
1189 + beacon->ssid_len//essid tagged val
1190 + rate_len//rates tagged val
1196 skb = dev_alloc_skb(len);
1201 hdr = (struct ieee80211_assoc_request_frame *)
1202 skb_put(skb, sizeof(struct ieee80211_assoc_request_frame));
1205 hdr->header.frame_ctl = IEEE80211_STYPE_ASSOC_REQ;
1206 hdr->header.duration_id= 37; //FIXME
1207 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1208 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1209 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1210 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);//for HW security, John
1212 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS);
1213 if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1214 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1215 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1216 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1218 if(ieee->short_slot)
1219 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1221 hdr->listen_interval = 0xa; //FIXME
1223 hdr->info_element.id = MFIE_TYPE_SSID;
1225 hdr->info_element.len = beacon->ssid_len;
1226 tag = skb_put(skb, beacon->ssid_len);
1227 memcpy(tag, beacon->ssid, beacon->ssid_len);
1229 tag = skb_put(skb, rate_len);
1231 ieee80211_MFIE_Brate(ieee, &tag);
1232 ieee80211_MFIE_Grate(ieee, &tag);
1234 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1235 //choose AES encryption as default algorithm while using mixed mode
1239 tag = skb_put(skb,wpa_len);
1244 //{add by david. 2006.8.31
1245 //fix linksys compatibility bug
1247 if(wpa_len > 24) {//22+2, mean include the capability
1248 beacon->wpa_ie[wpa_len - 2] = 0;
1250 //multicast cipher OUI
1251 if( beacon->wpa_ie[11]==0x2 ){ //0x0050f202 is the oui of tkip
1252 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1254 else if( beacon->wpa_ie[11]==0x4 ){//0x0050f204 is the oui of ccmp
1255 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1257 //unicast cipher OUI
1258 if( beacon->wpa_ie[14]==0
1259 && beacon->wpa_ie[15]==0x50
1260 && beacon->wpa_ie[16]==0xf2
1261 && beacon->wpa_ie[17]==0x2 ){ //0x0050f202 is the oui of tkip
1262 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1265 else if( beacon->wpa_ie[14]==0
1266 && beacon->wpa_ie[15]==0x50
1267 && beacon->wpa_ie[16]==0xf2
1268 && beacon->wpa_ie[17]==0x4 ){//0x0050f204 is the oui of ccmp
1269 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1271 //indicate the wpa_ie content to WPA_SUPPLICANT
1272 buff = kmalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
1273 memset(buff, 0, IW_CUSTOM_MAX);
1275 p += sprintf(p, "ASSOCINFO(ReqIEs=");
1276 for(i=0;i<wpa_len;i++){
1277 p += sprintf(p, "%02x", beacon->wpa_ie[i]);
1279 p += sprintf(p, ")");
1280 memset(&wrqu, 0, sizeof(wrqu) );
1281 wrqu.data.length = p - buff;
1283 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buff);
1284 memcpy(tag,beacon->wpa_ie,wpa_len);
1291 if( beacon->rsn_ie[4]==0x0 &&
1292 beacon->rsn_ie[5]==0xf &&
1293 beacon->rsn_ie[6]==0xac){
1295 switch(beacon->rsn_ie[7]){
1297 ieee->broadcast_key_type = KEY_TYPE_WEP40;
1300 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1303 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1306 ieee->broadcast_key_type = KEY_TYPE_WEP104;
1309 printk("fault suite type in RSN broadcast key\n");
1314 if( beacon->rsn_ie[10]==0x0 &&
1315 beacon->rsn_ie[11]==0xf &&
1316 beacon->rsn_ie[12]==0xac){
1317 if(beacon->rsn_ie[8]==1){//not mixed mode
1318 switch(beacon->rsn_ie[13]){
1320 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1323 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1326 printk("fault suite type in RSN pairwise key\n");
1330 else if(beacon->rsn_ie[8]==2){//mixed mode
1331 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1337 tag = skb_put(skb,22);
1338 memcpy(tag,(beacon->rsn_ie + info_addr),8);
1343 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
1344 for (i = 0; i < 2; i++) {
1348 suite_count = beacon->rsn_ie[info_addr] + \
1349 (beacon->rsn_ie[info_addr + 1] << 8);
1351 if(1 == suite_count) {
1352 memcpy(tag,(beacon->rsn_ie + info_addr),4);
1355 // if the wpax_type_notify has been set by the application,
1356 // just use it, otherwise just use the default one.
1357 if(ieee->wpax_type_set) {
1358 suit_select = ((0 == i) ? pairwise_type:authen_type)&0x0f ;
1359 memcpy(tag,rsn_authen_cipher_suite[suit_select],4);
1361 //default set as ccmp, or none authentication
1363 memcpy(tag,rsn_authen_cipher_suite[4],4);
1365 memcpy(tag,rsn_authen_cipher_suite[2],4);
1370 info_addr += (suite_count * 4);
1374 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
1377 tag[1] = beacon->rsn_ie[info_addr+1];
1380 tag = skb_put(skb,rsn_len);
1384 if( beacon->rsn_ie[4]==0x0 &&
1385 beacon->rsn_ie[5]==0xf &&
1386 beacon->rsn_ie[6]==0xac){
1387 switch(beacon->rsn_ie[7]){
1389 ieee->broadcast_key_type = KEY_TYPE_WEP40;
1392 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1395 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1398 ieee->broadcast_key_type = KEY_TYPE_WEP104;
1401 printk("fault suite type in RSN broadcast key\n");
1405 if( beacon->rsn_ie[10]==0x0 &&
1406 beacon->rsn_ie[11]==0xf &&
1407 beacon->rsn_ie[12]==0xac){
1408 if(beacon->rsn_ie[8]==1){//not mixed mode
1409 switch(beacon->rsn_ie[13]){
1411 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1414 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1417 printk("fault suite type in RSN pairwise key\n");
1422 else if(beacon->rsn_ie[8]==2){//mixed mode
1423 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1428 beacon->rsn_ie[rsn_len - 2] = 0;
1429 memcpy(tag,beacon->rsn_ie,rsn_len);
1433 tag = skb_put(skb,ieee->wpa_ie_len);
1434 memcpy(tag,ieee->wpa_ie,ieee->wpa_ie_len);
1436 tag = skb_put(skb,wmm_info_len);
1438 ieee80211_WMM_Info(ieee, &tag);
1441 tag = skb_put(skb,turbo_info_len);
1442 if(turbo_info_len) {
1443 ieee80211_TURBO_Info(ieee, &tag);
1450 void ieee80211_associate_abort(struct ieee80211_device *ieee)
1453 unsigned long flags;
1454 spin_lock_irqsave(&ieee->lock, flags);
1456 ieee->associate_seq++;
1458 /* don't scan, and avoid to have the RX path possibily
1459 * try again to associate. Even do not react to AUTH or
1460 * ASSOC response. Just wait for the retry wq to be scheduled.
1461 * Here we will check if there are good nets to associate
1462 * with, so we retry or just get back to NO_LINK and scanning
1464 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING){
1465 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1466 ieee->softmac_stats.no_auth_rs++;
1468 IEEE80211_DEBUG_MGMT("Association failed\n");
1469 ieee->softmac_stats.no_ass_rs++;
1472 ieee->state = IEEE80211_ASSOCIATING_RETRY;
1474 queue_delayed_work(ieee->wq, &ieee->associate_retry_wq,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME);
1476 spin_unlock_irqrestore(&ieee->lock, flags);
1479 void ieee80211_associate_abort_cb(unsigned long dev)
1481 ieee80211_associate_abort((struct ieee80211_device *) dev);
1485 void ieee80211_associate_step1(struct ieee80211_device *ieee)
1487 struct ieee80211_network *beacon = &ieee->current_network;
1488 struct sk_buff *skb;
1490 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1491 ieee->softmac_stats.tx_auth_rq++;
1492 skb=ieee80211_authentication_req(beacon, ieee, 0);
1495 ieee80211_associate_abort(ieee);
1498 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
1499 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1500 //printk("---Sending authentication request\n");
1501 softmac_mgmt_xmit(skb, ieee);
1502 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1503 if(!timer_pending(&ieee->associate_timer)){
1504 ieee->associate_timer.expires = jiffies + (HZ / 2);
1505 add_timer(&ieee->associate_timer);
1507 //If call dev_kfree_skb_any,a warning will ocur....
1508 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1509 //So ... 1204 by lawrence.
1510 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1511 //dev_kfree_skb_any(skb);//edit by thomas
1515 void ieee80211_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, int chlen)
1518 struct sk_buff *skb;
1519 struct ieee80211_network *beacon = &ieee->current_network;
1520 // int hlen = sizeof(struct ieee80211_authentication);
1521 del_timer_sync(&ieee->associate_timer);
1522 ieee->associate_seq++;
1523 ieee->softmac_stats.tx_auth_rq++;
1525 skb = ieee80211_authentication_req(beacon, ieee, chlen+2);
1527 ieee80211_associate_abort(ieee);
1529 c = skb_put(skb, chlen+2);
1530 *(c++) = MFIE_TYPE_CHALLENGE;
1532 memcpy(c, challenge, chlen);
1534 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1536 ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr ));
1538 softmac_mgmt_xmit(skb, ieee);
1539 if (!timer_pending(&ieee->associate_timer)){
1540 //printk("=========>add timer again, to crash\n");
1541 ieee->associate_timer.expires = jiffies + (HZ / 2);
1542 add_timer(&ieee->associate_timer);
1544 dev_kfree_skb_any(skb);//edit by thomas
1549 void ieee80211_associate_step2(struct ieee80211_device *ieee)
1551 struct sk_buff* skb;
1552 struct ieee80211_network *beacon = &ieee->current_network;
1554 del_timer_sync(&ieee->associate_timer);
1556 IEEE80211_DEBUG_MGMT("Sending association request\n");
1557 ieee->softmac_stats.tx_ass_rq++;
1558 skb=ieee80211_association_req(beacon, ieee);
1560 ieee80211_associate_abort(ieee);
1562 softmac_mgmt_xmit(skb, ieee);
1563 if (!timer_pending(&ieee->associate_timer)){
1564 ieee->associate_timer.expires = jiffies + (HZ / 2);
1565 add_timer(&ieee->associate_timer);
1567 //dev_kfree_skb_any(skb);//edit by thomas
1571 void ieee80211_associate_complete_wq(struct work_struct *work)
1573 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq);
1575 printk(KERN_INFO "Associated successfully\n");
1576 if(ieee80211_is_54g(ieee->current_network) &&
1577 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1580 printk(KERN_INFO"Using G rates\n");
1583 printk(KERN_INFO"Using B rates\n");
1585 ieee->link_change(ieee->dev);
1586 notify_wx_assoc_event(ieee);
1587 if (ieee->data_hard_resume)
1588 ieee->data_hard_resume(ieee->dev);
1589 netif_carrier_on(ieee->dev);
1592 void ieee80211_associate_complete(struct ieee80211_device *ieee)
1595 del_timer_sync(&ieee->associate_timer);
1597 for(i = 0; i < 6; i++) {
1598 //ieee->seq_ctrl[i] = 0;
1600 ieee->state = IEEE80211_LINKED;
1601 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1603 queue_work(ieee->wq, &ieee->associate_complete_wq);
1606 void ieee80211_associate_procedure_wq(struct work_struct *work)
1608 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1610 ieee->sync_scan_hurryup = 1;
1611 down(&ieee->wx_sem);
1613 if (ieee->data_hard_stop)
1614 ieee->data_hard_stop(ieee->dev);
1616 ieee80211_stop_scan(ieee);
1617 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1619 ieee->associate_seq = 1;
1620 ieee80211_associate_step1(ieee);
1625 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
1627 u8 tmp_ssid[IW_ESSID_MAX_SIZE+1];
1628 int tmp_ssid_len = 0;
1630 short apset,ssidset,ssidbroad,apmatch,ssidmatch;
1632 /* we are interested in new new only if we are not associated
1633 * and we are not associating / authenticating
1635 if (ieee->state != IEEE80211_NOLINK)
1638 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS))
1641 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS))
1645 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC){
1646 /* if the user specified the AP MAC, we need also the essid
1647 * This could be obtained by beacons or, if the network does not
1648 * broadcast it, it can be put manually.
1650 apset = ieee->wap_set;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1651 ssidset = ieee->ssid_set;//ieee->current_network.ssid[0] != '\0';
1652 ssidbroad = !(net->ssid_len == 0 || net->ssid[0]== '\0');
1653 apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN)==0);
1655 if(ieee->current_network.ssid_len != net->ssid_len)
1658 ssidmatch = (0==strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len));
1660 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1661 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1663 if ( /* if the user set the AP check if match.
1664 * if the network does not broadcast essid we check the user supplyed ANY essid
1665 * if the network does broadcast and the user does not set essid it is OK
1666 * if the network does broadcast and the user did set essid chech if essid match
1668 ( apset && apmatch &&
1669 ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1670 /* if the ap is not set, check that the user set the bssid
1671 * and the network does bradcast and that those two bssid matches
1673 (!apset && ssidset && ssidbroad && ssidmatch)
1677 /* if the essid is hidden replace it with the
1678 * essid provided by the user.
1681 strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
1682 tmp_ssid_len = ieee->current_network.ssid_len;
1684 memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
1687 strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
1688 ieee->current_network.ssid_len = tmp_ssid_len;
1690 printk(KERN_INFO"Linking with %s: channel is %d\n",ieee->current_network.ssid,ieee->current_network.channel);
1692 if (ieee->iw_mode == IW_MODE_INFRA){
1693 ieee->state = IEEE80211_ASSOCIATING;
1694 ieee->beinretry = false;
1695 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1697 if(ieee80211_is_54g(ieee->current_network) &&
1698 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1700 printk(KERN_INFO"Using G rates\n");
1703 printk(KERN_INFO"Using B rates\n");
1705 ieee->state = IEEE80211_LINKED;
1706 ieee->beinretry = false;
1714 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
1716 unsigned long flags;
1717 struct ieee80211_network *target;
1719 spin_lock_irqsave(&ieee->lock, flags);
1720 list_for_each_entry(target, &ieee->network_list, list) {
1722 /* if the state become different that NOLINK means
1723 * we had found what we are searching for
1726 if (ieee->state != IEEE80211_NOLINK)
1729 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
1730 ieee80211_softmac_new_net(ieee, target);
1733 spin_unlock_irqrestore(&ieee->lock, flags);
1738 static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
1740 struct ieee80211_authentication *a;
1742 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1743 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb->len);
1747 a = (struct ieee80211_authentication*) skb->data;
1748 if(skb->len > (sizeof(struct ieee80211_authentication) +3)){
1749 t = skb->data + sizeof(struct ieee80211_authentication);
1751 if(*(t++) == MFIE_TYPE_CHALLENGE){
1753 *challenge = (u8*)kmalloc(*chlen, GFP_ATOMIC);
1754 memcpy(*challenge, t, *chlen);
1758 return cpu_to_le16(a->status);
1763 int auth_rq_parse(struct sk_buff *skb,u8* dest)
1765 struct ieee80211_authentication *a;
1767 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1768 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
1771 a = (struct ieee80211_authentication*) skb->data;
1773 memcpy(dest,a->header.addr2, ETH_ALEN);
1775 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1776 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1778 return WLAN_STATUS_SUCCESS;
1781 static short probe_rq_parse(struct ieee80211_device *ieee, struct sk_buff *skb, u8 *src)
1788 struct ieee80211_hdr_3addr *header =
1789 (struct ieee80211_hdr_3addr *) skb->data;
1791 if (skb->len < sizeof (struct ieee80211_hdr_3addr ))
1792 return -1; /* corrupted */
1794 memcpy(src,header->addr2, ETH_ALEN);
1796 skbend = (u8*)skb->data + skb->len;
1798 tag = skb->data + sizeof (struct ieee80211_hdr_3addr );
1800 while (tag+1 < skbend){
1806 tag++; /* point to the len field */
1807 tag = tag + *(tag); /* point to the last data byte of the tag */
1808 tag++; /* point to the next tag */
1811 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1812 if (ssidlen == 0) return 1;
1814 if (!ssid) return 1; /* ssid not found in tagged param */
1815 return (!strncmp(ssid, ieee->current_network.ssid, ssidlen));
1819 int assoc_rq_parse(struct sk_buff *skb,u8* dest)
1821 struct ieee80211_assoc_request_frame *a;
1823 if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
1824 sizeof(struct ieee80211_info_element))) {
1826 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb->len);
1830 a = (struct ieee80211_assoc_request_frame*) skb->data;
1832 memcpy(dest,a->header.addr2,ETH_ALEN);
1837 static inline u16 assoc_parse(struct sk_buff *skb, int *aid)
1839 struct ieee80211_assoc_response_frame *a;
1840 if (skb->len < sizeof(struct ieee80211_assoc_response_frame)){
1841 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1845 a = (struct ieee80211_assoc_response_frame*) skb->data;
1846 *aid = le16_to_cpu(a->aid) & 0x3fff;
1847 return le16_to_cpu(a->status);
1851 ieee80211_rx_probe_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1855 //IEEE80211DMESG("Rx probe");
1856 ieee->softmac_stats.rx_probe_rq++;
1857 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1858 if (probe_rq_parse(ieee, skb, dest)){
1859 //IEEE80211DMESG("Was for me!");
1860 ieee->softmac_stats.tx_probe_rs++;
1861 ieee80211_resp_to_probe(ieee, dest);
1866 ieee80211_rx_auth_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1870 //IEEE80211DMESG("Rx probe");
1871 ieee->softmac_stats.rx_auth_rq++;
1873 if ((status = auth_rq_parse(skb, dest))!= -1){
1874 ieee80211_resp_to_auth(ieee, status, dest);
1876 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1881 ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1885 //unsigned long flags;
1887 ieee->softmac_stats.rx_ass_rq++;
1888 if (assoc_rq_parse(skb,dest) != -1){
1889 ieee80211_resp_to_assoc_rq(ieee, dest);
1892 printk(KERN_INFO"New client associated: "MAC_FMT"\n", MAC_ARG(dest));
1895 spin_lock_irqsave(&ieee->lock,flags);
1896 add_associate(ieee,dest);
1897 spin_unlock_irqrestore(&ieee->lock,flags);
1903 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr)
1906 struct sk_buff *buf = ieee80211_null_func(ieee, pwr);
1909 softmac_ps_mgmt_xmit(buf, ieee);
1914 short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, u32 *time_l)
1917 int timeout = ieee->ps_timeout;
1922 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1923 ieee->iw_mode != IW_MODE_INFRA ||
1924 ieee->state != IEEE80211_LINKED)
1928 dtim = ieee->current_network.dtim_data;
1931 if(!(dtim & IEEE80211_DTIM_VALID))
1934 timeout = ieee->current_network.beacon_interval;
1936 //printk("VALID\n");
1937 ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
1939 if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
1942 if(!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout)))
1945 if(!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout)))
1948 if((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE ) &&
1949 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1953 *time_l = ieee->current_network.last_dtim_sta_time[0]
1954 + (ieee->current_network.beacon_interval
1955 * ieee->current_network.dtim_period) * 1000;
1959 *time_l = ieee->current_network.last_dtim_sta_time[0]
1960 + MSECS((ieee->current_network.beacon_interval));
1961 //* ieee->current_network.dtim_period));
1962 //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);
1967 *time_h = ieee->current_network.last_dtim_sta_time[1];
1968 if(time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
1977 inline void ieee80211_sta_ps(struct ieee80211_device *ieee)
1983 unsigned long flags,flags2;
1985 spin_lock_irqsave(&ieee->lock, flags);
1987 if((ieee->ps == IEEE80211_PS_DISABLED ||
1989 ieee->iw_mode != IW_MODE_INFRA ||
1990 ieee->state != IEEE80211_LINKED)){
1992 //#warning CHECK_LOCK_HERE
1993 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1995 ieee80211_sta_wakeup(ieee, 1);
1997 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2000 sleep = ieee80211_sta_ps_sleep(ieee,&th, &tl);
2001 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
2002 /* 2 wake, 1 sleep, 0 do nothing */
2008 if(ieee->sta_sleep == 1)
2009 ieee->enter_sleep_state(ieee->dev,th,tl);
2011 else if(ieee->sta_sleep == 0){
2012 // printk("send null 1\n");
2013 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2015 if(ieee->ps_is_queue_empty(ieee->dev)){
2018 ieee->sta_sleep = 2;
2020 ieee->ps_request_tx_ack(ieee->dev);
2022 ieee80211_sta_ps_send_null_frame(ieee,1);
2027 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2032 }else if(sleep == 2){
2033 //#warning CHECK_LOCK_HERE
2034 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2036 // printk("send wakeup packet\n");
2037 ieee80211_sta_wakeup(ieee,1);
2039 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2043 spin_unlock_irqrestore(&ieee->lock, flags);
2047 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl)
2049 if(ieee->sta_sleep == 0){
2051 // printk("Warning: driver is probably failing to report TX ps error\n");
2052 ieee->ps_request_tx_ack(ieee->dev);
2053 ieee80211_sta_ps_send_null_frame(ieee, 0);
2059 if(ieee->sta_sleep == 1)
2060 ieee->sta_wake_up(ieee->dev);
2062 ieee->sta_sleep = 0;
2065 ieee->ps_request_tx_ack(ieee->dev);
2066 ieee80211_sta_ps_send_null_frame(ieee, 0);
2070 void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success)
2072 unsigned long flags,flags2;
2074 spin_lock_irqsave(&ieee->lock, flags);
2075 if(ieee->sta_sleep == 2){
2076 /* Null frame with PS bit set */
2079 // printk("==================> %s::enter sleep state\n",__func__);
2080 ieee->sta_sleep = 1;
2081 ieee->enter_sleep_state(ieee->dev,ieee->ps_th,ieee->ps_tl);
2083 /* if the card report not success we can't be sure the AP
2084 * has not RXed so we can't assume the AP believe us awake
2087 /* 21112005 - tx again null without PS bit if lost */
2090 if((ieee->sta_sleep == 0) && !success){
2091 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2092 ieee80211_sta_ps_send_null_frame(ieee, 0);
2093 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2096 spin_unlock_irqrestore(&ieee->lock, flags);
2100 ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
2101 struct ieee80211_rx_stats *rx_stats, u16 type,
2104 struct ieee80211_hdr_3addr *header = (struct ieee80211_hdr_3addr *) skb->data;
2109 struct ieee80211_assoc_response_frame *assoc_resp;
2110 struct ieee80211_info_element *info_element;
2112 if(!ieee->proto_started)
2115 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2116 ieee->iw_mode == IW_MODE_INFRA &&
2117 ieee->state == IEEE80211_LINKED))
2119 tasklet_schedule(&ieee->ps_task);
2121 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2122 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2123 ieee->last_rx_ps_time = jiffies;
2125 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2127 case IEEE80211_STYPE_ASSOC_RESP:
2128 case IEEE80211_STYPE_REASSOC_RESP:
2130 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2131 WLAN_FC_GET_STYPE(header->frame_ctl));
2132 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2133 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
2134 ieee->iw_mode == IW_MODE_INFRA){
2135 if (0 == (errcode=assoc_parse(skb, &aid))){
2138 ieee->state=IEEE80211_LINKED;
2139 ieee->assoc_id = aid;
2140 ieee->softmac_stats.rx_ass_ok++;
2142 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
2143 if(1 == rx_stats->nic_type) //card type is 8187
2145 goto associate_complete;
2147 assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data;
2148 info_element = &assoc_resp->info_element;
2149 left = skb->len - ((void*)info_element - (void*)assoc_resp);
2151 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
2152 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
2153 printk(KERN_WARNING "[re]associate reeponse error!");
2156 switch (info_element->id) {
2157 case MFIE_TYPE_GENERIC:
2158 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element->len);
2159 if (info_element->len >= 8 &&
2160 info_element->data[0] == 0x00 &&
2161 info_element->data[1] == 0x50 &&
2162 info_element->data[2] == 0xf2 &&
2163 info_element->data[3] == 0x02 &&
2164 info_element->data[4] == 0x01) {
2165 // Not care about version at present.
2166 //WMM Parameter Element
2167 memcpy(ieee->current_network.wmm_param,(u8*)(info_element->data\
2168 + 8),(info_element->len - 8));
2170 if (((ieee->current_network.wmm_info^info_element->data[6])& \
2171 0x0f)||(!ieee->init_wmmparam_flag)) {
2172 //refresh paramete element for current network
2173 // update the register parameter for hardware
2174 ieee->init_wmmparam_flag = 1;
2175 queue_work(ieee->wq, &ieee->wmm_param_update_wq);
2178 //update info_element for current network
2179 ieee->current_network.wmm_info = info_element->data[6];
2183 //nothing to do at present!!!
2187 left -= sizeof(struct ieee80211_info_element_hdr) +
2189 info_element = (struct ieee80211_info_element *)
2190 &info_element->data[info_element->len];
2192 if(!ieee->init_wmmparam_flag) //legacy AP, reset the AC_xx_param register
2194 queue_work(ieee->wq,&ieee->wmm_param_update_wq);
2195 ieee->init_wmmparam_flag = 1;//indicate AC_xx_param upated since last associate
2198 ieee80211_associate_complete(ieee);
2200 ieee->softmac_stats.rx_ass_err++;
2201 IEEE80211_DEBUG_MGMT(
2202 "Association response status code 0x%x\n",
2204 ieee80211_associate_abort(ieee);
2209 case IEEE80211_STYPE_ASSOC_REQ:
2210 case IEEE80211_STYPE_REASSOC_REQ:
2212 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2213 ieee->iw_mode == IW_MODE_MASTER)
2215 ieee80211_rx_assoc_rq(ieee, skb);
2218 case IEEE80211_STYPE_AUTH:
2220 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
2221 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
2222 ieee->iw_mode == IW_MODE_INFRA){
2224 IEEE80211_DEBUG_MGMT("Received authentication response");
2226 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
2227 if(ieee->open_wep || !challenge){
2228 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
2229 ieee->softmac_stats.rx_auth_rs_ok++;
2231 ieee80211_associate_step2(ieee);
2233 ieee80211_auth_challenge(ieee, challenge, chlen);
2236 ieee->softmac_stats.rx_auth_rs_err++;
2237 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode);
2238 ieee80211_associate_abort(ieee);
2241 }else if (ieee->iw_mode == IW_MODE_MASTER){
2242 ieee80211_rx_auth_rq(ieee, skb);
2247 case IEEE80211_STYPE_PROBE_REQ:
2249 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2250 ((ieee->iw_mode == IW_MODE_ADHOC ||
2251 ieee->iw_mode == IW_MODE_MASTER) &&
2252 ieee->state == IEEE80211_LINKED))
2254 ieee80211_rx_probe_rq(ieee, skb);
2257 case IEEE80211_STYPE_DISASSOC:
2258 case IEEE80211_STYPE_DEAUTH:
2259 /* FIXME for now repeat all the association procedure
2260 * both for disassociation and deauthentication
2262 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2263 (ieee->state == IEEE80211_LINKED) &&
2264 (ieee->iw_mode == IW_MODE_INFRA) &&
2265 (!memcmp(header->addr2,ieee->current_network.bssid,ETH_ALEN))){
2266 ieee->state = IEEE80211_ASSOCIATING;
2267 ieee->softmac_stats.reassoc++;
2269 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
2270 queue_work(ieee->wq, &ieee->associate_procedure_wq);
2280 //dev_kfree_skb_any(skb);
2286 /* following are for a simplier TX queue management.
2287 * Instead of using netif_[stop/wake]_queue the driver
2288 * will uses these two function (plus a reset one), that
2289 * will internally uses the kernel netif_* and takes
2290 * care of the ieee802.11 fragmentation.
2291 * So the driver receives a fragment per time and might
2292 * call the stop function when it want without take care
2293 * to have enought room to TX an entire packet.
2294 * This might be useful if each fragment need it's own
2295 * descriptor, thus just keep a total free memory > than
2296 * the max fragmentation treshold is not enought.. If the
2297 * ieee802.11 stack passed a TXB struct then you needed
2298 * to keep N free descriptors where
2299 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2300 * In this way you need just one and the 802.11 stack
2301 * will take care of buffering fragments and pass them to
2302 * to the driver later, when it wakes the queue.
2305 void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee)
2309 unsigned long flags;
2312 spin_lock_irqsave(&ieee->lock,flags);
2314 if(ieee->queue_stop){
2315 IEEE80211DMESG("EE: IEEE hard_start_xmit invoked when kernel queue should be stopped");
2316 netif_stop_queue(ieee->dev);
2317 ieee->ieee_stats.swtxstop++;
2318 //dev_kfree_skb_any(skb);
2323 ieee->stats.tx_bytes+=skb->len;
2326 txb=ieee80211_skb_to_txb(ieee,skb);
2330 IEEE80211DMESG("WW: IEEE stack failed to provide txb");
2331 //dev_kfree_skb_any(skb);
2337 /* called with 2nd parm 0, no tx mgmt lock required */
2338 ieee80211_sta_wakeup(ieee,0);
2340 for(i = 0; i < txb->nr_frags; i++) {
2342 if (ieee->queue_stop){
2343 ieee->tx_pending.txb = txb;
2344 ieee->tx_pending.frag = i;
2347 ieee->softmac_data_hard_start_xmit(
2349 ieee->dev,ieee->rate);
2350 //(i+1)<txb->nr_frags);
2351 ieee->stats.tx_packets++;
2352 ieee->stats.tx_bytes += txb->fragments[i]->len;
2353 ieee->dev->trans_start = jiffies;
2357 ieee80211_txb_free(txb);
2360 spin_unlock_irqrestore(&ieee->lock,flags);
2364 /* called with ieee->lock acquired */
2365 void ieee80211_resume_tx(struct ieee80211_device *ieee)
2368 for(i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) {
2370 if (ieee->queue_stop){
2371 ieee->tx_pending.frag = i;
2375 ieee->softmac_data_hard_start_xmit(
2376 ieee->tx_pending.txb->fragments[i],
2377 ieee->dev,ieee->rate);
2378 //(i+1)<ieee->tx_pending.txb->nr_frags);
2379 ieee->stats.tx_packets++;
2380 ieee->dev->trans_start = jiffies;
2385 ieee80211_txb_free(ieee->tx_pending.txb);
2386 ieee->tx_pending.txb = NULL;
2390 void ieee80211_reset_queue(struct ieee80211_device *ieee)
2392 unsigned long flags;
2394 spin_lock_irqsave(&ieee->lock,flags);
2395 init_mgmt_queue(ieee);
2396 if (ieee->tx_pending.txb){
2397 ieee80211_txb_free(ieee->tx_pending.txb);
2398 ieee->tx_pending.txb = NULL;
2400 ieee->queue_stop = 0;
2401 spin_unlock_irqrestore(&ieee->lock,flags);
2405 void ieee80211_wake_queue(struct ieee80211_device *ieee)
2408 unsigned long flags;
2409 struct sk_buff *skb;
2410 struct ieee80211_hdr_3addr *header;
2412 spin_lock_irqsave(&ieee->lock,flags);
2413 if (! ieee->queue_stop) goto exit;
2415 ieee->queue_stop = 0;
2417 if(ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE){
2418 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))){
2420 header = (struct ieee80211_hdr_3addr *) skb->data;
2422 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2424 if (ieee->seq_ctrl[0] == 0xFFF)
2425 ieee->seq_ctrl[0] = 0;
2427 ieee->seq_ctrl[0]++;
2429 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2430 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
2431 dev_kfree_skb_any(skb);//edit by thomas
2434 if (!ieee->queue_stop && ieee->tx_pending.txb)
2435 ieee80211_resume_tx(ieee);
2437 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)){
2438 ieee->softmac_stats.swtxawake++;
2439 netif_wake_queue(ieee->dev);
2443 spin_unlock_irqrestore(&ieee->lock,flags);
2447 void ieee80211_stop_queue(struct ieee80211_device *ieee)
2449 //unsigned long flags;
2450 //spin_lock_irqsave(&ieee->lock,flags);
2452 if (! netif_queue_stopped(ieee->dev)){
2453 netif_stop_queue(ieee->dev);
2454 ieee->softmac_stats.swtxstop++;
2456 ieee->queue_stop = 1;
2457 //spin_unlock_irqrestore(&ieee->lock,flags);
2462 inline void ieee80211_randomize_cell(struct ieee80211_device *ieee)
2465 get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2467 /* an IBSS cell address must have the two less significant
2468 * bits of the first byte = 2
2470 ieee->current_network.bssid[0] &= ~0x01;
2471 ieee->current_network.bssid[0] |= 0x02;
2474 /* called in user context only */
2475 void ieee80211_start_master_bss(struct ieee80211_device *ieee)
2479 if (ieee->current_network.ssid_len == 0){
2480 strncpy(ieee->current_network.ssid,
2481 IEEE80211_DEFAULT_TX_ESSID,
2484 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2488 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2490 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2491 ieee->state = IEEE80211_LINKED;
2492 ieee->link_change(ieee->dev);
2493 notify_wx_assoc_event(ieee);
2495 if (ieee->data_hard_resume)
2496 ieee->data_hard_resume(ieee->dev);
2498 netif_carrier_on(ieee->dev);
2501 void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
2505 if (ieee->data_hard_resume)
2506 ieee->data_hard_resume(ieee->dev);
2508 netif_carrier_on(ieee->dev);
2512 void ieee80211_start_ibss_wq(struct work_struct *work)
2514 struct delayed_work *dwork = to_delayed_work(work);
2515 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
2517 /* iwconfig mode ad-hoc will schedule this and return
2518 * on the other hand this will block further iwconfig SET
2519 * operations because of the wx_sem hold.
2520 * Anyway some most set operations set a flag to speed-up
2521 * (abort) this wq (when syncro scanning) before sleeping
2525 down(&ieee->wx_sem);
2528 if (ieee->current_network.ssid_len == 0){
2529 strcpy(ieee->current_network.ssid,IEEE80211_DEFAULT_TX_ESSID);
2530 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2534 /* check if we have this cell in our network list */
2535 ieee80211_softmac_check_all_nets(ieee);
2537 #ifdef ENABLE_DOT11D
2538 if(ieee->state == IEEE80211_NOLINK)
2539 ieee->current_network.channel = 10;
2541 /* if not then the state is not linked. Maybe the user swithced to
2542 * ad-hoc mode just after being in monitor mode, or just after
2543 * being very few time in managed mode (so the card have had no
2544 * time to scan all the chans..) or we have just run up the iface
2545 * after setting ad-hoc mode. So we have to give another try..
2546 * Here, in ibss mode, should be safe to do this without extra care
2547 * (in bss mode we had to make sure no-one tryed to associate when
2548 * we had just checked the ieee->state and we was going to start the
2549 * scan) beacause in ibss mode the ieee80211_new_net function, when
2550 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2551 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2552 * scan, that will stop at the first round because it sees the state
2555 if (ieee->state == IEEE80211_NOLINK)
2556 ieee80211_start_scan_syncro(ieee);
2558 /* the network definitively is not here.. create a new cell */
2559 if (ieee->state == IEEE80211_NOLINK){
2560 printk("creating new IBSS cell\n");
2562 ieee80211_randomize_cell(ieee);
2564 if(ieee->modulation & IEEE80211_CCK_MODULATION){
2566 ieee->current_network.rates_len = 4;
2568 ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
2569 ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
2570 ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
2571 ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
2574 ieee->current_network.rates_len = 0;
2576 if(ieee->modulation & IEEE80211_OFDM_MODULATION){
2577 ieee->current_network.rates_ex_len = 8;
2579 ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
2580 ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
2581 ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
2582 ieee->current_network.rates_ex[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
2583 ieee->current_network.rates_ex[4] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
2584 ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
2585 ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
2586 ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
2590 ieee->current_network.rates_ex_len = 0;
2594 // By default, WMM function will be disabled in IBSS mode
2595 ieee->current_network.QoS_Enable = 0;
2597 ieee->current_network.atim_window = 0;
2598 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2599 if(ieee->short_slot)
2600 ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT;
2604 ieee->state = IEEE80211_LINKED;
2605 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2606 ieee->link_change(ieee->dev);
2608 notify_wx_assoc_event(ieee);
2610 ieee80211_start_send_beacons(ieee);
2611 printk(KERN_WARNING "after sending beacon packet!\n");
2613 if (ieee->data_hard_resume)
2614 ieee->data_hard_resume(ieee->dev);
2616 netif_carrier_on(ieee->dev);
2620 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
2622 queue_delayed_work(ieee->wq, &ieee->start_ibss_wq, 100);
2625 /* this is called only in user context, with wx_sem held */
2626 void ieee80211_start_bss(struct ieee80211_device *ieee)
2628 unsigned long flags;
2629 #ifdef ENABLE_DOT11D
2631 // Ref: 802.11d 11.1.3.3
2632 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2634 if(IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee))
2636 if(! ieee->bGlobalDomain)
2642 /* check if we have already found the net we
2643 * are interested in (if any).
2644 * if not (we are disassociated and we are not
2645 * in associating / authenticating phase) start the background scanning.
2647 ieee80211_softmac_check_all_nets(ieee);
2649 /* ensure no-one start an associating process (thus setting
2650 * the ieee->state to ieee80211_ASSOCIATING) while we
2651 * have just cheked it and we are going to enable scan.
2652 * The ieee80211_new_net function is always called with
2653 * lock held (from both ieee80211_softmac_check_all_nets and
2654 * the rx path), so we cannot be in the middle of such function
2656 spin_lock_irqsave(&ieee->lock, flags);
2659 // printk("start bss ENABLE_IPS\n");
2661 if (ieee->state == IEEE80211_NOLINK){
2662 ieee->actscanning = true;
2663 ieee80211_start_scan(ieee);
2666 spin_unlock_irqrestore(&ieee->lock, flags);
2669 /* called only in userspace context */
2670 void ieee80211_disassociate(struct ieee80211_device *ieee)
2672 netif_carrier_off(ieee->dev);
2674 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2675 ieee80211_reset_queue(ieee);
2677 if (ieee->data_hard_stop)
2678 ieee->data_hard_stop(ieee->dev);
2680 #ifdef ENABLE_DOT11D
2681 if(IS_DOT11D_ENABLE(ieee))
2684 ieee->state = IEEE80211_NOLINK;
2685 ieee->link_change(ieee->dev);
2686 notify_wx_assoc_event(ieee);
2689 void ieee80211_associate_retry_wq(struct work_struct *work)
2691 struct delayed_work *dwork = to_delayed_work(work);
2692 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2693 unsigned long flags;
2694 down(&ieee->wx_sem);
2695 if(!ieee->proto_started)
2697 if(ieee->state != IEEE80211_ASSOCIATING_RETRY)
2699 /* until we do not set the state to IEEE80211_NOLINK
2700 * there are no possibility to have someone else trying
2701 * to start an association procdure (we get here with
2702 * ieee->state = IEEE80211_ASSOCIATING).
2703 * When we set the state to IEEE80211_NOLINK it is possible
2704 * that the RX path run an attempt to associate, but
2705 * both ieee80211_softmac_check_all_nets and the
2706 * RX path works with ieee->lock held so there are no
2707 * problems. If we are still disassociated then start a scan.
2708 * the lock here is necessary to ensure no one try to start
2709 * an association procedure when we have just checked the
2710 * state and we are going to start the scan.
2712 ieee->state = IEEE80211_NOLINK;
2713 ieee->beinretry = true;
2714 ieee80211_softmac_check_all_nets(ieee);
2716 spin_lock_irqsave(&ieee->lock, flags);
2718 if(ieee->state == IEEE80211_NOLINK){
2719 ieee->beinretry = false;
2720 ieee->actscanning = true;
2721 ieee80211_start_scan(ieee);
2723 //YJ,add,080828, notify os here
2724 if(ieee->state == IEEE80211_NOLINK)
2726 notify_wx_assoc_event(ieee);
2729 spin_unlock_irqrestore(&ieee->lock, flags);
2735 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
2737 u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2739 struct sk_buff *skb = NULL;
2740 struct ieee80211_probe_response *b;
2742 skb = ieee80211_probe_resp(ieee, broadcast_addr);
2746 b = (struct ieee80211_probe_response *) skb->data;
2747 b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON);
2753 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee)
2755 struct sk_buff *skb;
2756 struct ieee80211_probe_response *b;
2758 skb = ieee80211_get_beacon_(ieee);
2762 b = (struct ieee80211_probe_response *) skb->data;
2763 b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2765 if (ieee->seq_ctrl[0] == 0xFFF)
2766 ieee->seq_ctrl[0] = 0;
2768 ieee->seq_ctrl[0]++;
2773 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
2775 ieee->sync_scan_hurryup = 1;
2776 down(&ieee->wx_sem);
2777 ieee80211_stop_protocol(ieee);
2782 void ieee80211_stop_protocol(struct ieee80211_device *ieee)
2784 if (!ieee->proto_started)
2787 ieee->proto_started = 0;
2789 ieee80211_stop_send_beacons(ieee);
2790 if((ieee->iw_mode == IW_MODE_INFRA)&&(ieee->state == IEEE80211_LINKED)) {
2791 SendDisassociation(ieee,NULL,WLAN_REASON_DISASSOC_STA_HAS_LEFT);
2793 del_timer_sync(&ieee->associate_timer);
2794 cancel_delayed_work(&ieee->associate_retry_wq);
2795 cancel_delayed_work(&ieee->start_ibss_wq);
2796 ieee80211_stop_scan(ieee);
2798 ieee80211_disassociate(ieee);
2801 void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee)
2803 ieee->sync_scan_hurryup = 0;
2804 down(&ieee->wx_sem);
2805 ieee80211_start_protocol(ieee);
2809 void ieee80211_start_protocol(struct ieee80211_device *ieee)
2814 if (ieee->proto_started)
2817 ieee->proto_started = 1;
2819 if (ieee->current_network.channel == 0){
2822 if (ch > MAX_CHANNEL_NUMBER)
2823 return; /* no channel found */
2825 #ifdef ENABLE_DOT11D
2826 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]);
2828 }while(!ieee->channel_map[ch]);
2831 ieee->current_network.channel = ch;
2834 if (ieee->current_network.beacon_interval == 0)
2835 ieee->current_network.beacon_interval = 100;
2836 ieee->set_chan(ieee->dev,ieee->current_network.channel);
2838 for(i = 0; i < 17; i++) {
2839 ieee->last_rxseq_num[i] = -1;
2840 ieee->last_rxfrag_num[i] = -1;
2841 ieee->last_packet_time[i] = 0;
2844 ieee->init_wmmparam_flag = 0;//reinitialize AC_xx_PARAM registers.
2847 /* if the user set the MAC of the ad-hoc cell and then
2848 * switch to managed mode, shall we make sure that association
2849 * attempts does not fail just because the user provide the essid
2850 * and the nic is still checking for the AP MAC ??
2852 switch (ieee->iw_mode) {
2854 ieee->iw_mode = IW_MODE_INFRA;
2855 //not set break here intentionly
2857 ieee80211_start_bss(ieee);
2861 ieee80211_start_ibss(ieee);
2864 case IW_MODE_MASTER:
2865 ieee80211_start_master_bss(ieee);
2868 case IW_MODE_MONITOR:
2869 ieee80211_start_monitor_mode(ieee);
2873 ieee->iw_mode = IW_MODE_INFRA;
2874 ieee80211_start_bss(ieee);
2880 #define DRV_NAME "Ieee80211"
2881 void ieee80211_softmac_init(struct ieee80211_device *ieee)
2884 memset(&ieee->current_network, 0, sizeof(struct ieee80211_network));
2886 ieee->state = IEEE80211_NOLINK;
2887 ieee->sync_scan_hurryup = 0;
2888 for(i = 0; i < 5; i++) {
2889 ieee->seq_ctrl[i] = 0;
2893 ieee->queue_stop = 0;
2895 ieee->softmac_features = 0; //so IEEE2100-like driver are happy
2898 ieee->proto_started = 0;
2899 ieee->basic_rate = IEEE80211_DEFAULT_BASIC_RATE;
2902 ieee->ps = IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST;
2904 // ieee->ps = IEEE80211_PS_DISABLED;
2906 ieee->sta_sleep = 0;
2908 ieee->bInactivePs = false;
2909 ieee->actscanning = false;
2910 ieee->ListenInterval = 2;
2911 ieee->NumRxDataInPeriod = 0; //YJ,add,080828
2912 ieee->NumRxBcnInPeriod = 0; //YJ,add,080828
2913 ieee->NumRxOkTotal = 0;//+by amy 080312
2914 ieee->NumRxUnicast = 0;//YJ,add,080828,for keep alive
2915 ieee->beinretry = false;
2916 ieee->bHwRadioOff = false;
2919 init_mgmt_queue(ieee);
2921 init_timer(&ieee->scan_timer);
2922 ieee->scan_timer.data = (unsigned long)ieee;
2923 ieee->scan_timer.function = ieee80211_softmac_scan_cb;
2925 ieee->tx_pending.txb = NULL;
2927 init_timer(&ieee->associate_timer);
2928 ieee->associate_timer.data = (unsigned long)ieee;
2929 ieee->associate_timer.function = ieee80211_associate_abort_cb;
2931 init_timer(&ieee->beacon_timer);
2932 ieee->beacon_timer.data = (unsigned long) ieee;
2933 ieee->beacon_timer.function = ieee80211_send_beacon_cb;
2935 #ifdef PF_SYNCTHREAD
2936 ieee->wq = create_workqueue(DRV_NAME,0);
2938 ieee->wq = create_workqueue(DRV_NAME);
2940 INIT_DELAYED_WORK(&ieee->start_ibss_wq,(void*) ieee80211_start_ibss_wq);
2941 INIT_WORK(&ieee->associate_complete_wq,(void*) ieee80211_associate_complete_wq);
2942 INIT_WORK(&ieee->associate_procedure_wq,(void*) ieee80211_associate_procedure_wq);
2943 INIT_DELAYED_WORK(&ieee->softmac_scan_wq,(void*) ieee80211_softmac_scan_wq);
2944 INIT_DELAYED_WORK(&ieee->associate_retry_wq,(void*) ieee80211_associate_retry_wq);
2945 INIT_WORK(&ieee->wx_sync_scan_wq,(void*) ieee80211_wx_sync_scan_wq);
2946 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2948 sema_init(&ieee->wx_sem, 1);
2949 sema_init(&ieee->scan_sem, 1);
2951 spin_lock_init(&ieee->mgmt_tx_lock);
2952 spin_lock_init(&ieee->beacon_lock);
2954 tasklet_init(&ieee->ps_task,
2955 (void(*)(unsigned long)) ieee80211_sta_ps,
2956 (unsigned long)ieee);
2957 #ifdef ENABLE_DOT11D
2958 ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
2962 void ieee80211_softmac_free(struct ieee80211_device *ieee)
2964 down(&ieee->wx_sem);
2966 del_timer_sync(&ieee->associate_timer);
2967 cancel_delayed_work(&ieee->associate_retry_wq);
2970 //add for RF power on power of by lizhaoming 080512
2971 cancel_delayed_work(&ieee->GPIOChangeRFWorkItem);
2973 destroy_workqueue(ieee->wq);
2974 #ifdef ENABLE_DOT11D
2975 if(NULL != ieee->pDot11dInfo)
2976 kfree(ieee->pDot11dInfo);
2981 /********************************************************
2982 * Start of WPA code. *
2983 * this is stolen from the ipw2200 driver *
2984 ********************************************************/
2987 static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
2989 /* This is called when wpa_supplicant loads and closes the driver
2991 printk("%s WPA\n",value ? "enabling" : "disabling");
2992 ieee->wpa_enabled = value;
2997 void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, int wpa_ie_len)
2999 /* make sure WPA is enabled */
3000 ieee80211_wpa_enable(ieee, 1);
3002 ieee80211_disassociate(ieee);
3006 static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, int reason)
3012 case IEEE_MLME_STA_DEAUTH:
3016 case IEEE_MLME_STA_DISASSOC:
3017 ieee80211_disassociate(ieee);
3021 printk("Unknown MLME request: %d\n", command);
3029 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
3030 struct ieee_param *param, int plen)
3034 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3035 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3038 if (param->u.wpa_ie.len) {
3039 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
3043 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
3044 kfree(ieee->wpa_ie);
3046 ieee->wpa_ie_len = param->u.wpa_ie.len;
3048 kfree(ieee->wpa_ie);
3049 ieee->wpa_ie = NULL;
3050 ieee->wpa_ie_len = 0;
3053 ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3057 #define AUTH_ALG_OPEN_SYSTEM 0x1
3058 #define AUTH_ALG_SHARED_KEY 0x2
3060 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
3063 struct ieee80211_security sec = {
3064 .flags = SEC_AUTH_MODE,
3068 if (value & AUTH_ALG_SHARED_KEY) {
3069 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3072 sec.auth_mode = WLAN_AUTH_OPEN;
3076 if (ieee->set_security)
3077 ieee->set_security(ieee->dev, &sec);
3084 static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value)
3087 unsigned long flags;
3090 case IEEE_PARAM_WPA_ENABLED:
3091 ret = ieee80211_wpa_enable(ieee, value);
3094 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3095 ieee->tkip_countermeasures=value;
3098 case IEEE_PARAM_DROP_UNENCRYPTED: {
3101 * wpa_supplicant calls set_wpa_enabled when the driver
3102 * is loaded and unloaded, regardless of if WPA is being
3103 * used. No other calls are made which can be used to
3104 * determine if encryption will be used or not prior to
3105 * association being expected. If encryption is not being
3106 * used, drop_unencrypted is set to false, else true -- we
3107 * can use this to determine if the CAP_PRIVACY_ON bit should
3110 struct ieee80211_security sec = {
3111 .flags = SEC_ENABLED,
3114 ieee->drop_unencrypted = value;
3115 /* We only change SEC_LEVEL for open mode. Others
3116 * are set by ipw_wpa_set_encryption.
3119 sec.flags |= SEC_LEVEL;
3120 sec.level = SEC_LEVEL_0;
3123 sec.flags |= SEC_LEVEL;
3124 sec.level = SEC_LEVEL_1;
3126 if (ieee->set_security)
3127 ieee->set_security(ieee->dev, &sec);
3131 case IEEE_PARAM_PRIVACY_INVOKED:
3132 ieee->privacy_invoked=value;
3135 case IEEE_PARAM_AUTH_ALGS:
3136 ret = ieee80211_wpa_set_auth_algs(ieee, value);
3139 case IEEE_PARAM_IEEE_802_1X:
3140 ieee->ieee802_1x=value;
3142 case IEEE_PARAM_WPAX_SELECT:
3143 // added for WPA2 mixed mode
3144 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
3145 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
3146 ieee->wpax_type_set = 1;
3147 ieee->wpax_type_notify = value;
3148 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
3152 printk("Unknown WPA param: %d\n",name);
3159 /* implementation borrowed from hostap driver */
3161 static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
3162 struct ieee_param *param, int param_len)
3166 struct ieee80211_crypto_ops *ops;
3167 struct ieee80211_crypt_data **crypt;
3169 struct ieee80211_security sec = {
3173 param->u.crypt.err = 0;
3174 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3177 (int) ((char *) param->u.crypt.key - (char *) param) +
3178 param->u.crypt.key_len) {
3179 printk("Len mismatch %d, %d\n", param_len,
3180 param->u.crypt.key_len);
3183 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3184 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3185 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3186 if (param->u.crypt.idx >= WEP_KEYS)
3188 crypt = &ieee->crypt[param->u.crypt.idx];
3193 if (strcmp(param->u.crypt.alg, "none") == 0) {
3198 sec.level = SEC_LEVEL_0;
3199 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3200 ieee80211_crypt_delayed_deinit(ieee, crypt);
3207 sec.flags |= SEC_ENABLED;
3209 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3210 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3211 strcmp(param->u.crypt.alg, "TKIP"))
3212 goto skip_host_crypt;
3214 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3215 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3216 request_module("ieee80211_crypt_wep");
3217 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3218 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3219 request_module("ieee80211_crypt_tkip");
3220 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3221 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3222 request_module("ieee80211_crypt_ccmp");
3223 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3226 printk("unknown crypto alg '%s'\n", param->u.crypt.alg);
3227 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3232 if (*crypt == NULL || (*crypt)->ops != ops) {
3233 struct ieee80211_crypt_data *new_crypt;
3235 ieee80211_crypt_delayed_deinit(ieee, crypt);
3237 new_crypt = (struct ieee80211_crypt_data *)
3238 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
3239 if (new_crypt == NULL) {
3243 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3244 new_crypt->ops = ops;
3245 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
3247 new_crypt->ops->init(param->u.crypt.idx);
3249 if (new_crypt->priv == NULL) {
3251 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3259 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3260 (*crypt)->ops->set_key(param->u.crypt.key,
3261 param->u.crypt.key_len, param->u.crypt.seq,
3262 (*crypt)->priv) < 0) {
3263 printk("key setting failed\n");
3264 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3270 if (param->u.crypt.set_tx) {
3271 ieee->tx_keyidx = param->u.crypt.idx;
3272 sec.active_key = param->u.crypt.idx;
3273 sec.flags |= SEC_ACTIVE_KEY;
3275 sec.flags &= ~SEC_ACTIVE_KEY;
3277 if (param->u.crypt.alg != NULL) {
3278 memcpy(sec.keys[param->u.crypt.idx],
3280 param->u.crypt.key_len);
3281 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3282 sec.flags |= (1 << param->u.crypt.idx);
3284 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
3285 sec.flags |= SEC_LEVEL;
3286 sec.level = SEC_LEVEL_1;
3287 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
3288 sec.flags |= SEC_LEVEL;
3289 sec.level = SEC_LEVEL_2;
3290 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
3291 sec.flags |= SEC_LEVEL;
3292 sec.level = SEC_LEVEL_3;
3296 if (ieee->set_security)
3297 ieee->set_security(ieee->dev, &sec);
3299 /* Do not reset port if card is in Managed mode since resetting will
3300 * generate new IEEE 802.11 authentication which may end up in looping
3301 * with IEEE 802.1X. If your hardware requires a reset after WEP
3302 * configuration (for example... Prism2), implement the reset_port in
3303 * the callbacks structures used to initialize the 802.11 stack. */
3304 if (ieee->reset_on_keychange &&
3305 ieee->iw_mode != IW_MODE_INFRA &&
3307 ieee->reset_port(ieee->dev)) {
3308 printk("reset_port failed\n");
3309 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3316 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p)
3318 struct ieee_param *param;
3321 down(&ieee->wx_sem);
3322 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
3324 if (p->length < sizeof(struct ieee_param) || !p->pointer){
3329 param = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
3334 if (copy_from_user(param, p->pointer, p->length)) {
3340 switch (param->cmd) {
3342 case IEEE_CMD_SET_WPA_PARAM:
3343 ret = ieee80211_wpa_set_param(ieee, param->u.wpa_param.name,
3344 param->u.wpa_param.value);
3347 case IEEE_CMD_SET_WPA_IE:
3348 ret = ieee80211_wpa_set_wpa_ie(ieee, param, p->length);
3351 case IEEE_CMD_SET_ENCRYPTION:
3352 ret = ieee80211_wpa_set_encryption(ieee, param, p->length);
3356 ret = ieee80211_wpa_mlme(ieee, param->u.mlme.command,
3357 param->u.mlme.reason_code);
3361 printk("Unknown WPA supplicant request: %d\n",param->cmd);
3366 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3376 void notify_wx_assoc_event(struct ieee80211_device *ieee)
3378 union iwreq_data wrqu;
3379 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3380 if (ieee->state == IEEE80211_LINKED)
3381 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN);
3383 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
3384 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3389 EXPORT_SYMBOL(ieee80211_get_beacon);
3390 EXPORT_SYMBOL(ieee80211_wake_queue);
3391 EXPORT_SYMBOL(ieee80211_stop_queue);
3392 EXPORT_SYMBOL(ieee80211_reset_queue);
3393 EXPORT_SYMBOL(ieee80211_softmac_stop_protocol);
3394 EXPORT_SYMBOL(ieee80211_softmac_start_protocol);
3395 EXPORT_SYMBOL(ieee80211_is_shortslot);
3396 EXPORT_SYMBOL(ieee80211_is_54g);
3397 EXPORT_SYMBOL(ieee80211_wpa_supplicant_ioctl);
3398 EXPORT_SYMBOL(ieee80211_ps_tx_ack);
3399 EXPORT_SYMBOL(ieee80211_start_protocol);
3400 EXPORT_SYMBOL(ieee80211_stop_protocol);
3401 EXPORT_SYMBOL(notify_wx_assoc_event);
3402 EXPORT_SYMBOL(ieee80211_stop_send_beacons);
3403 EXPORT_SYMBOL(SendDisassociation);
3404 EXPORT_SYMBOL(ieee80211_disassociate);
3405 EXPORT_SYMBOL(ieee80211_start_scan);
3406 EXPORT_SYMBOL(ieee80211_softmac_ips_scan_syncro);
3407 EXPORT_SYMBOL(ieee80211_sta_ps_send_null_frame);