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");
452 // dump_chnl_map(channel_map);
459 if (ch > MAX_CHANNEL_NUMBER)
460 goto out; /* scan completed */
463 }while(!channel_map[ch]);
465 }while(!ieee->channel_map[ch]);
467 /* this fuction can be called in two situations
468 * 1- We have switched to ad-hoc mode and we are
469 * performing a complete syncro scan before conclude
470 * there are no interesting cell and to create a
471 * new one. In this case the link state is
472 * IEEE80211_NOLINK until we found an interesting cell.
473 * If so the ieee8021_new_net, called by the RX path
474 * will set the state to IEEE80211_LINKED, so we stop
476 * 2- We are linked and the root uses run iwlist scan.
477 * So we switch to IEEE80211_LINKED_SCANNING to remember
478 * that we are still logically linked (not interested in
479 * new network events, despite for updating the net list,
480 * but we are temporarly 'unlinked' as the driver shall
481 * not filter RX frames and the channel is changing.
482 * So the only situation in witch are interested is to check
483 * if the state become LINKED because of the #1 situation
486 if (ieee->state == IEEE80211_LINKED)
489 ieee->set_chan(ieee->dev, ch);
490 // printk("=====>channel=%d ",ch);
492 if(channel_map[ch] == 1)
495 // printk("====send probe request\n");
496 ieee80211_send_probe_requests(ieee);
498 /* this prevent excessive time wait when we
499 * need to wait for a syncro scan to end..
501 if (ieee->sync_scan_hurryup)
505 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
509 ieee->sync_scan_hurryup = 0;
512 if(IS_DOT11D_ENABLE(ieee))
513 DOT11D_ScanComplete(ieee);
517 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee)
520 unsigned int watch_dog = 0;
522 u8 channel_map[MAX_CHANNEL_NUMBER+1];
523 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
525 down(&ieee->scan_sem);
526 ch = ieee->current_network.channel;
527 // if(ieee->sync_scan_hurryup)
530 // printk("stop scan sync\n");
533 // printk("=======hh===============>ips scan\n");
536 /* this fuction can be called in two situations
537 * 1- We have switched to ad-hoc mode and we are
538 * performing a complete syncro scan before conclude
539 * there are no interesting cell and to create a
540 * new one. In this case the link state is
541 * IEEE80211_NOLINK until we found an interesting cell.
542 * If so the ieee8021_new_net, called by the RX path
543 * will set the state to IEEE80211_LINKED, so we stop
545 * 2- We are linked and the root uses run iwlist scan.
546 * So we switch to IEEE80211_LINKED_SCANNING to remember
547 * that we are still logically linked (not interested in
548 * new network events, despite for updating the net list,
549 * but we are temporarly 'unlinked' as the driver shall
550 * not filter RX frames and the channel is changing.
551 * So the only situation in witch are interested is to check
552 * if the state become LINKED because of the #1 situation
554 if (ieee->state == IEEE80211_LINKED)
559 if(channel_map[ieee->current_network.channel] > 0)
562 ieee->set_chan(ieee->dev, ieee->current_network.channel);
563 // printk("======>channel=%d ",ieee->current_network.channel);
566 if(channel_map[ieee->current_network.channel] == 1)
569 // printk("====send probe request\n");
570 ieee80211_send_probe_requests(ieee);
572 /* this prevent excessive time wait when we
573 * need to wait for a syncro scan to end..
575 // if (ieee->sync_scan_hurryup)
578 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
581 if (watch_dog++ >= MAX_CHANNEL_NUMBER)
582 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
583 goto out; /* scan completed */
585 ieee->current_network.channel = (ieee->current_network.channel + 1)%MAX_CHANNEL_NUMBER;
587 }while(!channel_map[ieee->current_network.channel]);
589 }while(!ieee->channel_map[ieee->current_network.channel]);
593 //ieee->sync_scan_hurryup = 0;
594 //ieee->set_chan(ieee->dev, ch);
595 //ieee->current_network.channel = ch;
596 ieee->actscanning = false;
599 if(IS_DOT11D_ENABLE(ieee))
600 DOT11D_ScanComplete(ieee);
606 /* called both by wq with ieee->lock held */
607 void ieee80211_softmac_scan(struct ieee80211_device *ieee)
612 ieee->current_network.channel =
613 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
614 if (watchdog++ > MAX_CHANNEL_NUMBER)
615 return; /* no good chans */
617 }while(!ieee->channel_map[ieee->current_network.channel]);
620 schedule_work(&ieee->softmac_scan_wq);
624 void ieee80211_softmac_scan_wq(struct work_struct *work)
626 struct delayed_work *dwork = to_delayed_work(work);
627 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
628 static short watchdog = 0;
630 u8 channel_map[MAX_CHANNEL_NUMBER+1];
631 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
633 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
634 // printk("in %s\n",__func__);
635 down(&ieee->scan_sem);
638 ieee->current_network.channel =
639 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
640 if (watchdog++ > MAX_CHANNEL_NUMBER)
641 goto out; /* no good chans */
644 }while(!channel_map[ieee->current_network.channel]);
646 }while(!ieee->channel_map[ieee->current_network.channel]);
649 //printk("current_network.channel:%d\n", ieee->current_network.channel);
650 if (ieee->scanning == 0 )
652 printk("error out, scanning = 0\n");
655 ieee->set_chan(ieee->dev, ieee->current_network.channel);
657 if(channel_map[ieee->current_network.channel] == 1)
659 ieee80211_send_probe_requests(ieee);
661 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
665 ieee->actscanning = false;
671 if(IS_DOT11D_ENABLE(ieee))
672 DOT11D_ScanComplete(ieee);
677 void ieee80211_softmac_scan_wq(struct work_struct *work)
679 struct delayed_work *dwork = to_delayed_work(work);
680 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, softmac_scan_wq);
683 u8 channel_map[MAX_CHANNEL_NUMBER+1];
684 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
686 // printk("enter scan wq,watchdog is %d\n",watchdog);
687 down(&ieee->scan_sem);
690 ieee->current_network.channel =
691 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
692 if (watchdog++ > MAX_CHANNEL_NUMBER)
693 goto out; /* no good chans */
696 }while(!channel_map[ieee->current_network.channel]);
698 }while(!ieee->channel_map[ieee->current_network.channel]);
701 // printk("current_network.channel:%d\n", ieee->current_network.channel);
702 if (ieee->scanning == 0 )
704 printk("error out, scanning = 0\n");
707 ieee->set_chan(ieee->dev, ieee->current_network.channel);
709 if(channel_map[ieee->current_network.channel] == 1)
711 ieee80211_send_probe_requests(ieee);
713 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
717 if(IS_DOT11D_ENABLE(ieee))
718 DOT11D_ScanComplete(ieee);
724 void ieee80211_beacons_start(struct ieee80211_device *ieee)
728 spin_lock_irqsave(&ieee->beacon_lock,flags);
730 ieee->beacon_txing = 1;
731 ieee80211_send_beacon(ieee);
733 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
736 void ieee80211_beacons_stop(struct ieee80211_device *ieee)
740 spin_lock_irqsave(&ieee->beacon_lock,flags);
742 ieee->beacon_txing = 0;
743 del_timer_sync(&ieee->beacon_timer);
745 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
750 void ieee80211_stop_send_beacons(struct ieee80211_device *ieee)
752 if(ieee->stop_send_beacons)
753 ieee->stop_send_beacons(ieee->dev);
754 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
755 ieee80211_beacons_stop(ieee);
759 void ieee80211_start_send_beacons(struct ieee80211_device *ieee)
761 if(ieee->start_send_beacons)
762 ieee->start_send_beacons(ieee->dev);
763 if(ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
764 ieee80211_beacons_start(ieee);
768 void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
770 // unsigned long flags;
772 //ieee->sync_scan_hurryup = 1;
774 down(&ieee->scan_sem);
775 // spin_lock_irqsave(&ieee->lock, flags);
777 if (ieee->scanning == 1){
779 //del_timer_sync(&ieee->scan_timer);
780 cancel_delayed_work(&ieee->softmac_scan_wq);
783 // spin_unlock_irqrestore(&ieee->lock, flags);
787 void ieee80211_stop_scan(struct ieee80211_device *ieee)
789 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
790 ieee80211_softmac_stop_scan(ieee);
792 ieee->stop_scan(ieee->dev);
795 /* called with ieee->lock held */
796 void ieee80211_start_scan(struct ieee80211_device *ieee)
799 if(IS_DOT11D_ENABLE(ieee) )
801 if(IS_COUNTRY_IE_VALID(ieee))
803 RESET_CIE_WATCHDOG(ieee);
807 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
808 if (ieee->scanning == 0)
811 //ieee80211_softmac_scan(ieee);
812 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
813 //care this,1203,2007,by lawrence
815 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq,0);
819 ieee->start_scan(ieee->dev);
823 /* called with wx_sem held */
824 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
827 if(IS_DOT11D_ENABLE(ieee) )
829 if(IS_COUNTRY_IE_VALID(ieee))
831 RESET_CIE_WATCHDOG(ieee);
835 ieee->sync_scan_hurryup = 0;
837 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
838 ieee80211_softmac_scan_syncro(ieee);
840 ieee->scan_syncro(ieee->dev);
844 inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
845 struct ieee80211_device *ieee, int challengelen)
848 struct ieee80211_authentication *auth;
850 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
852 if (!skb) return NULL;
854 auth = (struct ieee80211_authentication *)
855 skb_put(skb, sizeof(struct ieee80211_authentication));
857 auth->header.frame_ctl = IEEE80211_STYPE_AUTH;
858 if (challengelen) auth->header.frame_ctl |= IEEE80211_FCTL_WEP;
860 auth->header.duration_id = 0x013a; //FIXME
862 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
863 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
864 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
866 auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
868 auth->transaction = cpu_to_le16(ieee->associate_seq);
869 ieee->associate_seq++;
871 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
877 static struct sk_buff* ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *dest)
881 struct ieee80211_probe_response *beacon_buf;
884 int atim_len,erp_len;
885 struct ieee80211_crypt_data* crypt;
887 char *ssid = ieee->current_network.ssid;
888 int ssid_len = ieee->current_network.ssid_len;
889 int rate_len = ieee->current_network.rates_len+2;
890 int rate_ex_len = ieee->current_network.rates_ex_len;
891 int wpa_ie_len = ieee->wpa_ie_len;
892 if(rate_ex_len > 0) rate_ex_len+=2;
894 if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
899 if(ieee80211_is_54g(ieee->current_network))
904 beacon_size = sizeof(struct ieee80211_probe_response)+
913 skb = dev_alloc_skb(beacon_size);
918 beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
920 memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
921 memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
922 memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
924 beacon_buf->header.duration_id = 0; //FIXME
925 beacon_buf->beacon_interval =
926 cpu_to_le16(ieee->current_network.beacon_interval);
927 beacon_buf->capability =
928 cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
930 if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
931 cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
933 crypt = ieee->crypt[ieee->tx_keyidx];
935 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
936 ((0 == strcmp(crypt->ops->name, "WEP")) || wpa_ie_len);
939 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
942 beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
944 beacon_buf->info_element.id = MFIE_TYPE_SSID;
945 beacon_buf->info_element.len = ssid_len;
947 tag = (u8*) beacon_buf->info_element.data;
949 memcpy(tag, ssid, ssid_len);
953 *(tag++) = MFIE_TYPE_RATES;
954 *(tag++) = rate_len-2;
955 memcpy(tag,ieee->current_network.rates,rate_len-2);
958 *(tag++) = MFIE_TYPE_DS_SET;
960 *(tag++) = ieee->current_network.channel;
963 *(tag++) = MFIE_TYPE_IBSS_SET;
965 *((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window);
970 *(tag++) = MFIE_TYPE_ERP;
976 *(tag++) = MFIE_TYPE_RATES_EX;
977 *(tag++) = rate_ex_len-2;
978 memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
984 if (ieee->iw_mode == IW_MODE_ADHOC)
985 {//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
986 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
989 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
992 skb->dev = ieee->dev;
996 struct sk_buff* ieee80211_assoc_resp(struct ieee80211_device *ieee, u8 *dest)
1001 struct ieee80211_crypt_data* crypt;
1002 struct ieee80211_assoc_response_frame *assoc;
1005 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1006 int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
1008 skb = dev_alloc_skb(len);
1013 assoc = (struct ieee80211_assoc_response_frame *)
1014 skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
1016 assoc->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP);
1017 memcpy(assoc->header.addr1, dest,ETH_ALEN);
1018 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1019 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1020 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
1021 WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
1024 if(ieee->short_slot)
1025 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1027 if (ieee->host_encrypt)
1028 crypt = ieee->crypt[ieee->tx_keyidx];
1031 encrypt = ( crypt && crypt->ops);
1034 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1037 assoc->aid = cpu_to_le16(ieee->assoc_id);
1038 if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
1039 else ieee->assoc_id++;
1041 tag = (u8*) skb_put(skb, rate_len);
1043 ieee80211_MFIE_Brate(ieee, &tag);
1044 ieee80211_MFIE_Grate(ieee, &tag);
1049 struct sk_buff* ieee80211_auth_resp(struct ieee80211_device *ieee,int status, u8 *dest)
1051 struct sk_buff *skb;
1052 struct ieee80211_authentication *auth;
1054 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
1059 skb->len = sizeof(struct ieee80211_authentication);
1061 auth = (struct ieee80211_authentication *)skb->data;
1063 auth->status = cpu_to_le16(status);
1064 auth->transaction = cpu_to_le16(2);
1065 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
1067 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
1068 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1069 memcpy(auth->header.addr1, dest, ETH_ALEN);
1070 auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
1076 struct sk_buff* ieee80211_null_func(struct ieee80211_device *ieee,short pwr)
1078 struct sk_buff *skb;
1079 struct ieee80211_hdr_3addr* hdr;
1081 skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
1086 hdr = (struct ieee80211_hdr_3addr*)skb_put(skb,sizeof(struct ieee80211_hdr_3addr));
1088 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1089 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1090 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1092 hdr->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
1093 IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
1094 (pwr ? IEEE80211_FCTL_PM:0));
1102 void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8* dest)
1104 struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest);
1107 softmac_mgmt_xmit(buf, ieee);
1108 dev_kfree_skb_any(buf);//edit by thomas
1113 void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8* dest)
1115 struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest);
1118 softmac_mgmt_xmit(buf, ieee);
1119 dev_kfree_skb_any(buf);//edit by thomas
1124 void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest)
1127 struct sk_buff *buf = ieee80211_probe_resp(ieee, dest);
1130 softmac_mgmt_xmit(buf, ieee);
1131 dev_kfree_skb_any(buf);//edit by thomas
1136 inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beacon,struct ieee80211_device *ieee)
1138 struct sk_buff *skb;
1139 //unsigned long flags;
1141 struct ieee80211_assoc_request_frame *hdr;
1143 //short info_addr = 0;
1145 //u16 suite_count = 0;
1146 //u8 suit_select = 0;
1147 unsigned int wpa_len = beacon->wpa_ie_len;
1148 //struct net_device *dev = ieee->dev;
1149 //union iwreq_data wrqu;
1153 // for testing purpose
1154 unsigned int rsn_len = beacon->rsn_ie_len;
1156 unsigned int rsn_len = beacon->rsn_ie_len - 4;
1158 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1159 unsigned int wmm_info_len = beacon->QoS_Enable?9:0;
1161 unsigned int turbo_info_len = beacon->Turbo_Enable?9:0;
1164 u8 encry_proto = ieee->wpax_type_notify & 0xff;
1165 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1166 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1170 //[0] Notify type of encryption: WPA/WPA2
1171 //[1] pair wise type
1173 if(ieee->wpax_type_set) {
1174 if (IEEE_PROTO_WPA == encry_proto) {
1176 } else if (IEEE_PROTO_RSN == encry_proto) {
1181 len = sizeof(struct ieee80211_assoc_request_frame)+
1182 + beacon->ssid_len//essid tagged val
1183 + rate_len//rates tagged val
1189 len = sizeof(struct ieee80211_assoc_request_frame)+
1190 + beacon->ssid_len//essid tagged val
1191 + rate_len//rates tagged val
1197 skb = dev_alloc_skb(len);
1202 hdr = (struct ieee80211_assoc_request_frame *)
1203 skb_put(skb, sizeof(struct ieee80211_assoc_request_frame));
1206 hdr->header.frame_ctl = IEEE80211_STYPE_ASSOC_REQ;
1207 hdr->header.duration_id= 37; //FIXME
1208 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1209 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1210 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1211 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);//for HW security, John
1213 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS);
1214 if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1215 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1216 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1217 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1219 if(ieee->short_slot)
1220 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1222 hdr->listen_interval = 0xa; //FIXME
1224 hdr->info_element.id = MFIE_TYPE_SSID;
1226 hdr->info_element.len = beacon->ssid_len;
1227 tag = skb_put(skb, beacon->ssid_len);
1228 memcpy(tag, beacon->ssid, beacon->ssid_len);
1230 tag = skb_put(skb, rate_len);
1232 ieee80211_MFIE_Brate(ieee, &tag);
1233 ieee80211_MFIE_Grate(ieee, &tag);
1235 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1236 //choose AES encryption as default algorithm while using mixed mode
1240 tag = skb_put(skb,wpa_len);
1245 //{add by david. 2006.8.31
1246 //fix linksys compatibility bug
1248 if(wpa_len > 24) {//22+2, mean include the capability
1249 beacon->wpa_ie[wpa_len - 2] = 0;
1251 //multicast cipher OUI
1252 if( beacon->wpa_ie[11]==0x2 ){ //0x0050f202 is the oui of tkip
1253 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1255 else if( beacon->wpa_ie[11]==0x4 ){//0x0050f204 is the oui of ccmp
1256 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1258 //unicast cipher OUI
1259 if( beacon->wpa_ie[14]==0
1260 && beacon->wpa_ie[15]==0x50
1261 && beacon->wpa_ie[16]==0xf2
1262 && beacon->wpa_ie[17]==0x2 ){ //0x0050f202 is the oui of tkip
1263 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1266 else if( beacon->wpa_ie[14]==0
1267 && beacon->wpa_ie[15]==0x50
1268 && beacon->wpa_ie[16]==0xf2
1269 && beacon->wpa_ie[17]==0x4 ){//0x0050f204 is the oui of ccmp
1270 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1272 //indicate the wpa_ie content to WPA_SUPPLICANT
1273 buff = kmalloc(IW_CUSTOM_MAX, GFP_ATOMIC);
1274 memset(buff, 0, IW_CUSTOM_MAX);
1276 p += sprintf(p, "ASSOCINFO(ReqIEs=");
1277 for(i=0;i<wpa_len;i++){
1278 p += sprintf(p, "%02x", beacon->wpa_ie[i]);
1280 p += sprintf(p, ")");
1281 memset(&wrqu, 0, sizeof(wrqu) );
1282 wrqu.data.length = p - buff;
1284 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buff);
1285 memcpy(tag,beacon->wpa_ie,wpa_len);
1292 if( beacon->rsn_ie[4]==0x0 &&
1293 beacon->rsn_ie[5]==0xf &&
1294 beacon->rsn_ie[6]==0xac){
1296 switch(beacon->rsn_ie[7]){
1298 ieee->broadcast_key_type = KEY_TYPE_WEP40;
1301 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1304 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1307 ieee->broadcast_key_type = KEY_TYPE_WEP104;
1310 printk("fault suite type in RSN broadcast key\n");
1315 if( beacon->rsn_ie[10]==0x0 &&
1316 beacon->rsn_ie[11]==0xf &&
1317 beacon->rsn_ie[12]==0xac){
1318 if(beacon->rsn_ie[8]==1){//not mixed mode
1319 switch(beacon->rsn_ie[13]){
1321 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1324 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1327 printk("fault suite type in RSN pairwise key\n");
1331 else if(beacon->rsn_ie[8]==2){//mixed mode
1332 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1338 tag = skb_put(skb,22);
1339 memcpy(tag,(beacon->rsn_ie + info_addr),8);
1344 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
1345 for (i = 0; i < 2; i++) {
1349 suite_count = beacon->rsn_ie[info_addr] + \
1350 (beacon->rsn_ie[info_addr + 1] << 8);
1352 if(1 == suite_count) {
1353 memcpy(tag,(beacon->rsn_ie + info_addr),4);
1356 // if the wpax_type_notify has been set by the application,
1357 // just use it, otherwise just use the default one.
1358 if(ieee->wpax_type_set) {
1359 suit_select = ((0 == i) ? pairwise_type:authen_type)&0x0f ;
1360 memcpy(tag,rsn_authen_cipher_suite[suit_select],4);
1362 //default set as ccmp, or none authentication
1364 memcpy(tag,rsn_authen_cipher_suite[4],4);
1366 memcpy(tag,rsn_authen_cipher_suite[2],4);
1371 info_addr += (suite_count * 4);
1375 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
1378 tag[1] = beacon->rsn_ie[info_addr+1];
1381 tag = skb_put(skb,rsn_len);
1385 if( beacon->rsn_ie[4]==0x0 &&
1386 beacon->rsn_ie[5]==0xf &&
1387 beacon->rsn_ie[6]==0xac){
1388 switch(beacon->rsn_ie[7]){
1390 ieee->broadcast_key_type = KEY_TYPE_WEP40;
1393 ieee->broadcast_key_type = KEY_TYPE_TKIP;
1396 ieee->broadcast_key_type = KEY_TYPE_CCMP;
1399 ieee->broadcast_key_type = KEY_TYPE_WEP104;
1402 printk("fault suite type in RSN broadcast key\n");
1406 if( beacon->rsn_ie[10]==0x0 &&
1407 beacon->rsn_ie[11]==0xf &&
1408 beacon->rsn_ie[12]==0xac){
1409 if(beacon->rsn_ie[8]==1){//not mixed mode
1410 switch(beacon->rsn_ie[13]){
1412 ieee->pairwise_key_type = KEY_TYPE_TKIP;
1415 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1418 printk("fault suite type in RSN pairwise key\n");
1423 else if(beacon->rsn_ie[8]==2){//mixed mode
1424 ieee->pairwise_key_type = KEY_TYPE_CCMP;
1429 beacon->rsn_ie[rsn_len - 2] = 0;
1430 memcpy(tag,beacon->rsn_ie,rsn_len);
1434 tag = skb_put(skb,ieee->wpa_ie_len);
1435 memcpy(tag,ieee->wpa_ie,ieee->wpa_ie_len);
1437 tag = skb_put(skb,wmm_info_len);
1439 ieee80211_WMM_Info(ieee, &tag);
1442 tag = skb_put(skb,turbo_info_len);
1443 if(turbo_info_len) {
1444 ieee80211_TURBO_Info(ieee, &tag);
1451 void ieee80211_associate_abort(struct ieee80211_device *ieee)
1454 unsigned long flags;
1455 spin_lock_irqsave(&ieee->lock, flags);
1457 ieee->associate_seq++;
1459 /* don't scan, and avoid to have the RX path possibily
1460 * try again to associate. Even do not react to AUTH or
1461 * ASSOC response. Just wait for the retry wq to be scheduled.
1462 * Here we will check if there are good nets to associate
1463 * with, so we retry or just get back to NO_LINK and scanning
1465 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING){
1466 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1467 ieee->softmac_stats.no_auth_rs++;
1469 IEEE80211_DEBUG_MGMT("Association failed\n");
1470 ieee->softmac_stats.no_ass_rs++;
1473 ieee->state = IEEE80211_ASSOCIATING_RETRY;
1475 queue_delayed_work(ieee->wq, &ieee->associate_retry_wq,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME);
1477 spin_unlock_irqrestore(&ieee->lock, flags);
1480 void ieee80211_associate_abort_cb(unsigned long dev)
1482 ieee80211_associate_abort((struct ieee80211_device *) dev);
1486 void ieee80211_associate_step1(struct ieee80211_device *ieee)
1488 struct ieee80211_network *beacon = &ieee->current_network;
1489 struct sk_buff *skb;
1491 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1492 ieee->softmac_stats.tx_auth_rq++;
1493 skb=ieee80211_authentication_req(beacon, ieee, 0);
1496 ieee80211_associate_abort(ieee);
1499 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
1500 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1501 //printk("---Sending authentication request\n");
1502 softmac_mgmt_xmit(skb, ieee);
1503 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1504 if(!timer_pending(&ieee->associate_timer)){
1505 ieee->associate_timer.expires = jiffies + (HZ / 2);
1506 add_timer(&ieee->associate_timer);
1508 //If call dev_kfree_skb_any,a warning will ocur....
1509 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1510 //So ... 1204 by lawrence.
1511 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1512 //dev_kfree_skb_any(skb);//edit by thomas
1516 void ieee80211_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, int chlen)
1519 struct sk_buff *skb;
1520 struct ieee80211_network *beacon = &ieee->current_network;
1521 // int hlen = sizeof(struct ieee80211_authentication);
1522 del_timer_sync(&ieee->associate_timer);
1523 ieee->associate_seq++;
1524 ieee->softmac_stats.tx_auth_rq++;
1526 skb = ieee80211_authentication_req(beacon, ieee, chlen+2);
1528 ieee80211_associate_abort(ieee);
1530 c = skb_put(skb, chlen+2);
1531 *(c++) = MFIE_TYPE_CHALLENGE;
1533 memcpy(c, challenge, chlen);
1535 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1537 ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr ));
1539 softmac_mgmt_xmit(skb, ieee);
1540 if (!timer_pending(&ieee->associate_timer)){
1541 //printk("=========>add timer again, to crash\n");
1542 ieee->associate_timer.expires = jiffies + (HZ / 2);
1543 add_timer(&ieee->associate_timer);
1545 dev_kfree_skb_any(skb);//edit by thomas
1550 void ieee80211_associate_step2(struct ieee80211_device *ieee)
1552 struct sk_buff* skb;
1553 struct ieee80211_network *beacon = &ieee->current_network;
1555 del_timer_sync(&ieee->associate_timer);
1557 IEEE80211_DEBUG_MGMT("Sending association request\n");
1558 ieee->softmac_stats.tx_ass_rq++;
1559 skb=ieee80211_association_req(beacon, ieee);
1561 ieee80211_associate_abort(ieee);
1563 softmac_mgmt_xmit(skb, ieee);
1564 if (!timer_pending(&ieee->associate_timer)){
1565 ieee->associate_timer.expires = jiffies + (HZ / 2);
1566 add_timer(&ieee->associate_timer);
1568 //dev_kfree_skb_any(skb);//edit by thomas
1572 void ieee80211_associate_complete_wq(struct work_struct *work)
1574 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq);
1576 printk(KERN_INFO "Associated successfully\n");
1577 if(ieee80211_is_54g(ieee->current_network) &&
1578 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1581 printk(KERN_INFO"Using G rates\n");
1584 printk(KERN_INFO"Using B rates\n");
1586 ieee->link_change(ieee->dev);
1587 notify_wx_assoc_event(ieee);
1588 if (ieee->data_hard_resume)
1589 ieee->data_hard_resume(ieee->dev);
1590 netif_carrier_on(ieee->dev);
1593 void ieee80211_associate_complete(struct ieee80211_device *ieee)
1596 del_timer_sync(&ieee->associate_timer);
1598 for(i = 0; i < 6; i++) {
1599 //ieee->seq_ctrl[i] = 0;
1601 ieee->state = IEEE80211_LINKED;
1602 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1604 queue_work(ieee->wq, &ieee->associate_complete_wq);
1607 void ieee80211_associate_procedure_wq(struct work_struct *work)
1609 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1611 ieee->sync_scan_hurryup = 1;
1612 down(&ieee->wx_sem);
1614 if (ieee->data_hard_stop)
1615 ieee->data_hard_stop(ieee->dev);
1617 ieee80211_stop_scan(ieee);
1618 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1620 ieee->associate_seq = 1;
1621 ieee80211_associate_step1(ieee);
1626 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
1628 u8 tmp_ssid[IW_ESSID_MAX_SIZE+1];
1629 int tmp_ssid_len = 0;
1631 short apset,ssidset,ssidbroad,apmatch,ssidmatch;
1633 /* we are interested in new new only if we are not associated
1634 * and we are not associating / authenticating
1636 if (ieee->state != IEEE80211_NOLINK)
1639 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS))
1642 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS))
1646 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC){
1647 /* if the user specified the AP MAC, we need also the essid
1648 * This could be obtained by beacons or, if the network does not
1649 * broadcast it, it can be put manually.
1651 apset = ieee->wap_set;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1652 ssidset = ieee->ssid_set;//ieee->current_network.ssid[0] != '\0';
1653 ssidbroad = !(net->ssid_len == 0 || net->ssid[0]== '\0');
1654 apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN)==0);
1656 if(ieee->current_network.ssid_len != net->ssid_len)
1659 ssidmatch = (0==strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len));
1661 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1662 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1664 if ( /* if the user set the AP check if match.
1665 * if the network does not broadcast essid we check the user supplyed ANY essid
1666 * if the network does broadcast and the user does not set essid it is OK
1667 * if the network does broadcast and the user did set essid chech if essid match
1669 ( apset && apmatch &&
1670 ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1671 /* if the ap is not set, check that the user set the bssid
1672 * and the network does bradcast and that those two bssid matches
1674 (!apset && ssidset && ssidbroad && ssidmatch)
1678 /* if the essid is hidden replace it with the
1679 * essid provided by the user.
1682 strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
1683 tmp_ssid_len = ieee->current_network.ssid_len;
1685 memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
1688 strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
1689 ieee->current_network.ssid_len = tmp_ssid_len;
1691 printk(KERN_INFO"Linking with %s: channel is %d\n",ieee->current_network.ssid,ieee->current_network.channel);
1693 if (ieee->iw_mode == IW_MODE_INFRA){
1694 ieee->state = IEEE80211_ASSOCIATING;
1695 ieee->beinretry = false;
1696 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1698 if(ieee80211_is_54g(ieee->current_network) &&
1699 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1701 printk(KERN_INFO"Using G rates\n");
1704 printk(KERN_INFO"Using B rates\n");
1706 ieee->state = IEEE80211_LINKED;
1707 ieee->beinretry = false;
1715 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
1717 unsigned long flags;
1718 struct ieee80211_network *target;
1720 spin_lock_irqsave(&ieee->lock, flags);
1721 list_for_each_entry(target, &ieee->network_list, list) {
1723 /* if the state become different that NOLINK means
1724 * we had found what we are searching for
1727 if (ieee->state != IEEE80211_NOLINK)
1730 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
1731 ieee80211_softmac_new_net(ieee, target);
1734 spin_unlock_irqrestore(&ieee->lock, flags);
1739 static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
1741 struct ieee80211_authentication *a;
1743 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1744 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb->len);
1748 a = (struct ieee80211_authentication*) skb->data;
1749 if(skb->len > (sizeof(struct ieee80211_authentication) +3)){
1750 t = skb->data + sizeof(struct ieee80211_authentication);
1752 if(*(t++) == MFIE_TYPE_CHALLENGE){
1754 *challenge = (u8*)kmalloc(*chlen, GFP_ATOMIC);
1755 memcpy(*challenge, t, *chlen);
1759 return cpu_to_le16(a->status);
1764 int auth_rq_parse(struct sk_buff *skb,u8* dest)
1766 struct ieee80211_authentication *a;
1768 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1769 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
1772 a = (struct ieee80211_authentication*) skb->data;
1774 memcpy(dest,a->header.addr2, ETH_ALEN);
1776 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1777 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1779 return WLAN_STATUS_SUCCESS;
1782 static short probe_rq_parse(struct ieee80211_device *ieee, struct sk_buff *skb, u8 *src)
1789 struct ieee80211_hdr_3addr *header =
1790 (struct ieee80211_hdr_3addr *) skb->data;
1792 if (skb->len < sizeof (struct ieee80211_hdr_3addr ))
1793 return -1; /* corrupted */
1795 memcpy(src,header->addr2, ETH_ALEN);
1797 skbend = (u8*)skb->data + skb->len;
1799 tag = skb->data + sizeof (struct ieee80211_hdr_3addr );
1801 while (tag+1 < skbend){
1807 tag++; /* point to the len field */
1808 tag = tag + *(tag); /* point to the last data byte of the tag */
1809 tag++; /* point to the next tag */
1812 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1813 if (ssidlen == 0) return 1;
1815 if (!ssid) return 1; /* ssid not found in tagged param */
1816 return (!strncmp(ssid, ieee->current_network.ssid, ssidlen));
1820 int assoc_rq_parse(struct sk_buff *skb,u8* dest)
1822 struct ieee80211_assoc_request_frame *a;
1824 if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
1825 sizeof(struct ieee80211_info_element))) {
1827 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb->len);
1831 a = (struct ieee80211_assoc_request_frame*) skb->data;
1833 memcpy(dest,a->header.addr2,ETH_ALEN);
1838 static inline u16 assoc_parse(struct sk_buff *skb, int *aid)
1840 struct ieee80211_assoc_response_frame *a;
1841 if (skb->len < sizeof(struct ieee80211_assoc_response_frame)){
1842 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1846 a = (struct ieee80211_assoc_response_frame*) skb->data;
1847 *aid = le16_to_cpu(a->aid) & 0x3fff;
1848 return le16_to_cpu(a->status);
1852 ieee80211_rx_probe_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1856 //IEEE80211DMESG("Rx probe");
1857 ieee->softmac_stats.rx_probe_rq++;
1858 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1859 if (probe_rq_parse(ieee, skb, dest)){
1860 //IEEE80211DMESG("Was for me!");
1861 ieee->softmac_stats.tx_probe_rs++;
1862 ieee80211_resp_to_probe(ieee, dest);
1867 ieee80211_rx_auth_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1871 //IEEE80211DMESG("Rx probe");
1872 ieee->softmac_stats.rx_auth_rq++;
1874 if ((status = auth_rq_parse(skb, dest))!= -1){
1875 ieee80211_resp_to_auth(ieee, status, dest);
1877 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1882 ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1886 //unsigned long flags;
1888 ieee->softmac_stats.rx_ass_rq++;
1889 if (assoc_rq_parse(skb,dest) != -1){
1890 ieee80211_resp_to_assoc_rq(ieee, dest);
1893 printk(KERN_INFO"New client associated: "MAC_FMT"\n", MAC_ARG(dest));
1896 spin_lock_irqsave(&ieee->lock,flags);
1897 add_associate(ieee,dest);
1898 spin_unlock_irqrestore(&ieee->lock,flags);
1904 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr)
1907 struct sk_buff *buf = ieee80211_null_func(ieee, pwr);
1910 softmac_ps_mgmt_xmit(buf, ieee);
1915 short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, u32 *time_l)
1918 int timeout = ieee->ps_timeout;
1923 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1924 ieee->iw_mode != IW_MODE_INFRA ||
1925 ieee->state != IEEE80211_LINKED)
1929 dtim = ieee->current_network.dtim_data;
1932 if(!(dtim & IEEE80211_DTIM_VALID))
1935 timeout = ieee->current_network.beacon_interval;
1937 //printk("VALID\n");
1938 ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
1940 if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
1943 if(!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout)))
1946 if(!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout)))
1949 if((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE ) &&
1950 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1954 *time_l = ieee->current_network.last_dtim_sta_time[0]
1955 + (ieee->current_network.beacon_interval
1956 * ieee->current_network.dtim_period) * 1000;
1960 *time_l = ieee->current_network.last_dtim_sta_time[0]
1961 + MSECS((ieee->current_network.beacon_interval));
1962 //* ieee->current_network.dtim_period));
1963 //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);
1968 *time_h = ieee->current_network.last_dtim_sta_time[1];
1969 if(time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
1978 inline void ieee80211_sta_ps(struct ieee80211_device *ieee)
1984 unsigned long flags,flags2;
1986 spin_lock_irqsave(&ieee->lock, flags);
1988 if((ieee->ps == IEEE80211_PS_DISABLED ||
1990 ieee->iw_mode != IW_MODE_INFRA ||
1991 ieee->state != IEEE80211_LINKED)){
1993 //#warning CHECK_LOCK_HERE
1994 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1996 ieee80211_sta_wakeup(ieee, 1);
1998 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2001 sleep = ieee80211_sta_ps_sleep(ieee,&th, &tl);
2002 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
2003 /* 2 wake, 1 sleep, 0 do nothing */
2009 if(ieee->sta_sleep == 1)
2010 ieee->enter_sleep_state(ieee->dev,th,tl);
2012 else if(ieee->sta_sleep == 0){
2013 // printk("send null 1\n");
2014 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2016 if(ieee->ps_is_queue_empty(ieee->dev)){
2019 ieee->sta_sleep = 2;
2021 ieee->ps_request_tx_ack(ieee->dev);
2023 ieee80211_sta_ps_send_null_frame(ieee,1);
2028 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2033 }else if(sleep == 2){
2034 //#warning CHECK_LOCK_HERE
2035 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2037 // printk("send wakeup packet\n");
2038 ieee80211_sta_wakeup(ieee,1);
2040 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2044 spin_unlock_irqrestore(&ieee->lock, flags);
2048 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl)
2050 if(ieee->sta_sleep == 0){
2052 // printk("Warning: driver is probably failing to report TX ps error\n");
2053 ieee->ps_request_tx_ack(ieee->dev);
2054 ieee80211_sta_ps_send_null_frame(ieee, 0);
2060 if(ieee->sta_sleep == 1)
2061 ieee->sta_wake_up(ieee->dev);
2063 ieee->sta_sleep = 0;
2066 ieee->ps_request_tx_ack(ieee->dev);
2067 ieee80211_sta_ps_send_null_frame(ieee, 0);
2071 void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success)
2073 unsigned long flags,flags2;
2075 spin_lock_irqsave(&ieee->lock, flags);
2076 if(ieee->sta_sleep == 2){
2077 /* Null frame with PS bit set */
2080 // printk("==================> %s::enter sleep state\n",__func__);
2081 ieee->sta_sleep = 1;
2082 ieee->enter_sleep_state(ieee->dev,ieee->ps_th,ieee->ps_tl);
2084 /* if the card report not success we can't be sure the AP
2085 * has not RXed so we can't assume the AP believe us awake
2088 /* 21112005 - tx again null without PS bit if lost */
2091 if((ieee->sta_sleep == 0) && !success){
2092 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
2093 ieee80211_sta_ps_send_null_frame(ieee, 0);
2094 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
2097 spin_unlock_irqrestore(&ieee->lock, flags);
2101 ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
2102 struct ieee80211_rx_stats *rx_stats, u16 type,
2105 struct ieee80211_hdr_3addr *header = (struct ieee80211_hdr_3addr *) skb->data;
2110 struct ieee80211_assoc_response_frame *assoc_resp;
2111 struct ieee80211_info_element *info_element;
2113 if(!ieee->proto_started)
2116 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
2117 ieee->iw_mode == IW_MODE_INFRA &&
2118 ieee->state == IEEE80211_LINKED))
2120 tasklet_schedule(&ieee->ps_task);
2122 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
2123 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
2124 ieee->last_rx_ps_time = jiffies;
2126 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
2128 case IEEE80211_STYPE_ASSOC_RESP:
2129 case IEEE80211_STYPE_REASSOC_RESP:
2131 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2132 WLAN_FC_GET_STYPE(header->frame_ctl));
2133 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2134 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
2135 ieee->iw_mode == IW_MODE_INFRA){
2136 if (0 == (errcode=assoc_parse(skb, &aid))){
2139 ieee->state=IEEE80211_LINKED;
2140 ieee->assoc_id = aid;
2141 ieee->softmac_stats.rx_ass_ok++;
2143 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
2144 if(1 == rx_stats->nic_type) //card type is 8187
2146 goto associate_complete;
2148 assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data;
2149 info_element = &assoc_resp->info_element;
2150 left = skb->len - ((void*)info_element - (void*)assoc_resp);
2152 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
2153 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
2154 printk(KERN_WARNING "[re]associate reeponse error!");
2157 switch (info_element->id) {
2158 case MFIE_TYPE_GENERIC:
2159 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element->len);
2160 if (info_element->len >= 8 &&
2161 info_element->data[0] == 0x00 &&
2162 info_element->data[1] == 0x50 &&
2163 info_element->data[2] == 0xf2 &&
2164 info_element->data[3] == 0x02 &&
2165 info_element->data[4] == 0x01) {
2166 // Not care about version at present.
2167 //WMM Parameter Element
2168 memcpy(ieee->current_network.wmm_param,(u8*)(info_element->data\
2169 + 8),(info_element->len - 8));
2171 if (((ieee->current_network.wmm_info^info_element->data[6])& \
2172 0x0f)||(!ieee->init_wmmparam_flag)) {
2173 //refresh paramete element for current network
2174 // update the register parameter for hardware
2175 ieee->init_wmmparam_flag = 1;
2176 queue_work(ieee->wq, &ieee->wmm_param_update_wq);
2179 //update info_element for current network
2180 ieee->current_network.wmm_info = info_element->data[6];
2184 //nothing to do at present!!!
2188 left -= sizeof(struct ieee80211_info_element_hdr) +
2190 info_element = (struct ieee80211_info_element *)
2191 &info_element->data[info_element->len];
2193 if(!ieee->init_wmmparam_flag) //legacy AP, reset the AC_xx_param register
2195 queue_work(ieee->wq,&ieee->wmm_param_update_wq);
2196 ieee->init_wmmparam_flag = 1;//indicate AC_xx_param upated since last associate
2199 ieee80211_associate_complete(ieee);
2201 ieee->softmac_stats.rx_ass_err++;
2202 IEEE80211_DEBUG_MGMT(
2203 "Association response status code 0x%x\n",
2205 ieee80211_associate_abort(ieee);
2210 case IEEE80211_STYPE_ASSOC_REQ:
2211 case IEEE80211_STYPE_REASSOC_REQ:
2213 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2214 ieee->iw_mode == IW_MODE_MASTER)
2216 ieee80211_rx_assoc_rq(ieee, skb);
2219 case IEEE80211_STYPE_AUTH:
2221 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
2222 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
2223 ieee->iw_mode == IW_MODE_INFRA){
2225 IEEE80211_DEBUG_MGMT("Received authentication response");
2227 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
2228 if(ieee->open_wep || !challenge){
2229 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
2230 ieee->softmac_stats.rx_auth_rs_ok++;
2232 ieee80211_associate_step2(ieee);
2234 ieee80211_auth_challenge(ieee, challenge, chlen);
2237 ieee->softmac_stats.rx_auth_rs_err++;
2238 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode);
2239 ieee80211_associate_abort(ieee);
2242 }else if (ieee->iw_mode == IW_MODE_MASTER){
2243 ieee80211_rx_auth_rq(ieee, skb);
2248 case IEEE80211_STYPE_PROBE_REQ:
2250 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2251 ((ieee->iw_mode == IW_MODE_ADHOC ||
2252 ieee->iw_mode == IW_MODE_MASTER) &&
2253 ieee->state == IEEE80211_LINKED))
2255 ieee80211_rx_probe_rq(ieee, skb);
2258 case IEEE80211_STYPE_DISASSOC:
2259 case IEEE80211_STYPE_DEAUTH:
2260 /* FIXME for now repeat all the association procedure
2261 * both for disassociation and deauthentication
2263 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2264 (ieee->state == IEEE80211_LINKED) &&
2265 (ieee->iw_mode == IW_MODE_INFRA) &&
2266 (!memcmp(header->addr2,ieee->current_network.bssid,ETH_ALEN))){
2267 ieee->state = IEEE80211_ASSOCIATING;
2268 ieee->softmac_stats.reassoc++;
2270 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
2271 queue_work(ieee->wq, &ieee->associate_procedure_wq);
2281 //dev_kfree_skb_any(skb);
2287 /* following are for a simplier TX queue management.
2288 * Instead of using netif_[stop/wake]_queue the driver
2289 * will uses these two function (plus a reset one), that
2290 * will internally uses the kernel netif_* and takes
2291 * care of the ieee802.11 fragmentation.
2292 * So the driver receives a fragment per time and might
2293 * call the stop function when it want without take care
2294 * to have enought room to TX an entire packet.
2295 * This might be useful if each fragment need it's own
2296 * descriptor, thus just keep a total free memory > than
2297 * the max fragmentation treshold is not enought.. If the
2298 * ieee802.11 stack passed a TXB struct then you needed
2299 * to keep N free descriptors where
2300 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2301 * In this way you need just one and the 802.11 stack
2302 * will take care of buffering fragments and pass them to
2303 * to the driver later, when it wakes the queue.
2306 void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee)
2310 unsigned long flags;
2313 spin_lock_irqsave(&ieee->lock,flags);
2315 if(ieee->queue_stop){
2316 IEEE80211DMESG("EE: IEEE hard_start_xmit invoked when kernel queue should be stopped");
2317 netif_stop_queue(ieee->dev);
2318 ieee->ieee_stats.swtxstop++;
2319 //dev_kfree_skb_any(skb);
2324 ieee->stats.tx_bytes+=skb->len;
2327 txb=ieee80211_skb_to_txb(ieee,skb);
2331 IEEE80211DMESG("WW: IEEE stack failed to provide txb");
2332 //dev_kfree_skb_any(skb);
2338 /* called with 2nd parm 0, no tx mgmt lock required */
2339 ieee80211_sta_wakeup(ieee,0);
2341 for(i = 0; i < txb->nr_frags; i++) {
2343 if (ieee->queue_stop){
2344 ieee->tx_pending.txb = txb;
2345 ieee->tx_pending.frag = i;
2348 ieee->softmac_data_hard_start_xmit(
2350 ieee->dev,ieee->rate);
2351 //(i+1)<txb->nr_frags);
2352 ieee->stats.tx_packets++;
2353 ieee->stats.tx_bytes += txb->fragments[i]->len;
2354 ieee->dev->trans_start = jiffies;
2358 ieee80211_txb_free(txb);
2361 spin_unlock_irqrestore(&ieee->lock,flags);
2365 /* called with ieee->lock acquired */
2366 void ieee80211_resume_tx(struct ieee80211_device *ieee)
2369 for(i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) {
2371 if (ieee->queue_stop){
2372 ieee->tx_pending.frag = i;
2376 ieee->softmac_data_hard_start_xmit(
2377 ieee->tx_pending.txb->fragments[i],
2378 ieee->dev,ieee->rate);
2379 //(i+1)<ieee->tx_pending.txb->nr_frags);
2380 ieee->stats.tx_packets++;
2381 ieee->dev->trans_start = jiffies;
2386 ieee80211_txb_free(ieee->tx_pending.txb);
2387 ieee->tx_pending.txb = NULL;
2391 void ieee80211_reset_queue(struct ieee80211_device *ieee)
2393 unsigned long flags;
2395 spin_lock_irqsave(&ieee->lock,flags);
2396 init_mgmt_queue(ieee);
2397 if (ieee->tx_pending.txb){
2398 ieee80211_txb_free(ieee->tx_pending.txb);
2399 ieee->tx_pending.txb = NULL;
2401 ieee->queue_stop = 0;
2402 spin_unlock_irqrestore(&ieee->lock,flags);
2406 void ieee80211_wake_queue(struct ieee80211_device *ieee)
2409 unsigned long flags;
2410 struct sk_buff *skb;
2411 struct ieee80211_hdr_3addr *header;
2413 spin_lock_irqsave(&ieee->lock,flags);
2414 if (! ieee->queue_stop) goto exit;
2416 ieee->queue_stop = 0;
2418 if(ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE){
2419 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))){
2421 header = (struct ieee80211_hdr_3addr *) skb->data;
2423 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2425 if (ieee->seq_ctrl[0] == 0xFFF)
2426 ieee->seq_ctrl[0] = 0;
2428 ieee->seq_ctrl[0]++;
2430 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2431 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
2432 dev_kfree_skb_any(skb);//edit by thomas
2435 if (!ieee->queue_stop && ieee->tx_pending.txb)
2436 ieee80211_resume_tx(ieee);
2438 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)){
2439 ieee->softmac_stats.swtxawake++;
2440 netif_wake_queue(ieee->dev);
2444 spin_unlock_irqrestore(&ieee->lock,flags);
2448 void ieee80211_stop_queue(struct ieee80211_device *ieee)
2450 //unsigned long flags;
2451 //spin_lock_irqsave(&ieee->lock,flags);
2453 if (! netif_queue_stopped(ieee->dev)){
2454 netif_stop_queue(ieee->dev);
2455 ieee->softmac_stats.swtxstop++;
2457 ieee->queue_stop = 1;
2458 //spin_unlock_irqrestore(&ieee->lock,flags);
2463 inline void ieee80211_randomize_cell(struct ieee80211_device *ieee)
2466 get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2468 /* an IBSS cell address must have the two less significant
2469 * bits of the first byte = 2
2471 ieee->current_network.bssid[0] &= ~0x01;
2472 ieee->current_network.bssid[0] |= 0x02;
2475 /* called in user context only */
2476 void ieee80211_start_master_bss(struct ieee80211_device *ieee)
2480 if (ieee->current_network.ssid_len == 0){
2481 strncpy(ieee->current_network.ssid,
2482 IEEE80211_DEFAULT_TX_ESSID,
2485 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2489 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2491 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2492 ieee->state = IEEE80211_LINKED;
2493 ieee->link_change(ieee->dev);
2494 notify_wx_assoc_event(ieee);
2496 if (ieee->data_hard_resume)
2497 ieee->data_hard_resume(ieee->dev);
2499 netif_carrier_on(ieee->dev);
2502 void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
2506 if (ieee->data_hard_resume)
2507 ieee->data_hard_resume(ieee->dev);
2509 netif_carrier_on(ieee->dev);
2513 void ieee80211_start_ibss_wq(struct work_struct *work)
2515 struct delayed_work *dwork = to_delayed_work(work);
2516 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
2518 /* iwconfig mode ad-hoc will schedule this and return
2519 * on the other hand this will block further iwconfig SET
2520 * operations because of the wx_sem hold.
2521 * Anyway some most set operations set a flag to speed-up
2522 * (abort) this wq (when syncro scanning) before sleeping
2526 down(&ieee->wx_sem);
2529 if (ieee->current_network.ssid_len == 0){
2530 strcpy(ieee->current_network.ssid,IEEE80211_DEFAULT_TX_ESSID);
2531 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2535 /* check if we have this cell in our network list */
2536 ieee80211_softmac_check_all_nets(ieee);
2538 #ifdef ENABLE_DOT11D
2539 if(ieee->state == IEEE80211_NOLINK)
2540 ieee->current_network.channel = 10;
2542 /* if not then the state is not linked. Maybe the user swithced to
2543 * ad-hoc mode just after being in monitor mode, or just after
2544 * being very few time in managed mode (so the card have had no
2545 * time to scan all the chans..) or we have just run up the iface
2546 * after setting ad-hoc mode. So we have to give another try..
2547 * Here, in ibss mode, should be safe to do this without extra care
2548 * (in bss mode we had to make sure no-one tryed to associate when
2549 * we had just checked the ieee->state and we was going to start the
2550 * scan) beacause in ibss mode the ieee80211_new_net function, when
2551 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2552 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2553 * scan, that will stop at the first round because it sees the state
2556 if (ieee->state == IEEE80211_NOLINK)
2557 ieee80211_start_scan_syncro(ieee);
2559 /* the network definitively is not here.. create a new cell */
2560 if (ieee->state == IEEE80211_NOLINK){
2561 printk("creating new IBSS cell\n");
2563 ieee80211_randomize_cell(ieee);
2565 if(ieee->modulation & IEEE80211_CCK_MODULATION){
2567 ieee->current_network.rates_len = 4;
2569 ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
2570 ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
2571 ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
2572 ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
2575 ieee->current_network.rates_len = 0;
2577 if(ieee->modulation & IEEE80211_OFDM_MODULATION){
2578 ieee->current_network.rates_ex_len = 8;
2580 ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
2581 ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
2582 ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
2583 ieee->current_network.rates_ex[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
2584 ieee->current_network.rates_ex[4] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
2585 ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
2586 ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
2587 ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
2591 ieee->current_network.rates_ex_len = 0;
2595 // By default, WMM function will be disabled in IBSS mode
2596 ieee->current_network.QoS_Enable = 0;
2598 ieee->current_network.atim_window = 0;
2599 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2600 if(ieee->short_slot)
2601 ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT;
2605 ieee->state = IEEE80211_LINKED;
2606 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2607 ieee->link_change(ieee->dev);
2609 notify_wx_assoc_event(ieee);
2611 ieee80211_start_send_beacons(ieee);
2612 printk(KERN_WARNING "after sending beacon packet!\n");
2614 if (ieee->data_hard_resume)
2615 ieee->data_hard_resume(ieee->dev);
2617 netif_carrier_on(ieee->dev);
2621 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
2623 queue_delayed_work(ieee->wq, &ieee->start_ibss_wq, 100);
2626 /* this is called only in user context, with wx_sem held */
2627 void ieee80211_start_bss(struct ieee80211_device *ieee)
2629 unsigned long flags;
2630 #ifdef ENABLE_DOT11D
2632 // Ref: 802.11d 11.1.3.3
2633 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2635 if(IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee))
2637 if(! ieee->bGlobalDomain)
2643 /* check if we have already found the net we
2644 * are interested in (if any).
2645 * if not (we are disassociated and we are not
2646 * in associating / authenticating phase) start the background scanning.
2648 ieee80211_softmac_check_all_nets(ieee);
2650 /* ensure no-one start an associating process (thus setting
2651 * the ieee->state to ieee80211_ASSOCIATING) while we
2652 * have just cheked it and we are going to enable scan.
2653 * The ieee80211_new_net function is always called with
2654 * lock held (from both ieee80211_softmac_check_all_nets and
2655 * the rx path), so we cannot be in the middle of such function
2657 spin_lock_irqsave(&ieee->lock, flags);
2660 // printk("start bss ENABLE_IPS\n");
2662 if (ieee->state == IEEE80211_NOLINK){
2663 ieee->actscanning = true;
2664 ieee80211_start_scan(ieee);
2667 spin_unlock_irqrestore(&ieee->lock, flags);
2670 /* called only in userspace context */
2671 void ieee80211_disassociate(struct ieee80211_device *ieee)
2673 netif_carrier_off(ieee->dev);
2675 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2676 ieee80211_reset_queue(ieee);
2678 if (ieee->data_hard_stop)
2679 ieee->data_hard_stop(ieee->dev);
2681 #ifdef ENABLE_DOT11D
2682 if(IS_DOT11D_ENABLE(ieee))
2685 ieee->state = IEEE80211_NOLINK;
2686 ieee->link_change(ieee->dev);
2687 notify_wx_assoc_event(ieee);
2690 void ieee80211_associate_retry_wq(struct work_struct *work)
2692 struct delayed_work *dwork = to_delayed_work(work);
2693 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2694 unsigned long flags;
2695 down(&ieee->wx_sem);
2696 if(!ieee->proto_started)
2698 if(ieee->state != IEEE80211_ASSOCIATING_RETRY)
2700 /* until we do not set the state to IEEE80211_NOLINK
2701 * there are no possibility to have someone else trying
2702 * to start an association procdure (we get here with
2703 * ieee->state = IEEE80211_ASSOCIATING).
2704 * When we set the state to IEEE80211_NOLINK it is possible
2705 * that the RX path run an attempt to associate, but
2706 * both ieee80211_softmac_check_all_nets and the
2707 * RX path works with ieee->lock held so there are no
2708 * problems. If we are still disassociated then start a scan.
2709 * the lock here is necessary to ensure no one try to start
2710 * an association procedure when we have just checked the
2711 * state and we are going to start the scan.
2713 ieee->state = IEEE80211_NOLINK;
2714 ieee->beinretry = true;
2715 ieee80211_softmac_check_all_nets(ieee);
2717 spin_lock_irqsave(&ieee->lock, flags);
2719 if(ieee->state == IEEE80211_NOLINK){
2720 ieee->beinretry = false;
2721 ieee->actscanning = true;
2722 ieee80211_start_scan(ieee);
2724 //YJ,add,080828, notify os here
2725 if(ieee->state == IEEE80211_NOLINK)
2727 notify_wx_assoc_event(ieee);
2730 spin_unlock_irqrestore(&ieee->lock, flags);
2736 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
2738 u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2740 struct sk_buff *skb = NULL;
2741 struct ieee80211_probe_response *b;
2743 skb = ieee80211_probe_resp(ieee, broadcast_addr);
2747 b = (struct ieee80211_probe_response *) skb->data;
2748 b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON);
2754 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee)
2756 struct sk_buff *skb;
2757 struct ieee80211_probe_response *b;
2759 skb = ieee80211_get_beacon_(ieee);
2763 b = (struct ieee80211_probe_response *) skb->data;
2764 b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2766 if (ieee->seq_ctrl[0] == 0xFFF)
2767 ieee->seq_ctrl[0] = 0;
2769 ieee->seq_ctrl[0]++;
2774 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
2776 ieee->sync_scan_hurryup = 1;
2777 down(&ieee->wx_sem);
2778 ieee80211_stop_protocol(ieee);
2783 void ieee80211_stop_protocol(struct ieee80211_device *ieee)
2785 if (!ieee->proto_started)
2788 ieee->proto_started = 0;
2790 ieee80211_stop_send_beacons(ieee);
2791 if((ieee->iw_mode == IW_MODE_INFRA)&&(ieee->state == IEEE80211_LINKED)) {
2792 SendDisassociation(ieee,NULL,WLAN_REASON_DISASSOC_STA_HAS_LEFT);
2794 del_timer_sync(&ieee->associate_timer);
2795 cancel_delayed_work(&ieee->associate_retry_wq);
2796 cancel_delayed_work(&ieee->start_ibss_wq);
2797 ieee80211_stop_scan(ieee);
2799 ieee80211_disassociate(ieee);
2802 void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee)
2804 ieee->sync_scan_hurryup = 0;
2805 down(&ieee->wx_sem);
2806 ieee80211_start_protocol(ieee);
2810 void ieee80211_start_protocol(struct ieee80211_device *ieee)
2815 if (ieee->proto_started)
2818 ieee->proto_started = 1;
2820 if (ieee->current_network.channel == 0){
2823 if (ch > MAX_CHANNEL_NUMBER)
2824 return; /* no channel found */
2826 #ifdef ENABLE_DOT11D
2827 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]);
2829 }while(!ieee->channel_map[ch]);
2832 ieee->current_network.channel = ch;
2835 if (ieee->current_network.beacon_interval == 0)
2836 ieee->current_network.beacon_interval = 100;
2837 ieee->set_chan(ieee->dev,ieee->current_network.channel);
2839 for(i = 0; i < 17; i++) {
2840 ieee->last_rxseq_num[i] = -1;
2841 ieee->last_rxfrag_num[i] = -1;
2842 ieee->last_packet_time[i] = 0;
2845 ieee->init_wmmparam_flag = 0;//reinitialize AC_xx_PARAM registers.
2848 /* if the user set the MAC of the ad-hoc cell and then
2849 * switch to managed mode, shall we make sure that association
2850 * attempts does not fail just because the user provide the essid
2851 * and the nic is still checking for the AP MAC ??
2853 switch (ieee->iw_mode) {
2855 ieee->iw_mode = IW_MODE_INFRA;
2856 //not set break here intentionly
2858 ieee80211_start_bss(ieee);
2862 ieee80211_start_ibss(ieee);
2865 case IW_MODE_MASTER:
2866 ieee80211_start_master_bss(ieee);
2869 case IW_MODE_MONITOR:
2870 ieee80211_start_monitor_mode(ieee);
2874 ieee->iw_mode = IW_MODE_INFRA;
2875 ieee80211_start_bss(ieee);
2881 #define DRV_NAME "Ieee80211"
2882 void ieee80211_softmac_init(struct ieee80211_device *ieee)
2885 memset(&ieee->current_network, 0, sizeof(struct ieee80211_network));
2887 ieee->state = IEEE80211_NOLINK;
2888 ieee->sync_scan_hurryup = 0;
2889 for(i = 0; i < 5; i++) {
2890 ieee->seq_ctrl[i] = 0;
2894 ieee->queue_stop = 0;
2896 ieee->softmac_features = 0; //so IEEE2100-like driver are happy
2899 ieee->proto_started = 0;
2900 ieee->basic_rate = IEEE80211_DEFAULT_BASIC_RATE;
2903 ieee->ps = IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST;
2905 // ieee->ps = IEEE80211_PS_DISABLED;
2907 ieee->sta_sleep = 0;
2909 ieee->bInactivePs = false;
2910 ieee->actscanning = false;
2911 ieee->ListenInterval = 2;
2912 ieee->NumRxDataInPeriod = 0; //YJ,add,080828
2913 ieee->NumRxBcnInPeriod = 0; //YJ,add,080828
2914 ieee->NumRxOkTotal = 0;//+by amy 080312
2915 ieee->NumRxUnicast = 0;//YJ,add,080828,for keep alive
2916 ieee->beinretry = false;
2917 ieee->bHwRadioOff = false;
2920 init_mgmt_queue(ieee);
2922 init_timer(&ieee->scan_timer);
2923 ieee->scan_timer.data = (unsigned long)ieee;
2924 ieee->scan_timer.function = ieee80211_softmac_scan_cb;
2926 ieee->tx_pending.txb = NULL;
2928 init_timer(&ieee->associate_timer);
2929 ieee->associate_timer.data = (unsigned long)ieee;
2930 ieee->associate_timer.function = ieee80211_associate_abort_cb;
2932 init_timer(&ieee->beacon_timer);
2933 ieee->beacon_timer.data = (unsigned long) ieee;
2934 ieee->beacon_timer.function = ieee80211_send_beacon_cb;
2936 #ifdef PF_SYNCTHREAD
2937 ieee->wq = create_workqueue(DRV_NAME,0);
2939 ieee->wq = create_workqueue(DRV_NAME);
2941 INIT_DELAYED_WORK(&ieee->start_ibss_wq,(void*) ieee80211_start_ibss_wq);
2942 INIT_WORK(&ieee->associate_complete_wq,(void*) ieee80211_associate_complete_wq);
2943 INIT_WORK(&ieee->associate_procedure_wq,(void*) ieee80211_associate_procedure_wq);
2944 INIT_DELAYED_WORK(&ieee->softmac_scan_wq,(void*) ieee80211_softmac_scan_wq);
2945 INIT_DELAYED_WORK(&ieee->associate_retry_wq,(void*) ieee80211_associate_retry_wq);
2946 INIT_WORK(&ieee->wx_sync_scan_wq,(void*) ieee80211_wx_sync_scan_wq);
2947 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2949 sema_init(&ieee->wx_sem, 1);
2950 sema_init(&ieee->scan_sem, 1);
2952 spin_lock_init(&ieee->mgmt_tx_lock);
2953 spin_lock_init(&ieee->beacon_lock);
2955 tasklet_init(&ieee->ps_task,
2956 (void(*)(unsigned long)) ieee80211_sta_ps,
2957 (unsigned long)ieee);
2958 #ifdef ENABLE_DOT11D
2959 ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
2963 void ieee80211_softmac_free(struct ieee80211_device *ieee)
2965 down(&ieee->wx_sem);
2967 del_timer_sync(&ieee->associate_timer);
2968 cancel_delayed_work(&ieee->associate_retry_wq);
2971 //add for RF power on power of by lizhaoming 080512
2972 cancel_delayed_work(&ieee->GPIOChangeRFWorkItem);
2974 destroy_workqueue(ieee->wq);
2975 #ifdef ENABLE_DOT11D
2976 if(NULL != ieee->pDot11dInfo)
2977 kfree(ieee->pDot11dInfo);
2982 /********************************************************
2983 * Start of WPA code. *
2984 * this is stolen from the ipw2200 driver *
2985 ********************************************************/
2988 static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
2990 /* This is called when wpa_supplicant loads and closes the driver
2992 printk("%s WPA\n",value ? "enabling" : "disabling");
2993 ieee->wpa_enabled = value;
2998 void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, int wpa_ie_len)
3000 /* make sure WPA is enabled */
3001 ieee80211_wpa_enable(ieee, 1);
3003 ieee80211_disassociate(ieee);
3007 static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, int reason)
3013 case IEEE_MLME_STA_DEAUTH:
3017 case IEEE_MLME_STA_DISASSOC:
3018 ieee80211_disassociate(ieee);
3022 printk("Unknown MLME request: %d\n", command);
3030 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
3031 struct ieee_param *param, int plen)
3035 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
3036 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
3039 if (param->u.wpa_ie.len) {
3040 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
3044 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
3045 kfree(ieee->wpa_ie);
3047 ieee->wpa_ie_len = param->u.wpa_ie.len;
3049 kfree(ieee->wpa_ie);
3050 ieee->wpa_ie = NULL;
3051 ieee->wpa_ie_len = 0;
3054 ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
3058 #define AUTH_ALG_OPEN_SYSTEM 0x1
3059 #define AUTH_ALG_SHARED_KEY 0x2
3061 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
3064 struct ieee80211_security sec = {
3065 .flags = SEC_AUTH_MODE,
3069 if (value & AUTH_ALG_SHARED_KEY) {
3070 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
3073 sec.auth_mode = WLAN_AUTH_OPEN;
3077 if (ieee->set_security)
3078 ieee->set_security(ieee->dev, &sec);
3085 static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value)
3088 unsigned long flags;
3091 case IEEE_PARAM_WPA_ENABLED:
3092 ret = ieee80211_wpa_enable(ieee, value);
3095 case IEEE_PARAM_TKIP_COUNTERMEASURES:
3096 ieee->tkip_countermeasures=value;
3099 case IEEE_PARAM_DROP_UNENCRYPTED: {
3102 * wpa_supplicant calls set_wpa_enabled when the driver
3103 * is loaded and unloaded, regardless of if WPA is being
3104 * used. No other calls are made which can be used to
3105 * determine if encryption will be used or not prior to
3106 * association being expected. If encryption is not being
3107 * used, drop_unencrypted is set to false, else true -- we
3108 * can use this to determine if the CAP_PRIVACY_ON bit should
3111 struct ieee80211_security sec = {
3112 .flags = SEC_ENABLED,
3115 ieee->drop_unencrypted = value;
3116 /* We only change SEC_LEVEL for open mode. Others
3117 * are set by ipw_wpa_set_encryption.
3120 sec.flags |= SEC_LEVEL;
3121 sec.level = SEC_LEVEL_0;
3124 sec.flags |= SEC_LEVEL;
3125 sec.level = SEC_LEVEL_1;
3127 if (ieee->set_security)
3128 ieee->set_security(ieee->dev, &sec);
3132 case IEEE_PARAM_PRIVACY_INVOKED:
3133 ieee->privacy_invoked=value;
3136 case IEEE_PARAM_AUTH_ALGS:
3137 ret = ieee80211_wpa_set_auth_algs(ieee, value);
3140 case IEEE_PARAM_IEEE_802_1X:
3141 ieee->ieee802_1x=value;
3143 case IEEE_PARAM_WPAX_SELECT:
3144 // added for WPA2 mixed mode
3145 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
3146 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
3147 ieee->wpax_type_set = 1;
3148 ieee->wpax_type_notify = value;
3149 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
3153 printk("Unknown WPA param: %d\n",name);
3160 /* implementation borrowed from hostap driver */
3162 static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
3163 struct ieee_param *param, int param_len)
3167 struct ieee80211_crypto_ops *ops;
3168 struct ieee80211_crypt_data **crypt;
3170 struct ieee80211_security sec = {
3174 param->u.crypt.err = 0;
3175 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
3178 (int) ((char *) param->u.crypt.key - (char *) param) +
3179 param->u.crypt.key_len) {
3180 printk("Len mismatch %d, %d\n", param_len,
3181 param->u.crypt.key_len);
3184 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3185 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3186 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3187 if (param->u.crypt.idx >= WEP_KEYS)
3189 crypt = &ieee->crypt[param->u.crypt.idx];
3194 if (strcmp(param->u.crypt.alg, "none") == 0) {
3199 sec.level = SEC_LEVEL_0;
3200 sec.flags |= SEC_ENABLED | SEC_LEVEL;
3201 ieee80211_crypt_delayed_deinit(ieee, crypt);
3208 sec.flags |= SEC_ENABLED;
3210 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3211 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
3212 strcmp(param->u.crypt.alg, "TKIP"))
3213 goto skip_host_crypt;
3215 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3216 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3217 request_module("ieee80211_crypt_wep");
3218 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3219 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3220 request_module("ieee80211_crypt_tkip");
3221 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3222 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3223 request_module("ieee80211_crypt_ccmp");
3224 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3227 printk("unknown crypto alg '%s'\n", param->u.crypt.alg);
3228 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
3233 if (*crypt == NULL || (*crypt)->ops != ops) {
3234 struct ieee80211_crypt_data *new_crypt;
3236 ieee80211_crypt_delayed_deinit(ieee, crypt);
3238 new_crypt = (struct ieee80211_crypt_data *)
3239 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
3240 if (new_crypt == NULL) {
3244 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3245 new_crypt->ops = ops;
3246 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
3248 new_crypt->ops->init(param->u.crypt.idx);
3250 if (new_crypt->priv == NULL) {
3252 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
3260 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
3261 (*crypt)->ops->set_key(param->u.crypt.key,
3262 param->u.crypt.key_len, param->u.crypt.seq,
3263 (*crypt)->priv) < 0) {
3264 printk("key setting failed\n");
3265 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
3271 if (param->u.crypt.set_tx) {
3272 ieee->tx_keyidx = param->u.crypt.idx;
3273 sec.active_key = param->u.crypt.idx;
3274 sec.flags |= SEC_ACTIVE_KEY;
3276 sec.flags &= ~SEC_ACTIVE_KEY;
3278 if (param->u.crypt.alg != NULL) {
3279 memcpy(sec.keys[param->u.crypt.idx],
3281 param->u.crypt.key_len);
3282 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3283 sec.flags |= (1 << param->u.crypt.idx);
3285 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
3286 sec.flags |= SEC_LEVEL;
3287 sec.level = SEC_LEVEL_1;
3288 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
3289 sec.flags |= SEC_LEVEL;
3290 sec.level = SEC_LEVEL_2;
3291 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
3292 sec.flags |= SEC_LEVEL;
3293 sec.level = SEC_LEVEL_3;
3297 if (ieee->set_security)
3298 ieee->set_security(ieee->dev, &sec);
3300 /* Do not reset port if card is in Managed mode since resetting will
3301 * generate new IEEE 802.11 authentication which may end up in looping
3302 * with IEEE 802.1X. If your hardware requires a reset after WEP
3303 * configuration (for example... Prism2), implement the reset_port in
3304 * the callbacks structures used to initialize the 802.11 stack. */
3305 if (ieee->reset_on_keychange &&
3306 ieee->iw_mode != IW_MODE_INFRA &&
3308 ieee->reset_port(ieee->dev)) {
3309 printk("reset_port failed\n");
3310 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
3317 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p)
3319 struct ieee_param *param;
3322 down(&ieee->wx_sem);
3323 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
3325 if (p->length < sizeof(struct ieee_param) || !p->pointer){
3330 param = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
3335 if (copy_from_user(param, p->pointer, p->length)) {
3341 switch (param->cmd) {
3343 case IEEE_CMD_SET_WPA_PARAM:
3344 ret = ieee80211_wpa_set_param(ieee, param->u.wpa_param.name,
3345 param->u.wpa_param.value);
3348 case IEEE_CMD_SET_WPA_IE:
3349 ret = ieee80211_wpa_set_wpa_ie(ieee, param, p->length);
3352 case IEEE_CMD_SET_ENCRYPTION:
3353 ret = ieee80211_wpa_set_encryption(ieee, param, p->length);
3357 ret = ieee80211_wpa_mlme(ieee, param->u.mlme.command,
3358 param->u.mlme.reason_code);
3362 printk("Unknown WPA supplicant request: %d\n",param->cmd);
3367 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3377 void notify_wx_assoc_event(struct ieee80211_device *ieee)
3379 union iwreq_data wrqu;
3380 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3381 if (ieee->state == IEEE80211_LINKED)
3382 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN);
3384 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
3385 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);
3390 EXPORT_SYMBOL(ieee80211_get_beacon);
3391 EXPORT_SYMBOL(ieee80211_wake_queue);
3392 EXPORT_SYMBOL(ieee80211_stop_queue);
3393 EXPORT_SYMBOL(ieee80211_reset_queue);
3394 EXPORT_SYMBOL(ieee80211_softmac_stop_protocol);
3395 EXPORT_SYMBOL(ieee80211_softmac_start_protocol);
3396 EXPORT_SYMBOL(ieee80211_is_shortslot);
3397 EXPORT_SYMBOL(ieee80211_is_54g);
3398 EXPORT_SYMBOL(ieee80211_wpa_supplicant_ioctl);
3399 EXPORT_SYMBOL(ieee80211_ps_tx_ack);
3400 EXPORT_SYMBOL(ieee80211_start_protocol);
3401 EXPORT_SYMBOL(ieee80211_stop_protocol);
3402 EXPORT_SYMBOL(notify_wx_assoc_event);
3403 EXPORT_SYMBOL(ieee80211_stop_send_beacons);
3404 EXPORT_SYMBOL(SendDisassociation);
3405 EXPORT_SYMBOL(ieee80211_disassociate);
3406 EXPORT_SYMBOL(ieee80211_start_scan);
3407 EXPORT_SYMBOL(ieee80211_softmac_ips_scan_syncro);
3408 EXPORT_SYMBOL(ieee80211_sta_ps_send_null_frame);