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/slab.h>
22 #include <linux/version.h>
23 #include <linux/interrupt.h>
24 #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
;
132 void ieee80211_TURBO_Info(struct ieee80211_device
*ieee
, u8
**tag_p
) {
135 *tag
++ = MFIE_TYPE_GENERIC
; //0
146 printk(KERN_ALERT
"This is enable turbo mode IE process\n");
149 void enqueue_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
152 nh
= (ieee
->mgmt_queue_head
+1) % MGMT_QUEUE_NUM
;
155 * if the queue is full but we have newer frames then
156 * just overwrites the oldest.
158 * if (nh == ieee->mgmt_queue_tail)
161 ieee
->mgmt_queue_head
= nh
;
162 ieee
->mgmt_queue_ring
[nh
] = skb
;
167 struct sk_buff
*dequeue_mgmt(struct ieee80211_device
*ieee
)
171 if(ieee
->mgmt_queue_tail
== ieee
->mgmt_queue_head
)
174 ret
= ieee
->mgmt_queue_ring
[ieee
->mgmt_queue_tail
];
176 ieee
->mgmt_queue_tail
=
177 (ieee
->mgmt_queue_tail
+1) % MGMT_QUEUE_NUM
;
182 void init_mgmt_queue(struct ieee80211_device
*ieee
)
184 ieee
->mgmt_queue_tail
= ieee
->mgmt_queue_head
= 0;
188 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
);
190 inline void softmac_mgmt_xmit(struct sk_buff
*skb
, struct ieee80211_device
*ieee
)
193 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
194 struct ieee80211_hdr_3addr
*header
=
195 (struct ieee80211_hdr_3addr
*) skb
->data
;
198 spin_lock_irqsave(&ieee
->lock
, flags
);
200 /* called with 2nd param 0, no mgmt lock required */
201 ieee80211_sta_wakeup(ieee
,0);
204 if(ieee
->queue_stop
){
206 enqueue_mgmt(ieee
,skb
);
208 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4);
210 if (ieee
->seq_ctrl
[0] == 0xFFF)
211 ieee
->seq_ctrl
[0] = 0;
215 /* avoid watchdog triggers */
216 ieee
->dev
->trans_start
= jiffies
;
217 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
220 spin_unlock_irqrestore(&ieee
->lock
, flags
);
222 spin_unlock_irqrestore(&ieee
->lock
, flags
);
223 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags
);
225 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
227 if (ieee
->seq_ctrl
[0] == 0xFFF)
228 ieee
->seq_ctrl
[0] = 0;
232 /* avoid watchdog triggers */
233 ieee
->dev
->trans_start
= jiffies
;
234 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
236 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags
);
241 inline void softmac_ps_mgmt_xmit(struct sk_buff
*skb
, struct ieee80211_device
*ieee
)
244 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
245 struct ieee80211_hdr_3addr
*header
=
246 (struct ieee80211_hdr_3addr
*) skb
->data
;
251 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
253 if (ieee
->seq_ctrl
[0] == 0xFFF)
254 ieee
->seq_ctrl
[0] = 0;
258 /* avoid watchdog triggers */
259 ieee
->dev
->trans_start
= jiffies
;
260 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
264 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
266 if (ieee
->seq_ctrl
[0] == 0xFFF)
267 ieee
->seq_ctrl
[0] = 0;
271 /* avoid watchdog triggers */
272 ieee
->dev
->trans_start
= jiffies
;
273 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
276 // dev_kfree_skb_any(skb);//edit by thomas
278 //by amy for power save
279 inline struct sk_buff
*ieee80211_disassociate_skb(
280 struct ieee80211_network
*beacon
,
281 struct ieee80211_device
*ieee
,
285 struct ieee80211_disassoc_frame
*disass
;
287 skb
= dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame
));
291 disass
= (struct ieee80211_disassoc_frame
*) skb_put(skb
,sizeof(struct ieee80211_disassoc_frame
));
292 disass
->header
.frame_control
= cpu_to_le16(IEEE80211_STYPE_DISASSOC
);
293 disass
->header
.duration_id
= 0;
295 memcpy(disass
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
296 memcpy(disass
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
297 memcpy(disass
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
299 disass
->reasoncode
= asRsn
;
304 struct ieee80211_device
*ieee
,
309 struct ieee80211_network
*beacon
= &ieee
->current_network
;
311 skb
= ieee80211_disassociate_skb(beacon
,ieee
,asRsn
);
313 softmac_mgmt_xmit(skb
, ieee
);
314 //dev_kfree_skb_any(skb);//edit by thomas
318 //by amy for power save
319 inline struct sk_buff
*ieee80211_probe_req(struct ieee80211_device
*ieee
)
321 unsigned int len
,rate_len
;
324 struct ieee80211_probe_request
*req
;
326 len
= ieee
->current_network
.ssid_len
;
328 rate_len
= ieee80211_MFIE_rate_len(ieee
);
330 skb
= dev_alloc_skb(sizeof(struct ieee80211_probe_request
) +
335 req
= (struct ieee80211_probe_request
*) skb_put(skb
,sizeof(struct ieee80211_probe_request
));
336 req
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
337 req
->header
.duration_id
= 0; //FIXME: is this OK ?
339 memset(req
->header
.addr1
, 0xff, ETH_ALEN
);
340 memcpy(req
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
341 memset(req
->header
.addr3
, 0xff, ETH_ALEN
);
343 tag
= (u8
*) skb_put(skb
,len
+2+rate_len
);
345 *tag
++ = MFIE_TYPE_SSID
;
347 memcpy(tag
, ieee
->current_network
.ssid
, len
);
349 ieee80211_MFIE_Brate(ieee
,&tag
);
350 ieee80211_MFIE_Grate(ieee
,&tag
);
355 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
);
357 void ext_ieee80211_send_beacon_wq(struct ieee80211_device
*ieee
)
361 //unsigned long flags;
363 skb
= ieee80211_get_beacon_(ieee
);
366 softmac_mgmt_xmit(skb
, ieee
);
367 ieee
->softmac_stats
.tx_beacons
++;
368 dev_kfree_skb_any(skb
);//edit by thomas
372 //printk(KERN_WARNING "[1] beacon sending!\n");
373 ieee
->beacon_timer
.expires
= jiffies
+
374 (MSECS( ieee
->current_network
.beacon_interval
-5));
376 //spin_lock_irqsave(&ieee->beacon_lock,flags);
377 if(ieee
->beacon_txing
)
378 add_timer(&ieee
->beacon_timer
);
379 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
382 void ieee80211_send_beacon(struct ieee80211_device
*ieee
)
386 //unsigned long flags;
388 skb
= ieee80211_get_beacon_(ieee
);
391 softmac_mgmt_xmit(skb
, ieee
);
392 ieee
->softmac_stats
.tx_beacons
++;
393 dev_kfree_skb_any(skb
);//edit by thomas
396 //printk(KERN_WARNING "[1] beacon sending!\n");
397 ieee
->beacon_timer
.expires
= jiffies
+
398 (MSECS( ieee
->current_network
.beacon_interval
-5));
400 //spin_lock_irqsave(&ieee->beacon_lock,flags);
401 if(ieee
->beacon_txing
)
402 add_timer(&ieee
->beacon_timer
);
403 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
407 void ieee80211_send_beacon_cb(unsigned long _ieee
)
409 struct ieee80211_device
*ieee
=
410 (struct ieee80211_device
*) _ieee
;
413 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
414 ieee80211_send_beacon(ieee
);
415 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
418 void ieee80211_send_probe(struct ieee80211_device
*ieee
)
422 skb
= ieee80211_probe_req(ieee
);
424 softmac_mgmt_xmit(skb
, ieee
);
425 ieee
->softmac_stats
.tx_probe_rq
++;
426 //dev_kfree_skb_any(skb);//edit by thomas
430 void ieee80211_send_probe_requests(struct ieee80211_device
*ieee
)
432 if (ieee
->active_scan
&& (ieee
->softmac_features
& IEEE_SOFTMAC_PROBERQ
)){
433 ieee80211_send_probe(ieee
);
434 ieee80211_send_probe(ieee
);
438 /* this performs syncro scan blocking the caller until all channels
439 * in the allowed channel map has been checked.
441 void ieee80211_softmac_scan_syncro(struct ieee80211_device
*ieee
)
444 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
445 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
446 down(&ieee
->scan_sem
);
447 // printk("==================> Sync scan\n");
454 if (ch
> MAX_CHANNEL_NUMBER
)
455 goto out
; /* scan completed */
457 }while(!channel_map
[ch
]);
458 /* this function can be called in two situations
459 * 1- We have switched to ad-hoc mode and we are
460 * performing a complete syncro scan before conclude
461 * there are no interesting cell and to create a
462 * new one. In this case the link state is
463 * IEEE80211_NOLINK until we found an interesting cell.
464 * If so the ieee8021_new_net, called by the RX path
465 * will set the state to IEEE80211_LINKED, so we stop
467 * 2- We are linked and the root uses run iwlist scan.
468 * So we switch to IEEE80211_LINKED_SCANNING to remember
469 * that we are still logically linked (not interested in
470 * new network events, despite for updating the net list,
471 * but we are temporarly 'unlinked' as the driver shall
472 * not filter RX frames and the channel is changing.
473 * So the only situation in witch are interested is to check
474 * if the state become LINKED because of the #1 situation
477 if (ieee
->state
== IEEE80211_LINKED
)
480 ieee
->set_chan(ieee
->dev
, ch
);
481 // printk("=====>channel=%d ",ch);
482 if(channel_map
[ch
] == 1)
484 // printk("====send probe request\n");
485 ieee80211_send_probe_requests(ieee
);
487 /* this prevent excessive time wait when we
488 * need to wait for a syncro scan to end..
490 if (ieee
->sync_scan_hurryup
)
494 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME
);
498 ieee
->sync_scan_hurryup
= 0;
500 if(IS_DOT11D_ENABLE(ieee
))
501 DOT11D_ScanComplete(ieee
);
504 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device
*ieee
)
507 unsigned int watch_dog
= 0;
508 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
509 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
510 down(&ieee
->scan_sem
);
511 ch
= ieee
->current_network
.channel
;
512 // if(ieee->sync_scan_hurryup)
515 // printk("stop scan sync\n");
518 // printk("=======hh===============>ips scan\n");
521 /* this function can be called in two situations
522 * 1- We have switched to ad-hoc mode and we are
523 * performing a complete syncro scan before conclude
524 * there are no interesting cell and to create a
525 * new one. In this case the link state is
526 * IEEE80211_NOLINK until we found an interesting cell.
527 * If so the ieee8021_new_net, called by the RX path
528 * will set the state to IEEE80211_LINKED, so we stop
530 * 2- We are linked and the root uses run iwlist scan.
531 * So we switch to IEEE80211_LINKED_SCANNING to remember
532 * that we are still logically linked (not interested in
533 * new network events, despite for updating the net list,
534 * but we are temporarly 'unlinked' as the driver shall
535 * not filter RX frames and the channel is changing.
536 * So the only situation in witch are interested is to check
537 * if the state become LINKED because of the #1 situation
539 if (ieee
->state
== IEEE80211_LINKED
)
543 if(channel_map
[ieee
->current_network
.channel
] > 0)
545 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
546 // printk("======>channel=%d ",ieee->current_network.channel);
548 if(channel_map
[ieee
->current_network
.channel
] == 1)
550 // printk("====send probe request\n");
551 ieee80211_send_probe_requests(ieee
);
553 /* this prevent excessive time wait when we
554 * need to wait for a syncro scan to end..
556 // if (ieee->sync_scan_hurryup)
559 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME
);
562 if (watch_dog
++ >= MAX_CHANNEL_NUMBER
)
563 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
564 goto out
; /* scan completed */
566 ieee
->current_network
.channel
= (ieee
->current_network
.channel
+ 1)%MAX_CHANNEL_NUMBER
;
567 }while(!channel_map
[ieee
->current_network
.channel
]);
570 //ieee->sync_scan_hurryup = 0;
571 //ieee->set_chan(ieee->dev, ch);
572 //ieee->current_network.channel = ch;
573 ieee
->actscanning
= false;
575 if(IS_DOT11D_ENABLE(ieee
))
576 DOT11D_ScanComplete(ieee
);
579 void ieee80211_softmac_scan_wq(struct work_struct
*work
)
581 struct delayed_work
*dwork
= to_delayed_work(work
);
582 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, softmac_scan_wq
);
583 static short watchdog
= 0;
584 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
585 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
586 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
587 // printk("in %s\n",__func__);
588 down(&ieee
->scan_sem
);
591 ieee
->current_network
.channel
=
592 (ieee
->current_network
.channel
+ 1) % MAX_CHANNEL_NUMBER
;
593 if (watchdog
++ > MAX_CHANNEL_NUMBER
)
594 goto out
; /* no good chans */
596 }while(!channel_map
[ieee
->current_network
.channel
]);
598 //printk("current_network.channel:%d\n", ieee->current_network.channel);
599 if (ieee
->scanning
== 0 )
601 printk("error out, scanning = 0\n");
604 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
605 if(channel_map
[ieee
->current_network
.channel
] == 1)
606 ieee80211_send_probe_requests(ieee
);
608 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
, IEEE80211_SOFTMAC_SCAN_TIME
);
612 ieee
->actscanning
= false;
617 if(IS_DOT11D_ENABLE(ieee
))
618 DOT11D_ScanComplete(ieee
);
622 void ieee80211_beacons_start(struct ieee80211_device
*ieee
)
626 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
628 ieee
->beacon_txing
= 1;
629 ieee80211_send_beacon(ieee
);
631 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
634 void ieee80211_beacons_stop(struct ieee80211_device
*ieee
)
638 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
640 ieee
->beacon_txing
= 0;
641 del_timer_sync(&ieee
->beacon_timer
);
643 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
648 void ieee80211_stop_send_beacons(struct ieee80211_device
*ieee
)
650 if(ieee
->stop_send_beacons
)
651 ieee
->stop_send_beacons(ieee
->dev
);
652 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
653 ieee80211_beacons_stop(ieee
);
657 void ieee80211_start_send_beacons(struct ieee80211_device
*ieee
)
659 if(ieee
->start_send_beacons
)
660 ieee
->start_send_beacons(ieee
->dev
);
661 if(ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
662 ieee80211_beacons_start(ieee
);
666 void ieee80211_softmac_stop_scan(struct ieee80211_device
*ieee
)
668 // unsigned long flags;
670 //ieee->sync_scan_hurryup = 1;
672 down(&ieee
->scan_sem
);
673 // spin_lock_irqsave(&ieee->lock, flags);
675 if (ieee
->scanning
== 1){
677 //del_timer_sync(&ieee->scan_timer);
678 cancel_delayed_work(&ieee
->softmac_scan_wq
);
681 // spin_unlock_irqrestore(&ieee->lock, flags);
685 void ieee80211_stop_scan(struct ieee80211_device
*ieee
)
687 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
688 ieee80211_softmac_stop_scan(ieee
);
690 ieee
->stop_scan(ieee
->dev
);
693 /* called with ieee->lock held */
694 void ieee80211_rtl_start_scan(struct ieee80211_device
*ieee
)
696 if(IS_DOT11D_ENABLE(ieee
) )
698 if(IS_COUNTRY_IE_VALID(ieee
))
700 RESET_CIE_WATCHDOG(ieee
);
703 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
704 if (ieee
->scanning
== 0)
707 //ieee80211_softmac_scan(ieee);
708 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
709 //care this,1203,2007,by lawrence
711 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
,0);
715 ieee
->start_scan(ieee
->dev
);
719 /* called with wx_sem held */
720 void ieee80211_start_scan_syncro(struct ieee80211_device
*ieee
)
722 if(IS_DOT11D_ENABLE(ieee
) )
724 if(IS_COUNTRY_IE_VALID(ieee
))
726 RESET_CIE_WATCHDOG(ieee
);
729 ieee
->sync_scan_hurryup
= 0;
731 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
732 ieee80211_softmac_scan_syncro(ieee
);
734 ieee
->scan_syncro(ieee
->dev
);
738 inline struct sk_buff
*ieee80211_authentication_req(struct ieee80211_network
*beacon
,
739 struct ieee80211_device
*ieee
, int challengelen
)
742 struct ieee80211_authentication
*auth
;
744 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
) + challengelen
);
746 if (!skb
) return NULL
;
748 auth
= (struct ieee80211_authentication
*)
749 skb_put(skb
, sizeof(struct ieee80211_authentication
));
751 auth
->header
.frame_ctl
= IEEE80211_STYPE_AUTH
;
752 if (challengelen
) auth
->header
.frame_ctl
|= IEEE80211_FCTL_WEP
;
754 auth
->header
.duration_id
= 0x013a; //FIXME
756 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
757 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
758 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
760 auth
->algorithm
= ieee
->open_wep
? WLAN_AUTH_OPEN
: WLAN_AUTH_SHARED_KEY
;
762 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
763 ieee
->associate_seq
++;
765 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
771 static struct sk_buff
* ieee80211_probe_resp(struct ieee80211_device
*ieee
, u8
*dest
)
775 struct ieee80211_probe_response
*beacon_buf
;
778 int atim_len
,erp_len
;
779 struct ieee80211_crypt_data
* crypt
;
781 char *ssid
= ieee
->current_network
.ssid
;
782 int ssid_len
= ieee
->current_network
.ssid_len
;
783 int rate_len
= ieee
->current_network
.rates_len
+2;
784 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
785 int wpa_ie_len
= ieee
->wpa_ie_len
;
786 if(rate_ex_len
> 0) rate_ex_len
+=2;
788 if(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
793 if(ieee80211_is_54g(ieee
->current_network
))
798 beacon_size
= sizeof(struct ieee80211_probe_response
)+
807 skb
= dev_alloc_skb(beacon_size
);
812 beacon_buf
= (struct ieee80211_probe_response
*) skb_put(skb
, beacon_size
);
814 memcpy (beacon_buf
->header
.addr1
, dest
,ETH_ALEN
);
815 memcpy (beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
816 memcpy (beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
818 beacon_buf
->header
.duration_id
= 0; //FIXME
819 beacon_buf
->beacon_interval
=
820 cpu_to_le16(ieee
->current_network
.beacon_interval
);
821 beacon_buf
->capability
=
822 cpu_to_le16(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
);
824 if(ieee
->short_slot
&& (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_SLOT
))
825 cpu_to_le16((beacon_buf
->capability
|= WLAN_CAPABILITY_SHORT_SLOT
));
827 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
829 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
830 ((0 == strcmp(crypt
->ops
->name
, "WEP")) || wpa_ie_len
);
833 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
836 beacon_buf
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
);
838 beacon_buf
->info_element
.id
= MFIE_TYPE_SSID
;
839 beacon_buf
->info_element
.len
= ssid_len
;
841 tag
= (u8
*) beacon_buf
->info_element
.data
;
843 memcpy(tag
, ssid
, ssid_len
);
847 *(tag
++) = MFIE_TYPE_RATES
;
848 *(tag
++) = rate_len
-2;
849 memcpy(tag
,ieee
->current_network
.rates
,rate_len
-2);
852 *(tag
++) = MFIE_TYPE_DS_SET
;
854 *(tag
++) = ieee
->current_network
.channel
;
857 *(tag
++) = MFIE_TYPE_IBSS_SET
;
859 *((u16
*)(tag
)) = cpu_to_le16(ieee
->current_network
.atim_window
);
864 *(tag
++) = MFIE_TYPE_ERP
;
870 *(tag
++) = MFIE_TYPE_RATES_EX
;
871 *(tag
++) = rate_ex_len
-2;
872 memcpy(tag
,ieee
->current_network
.rates_ex
,rate_ex_len
-2);
878 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
879 {//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
880 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
883 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
886 skb
->dev
= ieee
->dev
;
890 struct sk_buff
* ieee80211_assoc_resp(struct ieee80211_device
*ieee
, u8
*dest
)
895 struct ieee80211_crypt_data
* crypt
;
896 struct ieee80211_assoc_response_frame
*assoc
;
899 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
900 int len
= sizeof(struct ieee80211_assoc_response_frame
) + rate_len
;
902 skb
= dev_alloc_skb(len
);
907 assoc
= (struct ieee80211_assoc_response_frame
*)
908 skb_put(skb
,sizeof(struct ieee80211_assoc_response_frame
));
910 assoc
->header
.frame_control
= cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
);
911 memcpy(assoc
->header
.addr1
, dest
,ETH_ALEN
);
912 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
913 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
914 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
915 WLAN_CAPABILITY_BSS
: WLAN_CAPABILITY_IBSS
);
919 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
921 if (ieee
->host_encrypt
)
922 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
925 encrypt
= ( crypt
&& crypt
->ops
);
928 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
931 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
932 if (ieee
->assoc_id
== 0x2007) ieee
->assoc_id
=0;
933 else ieee
->assoc_id
++;
935 tag
= (u8
*) skb_put(skb
, rate_len
);
937 ieee80211_MFIE_Brate(ieee
, &tag
);
938 ieee80211_MFIE_Grate(ieee
, &tag
);
943 struct sk_buff
* ieee80211_auth_resp(struct ieee80211_device
*ieee
,int status
, u8
*dest
)
946 struct ieee80211_authentication
*auth
;
948 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
)+1);
953 skb
->len
= sizeof(struct ieee80211_authentication
);
955 auth
= (struct ieee80211_authentication
*)skb
->data
;
957 auth
->status
= cpu_to_le16(status
);
958 auth
->transaction
= cpu_to_le16(2);
959 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
961 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
962 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
963 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
964 auth
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_AUTH
);
970 struct sk_buff
* ieee80211_null_func(struct ieee80211_device
*ieee
,short pwr
)
973 struct ieee80211_hdr_3addr
* hdr
;
975 skb
= dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr
));
980 hdr
= (struct ieee80211_hdr_3addr
*)skb_put(skb
,sizeof(struct ieee80211_hdr_3addr
));
982 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
983 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
984 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
986 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
987 IEEE80211_STYPE_NULLFUNC
| IEEE80211_FCTL_TODS
|
988 (pwr
? IEEE80211_FCTL_PM
:0));
996 void ieee80211_resp_to_assoc_rq(struct ieee80211_device
*ieee
, u8
* dest
)
998 struct sk_buff
*buf
= ieee80211_assoc_resp(ieee
, dest
);
1001 softmac_mgmt_xmit(buf
, ieee
);
1002 dev_kfree_skb_any(buf
);//edit by thomas
1007 void ieee80211_resp_to_auth(struct ieee80211_device
*ieee
, int s
, u8
* dest
)
1009 struct sk_buff
*buf
= ieee80211_auth_resp(ieee
, s
, dest
);
1012 softmac_mgmt_xmit(buf
, ieee
);
1013 dev_kfree_skb_any(buf
);//edit by thomas
1018 void ieee80211_resp_to_probe(struct ieee80211_device
*ieee
, u8
*dest
)
1021 struct sk_buff
*buf
= ieee80211_probe_resp(ieee
, dest
);
1024 softmac_mgmt_xmit(buf
, ieee
);
1025 dev_kfree_skb_any(buf
);//edit by thomas
1030 inline struct sk_buff
*ieee80211_association_req(struct ieee80211_network
*beacon
,struct ieee80211_device
*ieee
)
1032 struct sk_buff
*skb
;
1033 //unsigned long flags;
1035 struct ieee80211_assoc_request_frame
*hdr
;
1037 //short info_addr = 0;
1039 //u16 suite_count = 0;
1040 //u8 suit_select = 0;
1041 unsigned int wpa_len
= beacon
->wpa_ie_len
;
1042 //struct net_device *dev = ieee->dev;
1043 //union iwreq_data wrqu;
1047 // for testing purpose
1048 unsigned int rsn_len
= beacon
->rsn_ie_len
;
1050 unsigned int rsn_len
= beacon
->rsn_ie_len
- 4;
1052 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
1053 unsigned int wmm_info_len
= beacon
->QoS_Enable
?9:0;
1054 unsigned int turbo_info_len
= beacon
->Turbo_Enable
?9:0;
1056 u8 encry_proto
= ieee
->wpax_type_notify
& 0xff;
1057 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1058 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1062 //[0] Notify type of encryption: WPA/WPA2
1063 //[1] pair wise type
1065 if(ieee
->wpax_type_set
) {
1066 if (IEEE_PROTO_WPA
== encry_proto
) {
1068 } else if (IEEE_PROTO_RSN
== encry_proto
) {
1072 len
= sizeof(struct ieee80211_assoc_request_frame
)+
1073 + beacon
->ssid_len
//essid tagged val
1074 + rate_len
//rates tagged val
1080 skb
= dev_alloc_skb(len
);
1085 hdr
= (struct ieee80211_assoc_request_frame
*)
1086 skb_put(skb
, sizeof(struct ieee80211_assoc_request_frame
));
1089 hdr
->header
.frame_control
= IEEE80211_STYPE_ASSOC_REQ
;
1090 hdr
->header
.duration_id
= 37; //FIXME
1091 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1092 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1093 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1094 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);//for HW security, John
1096 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_BSS
);
1097 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1098 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1099 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1100 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1102 if(ieee
->short_slot
)
1103 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
1105 hdr
->listen_interval
= 0xa; //FIXME
1107 hdr
->info_element
.id
= MFIE_TYPE_SSID
;
1109 hdr
->info_element
.len
= beacon
->ssid_len
;
1110 tag
= skb_put(skb
, beacon
->ssid_len
);
1111 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1113 tag
= skb_put(skb
, rate_len
);
1115 ieee80211_MFIE_Brate(ieee
, &tag
);
1116 ieee80211_MFIE_Grate(ieee
, &tag
);
1118 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1119 //choose AES encryption as default algorithm while using mixed mode
1121 tag
= skb_put(skb
,ieee
->wpa_ie_len
);
1122 memcpy(tag
,ieee
->wpa_ie
,ieee
->wpa_ie_len
);
1124 tag
= skb_put(skb
,wmm_info_len
);
1126 ieee80211_WMM_Info(ieee
, &tag
);
1128 tag
= skb_put(skb
,turbo_info_len
);
1129 if(turbo_info_len
) {
1130 ieee80211_TURBO_Info(ieee
, &tag
);
1136 void ieee80211_associate_abort(struct ieee80211_device
*ieee
)
1139 unsigned long flags
;
1140 spin_lock_irqsave(&ieee
->lock
, flags
);
1142 ieee
->associate_seq
++;
1144 /* don't scan, and avoid to have the RX path possibily
1145 * try again to associate. Even do not react to AUTH or
1146 * ASSOC response. Just wait for the retry wq to be scheduled.
1147 * Here we will check if there are good nets to associate
1148 * with, so we retry or just get back to NO_LINK and scanning
1150 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
){
1151 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1152 ieee
->softmac_stats
.no_auth_rs
++;
1154 IEEE80211_DEBUG_MGMT("Association failed\n");
1155 ieee
->softmac_stats
.no_ass_rs
++;
1158 ieee
->state
= IEEE80211_ASSOCIATING_RETRY
;
1160 queue_delayed_work(ieee
->wq
, &ieee
->associate_retry_wq
,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME
);
1162 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1165 void ieee80211_associate_abort_cb(unsigned long dev
)
1167 ieee80211_associate_abort((struct ieee80211_device
*) dev
);
1171 void ieee80211_associate_step1(struct ieee80211_device
*ieee
)
1173 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1174 struct sk_buff
*skb
;
1176 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1177 ieee
->softmac_stats
.tx_auth_rq
++;
1178 skb
=ieee80211_authentication_req(beacon
, ieee
, 0);
1181 ieee80211_associate_abort(ieee
);
1184 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATING
;
1185 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1186 //printk("---Sending authentication request\n");
1187 softmac_mgmt_xmit(skb
, ieee
);
1188 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1189 if(!timer_pending(&ieee
->associate_timer
)){
1190 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1191 add_timer(&ieee
->associate_timer
);
1193 //If call dev_kfree_skb_any,a warning will ocur....
1194 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1195 //So ... 1204 by lawrence.
1196 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1197 //dev_kfree_skb_any(skb);//edit by thomas
1201 void ieee80211_rtl_auth_challenge(struct ieee80211_device
*ieee
, u8
*challenge
, int chlen
)
1204 struct sk_buff
*skb
;
1205 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1206 // int hlen = sizeof(struct ieee80211_authentication);
1207 del_timer_sync(&ieee
->associate_timer
);
1208 ieee
->associate_seq
++;
1209 ieee
->softmac_stats
.tx_auth_rq
++;
1211 skb
= ieee80211_authentication_req(beacon
, ieee
, chlen
+2);
1213 ieee80211_associate_abort(ieee
);
1215 c
= skb_put(skb
, chlen
+2);
1216 *(c
++) = MFIE_TYPE_CHALLENGE
;
1218 memcpy(c
, challenge
, chlen
);
1220 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1222 ieee80211_encrypt_fragment(ieee
, skb
, sizeof(struct ieee80211_hdr_3addr
));
1224 softmac_mgmt_xmit(skb
, ieee
);
1225 if (!timer_pending(&ieee
->associate_timer
)){
1226 //printk("=========>add timer again, to crash\n");
1227 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1228 add_timer(&ieee
->associate_timer
);
1230 dev_kfree_skb_any(skb
);//edit by thomas
1235 void ieee80211_associate_step2(struct ieee80211_device
*ieee
)
1237 struct sk_buff
* skb
;
1238 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1240 del_timer_sync(&ieee
->associate_timer
);
1242 IEEE80211_DEBUG_MGMT("Sending association request\n");
1243 ieee
->softmac_stats
.tx_ass_rq
++;
1244 skb
=ieee80211_association_req(beacon
, ieee
);
1246 ieee80211_associate_abort(ieee
);
1248 softmac_mgmt_xmit(skb
, ieee
);
1249 if (!timer_pending(&ieee
->associate_timer
)){
1250 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1251 add_timer(&ieee
->associate_timer
);
1253 //dev_kfree_skb_any(skb);//edit by thomas
1257 void ieee80211_associate_complete_wq(struct work_struct
*work
)
1259 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_complete_wq
);
1261 printk(KERN_INFO
"Associated successfully\n");
1262 if(ieee80211_is_54g(ieee
->current_network
) &&
1263 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1266 printk(KERN_INFO
"Using G rates\n");
1269 printk(KERN_INFO
"Using B rates\n");
1271 ieee
->link_change(ieee
->dev
);
1272 notify_wx_assoc_event(ieee
);
1273 if (ieee
->data_hard_resume
)
1274 ieee
->data_hard_resume(ieee
->dev
);
1275 netif_carrier_on(ieee
->dev
);
1278 void ieee80211_associate_complete(struct ieee80211_device
*ieee
)
1281 del_timer_sync(&ieee
->associate_timer
);
1283 for(i
= 0; i
< 6; i
++) {
1284 //ieee->seq_ctrl[i] = 0;
1286 ieee
->state
= IEEE80211_LINKED
;
1287 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1289 queue_work(ieee
->wq
, &ieee
->associate_complete_wq
);
1292 void ieee80211_associate_procedure_wq(struct work_struct
*work
)
1294 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_procedure_wq
);
1296 ieee
->sync_scan_hurryup
= 1;
1297 down(&ieee
->wx_sem
);
1299 if (ieee
->data_hard_stop
)
1300 ieee
->data_hard_stop(ieee
->dev
);
1302 ieee80211_stop_scan(ieee
);
1303 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
1305 ieee
->associate_seq
= 1;
1306 ieee80211_associate_step1(ieee
);
1311 inline void ieee80211_softmac_new_net(struct ieee80211_device
*ieee
, struct ieee80211_network
*net
)
1313 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+1];
1314 int tmp_ssid_len
= 0;
1316 short apset
,ssidset
,ssidbroad
,apmatch
,ssidmatch
;
1318 /* we are interested in new new only if we are not associated
1319 * and we are not associating / authenticating
1321 if (ieee
->state
!= IEEE80211_NOLINK
)
1324 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
& WLAN_CAPABILITY_BSS
))
1327 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
& WLAN_CAPABILITY_IBSS
))
1331 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
){
1332 /* if the user specified the AP MAC, we need also the essid
1333 * This could be obtained by beacons or, if the network does not
1334 * broadcast it, it can be put manually.
1336 apset
= ieee
->wap_set
;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1337 ssidset
= ieee
->ssid_set
;//ieee->current_network.ssid[0] != '\0';
1338 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0]== '\0');
1339 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
, ETH_ALEN
)==0);
1341 if(ieee
->current_network
.ssid_len
!= net
->ssid_len
)
1344 ssidmatch
= (0==strncmp(ieee
->current_network
.ssid
, net
->ssid
, net
->ssid_len
));
1346 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1347 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1349 if ( /* if the user set the AP check if match.
1350 * if the network does not broadcast essid we check the user supplyed ANY essid
1351 * if the network does broadcast and the user does not set essid it is OK
1352 * if the network does broadcast and the user did set essid chech if essid match
1354 ( apset
&& apmatch
&&
1355 ((ssidset
&& ssidbroad
&& ssidmatch
) || (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
)) ) ||
1356 /* if the ap is not set, check that the user set the bssid
1357 * and the network does bradcast and that those two bssid matches
1359 (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
)
1363 /* if the essid is hidden replace it with the
1364 * essid provided by the user.
1367 strncpy(tmp_ssid
, ieee
->current_network
.ssid
, IW_ESSID_MAX_SIZE
);
1368 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1370 memcpy(&ieee
->current_network
, net
, sizeof(struct ieee80211_network
));
1373 strncpy(ieee
->current_network
.ssid
, tmp_ssid
, IW_ESSID_MAX_SIZE
);
1374 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1376 printk(KERN_INFO
"Linking with %s: channel is %d\n",ieee
->current_network
.ssid
,ieee
->current_network
.channel
);
1378 if (ieee
->iw_mode
== IW_MODE_INFRA
){
1379 ieee
->state
= IEEE80211_ASSOCIATING
;
1380 ieee
->beinretry
= false;
1381 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1383 if(ieee80211_is_54g(ieee
->current_network
) &&
1384 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1386 printk(KERN_INFO
"Using G rates\n");
1389 printk(KERN_INFO
"Using B rates\n");
1391 ieee
->state
= IEEE80211_LINKED
;
1392 ieee
->beinretry
= false;
1400 void ieee80211_softmac_check_all_nets(struct ieee80211_device
*ieee
)
1402 unsigned long flags
;
1403 struct ieee80211_network
*target
;
1405 spin_lock_irqsave(&ieee
->lock
, flags
);
1406 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1408 /* if the state become different that NOLINK means
1409 * we had found what we are searching for
1412 if (ieee
->state
!= IEEE80211_NOLINK
)
1415 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
))
1416 ieee80211_softmac_new_net(ieee
, target
);
1419 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1424 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1426 struct ieee80211_authentication
*a
;
1428 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1429 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb
->len
);
1433 a
= (struct ieee80211_authentication
*) skb
->data
;
1434 if(skb
->len
> (sizeof(struct ieee80211_authentication
) +3)){
1435 t
= skb
->data
+ sizeof(struct ieee80211_authentication
);
1437 if(*(t
++) == MFIE_TYPE_CHALLENGE
){
1439 *challenge
= kmemdup(t
, *chlen
, GFP_ATOMIC
);
1445 return cpu_to_le16(a
->status
);
1450 int auth_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1452 struct ieee80211_authentication
*a
;
1454 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1455 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb
->len
);
1458 a
= (struct ieee80211_authentication
*) skb
->data
;
1460 memcpy(dest
,a
->header
.addr2
, ETH_ALEN
);
1462 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1463 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1465 return WLAN_STATUS_SUCCESS
;
1468 static short probe_rq_parse(struct ieee80211_device
*ieee
, struct sk_buff
*skb
, u8
*src
)
1475 struct ieee80211_hdr_3addr
*header
=
1476 (struct ieee80211_hdr_3addr
*) skb
->data
;
1478 if (skb
->len
< sizeof (struct ieee80211_hdr_3addr
))
1479 return -1; /* corrupted */
1481 memcpy(src
,header
->addr2
, ETH_ALEN
);
1483 skbend
= (u8
*)skb
->data
+ skb
->len
;
1485 tag
= skb
->data
+ sizeof (struct ieee80211_hdr_3addr
);
1487 while (tag
+1 < skbend
){
1493 tag
++; /* point to the len field */
1494 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1495 tag
++; /* point to the next tag */
1498 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1499 if (ssidlen
== 0) return 1;
1501 if (!ssid
) return 1; /* ssid not found in tagged param */
1502 return (!strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
));
1506 int assoc_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1508 struct ieee80211_assoc_request_frame
*a
;
1510 if (skb
->len
< (sizeof(struct ieee80211_assoc_request_frame
) -
1511 sizeof(struct ieee80211_info_element
))) {
1513 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb
->len
);
1517 a
= (struct ieee80211_assoc_request_frame
*) skb
->data
;
1519 memcpy(dest
,a
->header
.addr2
,ETH_ALEN
);
1524 static inline u16
assoc_parse(struct sk_buff
*skb
, int *aid
)
1526 struct ieee80211_assoc_response_frame
*a
;
1527 if (skb
->len
< sizeof(struct ieee80211_assoc_response_frame
)){
1528 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1532 a
= (struct ieee80211_assoc_response_frame
*) skb
->data
;
1533 *aid
= le16_to_cpu(a
->aid
) & 0x3fff;
1534 return le16_to_cpu(a
->status
);
1538 ieee80211_rx_probe_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1542 //IEEE80211DMESG("Rx probe");
1543 ieee
->softmac_stats
.rx_probe_rq
++;
1544 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1545 if (probe_rq_parse(ieee
, skb
, dest
)){
1546 //IEEE80211DMESG("Was for me!");
1547 ieee
->softmac_stats
.tx_probe_rs
++;
1548 ieee80211_resp_to_probe(ieee
, dest
);
1553 ieee80211_rx_auth_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1557 //IEEE80211DMESG("Rx probe");
1558 ieee
->softmac_stats
.rx_auth_rq
++;
1560 status
= auth_rq_parse(skb
, dest
);
1562 ieee80211_resp_to_auth(ieee
, status
, dest
);
1564 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1569 ieee80211_rx_assoc_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1573 //unsigned long flags;
1575 ieee
->softmac_stats
.rx_ass_rq
++;
1576 if (assoc_rq_parse(skb
,dest
) != -1){
1577 ieee80211_resp_to_assoc_rq(ieee
, dest
);
1580 printk(KERN_INFO
"New client associated: %pM\n", dest
);
1585 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device
*ieee
, short pwr
)
1588 struct sk_buff
*buf
= ieee80211_null_func(ieee
, pwr
);
1591 softmac_ps_mgmt_xmit(buf
, ieee
);
1596 short ieee80211_sta_ps_sleep(struct ieee80211_device
*ieee
, u32
*time_h
, u32
*time_l
)
1601 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1602 ieee->iw_mode != IW_MODE_INFRA ||
1603 ieee->state != IEEE80211_LINKED)
1607 dtim
= ieee
->current_network
.dtim_data
;
1610 if(!(dtim
& IEEE80211_DTIM_VALID
))
1613 timeout
= ieee
->current_network
.beacon_interval
;
1615 //printk("VALID\n");
1616 ieee
->current_network
.dtim_data
= IEEE80211_DTIM_INVALID
;
1618 if(dtim
& ((IEEE80211_DTIM_UCAST
| IEEE80211_DTIM_MBCAST
)& ieee
->ps
))
1621 if(!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
)))
1624 if(!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
)))
1627 if((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
1628 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
1632 *time_l
= ieee
->current_network
.last_dtim_sta_time
[0]
1633 + MSECS((ieee
->current_network
.beacon_interval
));
1634 //* ieee->current_network.dtim_period));
1635 //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);
1639 *time_h
= ieee
->current_network
.last_dtim_sta_time
[1];
1640 if(time_l
&& *time_l
< ieee
->current_network
.last_dtim_sta_time
[0])
1649 inline void ieee80211_sta_ps(struct ieee80211_device
*ieee
)
1655 unsigned long flags
,flags2
;
1657 spin_lock_irqsave(&ieee
->lock
, flags
);
1659 if((ieee
->ps
== IEEE80211_PS_DISABLED
||
1661 ieee
->iw_mode
!= IW_MODE_INFRA
||
1662 ieee
->state
!= IEEE80211_LINKED
)){
1664 //#warning CHECK_LOCK_HERE
1665 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1667 ieee80211_sta_wakeup(ieee
, 1);
1669 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1672 sleep
= ieee80211_sta_ps_sleep(ieee
,&th
, &tl
);
1673 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
1674 /* 2 wake, 1 sleep, 0 do nothing */
1680 if(ieee
->sta_sleep
== 1)
1681 ieee
->enter_sleep_state(ieee
->dev
,th
,tl
);
1683 else if(ieee
->sta_sleep
== 0){
1684 // printk("send null 1\n");
1685 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1687 if(ieee
->ps_is_queue_empty(ieee
->dev
)){
1690 ieee
->sta_sleep
= 2;
1692 ieee
->ps_request_tx_ack(ieee
->dev
);
1694 ieee80211_sta_ps_send_null_frame(ieee
,1);
1699 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1704 }else if(sleep
== 2){
1705 //#warning CHECK_LOCK_HERE
1706 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1708 // printk("send wakeup packet\n");
1709 ieee80211_sta_wakeup(ieee
,1);
1711 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1715 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1719 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
)
1721 if(ieee
->sta_sleep
== 0){
1723 // printk("Warning: driver is probably failing to report TX ps error\n");
1724 ieee
->ps_request_tx_ack(ieee
->dev
);
1725 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1731 if(ieee
->sta_sleep
== 1)
1732 ieee
->sta_wake_up(ieee
->dev
);
1734 ieee
->sta_sleep
= 0;
1737 ieee
->ps_request_tx_ack(ieee
->dev
);
1738 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1742 void ieee80211_ps_tx_ack(struct ieee80211_device
*ieee
, short success
)
1744 unsigned long flags
,flags2
;
1746 spin_lock_irqsave(&ieee
->lock
, flags
);
1747 if(ieee
->sta_sleep
== 2){
1748 /* Null frame with PS bit set */
1751 // printk("==================> %s::enter sleep state\n",__func__);
1752 ieee
->sta_sleep
= 1;
1753 ieee
->enter_sleep_state(ieee
->dev
,ieee
->ps_th
,ieee
->ps_tl
);
1755 /* if the card report not success we can't be sure the AP
1756 * has not RXed so we can't assume the AP believe us awake
1759 /* 21112005 - tx again null without PS bit if lost */
1762 if((ieee
->sta_sleep
== 0) && !success
){
1763 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1764 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1765 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1768 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1772 ieee80211_rx_frame_softmac(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
1773 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
1776 struct ieee80211_hdr_3addr
*header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
1781 struct ieee80211_assoc_response_frame
*assoc_resp
;
1782 struct ieee80211_info_element
*info_element
;
1784 if(!ieee
->proto_started
)
1787 if(ieee
->sta_sleep
|| (ieee
->ps
!= IEEE80211_PS_DISABLED
&&
1788 ieee
->iw_mode
== IW_MODE_INFRA
&&
1789 ieee
->state
== IEEE80211_LINKED
))
1791 tasklet_schedule(&ieee
->ps_task
);
1793 if (WLAN_FC_GET_STYPE(header
->frame_control
) != IEEE80211_STYPE_PROBE_RESP
&&
1794 WLAN_FC_GET_STYPE(header
->frame_control
) != IEEE80211_STYPE_BEACON
)
1795 ieee
->last_rx_ps_time
= jiffies
;
1797 switch (WLAN_FC_GET_STYPE(header
->frame_control
)) {
1799 case IEEE80211_STYPE_ASSOC_RESP
:
1800 case IEEE80211_STYPE_REASSOC_RESP
:
1802 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1803 WLAN_FC_GET_STYPE(header
->frame_ctl
));
1804 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1805 ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATED
&&
1806 ieee
->iw_mode
== IW_MODE_INFRA
){
1807 if (0 == (errcode
=assoc_parse(skb
, &aid
))){
1810 ieee
->state
=IEEE80211_LINKED
;
1811 ieee
->assoc_id
= aid
;
1812 ieee
->softmac_stats
.rx_ass_ok
++;
1814 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
1815 if(1 == rx_stats
->nic_type
) //card type is 8187
1817 goto associate_complete
;
1819 assoc_resp
= (struct ieee80211_assoc_response_frame
*)skb
->data
;
1820 info_element
= &assoc_resp
->info_element
;
1821 left
= skb
->len
- ((void*)info_element
- (void*)assoc_resp
);
1823 while (left
>= sizeof(struct ieee80211_info_element_hdr
)) {
1824 if (sizeof(struct ieee80211_info_element_hdr
) + info_element
->len
> left
) {
1825 printk(KERN_WARNING
"[re]associate reeponse error!");
1828 switch (info_element
->id
) {
1829 case MFIE_TYPE_GENERIC
:
1830 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element
->len
);
1831 if (info_element
->len
>= 8 &&
1832 info_element
->data
[0] == 0x00 &&
1833 info_element
->data
[1] == 0x50 &&
1834 info_element
->data
[2] == 0xf2 &&
1835 info_element
->data
[3] == 0x02 &&
1836 info_element
->data
[4] == 0x01) {
1837 // Not care about version at present.
1838 //WMM Parameter Element
1839 memcpy(ieee
->current_network
.wmm_param
,(u8
*)(info_element
->data\
1840 + 8),(info_element
->len
- 8));
1842 if (((ieee
->current_network
.wmm_info
^info_element
->data
[6])& \
1843 0x0f)||(!ieee
->init_wmmparam_flag
)) {
1844 // refresh parameter element for current network
1845 // update the register parameter for hardware
1846 ieee
->init_wmmparam_flag
= 1;
1847 queue_work(ieee
->wq
, &ieee
->wmm_param_update_wq
);
1850 //update info_element for current network
1851 ieee
->current_network
.wmm_info
= info_element
->data
[6];
1855 //nothing to do at present!!!
1859 left
-= sizeof(struct ieee80211_info_element_hdr
) +
1861 info_element
= (struct ieee80211_info_element
*)
1862 &info_element
->data
[info_element
->len
];
1864 if(!ieee
->init_wmmparam_flag
) //legacy AP, reset the AC_xx_param register
1866 queue_work(ieee
->wq
,&ieee
->wmm_param_update_wq
);
1867 ieee
->init_wmmparam_flag
= 1;//indicate AC_xx_param upated since last associate
1870 ieee80211_associate_complete(ieee
);
1872 ieee
->softmac_stats
.rx_ass_err
++;
1873 IEEE80211_DEBUG_MGMT(
1874 "Association response status code 0x%x\n",
1876 ieee80211_associate_abort(ieee
);
1881 case IEEE80211_STYPE_ASSOC_REQ
:
1882 case IEEE80211_STYPE_REASSOC_REQ
:
1884 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1885 ieee
->iw_mode
== IW_MODE_MASTER
)
1887 ieee80211_rx_assoc_rq(ieee
, skb
);
1890 case IEEE80211_STYPE_AUTH
:
1892 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
){
1893 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
&&
1894 ieee
->iw_mode
== IW_MODE_INFRA
){
1896 IEEE80211_DEBUG_MGMT("Received authentication response");
1898 if (0 == (errcode
=auth_parse(skb
, &challenge
, &chlen
))){
1899 if(ieee
->open_wep
|| !challenge
){
1900 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATED
;
1901 ieee
->softmac_stats
.rx_auth_rs_ok
++;
1903 ieee80211_associate_step2(ieee
);
1905 ieee80211_rtl_auth_challenge(ieee
, challenge
, chlen
);
1908 ieee
->softmac_stats
.rx_auth_rs_err
++;
1909 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode
);
1910 ieee80211_associate_abort(ieee
);
1913 }else if (ieee
->iw_mode
== IW_MODE_MASTER
){
1914 ieee80211_rx_auth_rq(ieee
, skb
);
1919 case IEEE80211_STYPE_PROBE_REQ
:
1921 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
1922 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
1923 ieee
->iw_mode
== IW_MODE_MASTER
) &&
1924 ieee
->state
== IEEE80211_LINKED
))
1926 ieee80211_rx_probe_rq(ieee
, skb
);
1929 case IEEE80211_STYPE_DISASSOC
:
1930 case IEEE80211_STYPE_DEAUTH
:
1931 /* FIXME for now repeat all the association procedure
1932 * both for disassociation and deauthentication
1934 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1935 (ieee
->state
== IEEE80211_LINKED
) &&
1936 (ieee
->iw_mode
== IW_MODE_INFRA
) &&
1937 (!memcmp(header
->addr2
,ieee
->current_network
.bssid
,ETH_ALEN
))){
1938 ieee
->state
= IEEE80211_ASSOCIATING
;
1939 ieee
->softmac_stats
.reassoc
++;
1941 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
1942 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1952 //dev_kfree_skb_any(skb);
1958 /* following are for a simpler TX queue management.
1959 * Instead of using netif_[stop/wake]_queue the driver
1960 * will uses these two function (plus a reset one), that
1961 * will internally uses the kernel netif_* and takes
1962 * care of the ieee802.11 fragmentation.
1963 * So the driver receives a fragment per time and might
1964 * call the stop function when it want without take care
1965 * to have enough room to TX an entire packet.
1966 * This might be useful if each fragment need it's own
1967 * descriptor, thus just keep a total free memory > than
1968 * the max fragmentation threshold is not enough.. If the
1969 * ieee802.11 stack passed a TXB struct then you needed
1970 * to keep N free descriptors where
1971 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
1972 * In this way you need just one and the 802.11 stack
1973 * will take care of buffering fragments and pass them to
1974 * to the driver later, when it wakes the queue.
1977 void ieee80211_softmac_xmit(struct ieee80211_txb
*txb
, struct ieee80211_device
*ieee
)
1981 unsigned long flags
;
1984 spin_lock_irqsave(&ieee
->lock
,flags
);
1986 /* called with 2nd parm 0, no tx mgmt lock required */
1987 ieee80211_sta_wakeup(ieee
,0);
1989 for(i
= 0; i
< txb
->nr_frags
; i
++) {
1991 if (ieee
->queue_stop
){
1992 ieee
->tx_pending
.txb
= txb
;
1993 ieee
->tx_pending
.frag
= i
;
1996 ieee
->softmac_data_hard_start_xmit(
1998 ieee
->dev
,ieee
->rate
);
1999 //(i+1)<txb->nr_frags);
2000 ieee
->stats
.tx_packets
++;
2001 ieee
->stats
.tx_bytes
+= txb
->fragments
[i
]->len
;
2002 ieee
->dev
->trans_start
= jiffies
;
2006 ieee80211_txb_free(txb
);
2009 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2013 /* called with ieee->lock acquired */
2014 void ieee80211_resume_tx(struct ieee80211_device
*ieee
)
2017 for(i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
; i
++) {
2019 if (ieee
->queue_stop
){
2020 ieee
->tx_pending
.frag
= i
;
2024 ieee
->softmac_data_hard_start_xmit(
2025 ieee
->tx_pending
.txb
->fragments
[i
],
2026 ieee
->dev
,ieee
->rate
);
2027 //(i+1)<ieee->tx_pending.txb->nr_frags);
2028 ieee
->stats
.tx_packets
++;
2029 ieee
->dev
->trans_start
= jiffies
;
2034 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2035 ieee
->tx_pending
.txb
= NULL
;
2039 void ieee80211_reset_queue(struct ieee80211_device
*ieee
)
2041 unsigned long flags
;
2043 spin_lock_irqsave(&ieee
->lock
,flags
);
2044 init_mgmt_queue(ieee
);
2045 if (ieee
->tx_pending
.txb
){
2046 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2047 ieee
->tx_pending
.txb
= NULL
;
2049 ieee
->queue_stop
= 0;
2050 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2054 void ieee80211_rtl_wake_queue(struct ieee80211_device
*ieee
)
2057 unsigned long flags
;
2058 struct sk_buff
*skb
;
2059 struct ieee80211_hdr_3addr
*header
;
2061 spin_lock_irqsave(&ieee
->lock
,flags
);
2062 if (! ieee
->queue_stop
) goto exit
;
2064 ieee
->queue_stop
= 0;
2066 if(ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
){
2067 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))){
2069 header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
2071 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2073 if (ieee
->seq_ctrl
[0] == 0xFFF)
2074 ieee
->seq_ctrl
[0] = 0;
2076 ieee
->seq_ctrl
[0]++;
2078 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2079 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
2080 dev_kfree_skb_any(skb
);//edit by thomas
2083 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2084 ieee80211_resume_tx(ieee
);
2086 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)){
2087 ieee
->softmac_stats
.swtxawake
++;
2088 netif_wake_queue(ieee
->dev
);
2092 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2096 void ieee80211_rtl_stop_queue(struct ieee80211_device
*ieee
)
2098 //unsigned long flags;
2099 //spin_lock_irqsave(&ieee->lock,flags);
2101 if (! netif_queue_stopped(ieee
->dev
)){
2102 netif_stop_queue(ieee
->dev
);
2103 ieee
->softmac_stats
.swtxstop
++;
2105 ieee
->queue_stop
= 1;
2106 //spin_unlock_irqrestore(&ieee->lock,flags);
2111 inline void ieee80211_randomize_cell(struct ieee80211_device
*ieee
)
2114 get_random_bytes(ieee
->current_network
.bssid
, ETH_ALEN
);
2116 /* an IBSS cell address must have the two less significant
2117 * bits of the first byte = 2
2119 ieee
->current_network
.bssid
[0] &= ~0x01;
2120 ieee
->current_network
.bssid
[0] |= 0x02;
2123 /* called in user context only */
2124 void ieee80211_start_master_bss(struct ieee80211_device
*ieee
)
2128 if (ieee
->current_network
.ssid_len
== 0){
2129 strncpy(ieee
->current_network
.ssid
,
2130 IEEE80211_DEFAULT_TX_ESSID
,
2133 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2137 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2139 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2140 ieee
->state
= IEEE80211_LINKED
;
2141 ieee
->link_change(ieee
->dev
);
2142 notify_wx_assoc_event(ieee
);
2144 if (ieee
->data_hard_resume
)
2145 ieee
->data_hard_resume(ieee
->dev
);
2147 netif_carrier_on(ieee
->dev
);
2150 void ieee80211_start_monitor_mode(struct ieee80211_device
*ieee
)
2154 if (ieee
->data_hard_resume
)
2155 ieee
->data_hard_resume(ieee
->dev
);
2157 netif_carrier_on(ieee
->dev
);
2161 void ieee80211_start_ibss_wq(struct work_struct
*work
)
2163 struct delayed_work
*dwork
= to_delayed_work(work
);
2164 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, start_ibss_wq
);
2166 /* iwconfig mode ad-hoc will schedule this and return
2167 * on the other hand this will block further iwconfig SET
2168 * operations because of the wx_sem hold.
2169 * Anyway some most set operations set a flag to speed-up
2170 * (abort) this wq (when syncro scanning) before sleeping
2174 down(&ieee
->wx_sem
);
2177 if (ieee
->current_network
.ssid_len
== 0){
2178 strcpy(ieee
->current_network
.ssid
,IEEE80211_DEFAULT_TX_ESSID
);
2179 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2183 /* check if we have this cell in our network list */
2184 ieee80211_softmac_check_all_nets(ieee
);
2186 if(ieee
->state
== IEEE80211_NOLINK
)
2187 ieee
->current_network
.channel
= 10;
2188 /* if not then the state is not linked. Maybe the user swithced to
2189 * ad-hoc mode just after being in monitor mode, or just after
2190 * being very few time in managed mode (so the card have had no
2191 * time to scan all the chans..) or we have just run up the iface
2192 * after setting ad-hoc mode. So we have to give another try..
2193 * Here, in ibss mode, should be safe to do this without extra care
2194 * (in bss mode we had to make sure no-one tryed to associate when
2195 * we had just checked the ieee->state and we was going to start the
2196 * scan) beacause in ibss mode the ieee80211_new_net function, when
2197 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2198 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2199 * scan, that will stop at the first round because it sees the state
2202 if (ieee
->state
== IEEE80211_NOLINK
)
2203 ieee80211_start_scan_syncro(ieee
);
2205 /* the network definitively is not here.. create a new cell */
2206 if (ieee
->state
== IEEE80211_NOLINK
){
2207 printk("creating new IBSS cell\n");
2209 ieee80211_randomize_cell(ieee
);
2211 if(ieee
->modulation
& IEEE80211_CCK_MODULATION
){
2213 ieee
->current_network
.rates_len
= 4;
2215 ieee
->current_network
.rates
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
2216 ieee
->current_network
.rates
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
2217 ieee
->current_network
.rates
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_5MB
;
2218 ieee
->current_network
.rates
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_11MB
;
2221 ieee
->current_network
.rates_len
= 0;
2223 if(ieee
->modulation
& IEEE80211_OFDM_MODULATION
){
2224 ieee
->current_network
.rates_ex_len
= 8;
2226 ieee
->current_network
.rates_ex
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_6MB
;
2227 ieee
->current_network
.rates_ex
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_9MB
;
2228 ieee
->current_network
.rates_ex
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_12MB
;
2229 ieee
->current_network
.rates_ex
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_18MB
;
2230 ieee
->current_network
.rates_ex
[4] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
2231 ieee
->current_network
.rates_ex
[5] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_36MB
;
2232 ieee
->current_network
.rates_ex
[6] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_48MB
;
2233 ieee
->current_network
.rates_ex
[7] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_54MB
;
2237 ieee
->current_network
.rates_ex_len
= 0;
2241 // By default, WMM function will be disabled in IBSS mode
2242 ieee
->current_network
.QoS_Enable
= 0;
2244 ieee
->current_network
.atim_window
= 0;
2245 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2246 if(ieee
->short_slot
)
2247 ieee
->current_network
.capability
|= WLAN_CAPABILITY_SHORT_SLOT
;
2251 ieee
->state
= IEEE80211_LINKED
;
2252 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2253 ieee
->link_change(ieee
->dev
);
2255 notify_wx_assoc_event(ieee
);
2257 ieee80211_start_send_beacons(ieee
);
2258 printk(KERN_WARNING
"after sending beacon packet!\n");
2260 if (ieee
->data_hard_resume
)
2261 ieee
->data_hard_resume(ieee
->dev
);
2263 netif_carrier_on(ieee
->dev
);
2267 inline void ieee80211_start_ibss(struct ieee80211_device
*ieee
)
2269 queue_delayed_work(ieee
->wq
, &ieee
->start_ibss_wq
, 100);
2272 /* this is called only in user context, with wx_sem held */
2273 void ieee80211_start_bss(struct ieee80211_device
*ieee
)
2275 unsigned long flags
;
2277 // Ref: 802.11d 11.1.3.3
2278 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2280 if(IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
))
2282 if(! ieee
->bGlobalDomain
)
2287 /* check if we have already found the net we
2288 * are interested in (if any).
2289 * if not (we are disassociated and we are not
2290 * in associating / authenticating phase) start the background scanning.
2292 ieee80211_softmac_check_all_nets(ieee
);
2294 /* ensure no-one start an associating process (thus setting
2295 * the ieee->state to ieee80211_ASSOCIATING) while we
2296 * have just cheked it and we are going to enable scan.
2297 * The ieee80211_new_net function is always called with
2298 * lock held (from both ieee80211_softmac_check_all_nets and
2299 * the rx path), so we cannot be in the middle of such function
2301 spin_lock_irqsave(&ieee
->lock
, flags
);
2304 // printk("start bss ENABLE_IPS\n");
2306 if (ieee
->state
== IEEE80211_NOLINK
){
2307 ieee
->actscanning
= true;
2308 ieee80211_rtl_start_scan(ieee
);
2311 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2314 /* called only in userspace context */
2315 void ieee80211_disassociate(struct ieee80211_device
*ieee
)
2317 netif_carrier_off(ieee
->dev
);
2319 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2320 ieee80211_reset_queue(ieee
);
2322 if (ieee
->data_hard_stop
)
2323 ieee
->data_hard_stop(ieee
->dev
);
2325 if(IS_DOT11D_ENABLE(ieee
))
2328 ieee
->link_change(ieee
->dev
);
2329 if (ieee
->state
== IEEE80211_LINKED
)
2330 notify_wx_assoc_event(ieee
);
2331 ieee
->state
= IEEE80211_NOLINK
;
2334 void ieee80211_associate_retry_wq(struct work_struct
*work
)
2336 struct delayed_work
*dwork
= to_delayed_work(work
);
2337 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, associate_retry_wq
);
2338 unsigned long flags
;
2339 down(&ieee
->wx_sem
);
2340 if(!ieee
->proto_started
)
2342 if(ieee
->state
!= IEEE80211_ASSOCIATING_RETRY
)
2344 /* until we do not set the state to IEEE80211_NOLINK
2345 * there are no possibility to have someone else trying
2346 * to start an association procdure (we get here with
2347 * ieee->state = IEEE80211_ASSOCIATING).
2348 * When we set the state to IEEE80211_NOLINK it is possible
2349 * that the RX path run an attempt to associate, but
2350 * both ieee80211_softmac_check_all_nets and the
2351 * RX path works with ieee->lock held so there are no
2352 * problems. If we are still disassociated then start a scan.
2353 * the lock here is necessary to ensure no one try to start
2354 * an association procedure when we have just checked the
2355 * state and we are going to start the scan.
2357 ieee
->state
= IEEE80211_NOLINK
;
2358 ieee
->beinretry
= true;
2359 ieee80211_softmac_check_all_nets(ieee
);
2361 spin_lock_irqsave(&ieee
->lock
, flags
);
2363 if(ieee
->state
== IEEE80211_NOLINK
){
2364 ieee
->beinretry
= false;
2365 ieee
->actscanning
= true;
2366 ieee80211_rtl_start_scan(ieee
);
2368 //YJ,add,080828, notify os here
2369 if(ieee
->state
== IEEE80211_NOLINK
)
2371 notify_wx_assoc_event(ieee
);
2374 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2380 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
)
2382 u8 broadcast_addr
[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2384 struct sk_buff
*skb
= NULL
;
2385 struct ieee80211_probe_response
*b
;
2387 skb
= ieee80211_probe_resp(ieee
, broadcast_addr
);
2391 b
= (struct ieee80211_probe_response
*) skb
->data
;
2392 b
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_BEACON
);
2398 struct sk_buff
*ieee80211_get_beacon(struct ieee80211_device
*ieee
)
2400 struct sk_buff
*skb
;
2401 struct ieee80211_probe_response
*b
;
2403 skb
= ieee80211_get_beacon_(ieee
);
2407 b
= (struct ieee80211_probe_response
*) skb
->data
;
2408 b
->header
.seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2410 if (ieee
->seq_ctrl
[0] == 0xFFF)
2411 ieee
->seq_ctrl
[0] = 0;
2413 ieee
->seq_ctrl
[0]++;
2418 void ieee80211_softmac_stop_protocol(struct ieee80211_device
*ieee
)
2420 ieee
->sync_scan_hurryup
= 1;
2421 down(&ieee
->wx_sem
);
2422 ieee80211_stop_protocol(ieee
);
2427 void ieee80211_stop_protocol(struct ieee80211_device
*ieee
)
2429 if (!ieee
->proto_started
)
2432 ieee
->proto_started
= 0;
2434 ieee80211_stop_send_beacons(ieee
);
2435 if((ieee
->iw_mode
== IW_MODE_INFRA
)&&(ieee
->state
== IEEE80211_LINKED
)) {
2436 SendDisassociation(ieee
,NULL
,WLAN_REASON_DISASSOC_STA_HAS_LEFT
);
2438 del_timer_sync(&ieee
->associate_timer
);
2439 cancel_delayed_work(&ieee
->associate_retry_wq
);
2440 cancel_delayed_work(&ieee
->start_ibss_wq
);
2441 ieee80211_stop_scan(ieee
);
2443 ieee80211_disassociate(ieee
);
2446 void ieee80211_softmac_start_protocol(struct ieee80211_device
*ieee
)
2448 ieee
->sync_scan_hurryup
= 0;
2449 down(&ieee
->wx_sem
);
2450 ieee80211_start_protocol(ieee
);
2454 void ieee80211_start_protocol(struct ieee80211_device
*ieee
)
2459 if (ieee
->proto_started
)
2462 ieee
->proto_started
= 1;
2464 if (ieee
->current_network
.channel
== 0){
2467 if (ch
> MAX_CHANNEL_NUMBER
)
2468 return; /* no channel found */
2470 }while(!GET_DOT11D_INFO(ieee
)->channel_map
[ch
]);
2472 ieee
->current_network
.channel
= ch
;
2475 if (ieee
->current_network
.beacon_interval
== 0)
2476 ieee
->current_network
.beacon_interval
= 100;
2477 ieee
->set_chan(ieee
->dev
,ieee
->current_network
.channel
);
2479 for(i
= 0; i
< 17; i
++) {
2480 ieee
->last_rxseq_num
[i
] = -1;
2481 ieee
->last_rxfrag_num
[i
] = -1;
2482 ieee
->last_packet_time
[i
] = 0;
2485 ieee
->init_wmmparam_flag
= 0;//reinitialize AC_xx_PARAM registers.
2488 /* if the user set the MAC of the ad-hoc cell and then
2489 * switch to managed mode, shall we make sure that association
2490 * attempts does not fail just because the user provide the essid
2491 * and the nic is still checking for the AP MAC ??
2493 switch (ieee
->iw_mode
) {
2495 ieee
->iw_mode
= IW_MODE_INFRA
;
2496 //not set break here intentionly
2498 ieee80211_start_bss(ieee
);
2502 ieee80211_start_ibss(ieee
);
2505 case IW_MODE_MASTER
:
2506 ieee80211_start_master_bss(ieee
);
2509 case IW_MODE_MONITOR
:
2510 ieee80211_start_monitor_mode(ieee
);
2514 ieee
->iw_mode
= IW_MODE_INFRA
;
2515 ieee80211_start_bss(ieee
);
2521 #define DRV_NAME "Ieee80211"
2522 void ieee80211_softmac_init(struct ieee80211_device
*ieee
)
2525 memset(&ieee
->current_network
, 0, sizeof(struct ieee80211_network
));
2527 ieee
->state
= IEEE80211_NOLINK
;
2528 ieee
->sync_scan_hurryup
= 0;
2529 for(i
= 0; i
< 5; i
++) {
2530 ieee
->seq_ctrl
[i
] = 0;
2534 ieee
->queue_stop
= 0;
2536 ieee
->softmac_features
= 0; //so IEEE2100-like driver are happy
2539 ieee
->proto_started
= 0;
2540 ieee
->basic_rate
= IEEE80211_DEFAULT_BASIC_RATE
;
2543 ieee
->ps
= IEEE80211_PS_MBCAST
|IEEE80211_PS_UNICAST
;
2545 // ieee->ps = IEEE80211_PS_DISABLED;
2547 ieee
->sta_sleep
= 0;
2549 ieee
->bInactivePs
= false;
2550 ieee
->actscanning
= false;
2551 ieee
->ListenInterval
= 2;
2552 ieee
->NumRxDataInPeriod
= 0; //YJ,add,080828
2553 ieee
->NumRxBcnInPeriod
= 0; //YJ,add,080828
2554 ieee
->NumRxOkTotal
= 0;//+by amy 080312
2555 ieee
->NumRxUnicast
= 0;//YJ,add,080828,for keep alive
2556 ieee
->beinretry
= false;
2557 ieee
->bHwRadioOff
= false;
2560 init_mgmt_queue(ieee
);
2562 ieee
->tx_pending
.txb
= NULL
;
2564 init_timer(&ieee
->associate_timer
);
2565 ieee
->associate_timer
.data
= (unsigned long)ieee
;
2566 ieee
->associate_timer
.function
= ieee80211_associate_abort_cb
;
2568 init_timer(&ieee
->beacon_timer
);
2569 ieee
->beacon_timer
.data
= (unsigned long) ieee
;
2570 ieee
->beacon_timer
.function
= ieee80211_send_beacon_cb
;
2572 #ifdef PF_SYNCTHREAD
2573 ieee
->wq
= create_workqueue(DRV_NAME
,0);
2575 ieee
->wq
= create_workqueue(DRV_NAME
);
2577 INIT_DELAYED_WORK(&ieee
->start_ibss_wq
,(void*) ieee80211_start_ibss_wq
);
2578 INIT_WORK(&ieee
->associate_complete_wq
,(void*) ieee80211_associate_complete_wq
);
2579 INIT_WORK(&ieee
->associate_procedure_wq
,(void*) ieee80211_associate_procedure_wq
);
2580 INIT_DELAYED_WORK(&ieee
->softmac_scan_wq
,(void*) ieee80211_softmac_scan_wq
);
2581 INIT_DELAYED_WORK(&ieee
->associate_retry_wq
,(void*) ieee80211_associate_retry_wq
);
2582 INIT_WORK(&ieee
->wx_sync_scan_wq
,(void*) ieee80211_wx_sync_scan_wq
);
2583 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2585 sema_init(&ieee
->wx_sem
, 1);
2586 sema_init(&ieee
->scan_sem
, 1);
2588 spin_lock_init(&ieee
->mgmt_tx_lock
);
2589 spin_lock_init(&ieee
->beacon_lock
);
2591 tasklet_init(&ieee
->ps_task
,
2592 (void(*)(unsigned long)) ieee80211_sta_ps
,
2593 (unsigned long)ieee
);
2594 ieee
->pDot11dInfo
= kmalloc(sizeof(RT_DOT11D_INFO
), GFP_ATOMIC
);
2597 void ieee80211_softmac_free(struct ieee80211_device
*ieee
)
2599 down(&ieee
->wx_sem
);
2601 del_timer_sync(&ieee
->associate_timer
);
2602 cancel_delayed_work(&ieee
->associate_retry_wq
);
2605 //add for RF power on power of by lizhaoming 080512
2606 cancel_delayed_work(&ieee
->GPIOChangeRFWorkItem
);
2608 destroy_workqueue(ieee
->wq
);
2609 kfree(ieee
->pDot11dInfo
);
2613 /********************************************************
2614 * Start of WPA code. *
2615 * this is stolen from the ipw2200 driver *
2616 ********************************************************/
2619 static int ieee80211_wpa_enable(struct ieee80211_device
*ieee
, int value
)
2621 /* This is called when wpa_supplicant loads and closes the driver
2623 printk("%s WPA\n",value
? "enabling" : "disabling");
2624 ieee
->wpa_enabled
= value
;
2629 void ieee80211_wpa_assoc_frame(struct ieee80211_device
*ieee
, char *wpa_ie
, int wpa_ie_len
)
2631 /* make sure WPA is enabled */
2632 ieee80211_wpa_enable(ieee
, 1);
2634 ieee80211_disassociate(ieee
);
2638 static int ieee80211_wpa_mlme(struct ieee80211_device
*ieee
, int command
, int reason
)
2644 case IEEE_MLME_STA_DEAUTH
:
2648 case IEEE_MLME_STA_DISASSOC
:
2649 ieee80211_disassociate(ieee
);
2653 printk("Unknown MLME request: %d\n", command
);
2661 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device
*ieee
,
2662 struct ieee_param
*param
, int plen
)
2666 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
2667 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
2670 if (param
->u
.wpa_ie
.len
) {
2671 buf
= kmemdup(param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
,
2676 kfree(ieee
->wpa_ie
);
2678 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
2680 kfree(ieee
->wpa_ie
);
2681 ieee
->wpa_ie
= NULL
;
2682 ieee
->wpa_ie_len
= 0;
2685 ieee80211_wpa_assoc_frame(ieee
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
2689 #define AUTH_ALG_OPEN_SYSTEM 0x1
2690 #define AUTH_ALG_SHARED_KEY 0x2
2692 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device
*ieee
, int value
)
2695 struct ieee80211_security sec
= {
2696 .flags
= SEC_AUTH_MODE
,
2700 if (value
& AUTH_ALG_SHARED_KEY
) {
2701 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
2704 sec
.auth_mode
= WLAN_AUTH_OPEN
;
2708 if (ieee
->set_security
)
2709 ieee
->set_security(ieee
->dev
, &sec
);
2716 static int ieee80211_wpa_set_param(struct ieee80211_device
*ieee
, u8 name
, u32 value
)
2719 unsigned long flags
;
2722 case IEEE_PARAM_WPA_ENABLED
:
2723 ret
= ieee80211_wpa_enable(ieee
, value
);
2726 case IEEE_PARAM_TKIP_COUNTERMEASURES
:
2727 ieee
->tkip_countermeasures
=value
;
2730 case IEEE_PARAM_DROP_UNENCRYPTED
: {
2733 * wpa_supplicant calls set_wpa_enabled when the driver
2734 * is loaded and unloaded, regardless of if WPA is being
2735 * used. No other calls are made which can be used to
2736 * determine if encryption will be used or not prior to
2737 * association being expected. If encryption is not being
2738 * used, drop_unencrypted is set to false, else true -- we
2739 * can use this to determine if the CAP_PRIVACY_ON bit should
2742 struct ieee80211_security sec
= {
2743 .flags
= SEC_ENABLED
,
2746 ieee
->drop_unencrypted
= value
;
2747 /* We only change SEC_LEVEL for open mode. Others
2748 * are set by ipw_wpa_set_encryption.
2751 sec
.flags
|= SEC_LEVEL
;
2752 sec
.level
= SEC_LEVEL_0
;
2755 sec
.flags
|= SEC_LEVEL
;
2756 sec
.level
= SEC_LEVEL_1
;
2758 if (ieee
->set_security
)
2759 ieee
->set_security(ieee
->dev
, &sec
);
2763 case IEEE_PARAM_PRIVACY_INVOKED
:
2764 ieee
->privacy_invoked
=value
;
2767 case IEEE_PARAM_AUTH_ALGS
:
2768 ret
= ieee80211_wpa_set_auth_algs(ieee
, value
);
2771 case IEEE_PARAM_IEEE_802_1X
:
2772 ieee
->ieee802_1x
=value
;
2774 case IEEE_PARAM_WPAX_SELECT
:
2775 // added for WPA2 mixed mode
2776 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
2777 spin_lock_irqsave(&ieee
->wpax_suitlist_lock
,flags
);
2778 ieee
->wpax_type_set
= 1;
2779 ieee
->wpax_type_notify
= value
;
2780 spin_unlock_irqrestore(&ieee
->wpax_suitlist_lock
,flags
);
2784 printk("Unknown WPA param: %d\n",name
);
2791 /* implementation borrowed from hostap driver */
2793 static int ieee80211_wpa_set_encryption(struct ieee80211_device
*ieee
,
2794 struct ieee_param
*param
, int param_len
)
2798 struct ieee80211_crypto_ops
*ops
;
2799 struct ieee80211_crypt_data
**crypt
;
2801 struct ieee80211_security sec
= {
2805 param
->u
.crypt
.err
= 0;
2806 param
->u
.crypt
.alg
[IEEE_CRYPT_ALG_NAME_LEN
- 1] = '\0';
2809 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
2810 param
->u
.crypt
.key_len
) {
2811 printk("Len mismatch %d, %d\n", param_len
,
2812 param
->u
.crypt
.key_len
);
2815 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
2816 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
2817 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
2818 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
2820 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
2825 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
2830 sec
.level
= SEC_LEVEL_0
;
2831 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
2832 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2839 sec
.flags
|= SEC_ENABLED
;
2841 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
2842 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
2843 strcmp(param
->u
.crypt
.alg
, "TKIP"))
2844 goto skip_host_crypt
;
2846 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2847 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
2848 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2849 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0)
2850 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2851 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0)
2852 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2854 printk("unknown crypto alg '%s'\n", param
->u
.crypt
.alg
);
2855 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
2860 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
2861 struct ieee80211_crypt_data
*new_crypt
;
2863 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2865 new_crypt
= kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
2866 if (new_crypt
== NULL
) {
2870 memset(new_crypt
, 0, sizeof(struct ieee80211_crypt_data
));
2871 new_crypt
->ops
= ops
;
2874 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
2876 if (new_crypt
->priv
== NULL
) {
2878 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
2886 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
2887 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
2888 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
2889 (*crypt
)->priv
) < 0) {
2890 printk("key setting failed\n");
2891 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
2897 if (param
->u
.crypt
.set_tx
) {
2898 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
2899 sec
.active_key
= param
->u
.crypt
.idx
;
2900 sec
.flags
|= SEC_ACTIVE_KEY
;
2902 sec
.flags
&= ~SEC_ACTIVE_KEY
;
2904 if (param
->u
.crypt
.alg
!= NULL
) {
2905 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
2907 param
->u
.crypt
.key_len
);
2908 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
2909 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
2911 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
2912 sec
.flags
|= SEC_LEVEL
;
2913 sec
.level
= SEC_LEVEL_1
;
2914 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
2915 sec
.flags
|= SEC_LEVEL
;
2916 sec
.level
= SEC_LEVEL_2
;
2917 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
2918 sec
.flags
|= SEC_LEVEL
;
2919 sec
.level
= SEC_LEVEL_3
;
2923 if (ieee
->set_security
)
2924 ieee
->set_security(ieee
->dev
, &sec
);
2926 /* Do not reset port if card is in Managed mode since resetting will
2927 * generate new IEEE 802.11 authentication which may end up in looping
2928 * with IEEE 802.1X. If your hardware requires a reset after WEP
2929 * configuration (for example... Prism2), implement the reset_port in
2930 * the callbacks structures used to initialize the 802.11 stack. */
2931 if (ieee
->reset_on_keychange
&&
2932 ieee
->iw_mode
!= IW_MODE_INFRA
&&
2934 ieee
->reset_port(ieee
->dev
)) {
2935 printk("reset_port failed\n");
2936 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
2943 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device
*ieee
, struct iw_point
*p
)
2945 struct ieee_param
*param
;
2948 down(&ieee
->wx_sem
);
2949 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
2951 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
){
2956 param
= kmalloc(p
->length
, GFP_KERNEL
);
2961 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
2967 switch (param
->cmd
) {
2969 case IEEE_CMD_SET_WPA_PARAM
:
2970 ret
= ieee80211_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
2971 param
->u
.wpa_param
.value
);
2974 case IEEE_CMD_SET_WPA_IE
:
2975 ret
= ieee80211_wpa_set_wpa_ie(ieee
, param
, p
->length
);
2978 case IEEE_CMD_SET_ENCRYPTION
:
2979 ret
= ieee80211_wpa_set_encryption(ieee
, param
, p
->length
);
2983 ret
= ieee80211_wpa_mlme(ieee
, param
->u
.mlme
.command
,
2984 param
->u
.mlme
.reason_code
);
2988 printk("Unknown WPA supplicant request: %d\n",param
->cmd
);
2993 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
3003 void notify_wx_assoc_event(struct ieee80211_device
*ieee
)
3005 union iwreq_data wrqu
;
3006 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3007 if (ieee
->state
== IEEE80211_LINKED
)
3008 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
, ETH_ALEN
);
3010 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
3011 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);