1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
4 * Mostly extracted from the rtl8180-sa2400 driver for the
5 * in-kernel generic ieee802.11 stack.
7 * Few lines might be stolen from other part of the ieee80211
8 * stack. Copyright who own it's copyright
10 * WPA code stolen from the ipw2200 driver.
11 * Copyright who own it's copyright.
13 * released under the GPL
17 #include "ieee80211.h"
19 #include <linux/random.h>
20 #include <linux/delay.h>
21 #include <linux/slab.h>
22 #include <linux/version.h>
23 #include <asm/uaccess.h>
26 u8 rsn_authen_cipher_suite
[16][4] = {
27 {0x00,0x0F,0xAC,0x00}, //Use group key, //Reserved
28 {0x00,0x0F,0xAC,0x01}, //WEP-40 //RSNA default
29 {0x00,0x0F,0xAC,0x02}, //TKIP //NONE //{used just as default}
30 {0x00,0x0F,0xAC,0x03}, //WRAP-historical
31 {0x00,0x0F,0xAC,0x04}, //CCMP
32 {0x00,0x0F,0xAC,0x05}, //WEP-104
35 short ieee80211_is_54g(struct ieee80211_network net
)
37 return ((net
.rates_ex_len
> 0) || (net
.rates_len
> 4));
40 short ieee80211_is_shortslot(struct ieee80211_network net
)
42 return (net
.capability
& WLAN_CAPABILITY_SHORT_SLOT
);
45 /* returns the total length needed for pleacing the RATE MFIE
46 * tag and the EXTENDED RATE MFIE tag if needed.
47 * It encludes two bytes per tag for the tag itself and its len
49 unsigned int ieee80211_MFIE_rate_len(struct ieee80211_device
*ieee
)
51 unsigned int rate_len
= 0;
53 if (ieee
->modulation
& IEEE80211_CCK_MODULATION
)
54 rate_len
= IEEE80211_CCK_RATE_LEN
+ 2;
56 if (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)
58 rate_len
+= IEEE80211_OFDM_RATE_LEN
+ 2;
63 /* pleace the MFIE rate, tag to the memory (double) poined.
64 * Then it updates the pointer so that
65 * it points after the new MFIE tag added.
67 void ieee80211_MFIE_Brate(struct ieee80211_device
*ieee
, u8
**tag_p
)
71 if (ieee
->modulation
& IEEE80211_CCK_MODULATION
){
72 *tag
++ = MFIE_TYPE_RATES
;
74 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
75 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
76 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_5MB
;
77 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_11MB
;
80 /* We may add an option for custom rates that specific HW might support */
84 void ieee80211_MFIE_Grate(struct ieee80211_device
*ieee
, u8
**tag_p
)
88 if (ieee
->modulation
& IEEE80211_OFDM_MODULATION
){
90 *tag
++ = MFIE_TYPE_RATES_EX
;
92 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_6MB
;
93 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_9MB
;
94 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_12MB
;
95 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_18MB
;
96 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
97 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_36MB
;
98 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_48MB
;
99 *tag
++ = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_54MB
;
103 /* We may add an option for custom rates that specific HW might support */
108 void ieee80211_WMM_Info(struct ieee80211_device
*ieee
, u8
**tag_p
) {
111 *tag
++ = MFIE_TYPE_GENERIC
; //0
120 if(ieee
->current_network
.wmm_info
& 0x80) {
121 *tag
++ = 0x0f|MAX_SP_Len
;
131 void ieee80211_TURBO_Info(struct ieee80211_device
*ieee
, u8
**tag_p
) {
134 *tag
++ = MFIE_TYPE_GENERIC
; //0
145 printk(KERN_ALERT
"This is enable turbo mode IE process\n");
148 void enqueue_mgmt(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
151 nh
= (ieee
->mgmt_queue_head
+1) % MGMT_QUEUE_NUM
;
154 * if the queue is full but we have newer frames then
155 * just overwrites the oldest.
157 * if (nh == ieee->mgmt_queue_tail)
160 ieee
->mgmt_queue_head
= nh
;
161 ieee
->mgmt_queue_ring
[nh
] = skb
;
166 struct sk_buff
*dequeue_mgmt(struct ieee80211_device
*ieee
)
170 if(ieee
->mgmt_queue_tail
== ieee
->mgmt_queue_head
)
173 ret
= ieee
->mgmt_queue_ring
[ieee
->mgmt_queue_tail
];
175 ieee
->mgmt_queue_tail
=
176 (ieee
->mgmt_queue_tail
+1) % MGMT_QUEUE_NUM
;
181 void init_mgmt_queue(struct ieee80211_device
*ieee
)
183 ieee
->mgmt_queue_tail
= ieee
->mgmt_queue_head
= 0;
187 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
);
189 inline void softmac_mgmt_xmit(struct sk_buff
*skb
, struct ieee80211_device
*ieee
)
192 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
193 struct ieee80211_hdr_3addr
*header
=
194 (struct ieee80211_hdr_3addr
*) skb
->data
;
197 spin_lock_irqsave(&ieee
->lock
, flags
);
199 /* called with 2nd param 0, no mgmt lock required */
200 ieee80211_sta_wakeup(ieee
,0);
203 if(ieee
->queue_stop
){
205 enqueue_mgmt(ieee
,skb
);
207 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4);
209 if (ieee
->seq_ctrl
[0] == 0xFFF)
210 ieee
->seq_ctrl
[0] = 0;
214 /* avoid watchdog triggers */
215 ieee
->dev
->trans_start
= jiffies
;
216 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
219 spin_unlock_irqrestore(&ieee
->lock
, flags
);
221 spin_unlock_irqrestore(&ieee
->lock
, flags
);
222 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags
);
224 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
226 if (ieee
->seq_ctrl
[0] == 0xFFF)
227 ieee
->seq_ctrl
[0] = 0;
231 /* avoid watchdog triggers */
232 ieee
->dev
->trans_start
= jiffies
;
233 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
235 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags
);
240 inline void softmac_ps_mgmt_xmit(struct sk_buff
*skb
, struct ieee80211_device
*ieee
)
243 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
244 struct ieee80211_hdr_3addr
*header
=
245 (struct ieee80211_hdr_3addr
*) skb
->data
;
250 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
252 if (ieee
->seq_ctrl
[0] == 0xFFF)
253 ieee
->seq_ctrl
[0] = 0;
257 /* avoid watchdog triggers */
258 ieee
->dev
->trans_start
= jiffies
;
259 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
263 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
265 if (ieee
->seq_ctrl
[0] == 0xFFF)
266 ieee
->seq_ctrl
[0] = 0;
270 /* avoid watchdog triggers */
271 ieee
->dev
->trans_start
= jiffies
;
272 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
275 // dev_kfree_skb_any(skb);//edit by thomas
277 //by amy for power save
278 inline struct sk_buff
*ieee80211_disassociate_skb(
279 struct ieee80211_network
*beacon
,
280 struct ieee80211_device
*ieee
,
284 struct ieee80211_disassoc_frame
*disass
;
286 skb
= dev_alloc_skb(sizeof(struct ieee80211_disassoc_frame
));
290 disass
= (struct ieee80211_disassoc_frame
*) skb_put(skb
,sizeof(struct ieee80211_disassoc_frame
));
291 disass
->header
.frame_control
= cpu_to_le16(IEEE80211_STYPE_DISASSOC
);
292 disass
->header
.duration_id
= 0;
294 memcpy(disass
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
295 memcpy(disass
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
296 memcpy(disass
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
298 disass
->reasoncode
= asRsn
;
303 struct ieee80211_device
*ieee
,
308 struct ieee80211_network
*beacon
= &ieee
->current_network
;
310 skb
= ieee80211_disassociate_skb(beacon
,ieee
,asRsn
);
312 softmac_mgmt_xmit(skb
, ieee
);
313 //dev_kfree_skb_any(skb);//edit by thomas
317 //by amy for power save
318 inline struct sk_buff
*ieee80211_probe_req(struct ieee80211_device
*ieee
)
320 unsigned int len
,rate_len
;
323 struct ieee80211_probe_request
*req
;
325 len
= ieee
->current_network
.ssid_len
;
327 rate_len
= ieee80211_MFIE_rate_len(ieee
);
329 skb
= dev_alloc_skb(sizeof(struct ieee80211_probe_request
) +
334 req
= (struct ieee80211_probe_request
*) skb_put(skb
,sizeof(struct ieee80211_probe_request
));
335 req
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
336 req
->header
.duration_id
= 0; //FIXME: is this OK ?
338 memset(req
->header
.addr1
, 0xff, ETH_ALEN
);
339 memcpy(req
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
340 memset(req
->header
.addr3
, 0xff, ETH_ALEN
);
342 tag
= (u8
*) skb_put(skb
,len
+2+rate_len
);
344 *tag
++ = MFIE_TYPE_SSID
;
346 memcpy(tag
, ieee
->current_network
.ssid
, len
);
348 ieee80211_MFIE_Brate(ieee
,&tag
);
349 ieee80211_MFIE_Grate(ieee
,&tag
);
354 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
);
356 void ext_ieee80211_send_beacon_wq(struct ieee80211_device
*ieee
)
360 //unsigned long flags;
362 skb
= ieee80211_get_beacon_(ieee
);
365 softmac_mgmt_xmit(skb
, ieee
);
366 ieee
->softmac_stats
.tx_beacons
++;
367 dev_kfree_skb_any(skb
);//edit by thomas
371 //printk(KERN_WARNING "[1] beacon sending!\n");
372 ieee
->beacon_timer
.expires
= jiffies
+
373 (MSECS( ieee
->current_network
.beacon_interval
-5));
375 //spin_lock_irqsave(&ieee->beacon_lock,flags);
376 if(ieee
->beacon_txing
)
377 add_timer(&ieee
->beacon_timer
);
378 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
381 void ieee80211_send_beacon(struct ieee80211_device
*ieee
)
385 //unsigned long flags;
387 skb
= ieee80211_get_beacon_(ieee
);
390 softmac_mgmt_xmit(skb
, ieee
);
391 ieee
->softmac_stats
.tx_beacons
++;
392 dev_kfree_skb_any(skb
);//edit by thomas
395 //printk(KERN_WARNING "[1] beacon sending!\n");
396 ieee
->beacon_timer
.expires
= jiffies
+
397 (MSECS( ieee
->current_network
.beacon_interval
-5));
399 //spin_lock_irqsave(&ieee->beacon_lock,flags);
400 if(ieee
->beacon_txing
)
401 add_timer(&ieee
->beacon_timer
);
402 //spin_unlock_irqrestore(&ieee->beacon_lock,flags);
406 void ieee80211_send_beacon_cb(unsigned long _ieee
)
408 struct ieee80211_device
*ieee
=
409 (struct ieee80211_device
*) _ieee
;
412 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
413 ieee80211_send_beacon(ieee
);
414 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
417 void ieee80211_send_probe(struct ieee80211_device
*ieee
)
421 skb
= ieee80211_probe_req(ieee
);
423 softmac_mgmt_xmit(skb
, ieee
);
424 ieee
->softmac_stats
.tx_probe_rq
++;
425 //dev_kfree_skb_any(skb);//edit by thomas
429 void ieee80211_send_probe_requests(struct ieee80211_device
*ieee
)
431 if (ieee
->active_scan
&& (ieee
->softmac_features
& IEEE_SOFTMAC_PROBERQ
)){
432 ieee80211_send_probe(ieee
);
433 ieee80211_send_probe(ieee
);
437 /* this performs syncro scan blocking the caller until all channels
438 * in the allowed channel map has been checked.
440 void ieee80211_softmac_scan_syncro(struct ieee80211_device
*ieee
)
443 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
444 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
445 down(&ieee
->scan_sem
);
446 // printk("==================> Sync scan\n");
453 if (ch
> MAX_CHANNEL_NUMBER
)
454 goto out
; /* scan completed */
456 }while(!channel_map
[ch
]);
457 /* this function can be called in two situations
458 * 1- We have switched to ad-hoc mode and we are
459 * performing a complete syncro scan before conclude
460 * there are no interesting cell and to create a
461 * new one. In this case the link state is
462 * IEEE80211_NOLINK until we found an interesting cell.
463 * If so the ieee8021_new_net, called by the RX path
464 * will set the state to IEEE80211_LINKED, so we stop
466 * 2- We are linked and the root uses run iwlist scan.
467 * So we switch to IEEE80211_LINKED_SCANNING to remember
468 * that we are still logically linked (not interested in
469 * new network events, despite for updating the net list,
470 * but we are temporarly 'unlinked' as the driver shall
471 * not filter RX frames and the channel is changing.
472 * So the only situation in witch are interested is to check
473 * if the state become LINKED because of the #1 situation
476 if (ieee
->state
== IEEE80211_LINKED
)
479 ieee
->set_chan(ieee
->dev
, ch
);
480 // printk("=====>channel=%d ",ch);
481 if(channel_map
[ch
] == 1)
483 // printk("====send probe request\n");
484 ieee80211_send_probe_requests(ieee
);
486 /* this prevent excessive time wait when we
487 * need to wait for a syncro scan to end..
489 if (ieee
->sync_scan_hurryup
)
493 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME
);
497 ieee
->sync_scan_hurryup
= 0;
499 if(IS_DOT11D_ENABLE(ieee
))
500 DOT11D_ScanComplete(ieee
);
503 void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device
*ieee
)
506 unsigned int watch_dog
= 0;
507 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
508 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
509 down(&ieee
->scan_sem
);
510 ch
= ieee
->current_network
.channel
;
511 // if(ieee->sync_scan_hurryup)
514 // printk("stop scan sync\n");
517 // printk("=======hh===============>ips scan\n");
520 /* this function can be called in two situations
521 * 1- We have switched to ad-hoc mode and we are
522 * performing a complete syncro scan before conclude
523 * there are no interesting cell and to create a
524 * new one. In this case the link state is
525 * IEEE80211_NOLINK until we found an interesting cell.
526 * If so the ieee8021_new_net, called by the RX path
527 * will set the state to IEEE80211_LINKED, so we stop
529 * 2- We are linked and the root uses run iwlist scan.
530 * So we switch to IEEE80211_LINKED_SCANNING to remember
531 * that we are still logically linked (not interested in
532 * new network events, despite for updating the net list,
533 * but we are temporarly 'unlinked' as the driver shall
534 * not filter RX frames and the channel is changing.
535 * So the only situation in witch are interested is to check
536 * if the state become LINKED because of the #1 situation
538 if (ieee
->state
== IEEE80211_LINKED
)
542 if(channel_map
[ieee
->current_network
.channel
] > 0)
544 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
545 // printk("======>channel=%d ",ieee->current_network.channel);
547 if(channel_map
[ieee
->current_network
.channel
] == 1)
549 // printk("====send probe request\n");
550 ieee80211_send_probe_requests(ieee
);
552 /* this prevent excessive time wait when we
553 * need to wait for a syncro scan to end..
555 // if (ieee->sync_scan_hurryup)
558 msleep_interruptible_rtl(IEEE80211_SOFTMAC_SCAN_TIME
);
561 if (watch_dog
++ >= MAX_CHANNEL_NUMBER
)
562 // if (++watch_dog >= 15);//MAX_CHANNEL_NUMBER) //YJ,modified,080630
563 goto out
; /* scan completed */
565 ieee
->current_network
.channel
= (ieee
->current_network
.channel
+ 1)%MAX_CHANNEL_NUMBER
;
566 }while(!channel_map
[ieee
->current_network
.channel
]);
569 //ieee->sync_scan_hurryup = 0;
570 //ieee->set_chan(ieee->dev, ch);
571 //ieee->current_network.channel = ch;
572 ieee
->actscanning
= false;
574 if(IS_DOT11D_ENABLE(ieee
))
575 DOT11D_ScanComplete(ieee
);
578 void ieee80211_softmac_scan_wq(struct work_struct
*work
)
580 struct delayed_work
*dwork
= to_delayed_work(work
);
581 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, softmac_scan_wq
);
582 static short watchdog
= 0;
583 u8 channel_map
[MAX_CHANNEL_NUMBER
+1];
584 memcpy(channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
585 // printk("ieee80211_softmac_scan_wq ENABLE_IPS\n");
586 // printk("in %s\n",__func__);
587 down(&ieee
->scan_sem
);
590 ieee
->current_network
.channel
=
591 (ieee
->current_network
.channel
+ 1) % MAX_CHANNEL_NUMBER
;
592 if (watchdog
++ > MAX_CHANNEL_NUMBER
)
593 goto out
; /* no good chans */
595 }while(!channel_map
[ieee
->current_network
.channel
]);
597 //printk("current_network.channel:%d\n", ieee->current_network.channel);
598 if (ieee
->scanning
== 0 )
600 printk("error out, scanning = 0\n");
603 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
604 if(channel_map
[ieee
->current_network
.channel
] == 1)
605 ieee80211_send_probe_requests(ieee
);
607 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
, IEEE80211_SOFTMAC_SCAN_TIME
);
611 ieee
->actscanning
= false;
616 if(IS_DOT11D_ENABLE(ieee
))
617 DOT11D_ScanComplete(ieee
);
621 void ieee80211_beacons_start(struct ieee80211_device
*ieee
)
625 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
627 ieee
->beacon_txing
= 1;
628 ieee80211_send_beacon(ieee
);
630 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
633 void ieee80211_beacons_stop(struct ieee80211_device
*ieee
)
637 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
639 ieee
->beacon_txing
= 0;
640 del_timer_sync(&ieee
->beacon_timer
);
642 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
647 void ieee80211_stop_send_beacons(struct ieee80211_device
*ieee
)
649 if(ieee
->stop_send_beacons
)
650 ieee
->stop_send_beacons(ieee
->dev
);
651 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
652 ieee80211_beacons_stop(ieee
);
656 void ieee80211_start_send_beacons(struct ieee80211_device
*ieee
)
658 if(ieee
->start_send_beacons
)
659 ieee
->start_send_beacons(ieee
->dev
);
660 if(ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
661 ieee80211_beacons_start(ieee
);
665 void ieee80211_softmac_stop_scan(struct ieee80211_device
*ieee
)
667 // unsigned long flags;
669 //ieee->sync_scan_hurryup = 1;
671 down(&ieee
->scan_sem
);
672 // spin_lock_irqsave(&ieee->lock, flags);
674 if (ieee
->scanning
== 1){
676 //del_timer_sync(&ieee->scan_timer);
677 cancel_delayed_work(&ieee
->softmac_scan_wq
);
680 // spin_unlock_irqrestore(&ieee->lock, flags);
684 void ieee80211_stop_scan(struct ieee80211_device
*ieee
)
686 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
687 ieee80211_softmac_stop_scan(ieee
);
689 ieee
->stop_scan(ieee
->dev
);
692 /* called with ieee->lock held */
693 void ieee80211_rtl_start_scan(struct ieee80211_device
*ieee
)
695 if(IS_DOT11D_ENABLE(ieee
) )
697 if(IS_COUNTRY_IE_VALID(ieee
))
699 RESET_CIE_WATCHDOG(ieee
);
702 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
703 if (ieee
->scanning
== 0)
706 //ieee80211_softmac_scan(ieee);
707 // queue_work(ieee->wq, &ieee->softmac_scan_wq);
708 //care this,1203,2007,by lawrence
710 queue_delayed_work(ieee
->wq
, &ieee
->softmac_scan_wq
,0);
714 ieee
->start_scan(ieee
->dev
);
718 /* called with wx_sem held */
719 void ieee80211_start_scan_syncro(struct ieee80211_device
*ieee
)
721 if(IS_DOT11D_ENABLE(ieee
) )
723 if(IS_COUNTRY_IE_VALID(ieee
))
725 RESET_CIE_WATCHDOG(ieee
);
728 ieee
->sync_scan_hurryup
= 0;
730 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)
731 ieee80211_softmac_scan_syncro(ieee
);
733 ieee
->scan_syncro(ieee
->dev
);
737 inline struct sk_buff
*ieee80211_authentication_req(struct ieee80211_network
*beacon
,
738 struct ieee80211_device
*ieee
, int challengelen
)
741 struct ieee80211_authentication
*auth
;
743 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
) + challengelen
);
745 if (!skb
) return NULL
;
747 auth
= (struct ieee80211_authentication
*)
748 skb_put(skb
, sizeof(struct ieee80211_authentication
));
750 auth
->header
.frame_ctl
= IEEE80211_STYPE_AUTH
;
751 if (challengelen
) auth
->header
.frame_ctl
|= IEEE80211_FCTL_WEP
;
753 auth
->header
.duration_id
= 0x013a; //FIXME
755 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
756 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
757 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
759 auth
->algorithm
= ieee
->open_wep
? WLAN_AUTH_OPEN
: WLAN_AUTH_SHARED_KEY
;
761 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
762 ieee
->associate_seq
++;
764 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
770 static struct sk_buff
* ieee80211_probe_resp(struct ieee80211_device
*ieee
, u8
*dest
)
774 struct ieee80211_probe_response
*beacon_buf
;
777 int atim_len
,erp_len
;
778 struct ieee80211_crypt_data
* crypt
;
780 char *ssid
= ieee
->current_network
.ssid
;
781 int ssid_len
= ieee
->current_network
.ssid_len
;
782 int rate_len
= ieee
->current_network
.rates_len
+2;
783 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
784 int wpa_ie_len
= ieee
->wpa_ie_len
;
785 if(rate_ex_len
> 0) rate_ex_len
+=2;
787 if(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
792 if(ieee80211_is_54g(ieee
->current_network
))
797 beacon_size
= sizeof(struct ieee80211_probe_response
)+
806 skb
= dev_alloc_skb(beacon_size
);
811 beacon_buf
= (struct ieee80211_probe_response
*) skb_put(skb
, beacon_size
);
813 memcpy (beacon_buf
->header
.addr1
, dest
,ETH_ALEN
);
814 memcpy (beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
815 memcpy (beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
817 beacon_buf
->header
.duration_id
= 0; //FIXME
818 beacon_buf
->beacon_interval
=
819 cpu_to_le16(ieee
->current_network
.beacon_interval
);
820 beacon_buf
->capability
=
821 cpu_to_le16(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
);
823 if(ieee
->short_slot
&& (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_SLOT
))
824 cpu_to_le16((beacon_buf
->capability
|= WLAN_CAPABILITY_SHORT_SLOT
));
826 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
828 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
829 ((0 == strcmp(crypt
->ops
->name
, "WEP")) || wpa_ie_len
);
832 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
835 beacon_buf
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
);
837 beacon_buf
->info_element
.id
= MFIE_TYPE_SSID
;
838 beacon_buf
->info_element
.len
= ssid_len
;
840 tag
= (u8
*) beacon_buf
->info_element
.data
;
842 memcpy(tag
, ssid
, ssid_len
);
846 *(tag
++) = MFIE_TYPE_RATES
;
847 *(tag
++) = rate_len
-2;
848 memcpy(tag
,ieee
->current_network
.rates
,rate_len
-2);
851 *(tag
++) = MFIE_TYPE_DS_SET
;
853 *(tag
++) = ieee
->current_network
.channel
;
856 *(tag
++) = MFIE_TYPE_IBSS_SET
;
858 *((u16
*)(tag
)) = cpu_to_le16(ieee
->current_network
.atim_window
);
863 *(tag
++) = MFIE_TYPE_ERP
;
869 *(tag
++) = MFIE_TYPE_RATES_EX
;
870 *(tag
++) = rate_ex_len
-2;
871 memcpy(tag
,ieee
->current_network
.rates_ex
,rate_ex_len
-2);
877 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
878 {//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
879 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
882 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
885 skb
->dev
= ieee
->dev
;
889 struct sk_buff
* ieee80211_assoc_resp(struct ieee80211_device
*ieee
, u8
*dest
)
894 struct ieee80211_crypt_data
* crypt
;
895 struct ieee80211_assoc_response_frame
*assoc
;
898 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
899 int len
= sizeof(struct ieee80211_assoc_response_frame
) + rate_len
;
901 skb
= dev_alloc_skb(len
);
906 assoc
= (struct ieee80211_assoc_response_frame
*)
907 skb_put(skb
,sizeof(struct ieee80211_assoc_response_frame
));
909 assoc
->header
.frame_control
= cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
);
910 memcpy(assoc
->header
.addr1
, dest
,ETH_ALEN
);
911 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
912 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
913 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
914 WLAN_CAPABILITY_BSS
: WLAN_CAPABILITY_IBSS
);
918 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
920 if (ieee
->host_encrypt
)
921 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
924 encrypt
= ( crypt
&& crypt
->ops
);
927 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
930 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
931 if (ieee
->assoc_id
== 0x2007) ieee
->assoc_id
=0;
932 else ieee
->assoc_id
++;
934 tag
= (u8
*) skb_put(skb
, rate_len
);
936 ieee80211_MFIE_Brate(ieee
, &tag
);
937 ieee80211_MFIE_Grate(ieee
, &tag
);
942 struct sk_buff
* ieee80211_auth_resp(struct ieee80211_device
*ieee
,int status
, u8
*dest
)
945 struct ieee80211_authentication
*auth
;
947 skb
= dev_alloc_skb(sizeof(struct ieee80211_authentication
)+1);
952 skb
->len
= sizeof(struct ieee80211_authentication
);
954 auth
= (struct ieee80211_authentication
*)skb
->data
;
956 auth
->status
= cpu_to_le16(status
);
957 auth
->transaction
= cpu_to_le16(2);
958 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
960 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
961 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
962 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
963 auth
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_AUTH
);
969 struct sk_buff
* ieee80211_null_func(struct ieee80211_device
*ieee
,short pwr
)
972 struct ieee80211_hdr_3addr
* hdr
;
974 skb
= dev_alloc_skb(sizeof(struct ieee80211_hdr_3addr
));
979 hdr
= (struct ieee80211_hdr_3addr
*)skb_put(skb
,sizeof(struct ieee80211_hdr_3addr
));
981 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
982 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
983 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
985 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
986 IEEE80211_STYPE_NULLFUNC
| IEEE80211_FCTL_TODS
|
987 (pwr
? IEEE80211_FCTL_PM
:0));
995 void ieee80211_resp_to_assoc_rq(struct ieee80211_device
*ieee
, u8
* dest
)
997 struct sk_buff
*buf
= ieee80211_assoc_resp(ieee
, dest
);
1000 softmac_mgmt_xmit(buf
, ieee
);
1001 dev_kfree_skb_any(buf
);//edit by thomas
1006 void ieee80211_resp_to_auth(struct ieee80211_device
*ieee
, int s
, u8
* dest
)
1008 struct sk_buff
*buf
= ieee80211_auth_resp(ieee
, s
, dest
);
1011 softmac_mgmt_xmit(buf
, ieee
);
1012 dev_kfree_skb_any(buf
);//edit by thomas
1017 void ieee80211_resp_to_probe(struct ieee80211_device
*ieee
, u8
*dest
)
1020 struct sk_buff
*buf
= ieee80211_probe_resp(ieee
, dest
);
1023 softmac_mgmt_xmit(buf
, ieee
);
1024 dev_kfree_skb_any(buf
);//edit by thomas
1029 inline struct sk_buff
*ieee80211_association_req(struct ieee80211_network
*beacon
,struct ieee80211_device
*ieee
)
1031 struct sk_buff
*skb
;
1032 //unsigned long flags;
1034 struct ieee80211_assoc_request_frame
*hdr
;
1036 //short info_addr = 0;
1038 //u16 suite_count = 0;
1039 //u8 suit_select = 0;
1040 unsigned int wpa_len
= beacon
->wpa_ie_len
;
1041 //struct net_device *dev = ieee->dev;
1042 //union iwreq_data wrqu;
1046 // for testing purpose
1047 unsigned int rsn_len
= beacon
->rsn_ie_len
;
1049 unsigned int rsn_len
= beacon
->rsn_ie_len
- 4;
1051 unsigned int rate_len
= ieee80211_MFIE_rate_len(ieee
);
1052 unsigned int wmm_info_len
= beacon
->QoS_Enable
?9:0;
1053 unsigned int turbo_info_len
= beacon
->Turbo_Enable
?9:0;
1055 u8 encry_proto
= ieee
->wpax_type_notify
& 0xff;
1056 //u8 pairwise_type = (ieee->wpax_type_notify >> 8) & 0xff;
1057 //u8 authen_type = (ieee->wpax_type_notify >> 16) & 0xff;
1061 //[0] Notify type of encryption: WPA/WPA2
1062 //[1] pair wise type
1064 if(ieee
->wpax_type_set
) {
1065 if (IEEE_PROTO_WPA
== encry_proto
) {
1067 } else if (IEEE_PROTO_RSN
== encry_proto
) {
1071 len
= sizeof(struct ieee80211_assoc_request_frame
)+
1072 + beacon
->ssid_len
//essid tagged val
1073 + rate_len
//rates tagged val
1079 skb
= dev_alloc_skb(len
);
1084 hdr
= (struct ieee80211_assoc_request_frame
*)
1085 skb_put(skb
, sizeof(struct ieee80211_assoc_request_frame
));
1088 hdr
->header
.frame_control
= IEEE80211_STYPE_ASSOC_REQ
;
1089 hdr
->header
.duration_id
= 37; //FIXME
1090 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1091 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1092 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1093 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);//for HW security, John
1095 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_BSS
);
1096 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1097 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1098 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1099 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1101 if(ieee
->short_slot
)
1102 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT
);
1104 hdr
->listen_interval
= 0xa; //FIXME
1106 hdr
->info_element
.id
= MFIE_TYPE_SSID
;
1108 hdr
->info_element
.len
= beacon
->ssid_len
;
1109 tag
= skb_put(skb
, beacon
->ssid_len
);
1110 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1112 tag
= skb_put(skb
, rate_len
);
1114 ieee80211_MFIE_Brate(ieee
, &tag
);
1115 ieee80211_MFIE_Grate(ieee
, &tag
);
1117 //add rsn==0 condition for ap's mix security mode(wpa+wpa2), john2007.8.9
1118 //choose AES encryption as default algorithm while using mixed mode
1120 tag
= skb_put(skb
,ieee
->wpa_ie_len
);
1121 memcpy(tag
,ieee
->wpa_ie
,ieee
->wpa_ie_len
);
1123 tag
= skb_put(skb
,wmm_info_len
);
1125 ieee80211_WMM_Info(ieee
, &tag
);
1127 tag
= skb_put(skb
,turbo_info_len
);
1128 if(turbo_info_len
) {
1129 ieee80211_TURBO_Info(ieee
, &tag
);
1135 void ieee80211_associate_abort(struct ieee80211_device
*ieee
)
1138 unsigned long flags
;
1139 spin_lock_irqsave(&ieee
->lock
, flags
);
1141 ieee
->associate_seq
++;
1143 /* don't scan, and avoid to have the RX path possibily
1144 * try again to associate. Even do not react to AUTH or
1145 * ASSOC response. Just wait for the retry wq to be scheduled.
1146 * Here we will check if there are good nets to associate
1147 * with, so we retry or just get back to NO_LINK and scanning
1149 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
){
1150 IEEE80211_DEBUG_MGMT("Authentication failed\n");
1151 ieee
->softmac_stats
.no_auth_rs
++;
1153 IEEE80211_DEBUG_MGMT("Association failed\n");
1154 ieee
->softmac_stats
.no_ass_rs
++;
1157 ieee
->state
= IEEE80211_ASSOCIATING_RETRY
;
1159 queue_delayed_work(ieee
->wq
, &ieee
->associate_retry_wq
,IEEE80211_SOFTMAC_ASSOC_RETRY_TIME
);
1161 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1164 void ieee80211_associate_abort_cb(unsigned long dev
)
1166 ieee80211_associate_abort((struct ieee80211_device
*) dev
);
1170 void ieee80211_associate_step1(struct ieee80211_device
*ieee
)
1172 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1173 struct sk_buff
*skb
;
1175 IEEE80211_DEBUG_MGMT("Stopping scan\n");
1176 ieee
->softmac_stats
.tx_auth_rq
++;
1177 skb
=ieee80211_authentication_req(beacon
, ieee
, 0);
1180 ieee80211_associate_abort(ieee
);
1183 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATING
;
1184 IEEE80211_DEBUG_MGMT("Sending authentication request\n");
1185 //printk("---Sending authentication request\n");
1186 softmac_mgmt_xmit(skb
, ieee
);
1187 //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
1188 if(!timer_pending(&ieee
->associate_timer
)){
1189 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1190 add_timer(&ieee
->associate_timer
);
1192 //If call dev_kfree_skb_any,a warning will ocur....
1193 //KERNEL: assertion (!atomic_read(&skb->users)) failed at net/core/dev.c (1708)
1194 //So ... 1204 by lawrence.
1195 //printk("\nIn %s,line %d call kfree skb.",__func__,__LINE__);
1196 //dev_kfree_skb_any(skb);//edit by thomas
1200 void ieee80211_rtl_auth_challenge(struct ieee80211_device
*ieee
, u8
*challenge
, int chlen
)
1203 struct sk_buff
*skb
;
1204 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1205 // int hlen = sizeof(struct ieee80211_authentication);
1206 del_timer_sync(&ieee
->associate_timer
);
1207 ieee
->associate_seq
++;
1208 ieee
->softmac_stats
.tx_auth_rq
++;
1210 skb
= ieee80211_authentication_req(beacon
, ieee
, chlen
+2);
1212 ieee80211_associate_abort(ieee
);
1214 c
= skb_put(skb
, chlen
+2);
1215 *(c
++) = MFIE_TYPE_CHALLENGE
;
1217 memcpy(c
, challenge
, chlen
);
1219 IEEE80211_DEBUG_MGMT("Sending authentication challenge response\n");
1221 ieee80211_encrypt_fragment(ieee
, skb
, sizeof(struct ieee80211_hdr_3addr
));
1223 softmac_mgmt_xmit(skb
, ieee
);
1224 if (!timer_pending(&ieee
->associate_timer
)){
1225 //printk("=========>add timer again, to crash\n");
1226 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1227 add_timer(&ieee
->associate_timer
);
1229 dev_kfree_skb_any(skb
);//edit by thomas
1234 void ieee80211_associate_step2(struct ieee80211_device
*ieee
)
1236 struct sk_buff
* skb
;
1237 struct ieee80211_network
*beacon
= &ieee
->current_network
;
1239 del_timer_sync(&ieee
->associate_timer
);
1241 IEEE80211_DEBUG_MGMT("Sending association request\n");
1242 ieee
->softmac_stats
.tx_ass_rq
++;
1243 skb
=ieee80211_association_req(beacon
, ieee
);
1245 ieee80211_associate_abort(ieee
);
1247 softmac_mgmt_xmit(skb
, ieee
);
1248 if (!timer_pending(&ieee
->associate_timer
)){
1249 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1250 add_timer(&ieee
->associate_timer
);
1252 //dev_kfree_skb_any(skb);//edit by thomas
1256 void ieee80211_associate_complete_wq(struct work_struct
*work
)
1258 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_complete_wq
);
1260 printk(KERN_INFO
"Associated successfully\n");
1261 if(ieee80211_is_54g(ieee
->current_network
) &&
1262 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1265 printk(KERN_INFO
"Using G rates\n");
1268 printk(KERN_INFO
"Using B rates\n");
1270 ieee
->link_change(ieee
->dev
);
1271 notify_wx_assoc_event(ieee
);
1272 if (ieee
->data_hard_resume
)
1273 ieee
->data_hard_resume(ieee
->dev
);
1274 netif_carrier_on(ieee
->dev
);
1277 void ieee80211_associate_complete(struct ieee80211_device
*ieee
)
1280 del_timer_sync(&ieee
->associate_timer
);
1282 for(i
= 0; i
< 6; i
++) {
1283 //ieee->seq_ctrl[i] = 0;
1285 ieee
->state
= IEEE80211_LINKED
;
1286 IEEE80211_DEBUG_MGMT("Successfully associated\n");
1288 queue_work(ieee
->wq
, &ieee
->associate_complete_wq
);
1291 void ieee80211_associate_procedure_wq(struct work_struct
*work
)
1293 struct ieee80211_device
*ieee
= container_of(work
, struct ieee80211_device
, associate_procedure_wq
);
1295 ieee
->sync_scan_hurryup
= 1;
1296 down(&ieee
->wx_sem
);
1298 if (ieee
->data_hard_stop
)
1299 ieee
->data_hard_stop(ieee
->dev
);
1301 ieee80211_stop_scan(ieee
);
1302 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
1304 ieee
->associate_seq
= 1;
1305 ieee80211_associate_step1(ieee
);
1310 inline void ieee80211_softmac_new_net(struct ieee80211_device
*ieee
, struct ieee80211_network
*net
)
1312 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+1];
1313 int tmp_ssid_len
= 0;
1315 short apset
,ssidset
,ssidbroad
,apmatch
,ssidmatch
;
1317 /* we are interested in new new only if we are not associated
1318 * and we are not associating / authenticating
1320 if (ieee
->state
!= IEEE80211_NOLINK
)
1323 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
& WLAN_CAPABILITY_BSS
))
1326 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
& WLAN_CAPABILITY_IBSS
))
1330 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
){
1331 /* if the user specified the AP MAC, we need also the essid
1332 * This could be obtained by beacons or, if the network does not
1333 * broadcast it, it can be put manually.
1335 apset
= ieee
->wap_set
;//(memcmp(ieee->current_network.bssid, zero,ETH_ALEN)!=0 );
1336 ssidset
= ieee
->ssid_set
;//ieee->current_network.ssid[0] != '\0';
1337 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0]== '\0');
1338 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
, ETH_ALEN
)==0);
1340 if(ieee
->current_network
.ssid_len
!= net
->ssid_len
)
1343 ssidmatch
= (0==strncmp(ieee
->current_network
.ssid
, net
->ssid
, net
->ssid_len
));
1345 //printk("cur: %s, %d, net:%s, %d\n", ieee->current_network.ssid, ieee->current_network.ssid_len, net->ssid, net->ssid_len);
1346 //printk("apset=%d apmatch=%d ssidset=%d ssidbroad=%d ssidmatch=%d\n",apset,apmatch,ssidset,ssidbroad,ssidmatch);
1348 if ( /* if the user set the AP check if match.
1349 * if the network does not broadcast essid we check the user supplyed ANY essid
1350 * if the network does broadcast and the user does not set essid it is OK
1351 * if the network does broadcast and the user did set essid chech if essid match
1353 ( apset
&& apmatch
&&
1354 ((ssidset
&& ssidbroad
&& ssidmatch
) || (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
)) ) ||
1355 /* if the ap is not set, check that the user set the bssid
1356 * and the network does bradcast and that those two bssid matches
1358 (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
)
1362 /* if the essid is hidden replace it with the
1363 * essid provided by the user.
1366 strncpy(tmp_ssid
, ieee
->current_network
.ssid
, IW_ESSID_MAX_SIZE
);
1367 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1369 memcpy(&ieee
->current_network
, net
, sizeof(struct ieee80211_network
));
1372 strncpy(ieee
->current_network
.ssid
, tmp_ssid
, IW_ESSID_MAX_SIZE
);
1373 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1375 printk(KERN_INFO
"Linking with %s: channel is %d\n",ieee
->current_network
.ssid
,ieee
->current_network
.channel
);
1377 if (ieee
->iw_mode
== IW_MODE_INFRA
){
1378 ieee
->state
= IEEE80211_ASSOCIATING
;
1379 ieee
->beinretry
= false;
1380 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1382 if(ieee80211_is_54g(ieee
->current_network
) &&
1383 (ieee
->modulation
& IEEE80211_OFDM_MODULATION
)){
1385 printk(KERN_INFO
"Using G rates\n");
1388 printk(KERN_INFO
"Using B rates\n");
1390 ieee
->state
= IEEE80211_LINKED
;
1391 ieee
->beinretry
= false;
1399 void ieee80211_softmac_check_all_nets(struct ieee80211_device
*ieee
)
1401 unsigned long flags
;
1402 struct ieee80211_network
*target
;
1404 spin_lock_irqsave(&ieee
->lock
, flags
);
1405 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1407 /* if the state become different that NOLINK means
1408 * we had found what we are searching for
1411 if (ieee
->state
!= IEEE80211_NOLINK
)
1414 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
))
1415 ieee80211_softmac_new_net(ieee
, target
);
1418 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1423 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1425 struct ieee80211_authentication
*a
;
1427 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1428 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n",skb
->len
);
1432 a
= (struct ieee80211_authentication
*) skb
->data
;
1433 if(skb
->len
> (sizeof(struct ieee80211_authentication
) +3)){
1434 t
= skb
->data
+ sizeof(struct ieee80211_authentication
);
1436 if(*(t
++) == MFIE_TYPE_CHALLENGE
){
1438 *challenge
= kmemdup(t
, *chlen
, GFP_ATOMIC
);
1444 return cpu_to_le16(a
->status
);
1449 int auth_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1451 struct ieee80211_authentication
*a
;
1453 if (skb
->len
< (sizeof(struct ieee80211_authentication
)-sizeof(struct ieee80211_info_element
))){
1454 IEEE80211_DEBUG_MGMT("invalid len in auth request: %d\n",skb
->len
);
1457 a
= (struct ieee80211_authentication
*) skb
->data
;
1459 memcpy(dest
,a
->header
.addr2
, ETH_ALEN
);
1461 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1462 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1464 return WLAN_STATUS_SUCCESS
;
1467 static short probe_rq_parse(struct ieee80211_device
*ieee
, struct sk_buff
*skb
, u8
*src
)
1474 struct ieee80211_hdr_3addr
*header
=
1475 (struct ieee80211_hdr_3addr
*) skb
->data
;
1477 if (skb
->len
< sizeof (struct ieee80211_hdr_3addr
))
1478 return -1; /* corrupted */
1480 memcpy(src
,header
->addr2
, ETH_ALEN
);
1482 skbend
= (u8
*)skb
->data
+ skb
->len
;
1484 tag
= skb
->data
+ sizeof (struct ieee80211_hdr_3addr
);
1486 while (tag
+1 < skbend
){
1492 tag
++; /* point to the len field */
1493 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1494 tag
++; /* point to the next tag */
1497 //IEEE80211DMESG("Card MAC address is "MACSTR, MAC2STR(src));
1498 if (ssidlen
== 0) return 1;
1500 if (!ssid
) return 1; /* ssid not found in tagged param */
1501 return (!strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
));
1505 int assoc_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1507 struct ieee80211_assoc_request_frame
*a
;
1509 if (skb
->len
< (sizeof(struct ieee80211_assoc_request_frame
) -
1510 sizeof(struct ieee80211_info_element
))) {
1512 IEEE80211_DEBUG_MGMT("invalid len in auth request:%d \n", skb
->len
);
1516 a
= (struct ieee80211_assoc_request_frame
*) skb
->data
;
1518 memcpy(dest
,a
->header
.addr2
,ETH_ALEN
);
1523 static inline u16
assoc_parse(struct sk_buff
*skb
, int *aid
)
1525 struct ieee80211_assoc_response_frame
*a
;
1526 if (skb
->len
< sizeof(struct ieee80211_assoc_response_frame
)){
1527 IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1531 a
= (struct ieee80211_assoc_response_frame
*) skb
->data
;
1532 *aid
= le16_to_cpu(a
->aid
) & 0x3fff;
1533 return le16_to_cpu(a
->status
);
1537 ieee80211_rx_probe_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1541 //IEEE80211DMESG("Rx probe");
1542 ieee
->softmac_stats
.rx_probe_rq
++;
1543 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1544 if (probe_rq_parse(ieee
, skb
, dest
)){
1545 //IEEE80211DMESG("Was for me!");
1546 ieee
->softmac_stats
.tx_probe_rs
++;
1547 ieee80211_resp_to_probe(ieee
, dest
);
1552 ieee80211_rx_auth_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1556 //IEEE80211DMESG("Rx probe");
1557 ieee
->softmac_stats
.rx_auth_rq
++;
1559 status
= auth_rq_parse(skb
, dest
);
1561 ieee80211_resp_to_auth(ieee
, status
, dest
);
1563 //DMESG("Dest is "MACSTR, MAC2STR(dest));
1568 ieee80211_rx_assoc_rq(struct ieee80211_device
*ieee
, struct sk_buff
*skb
)
1572 //unsigned long flags;
1574 ieee
->softmac_stats
.rx_ass_rq
++;
1575 if (assoc_rq_parse(skb
,dest
) != -1){
1576 ieee80211_resp_to_assoc_rq(ieee
, dest
);
1579 printk(KERN_INFO
"New client associated: %pM\n", dest
);
1584 void ieee80211_sta_ps_send_null_frame(struct ieee80211_device
*ieee
, short pwr
)
1587 struct sk_buff
*buf
= ieee80211_null_func(ieee
, pwr
);
1590 softmac_ps_mgmt_xmit(buf
, ieee
);
1595 short ieee80211_sta_ps_sleep(struct ieee80211_device
*ieee
, u32
*time_h
, u32
*time_l
)
1600 /*if(ieee->ps == IEEE80211_PS_DISABLED ||
1601 ieee->iw_mode != IW_MODE_INFRA ||
1602 ieee->state != IEEE80211_LINKED)
1606 dtim
= ieee
->current_network
.dtim_data
;
1609 if(!(dtim
& IEEE80211_DTIM_VALID
))
1612 timeout
= ieee
->current_network
.beacon_interval
;
1614 //printk("VALID\n");
1615 ieee
->current_network
.dtim_data
= IEEE80211_DTIM_INVALID
;
1617 if(dtim
& ((IEEE80211_DTIM_UCAST
| IEEE80211_DTIM_MBCAST
)& ieee
->ps
))
1620 if(!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
)))
1623 if(!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
)))
1626 if((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
1627 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
1631 *time_l
= ieee
->current_network
.last_dtim_sta_time
[0]
1632 + MSECS((ieee
->current_network
.beacon_interval
));
1633 //* ieee->current_network.dtim_period));
1634 //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);
1638 *time_h
= ieee
->current_network
.last_dtim_sta_time
[1];
1639 if(time_l
&& *time_l
< ieee
->current_network
.last_dtim_sta_time
[0])
1648 inline void ieee80211_sta_ps(struct ieee80211_device
*ieee
)
1654 unsigned long flags
,flags2
;
1656 spin_lock_irqsave(&ieee
->lock
, flags
);
1658 if((ieee
->ps
== IEEE80211_PS_DISABLED
||
1660 ieee
->iw_mode
!= IW_MODE_INFRA
||
1661 ieee
->state
!= IEEE80211_LINKED
)){
1663 //#warning CHECK_LOCK_HERE
1664 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1666 ieee80211_sta_wakeup(ieee
, 1);
1668 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1671 sleep
= ieee80211_sta_ps_sleep(ieee
,&th
, &tl
);
1672 // printk("===>%s,%d[2 wake, 1 sleep, 0 do nothing], ieee->sta_sleep = %d\n",__func__, sleep,ieee->sta_sleep);
1673 /* 2 wake, 1 sleep, 0 do nothing */
1679 if(ieee
->sta_sleep
== 1)
1680 ieee
->enter_sleep_state(ieee
->dev
,th
,tl
);
1682 else if(ieee
->sta_sleep
== 0){
1683 // printk("send null 1\n");
1684 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1686 if(ieee
->ps_is_queue_empty(ieee
->dev
)){
1689 ieee
->sta_sleep
= 2;
1691 ieee
->ps_request_tx_ack(ieee
->dev
);
1693 ieee80211_sta_ps_send_null_frame(ieee
,1);
1698 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1703 }else if(sleep
== 2){
1704 //#warning CHECK_LOCK_HERE
1705 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1707 // printk("send wakeup packet\n");
1708 ieee80211_sta_wakeup(ieee
,1);
1710 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1714 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1718 void ieee80211_sta_wakeup(struct ieee80211_device
*ieee
, short nl
)
1720 if(ieee
->sta_sleep
== 0){
1722 // printk("Warning: driver is probably failing to report TX ps error\n");
1723 ieee
->ps_request_tx_ack(ieee
->dev
);
1724 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1730 if(ieee
->sta_sleep
== 1)
1731 ieee
->sta_wake_up(ieee
->dev
);
1733 ieee
->sta_sleep
= 0;
1736 ieee
->ps_request_tx_ack(ieee
->dev
);
1737 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1741 void ieee80211_ps_tx_ack(struct ieee80211_device
*ieee
, short success
)
1743 unsigned long flags
,flags2
;
1745 spin_lock_irqsave(&ieee
->lock
, flags
);
1746 if(ieee
->sta_sleep
== 2){
1747 /* Null frame with PS bit set */
1750 // printk("==================> %s::enter sleep state\n",__func__);
1751 ieee
->sta_sleep
= 1;
1752 ieee
->enter_sleep_state(ieee
->dev
,ieee
->ps_th
,ieee
->ps_tl
);
1754 /* if the card report not success we can't be sure the AP
1755 * has not RXed so we can't assume the AP believe us awake
1758 /* 21112005 - tx again null without PS bit if lost */
1761 if((ieee
->sta_sleep
== 0) && !success
){
1762 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
1763 ieee80211_sta_ps_send_null_frame(ieee
, 0);
1764 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
1767 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1771 ieee80211_rx_frame_softmac(struct ieee80211_device
*ieee
, struct sk_buff
*skb
,
1772 struct ieee80211_rx_stats
*rx_stats
, u16 type
,
1775 struct ieee80211_hdr_3addr
*header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
1780 struct ieee80211_assoc_response_frame
*assoc_resp
;
1781 struct ieee80211_info_element
*info_element
;
1783 if(!ieee
->proto_started
)
1786 if(ieee
->sta_sleep
|| (ieee
->ps
!= IEEE80211_PS_DISABLED
&&
1787 ieee
->iw_mode
== IW_MODE_INFRA
&&
1788 ieee
->state
== IEEE80211_LINKED
))
1790 tasklet_schedule(&ieee
->ps_task
);
1792 if (WLAN_FC_GET_STYPE(header
->frame_control
) != IEEE80211_STYPE_PROBE_RESP
&&
1793 WLAN_FC_GET_STYPE(header
->frame_control
) != IEEE80211_STYPE_BEACON
)
1794 ieee
->last_rx_ps_time
= jiffies
;
1796 switch (WLAN_FC_GET_STYPE(header
->frame_control
)) {
1798 case IEEE80211_STYPE_ASSOC_RESP
:
1799 case IEEE80211_STYPE_REASSOC_RESP
:
1801 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1802 WLAN_FC_GET_STYPE(header
->frame_ctl
));
1803 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1804 ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATED
&&
1805 ieee
->iw_mode
== IW_MODE_INFRA
){
1806 if (0 == (errcode
=assoc_parse(skb
, &aid
))){
1809 ieee
->state
=IEEE80211_LINKED
;
1810 ieee
->assoc_id
= aid
;
1811 ieee
->softmac_stats
.rx_ass_ok
++;
1813 //printk(KERN_WARNING "nic_type = %s", (rx_stats->nic_type == 1)?"rtl8187":"rtl8187B");
1814 if(1 == rx_stats
->nic_type
) //card type is 8187
1816 goto associate_complete
;
1818 assoc_resp
= (struct ieee80211_assoc_response_frame
*)skb
->data
;
1819 info_element
= &assoc_resp
->info_element
;
1820 left
= skb
->len
- ((void*)info_element
- (void*)assoc_resp
);
1822 while (left
>= sizeof(struct ieee80211_info_element_hdr
)) {
1823 if (sizeof(struct ieee80211_info_element_hdr
) + info_element
->len
> left
) {
1824 printk(KERN_WARNING
"[re]associate reeponse error!");
1827 switch (info_element
->id
) {
1828 case MFIE_TYPE_GENERIC
:
1829 IEEE80211_DEBUG_SCAN("MFIE_TYPE_GENERIC: %d bytes\n", info_element
->len
);
1830 if (info_element
->len
>= 8 &&
1831 info_element
->data
[0] == 0x00 &&
1832 info_element
->data
[1] == 0x50 &&
1833 info_element
->data
[2] == 0xf2 &&
1834 info_element
->data
[3] == 0x02 &&
1835 info_element
->data
[4] == 0x01) {
1836 // Not care about version at present.
1837 //WMM Parameter Element
1838 memcpy(ieee
->current_network
.wmm_param
,(u8
*)(info_element
->data\
1839 + 8),(info_element
->len
- 8));
1841 if (((ieee
->current_network
.wmm_info
^info_element
->data
[6])& \
1842 0x0f)||(!ieee
->init_wmmparam_flag
)) {
1843 // refresh parameter element for current network
1844 // update the register parameter for hardware
1845 ieee
->init_wmmparam_flag
= 1;
1846 queue_work(ieee
->wq
, &ieee
->wmm_param_update_wq
);
1849 //update info_element for current network
1850 ieee
->current_network
.wmm_info
= info_element
->data
[6];
1854 //nothing to do at present!!!
1858 left
-= sizeof(struct ieee80211_info_element_hdr
) +
1860 info_element
= (struct ieee80211_info_element
*)
1861 &info_element
->data
[info_element
->len
];
1863 if(!ieee
->init_wmmparam_flag
) //legacy AP, reset the AC_xx_param register
1865 queue_work(ieee
->wq
,&ieee
->wmm_param_update_wq
);
1866 ieee
->init_wmmparam_flag
= 1;//indicate AC_xx_param upated since last associate
1869 ieee80211_associate_complete(ieee
);
1871 ieee
->softmac_stats
.rx_ass_err
++;
1872 IEEE80211_DEBUG_MGMT(
1873 "Association response status code 0x%x\n",
1875 ieee80211_associate_abort(ieee
);
1880 case IEEE80211_STYPE_ASSOC_REQ
:
1881 case IEEE80211_STYPE_REASSOC_REQ
:
1883 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1884 ieee
->iw_mode
== IW_MODE_MASTER
)
1886 ieee80211_rx_assoc_rq(ieee
, skb
);
1889 case IEEE80211_STYPE_AUTH
:
1891 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
){
1892 if (ieee
->state
== IEEE80211_ASSOCIATING_AUTHENTICATING
&&
1893 ieee
->iw_mode
== IW_MODE_INFRA
){
1895 IEEE80211_DEBUG_MGMT("Received authentication response");
1897 if (0 == (errcode
=auth_parse(skb
, &challenge
, &chlen
))){
1898 if(ieee
->open_wep
|| !challenge
){
1899 ieee
->state
= IEEE80211_ASSOCIATING_AUTHENTICATED
;
1900 ieee
->softmac_stats
.rx_auth_rs_ok
++;
1902 ieee80211_associate_step2(ieee
);
1904 ieee80211_rtl_auth_challenge(ieee
, challenge
, chlen
);
1907 ieee
->softmac_stats
.rx_auth_rs_err
++;
1908 IEEE80211_DEBUG_MGMT("Authentication respose status code 0x%x",errcode
);
1909 ieee80211_associate_abort(ieee
);
1912 }else if (ieee
->iw_mode
== IW_MODE_MASTER
){
1913 ieee80211_rx_auth_rq(ieee
, skb
);
1918 case IEEE80211_STYPE_PROBE_REQ
:
1920 if ((ieee
->softmac_features
& IEEE_SOFTMAC_PROBERS
) &&
1921 ((ieee
->iw_mode
== IW_MODE_ADHOC
||
1922 ieee
->iw_mode
== IW_MODE_MASTER
) &&
1923 ieee
->state
== IEEE80211_LINKED
))
1925 ieee80211_rx_probe_rq(ieee
, skb
);
1928 case IEEE80211_STYPE_DISASSOC
:
1929 case IEEE80211_STYPE_DEAUTH
:
1930 /* FIXME for now repeat all the association procedure
1931 * both for disassociation and deauthentication
1933 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
1934 (ieee
->state
== IEEE80211_LINKED
) &&
1935 (ieee
->iw_mode
== IW_MODE_INFRA
) &&
1936 (!memcmp(header
->addr2
,ieee
->current_network
.bssid
,ETH_ALEN
))){
1937 ieee
->state
= IEEE80211_ASSOCIATING
;
1938 ieee
->softmac_stats
.reassoc
++;
1940 //notify_wx_assoc_event(ieee); //YJ,del,080828, do not notify os here
1941 queue_work(ieee
->wq
, &ieee
->associate_procedure_wq
);
1951 //dev_kfree_skb_any(skb);
1957 /* following are for a simpler TX queue management.
1958 * Instead of using netif_[stop/wake]_queue the driver
1959 * will uses these two function (plus a reset one), that
1960 * will internally uses the kernel netif_* and takes
1961 * care of the ieee802.11 fragmentation.
1962 * So the driver receives a fragment per time and might
1963 * call the stop function when it want without take care
1964 * to have enough room to TX an entire packet.
1965 * This might be useful if each fragment need it's own
1966 * descriptor, thus just keep a total free memory > than
1967 * the max fragmentation threshold is not enough.. If the
1968 * ieee802.11 stack passed a TXB struct then you needed
1969 * to keep N free descriptors where
1970 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
1971 * In this way you need just one and the 802.11 stack
1972 * will take care of buffering fragments and pass them to
1973 * to the driver later, when it wakes the queue.
1976 void ieee80211_softmac_xmit(struct ieee80211_txb
*txb
, struct ieee80211_device
*ieee
)
1980 unsigned long flags
;
1983 spin_lock_irqsave(&ieee
->lock
,flags
);
1985 /* called with 2nd parm 0, no tx mgmt lock required */
1986 ieee80211_sta_wakeup(ieee
,0);
1988 for(i
= 0; i
< txb
->nr_frags
; i
++) {
1990 if (ieee
->queue_stop
){
1991 ieee
->tx_pending
.txb
= txb
;
1992 ieee
->tx_pending
.frag
= i
;
1995 ieee
->softmac_data_hard_start_xmit(
1997 ieee
->dev
,ieee
->rate
);
1998 //(i+1)<txb->nr_frags);
1999 ieee
->stats
.tx_packets
++;
2000 ieee
->stats
.tx_bytes
+= txb
->fragments
[i
]->len
;
2001 ieee
->dev
->trans_start
= jiffies
;
2005 ieee80211_txb_free(txb
);
2008 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2012 /* called with ieee->lock acquired */
2013 void ieee80211_resume_tx(struct ieee80211_device
*ieee
)
2016 for(i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
; i
++) {
2018 if (ieee
->queue_stop
){
2019 ieee
->tx_pending
.frag
= i
;
2023 ieee
->softmac_data_hard_start_xmit(
2024 ieee
->tx_pending
.txb
->fragments
[i
],
2025 ieee
->dev
,ieee
->rate
);
2026 //(i+1)<ieee->tx_pending.txb->nr_frags);
2027 ieee
->stats
.tx_packets
++;
2028 ieee
->dev
->trans_start
= jiffies
;
2033 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2034 ieee
->tx_pending
.txb
= NULL
;
2038 void ieee80211_reset_queue(struct ieee80211_device
*ieee
)
2040 unsigned long flags
;
2042 spin_lock_irqsave(&ieee
->lock
,flags
);
2043 init_mgmt_queue(ieee
);
2044 if (ieee
->tx_pending
.txb
){
2045 ieee80211_txb_free(ieee
->tx_pending
.txb
);
2046 ieee
->tx_pending
.txb
= NULL
;
2048 ieee
->queue_stop
= 0;
2049 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2053 void ieee80211_rtl_wake_queue(struct ieee80211_device
*ieee
)
2056 unsigned long flags
;
2057 struct sk_buff
*skb
;
2058 struct ieee80211_hdr_3addr
*header
;
2060 spin_lock_irqsave(&ieee
->lock
,flags
);
2061 if (! ieee
->queue_stop
) goto exit
;
2063 ieee
->queue_stop
= 0;
2065 if(ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
){
2066 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))){
2068 header
= (struct ieee80211_hdr_3addr
*) skb
->data
;
2070 header
->seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2072 if (ieee
->seq_ctrl
[0] == 0xFFF)
2073 ieee
->seq_ctrl
[0] = 0;
2075 ieee
->seq_ctrl
[0]++;
2077 //printk(KERN_ALERT "ieee80211_wake_queue \n");
2078 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
2079 dev_kfree_skb_any(skb
);//edit by thomas
2082 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2083 ieee80211_resume_tx(ieee
);
2085 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)){
2086 ieee
->softmac_stats
.swtxawake
++;
2087 netif_wake_queue(ieee
->dev
);
2091 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2095 void ieee80211_rtl_stop_queue(struct ieee80211_device
*ieee
)
2097 //unsigned long flags;
2098 //spin_lock_irqsave(&ieee->lock,flags);
2100 if (! netif_queue_stopped(ieee
->dev
)){
2101 netif_stop_queue(ieee
->dev
);
2102 ieee
->softmac_stats
.swtxstop
++;
2104 ieee
->queue_stop
= 1;
2105 //spin_unlock_irqrestore(&ieee->lock,flags);
2110 inline void ieee80211_randomize_cell(struct ieee80211_device
*ieee
)
2113 get_random_bytes(ieee
->current_network
.bssid
, ETH_ALEN
);
2115 /* an IBSS cell address must have the two less significant
2116 * bits of the first byte = 2
2118 ieee
->current_network
.bssid
[0] &= ~0x01;
2119 ieee
->current_network
.bssid
[0] |= 0x02;
2122 /* called in user context only */
2123 void ieee80211_start_master_bss(struct ieee80211_device
*ieee
)
2127 if (ieee
->current_network
.ssid_len
== 0){
2128 strncpy(ieee
->current_network
.ssid
,
2129 IEEE80211_DEFAULT_TX_ESSID
,
2132 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2136 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2138 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2139 ieee
->state
= IEEE80211_LINKED
;
2140 ieee
->link_change(ieee
->dev
);
2141 notify_wx_assoc_event(ieee
);
2143 if (ieee
->data_hard_resume
)
2144 ieee
->data_hard_resume(ieee
->dev
);
2146 netif_carrier_on(ieee
->dev
);
2149 void ieee80211_start_monitor_mode(struct ieee80211_device
*ieee
)
2153 if (ieee
->data_hard_resume
)
2154 ieee
->data_hard_resume(ieee
->dev
);
2156 netif_carrier_on(ieee
->dev
);
2160 void ieee80211_start_ibss_wq(struct work_struct
*work
)
2162 struct delayed_work
*dwork
= to_delayed_work(work
);
2163 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, start_ibss_wq
);
2165 /* iwconfig mode ad-hoc will schedule this and return
2166 * on the other hand this will block further iwconfig SET
2167 * operations because of the wx_sem hold.
2168 * Anyway some most set operations set a flag to speed-up
2169 * (abort) this wq (when syncro scanning) before sleeping
2173 down(&ieee
->wx_sem
);
2176 if (ieee
->current_network
.ssid_len
== 0){
2177 strcpy(ieee
->current_network
.ssid
,IEEE80211_DEFAULT_TX_ESSID
);
2178 ieee
->current_network
.ssid_len
= strlen(IEEE80211_DEFAULT_TX_ESSID
);
2182 /* check if we have this cell in our network list */
2183 ieee80211_softmac_check_all_nets(ieee
);
2185 if(ieee
->state
== IEEE80211_NOLINK
)
2186 ieee
->current_network
.channel
= 10;
2187 /* if not then the state is not linked. Maybe the user swithced to
2188 * ad-hoc mode just after being in monitor mode, or just after
2189 * being very few time in managed mode (so the card have had no
2190 * time to scan all the chans..) or we have just run up the iface
2191 * after setting ad-hoc mode. So we have to give another try..
2192 * Here, in ibss mode, should be safe to do this without extra care
2193 * (in bss mode we had to make sure no-one tryed to associate when
2194 * we had just checked the ieee->state and we was going to start the
2195 * scan) beacause in ibss mode the ieee80211_new_net function, when
2196 * finds a good net, just set the ieee->state to IEEE80211_LINKED,
2197 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2198 * scan, that will stop at the first round because it sees the state
2201 if (ieee
->state
== IEEE80211_NOLINK
)
2202 ieee80211_start_scan_syncro(ieee
);
2204 /* the network definitively is not here.. create a new cell */
2205 if (ieee
->state
== IEEE80211_NOLINK
){
2206 printk("creating new IBSS cell\n");
2208 ieee80211_randomize_cell(ieee
);
2210 if(ieee
->modulation
& IEEE80211_CCK_MODULATION
){
2212 ieee
->current_network
.rates_len
= 4;
2214 ieee
->current_network
.rates
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
2215 ieee
->current_network
.rates
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
2216 ieee
->current_network
.rates
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_5MB
;
2217 ieee
->current_network
.rates
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_11MB
;
2220 ieee
->current_network
.rates_len
= 0;
2222 if(ieee
->modulation
& IEEE80211_OFDM_MODULATION
){
2223 ieee
->current_network
.rates_ex_len
= 8;
2225 ieee
->current_network
.rates_ex
[0] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_6MB
;
2226 ieee
->current_network
.rates_ex
[1] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_9MB
;
2227 ieee
->current_network
.rates_ex
[2] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_12MB
;
2228 ieee
->current_network
.rates_ex
[3] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_18MB
;
2229 ieee
->current_network
.rates_ex
[4] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_24MB
;
2230 ieee
->current_network
.rates_ex
[5] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_36MB
;
2231 ieee
->current_network
.rates_ex
[6] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_48MB
;
2232 ieee
->current_network
.rates_ex
[7] = IEEE80211_BASIC_RATE_MASK
| IEEE80211_OFDM_RATE_54MB
;
2236 ieee
->current_network
.rates_ex_len
= 0;
2240 // By default, WMM function will be disabled in IBSS mode
2241 ieee
->current_network
.QoS_Enable
= 0;
2243 ieee
->current_network
.atim_window
= 0;
2244 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2245 if(ieee
->short_slot
)
2246 ieee
->current_network
.capability
|= WLAN_CAPABILITY_SHORT_SLOT
;
2250 ieee
->state
= IEEE80211_LINKED
;
2251 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2252 ieee
->link_change(ieee
->dev
);
2254 notify_wx_assoc_event(ieee
);
2256 ieee80211_start_send_beacons(ieee
);
2257 printk(KERN_WARNING
"after sending beacon packet!\n");
2259 if (ieee
->data_hard_resume
)
2260 ieee
->data_hard_resume(ieee
->dev
);
2262 netif_carrier_on(ieee
->dev
);
2266 inline void ieee80211_start_ibss(struct ieee80211_device
*ieee
)
2268 queue_delayed_work(ieee
->wq
, &ieee
->start_ibss_wq
, 100);
2271 /* this is called only in user context, with wx_sem held */
2272 void ieee80211_start_bss(struct ieee80211_device
*ieee
)
2274 unsigned long flags
;
2276 // Ref: 802.11d 11.1.3.3
2277 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
2279 if(IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
))
2281 if(! ieee
->bGlobalDomain
)
2286 /* check if we have already found the net we
2287 * are interested in (if any).
2288 * if not (we are disassociated and we are not
2289 * in associating / authenticating phase) start the background scanning.
2291 ieee80211_softmac_check_all_nets(ieee
);
2293 /* ensure no-one start an associating process (thus setting
2294 * the ieee->state to ieee80211_ASSOCIATING) while we
2295 * have just cheked it and we are going to enable scan.
2296 * The ieee80211_new_net function is always called with
2297 * lock held (from both ieee80211_softmac_check_all_nets and
2298 * the rx path), so we cannot be in the middle of such function
2300 spin_lock_irqsave(&ieee
->lock
, flags
);
2303 // printk("start bss ENABLE_IPS\n");
2305 if (ieee
->state
== IEEE80211_NOLINK
){
2306 ieee
->actscanning
= true;
2307 ieee80211_rtl_start_scan(ieee
);
2310 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2313 /* called only in userspace context */
2314 void ieee80211_disassociate(struct ieee80211_device
*ieee
)
2316 netif_carrier_off(ieee
->dev
);
2318 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2319 ieee80211_reset_queue(ieee
);
2321 if (ieee
->data_hard_stop
)
2322 ieee
->data_hard_stop(ieee
->dev
);
2324 if(IS_DOT11D_ENABLE(ieee
))
2327 ieee
->link_change(ieee
->dev
);
2328 if (ieee
->state
== IEEE80211_LINKED
)
2329 notify_wx_assoc_event(ieee
);
2330 ieee
->state
= IEEE80211_NOLINK
;
2333 void ieee80211_associate_retry_wq(struct work_struct
*work
)
2335 struct delayed_work
*dwork
= to_delayed_work(work
);
2336 struct ieee80211_device
*ieee
= container_of(dwork
, struct ieee80211_device
, associate_retry_wq
);
2337 unsigned long flags
;
2338 down(&ieee
->wx_sem
);
2339 if(!ieee
->proto_started
)
2341 if(ieee
->state
!= IEEE80211_ASSOCIATING_RETRY
)
2343 /* until we do not set the state to IEEE80211_NOLINK
2344 * there are no possibility to have someone else trying
2345 * to start an association procdure (we get here with
2346 * ieee->state = IEEE80211_ASSOCIATING).
2347 * When we set the state to IEEE80211_NOLINK it is possible
2348 * that the RX path run an attempt to associate, but
2349 * both ieee80211_softmac_check_all_nets and the
2350 * RX path works with ieee->lock held so there are no
2351 * problems. If we are still disassociated then start a scan.
2352 * the lock here is necessary to ensure no one try to start
2353 * an association procedure when we have just checked the
2354 * state and we are going to start the scan.
2356 ieee
->state
= IEEE80211_NOLINK
;
2357 ieee
->beinretry
= true;
2358 ieee80211_softmac_check_all_nets(ieee
);
2360 spin_lock_irqsave(&ieee
->lock
, flags
);
2362 if(ieee
->state
== IEEE80211_NOLINK
){
2363 ieee
->beinretry
= false;
2364 ieee
->actscanning
= true;
2365 ieee80211_rtl_start_scan(ieee
);
2367 //YJ,add,080828, notify os here
2368 if(ieee
->state
== IEEE80211_NOLINK
)
2370 notify_wx_assoc_event(ieee
);
2373 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2379 struct sk_buff
*ieee80211_get_beacon_(struct ieee80211_device
*ieee
)
2381 u8 broadcast_addr
[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2383 struct sk_buff
*skb
= NULL
;
2384 struct ieee80211_probe_response
*b
;
2386 skb
= ieee80211_probe_resp(ieee
, broadcast_addr
);
2390 b
= (struct ieee80211_probe_response
*) skb
->data
;
2391 b
->header
.frame_ctl
= cpu_to_le16(IEEE80211_STYPE_BEACON
);
2397 struct sk_buff
*ieee80211_get_beacon(struct ieee80211_device
*ieee
)
2399 struct sk_buff
*skb
;
2400 struct ieee80211_probe_response
*b
;
2402 skb
= ieee80211_get_beacon_(ieee
);
2406 b
= (struct ieee80211_probe_response
*) skb
->data
;
2407 b
->header
.seq_ctrl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2409 if (ieee
->seq_ctrl
[0] == 0xFFF)
2410 ieee
->seq_ctrl
[0] = 0;
2412 ieee
->seq_ctrl
[0]++;
2417 void ieee80211_softmac_stop_protocol(struct ieee80211_device
*ieee
)
2419 ieee
->sync_scan_hurryup
= 1;
2420 down(&ieee
->wx_sem
);
2421 ieee80211_stop_protocol(ieee
);
2426 void ieee80211_stop_protocol(struct ieee80211_device
*ieee
)
2428 if (!ieee
->proto_started
)
2431 ieee
->proto_started
= 0;
2433 ieee80211_stop_send_beacons(ieee
);
2434 if((ieee
->iw_mode
== IW_MODE_INFRA
)&&(ieee
->state
== IEEE80211_LINKED
)) {
2435 SendDisassociation(ieee
,NULL
,WLAN_REASON_DISASSOC_STA_HAS_LEFT
);
2437 del_timer_sync(&ieee
->associate_timer
);
2438 cancel_delayed_work(&ieee
->associate_retry_wq
);
2439 cancel_delayed_work(&ieee
->start_ibss_wq
);
2440 ieee80211_stop_scan(ieee
);
2442 ieee80211_disassociate(ieee
);
2445 void ieee80211_softmac_start_protocol(struct ieee80211_device
*ieee
)
2447 ieee
->sync_scan_hurryup
= 0;
2448 down(&ieee
->wx_sem
);
2449 ieee80211_start_protocol(ieee
);
2453 void ieee80211_start_protocol(struct ieee80211_device
*ieee
)
2458 if (ieee
->proto_started
)
2461 ieee
->proto_started
= 1;
2463 if (ieee
->current_network
.channel
== 0){
2466 if (ch
> MAX_CHANNEL_NUMBER
)
2467 return; /* no channel found */
2469 }while(!GET_DOT11D_INFO(ieee
)->channel_map
[ch
]);
2471 ieee
->current_network
.channel
= ch
;
2474 if (ieee
->current_network
.beacon_interval
== 0)
2475 ieee
->current_network
.beacon_interval
= 100;
2476 ieee
->set_chan(ieee
->dev
,ieee
->current_network
.channel
);
2478 for(i
= 0; i
< 17; i
++) {
2479 ieee
->last_rxseq_num
[i
] = -1;
2480 ieee
->last_rxfrag_num
[i
] = -1;
2481 ieee
->last_packet_time
[i
] = 0;
2484 ieee
->init_wmmparam_flag
= 0;//reinitialize AC_xx_PARAM registers.
2487 /* if the user set the MAC of the ad-hoc cell and then
2488 * switch to managed mode, shall we make sure that association
2489 * attempts does not fail just because the user provide the essid
2490 * and the nic is still checking for the AP MAC ??
2492 switch (ieee
->iw_mode
) {
2494 ieee
->iw_mode
= IW_MODE_INFRA
;
2495 //not set break here intentionly
2497 ieee80211_start_bss(ieee
);
2501 ieee80211_start_ibss(ieee
);
2504 case IW_MODE_MASTER
:
2505 ieee80211_start_master_bss(ieee
);
2508 case IW_MODE_MONITOR
:
2509 ieee80211_start_monitor_mode(ieee
);
2513 ieee
->iw_mode
= IW_MODE_INFRA
;
2514 ieee80211_start_bss(ieee
);
2520 #define DRV_NAME "Ieee80211"
2521 void ieee80211_softmac_init(struct ieee80211_device
*ieee
)
2524 memset(&ieee
->current_network
, 0, sizeof(struct ieee80211_network
));
2526 ieee
->state
= IEEE80211_NOLINK
;
2527 ieee
->sync_scan_hurryup
= 0;
2528 for(i
= 0; i
< 5; i
++) {
2529 ieee
->seq_ctrl
[i
] = 0;
2533 ieee
->queue_stop
= 0;
2535 ieee
->softmac_features
= 0; //so IEEE2100-like driver are happy
2538 ieee
->proto_started
= 0;
2539 ieee
->basic_rate
= IEEE80211_DEFAULT_BASIC_RATE
;
2542 ieee
->ps
= IEEE80211_PS_MBCAST
|IEEE80211_PS_UNICAST
;
2544 // ieee->ps = IEEE80211_PS_DISABLED;
2546 ieee
->sta_sleep
= 0;
2548 ieee
->bInactivePs
= false;
2549 ieee
->actscanning
= false;
2550 ieee
->ListenInterval
= 2;
2551 ieee
->NumRxDataInPeriod
= 0; //YJ,add,080828
2552 ieee
->NumRxBcnInPeriod
= 0; //YJ,add,080828
2553 ieee
->NumRxOkTotal
= 0;//+by amy 080312
2554 ieee
->NumRxUnicast
= 0;//YJ,add,080828,for keep alive
2555 ieee
->beinretry
= false;
2556 ieee
->bHwRadioOff
= false;
2559 init_mgmt_queue(ieee
);
2561 ieee
->tx_pending
.txb
= NULL
;
2563 init_timer(&ieee
->associate_timer
);
2564 ieee
->associate_timer
.data
= (unsigned long)ieee
;
2565 ieee
->associate_timer
.function
= ieee80211_associate_abort_cb
;
2567 init_timer(&ieee
->beacon_timer
);
2568 ieee
->beacon_timer
.data
= (unsigned long) ieee
;
2569 ieee
->beacon_timer
.function
= ieee80211_send_beacon_cb
;
2571 #ifdef PF_SYNCTHREAD
2572 ieee
->wq
= create_workqueue(DRV_NAME
,0);
2574 ieee
->wq
= create_workqueue(DRV_NAME
);
2576 INIT_DELAYED_WORK(&ieee
->start_ibss_wq
,(void*) ieee80211_start_ibss_wq
);
2577 INIT_WORK(&ieee
->associate_complete_wq
,(void*) ieee80211_associate_complete_wq
);
2578 INIT_WORK(&ieee
->associate_procedure_wq
,(void*) ieee80211_associate_procedure_wq
);
2579 INIT_DELAYED_WORK(&ieee
->softmac_scan_wq
,(void*) ieee80211_softmac_scan_wq
);
2580 INIT_DELAYED_WORK(&ieee
->associate_retry_wq
,(void*) ieee80211_associate_retry_wq
);
2581 INIT_WORK(&ieee
->wx_sync_scan_wq
,(void*) ieee80211_wx_sync_scan_wq
);
2582 // INIT_WORK(&ieee->watch_dog_wq,(void*) ieee80211_watch_dog_wq);
2584 sema_init(&ieee
->wx_sem
, 1);
2585 sema_init(&ieee
->scan_sem
, 1);
2587 spin_lock_init(&ieee
->mgmt_tx_lock
);
2588 spin_lock_init(&ieee
->beacon_lock
);
2590 tasklet_init(&ieee
->ps_task
,
2591 (void(*)(unsigned long)) ieee80211_sta_ps
,
2592 (unsigned long)ieee
);
2593 ieee
->pDot11dInfo
= kmalloc(sizeof(RT_DOT11D_INFO
), GFP_ATOMIC
);
2596 void ieee80211_softmac_free(struct ieee80211_device
*ieee
)
2598 down(&ieee
->wx_sem
);
2600 del_timer_sync(&ieee
->associate_timer
);
2601 cancel_delayed_work(&ieee
->associate_retry_wq
);
2604 //add for RF power on power of by lizhaoming 080512
2605 cancel_delayed_work(&ieee
->GPIOChangeRFWorkItem
);
2607 destroy_workqueue(ieee
->wq
);
2608 kfree(ieee
->pDot11dInfo
);
2612 /********************************************************
2613 * Start of WPA code. *
2614 * this is stolen from the ipw2200 driver *
2615 ********************************************************/
2618 static int ieee80211_wpa_enable(struct ieee80211_device
*ieee
, int value
)
2620 /* This is called when wpa_supplicant loads and closes the driver
2622 printk("%s WPA\n",value
? "enabling" : "disabling");
2623 ieee
->wpa_enabled
= value
;
2628 void ieee80211_wpa_assoc_frame(struct ieee80211_device
*ieee
, char *wpa_ie
, int wpa_ie_len
)
2630 /* make sure WPA is enabled */
2631 ieee80211_wpa_enable(ieee
, 1);
2633 ieee80211_disassociate(ieee
);
2637 static int ieee80211_wpa_mlme(struct ieee80211_device
*ieee
, int command
, int reason
)
2643 case IEEE_MLME_STA_DEAUTH
:
2647 case IEEE_MLME_STA_DISASSOC
:
2648 ieee80211_disassociate(ieee
);
2652 printk("Unknown MLME request: %d\n", command
);
2660 static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device
*ieee
,
2661 struct ieee_param
*param
, int plen
)
2665 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
2666 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
2669 if (param
->u
.wpa_ie
.len
) {
2670 buf
= kmemdup(param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
,
2675 kfree(ieee
->wpa_ie
);
2677 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
2679 kfree(ieee
->wpa_ie
);
2680 ieee
->wpa_ie
= NULL
;
2681 ieee
->wpa_ie_len
= 0;
2684 ieee80211_wpa_assoc_frame(ieee
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
2688 #define AUTH_ALG_OPEN_SYSTEM 0x1
2689 #define AUTH_ALG_SHARED_KEY 0x2
2691 static int ieee80211_wpa_set_auth_algs(struct ieee80211_device
*ieee
, int value
)
2694 struct ieee80211_security sec
= {
2695 .flags
= SEC_AUTH_MODE
,
2699 if (value
& AUTH_ALG_SHARED_KEY
) {
2700 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
2703 sec
.auth_mode
= WLAN_AUTH_OPEN
;
2707 if (ieee
->set_security
)
2708 ieee
->set_security(ieee
->dev
, &sec
);
2715 static int ieee80211_wpa_set_param(struct ieee80211_device
*ieee
, u8 name
, u32 value
)
2718 unsigned long flags
;
2721 case IEEE_PARAM_WPA_ENABLED
:
2722 ret
= ieee80211_wpa_enable(ieee
, value
);
2725 case IEEE_PARAM_TKIP_COUNTERMEASURES
:
2726 ieee
->tkip_countermeasures
=value
;
2729 case IEEE_PARAM_DROP_UNENCRYPTED
: {
2732 * wpa_supplicant calls set_wpa_enabled when the driver
2733 * is loaded and unloaded, regardless of if WPA is being
2734 * used. No other calls are made which can be used to
2735 * determine if encryption will be used or not prior to
2736 * association being expected. If encryption is not being
2737 * used, drop_unencrypted is set to false, else true -- we
2738 * can use this to determine if the CAP_PRIVACY_ON bit should
2741 struct ieee80211_security sec
= {
2742 .flags
= SEC_ENABLED
,
2745 ieee
->drop_unencrypted
= value
;
2746 /* We only change SEC_LEVEL for open mode. Others
2747 * are set by ipw_wpa_set_encryption.
2750 sec
.flags
|= SEC_LEVEL
;
2751 sec
.level
= SEC_LEVEL_0
;
2754 sec
.flags
|= SEC_LEVEL
;
2755 sec
.level
= SEC_LEVEL_1
;
2757 if (ieee
->set_security
)
2758 ieee
->set_security(ieee
->dev
, &sec
);
2762 case IEEE_PARAM_PRIVACY_INVOKED
:
2763 ieee
->privacy_invoked
=value
;
2766 case IEEE_PARAM_AUTH_ALGS
:
2767 ret
= ieee80211_wpa_set_auth_algs(ieee
, value
);
2770 case IEEE_PARAM_IEEE_802_1X
:
2771 ieee
->ieee802_1x
=value
;
2773 case IEEE_PARAM_WPAX_SELECT
:
2774 // added for WPA2 mixed mode
2775 //printk(KERN_WARNING "------------------------>wpax value = %x\n", value);
2776 spin_lock_irqsave(&ieee
->wpax_suitlist_lock
,flags
);
2777 ieee
->wpax_type_set
= 1;
2778 ieee
->wpax_type_notify
= value
;
2779 spin_unlock_irqrestore(&ieee
->wpax_suitlist_lock
,flags
);
2783 printk("Unknown WPA param: %d\n",name
);
2790 /* implementation borrowed from hostap driver */
2792 static int ieee80211_wpa_set_encryption(struct ieee80211_device
*ieee
,
2793 struct ieee_param
*param
, int param_len
)
2797 struct ieee80211_crypto_ops
*ops
;
2798 struct ieee80211_crypt_data
**crypt
;
2800 struct ieee80211_security sec
= {
2804 param
->u
.crypt
.err
= 0;
2805 param
->u
.crypt
.alg
[IEEE_CRYPT_ALG_NAME_LEN
- 1] = '\0';
2808 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
2809 param
->u
.crypt
.key_len
) {
2810 printk("Len mismatch %d, %d\n", param_len
,
2811 param
->u
.crypt
.key_len
);
2814 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
2815 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
2816 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
2817 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
2819 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
2824 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
2829 sec
.level
= SEC_LEVEL_0
;
2830 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
2831 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2838 sec
.flags
|= SEC_ENABLED
;
2840 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
2841 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
2842 strcmp(param
->u
.crypt
.alg
, "TKIP"))
2843 goto skip_host_crypt
;
2845 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2846 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0)
2847 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2848 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0)
2849 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2850 else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0)
2851 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
2853 printk("unknown crypto alg '%s'\n", param
->u
.crypt
.alg
);
2854 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
2859 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
2860 struct ieee80211_crypt_data
*new_crypt
;
2862 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
2864 new_crypt
= kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
2865 if (new_crypt
== NULL
) {
2869 memset(new_crypt
, 0, sizeof(struct ieee80211_crypt_data
));
2870 new_crypt
->ops
= ops
;
2873 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
2875 if (new_crypt
->priv
== NULL
) {
2877 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
2885 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
2886 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
2887 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
2888 (*crypt
)->priv
) < 0) {
2889 printk("key setting failed\n");
2890 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
2896 if (param
->u
.crypt
.set_tx
) {
2897 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
2898 sec
.active_key
= param
->u
.crypt
.idx
;
2899 sec
.flags
|= SEC_ACTIVE_KEY
;
2901 sec
.flags
&= ~SEC_ACTIVE_KEY
;
2903 if (param
->u
.crypt
.alg
!= NULL
) {
2904 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
2906 param
->u
.crypt
.key_len
);
2907 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
2908 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
2910 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
2911 sec
.flags
|= SEC_LEVEL
;
2912 sec
.level
= SEC_LEVEL_1
;
2913 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
2914 sec
.flags
|= SEC_LEVEL
;
2915 sec
.level
= SEC_LEVEL_2
;
2916 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
2917 sec
.flags
|= SEC_LEVEL
;
2918 sec
.level
= SEC_LEVEL_3
;
2922 if (ieee
->set_security
)
2923 ieee
->set_security(ieee
->dev
, &sec
);
2925 /* Do not reset port if card is in Managed mode since resetting will
2926 * generate new IEEE 802.11 authentication which may end up in looping
2927 * with IEEE 802.1X. If your hardware requires a reset after WEP
2928 * configuration (for example... Prism2), implement the reset_port in
2929 * the callbacks structures used to initialize the 802.11 stack. */
2930 if (ieee
->reset_on_keychange
&&
2931 ieee
->iw_mode
!= IW_MODE_INFRA
&&
2933 ieee
->reset_port(ieee
->dev
)) {
2934 printk("reset_port failed\n");
2935 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
2942 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device
*ieee
, struct iw_point
*p
)
2944 struct ieee_param
*param
;
2947 down(&ieee
->wx_sem
);
2948 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
2950 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
){
2955 param
= kmalloc(p
->length
, GFP_KERNEL
);
2960 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
2966 switch (param
->cmd
) {
2968 case IEEE_CMD_SET_WPA_PARAM
:
2969 ret
= ieee80211_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
2970 param
->u
.wpa_param
.value
);
2973 case IEEE_CMD_SET_WPA_IE
:
2974 ret
= ieee80211_wpa_set_wpa_ie(ieee
, param
, p
->length
);
2977 case IEEE_CMD_SET_ENCRYPTION
:
2978 ret
= ieee80211_wpa_set_encryption(ieee
, param
, p
->length
);
2982 ret
= ieee80211_wpa_mlme(ieee
, param
->u
.mlme
.command
,
2983 param
->u
.mlme
.reason_code
);
2987 printk("Unknown WPA supplicant request: %d\n",param
->cmd
);
2992 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
3002 void notify_wx_assoc_event(struct ieee80211_device
*ieee
)
3004 union iwreq_data wrqu
;
3005 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3006 if (ieee
->state
== IEEE80211_LINKED
)
3007 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
, ETH_ALEN
);
3009 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
3010 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);