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
);
577 void ieee80211_softmac_scan_wq(struct work_struct
*work
)
579 struct delayed_work
*dwork
= to_delayed_work(work
);
580 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, softmac_scan_wq
);
581 static short watchdog
= 0;
582 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
583 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
584 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
585 // printk("in %s\n",__func__);
586 down(&ieee
->scan_sem
);
589 ieee
->current_network
.channel
=
590 (ieee
->current_network
.channel
+ 1) % MAX_CHANNEL_NUMBER
;
591 if (watchdog
++ > MAX_CHANNEL_NUMBER
)
592 goto out
; /* no good chans */
594 }while(!channel_map
[ieee
->current_network
.channel
]);
596 //printk("current_network.channel:%d\n", ieee->current_network.channel);
597 if (ieee
->scanning
== 0 )
599 printk("error out, scanning = 0\n");
602 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
603 if(channel_map
[ieee
->current_network
.channel
] == 1)
604 ieee80211_send_probe_requests(ieee
);
606 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
, IEEE80211_SOFTMAC_SCAN_TIME
);
610 ieee
->actscanning
= false;
615 if(IS_DOT11D_ENABLE(ieee
))
616 DOT11D_ScanComplete(ieee
);
620 void ieee80211_beacons_start(struct ieee80211_device
*ieee
)
624 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
626 ieee
->beacon_txing
= 1;
627 ieee80211_send_beacon(ieee
);
629 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
632 void ieee80211_beacons_stop(struct ieee80211_device
*ieee
)
636 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
638 ieee
->beacon_txing
= 0;
639 del_timer_sync(&ieee
->beacon_timer
);
641 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
646 void ieee80211_stop_send_beacons(struct ieee80211_device
*ieee
)
648 if(ieee
->stop_send_beacons
)
649 ieee
->stop_send_beacons(ieee
->dev
);
650 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
651 ieee80211_beacons_stop(ieee
);
655 void ieee80211_start_send_beacons(struct ieee80211_device
*ieee
)
657 if(ieee
->start_send_beacons
)
658 ieee
->start_send_beacons(ieee
->dev
);
659 if(ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
660 ieee80211_beacons_start(ieee
);
664 void ieee80211_softmac_stop_scan(struct ieee80211_device
*ieee
)
666 // unsigned long flags;
668 //ieee->sync_scan_hurryup = 1;
670 down(&ieee
->scan_sem
);
671 // spin_lock_irqsave(&ieee->lock, flags);
673 if (ieee
->scanning
== 1){
675 //del_timer_sync(&ieee->scan_timer);
676 cancel_delayed_work(&ieee
->softmac_scan_wq
);
679 // spin_unlock_irqrestore(&ieee->lock, flags);
683 void ieee80211_stop_scan(struct ieee80211_device
*ieee
)
685 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
686 ieee80211_softmac_stop_scan(ieee
);
688 ieee
->stop_scan(ieee
->dev
);
691 /* called with ieee->lock held */
692 void ieee80211_rtl_start_scan(struct ieee80211_device
*ieee
)
694 if(IS_DOT11D_ENABLE(ieee
) )
696 if(IS_COUNTRY_IE_VALID(ieee
))
698 RESET_CIE_WATCHDOG(ieee
);
701 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
702 if (ieee
->scanning
== 0)
705 //ieee80211_softmac_scan(ieee);
706 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
707 //care this,1203,2007,by lawrence
709 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
,0);
713 ieee
->start_scan(ieee
->dev
);
717 /* called with wx_sem held */
718 void ieee80211_start_scan_syncro(struct ieee80211_device
*ieee
)
720 if(IS_DOT11D_ENABLE(ieee
) )
722 if(IS_COUNTRY_IE_VALID(ieee
))
724 RESET_CIE_WATCHDOG(ieee
);
727 ieee
->sync_scan_hurryup
= 0;
729 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
730 ieee80211_softmac_scan_syncro(ieee
);
732 ieee
->scan_syncro(ieee
->dev
);
736 inline struct sk_buff
*ieee80211_authentication_req(struct ieee80211_network
*beacon
,
737 struct ieee80211_device
*ieee
, int challengelen
)
740 struct ieee80211_authentication
*auth
;
742 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
) + challengelen
);
744 if (!skb
) return NULL
;
746 auth
= (struct ieee80211_authentication
*)
747 skb_put(skb
, sizeof(struct ieee80211_authentication
));
749 auth
->header
.frame_ctl
= IEEE80211_STYPE_AUTH
;
750 if (challengelen
) auth
->header
.frame_ctl
|= IEEE80211_FCTL_WEP
;
752 auth
->header
.duration_id
= 0x013a; //FIXME
754 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
755 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
756 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
758 auth
->algorithm
= ieee
->open_wep
? WLAN_AUTH_OPEN
: WLAN_AUTH_SHARED_KEY
;
760 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
761 ieee
->associate_seq
++;
763 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
769 static struct sk_buff
* ieee80211_probe_resp(struct ieee80211_device
*ieee
, u8
*dest
)
773 struct ieee80211_probe_response
*beacon_buf
;
776 int atim_len
,erp_len
;
777 struct ieee80211_crypt_data
* crypt
;
779 char *ssid
= ieee
->current_network
.ssid
;
780 int ssid_len
= ieee
->current_network
.ssid_len
;
781 int rate_len
= ieee
->current_network
.rates_len
+2;
782 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
783 int wpa_ie_len
= ieee
->wpa_ie_len
;
784 if(rate_ex_len
> 0) rate_ex_len
+=2;
786 if(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
791 if(ieee80211_is_54g(ieee
->current_network
))
796 beacon_size
= sizeof(struct ieee80211_probe_response
)+
805 skb
= dev_alloc_skb(beacon_size
);
810 beacon_buf
= (struct ieee80211_probe_response
*) skb_put(skb
, beacon_size
);
812 memcpy (beacon_buf
->header
.addr1
, dest
,ETH_ALEN
);
813 memcpy (beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
814 memcpy (beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
816 beacon_buf
->header
.duration_id
= 0; //FIXME
817 beacon_buf
->beacon_interval
=
818 cpu_to_le16(ieee
->current_network
.beacon_interval
);
819 beacon_buf
->capability
=
820 cpu_to_le16(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
);
822 if(ieee
->short_slot
&& (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_SLOT
))
823 cpu_to_le16((beacon_buf
->capability
|= WLAN_CAPABILITY_SHORT_SLOT
));
825 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
827 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
828 ((0 == strcmp(crypt
->ops
->name
, "WEP")) || wpa_ie_len
);
831 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
834 beacon_buf
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
);
836 beacon_buf
->info_element
.id
= MFIE_TYPE_SSID
;
837 beacon_buf
->info_element
.len
= ssid_len
;
839 tag
= (u8
*) beacon_buf
->info_element
.data
;
841 memcpy(tag
, ssid
, ssid_len
);
845 *(tag
++) = MFIE_TYPE_RATES
;
846 *(tag
++) = rate_len
-2;
847 memcpy(tag
,ieee
->current_network
.rates
,rate_len
-2);
850 *(tag
++) = MFIE_TYPE_DS_SET
;
852 *(tag
++) = ieee
->current_network
.channel
;
855 *(tag
++) = MFIE_TYPE_IBSS_SET
;
857 *((u16
*)(tag
)) = cpu_to_le16(ieee
->current_network
.atim_window
);
862 *(tag
++) = MFIE_TYPE_ERP
;
868 *(tag
++) = MFIE_TYPE_RATES_EX
;
869 *(tag
++) = rate_ex_len
-2;
870 memcpy(tag
,ieee
->current_network
.rates_ex
,rate_ex_len
-2);
876 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
877 {//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
878 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
881 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
884 skb
->dev
= ieee
->dev
;
888 struct sk_buff
* ieee80211_assoc_resp(struct ieee80211_device
*ieee
, u8
*dest
)
893 struct ieee80211_crypt_data
* crypt
;
894 struct ieee80211_assoc_response_frame
*assoc
;
897 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
898 int len
= sizeof(struct ieee80211_assoc_response_frame
) + rate_len
;
900 skb
= dev_alloc_skb(len
);
905 assoc
= (struct ieee80211_assoc_response_frame
*)
906 skb_put(skb
,sizeof(struct ieee80211_assoc_response_frame
));
908 assoc
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
);
909 memcpy(assoc
->header
.addr1
, dest
,ETH_ALEN
);
910 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
911 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
912 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
913 WLAN_CAPABILITY_BSS
: WLAN_CAPABILITY_IBSS
);
917 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
919 if (ieee
->host_encrypt
)
920 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
923 encrypt
= ( crypt
&& crypt
->ops
);
926 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
929 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
930 if (ieee
->assoc_id
== 0x2007) ieee
->assoc_id
=0;
931 else ieee
->assoc_id
++;
933 tag
= (u8
*) skb_put(skb
, rate_len
);
935 ieee80211_MFIE_Brate(ieee
, &tag
);
936 ieee80211_MFIE_Grate(ieee
, &tag
);
941 struct sk_buff
* ieee80211_auth_resp(struct ieee80211_device
*ieee
,int status
, u8
*dest
)
944 struct ieee80211_authentication
*auth
;
946 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
)+1);
951 skb
->len
= sizeof(struct ieee80211_authentication
);
953 auth
= (struct ieee80211_authentication
*)skb
->data
;
955 auth
->status
= cpu_to_le16(status
);
956 auth
->transaction
= cpu_to_le16(2);
957 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
959 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
960 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
961 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
962 auth
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_AUTH
);
968 struct sk_buff
* ieee80211_null_func(struct ieee80211_device
*ieee
,short pwr
)
971 struct ieee80211_hdr_3addr
* hdr
;
973 skb
= dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr
));
978 hdr
= (struct ieee80211_hdr_3addr
*)skb_put(skb
,sizeof(struct ieee80211_hdr_3addr
));
980 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
981 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
982 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
984 hdr
->frame_ctl
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
985 IEEE80211_STYPE_NULLFUNC
| IEEE80211_FCTL_TODS
|
986 (pwr
? IEEE80211_FCTL_PM
:0));
994 void ieee80211_resp_to_assoc_rq(struct ieee80211_device
*ieee
, u8
* dest
)
996 struct sk_buff
*buf
= ieee80211_assoc_resp(ieee
, dest
);
999 softmac_mgmt_xmit(buf
, ieee
);
1000 dev_kfree_skb_any(buf
);//edit by thomas
1005 void ieee80211_resp_to_auth(struct ieee80211_device
*ieee
, int s
, u8
* dest
)
1007 struct sk_buff
*buf
= ieee80211_auth_resp(ieee
, s
, dest
);
1010 softmac_mgmt_xmit(buf
, ieee
);
1011 dev_kfree_skb_any(buf
);//edit by thomas
1016 void ieee80211_resp_to_probe(struct ieee80211_device
*ieee
, u8
*dest
)
1019 struct sk_buff
*buf
= ieee80211_probe_resp(ieee
, dest
);
1022 softmac_mgmt_xmit(buf
, ieee
);
1023 dev_kfree_skb_any(buf
);//edit by thomas
1028 inline struct sk_buff
*ieee80211_association_req(struct ieee80211_network
*beacon
,struct ieee80211_device
*ieee
)
1030 struct sk_buff
*skb
;
1031 //unsigned long flags;
1033 struct ieee80211_assoc_request_frame
*hdr
;
1035 //short info_addr = 0;
1037 //u16 suite_count = 0;
1038 //u8 suit_select = 0;
1039 unsigned int wpa_len
= beacon
->wpa_ie_len
;
1040 //struct net_device *dev = ieee->dev;
1041 //union iwreq_data wrqu;
1045 // for testing purpose
1046 unsigned int rsn_len
= beacon
->rsn_ie_len
;
1048 unsigned int rsn_len
= beacon
->rsn_ie_len
- 4;
1050 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
1051 unsigned int wmm_info_len
= beacon
->QoS_Enable
?9:0;
1052 unsigned int turbo_info_len
= beacon
->Turbo_Enable
?9:0;
1054 u8 encry_proto
= ieee
->wpax_type_notify
& 0xff;
1055 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1056 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1060 //[0] Notify type of encryption: WPA/WPA2
1061 //[1] pair wise type
1063 if(ieee
->wpax_type_set
) {
1064 if (IEEE_PROTO_WPA
== encry_proto
) {
1066 } else if (IEEE_PROTO_RSN
== encry_proto
) {
1070 len
= sizeof(struct ieee80211_assoc_request_frame
)+
1071 + beacon
->ssid_len
//essid tagged val
1072 + rate_len
//rates tagged val
1078 skb
= dev_alloc_skb(len
);
1083 hdr
= (struct ieee80211_assoc_request_frame
*)
1084 skb_put(skb
, sizeof(struct ieee80211_assoc_request_frame
));
1087 hdr
->header
.frame_ctl
= IEEE80211_STYPE_ASSOC_REQ
;
1088 hdr
->header
.duration_id
= 37; //FIXME
1089 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1090 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1091 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1092 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);//for HW security, John
1094 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_BSS
);
1095 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1096 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1097 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1098 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1100 if(ieee
->short_slot
)
1101 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
1103 hdr
->listen_interval
= 0xa; //FIXME
1105 hdr
->info_element
.id
= MFIE_TYPE_SSID
;
1107 hdr
->info_element
.len
= beacon
->ssid_len
;
1108 tag
= skb_put(skb
, beacon
->ssid_len
);
1109 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1111 tag
= skb_put(skb
, rate_len
);
1113 ieee80211_MFIE_Brate(ieee
, &tag
);
1114 ieee80211_MFIE_Grate(ieee
, &tag
);
1116 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1117 //choose AES encryption as default algorithm while using mixed mode
1119 tag
= skb_put(skb
,ieee
->wpa_ie_len
);
1120 memcpy(tag
,ieee
->wpa_ie
,ieee
->wpa_ie_len
);
1122 tag
= skb_put(skb
,wmm_info_len
);
1124 ieee80211_WMM_Info(ieee
, &tag
);
1126 tag
= skb_put(skb
,turbo_info_len
);
1127 if(turbo_info_len
) {
1128 ieee80211_TURBO_Info(ieee
, &tag
);
1134 void ieee80211_associate_abort(struct ieee80211_device
*ieee
)
1137 unsigned long flags
;
1138 spin_lock_irqsave(&ieee
->lock
, flags
);
1140 ieee
->associate_seq
++;
1142 /* don't scan, and avoid to have the RX path possibily
1143 * try again to associate. Even do not react to AUTH or
1144 * ASSOC response. Just wait for the retry wq to be scheduled.
1145 * Here we will check if there are good nets to associate
1146 * with, so we retry or just get back to NO_LINK and scanning
1148 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
){
1149 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1150 ieee
->softmac_stats
.no_auth_rs
++;
1152 IEEE80211_DEBUG_MGMT("Association failed\n");
1153 ieee
->softmac_stats
.no_ass_rs
++;
1156 ieee
->state
= IEEE80211_ASSOCIATING_RETRY
;
1158 queue_delayed_work(ieee
->wq
, &ieee
->associate_retry_wq
,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME
);
1160 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1163 void ieee80211_associate_abort_cb(unsigned long dev
)
1165 ieee80211_associate_abort((struct ieee80211_device
*) dev
);
1169 void ieee80211_associate_step1(struct ieee80211_device
*ieee
)
1171 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1172 struct sk_buff
*skb
;
1174 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1175 ieee
->softmac_stats
.tx_auth_rq
++;
1176 skb
=ieee80211_authentication_req(beacon
, ieee
, 0);
1179 ieee80211_associate_abort(ieee
);
1182 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATING
;
1183 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1184 //printk("---Sending authentication request\n");
1185 softmac_mgmt_xmit(skb
, ieee
);
1186 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1187 if(!timer_pending(&ieee
->associate_timer
)){
1188 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1189 add_timer(&ieee
->associate_timer
);
1191 //If call dev_kfree_skb_any,a warning will ocur....
1192 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1193 //So ... 1204 by lawrence.
1194 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1195 //dev_kfree_skb_any(skb);//edit by thomas
1199 void ieee80211_rtl_auth_challenge(struct ieee80211_device
*ieee
, u8
*challenge
, int chlen
)
1202 struct sk_buff
*skb
;
1203 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1204 // int hlen = sizeof(struct ieee80211_authentication);
1205 del_timer_sync(&ieee
->associate_timer
);
1206 ieee
->associate_seq
++;
1207 ieee
->softmac_stats
.tx_auth_rq
++;
1209 skb
= ieee80211_authentication_req(beacon
, ieee
, chlen
+2);
1211 ieee80211_associate_abort(ieee
);
1213 c
= skb_put(skb
, chlen
+2);
1214 *(c
++) = MFIE_TYPE_CHALLENGE
;
1216 memcpy(c
, challenge
, chlen
);
1218 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1220 ieee80211_encrypt_fragment(ieee
, skb
, sizeof(struct ieee80211_hdr_3addr
));
1222 softmac_mgmt_xmit(skb
, ieee
);
1223 if (!timer_pending(&ieee
->associate_timer
)){
1224 //printk("=========>add timer again, to crash\n");
1225 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1226 add_timer(&ieee
->associate_timer
);
1228 dev_kfree_skb_any(skb
);//edit by thomas
1233 void ieee80211_associate_step2(struct ieee80211_device
*ieee
)
1235 struct sk_buff
* skb
;
1236 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1238 del_timer_sync(&ieee
->associate_timer
);
1240 IEEE80211_DEBUG_MGMT("Sending association request\n");
1241 ieee
->softmac_stats
.tx_ass_rq
++;
1242 skb
=ieee80211_association_req(beacon
, ieee
);
1244 ieee80211_associate_abort(ieee
);
1246 softmac_mgmt_xmit(skb
, ieee
);
1247 if (!timer_pending(&ieee
->associate_timer
)){
1248 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1249 add_timer(&ieee
->associate_timer
);
1251 //dev_kfree_skb_any(skb);//edit by thomas
1255 void ieee80211_associate_complete_wq(struct work_struct
*work
)
1257 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_complete_wq
);
1259 printk(KERN_INFO
"Associated successfully\n");
1260 if(ieee80211_is_54g(ieee
->current_network
) &&
1261 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1264 printk(KERN_INFO
"Using G rates\n");
1267 printk(KERN_INFO
"Using B rates\n");
1269 ieee
->link_change(ieee
->dev
);
1270 notify_wx_assoc_event(ieee
);
1271 if (ieee
->data_hard_resume
)
1272 ieee
->data_hard_resume(ieee
->dev
);
1273 netif_carrier_on(ieee
->dev
);
1276 void ieee80211_associate_complete(struct ieee80211_device
*ieee
)
1279 del_timer_sync(&ieee
->associate_timer
);
1281 for(i
= 0; i
< 6; i
++) {
1282 //ieee->seq_ctrl[i] = 0;
1284 ieee
->state
= IEEE80211_LINKED
;
1285 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1287 queue_work(ieee
->wq
, &ieee
->associate_complete_wq
);
1290 void ieee80211_associate_procedure_wq(struct work_struct
*work
)
1292 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_procedure_wq
);
1294 ieee
->sync_scan_hurryup
= 1;
1295 down(&ieee
->wx_sem
);
1297 if (ieee
->data_hard_stop
)
1298 ieee
->data_hard_stop(ieee
->dev
);
1300 ieee80211_stop_scan(ieee
);
1301 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
1303 ieee
->associate_seq
= 1;
1304 ieee80211_associate_step1(ieee
);
1309 inline void ieee80211_softmac_new_net(struct ieee80211_device
*ieee
, struct ieee80211_network
*net
)
1311 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+1];
1312 int tmp_ssid_len
= 0;
1314 short apset
,ssidset
,ssidbroad
,apmatch
,ssidmatch
;
1316 /* we are interested in new new only if we are not associated
1317 * and we are not associating / authenticating
1319 if (ieee
->state
!= IEEE80211_NOLINK
)
1322 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
& WLAN_CAPABILITY_BSS
))
1325 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
& WLAN_CAPABILITY_IBSS
))
1329 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
){
1330 /* if the user specified the AP MAC, we need also the essid
1331 * This could be obtained by beacons or, if the network does not
1332 * broadcast it, it can be put manually.
1334 apset
= ieee
->wap_set
;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1335 ssidset
= ieee
->ssid_set
;//ieee->current_network.ssid[0] != '\0';
1336 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0]== '\0');
1337 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
, ETH_ALEN
)==0);
1339 if(ieee
->current_network
.ssid_len
!= net
->ssid_len
)
1342 ssidmatch
= (0==strncmp(ieee
->current_network
.ssid
, net
->ssid
, net
->ssid_len
));
1344 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1345 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1347 if ( /* if the user set the AP check if match.
1348 * if the network does not broadcast essid we check the user supplyed ANY essid
1349 * if the network does broadcast and the user does not set essid it is OK
1350 * if the network does broadcast and the user did set essid chech if essid match
1352 ( apset
&& apmatch
&&
1353 ((ssidset
&& ssidbroad
&& ssidmatch
) || (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
)) ) ||
1354 /* if the ap is not set, check that the user set the bssid
1355 * and the network does bradcast and that those two bssid matches
1357 (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
)
1361 /* if the essid is hidden replace it with the
1362 * essid provided by the user.
1365 strncpy(tmp_ssid
, ieee
->current_network
.ssid
, IW_ESSID_MAX_SIZE
);
1366 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1368 memcpy(&ieee
->current_network
, net
, sizeof(struct ieee80211_network
));
1371 strncpy(ieee
->current_network
.ssid
, tmp_ssid
, IW_ESSID_MAX_SIZE
);
1372 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1374 printk(KERN_INFO
"Linking with %s: channel is %d\n",ieee
->current_network
.ssid
,ieee
->current_network
.channel
);
1376 if (ieee
->iw_mode
== IW_MODE_INFRA
){
1377 ieee
->state
= IEEE80211_ASSOCIATING
;
1378 ieee
->beinretry
= false;
1379 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1381 if(ieee80211_is_54g(ieee
->current_network
) &&
1382 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1384 printk(KERN_INFO
"Using G rates\n");
1387 printk(KERN_INFO
"Using B rates\n");
1389 ieee
->state
= IEEE80211_LINKED
;
1390 ieee
->beinretry
= false;
1398 void ieee80211_softmac_check_all_nets(struct ieee80211_device
*ieee
)
1400 unsigned long flags
;
1401 struct ieee80211_network
*target
;
1403 spin_lock_irqsave(&ieee
->lock
, flags
);
1404 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1406 /* if the state become different that NOLINK means
1407 * we had found what we are searching for
1410 if (ieee
->state
!= IEEE80211_NOLINK
)
1413 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
))
1414 ieee80211_softmac_new_net(ieee
, target
);
1417 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1422 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1424 struct ieee80211_authentication
*a
;
1426 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1427 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb
->len
);
1431 a
= (struct ieee80211_authentication
*) skb
->data
;
1432 if(skb
->len
> (sizeof(struct ieee80211_authentication
) +3)){
1433 t
= skb
->data
+ sizeof(struct ieee80211_authentication
);
1435 if(*(t
++) == MFIE_TYPE_CHALLENGE
){
1437 *challenge
= (u8
*)kmalloc(*chlen
, GFP_ATOMIC
);
1438 memcpy(*challenge
, t
, *chlen
);
1442 return cpu_to_le16(a
->status
);
1447 int auth_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1449 struct ieee80211_authentication
*a
;
1451 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1452 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb
->len
);
1455 a
= (struct ieee80211_authentication
*) skb
->data
;
1457 memcpy(dest
,a
->header
.addr2
, ETH_ALEN
);
1459 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1460 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1462 return WLAN_STATUS_SUCCESS
;
1465 static short probe_rq_parse(struct ieee80211_device
*ieee
, struct sk_buff
*skb
, u8
*src
)
1472 struct ieee80211_hdr_3addr
*header
=
1473 (struct ieee80211_hdr_3addr
*) skb
->data
;
1475 if (skb
->len
< sizeof (struct ieee80211_hdr_3addr
))
1476 return -1; /* corrupted */
1478 memcpy(src
,header
->addr2
, ETH_ALEN
);
1480 skbend
= (u8
*)skb
->data
+ skb
->len
;
1482 tag
= skb
->data
+ sizeof (struct ieee80211_hdr_3addr
);
1484 while (tag
+1 < skbend
){
1490 tag
++; /* point to the len field */
1491 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1492 tag
++; /* point to the next tag */
1495 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1496 if (ssidlen
== 0) return 1;
1498 if (!ssid
) return 1; /* ssid not found in tagged param */
1499 return (!strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
));
1503 int assoc_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1505 struct ieee80211_assoc_request_frame
*a
;
1507 if (skb
->len
< (sizeof(struct ieee80211_assoc_request_frame
) -
1508 sizeof(struct ieee80211_info_element
))) {
1510 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb
->len
);
1514 a
= (struct ieee80211_assoc_request_frame
*) skb
->data
;
1516 memcpy(dest
,a
->header
.addr2
,ETH_ALEN
);
1521 static inline u16
assoc_parse(struct sk_buff
*skb
, int *aid
)
1523 struct ieee80211_assoc_response_frame
*a
;
1524 if (skb
->len
< sizeof(struct ieee80211_assoc_response_frame
)){
1525 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1529 a
= (struct ieee80211_assoc_response_frame
*) skb
->data
;
1530 *aid
= le16_to_cpu(a
->aid
) & 0x3fff;
1531 return le16_to_cpu(a
->status
);
1535 ieee80211_rx_probe_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1539 //IEEE80211DMESG("Rx probe");
1540 ieee
->softmac_stats
.rx_probe_rq
++;
1541 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1542 if (probe_rq_parse(ieee
, skb
, dest
)){
1543 //IEEE80211DMESG("Was for me!");
1544 ieee
->softmac_stats
.tx_probe_rs
++;
1545 ieee80211_resp_to_probe(ieee
, dest
);
1550 ieee80211_rx_auth_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1554 //IEEE80211DMESG("Rx probe");
1555 ieee
->softmac_stats
.rx_auth_rq
++;
1557 if ((status
= auth_rq_parse(skb
, dest
))!= -1){
1558 ieee80211_resp_to_auth(ieee
, status
, dest
);
1560 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1565 ieee80211_rx_assoc_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1569 //unsigned long flags;
1571 ieee
->softmac_stats
.rx_ass_rq
++;
1572 if (assoc_rq_parse(skb
,dest
) != -1){
1573 ieee80211_resp_to_assoc_rq(ieee
, dest
);
1576 printk(KERN_INFO
"New client associated: "MAC_FMT
"\n", MAC_ARG(dest
));
1581 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device
*ieee
, short pwr
)
1584 struct sk_buff
*buf
= ieee80211_null_func(ieee
, pwr
);
1587 softmac_ps_mgmt_xmit(buf
, ieee
);
1592 short ieee80211_sta_ps_sleep(struct ieee80211_device
*ieee
, u32
*time_h
, u32
*time_l
)
1597 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1598 ieee->iw_mode != IW_MODE_INFRA ||
1599 ieee->state != IEEE80211_LINKED)
1603 dtim
= ieee
->current_network
.dtim_data
;
1606 if(!(dtim
& IEEE80211_DTIM_VALID
))
1609 timeout
= ieee
->current_network
.beacon_interval
;
1611 //printk("VALID\n");
1612 ieee
->current_network
.dtim_data
= IEEE80211_DTIM_INVALID
;
1614 if(dtim
& ((IEEE80211_DTIM_UCAST
| IEEE80211_DTIM_MBCAST
)& ieee
->ps
))
1617 if(!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
)))
1620 if(!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
)))
1623 if((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
1624 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
1628 *time_l
= ieee
->current_network
.last_dtim_sta_time
[0]
1629 + MSECS((ieee
->current_network
.beacon_interval
));
1630 //* ieee->current_network.dtim_period));
1631 //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);
1635 *time_h
= ieee
->current_network
.last_dtim_sta_time
[1];
1636 if(time_l
&& *time_l
< ieee
->current_network
.last_dtim_sta_time
[0])
1645 inline void ieee80211_sta_ps(struct ieee80211_device
*ieee
)
1651 unsigned long flags
,flags2
;
1653 spin_lock_irqsave(&ieee
->lock
, flags
);
1655 if((ieee
->ps
== IEEE80211_PS_DISABLED
||
1657 ieee
->iw_mode
!= IW_MODE_INFRA
||
1658 ieee
->state
!= IEEE80211_LINKED
)){
1660 //#warning CHECK_LOCK_HERE
1661 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1663 ieee80211_sta_wakeup(ieee
, 1);
1665 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1668 sleep
= ieee80211_sta_ps_sleep(ieee
,&th
, &tl
);
1669 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
1670 /* 2 wake, 1 sleep, 0 do nothing */
1676 if(ieee
->sta_sleep
== 1)
1677 ieee
->enter_sleep_state(ieee
->dev
,th
,tl
);
1679 else if(ieee
->sta_sleep
== 0){
1680 // printk("send null 1\n");
1681 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1683 if(ieee
->ps_is_queue_empty(ieee
->dev
)){
1686 ieee
->sta_sleep
= 2;
1688 ieee
->ps_request_tx_ack(ieee
->dev
);
1690 ieee80211_sta_ps_send_null_frame(ieee
,1);
1695 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1700 }else if(sleep
== 2){
1701 //#warning CHECK_LOCK_HERE
1702 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1704 // printk("send wakeup packet\n");
1705 ieee80211_sta_wakeup(ieee
,1);
1707 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1711 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1715 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
)
1717 if(ieee
->sta_sleep
== 0){
1719 // printk("Warning: driver is probably failing to report TX ps error\n");
1720 ieee
->ps_request_tx_ack(ieee
->dev
);
1721 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1727 if(ieee
->sta_sleep
== 1)
1728 ieee
->sta_wake_up(ieee
->dev
);
1730 ieee
->sta_sleep
= 0;
1733 ieee
->ps_request_tx_ack(ieee
->dev
);
1734 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1738 void ieee80211_ps_tx_ack(struct ieee80211_device
*ieee
, short success
)
1740 unsigned long flags
,flags2
;
1742 spin_lock_irqsave(&ieee
->lock
, flags
);
1743 if(ieee
->sta_sleep
== 2){
1744 /* Null frame with PS bit set */
1747 // printk("==================> %s::enter sleep state\n",__func__);
1748 ieee
->sta_sleep
= 1;
1749 ieee
->enter_sleep_state(ieee
->dev
,ieee
->ps_th
,ieee
->ps_tl
);
1751 /* if the card report not success we can't be sure the AP
1752 * has not RXed so we can't assume the AP believe us awake
1755 /* 21112005 - tx again null without PS bit if lost */
1758 if((ieee
->sta_sleep
== 0) && !success
){
1759 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1760 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1761 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1764 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1768 ieee80211_rx_frame_softmac(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
1769 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
1772 struct ieee80211_hdr_3addr
*header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
1777 struct ieee80211_assoc_response_frame
*assoc_resp
;
1778 struct ieee80211_info_element
*info_element
;
1780 if(!ieee
->proto_started
)
1783 if(ieee
->sta_sleep
|| (ieee
->ps
!= IEEE80211_PS_DISABLED
&&
1784 ieee
->iw_mode
== IW_MODE_INFRA
&&
1785 ieee
->state
== IEEE80211_LINKED
))
1787 tasklet_schedule(&ieee
->ps_task
);
1789 if(WLAN_FC_GET_STYPE(header
->frame_ctl
) != IEEE80211_STYPE_PROBE_RESP
&&
1790 WLAN_FC_GET_STYPE(header
->frame_ctl
) != IEEE80211_STYPE_BEACON
)
1791 ieee
->last_rx_ps_time
= jiffies
;
1793 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
1795 case IEEE80211_STYPE_ASSOC_RESP
:
1796 case IEEE80211_STYPE_REASSOC_RESP
:
1798 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1799 WLAN_FC_GET_STYPE(header
->frame_ctl
));
1800 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1801 ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATED
&&
1802 ieee
->iw_mode
== IW_MODE_INFRA
){
1803 if (0 == (errcode
=assoc_parse(skb
, &aid
))){
1806 ieee
->state
=IEEE80211_LINKED
;
1807 ieee
->assoc_id
= aid
;
1808 ieee
->softmac_stats
.rx_ass_ok
++;
1810 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
1811 if(1 == rx_stats
->nic_type
) //card type is 8187
1813 goto associate_complete
;
1815 assoc_resp
= (struct ieee80211_assoc_response_frame
*)skb
->data
;
1816 info_element
= &assoc_resp
->info_element
;
1817 left
= skb
->len
- ((void*)info_element
- (void*)assoc_resp
);
1819 while (left
>= sizeof(struct ieee80211_info_element_hdr
)) {
1820 if (sizeof(struct ieee80211_info_element_hdr
) + info_element
->len
> left
) {
1821 printk(KERN_WARNING
"[re]associate reeponse error!");
1824 switch (info_element
->id
) {
1825 case MFIE_TYPE_GENERIC
:
1826 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element
->len
);
1827 if (info_element
->len
>= 8 &&
1828 info_element
->data
[0] == 0x00 &&
1829 info_element
->data
[1] == 0x50 &&
1830 info_element
->data
[2] == 0xf2 &&
1831 info_element
->data
[3] == 0x02 &&
1832 info_element
->data
[4] == 0x01) {
1833 // Not care about version at present.
1834 //WMM Parameter Element
1835 memcpy(ieee
->current_network
.wmm_param
,(u8
*)(info_element
->data\
1836 + 8),(info_element
->len
- 8));
1838 if (((ieee
->current_network
.wmm_info
^info_element
->data
[6])& \
1839 0x0f)||(!ieee
->init_wmmparam_flag
)) {
1840 // refresh parameter element for current network
1841 // update the register parameter for hardware
1842 ieee
->init_wmmparam_flag
= 1;
1843 queue_work(ieee
->wq
, &ieee
->wmm_param_update_wq
);
1846 //update info_element for current network
1847 ieee
->current_network
.wmm_info
= info_element
->data
[6];
1851 //nothing to do at present!!!
1855 left
-= sizeof(struct ieee80211_info_element_hdr
) +
1857 info_element
= (struct ieee80211_info_element
*)
1858 &info_element
->data
[info_element
->len
];
1860 if(!ieee
->init_wmmparam_flag
) //legacy AP, reset the AC_xx_param register
1862 queue_work(ieee
->wq
,&ieee
->wmm_param_update_wq
);
1863 ieee
->init_wmmparam_flag
= 1;//indicate AC_xx_param upated since last associate
1866 ieee80211_associate_complete(ieee
);
1868 ieee
->softmac_stats
.rx_ass_err
++;
1869 IEEE80211_DEBUG_MGMT(
1870 "Association response status code 0x%x\n",
1872 ieee80211_associate_abort(ieee
);
1877 case IEEE80211_STYPE_ASSOC_REQ
:
1878 case IEEE80211_STYPE_REASSOC_REQ
:
1880 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1881 ieee
->iw_mode
== IW_MODE_MASTER
)
1883 ieee80211_rx_assoc_rq(ieee
, skb
);
1886 case IEEE80211_STYPE_AUTH
:
1888 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
){
1889 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
&&
1890 ieee
->iw_mode
== IW_MODE_INFRA
){
1892 IEEE80211_DEBUG_MGMT("Received authentication response");
1894 if (0 == (errcode
=auth_parse(skb
, &challenge
, &chlen
))){
1895 if(ieee
->open_wep
|| !challenge
){
1896 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATED
;
1897 ieee
->softmac_stats
.rx_auth_rs_ok
++;
1899 ieee80211_associate_step2(ieee
);
1901 ieee80211_rtl_auth_challenge(ieee
, challenge
, chlen
);
1904 ieee
->softmac_stats
.rx_auth_rs_err
++;
1905 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode
);
1906 ieee80211_associate_abort(ieee
);
1909 }else if (ieee
->iw_mode
== IW_MODE_MASTER
){
1910 ieee80211_rx_auth_rq(ieee
, skb
);
1915 case IEEE80211_STYPE_PROBE_REQ
:
1917 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
1918 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
1919 ieee
->iw_mode
== IW_MODE_MASTER
) &&
1920 ieee
->state
== IEEE80211_LINKED
))
1922 ieee80211_rx_probe_rq(ieee
, skb
);
1925 case IEEE80211_STYPE_DISASSOC
:
1926 case IEEE80211_STYPE_DEAUTH
:
1927 /* FIXME for now repeat all the association procedure
1928 * both for disassociation and deauthentication
1930 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1931 (ieee
->state
== IEEE80211_LINKED
) &&
1932 (ieee
->iw_mode
== IW_MODE_INFRA
) &&
1933 (!memcmp(header
->addr2
,ieee
->current_network
.bssid
,ETH_ALEN
))){
1934 ieee
->state
= IEEE80211_ASSOCIATING
;
1935 ieee
->softmac_stats
.reassoc
++;
1937 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
1938 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1948 //dev_kfree_skb_any(skb);
1954 /* following are for a simplier TX queue management.
1955 * Instead of using netif_[stop/wake]_queue the driver
1956 * will uses these two function (plus a reset one), that
1957 * will internally uses the kernel netif_* and takes
1958 * care of the ieee802.11 fragmentation.
1959 * So the driver receives a fragment per time and might
1960 * call the stop function when it want without take care
1961 * to have enough room to TX an entire packet.
1962 * This might be useful if each fragment need it's own
1963 * descriptor, thus just keep a total free memory > than
1964 * the max fragmentation threshold is not enough.. If the
1965 * ieee802.11 stack passed a TXB struct then you needed
1966 * to keep N free descriptors where
1967 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
1968 * In this way you need just one and the 802.11 stack
1969 * will take care of buffering fragments and pass them to
1970 * to the driver later, when it wakes the queue.
1973 void ieee80211_softmac_xmit(struct ieee80211_txb
*txb
, struct ieee80211_device
*ieee
)
1977 unsigned long flags
;
1980 spin_lock_irqsave(&ieee
->lock
,flags
);
1982 /* called with 2nd parm 0, no tx mgmt lock required */
1983 ieee80211_sta_wakeup(ieee
,0);
1985 for(i
= 0; i
< txb
->nr_frags
; i
++) {
1987 if (ieee
->queue_stop
){
1988 ieee
->tx_pending
.txb
= txb
;
1989 ieee
->tx_pending
.frag
= i
;
1992 ieee
->softmac_data_hard_start_xmit(
1994 ieee
->dev
,ieee
->rate
);
1995 //(i+1)<txb->nr_frags);
1996 ieee
->stats
.tx_packets
++;
1997 ieee
->stats
.tx_bytes
+= txb
->fragments
[i
]->len
;
1998 ieee
->dev
->trans_start
= jiffies
;
2002 ieee80211_txb_free(txb
);
2005 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2009 /* called with ieee->lock acquired */
2010 void ieee80211_resume_tx(struct ieee80211_device
*ieee
)
2013 for(i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
; i
++) {
2015 if (ieee
->queue_stop
){
2016 ieee
->tx_pending
.frag
= i
;
2020 ieee
->softmac_data_hard_start_xmit(
2021 ieee
->tx_pending
.txb
->fragments
[i
],
2022 ieee
->dev
,ieee
->rate
);
2023 //(i+1)<ieee->tx_pending.txb->nr_frags);
2024 ieee
->stats
.tx_packets
++;
2025 ieee
->dev
->trans_start
= jiffies
;
2030 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2031 ieee
->tx_pending
.txb
= NULL
;
2035 void ieee80211_reset_queue(struct ieee80211_device
*ieee
)
2037 unsigned long flags
;
2039 spin_lock_irqsave(&ieee
->lock
,flags
);
2040 init_mgmt_queue(ieee
);
2041 if (ieee
->tx_pending
.txb
){
2042 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2043 ieee
->tx_pending
.txb
= NULL
;
2045 ieee
->queue_stop
= 0;
2046 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2050 void ieee80211_rtl_wake_queue(struct ieee80211_device
*ieee
)
2053 unsigned long flags
;
2054 struct sk_buff
*skb
;
2055 struct ieee80211_hdr_3addr
*header
;
2057 spin_lock_irqsave(&ieee
->lock
,flags
);
2058 if (! ieee
->queue_stop
) goto exit
;
2060 ieee
->queue_stop
= 0;
2062 if(ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
){
2063 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))){
2065 header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
2067 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2069 if (ieee
->seq_ctrl
[0] == 0xFFF)
2070 ieee
->seq_ctrl
[0] = 0;
2072 ieee
->seq_ctrl
[0]++;
2074 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2075 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
2076 dev_kfree_skb_any(skb
);//edit by thomas
2079 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2080 ieee80211_resume_tx(ieee
);
2082 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)){
2083 ieee
->softmac_stats
.swtxawake
++;
2084 netif_wake_queue(ieee
->dev
);
2088 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2092 void ieee80211_rtl_stop_queue(struct ieee80211_device
*ieee
)
2094 //unsigned long flags;
2095 //spin_lock_irqsave(&ieee->lock,flags);
2097 if (! netif_queue_stopped(ieee
->dev
)){
2098 netif_stop_queue(ieee
->dev
);
2099 ieee
->softmac_stats
.swtxstop
++;
2101 ieee
->queue_stop
= 1;
2102 //spin_unlock_irqrestore(&ieee->lock,flags);
2107 inline void ieee80211_randomize_cell(struct ieee80211_device
*ieee
)
2110 get_random_bytes(ieee
->current_network
.bssid
, ETH_ALEN
);
2112 /* an IBSS cell address must have the two less significant
2113 * bits of the first byte = 2
2115 ieee
->current_network
.bssid
[0] &= ~0x01;
2116 ieee
->current_network
.bssid
[0] |= 0x02;
2119 /* called in user context only */
2120 void ieee80211_start_master_bss(struct ieee80211_device
*ieee
)
2124 if (ieee
->current_network
.ssid_len
== 0){
2125 strncpy(ieee
->current_network
.ssid
,
2126 IEEE80211_DEFAULT_TX_ESSID
,
2129 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2133 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2135 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2136 ieee
->state
= IEEE80211_LINKED
;
2137 ieee
->link_change(ieee
->dev
);
2138 notify_wx_assoc_event(ieee
);
2140 if (ieee
->data_hard_resume
)
2141 ieee
->data_hard_resume(ieee
->dev
);
2143 netif_carrier_on(ieee
->dev
);
2146 void ieee80211_start_monitor_mode(struct ieee80211_device
*ieee
)
2150 if (ieee
->data_hard_resume
)
2151 ieee
->data_hard_resume(ieee
->dev
);
2153 netif_carrier_on(ieee
->dev
);
2157 void ieee80211_start_ibss_wq(struct work_struct
*work
)
2159 struct delayed_work
*dwork
= to_delayed_work(work
);
2160 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, start_ibss_wq
);
2162 /* iwconfig mode ad-hoc will schedule this and return
2163 * on the other hand this will block further iwconfig SET
2164 * operations because of the wx_sem hold.
2165 * Anyway some most set operations set a flag to speed-up
2166 * (abort) this wq (when syncro scanning) before sleeping
2170 down(&ieee
->wx_sem
);
2173 if (ieee
->current_network
.ssid_len
== 0){
2174 strcpy(ieee
->current_network
.ssid
,IEEE80211_DEFAULT_TX_ESSID
);
2175 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2179 /* check if we have this cell in our network list */
2180 ieee80211_softmac_check_all_nets(ieee
);
2182 if(ieee
->state
== IEEE80211_NOLINK
)
2183 ieee
->current_network
.channel
= 10;
2184 /* if not then the state is not linked. Maybe the user swithced to
2185 * ad-hoc mode just after being in monitor mode, or just after
2186 * being very few time in managed mode (so the card have had no
2187 * time to scan all the chans..) or we have just run up the iface
2188 * after setting ad-hoc mode. So we have to give another try..
2189 * Here, in ibss mode, should be safe to do this without extra care
2190 * (in bss mode we had to make sure no-one tryed to associate when
2191 * we had just checked the ieee->state and we was going to start the
2192 * scan) beacause in ibss mode the ieee80211_new_net function, when
2193 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2194 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2195 * scan, that will stop at the first round because it sees the state
2198 if (ieee
->state
== IEEE80211_NOLINK
)
2199 ieee80211_start_scan_syncro(ieee
);
2201 /* the network definitively is not here.. create a new cell */
2202 if (ieee
->state
== IEEE80211_NOLINK
){
2203 printk("creating new IBSS cell\n");
2205 ieee80211_randomize_cell(ieee
);
2207 if(ieee
->modulation
& IEEE80211_CCK_MODULATION
){
2209 ieee
->current_network
.rates_len
= 4;
2211 ieee
->current_network
.rates
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
2212 ieee
->current_network
.rates
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
2213 ieee
->current_network
.rates
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_5MB
;
2214 ieee
->current_network
.rates
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_11MB
;
2217 ieee
->current_network
.rates_len
= 0;
2219 if(ieee
->modulation
& IEEE80211_OFDM_MODULATION
){
2220 ieee
->current_network
.rates_ex_len
= 8;
2222 ieee
->current_network
.rates_ex
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_6MB
;
2223 ieee
->current_network
.rates_ex
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_9MB
;
2224 ieee
->current_network
.rates_ex
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_12MB
;
2225 ieee
->current_network
.rates_ex
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_18MB
;
2226 ieee
->current_network
.rates_ex
[4] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
2227 ieee
->current_network
.rates_ex
[5] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_36MB
;
2228 ieee
->current_network
.rates_ex
[6] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_48MB
;
2229 ieee
->current_network
.rates_ex
[7] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_54MB
;
2233 ieee
->current_network
.rates_ex_len
= 0;
2237 // By default, WMM function will be disabled in IBSS mode
2238 ieee
->current_network
.QoS_Enable
= 0;
2240 ieee
->current_network
.atim_window
= 0;
2241 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2242 if(ieee
->short_slot
)
2243 ieee
->current_network
.capability
|= WLAN_CAPABILITY_SHORT_SLOT
;
2247 ieee
->state
= IEEE80211_LINKED
;
2248 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2249 ieee
->link_change(ieee
->dev
);
2251 notify_wx_assoc_event(ieee
);
2253 ieee80211_start_send_beacons(ieee
);
2254 printk(KERN_WARNING
"after sending beacon packet!\n");
2256 if (ieee
->data_hard_resume
)
2257 ieee
->data_hard_resume(ieee
->dev
);
2259 netif_carrier_on(ieee
->dev
);
2263 inline void ieee80211_start_ibss(struct ieee80211_device
*ieee
)
2265 queue_delayed_work(ieee
->wq
, &ieee
->start_ibss_wq
, 100);
2268 /* this is called only in user context, with wx_sem held */
2269 void ieee80211_start_bss(struct ieee80211_device
*ieee
)
2271 unsigned long flags
;
2273 // Ref: 802.11d 11.1.3.3
2274 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2276 if(IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
))
2278 if(! ieee
->bGlobalDomain
)
2283 /* check if we have already found the net we
2284 * are interested in (if any).
2285 * if not (we are disassociated and we are not
2286 * in associating / authenticating phase) start the background scanning.
2288 ieee80211_softmac_check_all_nets(ieee
);
2290 /* ensure no-one start an associating process (thus setting
2291 * the ieee->state to ieee80211_ASSOCIATING) while we
2292 * have just cheked it and we are going to enable scan.
2293 * The ieee80211_new_net function is always called with
2294 * lock held (from both ieee80211_softmac_check_all_nets and
2295 * the rx path), so we cannot be in the middle of such function
2297 spin_lock_irqsave(&ieee
->lock
, flags
);
2300 // printk("start bss ENABLE_IPS\n");
2302 if (ieee
->state
== IEEE80211_NOLINK
){
2303 ieee
->actscanning
= true;
2304 ieee80211_rtl_start_scan(ieee
);
2307 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2310 /* called only in userspace context */
2311 void ieee80211_disassociate(struct ieee80211_device
*ieee
)
2313 netif_carrier_off(ieee
->dev
);
2315 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2316 ieee80211_reset_queue(ieee
);
2318 if (ieee
->data_hard_stop
)
2319 ieee
->data_hard_stop(ieee
->dev
);
2321 if(IS_DOT11D_ENABLE(ieee
))
2323 ieee
->state
= IEEE80211_NOLINK
;
2324 ieee
->link_change(ieee
->dev
);
2325 notify_wx_assoc_event(ieee
);
2328 void ieee80211_associate_retry_wq(struct work_struct
*work
)
2330 struct delayed_work
*dwork
= to_delayed_work(work
);
2331 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, associate_retry_wq
);
2332 unsigned long flags
;
2333 down(&ieee
->wx_sem
);
2334 if(!ieee
->proto_started
)
2336 if(ieee
->state
!= IEEE80211_ASSOCIATING_RETRY
)
2338 /* until we do not set the state to IEEE80211_NOLINK
2339 * there are no possibility to have someone else trying
2340 * to start an association procdure (we get here with
2341 * ieee->state = IEEE80211_ASSOCIATING).
2342 * When we set the state to IEEE80211_NOLINK it is possible
2343 * that the RX path run an attempt to associate, but
2344 * both ieee80211_softmac_check_all_nets and the
2345 * RX path works with ieee->lock held so there are no
2346 * problems. If we are still disassociated then start a scan.
2347 * the lock here is necessary to ensure no one try to start
2348 * an association procedure when we have just checked the
2349 * state and we are going to start the scan.
2351 ieee
->state
= IEEE80211_NOLINK
;
2352 ieee
->beinretry
= true;
2353 ieee80211_softmac_check_all_nets(ieee
);
2355 spin_lock_irqsave(&ieee
->lock
, flags
);
2357 if(ieee
->state
== IEEE80211_NOLINK
){
2358 ieee
->beinretry
= false;
2359 ieee
->actscanning
= true;
2360 ieee80211_rtl_start_scan(ieee
);
2362 //YJ,add,080828, notify os here
2363 if(ieee
->state
== IEEE80211_NOLINK
)
2365 notify_wx_assoc_event(ieee
);
2368 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2374 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
)
2376 u8 broadcast_addr
[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2378 struct sk_buff
*skb
= NULL
;
2379 struct ieee80211_probe_response
*b
;
2381 skb
= ieee80211_probe_resp(ieee
, broadcast_addr
);
2385 b
= (struct ieee80211_probe_response
*) skb
->data
;
2386 b
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_BEACON
);
2392 struct sk_buff
*ieee80211_get_beacon(struct ieee80211_device
*ieee
)
2394 struct sk_buff
*skb
;
2395 struct ieee80211_probe_response
*b
;
2397 skb
= ieee80211_get_beacon_(ieee
);
2401 b
= (struct ieee80211_probe_response
*) skb
->data
;
2402 b
->header
.seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2404 if (ieee
->seq_ctrl
[0] == 0xFFF)
2405 ieee
->seq_ctrl
[0] = 0;
2407 ieee
->seq_ctrl
[0]++;
2412 void ieee80211_softmac_stop_protocol(struct ieee80211_device
*ieee
)
2414 ieee
->sync_scan_hurryup
= 1;
2415 down(&ieee
->wx_sem
);
2416 ieee80211_stop_protocol(ieee
);
2421 void ieee80211_stop_protocol(struct ieee80211_device
*ieee
)
2423 if (!ieee
->proto_started
)
2426 ieee
->proto_started
= 0;
2428 ieee80211_stop_send_beacons(ieee
);
2429 if((ieee
->iw_mode
== IW_MODE_INFRA
)&&(ieee
->state
== IEEE80211_LINKED
)) {
2430 SendDisassociation(ieee
,NULL
,WLAN_REASON_DISASSOC_STA_HAS_LEFT
);
2432 del_timer_sync(&ieee
->associate_timer
);
2433 cancel_delayed_work(&ieee
->associate_retry_wq
);
2434 cancel_delayed_work(&ieee
->start_ibss_wq
);
2435 ieee80211_stop_scan(ieee
);
2437 ieee80211_disassociate(ieee
);
2440 void ieee80211_softmac_start_protocol(struct ieee80211_device
*ieee
)
2442 ieee
->sync_scan_hurryup
= 0;
2443 down(&ieee
->wx_sem
);
2444 ieee80211_start_protocol(ieee
);
2448 void ieee80211_start_protocol(struct ieee80211_device
*ieee
)
2453 if (ieee
->proto_started
)
2456 ieee
->proto_started
= 1;
2458 if (ieee
->current_network
.channel
== 0){
2461 if (ch
> MAX_CHANNEL_NUMBER
)
2462 return; /* no channel found */
2464 }while(!GET_DOT11D_INFO(ieee
)->channel_map
[ch
]);
2466 ieee
->current_network
.channel
= ch
;
2469 if (ieee
->current_network
.beacon_interval
== 0)
2470 ieee
->current_network
.beacon_interval
= 100;
2471 ieee
->set_chan(ieee
->dev
,ieee
->current_network
.channel
);
2473 for(i
= 0; i
< 17; i
++) {
2474 ieee
->last_rxseq_num
[i
] = -1;
2475 ieee
->last_rxfrag_num
[i
] = -1;
2476 ieee
->last_packet_time
[i
] = 0;
2479 ieee
->init_wmmparam_flag
= 0;//reinitialize AC_xx_PARAM registers.
2482 /* if the user set the MAC of the ad-hoc cell and then
2483 * switch to managed mode, shall we make sure that association
2484 * attempts does not fail just because the user provide the essid
2485 * and the nic is still checking for the AP MAC ??
2487 switch (ieee
->iw_mode
) {
2489 ieee
->iw_mode
= IW_MODE_INFRA
;
2490 //not set break here intentionly
2492 ieee80211_start_bss(ieee
);
2496 ieee80211_start_ibss(ieee
);
2499 case IW_MODE_MASTER
:
2500 ieee80211_start_master_bss(ieee
);
2503 case IW_MODE_MONITOR
:
2504 ieee80211_start_monitor_mode(ieee
);
2508 ieee
->iw_mode
= IW_MODE_INFRA
;
2509 ieee80211_start_bss(ieee
);
2515 #define DRV_NAME "Ieee80211"
2516 void ieee80211_softmac_init(struct ieee80211_device
*ieee
)
2519 memset(&ieee
->current_network
, 0, sizeof(struct ieee80211_network
));
2521 ieee
->state
= IEEE80211_NOLINK
;
2522 ieee
->sync_scan_hurryup
= 0;
2523 for(i
= 0; i
< 5; i
++) {
2524 ieee
->seq_ctrl
[i
] = 0;
2528 ieee
->queue_stop
= 0;
2530 ieee
->softmac_features
= 0; //so IEEE2100-like driver are happy
2533 ieee
->proto_started
= 0;
2534 ieee
->basic_rate
= IEEE80211_DEFAULT_BASIC_RATE
;
2537 ieee
->ps
= IEEE80211_PS_MBCAST
|IEEE80211_PS_UNICAST
;
2539 // ieee->ps = IEEE80211_PS_DISABLED;
2541 ieee
->sta_sleep
= 0;
2543 ieee
->bInactivePs
= false;
2544 ieee
->actscanning
= false;
2545 ieee
->ListenInterval
= 2;
2546 ieee
->NumRxDataInPeriod
= 0; //YJ,add,080828
2547 ieee
->NumRxBcnInPeriod
= 0; //YJ,add,080828
2548 ieee
->NumRxOkTotal
= 0;//+by amy 080312
2549 ieee
->NumRxUnicast
= 0;//YJ,add,080828,for keep alive
2550 ieee
->beinretry
= false;
2551 ieee
->bHwRadioOff
= false;
2554 init_mgmt_queue(ieee
);
2556 ieee
->tx_pending
.txb
= NULL
;
2558 init_timer(&ieee
->associate_timer
);
2559 ieee
->associate_timer
.data
= (unsigned long)ieee
;
2560 ieee
->associate_timer
.function
= ieee80211_associate_abort_cb
;
2562 init_timer(&ieee
->beacon_timer
);
2563 ieee
->beacon_timer
.data
= (unsigned long) ieee
;
2564 ieee
->beacon_timer
.function
= ieee80211_send_beacon_cb
;
2566 #ifdef PF_SYNCTHREAD
2567 ieee
->wq
= create_workqueue(DRV_NAME
,0);
2569 ieee
->wq
= create_workqueue(DRV_NAME
);
2571 INIT_DELAYED_WORK(&ieee
->start_ibss_wq
,(void*) ieee80211_start_ibss_wq
);
2572 INIT_WORK(&ieee
->associate_complete_wq
,(void*) ieee80211_associate_complete_wq
);
2573 INIT_WORK(&ieee
->associate_procedure_wq
,(void*) ieee80211_associate_procedure_wq
);
2574 INIT_DELAYED_WORK(&ieee
->softmac_scan_wq
,(void*) ieee80211_softmac_scan_wq
);
2575 INIT_DELAYED_WORK(&ieee
->associate_retry_wq
,(void*) ieee80211_associate_retry_wq
);
2576 INIT_WORK(&ieee
->wx_sync_scan_wq
,(void*) ieee80211_wx_sync_scan_wq
);
2577 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2579 sema_init(&ieee
->wx_sem
, 1);
2580 sema_init(&ieee
->scan_sem
, 1);
2582 spin_lock_init(&ieee
->mgmt_tx_lock
);
2583 spin_lock_init(&ieee
->beacon_lock
);
2585 tasklet_init(&ieee
->ps_task
,
2586 (void(*)(unsigned long)) ieee80211_sta_ps
,
2587 (unsigned long)ieee
);
2588 ieee
->pDot11dInfo
= kmalloc(sizeof(RT_DOT11D_INFO
), GFP_ATOMIC
);
2591 void ieee80211_softmac_free(struct ieee80211_device
*ieee
)
2593 down(&ieee
->wx_sem
);
2595 del_timer_sync(&ieee
->associate_timer
);
2596 cancel_delayed_work(&ieee
->associate_retry_wq
);
2599 //add for RF power on power of by lizhaoming 080512
2600 cancel_delayed_work(&ieee
->GPIOChangeRFWorkItem
);
2602 destroy_workqueue(ieee
->wq
);
2603 if(NULL
!= ieee
->pDot11dInfo
)
2604 kfree(ieee
->pDot11dInfo
);
2608 /********************************************************
2609 * Start of WPA code. *
2610 * this is stolen from the ipw2200 driver *
2611 ********************************************************/
2614 static int ieee80211_wpa_enable(struct ieee80211_device
*ieee
, int value
)
2616 /* This is called when wpa_supplicant loads and closes the driver
2618 printk("%s WPA\n",value
? "enabling" : "disabling");
2619 ieee
->wpa_enabled
= value
;
2624 void ieee80211_wpa_assoc_frame(struct ieee80211_device
*ieee
, char *wpa_ie
, int wpa_ie_len
)
2626 /* make sure WPA is enabled */
2627 ieee80211_wpa_enable(ieee
, 1);
2629 ieee80211_disassociate(ieee
);
2633 static int ieee80211_wpa_mlme(struct ieee80211_device
*ieee
, int command
, int reason
)
2639 case IEEE_MLME_STA_DEAUTH
:
2643 case IEEE_MLME_STA_DISASSOC
:
2644 ieee80211_disassociate(ieee
);
2648 printk("Unknown MLME request: %d\n", command
);
2656 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device
*ieee
,
2657 struct ieee_param
*param
, int plen
)
2661 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
2662 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
2665 if (param
->u
.wpa_ie
.len
) {
2666 buf
= kmalloc(param
->u
.wpa_ie
.len
, GFP_KERNEL
);
2670 memcpy(buf
, param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
);
2671 kfree(ieee
->wpa_ie
);
2673 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
2675 kfree(ieee
->wpa_ie
);
2676 ieee
->wpa_ie
= NULL
;
2677 ieee
->wpa_ie_len
= 0;
2680 ieee80211_wpa_assoc_frame(ieee
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
2684 #define AUTH_ALG_OPEN_SYSTEM 0x1
2685 #define AUTH_ALG_SHARED_KEY 0x2
2687 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device
*ieee
, int value
)
2690 struct ieee80211_security sec
= {
2691 .flags
= SEC_AUTH_MODE
,
2695 if (value
& AUTH_ALG_SHARED_KEY
) {
2696 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
2699 sec
.auth_mode
= WLAN_AUTH_OPEN
;
2703 if (ieee
->set_security
)
2704 ieee
->set_security(ieee
->dev
, &sec
);
2711 static int ieee80211_wpa_set_param(struct ieee80211_device
*ieee
, u8 name
, u32 value
)
2714 unsigned long flags
;
2717 case IEEE_PARAM_WPA_ENABLED
:
2718 ret
= ieee80211_wpa_enable(ieee
, value
);
2721 case IEEE_PARAM_TKIP_COUNTERMEASURES
:
2722 ieee
->tkip_countermeasures
=value
;
2725 case IEEE_PARAM_DROP_UNENCRYPTED
: {
2728 * wpa_supplicant calls set_wpa_enabled when the driver
2729 * is loaded and unloaded, regardless of if WPA is being
2730 * used. No other calls are made which can be used to
2731 * determine if encryption will be used or not prior to
2732 * association being expected. If encryption is not being
2733 * used, drop_unencrypted is set to false, else true -- we
2734 * can use this to determine if the CAP_PRIVACY_ON bit should
2737 struct ieee80211_security sec
= {
2738 .flags
= SEC_ENABLED
,
2741 ieee
->drop_unencrypted
= value
;
2742 /* We only change SEC_LEVEL for open mode. Others
2743 * are set by ipw_wpa_set_encryption.
2746 sec
.flags
|= SEC_LEVEL
;
2747 sec
.level
= SEC_LEVEL_0
;
2750 sec
.flags
|= SEC_LEVEL
;
2751 sec
.level
= SEC_LEVEL_1
;
2753 if (ieee
->set_security
)
2754 ieee
->set_security(ieee
->dev
, &sec
);
2758 case IEEE_PARAM_PRIVACY_INVOKED
:
2759 ieee
->privacy_invoked
=value
;
2762 case IEEE_PARAM_AUTH_ALGS
:
2763 ret
= ieee80211_wpa_set_auth_algs(ieee
, value
);
2766 case IEEE_PARAM_IEEE_802_1X
:
2767 ieee
->ieee802_1x
=value
;
2769 case IEEE_PARAM_WPAX_SELECT
:
2770 // added for WPA2 mixed mode
2771 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
2772 spin_lock_irqsave(&ieee
->wpax_suitlist_lock
,flags
);
2773 ieee
->wpax_type_set
= 1;
2774 ieee
->wpax_type_notify
= value
;
2775 spin_unlock_irqrestore(&ieee
->wpax_suitlist_lock
,flags
);
2779 printk("Unknown WPA param: %d\n",name
);
2786 /* implementation borrowed from hostap driver */
2788 static int ieee80211_wpa_set_encryption(struct ieee80211_device
*ieee
,
2789 struct ieee_param
*param
, int param_len
)
2793 struct ieee80211_crypto_ops
*ops
;
2794 struct ieee80211_crypt_data
**crypt
;
2796 struct ieee80211_security sec
= {
2800 param
->u
.crypt
.err
= 0;
2801 param
->u
.crypt
.alg
[IEEE_CRYPT_ALG_NAME_LEN
- 1] = '\0';
2804 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
2805 param
->u
.crypt
.key_len
) {
2806 printk("Len mismatch %d, %d\n", param_len
,
2807 param
->u
.crypt
.key_len
);
2810 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
2811 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
2812 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
2813 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
2815 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
2820 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
2825 sec
.level
= SEC_LEVEL_0
;
2826 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
2827 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2834 sec
.flags
|= SEC_ENABLED
;
2836 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
2837 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
2838 strcmp(param
->u
.crypt
.alg
, "TKIP"))
2839 goto skip_host_crypt
;
2841 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2842 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
2843 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2844 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0)
2845 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2846 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0)
2847 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2849 printk("unknown crypto alg '%s'\n", param
->u
.crypt
.alg
);
2850 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
2855 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
2856 struct ieee80211_crypt_data
*new_crypt
;
2858 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2860 new_crypt
= (struct ieee80211_crypt_data
*)
2861 kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
2862 if (new_crypt
== NULL
) {
2866 memset(new_crypt
, 0, sizeof(struct ieee80211_crypt_data
));
2867 new_crypt
->ops
= ops
;
2870 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
2872 if (new_crypt
->priv
== NULL
) {
2874 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
2882 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
2883 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
2884 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
2885 (*crypt
)->priv
) < 0) {
2886 printk("key setting failed\n");
2887 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
2893 if (param
->u
.crypt
.set_tx
) {
2894 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
2895 sec
.active_key
= param
->u
.crypt
.idx
;
2896 sec
.flags
|= SEC_ACTIVE_KEY
;
2898 sec
.flags
&= ~SEC_ACTIVE_KEY
;
2900 if (param
->u
.crypt
.alg
!= NULL
) {
2901 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
2903 param
->u
.crypt
.key_len
);
2904 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
2905 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
2907 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
2908 sec
.flags
|= SEC_LEVEL
;
2909 sec
.level
= SEC_LEVEL_1
;
2910 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
2911 sec
.flags
|= SEC_LEVEL
;
2912 sec
.level
= SEC_LEVEL_2
;
2913 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
2914 sec
.flags
|= SEC_LEVEL
;
2915 sec
.level
= SEC_LEVEL_3
;
2919 if (ieee
->set_security
)
2920 ieee
->set_security(ieee
->dev
, &sec
);
2922 /* Do not reset port if card is in Managed mode since resetting will
2923 * generate new IEEE 802.11 authentication which may end up in looping
2924 * with IEEE 802.1X. If your hardware requires a reset after WEP
2925 * configuration (for example... Prism2), implement the reset_port in
2926 * the callbacks structures used to initialize the 802.11 stack. */
2927 if (ieee
->reset_on_keychange
&&
2928 ieee
->iw_mode
!= IW_MODE_INFRA
&&
2930 ieee
->reset_port(ieee
->dev
)) {
2931 printk("reset_port failed\n");
2932 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
2939 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device
*ieee
, struct iw_point
*p
)
2941 struct ieee_param
*param
;
2944 down(&ieee
->wx_sem
);
2945 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
2947 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
){
2952 param
= (struct ieee_param
*)kmalloc(p
->length
, GFP_KERNEL
);
2957 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
2963 switch (param
->cmd
) {
2965 case IEEE_CMD_SET_WPA_PARAM
:
2966 ret
= ieee80211_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
2967 param
->u
.wpa_param
.value
);
2970 case IEEE_CMD_SET_WPA_IE
:
2971 ret
= ieee80211_wpa_set_wpa_ie(ieee
, param
, p
->length
);
2974 case IEEE_CMD_SET_ENCRYPTION
:
2975 ret
= ieee80211_wpa_set_encryption(ieee
, param
, p
->length
);
2979 ret
= ieee80211_wpa_mlme(ieee
, param
->u
.mlme
.command
,
2980 param
->u
.mlme
.reason_code
);
2984 printk("Unknown WPA supplicant request: %d\n",param
->cmd
);
2989 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
2999 void notify_wx_assoc_event(struct ieee80211_device
*ieee
)
3001 union iwreq_data wrqu
;
3002 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3003 if (ieee
->state
== IEEE80211_LINKED
)
3004 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
, ETH_ALEN
);
3006 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
3007 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);