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>
25 u8 rsn_authen_cipher_suite[16][4] = {
26 {0x00,0x0F,0xAC,0x00}, //Use group key, //Reserved
27 {0x00,0x0F,0xAC,0x01}, //WEP-40 //RSNA default
28 {0x00,0x0F,0xAC,0x02}, //TKIP //NONE //{used just as default}
29 {0x00,0x0F,0xAC,0x03}, //WRAP-historical
30 {0x00,0x0F,0xAC,0x04}, //CCMP
31 {0x00,0x0F,0xAC,0x05}, //WEP-104
34 short ieee80211_is_54g(struct ieee80211_network net)
36 return ((net.rates_ex_len > 0) || (net.rates_len > 4));
39 short ieee80211_is_shortslot(struct ieee80211_network net)
41 return (net.capability & WLAN_CAPABILITY_SHORT_SLOT);
44 /* returns the total length needed for pleacing the RATE MFIE
45 * tag and the EXTENDED RATE MFIE tag if needed.
46 * It encludes two bytes per tag for the tag itself and its len
48 unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device *ieee)
50 unsigned int rate_len = 0;
52 if (ieee->modulation & IEEE80211_CCK_MODULATION)
53 rate_len = IEEE80211_CCK_RATE_LEN + 2;
55 if (ieee->modulation & IEEE80211_OFDM_MODULATION)
57 rate_len += IEEE80211_OFDM_RATE_LEN + 2;
62 /* pleace the MFIE rate, tag to the memory (double) poined.
63 * Then it updates the pointer so that
64 * it points after the new MFIE tag added.
66 void ieee80211_MFIE_Brate(struct ieee80211_device *ieee, u8 **tag_p)
70 if (ieee->modulation & IEEE80211_CCK_MODULATION){
71 *tag++ = MFIE_TYPE_RATES;
73 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
74 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
75 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
76 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
79 /* We may add an option for custom rates that specific HW might support */
83 void ieee80211_MFIE_Grate(struct ieee80211_device *ieee, u8 **tag_p)
87 if (ieee->modulation & IEEE80211_OFDM_MODULATION){
89 *tag++ = MFIE_TYPE_RATES_EX;
91 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
92 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
93 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
94 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
95 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
96 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
97 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
98 *tag++ = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
102 /* We may add an option for custom rates that specific HW might support */
107 void ieee80211_WMM_Info(struct ieee80211_device *ieee, u8 **tag_p) {
110 *tag++ = MFIE_TYPE_GENERIC; //0
119 if(ieee->current_network.wmm_info & 0x80) {
120 *tag++ = 0x0f|MAX_SP_Len;
130 void ieee80211_TURBO_Info(struct ieee80211_device *ieee, u8 **tag_p) {
133 *tag++ = MFIE_TYPE_GENERIC; //0
144 printk(KERN_ALERT "This is enable turbo mode IE process\n");
147 void enqueue_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb)
150 nh = (ieee->mgmt_queue_head +1) % MGMT_QUEUE_NUM;
153 * if the queue is full but we have newer frames then
154 * just overwrites the oldest.
156 * if (nh == ieee->mgmt_queue_tail)
159 ieee->mgmt_queue_head = nh;
160 ieee->mgmt_queue_ring[nh] = skb;
165 struct sk_buff *dequeue_mgmt(struct ieee80211_device *ieee)
169 if(ieee->mgmt_queue_tail == ieee->mgmt_queue_head)
172 ret = ieee->mgmt_queue_ring[ieee->mgmt_queue_tail];
174 ieee->mgmt_queue_tail =
175 (ieee->mgmt_queue_tail+1) % MGMT_QUEUE_NUM;
180 void init_mgmt_queue(struct ieee80211_device *ieee)
182 ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0;
186 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl);
188 inline void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
191 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
192 struct ieee80211_hdr_3addr *header=
193 (struct ieee80211_hdr_3addr *) skb->data;
196 spin_lock_irqsave(&ieee->lock, flags);
198 /* called with 2nd param 0, no mgmt lock required */
199 ieee80211_sta_wakeup(ieee,0);
202 if(ieee->queue_stop){
204 enqueue_mgmt(ieee,skb);
206 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4);
208 if (ieee->seq_ctrl[0] == 0xFFF)
209 ieee->seq_ctrl[0] = 0;
213 /* avoid watchdog triggers */
214 ieee->dev->trans_start = jiffies;
215 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
218 spin_unlock_irqrestore(&ieee->lock, flags);
220 spin_unlock_irqrestore(&ieee->lock, flags);
221 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags);
223 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
225 if (ieee->seq_ctrl[0] == 0xFFF)
226 ieee->seq_ctrl[0] = 0;
230 /* avoid watchdog triggers */
231 ieee->dev->trans_start = jiffies;
232 ieee->softmac_hard_start_xmit(skb,ieee->dev);
234 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags);
239 inline void softmac_ps_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee)
242 short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE;
243 struct ieee80211_hdr_3addr *header =
244 (struct ieee80211_hdr_3addr *) skb->data;
249 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
251 if (ieee->seq_ctrl[0] == 0xFFF)
252 ieee->seq_ctrl[0] = 0;
256 /* avoid watchdog triggers */
257 ieee->dev->trans_start = jiffies;
258 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
262 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
264 if (ieee->seq_ctrl[0] == 0xFFF)
265 ieee->seq_ctrl[0] = 0;
269 /* avoid watchdog triggers */
270 ieee->dev->trans_start = jiffies;
271 ieee->softmac_hard_start_xmit(skb,ieee->dev);
274 // dev_kfree_skb_any(skb);//edit by thomas
276 //by amy for power save
277 inline struct sk_buff *ieee80211_disassociate_skb(
278 struct ieee80211_network *beacon,
279 struct ieee80211_device *ieee,
283 struct ieee80211_disassoc_frame *disass;
285 skb = dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame));
289 disass = (struct ieee80211_disassoc_frame *) skb_put(skb,sizeof(struct ieee80211_disassoc_frame));
290 disass->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_DISASSOC);
291 disass->header.duration_id = 0;
293 memcpy(disass->header.addr1, beacon->bssid, ETH_ALEN);
294 memcpy(disass->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
295 memcpy(disass->header.addr3, beacon->bssid, ETH_ALEN);
297 disass->reasoncode = asRsn;
302 struct ieee80211_device *ieee,
307 struct ieee80211_network *beacon = &ieee->current_network;
309 skb = ieee80211_disassociate_skb(beacon,ieee,asRsn);
311 softmac_mgmt_xmit(skb, ieee);
312 //dev_kfree_skb_any(skb);//edit by thomas
316 //by amy for power save
317 inline struct sk_buff *ieee80211_probe_req(struct ieee80211_device *ieee)
319 unsigned int len,rate_len;
322 struct ieee80211_probe_request *req;
324 len = ieee->current_network.ssid_len;
326 rate_len = ieee80211_MFIE_rate_len(ieee);
328 skb = dev_alloc_skb(sizeof(struct ieee80211_probe_request) +
333 req = (struct ieee80211_probe_request *) skb_put(skb,sizeof(struct ieee80211_probe_request));
334 req->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
335 req->header.duration_id = 0; //FIXME: is this OK ?
337 memset(req->header.addr1, 0xff, ETH_ALEN);
338 memcpy(req->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
339 memset(req->header.addr3, 0xff, ETH_ALEN);
341 tag = (u8 *) skb_put(skb,len+2+rate_len);
343 *tag++ = MFIE_TYPE_SSID;
345 memcpy(tag, ieee->current_network.ssid, len);
347 ieee80211_MFIE_Brate(ieee,&tag);
348 ieee80211_MFIE_Grate(ieee,&tag);
353 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee);
355 void ext_ieee80211_send_beacon_wq(struct ieee80211_device *ieee)
359 //unsigned long flags;
361 skb = ieee80211_get_beacon_(ieee);
364 softmac_mgmt_xmit(skb, ieee);
365 ieee->softmac_stats.tx_beacons++;
366 dev_kfree_skb_any(skb);//edit by thomas
370 //printk(KERN_WARNING "[1] beacon sending!\n");
371 ieee->beacon_timer.expires = jiffies +
372 (MSECS( ieee->current_network.beacon_interval -5));
374 //spin_lock_irqsave(&ieee->beacon_lock,flags);
375 if(ieee->beacon_txing)
376 add_timer(&ieee->beacon_timer);
377 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
380 void ieee80211_send_beacon(struct ieee80211_device *ieee)
384 //unsigned long flags;
386 skb = ieee80211_get_beacon_(ieee);
389 softmac_mgmt_xmit(skb, ieee);
390 ieee->softmac_stats.tx_beacons++;
391 dev_kfree_skb_any(skb);//edit by thomas
394 //printk(KERN_WARNING "[1] beacon sending!\n");
395 ieee->beacon_timer.expires = jiffies +
396 (MSECS( ieee->current_network.beacon_interval -5));
398 //spin_lock_irqsave(&ieee->beacon_lock,flags);
399 if(ieee->beacon_txing)
400 add_timer(&ieee->beacon_timer);
401 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
405 void ieee80211_send_beacon_cb(unsigned long _ieee)
407 struct ieee80211_device *ieee =
408 (struct ieee80211_device *) _ieee;
411 spin_lock_irqsave(&ieee->beacon_lock, flags);
412 ieee80211_send_beacon(ieee);
413 spin_unlock_irqrestore(&ieee->beacon_lock, flags);
416 void ieee80211_send_probe(struct ieee80211_device *ieee)
420 skb = ieee80211_probe_req(ieee);
422 softmac_mgmt_xmit(skb, ieee);
423 ieee->softmac_stats.tx_probe_rq++;
424 //dev_kfree_skb_any(skb);//edit by thomas
428 void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
430 if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)){
431 ieee80211_send_probe(ieee);
432 ieee80211_send_probe(ieee);
436 /* this performs syncro scan blocking the caller until all channels
437 * in the allowed channel map has been checked.
439 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
442 u8 channel_map[MAX_CHANNEL_NUMBER+1];
443 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
444 down(&ieee->scan_sem);
445 // printk("==================> Sync scan\n");
452 if (ch > MAX_CHANNEL_NUMBER)
453 goto out; /* scan completed */
455 }while(!channel_map[ch]);
456 /* this fuction can be called in two situations
457 * 1- We have switched to ad-hoc mode and we are
458 * performing a complete syncro scan before conclude
459 * there are no interesting cell and to create a
460 * new one. In this case the link state is
461 * IEEE80211_NOLINK until we found an interesting cell.
462 * If so the ieee8021_new_net, called by the RX path
463 * will set the state to IEEE80211_LINKED, so we stop
465 * 2- We are linked and the root uses run iwlist scan.
466 * So we switch to IEEE80211_LINKED_SCANNING to remember
467 * that we are still logically linked (not interested in
468 * new network events, despite for updating the net list,
469 * but we are temporarly 'unlinked' as the driver shall
470 * not filter RX frames and the channel is changing.
471 * So the only situation in witch are interested is to check
472 * if the state become LINKED because of the #1 situation
475 if (ieee->state == IEEE80211_LINKED)
478 ieee->set_chan(ieee->dev, ch);
479 // printk("=====>channel=%d ",ch);
480 if(channel_map[ch] == 1)
482 // printk("====send probe request\n");
483 ieee80211_send_probe_requests(ieee);
485 /* this prevent excessive time wait when we
486 * need to wait for a syncro scan to end..
488 if (ieee->sync_scan_hurryup)
492 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
496 ieee->sync_scan_hurryup = 0;
498 if(IS_DOT11D_ENABLE(ieee))
499 DOT11D_ScanComplete(ieee);
502 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee)
505 unsigned int watch_dog = 0;
506 u8 channel_map[MAX_CHANNEL_NUMBER+1];
507 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
508 down(&ieee->scan_sem);
509 ch = ieee->current_network.channel;
510 // if(ieee->sync_scan_hurryup)
513 // printk("stop scan sync\n");
516 // printk("=======hh===============>ips scan\n");
519 /* this fuction can be called in two situations
520 * 1- We have switched to ad-hoc mode and we are
521 * performing a complete syncro scan before conclude
522 * there are no interesting cell and to create a
523 * new one. In this case the link state is
524 * IEEE80211_NOLINK until we found an interesting cell.
525 * If so the ieee8021_new_net, called by the RX path
526 * will set the state to IEEE80211_LINKED, so we stop
528 * 2- We are linked and the root uses run iwlist scan.
529 * So we switch to IEEE80211_LINKED_SCANNING to remember
530 * that we are still logically linked (not interested in
531 * new network events, despite for updating the net list,
532 * but we are temporarly 'unlinked' as the driver shall
533 * not filter RX frames and the channel is changing.
534 * So the only situation in witch are interested is to check
535 * if the state become LINKED because of the #1 situation
537 if (ieee->state == IEEE80211_LINKED)
541 if(channel_map[ieee->current_network.channel] > 0)
543 ieee->set_chan(ieee->dev, ieee->current_network.channel);
544 // printk("======>channel=%d ",ieee->current_network.channel);
546 if(channel_map[ieee->current_network.channel] == 1)
548 // printk("====send probe request\n");
549 ieee80211_send_probe_requests(ieee);
551 /* this prevent excessive time wait when we
552 * need to wait for a syncro scan to end..
554 // if (ieee->sync_scan_hurryup)
557 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME);
560 if (watch_dog++ >= MAX_CHANNEL_NUMBER)
561 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
562 goto out; /* scan completed */
564 ieee->current_network.channel = (ieee->current_network.channel + 1)%MAX_CHANNEL_NUMBER;
565 }while(!channel_map[ieee->current_network.channel]);
568 //ieee->sync_scan_hurryup = 0;
569 //ieee->set_chan(ieee->dev, ch);
570 //ieee->current_network.channel = ch;
571 ieee->actscanning = false;
573 if(IS_DOT11D_ENABLE(ieee))
574 DOT11D_ScanComplete(ieee);
578 void ieee80211_softmac_scan_wq(struct work_struct *work)
580 struct delayed_work *dwork = to_delayed_work(work);
581 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
582 static short watchdog = 0;
583 u8 channel_map[MAX_CHANNEL_NUMBER+1];
584 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
585 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
586 // printk("in %s\n",__func__);
587 down(&ieee->scan_sem);
590 ieee->current_network.channel =
591 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
592 if (watchdog++ > MAX_CHANNEL_NUMBER)
593 goto out; /* no good chans */
595 }while(!channel_map[ieee->current_network.channel]);
597 //printk("current_network.channel:%d\n", ieee->current_network.channel);
598 if (ieee->scanning == 0 )
600 printk("error out, scanning = 0\n");
603 ieee->set_chan(ieee->dev, ieee->current_network.channel);
604 if(channel_map[ieee->current_network.channel] == 1)
605 ieee80211_send_probe_requests(ieee);
607 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
611 ieee->actscanning = false;
616 if(IS_DOT11D_ENABLE(ieee))
617 DOT11D_ScanComplete(ieee);
621 void ieee80211_softmac_scan_wq(struct work_struct *work)
623 struct delayed_work *dwork = to_delayed_work(work);
624 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, softmac_scan_wq);
626 u8 channel_map[MAX_CHANNEL_NUMBER+1];
627 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
628 // printk("enter scan wq,watchdog is %d\n",watchdog);
629 down(&ieee->scan_sem);
632 ieee->current_network.channel =
633 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
634 if (watchdog++ > MAX_CHANNEL_NUMBER)
635 goto out; /* no good chans */
637 }while(!channel_map[ieee->current_network.channel]);
639 // printk("current_network.channel:%d\n", ieee->current_network.channel);
640 if (ieee->scanning == 0 )
642 printk("error out, scanning = 0\n");
645 ieee->set_chan(ieee->dev, ieee->current_network.channel);
646 if(channel_map[ieee->current_network.channel] == 1)
647 ieee80211_send_probe_requests(ieee);
649 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
652 if(IS_DOT11D_ENABLE(ieee))
653 DOT11D_ScanComplete(ieee);
658 void ieee80211_beacons_start(struct ieee80211_device *ieee)
662 spin_lock_irqsave(&ieee->beacon_lock,flags);
664 ieee->beacon_txing = 1;
665 ieee80211_send_beacon(ieee);
667 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
670 void ieee80211_beacons_stop(struct ieee80211_device *ieee)
674 spin_lock_irqsave(&ieee->beacon_lock,flags);
676 ieee->beacon_txing = 0;
677 del_timer_sync(&ieee->beacon_timer);
679 spin_unlock_irqrestore(&ieee->beacon_lock,flags);
684 void ieee80211_stop_send_beacons(struct ieee80211_device *ieee)
686 if(ieee->stop_send_beacons)
687 ieee->stop_send_beacons(ieee->dev);
688 if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
689 ieee80211_beacons_stop(ieee);
693 void ieee80211_start_send_beacons(struct ieee80211_device *ieee)
695 if(ieee->start_send_beacons)
696 ieee->start_send_beacons(ieee->dev);
697 if(ieee->softmac_features & IEEE_SOFTMAC_BEACONS)
698 ieee80211_beacons_start(ieee);
702 void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
704 // unsigned long flags;
706 //ieee->sync_scan_hurryup = 1;
708 down(&ieee->scan_sem);
709 // spin_lock_irqsave(&ieee->lock, flags);
711 if (ieee->scanning == 1){
713 //del_timer_sync(&ieee->scan_timer);
714 cancel_delayed_work(&ieee->softmac_scan_wq);
717 // spin_unlock_irqrestore(&ieee->lock, flags);
721 void ieee80211_stop_scan(struct ieee80211_device *ieee)
723 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
724 ieee80211_softmac_stop_scan(ieee);
726 ieee->stop_scan(ieee->dev);
729 /* called with ieee->lock held */
730 void ieee80211_start_scan(struct ieee80211_device *ieee)
732 if(IS_DOT11D_ENABLE(ieee) )
734 if(IS_COUNTRY_IE_VALID(ieee))
736 RESET_CIE_WATCHDOG(ieee);
739 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
740 if (ieee->scanning == 0)
743 //ieee80211_softmac_scan(ieee);
744 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
745 //care this,1203,2007,by lawrence
747 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq,0);
751 ieee->start_scan(ieee->dev);
755 /* called with wx_sem held */
756 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
758 if(IS_DOT11D_ENABLE(ieee) )
760 if(IS_COUNTRY_IE_VALID(ieee))
762 RESET_CIE_WATCHDOG(ieee);
765 ieee->sync_scan_hurryup = 0;
767 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
768 ieee80211_softmac_scan_syncro(ieee);
770 ieee->scan_syncro(ieee->dev);
774 inline struct sk_buff *ieee80211_authentication_req(struct ieee80211_network *beacon,
775 struct ieee80211_device *ieee, int challengelen)
778 struct ieee80211_authentication *auth;
780 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication) + challengelen);
782 if (!skb) return NULL;
784 auth = (struct ieee80211_authentication *)
785 skb_put(skb, sizeof(struct ieee80211_authentication));
787 auth->header.frame_ctl = IEEE80211_STYPE_AUTH;
788 if (challengelen) auth->header.frame_ctl |= IEEE80211_FCTL_WEP;
790 auth->header.duration_id = 0x013a; //FIXME
792 memcpy(auth->header.addr1, beacon->bssid, ETH_ALEN);
793 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
794 memcpy(auth->header.addr3, beacon->bssid, ETH_ALEN);
796 auth->algorithm = ieee->open_wep ? WLAN_AUTH_OPEN : WLAN_AUTH_SHARED_KEY;
798 auth->transaction = cpu_to_le16(ieee->associate_seq);
799 ieee->associate_seq++;
801 auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS);
807 static struct sk_buff* ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *dest)
811 struct ieee80211_probe_response *beacon_buf;
814 int atim_len,erp_len;
815 struct ieee80211_crypt_data* crypt;
817 char *ssid = ieee->current_network.ssid;
818 int ssid_len = ieee->current_network.ssid_len;
819 int rate_len = ieee->current_network.rates_len+2;
820 int rate_ex_len = ieee->current_network.rates_ex_len;
821 int wpa_ie_len = ieee->wpa_ie_len;
822 if(rate_ex_len > 0) rate_ex_len+=2;
824 if(ieee->current_network.capability & WLAN_CAPABILITY_IBSS)
829 if(ieee80211_is_54g(ieee->current_network))
834 beacon_size = sizeof(struct ieee80211_probe_response)+
843 skb = dev_alloc_skb(beacon_size);
848 beacon_buf = (struct ieee80211_probe_response*) skb_put(skb, beacon_size);
850 memcpy (beacon_buf->header.addr1, dest,ETH_ALEN);
851 memcpy (beacon_buf->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
852 memcpy (beacon_buf->header.addr3, ieee->current_network.bssid, ETH_ALEN);
854 beacon_buf->header.duration_id = 0; //FIXME
855 beacon_buf->beacon_interval =
856 cpu_to_le16(ieee->current_network.beacon_interval);
857 beacon_buf->capability =
858 cpu_to_le16(ieee->current_network.capability & WLAN_CAPABILITY_IBSS);
860 if(ieee->short_slot && (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_SLOT))
861 cpu_to_le16((beacon_buf->capability |= WLAN_CAPABILITY_SHORT_SLOT));
863 crypt = ieee->crypt[ieee->tx_keyidx];
865 encrypt = ieee->host_encrypt && crypt && crypt->ops &&
866 ((0 == strcmp(crypt->ops->name, "WEP")) || wpa_ie_len);
869 beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
872 beacon_buf->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_RESP);
874 beacon_buf->info_element.id = MFIE_TYPE_SSID;
875 beacon_buf->info_element.len = ssid_len;
877 tag = (u8*) beacon_buf->info_element.data;
879 memcpy(tag, ssid, ssid_len);
883 *(tag++) = MFIE_TYPE_RATES;
884 *(tag++) = rate_len-2;
885 memcpy(tag,ieee->current_network.rates,rate_len-2);
888 *(tag++) = MFIE_TYPE_DS_SET;
890 *(tag++) = ieee->current_network.channel;
893 *(tag++) = MFIE_TYPE_IBSS_SET;
895 *((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window);
900 *(tag++) = MFIE_TYPE_ERP;
906 *(tag++) = MFIE_TYPE_RATES_EX;
907 *(tag++) = rate_ex_len-2;
908 memcpy(tag,ieee->current_network.rates_ex,rate_ex_len-2);
914 if (ieee->iw_mode == IW_MODE_ADHOC)
915 {//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
916 memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4);
919 memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len);
922 skb->dev = ieee->dev;
926 struct sk_buff* ieee80211_assoc_resp(struct ieee80211_device *ieee, u8 *dest)
931 struct ieee80211_crypt_data* crypt;
932 struct ieee80211_assoc_response_frame *assoc;
935 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
936 int len = sizeof(struct ieee80211_assoc_response_frame) + rate_len;
938 skb = dev_alloc_skb(len);
943 assoc = (struct ieee80211_assoc_response_frame *)
944 skb_put(skb,sizeof(struct ieee80211_assoc_response_frame));
946 assoc->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP);
947 memcpy(assoc->header.addr1, dest,ETH_ALEN);
948 memcpy(assoc->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
949 memcpy(assoc->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
950 assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ?
951 WLAN_CAPABILITY_BSS : WLAN_CAPABILITY_IBSS);
955 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
957 if (ieee->host_encrypt)
958 crypt = ieee->crypt[ieee->tx_keyidx];
961 encrypt = ( crypt && crypt->ops);
964 assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
967 assoc->aid = cpu_to_le16(ieee->assoc_id);
968 if (ieee->assoc_id == 0x2007) ieee->assoc_id=0;
969 else ieee->assoc_id++;
971 tag = (u8*) skb_put(skb, rate_len);
973 ieee80211_MFIE_Brate(ieee, &tag);
974 ieee80211_MFIE_Grate(ieee, &tag);
979 struct sk_buff* ieee80211_auth_resp(struct ieee80211_device *ieee,int status, u8 *dest)
982 struct ieee80211_authentication *auth;
984 skb = dev_alloc_skb(sizeof(struct ieee80211_authentication)+1);
989 skb->len = sizeof(struct ieee80211_authentication);
991 auth = (struct ieee80211_authentication *)skb->data;
993 auth->status = cpu_to_le16(status);
994 auth->transaction = cpu_to_le16(2);
995 auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN);
997 memcpy(auth->header.addr3, ieee->dev->dev_addr, ETH_ALEN);
998 memcpy(auth->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
999 memcpy(auth->header.addr1, dest, ETH_ALEN);
1000 auth->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_AUTH);
1006 struct sk_buff* ieee80211_null_func(struct ieee80211_device *ieee,short pwr)
1008 struct sk_buff *skb;
1009 struct ieee80211_hdr_3addr* hdr;
1011 skb = dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr));
1016 hdr = (struct ieee80211_hdr_3addr*)skb_put(skb,sizeof(struct ieee80211_hdr_3addr));
1018 memcpy(hdr->addr1, ieee->current_network.bssid, ETH_ALEN);
1019 memcpy(hdr->addr2, ieee->dev->dev_addr, ETH_ALEN);
1020 memcpy(hdr->addr3, ieee->current_network.bssid, ETH_ALEN);
1022 hdr->frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
1023 IEEE80211_STYPE_NULLFUNC | IEEE80211_FCTL_TODS |
1024 (pwr ? IEEE80211_FCTL_PM:0));
1032 void ieee80211_resp_to_assoc_rq(struct ieee80211_device *ieee, u8* dest)
1034 struct sk_buff *buf = ieee80211_assoc_resp(ieee, dest);
1037 softmac_mgmt_xmit(buf, ieee);
1038 dev_kfree_skb_any(buf);//edit by thomas
1043 void ieee80211_resp_to_auth(struct ieee80211_device *ieee, int s, u8* dest)
1045 struct sk_buff *buf = ieee80211_auth_resp(ieee, s, dest);
1048 softmac_mgmt_xmit(buf, ieee);
1049 dev_kfree_skb_any(buf);//edit by thomas
1054 void ieee80211_resp_to_probe(struct ieee80211_device *ieee, u8 *dest)
1057 struct sk_buff *buf = ieee80211_probe_resp(ieee, dest);
1060 softmac_mgmt_xmit(buf, ieee);
1061 dev_kfree_skb_any(buf);//edit by thomas
1066 inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beacon,struct ieee80211_device *ieee)
1068 struct sk_buff *skb;
1069 //unsigned long flags;
1071 struct ieee80211_assoc_request_frame *hdr;
1073 //short info_addr = 0;
1075 //u16 suite_count = 0;
1076 //u8 suit_select = 0;
1077 unsigned int wpa_len = beacon->wpa_ie_len;
1078 //struct net_device *dev = ieee->dev;
1079 //union iwreq_data wrqu;
1083 // for testing purpose
1084 unsigned int rsn_len = beacon->rsn_ie_len;
1086 unsigned int rsn_len = beacon->rsn_ie_len - 4;
1088 unsigned int rate_len = ieee80211_MFIE_rate_len(ieee);
1089 unsigned int wmm_info_len = beacon->QoS_Enable?9:0;
1090 unsigned int turbo_info_len = beacon->Turbo_Enable?9:0;
1092 u8 encry_proto = ieee->wpax_type_notify & 0xff;
1093 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1094 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1098 //[0] Notify type of encryption: WPA/WPA2
1099 //[1] pair wise type
1101 if(ieee->wpax_type_set) {
1102 if (IEEE_PROTO_WPA == encry_proto) {
1104 } else if (IEEE_PROTO_RSN == encry_proto) {
1108 len = sizeof(struct ieee80211_assoc_request_frame)+
1109 + beacon->ssid_len//essid tagged val
1110 + rate_len//rates tagged val
1116 skb = dev_alloc_skb(len);
1121 hdr = (struct ieee80211_assoc_request_frame *)
1122 skb_put(skb, sizeof(struct ieee80211_assoc_request_frame));
1125 hdr->header.frame_ctl = IEEE80211_STYPE_ASSOC_REQ;
1126 hdr->header.duration_id= 37; //FIXME
1127 memcpy(hdr->header.addr1, beacon->bssid, ETH_ALEN);
1128 memcpy(hdr->header.addr2, ieee->dev->dev_addr, ETH_ALEN);
1129 memcpy(hdr->header.addr3, beacon->bssid, ETH_ALEN);
1130 memcpy(ieee->ap_mac_addr, beacon->bssid, ETH_ALEN);//for HW security, John
1132 hdr->capability = cpu_to_le16(WLAN_CAPABILITY_BSS);
1133 if (beacon->capability & WLAN_CAPABILITY_PRIVACY )
1134 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
1135 if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1136 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
1138 if(ieee->short_slot)
1139 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1141 hdr->listen_interval = 0xa; //FIXME
1143 hdr->info_element.id = MFIE_TYPE_SSID;
1145 hdr->info_element.len = beacon->ssid_len;
1146 tag = skb_put(skb, beacon->ssid_len);
1147 memcpy(tag, beacon->ssid, beacon->ssid_len);
1149 tag = skb_put(skb, rate_len);
1151 ieee80211_MFIE_Brate(ieee, &tag);
1152 ieee80211_MFIE_Grate(ieee, &tag);
1154 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1155 //choose AES encryption as default algorithm while using mixed mode
1157 tag = skb_put(skb,ieee->wpa_ie_len);
1158 memcpy(tag,ieee->wpa_ie,ieee->wpa_ie_len);
1160 tag = skb_put(skb,wmm_info_len);
1162 ieee80211_WMM_Info(ieee, &tag);
1164 tag = skb_put(skb,turbo_info_len);
1165 if(turbo_info_len) {
1166 ieee80211_TURBO_Info(ieee, &tag);
1172 void ieee80211_associate_abort(struct ieee80211_device *ieee)
1175 unsigned long flags;
1176 spin_lock_irqsave(&ieee->lock, flags);
1178 ieee->associate_seq++;
1180 /* don't scan, and avoid to have the RX path possibily
1181 * try again to associate. Even do not react to AUTH or
1182 * ASSOC response. Just wait for the retry wq to be scheduled.
1183 * Here we will check if there are good nets to associate
1184 * with, so we retry or just get back to NO_LINK and scanning
1186 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING){
1187 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1188 ieee->softmac_stats.no_auth_rs++;
1190 IEEE80211_DEBUG_MGMT("Association failed\n");
1191 ieee->softmac_stats.no_ass_rs++;
1194 ieee->state = IEEE80211_ASSOCIATING_RETRY;
1196 queue_delayed_work(ieee->wq, &ieee->associate_retry_wq,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME);
1198 spin_unlock_irqrestore(&ieee->lock, flags);
1201 void ieee80211_associate_abort_cb(unsigned long dev)
1203 ieee80211_associate_abort((struct ieee80211_device *) dev);
1207 void ieee80211_associate_step1(struct ieee80211_device *ieee)
1209 struct ieee80211_network *beacon = &ieee->current_network;
1210 struct sk_buff *skb;
1212 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1213 ieee->softmac_stats.tx_auth_rq++;
1214 skb=ieee80211_authentication_req(beacon, ieee, 0);
1217 ieee80211_associate_abort(ieee);
1220 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
1221 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1222 //printk("---Sending authentication request\n");
1223 softmac_mgmt_xmit(skb, ieee);
1224 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1225 if(!timer_pending(&ieee->associate_timer)){
1226 ieee->associate_timer.expires = jiffies + (HZ / 2);
1227 add_timer(&ieee->associate_timer);
1229 //If call dev_kfree_skb_any,a warning will ocur....
1230 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1231 //So ... 1204 by lawrence.
1232 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1233 //dev_kfree_skb_any(skb);//edit by thomas
1237 void ieee80211_auth_challenge(struct ieee80211_device *ieee, u8 *challenge, int chlen)
1240 struct sk_buff *skb;
1241 struct ieee80211_network *beacon = &ieee->current_network;
1242 // int hlen = sizeof(struct ieee80211_authentication);
1243 del_timer_sync(&ieee->associate_timer);
1244 ieee->associate_seq++;
1245 ieee->softmac_stats.tx_auth_rq++;
1247 skb = ieee80211_authentication_req(beacon, ieee, chlen+2);
1249 ieee80211_associate_abort(ieee);
1251 c = skb_put(skb, chlen+2);
1252 *(c++) = MFIE_TYPE_CHALLENGE;
1254 memcpy(c, challenge, chlen);
1256 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1258 ieee80211_encrypt_fragment(ieee, skb, sizeof(struct ieee80211_hdr_3addr ));
1260 softmac_mgmt_xmit(skb, ieee);
1261 if (!timer_pending(&ieee->associate_timer)){
1262 //printk("=========>add timer again, to crash\n");
1263 ieee->associate_timer.expires = jiffies + (HZ / 2);
1264 add_timer(&ieee->associate_timer);
1266 dev_kfree_skb_any(skb);//edit by thomas
1271 void ieee80211_associate_step2(struct ieee80211_device *ieee)
1273 struct sk_buff* skb;
1274 struct ieee80211_network *beacon = &ieee->current_network;
1276 del_timer_sync(&ieee->associate_timer);
1278 IEEE80211_DEBUG_MGMT("Sending association request\n");
1279 ieee->softmac_stats.tx_ass_rq++;
1280 skb=ieee80211_association_req(beacon, ieee);
1282 ieee80211_associate_abort(ieee);
1284 softmac_mgmt_xmit(skb, ieee);
1285 if (!timer_pending(&ieee->associate_timer)){
1286 ieee->associate_timer.expires = jiffies + (HZ / 2);
1287 add_timer(&ieee->associate_timer);
1289 //dev_kfree_skb_any(skb);//edit by thomas
1293 void ieee80211_associate_complete_wq(struct work_struct *work)
1295 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq);
1297 printk(KERN_INFO "Associated successfully\n");
1298 if(ieee80211_is_54g(ieee->current_network) &&
1299 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1302 printk(KERN_INFO"Using G rates\n");
1305 printk(KERN_INFO"Using B rates\n");
1307 ieee->link_change(ieee->dev);
1308 notify_wx_assoc_event(ieee);
1309 if (ieee->data_hard_resume)
1310 ieee->data_hard_resume(ieee->dev);
1311 netif_carrier_on(ieee->dev);
1314 void ieee80211_associate_complete(struct ieee80211_device *ieee)
1317 del_timer_sync(&ieee->associate_timer);
1319 for(i = 0; i < 6; i++) {
1320 //ieee->seq_ctrl[i] = 0;
1322 ieee->state = IEEE80211_LINKED;
1323 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1325 queue_work(ieee->wq, &ieee->associate_complete_wq);
1328 void ieee80211_associate_procedure_wq(struct work_struct *work)
1330 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1332 ieee->sync_scan_hurryup = 1;
1333 down(&ieee->wx_sem);
1335 if (ieee->data_hard_stop)
1336 ieee->data_hard_stop(ieee->dev);
1338 ieee80211_stop_scan(ieee);
1339 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1341 ieee->associate_seq = 1;
1342 ieee80211_associate_step1(ieee);
1347 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
1349 u8 tmp_ssid[IW_ESSID_MAX_SIZE+1];
1350 int tmp_ssid_len = 0;
1352 short apset,ssidset,ssidbroad,apmatch,ssidmatch;
1354 /* we are interested in new new only if we are not associated
1355 * and we are not associating / authenticating
1357 if (ieee->state != IEEE80211_NOLINK)
1360 if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & WLAN_CAPABILITY_BSS))
1363 if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & WLAN_CAPABILITY_IBSS))
1367 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC){
1368 /* if the user specified the AP MAC, we need also the essid
1369 * This could be obtained by beacons or, if the network does not
1370 * broadcast it, it can be put manually.
1372 apset = ieee->wap_set;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1373 ssidset = ieee->ssid_set;//ieee->current_network.ssid[0] != '\0';
1374 ssidbroad = !(net->ssid_len == 0 || net->ssid[0]== '\0');
1375 apmatch = (memcmp(ieee->current_network.bssid, net->bssid, ETH_ALEN)==0);
1377 if(ieee->current_network.ssid_len != net->ssid_len)
1380 ssidmatch = (0==strncmp(ieee->current_network.ssid, net->ssid, net->ssid_len));
1382 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1383 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1385 if ( /* if the user set the AP check if match.
1386 * if the network does not broadcast essid we check the user supplyed ANY essid
1387 * if the network does broadcast and the user does not set essid it is OK
1388 * if the network does broadcast and the user did set essid chech if essid match
1390 ( apset && apmatch &&
1391 ((ssidset && ssidbroad && ssidmatch) || (ssidbroad && !ssidset) || (!ssidbroad && ssidset)) ) ||
1392 /* if the ap is not set, check that the user set the bssid
1393 * and the network does bradcast and that those two bssid matches
1395 (!apset && ssidset && ssidbroad && ssidmatch)
1399 /* if the essid is hidden replace it with the
1400 * essid provided by the user.
1403 strncpy(tmp_ssid, ieee->current_network.ssid, IW_ESSID_MAX_SIZE);
1404 tmp_ssid_len = ieee->current_network.ssid_len;
1406 memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
1409 strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
1410 ieee->current_network.ssid_len = tmp_ssid_len;
1412 printk(KERN_INFO"Linking with %s: channel is %d\n",ieee->current_network.ssid,ieee->current_network.channel);
1414 if (ieee->iw_mode == IW_MODE_INFRA){
1415 ieee->state = IEEE80211_ASSOCIATING;
1416 ieee->beinretry = false;
1417 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1419 if(ieee80211_is_54g(ieee->current_network) &&
1420 (ieee->modulation & IEEE80211_OFDM_MODULATION)){
1422 printk(KERN_INFO"Using G rates\n");
1425 printk(KERN_INFO"Using B rates\n");
1427 ieee->state = IEEE80211_LINKED;
1428 ieee->beinretry = false;
1436 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
1438 unsigned long flags;
1439 struct ieee80211_network *target;
1441 spin_lock_irqsave(&ieee->lock, flags);
1442 list_for_each_entry(target, &ieee->network_list, list) {
1444 /* if the state become different that NOLINK means
1445 * we had found what we are searching for
1448 if (ieee->state != IEEE80211_NOLINK)
1451 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
1452 ieee80211_softmac_new_net(ieee, target);
1455 spin_unlock_irqrestore(&ieee->lock, flags);
1460 static inline u16 auth_parse(struct sk_buff *skb, u8** challenge, int *chlen)
1462 struct ieee80211_authentication *a;
1464 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1465 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb->len);
1469 a = (struct ieee80211_authentication*) skb->data;
1470 if(skb->len > (sizeof(struct ieee80211_authentication) +3)){
1471 t = skb->data + sizeof(struct ieee80211_authentication);
1473 if(*(t++) == MFIE_TYPE_CHALLENGE){
1475 *challenge = (u8*)kmalloc(*chlen, GFP_ATOMIC);
1476 memcpy(*challenge, t, *chlen);
1480 return cpu_to_le16(a->status);
1485 int auth_rq_parse(struct sk_buff *skb,u8* dest)
1487 struct ieee80211_authentication *a;
1489 if (skb->len < (sizeof(struct ieee80211_authentication)-sizeof(struct ieee80211_info_element))){
1490 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb->len);
1493 a = (struct ieee80211_authentication*) skb->data;
1495 memcpy(dest,a->header.addr2, ETH_ALEN);
1497 if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN)
1498 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1500 return WLAN_STATUS_SUCCESS;
1503 static short probe_rq_parse(struct ieee80211_device *ieee, struct sk_buff *skb, u8 *src)
1510 struct ieee80211_hdr_3addr *header =
1511 (struct ieee80211_hdr_3addr *) skb->data;
1513 if (skb->len < sizeof (struct ieee80211_hdr_3addr ))
1514 return -1; /* corrupted */
1516 memcpy(src,header->addr2, ETH_ALEN);
1518 skbend = (u8*)skb->data + skb->len;
1520 tag = skb->data + sizeof (struct ieee80211_hdr_3addr );
1522 while (tag+1 < skbend){
1528 tag++; /* point to the len field */
1529 tag = tag + *(tag); /* point to the last data byte of the tag */
1530 tag++; /* point to the next tag */
1533 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1534 if (ssidlen == 0) return 1;
1536 if (!ssid) return 1; /* ssid not found in tagged param */
1537 return (!strncmp(ssid, ieee->current_network.ssid, ssidlen));
1541 int assoc_rq_parse(struct sk_buff *skb,u8* dest)
1543 struct ieee80211_assoc_request_frame *a;
1545 if (skb->len < (sizeof(struct ieee80211_assoc_request_frame) -
1546 sizeof(struct ieee80211_info_element))) {
1548 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb->len);
1552 a = (struct ieee80211_assoc_request_frame*) skb->data;
1554 memcpy(dest,a->header.addr2,ETH_ALEN);
1559 static inline u16 assoc_parse(struct sk_buff *skb, int *aid)
1561 struct ieee80211_assoc_response_frame *a;
1562 if (skb->len < sizeof(struct ieee80211_assoc_response_frame)){
1563 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
1567 a = (struct ieee80211_assoc_response_frame*) skb->data;
1568 *aid = le16_to_cpu(a->aid) & 0x3fff;
1569 return le16_to_cpu(a->status);
1573 ieee80211_rx_probe_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1577 //IEEE80211DMESG("Rx probe");
1578 ieee->softmac_stats.rx_probe_rq++;
1579 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1580 if (probe_rq_parse(ieee, skb, dest)){
1581 //IEEE80211DMESG("Was for me!");
1582 ieee->softmac_stats.tx_probe_rs++;
1583 ieee80211_resp_to_probe(ieee, dest);
1588 ieee80211_rx_auth_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1592 //IEEE80211DMESG("Rx probe");
1593 ieee->softmac_stats.rx_auth_rq++;
1595 if ((status = auth_rq_parse(skb, dest))!= -1){
1596 ieee80211_resp_to_auth(ieee, status, dest);
1598 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1603 ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb)
1607 //unsigned long flags;
1609 ieee->softmac_stats.rx_ass_rq++;
1610 if (assoc_rq_parse(skb,dest) != -1){
1611 ieee80211_resp_to_assoc_rq(ieee, dest);
1614 printk(KERN_INFO"New client associated: "MAC_FMT"\n", MAC_ARG(dest));
1619 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr)
1622 struct sk_buff *buf = ieee80211_null_func(ieee, pwr);
1625 softmac_ps_mgmt_xmit(buf, ieee);
1630 short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h, u32 *time_l)
1635 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1636 ieee->iw_mode != IW_MODE_INFRA ||
1637 ieee->state != IEEE80211_LINKED)
1641 dtim = ieee->current_network.dtim_data;
1644 if(!(dtim & IEEE80211_DTIM_VALID))
1647 timeout = ieee->current_network.beacon_interval;
1649 //printk("VALID\n");
1650 ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
1652 if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
1655 if(!time_after(jiffies, ieee->dev->trans_start + MSECS(timeout)))
1658 if(!time_after(jiffies, ieee->last_rx_ps_time + MSECS(timeout)))
1661 if((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE ) &&
1662 (ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
1666 *time_l = ieee->current_network.last_dtim_sta_time[0]
1667 + MSECS((ieee->current_network.beacon_interval));
1668 //* ieee->current_network.dtim_period));
1669 //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);
1673 *time_h = ieee->current_network.last_dtim_sta_time[1];
1674 if(time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
1683 inline void ieee80211_sta_ps(struct ieee80211_device *ieee)
1689 unsigned long flags,flags2;
1691 spin_lock_irqsave(&ieee->lock, flags);
1693 if((ieee->ps == IEEE80211_PS_DISABLED ||
1695 ieee->iw_mode != IW_MODE_INFRA ||
1696 ieee->state != IEEE80211_LINKED)){
1698 //#warning CHECK_LOCK_HERE
1699 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1701 ieee80211_sta_wakeup(ieee, 1);
1703 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1706 sleep = ieee80211_sta_ps_sleep(ieee,&th, &tl);
1707 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
1708 /* 2 wake, 1 sleep, 0 do nothing */
1714 if(ieee->sta_sleep == 1)
1715 ieee->enter_sleep_state(ieee->dev,th,tl);
1717 else if(ieee->sta_sleep == 0){
1718 // printk("send null 1\n");
1719 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1721 if(ieee->ps_is_queue_empty(ieee->dev)){
1724 ieee->sta_sleep = 2;
1726 ieee->ps_request_tx_ack(ieee->dev);
1728 ieee80211_sta_ps_send_null_frame(ieee,1);
1733 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1738 }else if(sleep == 2){
1739 //#warning CHECK_LOCK_HERE
1740 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1742 // printk("send wakeup packet\n");
1743 ieee80211_sta_wakeup(ieee,1);
1745 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1749 spin_unlock_irqrestore(&ieee->lock, flags);
1753 void ieee80211_sta_wakeup(struct ieee80211_device *ieee, short nl)
1755 if(ieee->sta_sleep == 0){
1757 // printk("Warning: driver is probably failing to report TX ps error\n");
1758 ieee->ps_request_tx_ack(ieee->dev);
1759 ieee80211_sta_ps_send_null_frame(ieee, 0);
1765 if(ieee->sta_sleep == 1)
1766 ieee->sta_wake_up(ieee->dev);
1768 ieee->sta_sleep = 0;
1771 ieee->ps_request_tx_ack(ieee->dev);
1772 ieee80211_sta_ps_send_null_frame(ieee, 0);
1776 void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success)
1778 unsigned long flags,flags2;
1780 spin_lock_irqsave(&ieee->lock, flags);
1781 if(ieee->sta_sleep == 2){
1782 /* Null frame with PS bit set */
1785 // printk("==================> %s::enter sleep state\n",__func__);
1786 ieee->sta_sleep = 1;
1787 ieee->enter_sleep_state(ieee->dev,ieee->ps_th,ieee->ps_tl);
1789 /* if the card report not success we can't be sure the AP
1790 * has not RXed so we can't assume the AP believe us awake
1793 /* 21112005 - tx again null without PS bit if lost */
1796 if((ieee->sta_sleep == 0) && !success){
1797 spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2);
1798 ieee80211_sta_ps_send_null_frame(ieee, 0);
1799 spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
1802 spin_unlock_irqrestore(&ieee->lock, flags);
1806 ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1807 struct ieee80211_rx_stats *rx_stats, u16 type,
1810 struct ieee80211_hdr_3addr *header = (struct ieee80211_hdr_3addr *) skb->data;
1815 struct ieee80211_assoc_response_frame *assoc_resp;
1816 struct ieee80211_info_element *info_element;
1818 if(!ieee->proto_started)
1821 if(ieee->sta_sleep || (ieee->ps != IEEE80211_PS_DISABLED &&
1822 ieee->iw_mode == IW_MODE_INFRA &&
1823 ieee->state == IEEE80211_LINKED))
1825 tasklet_schedule(&ieee->ps_task);
1827 if(WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_PROBE_RESP &&
1828 WLAN_FC_GET_STYPE(header->frame_ctl) != IEEE80211_STYPE_BEACON)
1829 ieee->last_rx_ps_time = jiffies;
1831 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
1833 case IEEE80211_STYPE_ASSOC_RESP:
1834 case IEEE80211_STYPE_REASSOC_RESP:
1836 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1837 WLAN_FC_GET_STYPE(header->frame_ctl));
1838 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1839 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
1840 ieee->iw_mode == IW_MODE_INFRA){
1841 if (0 == (errcode=assoc_parse(skb, &aid))){
1844 ieee->state=IEEE80211_LINKED;
1845 ieee->assoc_id = aid;
1846 ieee->softmac_stats.rx_ass_ok++;
1848 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
1849 if(1 == rx_stats->nic_type) //card type is 8187
1851 goto associate_complete;
1853 assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data;
1854 info_element = &assoc_resp->info_element;
1855 left = skb->len - ((void*)info_element - (void*)assoc_resp);
1857 while (left >= sizeof(struct ieee80211_info_element_hdr)) {
1858 if (sizeof(struct ieee80211_info_element_hdr) + info_element->len > left) {
1859 printk(KERN_WARNING "[re]associate reeponse error!");
1862 switch (info_element->id) {
1863 case MFIE_TYPE_GENERIC:
1864 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element->len);
1865 if (info_element->len >= 8 &&
1866 info_element->data[0] == 0x00 &&
1867 info_element->data[1] == 0x50 &&
1868 info_element->data[2] == 0xf2 &&
1869 info_element->data[3] == 0x02 &&
1870 info_element->data[4] == 0x01) {
1871 // Not care about version at present.
1872 //WMM Parameter Element
1873 memcpy(ieee->current_network.wmm_param,(u8*)(info_element->data\
1874 + 8),(info_element->len - 8));
1876 if (((ieee->current_network.wmm_info^info_element->data[6])& \
1877 0x0f)||(!ieee->init_wmmparam_flag)) {
1878 //refresh paramete element for current network
1879 // update the register parameter for hardware
1880 ieee->init_wmmparam_flag = 1;
1881 queue_work(ieee->wq, &ieee->wmm_param_update_wq);
1884 //update info_element for current network
1885 ieee->current_network.wmm_info = info_element->data[6];
1889 //nothing to do at present!!!
1893 left -= sizeof(struct ieee80211_info_element_hdr) +
1895 info_element = (struct ieee80211_info_element *)
1896 &info_element->data[info_element->len];
1898 if(!ieee->init_wmmparam_flag) //legacy AP, reset the AC_xx_param register
1900 queue_work(ieee->wq,&ieee->wmm_param_update_wq);
1901 ieee->init_wmmparam_flag = 1;//indicate AC_xx_param upated since last associate
1904 ieee80211_associate_complete(ieee);
1906 ieee->softmac_stats.rx_ass_err++;
1907 IEEE80211_DEBUG_MGMT(
1908 "Association response status code 0x%x\n",
1910 ieee80211_associate_abort(ieee);
1915 case IEEE80211_STYPE_ASSOC_REQ:
1916 case IEEE80211_STYPE_REASSOC_REQ:
1918 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1919 ieee->iw_mode == IW_MODE_MASTER)
1921 ieee80211_rx_assoc_rq(ieee, skb);
1924 case IEEE80211_STYPE_AUTH:
1926 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
1927 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
1928 ieee->iw_mode == IW_MODE_INFRA){
1930 IEEE80211_DEBUG_MGMT("Received authentication response");
1932 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
1933 if(ieee->open_wep || !challenge){
1934 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
1935 ieee->softmac_stats.rx_auth_rs_ok++;
1937 ieee80211_associate_step2(ieee);
1939 ieee80211_auth_challenge(ieee, challenge, chlen);
1942 ieee->softmac_stats.rx_auth_rs_err++;
1943 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode);
1944 ieee80211_associate_abort(ieee);
1947 }else if (ieee->iw_mode == IW_MODE_MASTER){
1948 ieee80211_rx_auth_rq(ieee, skb);
1953 case IEEE80211_STYPE_PROBE_REQ:
1955 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
1956 ((ieee->iw_mode == IW_MODE_ADHOC ||
1957 ieee->iw_mode == IW_MODE_MASTER) &&
1958 ieee->state == IEEE80211_LINKED))
1960 ieee80211_rx_probe_rq(ieee, skb);
1963 case IEEE80211_STYPE_DISASSOC:
1964 case IEEE80211_STYPE_DEAUTH:
1965 /* FIXME for now repeat all the association procedure
1966 * both for disassociation and deauthentication
1968 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1969 (ieee->state == IEEE80211_LINKED) &&
1970 (ieee->iw_mode == IW_MODE_INFRA) &&
1971 (!memcmp(header->addr2,ieee->current_network.bssid,ETH_ALEN))){
1972 ieee->state = IEEE80211_ASSOCIATING;
1973 ieee->softmac_stats.reassoc++;
1975 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
1976 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1986 //dev_kfree_skb_any(skb);
1992 /* following are for a simplier TX queue management.
1993 * Instead of using netif_[stop/wake]_queue the driver
1994 * will uses these two function (plus a reset one), that
1995 * will internally uses the kernel netif_* and takes
1996 * care of the ieee802.11 fragmentation.
1997 * So the driver receives a fragment per time and might
1998 * call the stop function when it want without take care
1999 * to have enought room to TX an entire packet.
2000 * This might be useful if each fragment need it's own
2001 * descriptor, thus just keep a total free memory > than
2002 * the max fragmentation treshold is not enought.. If the
2003 * ieee802.11 stack passed a TXB struct then you needed
2004 * to keep N free descriptors where
2005 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2006 * In this way you need just one and the 802.11 stack
2007 * will take care of buffering fragments and pass them to
2008 * to the driver later, when it wakes the queue.
2011 void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee)
2015 unsigned long flags;
2018 spin_lock_irqsave(&ieee->lock,flags);
2020 /* called with 2nd parm 0, no tx mgmt lock required */
2021 ieee80211_sta_wakeup(ieee,0);
2023 for(i = 0; i < txb->nr_frags; i++) {
2025 if (ieee->queue_stop){
2026 ieee->tx_pending.txb = txb;
2027 ieee->tx_pending.frag = i;
2030 ieee->softmac_data_hard_start_xmit(
2032 ieee->dev,ieee->rate);
2033 //(i+1)<txb->nr_frags);
2034 ieee->stats.tx_packets++;
2035 ieee->stats.tx_bytes += txb->fragments[i]->len;
2036 ieee->dev->trans_start = jiffies;
2040 ieee80211_txb_free(txb);
2043 spin_unlock_irqrestore(&ieee->lock,flags);
2047 /* called with ieee->lock acquired */
2048 void ieee80211_resume_tx(struct ieee80211_device *ieee)
2051 for(i = ieee->tx_pending.frag; i < ieee->tx_pending.txb->nr_frags; i++) {
2053 if (ieee->queue_stop){
2054 ieee->tx_pending.frag = i;
2058 ieee->softmac_data_hard_start_xmit(
2059 ieee->tx_pending.txb->fragments[i],
2060 ieee->dev,ieee->rate);
2061 //(i+1)<ieee->tx_pending.txb->nr_frags);
2062 ieee->stats.tx_packets++;
2063 ieee->dev->trans_start = jiffies;
2068 ieee80211_txb_free(ieee->tx_pending.txb);
2069 ieee->tx_pending.txb = NULL;
2073 void ieee80211_reset_queue(struct ieee80211_device *ieee)
2075 unsigned long flags;
2077 spin_lock_irqsave(&ieee->lock,flags);
2078 init_mgmt_queue(ieee);
2079 if (ieee->tx_pending.txb){
2080 ieee80211_txb_free(ieee->tx_pending.txb);
2081 ieee->tx_pending.txb = NULL;
2083 ieee->queue_stop = 0;
2084 spin_unlock_irqrestore(&ieee->lock,flags);
2088 void ieee80211_wake_queue(struct ieee80211_device *ieee)
2091 unsigned long flags;
2092 struct sk_buff *skb;
2093 struct ieee80211_hdr_3addr *header;
2095 spin_lock_irqsave(&ieee->lock,flags);
2096 if (! ieee->queue_stop) goto exit;
2098 ieee->queue_stop = 0;
2100 if(ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE){
2101 while (!ieee->queue_stop && (skb = dequeue_mgmt(ieee))){
2103 header = (struct ieee80211_hdr_3addr *) skb->data;
2105 header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2107 if (ieee->seq_ctrl[0] == 0xFFF)
2108 ieee->seq_ctrl[0] = 0;
2110 ieee->seq_ctrl[0]++;
2112 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2113 ieee->softmac_data_hard_start_xmit(skb,ieee->dev,ieee->basic_rate);
2114 dev_kfree_skb_any(skb);//edit by thomas
2117 if (!ieee->queue_stop && ieee->tx_pending.txb)
2118 ieee80211_resume_tx(ieee);
2120 if (!ieee->queue_stop && netif_queue_stopped(ieee->dev)){
2121 ieee->softmac_stats.swtxawake++;
2122 netif_wake_queue(ieee->dev);
2126 spin_unlock_irqrestore(&ieee->lock,flags);
2130 void ieee80211_stop_queue(struct ieee80211_device *ieee)
2132 //unsigned long flags;
2133 //spin_lock_irqsave(&ieee->lock,flags);
2135 if (! netif_queue_stopped(ieee->dev)){
2136 netif_stop_queue(ieee->dev);
2137 ieee->softmac_stats.swtxstop++;
2139 ieee->queue_stop = 1;
2140 //spin_unlock_irqrestore(&ieee->lock,flags);
2145 inline void ieee80211_randomize_cell(struct ieee80211_device *ieee)
2148 get_random_bytes(ieee->current_network.bssid, ETH_ALEN);
2150 /* an IBSS cell address must have the two less significant
2151 * bits of the first byte = 2
2153 ieee->current_network.bssid[0] &= ~0x01;
2154 ieee->current_network.bssid[0] |= 0x02;
2157 /* called in user context only */
2158 void ieee80211_start_master_bss(struct ieee80211_device *ieee)
2162 if (ieee->current_network.ssid_len == 0){
2163 strncpy(ieee->current_network.ssid,
2164 IEEE80211_DEFAULT_TX_ESSID,
2167 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2171 memcpy(ieee->current_network.bssid, ieee->dev->dev_addr, ETH_ALEN);
2173 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2174 ieee->state = IEEE80211_LINKED;
2175 ieee->link_change(ieee->dev);
2176 notify_wx_assoc_event(ieee);
2178 if (ieee->data_hard_resume)
2179 ieee->data_hard_resume(ieee->dev);
2181 netif_carrier_on(ieee->dev);
2184 void ieee80211_start_monitor_mode(struct ieee80211_device *ieee)
2188 if (ieee->data_hard_resume)
2189 ieee->data_hard_resume(ieee->dev);
2191 netif_carrier_on(ieee->dev);
2195 void ieee80211_start_ibss_wq(struct work_struct *work)
2197 struct delayed_work *dwork = to_delayed_work(work);
2198 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
2200 /* iwconfig mode ad-hoc will schedule this and return
2201 * on the other hand this will block further iwconfig SET
2202 * operations because of the wx_sem hold.
2203 * Anyway some most set operations set a flag to speed-up
2204 * (abort) this wq (when syncro scanning) before sleeping
2208 down(&ieee->wx_sem);
2211 if (ieee->current_network.ssid_len == 0){
2212 strcpy(ieee->current_network.ssid,IEEE80211_DEFAULT_TX_ESSID);
2213 ieee->current_network.ssid_len = strlen(IEEE80211_DEFAULT_TX_ESSID);
2217 /* check if we have this cell in our network list */
2218 ieee80211_softmac_check_all_nets(ieee);
2220 if(ieee->state == IEEE80211_NOLINK)
2221 ieee->current_network.channel = 10;
2222 /* if not then the state is not linked. Maybe the user swithced to
2223 * ad-hoc mode just after being in monitor mode, or just after
2224 * being very few time in managed mode (so the card have had no
2225 * time to scan all the chans..) or we have just run up the iface
2226 * after setting ad-hoc mode. So we have to give another try..
2227 * Here, in ibss mode, should be safe to do this without extra care
2228 * (in bss mode we had to make sure no-one tryed to associate when
2229 * we had just checked the ieee->state and we was going to start the
2230 * scan) beacause in ibss mode the ieee80211_new_net function, when
2231 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2232 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2233 * scan, that will stop at the first round because it sees the state
2236 if (ieee->state == IEEE80211_NOLINK)
2237 ieee80211_start_scan_syncro(ieee);
2239 /* the network definitively is not here.. create a new cell */
2240 if (ieee->state == IEEE80211_NOLINK){
2241 printk("creating new IBSS cell\n");
2243 ieee80211_randomize_cell(ieee);
2245 if(ieee->modulation & IEEE80211_CCK_MODULATION){
2247 ieee->current_network.rates_len = 4;
2249 ieee->current_network.rates[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
2250 ieee->current_network.rates[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
2251 ieee->current_network.rates[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
2252 ieee->current_network.rates[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
2255 ieee->current_network.rates_len = 0;
2257 if(ieee->modulation & IEEE80211_OFDM_MODULATION){
2258 ieee->current_network.rates_ex_len = 8;
2260 ieee->current_network.rates_ex[0] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
2261 ieee->current_network.rates_ex[1] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
2262 ieee->current_network.rates_ex[2] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
2263 ieee->current_network.rates_ex[3] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
2264 ieee->current_network.rates_ex[4] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
2265 ieee->current_network.rates_ex[5] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
2266 ieee->current_network.rates_ex[6] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
2267 ieee->current_network.rates_ex[7] = IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
2271 ieee->current_network.rates_ex_len = 0;
2275 // By default, WMM function will be disabled in IBSS mode
2276 ieee->current_network.QoS_Enable = 0;
2278 ieee->current_network.atim_window = 0;
2279 ieee->current_network.capability = WLAN_CAPABILITY_IBSS;
2280 if(ieee->short_slot)
2281 ieee->current_network.capability |= WLAN_CAPABILITY_SHORT_SLOT;
2285 ieee->state = IEEE80211_LINKED;
2286 ieee->set_chan(ieee->dev, ieee->current_network.channel);
2287 ieee->link_change(ieee->dev);
2289 notify_wx_assoc_event(ieee);
2291 ieee80211_start_send_beacons(ieee);
2292 printk(KERN_WARNING "after sending beacon packet!\n");
2294 if (ieee->data_hard_resume)
2295 ieee->data_hard_resume(ieee->dev);
2297 netif_carrier_on(ieee->dev);
2301 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
2303 queue_delayed_work(ieee->wq, &ieee->start_ibss_wq, 100);
2306 /* this is called only in user context, with wx_sem held */
2307 void ieee80211_start_bss(struct ieee80211_device *ieee)
2309 unsigned long flags;
2311 // Ref: 802.11d 11.1.3.3
2312 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2314 if(IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee))
2316 if(! ieee->bGlobalDomain)
2321 /* check if we have already found the net we
2322 * are interested in (if any).
2323 * if not (we are disassociated and we are not
2324 * in associating / authenticating phase) start the background scanning.
2326 ieee80211_softmac_check_all_nets(ieee);
2328 /* ensure no-one start an associating process (thus setting
2329 * the ieee->state to ieee80211_ASSOCIATING) while we
2330 * have just cheked it and we are going to enable scan.
2331 * The ieee80211_new_net function is always called with
2332 * lock held (from both ieee80211_softmac_check_all_nets and
2333 * the rx path), so we cannot be in the middle of such function
2335 spin_lock_irqsave(&ieee->lock, flags);
2338 // printk("start bss ENABLE_IPS\n");
2340 if (ieee->state == IEEE80211_NOLINK){
2341 ieee->actscanning = true;
2342 ieee80211_start_scan(ieee);
2345 spin_unlock_irqrestore(&ieee->lock, flags);
2348 /* called only in userspace context */
2349 void ieee80211_disassociate(struct ieee80211_device *ieee)
2351 netif_carrier_off(ieee->dev);
2353 if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
2354 ieee80211_reset_queue(ieee);
2356 if (ieee->data_hard_stop)
2357 ieee->data_hard_stop(ieee->dev);
2359 if(IS_DOT11D_ENABLE(ieee))
2361 ieee->state = IEEE80211_NOLINK;
2362 ieee->link_change(ieee->dev);
2363 notify_wx_assoc_event(ieee);
2366 void ieee80211_associate_retry_wq(struct work_struct *work)
2368 struct delayed_work *dwork = to_delayed_work(work);
2369 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2370 unsigned long flags;
2371 down(&ieee->wx_sem);
2372 if(!ieee->proto_started)
2374 if(ieee->state != IEEE80211_ASSOCIATING_RETRY)
2376 /* until we do not set the state to IEEE80211_NOLINK
2377 * there are no possibility to have someone else trying
2378 * to start an association procdure (we get here with
2379 * ieee->state = IEEE80211_ASSOCIATING).
2380 * When we set the state to IEEE80211_NOLINK it is possible
2381 * that the RX path run an attempt to associate, but
2382 * both ieee80211_softmac_check_all_nets and the
2383 * RX path works with ieee->lock held so there are no
2384 * problems. If we are still disassociated then start a scan.
2385 * the lock here is necessary to ensure no one try to start
2386 * an association procedure when we have just checked the
2387 * state and we are going to start the scan.
2389 ieee->state = IEEE80211_NOLINK;
2390 ieee->beinretry = true;
2391 ieee80211_softmac_check_all_nets(ieee);
2393 spin_lock_irqsave(&ieee->lock, flags);
2395 if(ieee->state == IEEE80211_NOLINK){
2396 ieee->beinretry = false;
2397 ieee->actscanning = true;
2398 ieee80211_start_scan(ieee);
2400 //YJ,add,080828, notify os here
2401 if(ieee->state == IEEE80211_NOLINK)
2403 notify_wx_assoc_event(ieee);
2406 spin_unlock_irqrestore(&ieee->lock, flags);
2412 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
2414 u8 broadcast_addr[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2416 struct sk_buff *skb = NULL;
2417 struct ieee80211_probe_response *b;
2419 skb = ieee80211_probe_resp(ieee, broadcast_addr);
2423 b = (struct ieee80211_probe_response *) skb->data;
2424 b->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_BEACON);
2430 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee)
2432 struct sk_buff *skb;
2433 struct ieee80211_probe_response *b;
2435 skb = ieee80211_get_beacon_(ieee);
2439 b = (struct ieee80211_probe_response *) skb->data;
2440 b->header.seq_ctrl = cpu_to_le16(ieee->seq_ctrl[0] << 4);
2442 if (ieee->seq_ctrl[0] == 0xFFF)
2443 ieee->seq_ctrl[0] = 0;
2445 ieee->seq_ctrl[0]++;
2450 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
2452 ieee->sync_scan_hurryup = 1;
2453 down(&ieee->wx_sem);
2454 ieee80211_stop_protocol(ieee);
2459 void ieee80211_stop_protocol(struct ieee80211_device *ieee)
2461 if (!ieee->proto_started)
2464 ieee->proto_started = 0;
2466 ieee80211_stop_send_beacons(ieee);
2467 if((ieee->iw_mode == IW_MODE_INFRA)&&(ieee->state == IEEE80211_LINKED)) {
2468 SendDisassociation(ieee,NULL,WLAN_REASON_DISASSOC_STA_HAS_LEFT);
2470 del_timer_sync(&ieee->associate_timer);
2471 cancel_delayed_work(&ieee->associate_retry_wq);
2472 cancel_delayed_work(&ieee->start_ibss_wq);
2473 ieee80211_stop_scan(ieee);
2475 ieee80211_disassociate(ieee);
2478 void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee)
2480 ieee->sync_scan_hurryup = 0;
2481 down(&ieee->wx_sem);
2482 ieee80211_start_protocol(ieee);
2486 void ieee80211_start_protocol(struct ieee80211_device *ieee)
2491 if (ieee->proto_started)
2494 ieee->proto_started = 1;
2496 if (ieee->current_network.channel == 0){
2499 if (ch > MAX_CHANNEL_NUMBER)
2500 return; /* no channel found */
2502 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]);
2504 ieee->current_network.channel = ch;
2507 if (ieee->current_network.beacon_interval == 0)
2508 ieee->current_network.beacon_interval = 100;
2509 ieee->set_chan(ieee->dev,ieee->current_network.channel);
2511 for(i = 0; i < 17; i++) {
2512 ieee->last_rxseq_num[i] = -1;
2513 ieee->last_rxfrag_num[i] = -1;
2514 ieee->last_packet_time[i] = 0;
2517 ieee->init_wmmparam_flag = 0;//reinitialize AC_xx_PARAM registers.
2520 /* if the user set the MAC of the ad-hoc cell and then
2521 * switch to managed mode, shall we make sure that association
2522 * attempts does not fail just because the user provide the essid
2523 * and the nic is still checking for the AP MAC ??
2525 switch (ieee->iw_mode) {
2527 ieee->iw_mode = IW_MODE_INFRA;
2528 //not set break here intentionly
2530 ieee80211_start_bss(ieee);
2534 ieee80211_start_ibss(ieee);
2537 case IW_MODE_MASTER:
2538 ieee80211_start_master_bss(ieee);
2541 case IW_MODE_MONITOR:
2542 ieee80211_start_monitor_mode(ieee);
2546 ieee->iw_mode = IW_MODE_INFRA;
2547 ieee80211_start_bss(ieee);
2553 #define DRV_NAME "Ieee80211"
2554 void ieee80211_softmac_init(struct ieee80211_device *ieee)
2557 memset(&ieee->current_network, 0, sizeof(struct ieee80211_network));
2559 ieee->state = IEEE80211_NOLINK;
2560 ieee->sync_scan_hurryup = 0;
2561 for(i = 0; i < 5; i++) {
2562 ieee->seq_ctrl[i] = 0;
2566 ieee->queue_stop = 0;
2568 ieee->softmac_features = 0; //so IEEE2100-like driver are happy
2571 ieee->proto_started = 0;
2572 ieee->basic_rate = IEEE80211_DEFAULT_BASIC_RATE;
2575 ieee->ps = IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST;
2577 // ieee->ps = IEEE80211_PS_DISABLED;
2579 ieee->sta_sleep = 0;
2581 ieee->bInactivePs = false;
2582 ieee->actscanning = false;
2583 ieee->ListenInterval = 2;
2584 ieee->NumRxDataInPeriod = 0; //YJ,add,080828
2585 ieee->NumRxBcnInPeriod = 0; //YJ,add,080828
2586 ieee->NumRxOkTotal = 0;//+by amy 080312
2587 ieee->NumRxUnicast = 0;//YJ,add,080828,for keep alive
2588 ieee->beinretry = false;
2589 ieee->bHwRadioOff = false;
2592 init_mgmt_queue(ieee);
2594 ieee->tx_pending.txb = NULL;
2596 init_timer(&ieee->associate_timer);
2597 ieee->associate_timer.data = (unsigned long)ieee;
2598 ieee->associate_timer.function = ieee80211_associate_abort_cb;
2600 init_timer(&ieee->beacon_timer);
2601 ieee->beacon_timer.data = (unsigned long) ieee;
2602 ieee->beacon_timer.function = ieee80211_send_beacon_cb;
2604 #ifdef PF_SYNCTHREAD
2605 ieee->wq = create_workqueue(DRV_NAME,0);
2607 ieee->wq = create_workqueue(DRV_NAME);
2609 INIT_DELAYED_WORK(&ieee->start_ibss_wq,(void*) ieee80211_start_ibss_wq);
2610 INIT_WORK(&ieee->associate_complete_wq,(void*) ieee80211_associate_complete_wq);
2611 INIT_WORK(&ieee->associate_procedure_wq,(void*) ieee80211_associate_procedure_wq);
2612 INIT_DELAYED_WORK(&ieee->softmac_scan_wq,(void*) ieee80211_softmac_scan_wq);
2613 INIT_DELAYED_WORK(&ieee->associate_retry_wq,(void*) ieee80211_associate_retry_wq);
2614 INIT_WORK(&ieee->wx_sync_scan_wq,(void*) ieee80211_wx_sync_scan_wq);
2615 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2617 sema_init(&ieee->wx_sem, 1);
2618 sema_init(&ieee->scan_sem, 1);
2620 spin_lock_init(&ieee->mgmt_tx_lock);
2621 spin_lock_init(&ieee->beacon_lock);
2623 tasklet_init(&ieee->ps_task,
2624 (void(*)(unsigned long)) ieee80211_sta_ps,
2625 (unsigned long)ieee);
2626 ieee->pDot11dInfo = kmalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
2629 void ieee80211_softmac_free(struct ieee80211_device *ieee)
2631 down(&ieee->wx_sem);
2633 del_timer_sync(&ieee->associate_timer);
2634 cancel_delayed_work(&ieee->associate_retry_wq);
2637 //add for RF power on power of by lizhaoming 080512
2638 cancel_delayed_work(&ieee->GPIOChangeRFWorkItem);
2640 destroy_workqueue(ieee->wq);
2641 if(NULL != ieee->pDot11dInfo)
2642 kfree(ieee->pDot11dInfo);
2646 /********************************************************
2647 * Start of WPA code. *
2648 * this is stolen from the ipw2200 driver *
2649 ********************************************************/
2652 static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
2654 /* This is called when wpa_supplicant loads and closes the driver
2656 printk("%s WPA\n",value ? "enabling" : "disabling");
2657 ieee->wpa_enabled = value;
2662 void ieee80211_wpa_assoc_frame(struct ieee80211_device *ieee, char *wpa_ie, int wpa_ie_len)
2664 /* make sure WPA is enabled */
2665 ieee80211_wpa_enable(ieee, 1);
2667 ieee80211_disassociate(ieee);
2671 static int ieee80211_wpa_mlme(struct ieee80211_device *ieee, int command, int reason)
2677 case IEEE_MLME_STA_DEAUTH:
2681 case IEEE_MLME_STA_DISASSOC:
2682 ieee80211_disassociate(ieee);
2686 printk("Unknown MLME request: %d\n", command);
2694 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee,
2695 struct ieee_param *param, int plen)
2699 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
2700 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
2703 if (param->u.wpa_ie.len) {
2704 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
2708 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
2709 kfree(ieee->wpa_ie);
2711 ieee->wpa_ie_len = param->u.wpa_ie.len;
2713 kfree(ieee->wpa_ie);
2714 ieee->wpa_ie = NULL;
2715 ieee->wpa_ie_len = 0;
2718 ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
2722 #define AUTH_ALG_OPEN_SYSTEM 0x1
2723 #define AUTH_ALG_SHARED_KEY 0x2
2725 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
2728 struct ieee80211_security sec = {
2729 .flags = SEC_AUTH_MODE,
2733 if (value & AUTH_ALG_SHARED_KEY) {
2734 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
2737 sec.auth_mode = WLAN_AUTH_OPEN;
2741 if (ieee->set_security)
2742 ieee->set_security(ieee->dev, &sec);
2749 static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value)
2752 unsigned long flags;
2755 case IEEE_PARAM_WPA_ENABLED:
2756 ret = ieee80211_wpa_enable(ieee, value);
2759 case IEEE_PARAM_TKIP_COUNTERMEASURES:
2760 ieee->tkip_countermeasures=value;
2763 case IEEE_PARAM_DROP_UNENCRYPTED: {
2766 * wpa_supplicant calls set_wpa_enabled when the driver
2767 * is loaded and unloaded, regardless of if WPA is being
2768 * used. No other calls are made which can be used to
2769 * determine if encryption will be used or not prior to
2770 * association being expected. If encryption is not being
2771 * used, drop_unencrypted is set to false, else true -- we
2772 * can use this to determine if the CAP_PRIVACY_ON bit should
2775 struct ieee80211_security sec = {
2776 .flags = SEC_ENABLED,
2779 ieee->drop_unencrypted = value;
2780 /* We only change SEC_LEVEL for open mode. Others
2781 * are set by ipw_wpa_set_encryption.
2784 sec.flags |= SEC_LEVEL;
2785 sec.level = SEC_LEVEL_0;
2788 sec.flags |= SEC_LEVEL;
2789 sec.level = SEC_LEVEL_1;
2791 if (ieee->set_security)
2792 ieee->set_security(ieee->dev, &sec);
2796 case IEEE_PARAM_PRIVACY_INVOKED:
2797 ieee->privacy_invoked=value;
2800 case IEEE_PARAM_AUTH_ALGS:
2801 ret = ieee80211_wpa_set_auth_algs(ieee, value);
2804 case IEEE_PARAM_IEEE_802_1X:
2805 ieee->ieee802_1x=value;
2807 case IEEE_PARAM_WPAX_SELECT:
2808 // added for WPA2 mixed mode
2809 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
2810 spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
2811 ieee->wpax_type_set = 1;
2812 ieee->wpax_type_notify = value;
2813 spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
2817 printk("Unknown WPA param: %d\n",name);
2824 /* implementation borrowed from hostap driver */
2826 static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
2827 struct ieee_param *param, int param_len)
2831 struct ieee80211_crypto_ops *ops;
2832 struct ieee80211_crypt_data **crypt;
2834 struct ieee80211_security sec = {
2838 param->u.crypt.err = 0;
2839 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
2842 (int) ((char *) param->u.crypt.key - (char *) param) +
2843 param->u.crypt.key_len) {
2844 printk("Len mismatch %d, %d\n", param_len,
2845 param->u.crypt.key_len);
2848 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
2849 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
2850 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
2851 if (param->u.crypt.idx >= WEP_KEYS)
2853 crypt = &ieee->crypt[param->u.crypt.idx];
2858 if (strcmp(param->u.crypt.alg, "none") == 0) {
2863 sec.level = SEC_LEVEL_0;
2864 sec.flags |= SEC_ENABLED | SEC_LEVEL;
2865 ieee80211_crypt_delayed_deinit(ieee, crypt);
2872 sec.flags |= SEC_ENABLED;
2874 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
2875 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
2876 strcmp(param->u.crypt.alg, "TKIP"))
2877 goto skip_host_crypt;
2879 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2880 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
2881 request_module("ieee80211_crypt_wep");
2882 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2883 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
2884 request_module("ieee80211_crypt_tkip");
2885 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2886 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
2887 request_module("ieee80211_crypt_ccmp");
2888 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
2891 printk("unknown crypto alg '%s'\n", param->u.crypt.alg);
2892 param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG;
2897 if (*crypt == NULL || (*crypt)->ops != ops) {
2898 struct ieee80211_crypt_data *new_crypt;
2900 ieee80211_crypt_delayed_deinit(ieee, crypt);
2902 new_crypt = (struct ieee80211_crypt_data *)
2903 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
2904 if (new_crypt == NULL) {
2908 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
2909 new_crypt->ops = ops;
2910 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
2912 new_crypt->ops->init(param->u.crypt.idx);
2914 if (new_crypt->priv == NULL) {
2916 param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED;
2924 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
2925 (*crypt)->ops->set_key(param->u.crypt.key,
2926 param->u.crypt.key_len, param->u.crypt.seq,
2927 (*crypt)->priv) < 0) {
2928 printk("key setting failed\n");
2929 param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED;
2935 if (param->u.crypt.set_tx) {
2936 ieee->tx_keyidx = param->u.crypt.idx;
2937 sec.active_key = param->u.crypt.idx;
2938 sec.flags |= SEC_ACTIVE_KEY;
2940 sec.flags &= ~SEC_ACTIVE_KEY;
2942 if (param->u.crypt.alg != NULL) {
2943 memcpy(sec.keys[param->u.crypt.idx],
2945 param->u.crypt.key_len);
2946 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
2947 sec.flags |= (1 << param->u.crypt.idx);
2949 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
2950 sec.flags |= SEC_LEVEL;
2951 sec.level = SEC_LEVEL_1;
2952 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
2953 sec.flags |= SEC_LEVEL;
2954 sec.level = SEC_LEVEL_2;
2955 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
2956 sec.flags |= SEC_LEVEL;
2957 sec.level = SEC_LEVEL_3;
2961 if (ieee->set_security)
2962 ieee->set_security(ieee->dev, &sec);
2964 /* Do not reset port if card is in Managed mode since resetting will
2965 * generate new IEEE 802.11 authentication which may end up in looping
2966 * with IEEE 802.1X. If your hardware requires a reset after WEP
2967 * configuration (for example... Prism2), implement the reset_port in
2968 * the callbacks structures used to initialize the 802.11 stack. */
2969 if (ieee->reset_on_keychange &&
2970 ieee->iw_mode != IW_MODE_INFRA &&
2972 ieee->reset_port(ieee->dev)) {
2973 printk("reset_port failed\n");
2974 param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED;
2981 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p)
2983 struct ieee_param *param;
2986 down(&ieee->wx_sem);
2987 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
2989 if (p->length < sizeof(struct ieee_param) || !p->pointer){
2994 param = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
2999 if (copy_from_user(param, p->pointer, p->length)) {
3005 switch (param->cmd) {
3007 case IEEE_CMD_SET_WPA_PARAM:
3008 ret = ieee80211_wpa_set_param(ieee, param->u.wpa_param.name,
3009 param->u.wpa_param.value);
3012 case IEEE_CMD_SET_WPA_IE:
3013 ret = ieee80211_wpa_set_wpa_ie(ieee, param, p->length);
3016 case IEEE_CMD_SET_ENCRYPTION:
3017 ret = ieee80211_wpa_set_encryption(ieee, param, p->length);
3021 ret = ieee80211_wpa_mlme(ieee, param->u.mlme.command,
3022 param->u.mlme.reason_code);
3026 printk("Unknown WPA supplicant request: %d\n",param->cmd);
3031 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
3041 void notify_wx_assoc_event(struct ieee80211_device *ieee)
3043 union iwreq_data wrqu;
3044 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3045 if (ieee->state == IEEE80211_LINKED)
3046 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN);
3048 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
3049 wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL);