1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
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/interrupt.h>
23 #include <linux/uaccess.h>
24 #include <linux/etherdevice.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(const struct ieee80211_network
*net
)
38 return (net
->rates_ex_len
> 0) || (net
->rates_len
> 4);
41 short ieee80211_is_shortslot(const struct ieee80211_network
*net
)
43 return net
->capability
& WLAN_CAPABILITY_SHORT_SLOT
;
46 /* returns the total length needed for placing 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 /* place the MFIE rate, tag to the memory (double) poised.
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
)
113 *tag
++ = MFIE_TYPE_GENERIC
; //0
122 if (ieee
->current_network
.wmm_info
& 0x80) {
123 *tag
++ = 0x0f|MAX_SP_Len
;
133 void ieee80211_TURBO_Info(struct ieee80211_device
*ieee
, u8
**tag_p
)
137 *tag
++ = MFIE_TYPE_GENERIC
; //0
148 printk(KERN_ALERT
"This is enable turbo mode IE process\n");
151 void enqueue_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
154 nh
= (ieee
->mgmt_queue_head
+1) % MGMT_QUEUE_NUM
;
157 * if the queue is full but we have newer frames then
158 * just overwrites the oldest.
160 * if (nh == ieee->mgmt_queue_tail)
163 ieee
->mgmt_queue_head
= nh
;
164 ieee
->mgmt_queue_ring
[nh
] = skb
;
169 struct sk_buff
*dequeue_mgmt(struct ieee80211_device
*ieee
)
173 if(ieee
->mgmt_queue_tail
== ieee
->mgmt_queue_head
)
176 ret
= ieee
->mgmt_queue_ring
[ieee
->mgmt_queue_tail
];
178 ieee
->mgmt_queue_tail
=
179 (ieee
->mgmt_queue_tail
+1) % MGMT_QUEUE_NUM
;
184 void init_mgmt_queue(struct ieee80211_device
*ieee
)
186 ieee
->mgmt_queue_tail
= ieee
->mgmt_queue_head
= 0;
190 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
);
192 inline void softmac_mgmt_xmit(struct sk_buff
*skb
, struct ieee80211_device
*ieee
)
195 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
196 struct ieee80211_hdr_3addr
*header
=
197 (struct ieee80211_hdr_3addr
*) skb
->data
;
200 spin_lock_irqsave(&ieee
->lock
, flags
);
202 /* called with 2nd param 0, no mgmt lock required */
203 ieee80211_sta_wakeup(ieee
,0);
206 if(ieee
->queue_stop
){
208 enqueue_mgmt(ieee
,skb
);
210 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4);
212 if (ieee
->seq_ctrl
[0] == 0xFFF)
213 ieee
->seq_ctrl
[0] = 0;
217 /* avoid watchdog triggers */
218 ieee
->dev
->trans_start
= jiffies
;
219 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
222 spin_unlock_irqrestore(&ieee
->lock
, flags
);
224 spin_unlock_irqrestore(&ieee
->lock
, flags
);
225 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags
);
227 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
229 if (ieee
->seq_ctrl
[0] == 0xFFF)
230 ieee
->seq_ctrl
[0] = 0;
234 /* avoid watchdog triggers */
235 ieee
->dev
->trans_start
= jiffies
;
236 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
238 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags
);
243 inline void softmac_ps_mgmt_xmit(struct sk_buff
*skb
, struct ieee80211_device
*ieee
)
246 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
247 struct ieee80211_hdr_3addr
*header
=
248 (struct ieee80211_hdr_3addr
*) skb
->data
;
253 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
255 if (ieee
->seq_ctrl
[0] == 0xFFF)
256 ieee
->seq_ctrl
[0] = 0;
260 /* avoid watchdog triggers */
261 ieee
->dev
->trans_start
= jiffies
;
262 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
266 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
268 if (ieee
->seq_ctrl
[0] == 0xFFF)
269 ieee
->seq_ctrl
[0] = 0;
273 /* avoid watchdog triggers */
274 ieee
->dev
->trans_start
= jiffies
;
275 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
278 // dev_kfree_skb_any(skb);//edit by thomas
280 //by amy for power save
281 inline struct sk_buff
*ieee80211_disassociate_skb(
282 struct ieee80211_network
*beacon
,
283 struct ieee80211_device
*ieee
,
287 struct ieee80211_disassoc_frame
*disass
;
289 skb
= dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame
));
293 disass
= (struct ieee80211_disassoc_frame
*) skb_put(skb
,sizeof(struct ieee80211_disassoc_frame
));
294 disass
->header
.frame_control
= cpu_to_le16(IEEE80211_STYPE_DISASSOC
);
295 disass
->header
.duration_id
= 0;
297 memcpy(disass
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
298 memcpy(disass
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
299 memcpy(disass
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
301 disass
->reasoncode
= asRsn
;
306 struct ieee80211_device
*ieee
,
311 struct ieee80211_network
*beacon
= &ieee
->current_network
;
313 skb
= ieee80211_disassociate_skb(beacon
,ieee
,asRsn
);
315 softmac_mgmt_xmit(skb
, ieee
);
316 //dev_kfree_skb_any(skb);//edit by thomas
320 //by amy for power save
321 inline struct sk_buff
*ieee80211_probe_req(struct ieee80211_device
*ieee
)
323 unsigned int len
,rate_len
;
326 struct ieee80211_probe_request
*req
;
328 len
= ieee
->current_network
.ssid_len
;
330 rate_len
= ieee80211_MFIE_rate_len(ieee
);
332 skb
= dev_alloc_skb(sizeof(struct ieee80211_probe_request
) +
337 req
= (struct ieee80211_probe_request
*) skb_put(skb
,sizeof(struct ieee80211_probe_request
));
338 req
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
339 req
->header
.duration_id
= 0; //FIXME: is this OK ?
341 memset(req
->header
.addr1
, 0xff, ETH_ALEN
);
342 memcpy(req
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
343 memset(req
->header
.addr3
, 0xff, ETH_ALEN
);
345 tag
= (u8
*) skb_put(skb
,len
+2+rate_len
);
347 *tag
++ = MFIE_TYPE_SSID
;
349 memcpy(tag
, ieee
->current_network
.ssid
, len
);
351 ieee80211_MFIE_Brate(ieee
,&tag
);
352 ieee80211_MFIE_Grate(ieee
,&tag
);
357 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
);
359 void ext_ieee80211_send_beacon_wq(struct ieee80211_device
*ieee
)
363 //unsigned long flags;
365 skb
= ieee80211_get_beacon_(ieee
);
368 softmac_mgmt_xmit(skb
, ieee
);
369 ieee
->softmac_stats
.tx_beacons
++;
370 dev_kfree_skb_any(skb
);//edit by thomas
374 //printk(KERN_WARNING "[1] beacon sending!\n");
375 ieee
->beacon_timer
.expires
= jiffies
+
376 (MSECS( ieee
->current_network
.beacon_interval
-5));
378 //spin_lock_irqsave(&ieee->beacon_lock,flags);
379 if(ieee
->beacon_txing
)
380 add_timer(&ieee
->beacon_timer
);
381 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
384 void ieee80211_send_beacon(struct ieee80211_device
*ieee
)
388 //unsigned long flags;
390 skb
= ieee80211_get_beacon_(ieee
);
393 softmac_mgmt_xmit(skb
, ieee
);
394 ieee
->softmac_stats
.tx_beacons
++;
395 dev_kfree_skb_any(skb
);//edit by thomas
398 //printk(KERN_WARNING "[1] beacon sending!\n");
399 ieee
->beacon_timer
.expires
= jiffies
+
400 (MSECS( ieee
->current_network
.beacon_interval
-5));
402 //spin_lock_irqsave(&ieee->beacon_lock,flags);
403 if(ieee
->beacon_txing
)
404 add_timer(&ieee
->beacon_timer
);
405 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
409 void ieee80211_send_beacon_cb(unsigned long _ieee
)
411 struct ieee80211_device
*ieee
=
412 (struct ieee80211_device
*) _ieee
;
415 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
416 ieee80211_send_beacon(ieee
);
417 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
420 void ieee80211_send_probe(struct ieee80211_device
*ieee
)
424 skb
= ieee80211_probe_req(ieee
);
426 softmac_mgmt_xmit(skb
, ieee
);
427 ieee
->softmac_stats
.tx_probe_rq
++;
428 //dev_kfree_skb_any(skb);//edit by thomas
432 void ieee80211_send_probe_requests(struct ieee80211_device
*ieee
)
434 if (ieee
->active_scan
&& (ieee
->softmac_features
& IEEE_SOFTMAC_PROBERQ
)){
435 ieee80211_send_probe(ieee
);
436 ieee80211_send_probe(ieee
);
440 /* this performs syncro scan blocking the caller until all channels
441 * in the allowed channel map has been checked.
443 void ieee80211_softmac_scan_syncro(struct ieee80211_device
*ieee
)
446 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
447 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
448 down(&ieee
->scan_sem
);
449 // printk("==================> Sync scan\n");
456 if (ch
> MAX_CHANNEL_NUMBER
)
457 goto out
; /* scan completed */
459 }while(!channel_map
[ch
]);
460 /* this function can be called in two situations
461 * 1- We have switched to ad-hoc mode and we are
462 * performing a complete syncro scan before conclude
463 * there are no interesting cell and to create a
464 * new one. In this case the link state is
465 * IEEE80211_NOLINK until we found an interesting cell.
466 * If so the ieee8021_new_net, called by the RX path
467 * will set the state to IEEE80211_LINKED, so we stop
469 * 2- We are linked and the root uses run iwlist scan.
470 * So we switch to IEEE80211_LINKED_SCANNING to remember
471 * that we are still logically linked (not interested in
472 * new network events, despite for updating the net list,
473 * but we are temporarily 'unlinked' as the driver shall
474 * not filter RX frames and the channel is changing.
475 * So the only situation in witch are interested is to check
476 * if the state become LINKED because of the #1 situation
479 if (ieee
->state
== IEEE80211_LINKED
)
482 ieee
->set_chan(ieee
->dev
, ch
);
483 // printk("=====>channel=%d ",ch);
484 if(channel_map
[ch
] == 1)
486 // printk("====send probe request\n");
487 ieee80211_send_probe_requests(ieee
);
489 /* this prevent excessive time wait when we
490 * need to wait for a syncro scan to end..
492 if (ieee
->sync_scan_hurryup
)
496 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME
);
500 ieee
->sync_scan_hurryup
= 0;
502 if(IS_DOT11D_ENABLE(ieee
))
503 DOT11D_ScanComplete(ieee
);
506 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device
*ieee
)
509 unsigned int watch_dog
= 0;
510 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
511 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
512 down(&ieee
->scan_sem
);
513 ch
= ieee
->current_network
.channel
;
514 // if(ieee->sync_scan_hurryup)
517 // printk("stop scan sync\n");
520 // printk("=======hh===============>ips scan\n");
523 /* this function can be called in two situations
524 * 1- We have switched to ad-hoc mode and we are
525 * performing a complete syncro scan before conclude
526 * there are no interesting cell and to create a
527 * new one. In this case the link state is
528 * IEEE80211_NOLINK until we found an interesting cell.
529 * If so the ieee8021_new_net, called by the RX path
530 * will set the state to IEEE80211_LINKED, so we stop
532 * 2- We are linked and the root uses run iwlist scan.
533 * So we switch to IEEE80211_LINKED_SCANNING to remember
534 * that we are still logically linked (not interested in
535 * new network events, despite for updating the net list,
536 * but we are temporarily 'unlinked' as the driver shall
537 * not filter RX frames and the channel is changing.
538 * So the only situation in witch are interested is to check
539 * if the state become LINKED because of the #1 situation
541 if (ieee
->state
== IEEE80211_LINKED
)
545 if(channel_map
[ieee
->current_network
.channel
] > 0)
547 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
548 // printk("======>channel=%d ",ieee->current_network.channel);
550 if(channel_map
[ieee
->current_network
.channel
] == 1)
552 // printk("====send probe request\n");
553 ieee80211_send_probe_requests(ieee
);
555 /* this prevent excessive time wait when we
556 * need to wait for a syncro scan to end..
558 // if (ieee->sync_scan_hurryup)
561 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME
);
564 if (watch_dog
++ >= MAX_CHANNEL_NUMBER
)
565 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
566 goto out
; /* scan completed */
568 ieee
->current_network
.channel
= (ieee
->current_network
.channel
+ 1)%MAX_CHANNEL_NUMBER
;
569 }while(!channel_map
[ieee
->current_network
.channel
]);
572 //ieee->sync_scan_hurryup = 0;
573 //ieee->set_chan(ieee->dev, ch);
574 //ieee->current_network.channel = ch;
575 ieee
->actscanning
= false;
577 if(IS_DOT11D_ENABLE(ieee
))
578 DOT11D_ScanComplete(ieee
);
581 void ieee80211_softmac_scan_wq(struct work_struct
*work
)
583 struct delayed_work
*dwork
= to_delayed_work(work
);
584 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, softmac_scan_wq
);
585 static short watchdog
= 0;
586 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
587 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
588 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
589 // printk("in %s\n",__func__);
590 down(&ieee
->scan_sem
);
593 ieee
->current_network
.channel
=
594 (ieee
->current_network
.channel
+ 1) % MAX_CHANNEL_NUMBER
;
595 if (watchdog
++ > MAX_CHANNEL_NUMBER
)
596 goto out
; /* no good chans */
598 }while(!channel_map
[ieee
->current_network
.channel
]);
600 //printk("current_network.channel:%d\n", ieee->current_network.channel);
601 if (ieee
->scanning
== 0 )
603 printk("error out, scanning = 0\n");
606 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
607 if(channel_map
[ieee
->current_network
.channel
] == 1)
608 ieee80211_send_probe_requests(ieee
);
610 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
, IEEE80211_SOFTMAC_SCAN_TIME
);
614 ieee
->actscanning
= false;
619 if(IS_DOT11D_ENABLE(ieee
))
620 DOT11D_ScanComplete(ieee
);
624 void ieee80211_beacons_start(struct ieee80211_device
*ieee
)
628 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
630 ieee
->beacon_txing
= 1;
631 ieee80211_send_beacon(ieee
);
633 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
636 void ieee80211_beacons_stop(struct ieee80211_device
*ieee
)
640 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
642 ieee
->beacon_txing
= 0;
643 del_timer_sync(&ieee
->beacon_timer
);
645 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
650 void ieee80211_stop_send_beacons(struct ieee80211_device
*ieee
)
652 if(ieee
->stop_send_beacons
)
653 ieee
->stop_send_beacons(ieee
->dev
);
654 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
655 ieee80211_beacons_stop(ieee
);
659 void ieee80211_start_send_beacons(struct ieee80211_device
*ieee
)
661 if(ieee
->start_send_beacons
)
662 ieee
->start_send_beacons(ieee
->dev
);
663 if(ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
664 ieee80211_beacons_start(ieee
);
668 void ieee80211_softmac_stop_scan(struct ieee80211_device
*ieee
)
670 // unsigned long flags;
672 //ieee->sync_scan_hurryup = 1;
674 down(&ieee
->scan_sem
);
675 // spin_lock_irqsave(&ieee->lock, flags);
677 if (ieee
->scanning
== 1){
679 //del_timer_sync(&ieee->scan_timer);
680 cancel_delayed_work(&ieee
->softmac_scan_wq
);
683 // spin_unlock_irqrestore(&ieee->lock, flags);
687 void ieee80211_stop_scan(struct ieee80211_device
*ieee
)
689 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
690 ieee80211_softmac_stop_scan(ieee
);
692 ieee
->stop_scan(ieee
->dev
);
695 /* called with ieee->lock held */
696 void ieee80211_rtl_start_scan(struct ieee80211_device
*ieee
)
698 if(IS_DOT11D_ENABLE(ieee
) )
700 if(IS_COUNTRY_IE_VALID(ieee
))
702 RESET_CIE_WATCHDOG(ieee
);
705 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
706 if (ieee
->scanning
== 0)
709 //ieee80211_softmac_scan(ieee);
710 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
711 //care this,1203,2007,by lawrence
713 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
,0);
717 ieee
->start_scan(ieee
->dev
);
721 /* called with wx_sem held */
722 void ieee80211_start_scan_syncro(struct ieee80211_device
*ieee
)
724 if(IS_DOT11D_ENABLE(ieee
) )
726 if(IS_COUNTRY_IE_VALID(ieee
))
728 RESET_CIE_WATCHDOG(ieee
);
731 ieee
->sync_scan_hurryup
= 0;
733 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
734 ieee80211_softmac_scan_syncro(ieee
);
736 ieee
->scan_syncro(ieee
->dev
);
740 inline struct sk_buff
*ieee80211_authentication_req(struct ieee80211_network
*beacon
,
741 struct ieee80211_device
*ieee
, int challengelen
)
744 struct ieee80211_authentication
*auth
;
746 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
) + challengelen
);
748 if (!skb
) return NULL
;
750 auth
= (struct ieee80211_authentication
*)
751 skb_put(skb
, sizeof(struct ieee80211_authentication
));
753 auth
->header
.frame_ctl
= IEEE80211_STYPE_AUTH
;
754 if (challengelen
) auth
->header
.frame_ctl
|= IEEE80211_FCTL_WEP
;
756 auth
->header
.duration_id
= 0x013a; //FIXME
758 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
759 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
760 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
762 auth
->algorithm
= ieee
->open_wep
? WLAN_AUTH_OPEN
: WLAN_AUTH_SHARED_KEY
;
764 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
765 ieee
->associate_seq
++;
767 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
773 static struct sk_buff
* ieee80211_probe_resp(struct ieee80211_device
*ieee
, u8
*dest
)
777 struct ieee80211_probe_response
*beacon_buf
;
780 int atim_len
,erp_len
;
781 struct ieee80211_crypt_data
* crypt
;
783 char *ssid
= ieee
->current_network
.ssid
;
784 int ssid_len
= ieee
->current_network
.ssid_len
;
785 int rate_len
= ieee
->current_network
.rates_len
+2;
786 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
787 int wpa_ie_len
= ieee
->wpa_ie_len
;
788 if(rate_ex_len
> 0) rate_ex_len
+=2;
790 if(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
795 if(ieee80211_is_54g(&ieee
->current_network
))
800 beacon_size
= sizeof(struct ieee80211_probe_response
)+
809 skb
= dev_alloc_skb(beacon_size
);
814 beacon_buf
= (struct ieee80211_probe_response
*) skb_put(skb
, beacon_size
);
816 memcpy (beacon_buf
->header
.addr1
, dest
,ETH_ALEN
);
817 memcpy (beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
818 memcpy (beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
820 beacon_buf
->header
.duration_id
= 0; //FIXME
821 beacon_buf
->beacon_interval
=
822 cpu_to_le16(ieee
->current_network
.beacon_interval
);
823 beacon_buf
->capability
=
824 cpu_to_le16(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
);
826 if(ieee
->short_slot
&& (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_SLOT
))
827 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
829 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
831 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
832 ((0 == strcmp(crypt
->ops
->name
, "WEP")) || wpa_ie_len
);
835 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
838 beacon_buf
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
);
840 beacon_buf
->info_element
.id
= MFIE_TYPE_SSID
;
841 beacon_buf
->info_element
.len
= ssid_len
;
843 tag
= (u8
*) beacon_buf
->info_element
.data
;
845 memcpy(tag
, ssid
, ssid_len
);
849 *(tag
++) = MFIE_TYPE_RATES
;
850 *(tag
++) = rate_len
-2;
851 memcpy(tag
,ieee
->current_network
.rates
,rate_len
-2);
854 *(tag
++) = MFIE_TYPE_DS_SET
;
856 *(tag
++) = ieee
->current_network
.channel
;
859 *(tag
++) = MFIE_TYPE_IBSS_SET
;
861 *((u16
*)(tag
)) = cpu_to_le16(ieee
->current_network
.atim_window
);
866 *(tag
++) = MFIE_TYPE_ERP
;
872 *(tag
++) = MFIE_TYPE_RATES_EX
;
873 *(tag
++) = rate_ex_len
-2;
874 memcpy(tag
,ieee
->current_network
.rates_ex
,rate_ex_len
-2);
880 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
881 {//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
882 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
885 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
888 skb
->dev
= ieee
->dev
;
892 static struct sk_buff
*ieee80211_assoc_resp(struct ieee80211_device
*ieee
,
898 struct ieee80211_crypt_data
* crypt
;
899 struct ieee80211_assoc_response_frame
*assoc
;
902 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
903 int len
= sizeof(struct ieee80211_assoc_response_frame
) + rate_len
;
905 skb
= dev_alloc_skb(len
);
910 assoc
= (struct ieee80211_assoc_response_frame
*)
911 skb_put(skb
,sizeof(struct ieee80211_assoc_response_frame
));
913 assoc
->header
.frame_control
= cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
);
914 memcpy(assoc
->header
.addr1
, dest
,ETH_ALEN
);
915 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
916 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
917 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
918 WLAN_CAPABILITY_BSS
: WLAN_CAPABILITY_IBSS
);
922 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
924 if (ieee
->host_encrypt
)
925 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
928 encrypt
= ( crypt
&& crypt
->ops
);
931 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
934 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
935 if (ieee
->assoc_id
== 0x2007) ieee
->assoc_id
=0;
936 else ieee
->assoc_id
++;
938 tag
= (u8
*) skb_put(skb
, rate_len
);
940 ieee80211_MFIE_Brate(ieee
, &tag
);
941 ieee80211_MFIE_Grate(ieee
, &tag
);
946 static struct sk_buff
*ieee80211_auth_resp(struct ieee80211_device
*ieee
,
947 int status
, u8
*dest
)
950 struct ieee80211_authentication
*auth
;
952 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
)+1);
957 skb
->len
= sizeof(struct ieee80211_authentication
);
959 auth
= (struct ieee80211_authentication
*)skb
->data
;
961 auth
->status
= cpu_to_le16(status
);
962 auth
->transaction
= cpu_to_le16(2);
963 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
965 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
966 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
967 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
968 auth
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_AUTH
);
974 struct sk_buff
* ieee80211_null_func(struct ieee80211_device
*ieee
,short pwr
)
977 struct ieee80211_hdr_3addr
* hdr
;
979 skb
= dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr
));
984 hdr
= (struct ieee80211_hdr_3addr
*)skb_put(skb
,sizeof(struct ieee80211_hdr_3addr
));
986 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
987 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
988 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
990 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
991 IEEE80211_STYPE_NULLFUNC
| IEEE80211_FCTL_TODS
|
992 (pwr
? IEEE80211_FCTL_PM
:0));
1000 void ieee80211_resp_to_assoc_rq(struct ieee80211_device
*ieee
, u8
* dest
)
1002 struct sk_buff
*buf
= ieee80211_assoc_resp(ieee
, dest
);
1005 softmac_mgmt_xmit(buf
, ieee
);
1006 dev_kfree_skb_any(buf
);//edit by thomas
1011 void ieee80211_resp_to_auth(struct ieee80211_device
*ieee
, int s
, u8
* dest
)
1013 struct sk_buff
*buf
= ieee80211_auth_resp(ieee
, s
, dest
);
1016 softmac_mgmt_xmit(buf
, ieee
);
1017 dev_kfree_skb_any(buf
);//edit by thomas
1022 void ieee80211_resp_to_probe(struct ieee80211_device
*ieee
, u8
*dest
)
1025 struct sk_buff
*buf
= ieee80211_probe_resp(ieee
, dest
);
1028 softmac_mgmt_xmit(buf
, ieee
);
1029 dev_kfree_skb_any(buf
);//edit by thomas
1034 inline struct sk_buff
*ieee80211_association_req(struct ieee80211_network
*beacon
,struct ieee80211_device
*ieee
)
1036 struct sk_buff
*skb
;
1037 //unsigned long flags;
1039 struct ieee80211_assoc_request_frame
*hdr
;
1041 //short info_addr = 0;
1043 //u16 suite_count = 0;
1044 //u8 suit_select = 0;
1045 unsigned int wpa_len
= beacon
->wpa_ie_len
;
1046 //struct net_device *dev = ieee->dev;
1047 //union iwreq_data wrqu;
1051 // for testing purpose
1052 unsigned int rsn_len
= beacon
->rsn_ie_len
;
1054 unsigned int rsn_len
= beacon
->rsn_ie_len
- 4;
1056 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
1057 unsigned int wmm_info_len
= beacon
->QoS_Enable
?9:0;
1058 unsigned int turbo_info_len
= beacon
->Turbo_Enable
?9:0;
1060 u8 encry_proto
= ieee
->wpax_type_notify
& 0xff;
1061 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1062 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1066 //[0] Notify type of encryption: WPA/WPA2
1067 //[1] pair wise type
1069 if(ieee
->wpax_type_set
) {
1070 if (IEEE_PROTO_WPA
== encry_proto
) {
1072 } else if (IEEE_PROTO_RSN
== encry_proto
) {
1076 len
= sizeof(struct ieee80211_assoc_request_frame
)+
1077 + beacon
->ssid_len
//essid tagged val
1078 + rate_len
//rates tagged val
1084 skb
= dev_alloc_skb(len
);
1089 hdr
= (struct ieee80211_assoc_request_frame
*)
1090 skb_put(skb
, sizeof(struct ieee80211_assoc_request_frame
));
1093 hdr
->header
.frame_control
= IEEE80211_STYPE_ASSOC_REQ
;
1094 hdr
->header
.duration_id
= 37; //FIXME
1095 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1096 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1097 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1098 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);//for HW security, John
1100 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_BSS
);
1101 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1102 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1103 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1104 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1106 if(ieee
->short_slot
)
1107 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
1109 hdr
->listen_interval
= 0xa; //FIXME
1111 hdr
->info_element
.id
= MFIE_TYPE_SSID
;
1113 hdr
->info_element
.len
= beacon
->ssid_len
;
1114 tag
= skb_put(skb
, beacon
->ssid_len
);
1115 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1117 tag
= skb_put(skb
, rate_len
);
1119 ieee80211_MFIE_Brate(ieee
, &tag
);
1120 ieee80211_MFIE_Grate(ieee
, &tag
);
1122 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1123 //choose AES encryption as default algorithm while using mixed mode
1125 tag
= skb_put(skb
,ieee
->wpa_ie_len
);
1126 memcpy(tag
,ieee
->wpa_ie
,ieee
->wpa_ie_len
);
1128 tag
= skb_put(skb
,wmm_info_len
);
1130 ieee80211_WMM_Info(ieee
, &tag
);
1132 tag
= skb_put(skb
,turbo_info_len
);
1133 if(turbo_info_len
) {
1134 ieee80211_TURBO_Info(ieee
, &tag
);
1140 void ieee80211_associate_abort(struct ieee80211_device
*ieee
)
1143 unsigned long flags
;
1144 spin_lock_irqsave(&ieee
->lock
, flags
);
1146 ieee
->associate_seq
++;
1148 /* don't scan, and avoid to have the RX path possibly
1149 * try again to associate. Even do not react to AUTH or
1150 * ASSOC response. Just wait for the retry wq to be scheduled.
1151 * Here we will check if there are good nets to associate
1152 * with, so we retry or just get back to NO_LINK and scanning
1154 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
){
1155 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1156 ieee
->softmac_stats
.no_auth_rs
++;
1158 IEEE80211_DEBUG_MGMT("Association failed\n");
1159 ieee
->softmac_stats
.no_ass_rs
++;
1162 ieee
->state
= IEEE80211_ASSOCIATING_RETRY
;
1164 queue_delayed_work(ieee
->wq
, &ieee
->associate_retry_wq
,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME
);
1166 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1169 void ieee80211_associate_abort_cb(unsigned long dev
)
1171 ieee80211_associate_abort((struct ieee80211_device
*) dev
);
1175 void ieee80211_associate_step1(struct ieee80211_device
*ieee
)
1177 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1178 struct sk_buff
*skb
;
1180 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1181 ieee
->softmac_stats
.tx_auth_rq
++;
1182 skb
=ieee80211_authentication_req(beacon
, ieee
, 0);
1185 ieee80211_associate_abort(ieee
);
1188 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATING
;
1189 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1190 //printk("---Sending authentication request\n");
1191 softmac_mgmt_xmit(skb
, ieee
);
1192 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1193 if(!timer_pending(&ieee
->associate_timer
)){
1194 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1195 add_timer(&ieee
->associate_timer
);
1197 //If call dev_kfree_skb_any,a warning will ocur....
1198 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1199 //So ... 1204 by lawrence.
1200 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1201 //dev_kfree_skb_any(skb);//edit by thomas
1205 void ieee80211_rtl_auth_challenge(struct ieee80211_device
*ieee
, u8
*challenge
, int chlen
)
1208 struct sk_buff
*skb
;
1209 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1210 // int hlen = sizeof(struct ieee80211_authentication);
1211 del_timer_sync(&ieee
->associate_timer
);
1212 ieee
->associate_seq
++;
1213 ieee
->softmac_stats
.tx_auth_rq
++;
1215 skb
= ieee80211_authentication_req(beacon
, ieee
, chlen
+2);
1217 ieee80211_associate_abort(ieee
);
1219 c
= skb_put(skb
, chlen
+2);
1220 *(c
++) = MFIE_TYPE_CHALLENGE
;
1222 memcpy(c
, challenge
, chlen
);
1224 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1226 ieee80211_encrypt_fragment(ieee
, skb
, sizeof(struct ieee80211_hdr_3addr
));
1228 softmac_mgmt_xmit(skb
, ieee
);
1229 if (!timer_pending(&ieee
->associate_timer
)){
1230 //printk("=========>add timer again, to crash\n");
1231 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1232 add_timer(&ieee
->associate_timer
);
1234 dev_kfree_skb_any(skb
);//edit by thomas
1239 void ieee80211_associate_step2(struct ieee80211_device
*ieee
)
1241 struct sk_buff
* skb
;
1242 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1244 del_timer_sync(&ieee
->associate_timer
);
1246 IEEE80211_DEBUG_MGMT("Sending association request\n");
1247 ieee
->softmac_stats
.tx_ass_rq
++;
1248 skb
=ieee80211_association_req(beacon
, ieee
);
1250 ieee80211_associate_abort(ieee
);
1252 softmac_mgmt_xmit(skb
, ieee
);
1253 if (!timer_pending(&ieee
->associate_timer
)){
1254 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1255 add_timer(&ieee
->associate_timer
);
1257 //dev_kfree_skb_any(skb);//edit by thomas
1261 void ieee80211_associate_complete_wq(struct work_struct
*work
)
1263 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_complete_wq
);
1265 printk(KERN_INFO
"Associated successfully\n");
1266 if(ieee80211_is_54g(&ieee
->current_network
) &&
1267 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1270 printk(KERN_INFO
"Using G rates\n");
1273 printk(KERN_INFO
"Using B rates\n");
1275 ieee
->link_change(ieee
->dev
);
1276 notify_wx_assoc_event(ieee
);
1277 if (ieee
->data_hard_resume
)
1278 ieee
->data_hard_resume(ieee
->dev
);
1279 netif_carrier_on(ieee
->dev
);
1282 void ieee80211_associate_complete(struct ieee80211_device
*ieee
)
1285 del_timer_sync(&ieee
->associate_timer
);
1287 for(i
= 0; i
< 6; i
++) {
1288 //ieee->seq_ctrl[i] = 0;
1290 ieee
->state
= IEEE80211_LINKED
;
1291 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1293 queue_work(ieee
->wq
, &ieee
->associate_complete_wq
);
1296 void ieee80211_associate_procedure_wq(struct work_struct
*work
)
1298 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_procedure_wq
);
1300 ieee
->sync_scan_hurryup
= 1;
1301 down(&ieee
->wx_sem
);
1303 if (ieee
->data_hard_stop
)
1304 ieee
->data_hard_stop(ieee
->dev
);
1306 ieee80211_stop_scan(ieee
);
1307 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
1309 ieee
->associate_seq
= 1;
1310 ieee80211_associate_step1(ieee
);
1315 inline void ieee80211_softmac_new_net(struct ieee80211_device
*ieee
, struct ieee80211_network
*net
)
1317 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+1];
1318 int tmp_ssid_len
= 0;
1320 short apset
,ssidset
,ssidbroad
,apmatch
,ssidmatch
;
1322 /* we are interested in new new only if we are not associated
1323 * and we are not associating / authenticating
1325 if (ieee
->state
!= IEEE80211_NOLINK
)
1328 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
& WLAN_CAPABILITY_BSS
))
1331 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
& WLAN_CAPABILITY_IBSS
))
1335 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
){
1336 /* if the user specified the AP MAC, we need also the essid
1337 * This could be obtained by beacons or, if the network does not
1338 * broadcast it, it can be put manually.
1340 apset
= ieee
->wap_set
;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1341 ssidset
= ieee
->ssid_set
;//ieee->current_network.ssid[0] != '\0';
1342 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0]== '\0');
1343 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
, ETH_ALEN
)==0);
1345 if(ieee
->current_network
.ssid_len
!= net
->ssid_len
)
1348 ssidmatch
= (0==strncmp(ieee
->current_network
.ssid
, net
->ssid
, net
->ssid_len
));
1350 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1351 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1353 if ( /* if the user set the AP check if match.
1354 * if the network does not broadcast essid we check the user supplied ANY essid
1355 * if the network does broadcast and the user does not set essid it is OK
1356 * if the network does broadcast and the user did set essid chech if essid match
1358 ( apset
&& apmatch
&&
1359 ((ssidset
&& ssidbroad
&& ssidmatch
) || (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
)) ) ||
1360 /* if the ap is not set, check that the user set the bssid
1361 * and the network does broadcast and that those two bssid matches
1363 (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
)
1367 /* if the essid is hidden replace it with the
1368 * essid provided by the user.
1371 strncpy(tmp_ssid
, ieee
->current_network
.ssid
, IW_ESSID_MAX_SIZE
);
1372 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1374 memcpy(&ieee
->current_network
, net
, sizeof(struct ieee80211_network
));
1377 strncpy(ieee
->current_network
.ssid
, tmp_ssid
, IW_ESSID_MAX_SIZE
);
1378 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1380 printk(KERN_INFO
"Linking with %s: channel is %d\n",ieee
->current_network
.ssid
,ieee
->current_network
.channel
);
1382 if (ieee
->iw_mode
== IW_MODE_INFRA
){
1383 ieee
->state
= IEEE80211_ASSOCIATING
;
1384 ieee
->beinretry
= false;
1385 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1387 if(ieee80211_is_54g(&ieee
->current_network
) &&
1388 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1390 printk(KERN_INFO
"Using G rates\n");
1393 printk(KERN_INFO
"Using B rates\n");
1395 ieee
->state
= IEEE80211_LINKED
;
1396 ieee
->beinretry
= false;
1404 void ieee80211_softmac_check_all_nets(struct ieee80211_device
*ieee
)
1406 unsigned long flags
;
1407 struct ieee80211_network
*target
;
1409 spin_lock_irqsave(&ieee
->lock
, flags
);
1410 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1412 /* if the state become different that NOLINK means
1413 * we had found what we are searching for
1416 if (ieee
->state
!= IEEE80211_NOLINK
)
1419 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
))
1420 ieee80211_softmac_new_net(ieee
, target
);
1423 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1428 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1430 struct ieee80211_authentication
*a
;
1432 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1433 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb
->len
);
1437 a
= (struct ieee80211_authentication
*) skb
->data
;
1438 if(skb
->len
> (sizeof(struct ieee80211_authentication
) +3)){
1439 t
= skb
->data
+ sizeof(struct ieee80211_authentication
);
1441 if(*(t
++) == MFIE_TYPE_CHALLENGE
){
1443 *challenge
= kmemdup(t
, *chlen
, GFP_ATOMIC
);
1449 return cpu_to_le16(a
->status
);
1454 int auth_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1456 struct ieee80211_authentication
*a
;
1458 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1459 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb
->len
);
1462 a
= (struct ieee80211_authentication
*) skb
->data
;
1464 memcpy(dest
,a
->header
.addr2
, ETH_ALEN
);
1466 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1467 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1469 return WLAN_STATUS_SUCCESS
;
1472 static short probe_rq_parse(struct ieee80211_device
*ieee
, struct sk_buff
*skb
, u8
*src
)
1479 struct ieee80211_hdr_3addr
*header
=
1480 (struct ieee80211_hdr_3addr
*) skb
->data
;
1482 if (skb
->len
< sizeof (struct ieee80211_hdr_3addr
))
1483 return -1; /* corrupted */
1485 memcpy(src
,header
->addr2
, ETH_ALEN
);
1487 skbend
= (u8
*)skb
->data
+ skb
->len
;
1489 tag
= skb
->data
+ sizeof (struct ieee80211_hdr_3addr
);
1491 while (tag
+1 < skbend
){
1497 tag
++; /* point to the len field */
1498 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1499 tag
++; /* point to the next tag */
1502 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1503 if (ssidlen
== 0) return 1;
1505 if (!ssid
) return 1; /* ssid not found in tagged param */
1506 return (!strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
));
1510 int assoc_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1512 struct ieee80211_assoc_request_frame
*a
;
1514 if (skb
->len
< (sizeof(struct ieee80211_assoc_request_frame
) -
1515 sizeof(struct ieee80211_info_element
))) {
1517 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb
->len
);
1521 a
= (struct ieee80211_assoc_request_frame
*) skb
->data
;
1523 memcpy(dest
,a
->header
.addr2
,ETH_ALEN
);
1528 static inline u16
assoc_parse(struct sk_buff
*skb
, int *aid
)
1530 struct ieee80211_assoc_response_frame
*a
;
1531 if (skb
->len
< sizeof(struct ieee80211_assoc_response_frame
)){
1532 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1536 a
= (struct ieee80211_assoc_response_frame
*) skb
->data
;
1537 *aid
= le16_to_cpu(a
->aid
) & 0x3fff;
1538 return le16_to_cpu(a
->status
);
1542 ieee80211_rx_probe_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1546 //IEEE80211DMESG("Rx probe");
1547 ieee
->softmac_stats
.rx_probe_rq
++;
1548 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1549 if (probe_rq_parse(ieee
, skb
, dest
)){
1550 //IEEE80211DMESG("Was for me!");
1551 ieee
->softmac_stats
.tx_probe_rs
++;
1552 ieee80211_resp_to_probe(ieee
, dest
);
1557 ieee80211_rx_auth_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1561 //IEEE80211DMESG("Rx probe");
1562 ieee
->softmac_stats
.rx_auth_rq
++;
1564 status
= auth_rq_parse(skb
, dest
);
1566 ieee80211_resp_to_auth(ieee
, status
, dest
);
1568 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1573 ieee80211_rx_assoc_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1577 //unsigned long flags;
1579 ieee
->softmac_stats
.rx_ass_rq
++;
1580 if (assoc_rq_parse(skb
,dest
) != -1){
1581 ieee80211_resp_to_assoc_rq(ieee
, dest
);
1584 printk(KERN_INFO
"New client associated: %pM\n", dest
);
1589 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device
*ieee
, short pwr
)
1592 struct sk_buff
*buf
= ieee80211_null_func(ieee
, pwr
);
1595 softmac_ps_mgmt_xmit(buf
, ieee
);
1600 short ieee80211_sta_ps_sleep(struct ieee80211_device
*ieee
, u32
*time_h
, u32
*time_l
)
1605 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1606 ieee->iw_mode != IW_MODE_INFRA ||
1607 ieee->state != IEEE80211_LINKED)
1611 dtim
= ieee
->current_network
.dtim_data
;
1614 if(!(dtim
& IEEE80211_DTIM_VALID
))
1617 timeout
= ieee
->current_network
.beacon_interval
;
1619 //printk("VALID\n");
1620 ieee
->current_network
.dtim_data
= IEEE80211_DTIM_INVALID
;
1622 if(dtim
& ((IEEE80211_DTIM_UCAST
| IEEE80211_DTIM_MBCAST
)& ieee
->ps
))
1625 if(!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
)))
1628 if(!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
)))
1631 if((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
1632 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
1636 *time_l
= ieee
->current_network
.last_dtim_sta_time
[0]
1637 + MSECS((ieee
->current_network
.beacon_interval
));
1638 //* ieee->current_network.dtim_period));
1639 //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);
1643 *time_h
= ieee
->current_network
.last_dtim_sta_time
[1];
1644 if(time_l
&& *time_l
< ieee
->current_network
.last_dtim_sta_time
[0])
1653 inline void ieee80211_sta_ps(struct ieee80211_device
*ieee
)
1659 unsigned long flags
,flags2
;
1661 spin_lock_irqsave(&ieee
->lock
, flags
);
1663 if((ieee
->ps
== IEEE80211_PS_DISABLED
||
1665 ieee
->iw_mode
!= IW_MODE_INFRA
||
1666 ieee
->state
!= IEEE80211_LINKED
)){
1668 //#warning CHECK_LOCK_HERE
1669 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1671 ieee80211_sta_wakeup(ieee
, 1);
1673 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1676 sleep
= ieee80211_sta_ps_sleep(ieee
,&th
, &tl
);
1677 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
1678 /* 2 wake, 1 sleep, 0 do nothing */
1684 if(ieee
->sta_sleep
== 1)
1685 ieee
->enter_sleep_state(ieee
->dev
,th
,tl
);
1687 else if(ieee
->sta_sleep
== 0){
1688 // printk("send null 1\n");
1689 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1691 if(ieee
->ps_is_queue_empty(ieee
->dev
)){
1694 ieee
->sta_sleep
= 2;
1696 ieee
->ps_request_tx_ack(ieee
->dev
);
1698 ieee80211_sta_ps_send_null_frame(ieee
,1);
1703 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1708 }else if(sleep
== 2){
1709 //#warning CHECK_LOCK_HERE
1710 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1712 // printk("send wakeup packet\n");
1713 ieee80211_sta_wakeup(ieee
,1);
1715 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1719 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1723 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
)
1725 if(ieee
->sta_sleep
== 0){
1727 // printk("Warning: driver is probably failing to report TX ps error\n");
1728 ieee
->ps_request_tx_ack(ieee
->dev
);
1729 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1735 if(ieee
->sta_sleep
== 1)
1736 ieee
->sta_wake_up(ieee
->dev
);
1738 ieee
->sta_sleep
= 0;
1741 ieee
->ps_request_tx_ack(ieee
->dev
);
1742 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1746 void ieee80211_ps_tx_ack(struct ieee80211_device
*ieee
, short success
)
1748 unsigned long flags
,flags2
;
1750 spin_lock_irqsave(&ieee
->lock
, flags
);
1751 if(ieee
->sta_sleep
== 2){
1752 /* Null frame with PS bit set */
1755 // printk("==================> %s::enter sleep state\n",__func__);
1756 ieee
->sta_sleep
= 1;
1757 ieee
->enter_sleep_state(ieee
->dev
,ieee
->ps_th
,ieee
->ps_tl
);
1759 /* if the card report not success we can't be sure the AP
1760 * has not RXed so we can't assume the AP believe us awake
1763 /* 21112005 - tx again null without PS bit if lost */
1766 if((ieee
->sta_sleep
== 0) && !success
){
1767 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1768 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1769 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1772 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1776 ieee80211_rx_frame_softmac(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
1777 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
1780 struct ieee80211_hdr_3addr
*header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
1785 struct ieee80211_assoc_response_frame
*assoc_resp
;
1786 struct ieee80211_info_element
*info_element
;
1788 if(!ieee
->proto_started
)
1791 if(ieee
->sta_sleep
|| (ieee
->ps
!= IEEE80211_PS_DISABLED
&&
1792 ieee
->iw_mode
== IW_MODE_INFRA
&&
1793 ieee
->state
== IEEE80211_LINKED
))
1795 tasklet_schedule(&ieee
->ps_task
);
1797 if (WLAN_FC_GET_STYPE(header
->frame_control
) != IEEE80211_STYPE_PROBE_RESP
&&
1798 WLAN_FC_GET_STYPE(header
->frame_control
) != IEEE80211_STYPE_BEACON
)
1799 ieee
->last_rx_ps_time
= jiffies
;
1801 switch (WLAN_FC_GET_STYPE(header
->frame_control
)) {
1803 case IEEE80211_STYPE_ASSOC_RESP
:
1804 case IEEE80211_STYPE_REASSOC_RESP
:
1806 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1807 WLAN_FC_GET_STYPE(header
->frame_ctl
));
1808 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1809 ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATED
&&
1810 ieee
->iw_mode
== IW_MODE_INFRA
){
1811 if (0 == (errcode
=assoc_parse(skb
, &aid
))){
1814 ieee
->state
=IEEE80211_LINKED
;
1815 ieee
->assoc_id
= aid
;
1816 ieee
->softmac_stats
.rx_ass_ok
++;
1818 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
1819 if(1 == rx_stats
->nic_type
) //card type is 8187
1821 goto associate_complete
;
1823 assoc_resp
= (struct ieee80211_assoc_response_frame
*)skb
->data
;
1824 info_element
= &assoc_resp
->info_element
;
1825 left
= skb
->len
- ((void*)info_element
- (void*)assoc_resp
);
1827 while (left
>= sizeof(struct ieee80211_info_element_hdr
)) {
1828 if (sizeof(struct ieee80211_info_element_hdr
) + info_element
->len
> left
) {
1829 printk(KERN_WARNING
"[re]associate response error!");
1832 switch (info_element
->id
) {
1833 case MFIE_TYPE_GENERIC
:
1834 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element
->len
);
1835 if (info_element
->len
>= 8 &&
1836 info_element
->data
[0] == 0x00 &&
1837 info_element
->data
[1] == 0x50 &&
1838 info_element
->data
[2] == 0xf2 &&
1839 info_element
->data
[3] == 0x02 &&
1840 info_element
->data
[4] == 0x01) {
1841 // Not care about version at present.
1842 //WMM Parameter Element
1843 memcpy(ieee
->current_network
.wmm_param
,(u8
*)(info_element
->data\
1844 + 8),(info_element
->len
- 8));
1846 if (((ieee
->current_network
.wmm_info
^info_element
->data
[6])& \
1847 0x0f)||(!ieee
->init_wmmparam_flag
)) {
1848 // refresh parameter element for current network
1849 // update the register parameter for hardware
1850 ieee
->init_wmmparam_flag
= 1;
1851 queue_work(ieee
->wq
, &ieee
->wmm_param_update_wq
);
1854 //update info_element for current network
1855 ieee
->current_network
.wmm_info
= info_element
->data
[6];
1859 //nothing to do at present!!!
1863 left
-= sizeof(struct ieee80211_info_element_hdr
) +
1865 info_element
= (struct ieee80211_info_element
*)
1866 &info_element
->data
[info_element
->len
];
1868 if(!ieee
->init_wmmparam_flag
) //legacy AP, reset the AC_xx_param register
1870 queue_work(ieee
->wq
,&ieee
->wmm_param_update_wq
);
1871 ieee
->init_wmmparam_flag
= 1;//indicate AC_xx_param upated since last associate
1874 ieee80211_associate_complete(ieee
);
1876 ieee
->softmac_stats
.rx_ass_err
++;
1877 IEEE80211_DEBUG_MGMT(
1878 "Association response status code 0x%x\n",
1880 ieee80211_associate_abort(ieee
);
1885 case IEEE80211_STYPE_ASSOC_REQ
:
1886 case IEEE80211_STYPE_REASSOC_REQ
:
1888 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1889 ieee
->iw_mode
== IW_MODE_MASTER
)
1891 ieee80211_rx_assoc_rq(ieee
, skb
);
1894 case IEEE80211_STYPE_AUTH
:
1896 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
){
1897 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
&&
1898 ieee
->iw_mode
== IW_MODE_INFRA
){
1900 IEEE80211_DEBUG_MGMT("Received authentication response");
1902 if (0 == (errcode
=auth_parse(skb
, &challenge
, &chlen
))){
1903 if(ieee
->open_wep
|| !challenge
){
1904 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATED
;
1905 ieee
->softmac_stats
.rx_auth_rs_ok
++;
1907 ieee80211_associate_step2(ieee
);
1909 ieee80211_rtl_auth_challenge(ieee
, challenge
, chlen
);
1912 ieee
->softmac_stats
.rx_auth_rs_err
++;
1913 IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode
);
1914 ieee80211_associate_abort(ieee
);
1917 }else if (ieee
->iw_mode
== IW_MODE_MASTER
){
1918 ieee80211_rx_auth_rq(ieee
, skb
);
1923 case IEEE80211_STYPE_PROBE_REQ
:
1925 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
1926 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
1927 ieee
->iw_mode
== IW_MODE_MASTER
) &&
1928 ieee
->state
== IEEE80211_LINKED
))
1930 ieee80211_rx_probe_rq(ieee
, skb
);
1933 case IEEE80211_STYPE_DISASSOC
:
1934 case IEEE80211_STYPE_DEAUTH
:
1935 /* FIXME for now repeat all the association procedure
1936 * both for disassociation and deauthentication
1938 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1939 (ieee
->state
== IEEE80211_LINKED
) &&
1940 (ieee
->iw_mode
== IW_MODE_INFRA
) &&
1941 (!memcmp(header
->addr2
,ieee
->current_network
.bssid
,ETH_ALEN
))){
1942 ieee
->state
= IEEE80211_ASSOCIATING
;
1943 ieee
->softmac_stats
.reassoc
++;
1945 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
1946 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1956 //dev_kfree_skb_any(skb);
1962 /* following are for a simpler TX queue management.
1963 * Instead of using netif_[stop/wake]_queue the driver
1964 * will uses these two function (plus a reset one), that
1965 * will internally uses the kernel netif_* and takes
1966 * care of the ieee802.11 fragmentation.
1967 * So the driver receives a fragment per time and might
1968 * call the stop function when it want without take care
1969 * to have enough room to TX an entire packet.
1970 * This might be useful if each fragment need it's own
1971 * descriptor, thus just keep a total free memory > than
1972 * the max fragmentation threshold is not enough.. If the
1973 * ieee802.11 stack passed a TXB struct then you needed
1974 * to keep N free descriptors where
1975 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
1976 * In this way you need just one and the 802.11 stack
1977 * will take care of buffering fragments and pass them to
1978 * to the driver later, when it wakes the queue.
1981 void ieee80211_softmac_xmit(struct ieee80211_txb
*txb
, struct ieee80211_device
*ieee
)
1985 unsigned long flags
;
1988 spin_lock_irqsave(&ieee
->lock
,flags
);
1990 /* called with 2nd parm 0, no tx mgmt lock required */
1991 ieee80211_sta_wakeup(ieee
,0);
1993 for(i
= 0; i
< txb
->nr_frags
; i
++) {
1995 if (ieee
->queue_stop
){
1996 ieee
->tx_pending
.txb
= txb
;
1997 ieee
->tx_pending
.frag
= i
;
2000 ieee
->softmac_data_hard_start_xmit(
2002 ieee
->dev
,ieee
->rate
);
2003 //(i+1)<txb->nr_frags);
2004 ieee
->stats
.tx_packets
++;
2005 ieee
->stats
.tx_bytes
+= txb
->fragments
[i
]->len
;
2006 ieee
->dev
->trans_start
= jiffies
;
2010 ieee80211_txb_free(txb
);
2013 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2017 /* called with ieee->lock acquired */
2018 void ieee80211_resume_tx(struct ieee80211_device
*ieee
)
2021 for(i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
; i
++) {
2023 if (ieee
->queue_stop
){
2024 ieee
->tx_pending
.frag
= i
;
2028 ieee
->softmac_data_hard_start_xmit(
2029 ieee
->tx_pending
.txb
->fragments
[i
],
2030 ieee
->dev
,ieee
->rate
);
2031 //(i+1)<ieee->tx_pending.txb->nr_frags);
2032 ieee
->stats
.tx_packets
++;
2033 ieee
->dev
->trans_start
= jiffies
;
2038 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2039 ieee
->tx_pending
.txb
= NULL
;
2043 void ieee80211_reset_queue(struct ieee80211_device
*ieee
)
2045 unsigned long flags
;
2047 spin_lock_irqsave(&ieee
->lock
,flags
);
2048 init_mgmt_queue(ieee
);
2049 if (ieee
->tx_pending
.txb
){
2050 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2051 ieee
->tx_pending
.txb
= NULL
;
2053 ieee
->queue_stop
= 0;
2054 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2058 void ieee80211_rtl_wake_queue(struct ieee80211_device
*ieee
)
2061 unsigned long flags
;
2062 struct sk_buff
*skb
;
2063 struct ieee80211_hdr_3addr
*header
;
2065 spin_lock_irqsave(&ieee
->lock
,flags
);
2066 if (! ieee
->queue_stop
) goto exit
;
2068 ieee
->queue_stop
= 0;
2070 if(ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
){
2071 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))){
2073 header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
2075 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2077 if (ieee
->seq_ctrl
[0] == 0xFFF)
2078 ieee
->seq_ctrl
[0] = 0;
2080 ieee
->seq_ctrl
[0]++;
2082 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2083 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
2084 dev_kfree_skb_any(skb
);//edit by thomas
2087 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2088 ieee80211_resume_tx(ieee
);
2090 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)){
2091 ieee
->softmac_stats
.swtxawake
++;
2092 netif_wake_queue(ieee
->dev
);
2096 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2100 void ieee80211_rtl_stop_queue(struct ieee80211_device
*ieee
)
2102 //unsigned long flags;
2103 //spin_lock_irqsave(&ieee->lock,flags);
2105 if (! netif_queue_stopped(ieee
->dev
)){
2106 netif_stop_queue(ieee
->dev
);
2107 ieee
->softmac_stats
.swtxstop
++;
2109 ieee
->queue_stop
= 1;
2110 //spin_unlock_irqrestore(&ieee->lock,flags);
2115 inline void ieee80211_randomize_cell(struct ieee80211_device
*ieee
)
2118 random_ether_addr(ieee
->current_network
.bssid
);
2121 /* called in user context only */
2122 void ieee80211_start_master_bss(struct ieee80211_device
*ieee
)
2126 if (ieee
->current_network
.ssid_len
== 0){
2127 strncpy(ieee
->current_network
.ssid
,
2128 IEEE80211_DEFAULT_TX_ESSID
,
2131 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2135 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2137 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2138 ieee
->state
= IEEE80211_LINKED
;
2139 ieee
->link_change(ieee
->dev
);
2140 notify_wx_assoc_event(ieee
);
2142 if (ieee
->data_hard_resume
)
2143 ieee
->data_hard_resume(ieee
->dev
);
2145 netif_carrier_on(ieee
->dev
);
2148 void ieee80211_start_monitor_mode(struct ieee80211_device
*ieee
)
2152 if (ieee
->data_hard_resume
)
2153 ieee
->data_hard_resume(ieee
->dev
);
2155 netif_carrier_on(ieee
->dev
);
2159 void ieee80211_start_ibss_wq(struct work_struct
*work
)
2161 struct delayed_work
*dwork
= to_delayed_work(work
);
2162 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, start_ibss_wq
);
2164 /* iwconfig mode ad-hoc will schedule this and return
2165 * on the other hand this will block further iwconfig SET
2166 * operations because of the wx_sem hold.
2167 * Anyway some most set operations set a flag to speed-up
2168 * (abort) this wq (when syncro scanning) before sleeping
2172 down(&ieee
->wx_sem
);
2175 if (ieee
->current_network
.ssid_len
== 0){
2176 strcpy(ieee
->current_network
.ssid
,IEEE80211_DEFAULT_TX_ESSID
);
2177 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2181 /* check if we have this cell in our network list */
2182 ieee80211_softmac_check_all_nets(ieee
);
2184 if(ieee
->state
== IEEE80211_NOLINK
)
2185 ieee
->current_network
.channel
= 10;
2186 /* if not then the state is not linked. Maybe the user switched to
2187 * ad-hoc mode just after being in monitor mode, or just after
2188 * being very few time in managed mode (so the card have had no
2189 * time to scan all the chans..) or we have just run up the iface
2190 * after setting ad-hoc mode. So we have to give another try..
2191 * Here, in ibss mode, should be safe to do this without extra care
2192 * (in bss mode we had to make sure no-one tried to associate when
2193 * we had just checked the ieee->state and we was going to start the
2194 * scan) because in ibss mode the ieee80211_new_net function, when
2195 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2196 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2197 * scan, that will stop at the first round because it sees the state
2200 if (ieee
->state
== IEEE80211_NOLINK
)
2201 ieee80211_start_scan_syncro(ieee
);
2203 /* the network definitively is not here.. create a new cell */
2204 if (ieee
->state
== IEEE80211_NOLINK
){
2205 printk("creating new IBSS cell\n");
2207 ieee80211_randomize_cell(ieee
);
2209 if(ieee
->modulation
& IEEE80211_CCK_MODULATION
){
2211 ieee
->current_network
.rates_len
= 4;
2213 ieee
->current_network
.rates
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
2214 ieee
->current_network
.rates
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
2215 ieee
->current_network
.rates
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_5MB
;
2216 ieee
->current_network
.rates
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_11MB
;
2219 ieee
->current_network
.rates_len
= 0;
2221 if(ieee
->modulation
& IEEE80211_OFDM_MODULATION
){
2222 ieee
->current_network
.rates_ex_len
= 8;
2224 ieee
->current_network
.rates_ex
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_6MB
;
2225 ieee
->current_network
.rates_ex
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_9MB
;
2226 ieee
->current_network
.rates_ex
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_12MB
;
2227 ieee
->current_network
.rates_ex
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_18MB
;
2228 ieee
->current_network
.rates_ex
[4] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
2229 ieee
->current_network
.rates_ex
[5] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_36MB
;
2230 ieee
->current_network
.rates_ex
[6] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_48MB
;
2231 ieee
->current_network
.rates_ex
[7] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_54MB
;
2235 ieee
->current_network
.rates_ex_len
= 0;
2239 // By default, WMM function will be disabled in IBSS mode
2240 ieee
->current_network
.QoS_Enable
= 0;
2242 ieee
->current_network
.atim_window
= 0;
2243 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2244 if(ieee
->short_slot
)
2245 ieee
->current_network
.capability
|= WLAN_CAPABILITY_SHORT_SLOT
;
2249 ieee
->state
= IEEE80211_LINKED
;
2250 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2251 ieee
->link_change(ieee
->dev
);
2253 notify_wx_assoc_event(ieee
);
2255 ieee80211_start_send_beacons(ieee
);
2256 printk(KERN_WARNING
"after sending beacon packet!\n");
2258 if (ieee
->data_hard_resume
)
2259 ieee
->data_hard_resume(ieee
->dev
);
2261 netif_carrier_on(ieee
->dev
);
2265 inline void ieee80211_start_ibss(struct ieee80211_device
*ieee
)
2267 queue_delayed_work(ieee
->wq
, &ieee
->start_ibss_wq
, 100);
2270 /* this is called only in user context, with wx_sem held */
2271 void ieee80211_start_bss(struct ieee80211_device
*ieee
)
2273 unsigned long flags
;
2275 // Ref: 802.11d 11.1.3.3
2276 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2278 if(IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
))
2280 if(! ieee
->bGlobalDomain
)
2285 /* check if we have already found the net we
2286 * are interested in (if any).
2287 * if not (we are disassociated and we are not
2288 * in associating / authenticating phase) start the background scanning.
2290 ieee80211_softmac_check_all_nets(ieee
);
2292 /* ensure no-one start an associating process (thus setting
2293 * the ieee->state to ieee80211_ASSOCIATING) while we
2294 * have just cheked it and we are going to enable scan.
2295 * The ieee80211_new_net function is always called with
2296 * lock held (from both ieee80211_softmac_check_all_nets and
2297 * the rx path), so we cannot be in the middle of such function
2299 spin_lock_irqsave(&ieee
->lock
, flags
);
2302 // printk("start bss ENABLE_IPS\n");
2304 if (ieee
->state
== IEEE80211_NOLINK
){
2305 ieee
->actscanning
= true;
2306 ieee80211_rtl_start_scan(ieee
);
2309 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2312 /* called only in userspace context */
2313 void ieee80211_disassociate(struct ieee80211_device
*ieee
)
2315 netif_carrier_off(ieee
->dev
);
2317 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2318 ieee80211_reset_queue(ieee
);
2320 if (ieee
->data_hard_stop
)
2321 ieee
->data_hard_stop(ieee
->dev
);
2323 if(IS_DOT11D_ENABLE(ieee
))
2326 ieee
->link_change(ieee
->dev
);
2327 if (ieee
->state
== IEEE80211_LINKED
)
2328 notify_wx_assoc_event(ieee
);
2329 ieee
->state
= IEEE80211_NOLINK
;
2332 void ieee80211_associate_retry_wq(struct work_struct
*work
)
2334 struct delayed_work
*dwork
= to_delayed_work(work
);
2335 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, associate_retry_wq
);
2336 unsigned long flags
;
2337 down(&ieee
->wx_sem
);
2338 if(!ieee
->proto_started
)
2340 if(ieee
->state
!= IEEE80211_ASSOCIATING_RETRY
)
2342 /* until we do not set the state to IEEE80211_NOLINK
2343 * there are no possibility to have someone else trying
2344 * to start an association procedure (we get here with
2345 * ieee->state = IEEE80211_ASSOCIATING).
2346 * When we set the state to IEEE80211_NOLINK it is possible
2347 * that the RX path run an attempt to associate, but
2348 * both ieee80211_softmac_check_all_nets and the
2349 * RX path works with ieee->lock held so there are no
2350 * problems. If we are still disassociated then start a scan.
2351 * the lock here is necessary to ensure no one try to start
2352 * an association procedure when we have just checked the
2353 * state and we are going to start the scan.
2355 ieee
->state
= IEEE80211_NOLINK
;
2356 ieee
->beinretry
= true;
2357 ieee80211_softmac_check_all_nets(ieee
);
2359 spin_lock_irqsave(&ieee
->lock
, flags
);
2361 if(ieee
->state
== IEEE80211_NOLINK
){
2362 ieee
->beinretry
= false;
2363 ieee
->actscanning
= true;
2364 ieee80211_rtl_start_scan(ieee
);
2366 //YJ,add,080828, notify os here
2367 if(ieee
->state
== IEEE80211_NOLINK
)
2369 notify_wx_assoc_event(ieee
);
2372 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2378 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
)
2380 u8 broadcast_addr
[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2382 struct sk_buff
*skb
= NULL
;
2383 struct ieee80211_probe_response
*b
;
2385 skb
= ieee80211_probe_resp(ieee
, broadcast_addr
);
2389 b
= (struct ieee80211_probe_response
*) skb
->data
;
2390 b
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_BEACON
);
2396 struct sk_buff
*ieee80211_get_beacon(struct ieee80211_device
*ieee
)
2398 struct sk_buff
*skb
;
2399 struct ieee80211_probe_response
*b
;
2401 skb
= ieee80211_get_beacon_(ieee
);
2405 b
= (struct ieee80211_probe_response
*) skb
->data
;
2406 b
->header
.seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2408 if (ieee
->seq_ctrl
[0] == 0xFFF)
2409 ieee
->seq_ctrl
[0] = 0;
2411 ieee
->seq_ctrl
[0]++;
2416 void ieee80211_softmac_stop_protocol(struct ieee80211_device
*ieee
)
2418 ieee
->sync_scan_hurryup
= 1;
2419 down(&ieee
->wx_sem
);
2420 ieee80211_stop_protocol(ieee
);
2425 void ieee80211_stop_protocol(struct ieee80211_device
*ieee
)
2427 if (!ieee
->proto_started
)
2430 ieee
->proto_started
= 0;
2432 ieee80211_stop_send_beacons(ieee
);
2433 if((ieee
->iw_mode
== IW_MODE_INFRA
)&&(ieee
->state
== IEEE80211_LINKED
)) {
2434 SendDisassociation(ieee
,NULL
,WLAN_REASON_DISASSOC_STA_HAS_LEFT
);
2436 del_timer_sync(&ieee
->associate_timer
);
2437 cancel_delayed_work(&ieee
->associate_retry_wq
);
2438 cancel_delayed_work(&ieee
->start_ibss_wq
);
2439 ieee80211_stop_scan(ieee
);
2441 ieee80211_disassociate(ieee
);
2444 void ieee80211_softmac_start_protocol(struct ieee80211_device
*ieee
)
2446 ieee
->sync_scan_hurryup
= 0;
2447 down(&ieee
->wx_sem
);
2448 ieee80211_start_protocol(ieee
);
2452 void ieee80211_start_protocol(struct ieee80211_device
*ieee
)
2457 if (ieee
->proto_started
)
2460 ieee
->proto_started
= 1;
2462 if (ieee
->current_network
.channel
== 0){
2465 if (ch
> MAX_CHANNEL_NUMBER
)
2466 return; /* no channel found */
2468 }while(!GET_DOT11D_INFO(ieee
)->channel_map
[ch
]);
2470 ieee
->current_network
.channel
= ch
;
2473 if (ieee
->current_network
.beacon_interval
== 0)
2474 ieee
->current_network
.beacon_interval
= 100;
2475 ieee
->set_chan(ieee
->dev
,ieee
->current_network
.channel
);
2477 for(i
= 0; i
< 17; i
++) {
2478 ieee
->last_rxseq_num
[i
] = -1;
2479 ieee
->last_rxfrag_num
[i
] = -1;
2480 ieee
->last_packet_time
[i
] = 0;
2483 ieee
->init_wmmparam_flag
= 0;//reinitialize AC_xx_PARAM registers.
2486 /* if the user set the MAC of the ad-hoc cell and then
2487 * switch to managed mode, shall we make sure that association
2488 * attempts does not fail just because the user provide the essid
2489 * and the nic is still checking for the AP MAC ??
2491 switch (ieee
->iw_mode
) {
2493 ieee
->iw_mode
= IW_MODE_INFRA
;
2494 //not set break here intentionly
2496 ieee80211_start_bss(ieee
);
2500 ieee80211_start_ibss(ieee
);
2503 case IW_MODE_MASTER
:
2504 ieee80211_start_master_bss(ieee
);
2507 case IW_MODE_MONITOR
:
2508 ieee80211_start_monitor_mode(ieee
);
2512 ieee
->iw_mode
= IW_MODE_INFRA
;
2513 ieee80211_start_bss(ieee
);
2519 #define DRV_NAME "Ieee80211"
2520 void ieee80211_softmac_init(struct ieee80211_device
*ieee
)
2523 memset(&ieee
->current_network
, 0, sizeof(struct ieee80211_network
));
2525 ieee
->state
= IEEE80211_NOLINK
;
2526 ieee
->sync_scan_hurryup
= 0;
2527 for(i
= 0; i
< 5; i
++) {
2528 ieee
->seq_ctrl
[i
] = 0;
2532 ieee
->queue_stop
= 0;
2534 ieee
->softmac_features
= 0; //so IEEE2100-like driver are happy
2537 ieee
->proto_started
= 0;
2538 ieee
->basic_rate
= IEEE80211_DEFAULT_BASIC_RATE
;
2541 ieee
->ps
= IEEE80211_PS_MBCAST
|IEEE80211_PS_UNICAST
;
2543 // ieee->ps = IEEE80211_PS_DISABLED;
2545 ieee
->sta_sleep
= 0;
2547 ieee
->bInactivePs
= false;
2548 ieee
->actscanning
= false;
2549 ieee
->ListenInterval
= 2;
2550 ieee
->NumRxDataInPeriod
= 0; //YJ,add,080828
2551 ieee
->NumRxBcnInPeriod
= 0; //YJ,add,080828
2552 ieee
->NumRxOkTotal
= 0;//+by amy 080312
2553 ieee
->NumRxUnicast
= 0;//YJ,add,080828,for keep alive
2554 ieee
->beinretry
= false;
2555 ieee
->bHwRadioOff
= false;
2558 init_mgmt_queue(ieee
);
2560 ieee
->tx_pending
.txb
= NULL
;
2562 init_timer(&ieee
->associate_timer
);
2563 ieee
->associate_timer
.data
= (unsigned long)ieee
;
2564 ieee
->associate_timer
.function
= ieee80211_associate_abort_cb
;
2566 init_timer(&ieee
->beacon_timer
);
2567 ieee
->beacon_timer
.data
= (unsigned long) ieee
;
2568 ieee
->beacon_timer
.function
= ieee80211_send_beacon_cb
;
2570 ieee
->wq
= create_workqueue(DRV_NAME
);
2572 INIT_DELAYED_WORK(&ieee
->start_ibss_wq
,(void*) ieee80211_start_ibss_wq
);
2573 INIT_WORK(&ieee
->associate_complete_wq
,(void*) ieee80211_associate_complete_wq
);
2574 INIT_WORK(&ieee
->associate_procedure_wq
,(void*) ieee80211_associate_procedure_wq
);
2575 INIT_DELAYED_WORK(&ieee
->softmac_scan_wq
,(void*) ieee80211_softmac_scan_wq
);
2576 INIT_DELAYED_WORK(&ieee
->associate_retry_wq
,(void*) ieee80211_associate_retry_wq
);
2577 INIT_WORK(&ieee
->wx_sync_scan_wq
,(void*) ieee80211_wx_sync_scan_wq
);
2578 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2580 sema_init(&ieee
->wx_sem
, 1);
2581 sema_init(&ieee
->scan_sem
, 1);
2583 spin_lock_init(&ieee
->mgmt_tx_lock
);
2584 spin_lock_init(&ieee
->beacon_lock
);
2586 tasklet_init(&ieee
->ps_task
,
2587 (void(*)(unsigned long)) ieee80211_sta_ps
,
2588 (unsigned long)ieee
);
2589 ieee
->pDot11dInfo
= kmalloc(sizeof(RT_DOT11D_INFO
), GFP_ATOMIC
);
2592 void ieee80211_softmac_free(struct ieee80211_device
*ieee
)
2594 down(&ieee
->wx_sem
);
2596 del_timer_sync(&ieee
->associate_timer
);
2597 cancel_delayed_work(&ieee
->associate_retry_wq
);
2600 //add for RF power on power of by lizhaoming 080512
2601 cancel_delayed_work(&ieee
->GPIOChangeRFWorkItem
);
2603 destroy_workqueue(ieee
->wq
);
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
= kmemdup(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 (is_broadcast_ether_addr(param
->sta_addr
)) {
2811 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
2813 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
2818 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
2823 sec
.level
= SEC_LEVEL_0
;
2824 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
2825 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2832 sec
.flags
|= SEC_ENABLED
;
2834 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
2835 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
2836 strcmp(param
->u
.crypt
.alg
, "TKIP"))
2837 goto skip_host_crypt
;
2839 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2840 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
2841 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2842 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0)
2843 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2844 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0)
2845 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2847 printk("unknown crypto alg '%s'\n", param
->u
.crypt
.alg
);
2848 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
2853 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
2854 struct ieee80211_crypt_data
*new_crypt
;
2856 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2858 new_crypt
= kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
2859 if (new_crypt
== NULL
) {
2863 memset(new_crypt
, 0, sizeof(struct ieee80211_crypt_data
));
2864 new_crypt
->ops
= ops
;
2867 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
2869 if (new_crypt
->priv
== NULL
) {
2871 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
2879 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
2880 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
2881 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
2882 (*crypt
)->priv
) < 0) {
2883 printk("key setting failed\n");
2884 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
2890 if (param
->u
.crypt
.set_tx
) {
2891 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
2892 sec
.active_key
= param
->u
.crypt
.idx
;
2893 sec
.flags
|= SEC_ACTIVE_KEY
;
2895 sec
.flags
&= ~SEC_ACTIVE_KEY
;
2897 if (param
->u
.crypt
.alg
!= NULL
) {
2898 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
2900 param
->u
.crypt
.key_len
);
2901 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
2902 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
2904 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
2905 sec
.flags
|= SEC_LEVEL
;
2906 sec
.level
= SEC_LEVEL_1
;
2907 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
2908 sec
.flags
|= SEC_LEVEL
;
2909 sec
.level
= SEC_LEVEL_2
;
2910 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
2911 sec
.flags
|= SEC_LEVEL
;
2912 sec
.level
= SEC_LEVEL_3
;
2916 if (ieee
->set_security
)
2917 ieee
->set_security(ieee
->dev
, &sec
);
2919 /* Do not reset port if card is in Managed mode since resetting will
2920 * generate new IEEE 802.11 authentication which may end up in looping
2921 * with IEEE 802.1X. If your hardware requires a reset after WEP
2922 * configuration (for example... Prism2), implement the reset_port in
2923 * the callbacks structures used to initialize the 802.11 stack. */
2924 if (ieee
->reset_on_keychange
&&
2925 ieee
->iw_mode
!= IW_MODE_INFRA
&&
2927 ieee
->reset_port(ieee
->dev
)) {
2928 printk("reset_port failed\n");
2929 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
2936 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device
*ieee
, struct iw_point
*p
)
2938 struct ieee_param
*param
;
2941 down(&ieee
->wx_sem
);
2942 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
2944 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
){
2949 param
= memdup_user(p
->pointer
, p
->length
);
2950 if (IS_ERR(param
)) {
2951 ret
= PTR_ERR(param
);
2955 switch (param
->cmd
) {
2957 case IEEE_CMD_SET_WPA_PARAM
:
2958 ret
= ieee80211_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
2959 param
->u
.wpa_param
.value
);
2962 case IEEE_CMD_SET_WPA_IE
:
2963 ret
= ieee80211_wpa_set_wpa_ie(ieee
, param
, p
->length
);
2966 case IEEE_CMD_SET_ENCRYPTION
:
2967 ret
= ieee80211_wpa_set_encryption(ieee
, param
, p
->length
);
2971 ret
= ieee80211_wpa_mlme(ieee
, param
->u
.mlme
.command
,
2972 param
->u
.mlme
.reason_code
);
2976 printk("Unknown WPA supplicant request: %d\n",param
->cmd
);
2981 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
2991 void notify_wx_assoc_event(struct ieee80211_device
*ieee
)
2993 union iwreq_data wrqu
;
2994 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
2995 if (ieee
->state
== IEEE80211_LINKED
)
2996 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
, ETH_ALEN
);
2998 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
2999 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);