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 rtllib
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
20 #include <linux/random.h>
21 #include <linux/delay.h>
22 #include <linux/version.h>
23 #include <asm/uaccess.h>
26 extern void _setup_timer( struct timer_list
*, void*, unsigned long );
27 u8 rsn_authen_cipher_suite
[16][4] = {
28 {0x00,0x0F,0xAC,0x00},
29 {0x00,0x0F,0xAC,0x01},
30 {0x00,0x0F,0xAC,0x02},
31 {0x00,0x0F,0xAC,0x03},
32 {0x00,0x0F,0xAC,0x04},
33 {0x00,0x0F,0xAC,0x05},
36 short rtllib_is_54g(struct rtllib_network
*net
)
38 return ((net
->rates_ex_len
> 0) || (net
->rates_len
> 4));
41 short rtllib_is_shortslot(struct rtllib_network net
)
43 return (net
.capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
46 /* returns the total length needed for pleacing the RATE MFIE
47 * tag and the EXTENDED RATE MFIE tag if needed.
48 * It encludes two bytes per tag for the tag itself and its len
50 unsigned int rtllib_MFIE_rate_len(struct rtllib_device
*ieee
)
52 unsigned int rate_len
= 0;
54 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
)
55 rate_len
= RTLLIB_CCK_RATE_LEN
+ 2;
57 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)
59 rate_len
+= RTLLIB_OFDM_RATE_LEN
+ 2;
64 /* pleace the MFIE rate, tag to the memory (double) poined.
65 * Then it updates the pointer so that
66 * it points after the new MFIE tag added.
68 void rtllib_MFIE_Brate(struct rtllib_device
*ieee
, u8
**tag_p
)
72 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
){
73 *tag
++ = MFIE_TYPE_RATES
;
75 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_1MB
;
76 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_2MB
;
77 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_5MB
;
78 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_11MB
;
81 /* We may add an option for custom rates that specific HW might support */
85 void rtllib_MFIE_Grate(struct rtllib_device
*ieee
, u8
**tag_p
)
89 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
){
91 *tag
++ = MFIE_TYPE_RATES_EX
;
93 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_6MB
;
94 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_9MB
;
95 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_12MB
;
96 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_18MB
;
97 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_24MB
;
98 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_36MB
;
99 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_48MB
;
100 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_54MB
;
104 /* We may add an option for custom rates that specific HW might support */
108 void rtllib_WMM_Info(struct rtllib_device
*ieee
, u8
**tag_p
) {
111 *tag
++ = MFIE_TYPE_GENERIC
;
123 void rtllib_TURBO_Info(struct rtllib_device
*ieee
, u8
**tag_p
) {
126 *tag
++ = MFIE_TYPE_GENERIC
;
137 printk(KERN_ALERT
"This is enable turbo mode IE process\n");
140 void enqueue_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
143 nh
= (ieee
->mgmt_queue_head
+1) % MGMT_QUEUE_NUM
;
146 * if the queue is full but we have newer frames then
147 * just overwrites the oldest.
149 * if (nh == ieee->mgmt_queue_tail)
152 ieee
->mgmt_queue_head
= nh
;
153 ieee
->mgmt_queue_ring
[nh
] = skb
;
157 struct sk_buff
*dequeue_mgmt(struct rtllib_device
*ieee
)
161 if (ieee
->mgmt_queue_tail
== ieee
->mgmt_queue_head
)
164 ret
= ieee
->mgmt_queue_ring
[ieee
->mgmt_queue_tail
];
166 ieee
->mgmt_queue_tail
=
167 (ieee
->mgmt_queue_tail
+1) % MGMT_QUEUE_NUM
;
172 void init_mgmt_queue(struct rtllib_device
*ieee
)
174 ieee
->mgmt_queue_tail
= ieee
->mgmt_queue_head
= 0;
179 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device
*ieee
)
186 for ( i
= 0; i
< ieee
->current_network
.rates_len
; i
++)
188 BasicRate
= ieee
->current_network
.rates
[i
]&0x7F;
189 if (!rtllib_is_cck_rate(BasicRate
))
193 QueryRate
= BasicRate
;
197 if (BasicRate
< QueryRate
)
199 QueryRate
= BasicRate
;
208 printk("No BasicRate found!!\n");
213 u8
MgntQuery_MgntFrameTxRate(struct rtllib_device
*ieee
)
215 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
218 if (pHTInfo
->IOTAction
& HT_IOT_ACT_MGNT_USE_CCK_6M
)
221 rate
= ieee
->basic_rate
& 0x7f;
224 if (ieee
->mode
== IEEE_A
||
225 ieee
->mode
== IEEE_N_5G
||
226 (ieee
->mode
== IEEE_N_24G
&&!pHTInfo
->bCurSuppCCK
))
236 void rtllib_sta_wakeup(struct rtllib_device
*ieee
, short nl
);
238 inline void softmac_mgmt_xmit(struct sk_buff
*skb
, struct rtllib_device
*ieee
)
241 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
242 struct rtllib_hdr_3addr
*header
=
243 (struct rtllib_hdr_3addr
*) skb
->data
;
245 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ 8);
246 spin_lock_irqsave(&ieee
->lock
, flags
);
248 /* called with 2nd param 0, no mgmt lock required */
249 rtllib_sta_wakeup(ieee
,0);
251 if (header
->frame_ctl
== RTLLIB_STYPE_BEACON
)
252 tcb_desc
->queue_index
= BEACON_QUEUE
;
254 tcb_desc
->queue_index
= MGNT_QUEUE
;
256 if (ieee
->disable_mgnt_queue
)
257 tcb_desc
->queue_index
= HIGH_QUEUE
;
259 tcb_desc
->data_rate
= MgntQuery_MgntFrameTxRate(ieee
);
260 tcb_desc
->RATRIndex
= 7;
261 tcb_desc
->bTxDisableRateFallBack
= 1;
262 tcb_desc
->bTxUseDriverAssingedRate
= 1;
264 if (ieee
->queue_stop
){
265 enqueue_mgmt(ieee
,skb
);
267 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4);
269 if (ieee
->seq_ctrl
[0] == 0xFFF)
270 ieee
->seq_ctrl
[0] = 0;
274 /* avoid watchdog triggers */
275 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
278 spin_unlock_irqrestore(&ieee
->lock
, flags
);
280 spin_unlock_irqrestore(&ieee
->lock
, flags
);
281 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags
);
283 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
285 if (ieee
->seq_ctrl
[0] == 0xFFF)
286 ieee
->seq_ctrl
[0] = 0;
290 /* check wether the managed packet queued greater than 5 */
291 if (!ieee
->check_nic_enough_desc(ieee
->dev
,tcb_desc
->queue_index
)||\
292 (skb_queue_len(&ieee
->skb_waitQ
[tcb_desc
->queue_index
]) != 0)||\
293 (ieee
->queue_stop
) ) {
294 /* insert the skb packet to the management queue */
295 /* as for the completion function, it does not need
296 * to check it any more.
298 printk("%s():insert to waitqueue, queue_index:%d!\n",__func__
,tcb_desc
->queue_index
);
299 skb_queue_tail(&ieee
->skb_waitQ
[tcb_desc
->queue_index
], skb
);
301 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
303 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags
);
307 inline void softmac_ps_mgmt_xmit(struct sk_buff
*skb
,
308 struct rtllib_device
*ieee
)
310 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
311 struct rtllib_hdr_3addr
*header
=
312 (struct rtllib_hdr_3addr
*) skb
->data
;
314 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ 8);
316 fc
= header
->frame_ctl
;
317 type
= WLAN_FC_GET_TYPE(fc
);
318 stype
= WLAN_FC_GET_STYPE(fc
);
321 if (stype
!= RTLLIB_STYPE_PSPOLL
)
322 tcb_desc
->queue_index
= MGNT_QUEUE
;
324 tcb_desc
->queue_index
= HIGH_QUEUE
;
326 if (ieee
->disable_mgnt_queue
)
327 tcb_desc
->queue_index
= HIGH_QUEUE
;
330 tcb_desc
->data_rate
= MgntQuery_MgntFrameTxRate(ieee
);
331 tcb_desc
->RATRIndex
= 7;
332 tcb_desc
->bTxDisableRateFallBack
= 1;
333 tcb_desc
->bTxUseDriverAssingedRate
= 1;
335 if (type
!= RTLLIB_FTYPE_CTL
) {
336 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
338 if (ieee
->seq_ctrl
[0] == 0xFFF)
339 ieee
->seq_ctrl
[0] = 0;
344 /* avoid watchdog triggers */
345 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
348 if (type
!= RTLLIB_FTYPE_CTL
) {
349 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
351 if (ieee
->seq_ctrl
[0] == 0xFFF)
352 ieee
->seq_ctrl
[0] = 0;
356 ieee
->softmac_hard_start_xmit(skb
,ieee
->dev
);
361 inline struct sk_buff
*rtllib_probe_req(struct rtllib_device
*ieee
)
363 unsigned int len
,rate_len
;
366 struct rtllib_probe_request
*req
;
368 len
= ieee
->current_network
.ssid_len
;
370 rate_len
= rtllib_MFIE_rate_len(ieee
);
372 skb
= dev_alloc_skb(sizeof(struct rtllib_probe_request
) +
373 2 + len
+ rate_len
+ ieee
->tx_headroom
);
378 skb_reserve(skb
, ieee
->tx_headroom
);
380 req
= (struct rtllib_probe_request
*) skb_put(skb
,sizeof(struct rtllib_probe_request
));
381 req
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_PROBE_REQ
);
382 req
->header
.duration_id
= 0;
384 memset(req
->header
.addr1
, 0xff, ETH_ALEN
);
385 memcpy(req
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
386 memset(req
->header
.addr3
, 0xff, ETH_ALEN
);
388 tag
= (u8
*) skb_put(skb
,len
+2+rate_len
);
390 *tag
++ = MFIE_TYPE_SSID
;
392 memcpy(tag
, ieee
->current_network
.ssid
, len
);
395 rtllib_MFIE_Brate(ieee
,&tag
);
396 rtllib_MFIE_Grate(ieee
,&tag
);
401 struct sk_buff
*rtllib_get_beacon_(struct rtllib_device
*ieee
);
403 void rtllib_send_beacon(struct rtllib_device
*ieee
)
408 skb
= rtllib_get_beacon_(ieee
);
411 softmac_mgmt_xmit(skb
, ieee
);
412 ieee
->softmac_stats
.tx_beacons
++;
415 if (ieee
->beacon_txing
&& ieee
->ieee_up
){
416 mod_timer(&ieee
->beacon_timer
,jiffies
+(MSECS(ieee
->current_network
.beacon_interval
-5)));
421 void rtllib_send_beacon_cb(unsigned long _ieee
)
423 struct rtllib_device
*ieee
=
424 (struct rtllib_device
*) _ieee
;
427 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
428 rtllib_send_beacon(ieee
);
429 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
434 * Enable network monitor mode, all rx packets will be received.
436 void rtllib_EnableNetMonitorMode(struct net_device
* dev
,
439 struct rtllib_device
* ieee
= netdev_priv_rsl(dev
);
441 printk("========>Enter Monitor Mode\n");
443 ieee
->AllowAllDestAddrHandler(dev
, true, !bInitState
);
449 * Disable network network monitor mode, only packets destinated to
450 * us will be received.
452 void rtllib_DisableNetMonitorMode(struct net_device
* dev
,
455 struct rtllib_device
* ieee
= netdev_priv_rsl(dev
);
457 printk("========>Exit Monitor Mode\n");
459 ieee
->AllowAllDestAddrHandler(dev
, false, !bInitState
);
465 * This enables the specialized promiscuous mode required by Intel.
466 * In this mode, Intel intends to hear traffics from/to other STAs in the same BSS.
467 * Therefore we don't have to disable checking BSSID and we only need to allow all dest.
468 * BUT: if we enable checking BSSID then we can't recv packets from other STA.
470 void rtllib_EnableIntelPromiscuousMode(struct net_device
* dev
,
473 bool bFilterOutNonAssociatedBSSID
= false;
475 struct rtllib_device
* ieee
= netdev_priv_rsl(dev
);
477 printk("========>Enter Intel Promiscuous Mode\n");
479 ieee
->AllowAllDestAddrHandler(dev
, true, !bInitState
);
480 ieee
->SetHwRegHandler(dev
, HW_VAR_CECHK_BSSID
, (u8
*)&bFilterOutNonAssociatedBSSID
);
482 ieee
->bNetPromiscuousMode
= true;
488 * This disables the specialized promiscuous mode required by Intel.
489 * See MgntEnableIntelPromiscuousMode for detail.
491 void rtllib_DisableIntelPromiscuousMode(struct net_device
* dev
,
494 bool bFilterOutNonAssociatedBSSID
= true;
496 struct rtllib_device
* ieee
= netdev_priv_rsl(dev
);
498 printk("========>Exit Intel Promiscuous Mode\n");
500 ieee
->AllowAllDestAddrHandler(dev
, false, !bInitState
);
501 ieee
->SetHwRegHandler(dev
, HW_VAR_CECHK_BSSID
, (u8
*)&bFilterOutNonAssociatedBSSID
);
503 ieee
->bNetPromiscuousMode
= false;
506 void rtllib_send_probe(struct rtllib_device
*ieee
, u8 is_mesh
)
509 skb
= rtllib_probe_req(ieee
);
511 softmac_mgmt_xmit(skb
, ieee
);
512 ieee
->softmac_stats
.tx_probe_rq
++;
517 void rtllib_send_probe_requests(struct rtllib_device
*ieee
, u8 is_mesh
)
519 if (ieee
->active_scan
&& (ieee
->softmac_features
&
520 IEEE_SOFTMAC_PROBERQ
)) {
521 rtllib_send_probe(ieee
, 0);
522 rtllib_send_probe(ieee
, 0);
526 void rtllib_softmac_hint11d_wq(void *data
)
530 void rtllib_update_active_chan_map(struct rtllib_device
*ieee
)
532 memcpy(ieee
->active_channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
, MAX_CHANNEL_NUMBER
+1);
535 /* this performs syncro scan blocking the caller until all channels
536 * in the allowed channel map has been checked.
538 void rtllib_softmac_scan_syncro(struct rtllib_device
*ieee
, u8 is_mesh
)
542 rtllib_update_active_chan_map(ieee
);
544 ieee
->be_scan_inprogress
= true;
546 down(&ieee
->scan_sem
);
553 if (ch
> MAX_CHANNEL_NUMBER
)
554 goto out
; /* scan completed */
555 } while(!ieee
->active_channel_map
[ch
]);
557 /* this fuction can be called in two situations
558 * 1- We have switched to ad-hoc mode and we are
559 * performing a complete syncro scan before conclude
560 * there are no interesting cell and to create a
561 * new one. In this case the link state is
562 * RTLLIB_NOLINK until we found an interesting cell.
563 * If so the ieee8021_new_net, called by the RX path
564 * will set the state to RTLLIB_LINKED, so we stop
566 * 2- We are linked and the root uses run iwlist scan.
567 * So we switch to RTLLIB_LINKED_SCANNING to remember
568 * that we are still logically linked (not interested in
569 * new network events, despite for updating the net list,
570 * but we are temporarly 'unlinked' as the driver shall
571 * not filter RX frames and the channel is changing.
572 * So the only situation in witch are interested is to check
573 * if the state become LINKED because of the #1 situation
576 if (ieee
->state
== RTLLIB_LINKED
)
578 if (ieee
->sync_scan_hurryup
){
579 printk("============>sync_scan_hurryup out\n");
583 ieee
->set_chan(ieee
->dev
, ch
);
584 if (ieee
->active_channel_map
[ch
] == 1)
585 rtllib_send_probe_requests(ieee
, 0);
587 /* this prevent excessive time wait when we
588 * need to wait for a syncro scan to end..
590 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME
);
593 ieee
->actscanning
= false;
594 ieee
->sync_scan_hurryup
= 0;
596 if (ieee
->state
>= RTLLIB_LINKED
){
597 if (IS_DOT11D_ENABLE(ieee
))
598 DOT11D_ScanComplete(ieee
);
602 ieee
->be_scan_inprogress
= false;
605 union iwreq_data wrqu
;
606 memset(&wrqu
, 0, sizeof(wrqu
));
607 wireless_send_event(ieee
->dev
,SIOCGIWSCAN
,&wrqu
,NULL
);
611 void rtllib_softmac_scan_wq(void *data
)
613 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
, struct rtllib_device
, softmac_scan_wq
);
614 u8 last_channel
= ieee
->current_network
.channel
;
616 rtllib_update_active_chan_map(ieee
);
620 if (rtllib_act_scanning(ieee
,true) == true)
623 down(&ieee
->scan_sem
);
625 if (ieee
->eRFPowerState
== eRfOff
)
627 printk("======>%s():rf state is eRfOff, return\n",__func__
);
632 ieee
->current_network
.channel
=
633 (ieee
->current_network
.channel
+ 1) % MAX_CHANNEL_NUMBER
;
634 if (ieee
->scan_watch_dog
++ > MAX_CHANNEL_NUMBER
)
636 if (!ieee
->active_channel_map
[ieee
->current_network
.channel
])
637 ieee
->current_network
.channel
= 6;
638 goto out
; /* no good chans */
640 } while(!ieee
->active_channel_map
[ieee
->current_network
.channel
]);
642 if (ieee
->scanning_continue
== 0 )
645 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
647 if (ieee
->active_channel_map
[ieee
->current_network
.channel
] == 1)
648 rtllib_send_probe_requests(ieee
, 0);
650 queue_delayed_work_rsl(ieee
->wq
, &ieee
->softmac_scan_wq
, MSECS(RTLLIB_SOFTMAC_SCAN_TIME
));
656 if (IS_DOT11D_ENABLE(ieee
))
657 DOT11D_ScanComplete(ieee
);
658 ieee
->current_network
.channel
= last_channel
;
661 ieee
->actscanning
= false;
662 ieee
->scan_watch_dog
= 0;
663 ieee
->scanning_continue
= 0;
669 void rtllib_beacons_start(struct rtllib_device
*ieee
)
672 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
674 ieee
->beacon_txing
= 1;
675 rtllib_send_beacon(ieee
);
677 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
680 void rtllib_beacons_stop(struct rtllib_device
*ieee
)
684 spin_lock_irqsave(&ieee
->beacon_lock
,flags
);
686 ieee
->beacon_txing
= 0;
687 del_timer_sync(&ieee
->beacon_timer
);
689 spin_unlock_irqrestore(&ieee
->beacon_lock
,flags
);
694 void rtllib_stop_send_beacons(struct rtllib_device
*ieee
)
696 if (ieee
->stop_send_beacons
)
697 ieee
->stop_send_beacons(ieee
->dev
);
698 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
699 rtllib_beacons_stop(ieee
);
703 void rtllib_start_send_beacons(struct rtllib_device
*ieee
)
705 if (ieee
->start_send_beacons
)
706 ieee
->start_send_beacons(ieee
->dev
);
707 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
708 rtllib_beacons_start(ieee
);
712 void rtllib_softmac_stop_scan(struct rtllib_device
*ieee
)
714 down(&ieee
->scan_sem
);
715 ieee
->scan_watch_dog
= 0;
716 if (ieee
->scanning_continue
== 1) {
717 ieee
->scanning_continue
= 0;
718 ieee
->actscanning
= 0;
720 cancel_delayed_work(&ieee
->softmac_scan_wq
);
726 void rtllib_stop_scan(struct rtllib_device
*ieee
)
728 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
729 rtllib_softmac_stop_scan(ieee
);
731 if (ieee
->rtllib_stop_hw_scan
)
732 ieee
->rtllib_stop_hw_scan(ieee
->dev
);
736 void rtllib_stop_scan_syncro(struct rtllib_device
*ieee
)
738 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
739 ieee
->sync_scan_hurryup
= 1;
741 if (ieee
->rtllib_stop_hw_scan
)
742 ieee
->rtllib_stop_hw_scan(ieee
->dev
);
746 bool rtllib_act_scanning(struct rtllib_device
*ieee
, bool sync_scan
)
748 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
750 return ieee
->be_scan_inprogress
;
752 return (ieee
->actscanning
||ieee
->be_scan_inprogress
);
755 return test_bit(STATUS_SCANNING
, &ieee
->status
);
759 /* called with ieee->lock held */
760 void rtllib_start_scan(struct rtllib_device
*ieee
)
762 RT_TRACE(COMP_DBG
, "===>%s()\n",__func__
);
763 if (ieee
->rtllib_ips_leave_wq
!= NULL
)
764 ieee
->rtllib_ips_leave_wq(ieee
->dev
);
767 if (IS_DOT11D_ENABLE(ieee
) )
769 if (IS_COUNTRY_IE_VALID(ieee
))
771 RESET_CIE_WATCHDOG(ieee
);
774 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
775 if (ieee
->scanning_continue
== 0) {
776 ieee
->actscanning
= true;
777 ieee
->scanning_continue
= 1;
778 queue_delayed_work_rsl(ieee
->wq
, &ieee
->softmac_scan_wq
, 0);
781 if (ieee
->rtllib_start_hw_scan
)
782 ieee
->rtllib_start_hw_scan(ieee
->dev
);
787 /* called with wx_sem held */
788 void rtllib_start_scan_syncro(struct rtllib_device
*ieee
, u8 is_mesh
)
790 if (IS_DOT11D_ENABLE(ieee
) )
792 if (IS_COUNTRY_IE_VALID(ieee
))
794 RESET_CIE_WATCHDOG(ieee
);
797 ieee
->sync_scan_hurryup
= 0;
798 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
){
799 rtllib_softmac_scan_syncro(ieee
, is_mesh
);
801 if (ieee
->rtllib_start_hw_scan
)
802 ieee
->rtllib_start_hw_scan(ieee
->dev
);
807 inline struct sk_buff
*rtllib_authentication_req(struct rtllib_network
*beacon
,
808 struct rtllib_device
*ieee
, int challengelen
,u8
* daddr
)
811 struct rtllib_authentication
*auth
;
813 len
= sizeof(struct rtllib_authentication
) + challengelen
+ ieee
->tx_headroom
+ 4;
814 skb
= dev_alloc_skb(len
);
816 if (!skb
) return NULL
;
818 skb_reserve(skb
, ieee
->tx_headroom
);
820 auth
= (struct rtllib_authentication
*)
821 skb_put(skb
, sizeof(struct rtllib_authentication
));
823 auth
->header
.frame_ctl
= RTLLIB_STYPE_AUTH
;
824 if (challengelen
) auth
->header
.frame_ctl
|= RTLLIB_FCTL_WEP
;
826 auth
->header
.duration_id
= 0x013a;
827 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
828 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
829 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
830 if (ieee
->auth_mode
== 0)
831 auth
->algorithm
= WLAN_AUTH_OPEN
;
832 else if (ieee
->auth_mode
== 1)
833 auth
->algorithm
= WLAN_AUTH_SHARED_KEY
;
834 else if (ieee
->auth_mode
== 2)
835 auth
->algorithm
= WLAN_AUTH_OPEN
;
836 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
837 ieee
->associate_seq
++;
839 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
845 void constructWMMIE(u8
* wmmie
, u8
* wmm_len
,u8 oui_subtype
)
847 u8 szQoSOUI
[] ={221, 0, 0x00, 0x50, 0xf2, 0x02, 0, 1};
849 if (oui_subtype
== OUI_SUBTYPE_QOS_CAPABI
)
852 szQoSOUI
[1] = *wmm_len
;
853 memcpy(wmmie
,szQoSOUI
,3);
858 szQoSOUI
[1] = *wmm_len
+ 6;
859 szQoSOUI
[6] = oui_subtype
;
860 memcpy(wmmie
, szQoSOUI
, 8);
866 static struct sk_buff
* rtllib_probe_resp(struct rtllib_device
*ieee
, u8
*dest
)
870 struct rtllib_probe_response
*beacon_buf
;
871 struct sk_buff
*skb
= NULL
;
873 int atim_len
,erp_len
;
874 struct rtllib_crypt_data
* crypt
;
876 char *ssid
= ieee
->current_network
.ssid
;
877 int ssid_len
= ieee
->current_network
.ssid_len
;
878 int rate_len
= ieee
->current_network
.rates_len
+2;
879 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
880 int wpa_ie_len
= ieee
->wpa_ie_len
;
881 u8 erpinfo_content
= 0;
883 u8
* tmp_ht_cap_buf
= NULL
;
884 u8 tmp_ht_cap_len
= 0;
885 u8
* tmp_ht_info_buf
= NULL
;
886 u8 tmp_ht_info_len
= 0;
887 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
888 u8
* tmp_generic_ie_buf
= NULL
;
889 u8 tmp_generic_ie_len
= 0;
894 if (ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
899 if ((ieee
->current_network
.mode
== IEEE_G
)
900 ||( ieee
->current_network
.mode
== IEEE_N_24G
&& ieee
->pHTInfo
->bCurSuppCCK
)) {
903 if (ieee
->current_network
.buseprotection
)
904 erpinfo_content
|= ERP_UseProtection
;
909 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
910 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
911 ((0 == strcmp(crypt
->ops
->name
, "WEP") || wpa_ie_len
));
912 if (ieee
->pHTInfo
->bCurrentHTSupport
){
913 tmp_ht_cap_buf
=(u8
*) &(ieee
->pHTInfo
->SelfHTCap
);
914 tmp_ht_cap_len
= sizeof(ieee
->pHTInfo
->SelfHTCap
);
915 tmp_ht_info_buf
=(u8
*) &(ieee
->pHTInfo
->SelfHTInfo
);
916 tmp_ht_info_len
= sizeof(ieee
->pHTInfo
->SelfHTInfo
);
917 HTConstructCapabilityElement(ieee
, tmp_ht_cap_buf
, &tmp_ht_cap_len
,encrypt
, false);
918 HTConstructInfoElement(ieee
,tmp_ht_info_buf
,&tmp_ht_info_len
, encrypt
);
921 if (pHTInfo
->bRegRT2RTAggregation
)
923 tmp_generic_ie_buf
= ieee
->pHTInfo
->szRT2RTAggBuffer
;
924 tmp_generic_ie_len
= sizeof(ieee
->pHTInfo
->szRT2RTAggBuffer
);
925 HTConstructRT2RTAggElement(ieee
, tmp_generic_ie_buf
, &tmp_generic_ie_len
);
929 beacon_size
= sizeof(struct rtllib_probe_response
)+2+
938 skb
= dev_alloc_skb(beacon_size
);
942 skb_reserve(skb
, ieee
->tx_headroom
);
944 beacon_buf
= (struct rtllib_probe_response
*) skb_put(skb
, (beacon_size
- ieee
->tx_headroom
));
945 memcpy (beacon_buf
->header
.addr1
, dest
,ETH_ALEN
);
946 memcpy (beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
947 memcpy (beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
949 beacon_buf
->header
.duration_id
= 0;
950 beacon_buf
->beacon_interval
=
951 cpu_to_le16(ieee
->current_network
.beacon_interval
);
952 beacon_buf
->capability
=
953 cpu_to_le16(ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
);
954 beacon_buf
->capability
|=
955 cpu_to_le16(ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
957 if (ieee
->short_slot
&& (ieee
->current_network
.capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
))
958 cpu_to_le16((beacon_buf
->capability
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
));
960 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
962 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
965 beacon_buf
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_PROBE_RESP
);
966 beacon_buf
->info_element
[0].id
= MFIE_TYPE_SSID
;
967 beacon_buf
->info_element
[0].len
= ssid_len
;
969 tag
= (u8
*) beacon_buf
->info_element
[0].data
;
971 memcpy(tag
, ssid
, ssid_len
);
975 *(tag
++) = MFIE_TYPE_RATES
;
976 *(tag
++) = rate_len
-2;
977 memcpy(tag
,ieee
->current_network
.rates
,rate_len
-2);
980 *(tag
++) = MFIE_TYPE_DS_SET
;
982 *(tag
++) = ieee
->current_network
.channel
;
986 *(tag
++) = MFIE_TYPE_IBSS_SET
;
988 val16
= cpu_to_le16(ieee
->current_network
.atim_window
);
989 memcpy((u8
*)tag
, (u8
*)&val16
, 2);
994 *(tag
++) = MFIE_TYPE_ERP
;
996 *(tag
++) = erpinfo_content
;
999 *(tag
++) = MFIE_TYPE_RATES_EX
;
1000 *(tag
++) = rate_ex_len
-2;
1001 memcpy(tag
,ieee
->current_network
.rates_ex
,rate_ex_len
-2);
1007 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
1009 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
1011 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
1012 tag
+= ieee
->wpa_ie_len
;
1018 struct sk_buff
* rtllib_assoc_resp(struct rtllib_device
*ieee
, u8
*dest
)
1020 struct sk_buff
*skb
;
1023 struct rtllib_crypt_data
* crypt
;
1024 struct rtllib_assoc_response_frame
*assoc
;
1027 unsigned int rate_len
= rtllib_MFIE_rate_len(ieee
);
1028 int len
= sizeof(struct rtllib_assoc_response_frame
) + rate_len
+ ieee
->tx_headroom
;
1030 skb
= dev_alloc_skb(len
);
1035 skb_reserve(skb
, ieee
->tx_headroom
);
1037 assoc
= (struct rtllib_assoc_response_frame
*)
1038 skb_put(skb
,sizeof(struct rtllib_assoc_response_frame
));
1040 assoc
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP
);
1041 memcpy(assoc
->header
.addr1
, dest
,ETH_ALEN
);
1042 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1043 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1044 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
1045 WLAN_CAPABILITY_ESS
: WLAN_CAPABILITY_IBSS
);
1048 if (ieee
->short_slot
)
1049 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1051 if (ieee
->host_encrypt
)
1052 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
1056 encrypt
= ( crypt
&& crypt
->ops
);
1059 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1062 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
1063 if (ieee
->assoc_id
== 0x2007)
1068 tag
= (u8
*) skb_put(skb
, rate_len
);
1069 rtllib_MFIE_Brate(ieee
, &tag
);
1070 rtllib_MFIE_Grate(ieee
, &tag
);
1075 struct sk_buff
* rtllib_auth_resp(struct rtllib_device
*ieee
,int status
, u8
*dest
)
1077 struct sk_buff
*skb
= NULL
;
1078 struct rtllib_authentication
*auth
;
1079 int len
= ieee
->tx_headroom
+ sizeof(struct rtllib_authentication
)+1;
1080 skb
= dev_alloc_skb(len
);
1084 skb
->len
= sizeof(struct rtllib_authentication
);
1086 skb_reserve(skb
, ieee
->tx_headroom
);
1088 auth
= (struct rtllib_authentication
*)
1089 skb_put(skb
, sizeof(struct rtllib_authentication
));
1091 auth
->status
= cpu_to_le16(status
);
1092 auth
->transaction
= cpu_to_le16(2);
1093 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
1095 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1096 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1097 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
1098 auth
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_AUTH
);
1104 struct sk_buff
* rtllib_null_func(struct rtllib_device
*ieee
,short pwr
)
1106 struct sk_buff
*skb
;
1107 struct rtllib_hdr_3addr
* hdr
;
1109 skb
= dev_alloc_skb(sizeof(struct rtllib_hdr_3addr
)+ieee
->tx_headroom
);
1113 skb_reserve(skb
, ieee
->tx_headroom
);
1115 hdr
= (struct rtllib_hdr_3addr
*)skb_put(skb
,sizeof(struct rtllib_hdr_3addr
));
1117 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
1118 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1119 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
1121 hdr
->frame_ctl
= cpu_to_le16(RTLLIB_FTYPE_DATA
|
1122 RTLLIB_STYPE_NULLFUNC
| RTLLIB_FCTL_TODS
|
1123 (pwr
? RTLLIB_FCTL_PM
:0));
1130 struct sk_buff
* rtllib_pspoll_func(struct rtllib_device
*ieee
)
1132 struct sk_buff
*skb
;
1133 struct rtllib_pspoll_hdr
* hdr
;
1135 skb
= dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr
)+ieee
->tx_headroom
);
1139 skb_reserve(skb
, ieee
->tx_headroom
);
1141 hdr
= (struct rtllib_pspoll_hdr
*)skb_put(skb
,sizeof(struct rtllib_pspoll_hdr
));
1143 memcpy(hdr
->bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
1144 memcpy(hdr
->ta
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1146 hdr
->aid
= cpu_to_le16(ieee
->assoc_id
| 0xc000);
1147 hdr
->frame_ctl
= cpu_to_le16(RTLLIB_FTYPE_CTL
|RTLLIB_STYPE_PSPOLL
| RTLLIB_FCTL_PM
);
1153 void rtllib_resp_to_assoc_rq(struct rtllib_device
*ieee
, u8
* dest
)
1155 struct sk_buff
*buf
= rtllib_assoc_resp(ieee
, dest
);
1158 softmac_mgmt_xmit(buf
, ieee
);
1162 void rtllib_resp_to_auth(struct rtllib_device
*ieee
, int s
, u8
* dest
)
1164 struct sk_buff
*buf
= rtllib_auth_resp(ieee
, s
, dest
);
1167 softmac_mgmt_xmit(buf
, ieee
);
1171 void rtllib_resp_to_probe(struct rtllib_device
*ieee
, u8
*dest
)
1174 struct sk_buff
*buf
= rtllib_probe_resp(ieee
, dest
);
1176 softmac_mgmt_xmit(buf
, ieee
);
1180 inline int SecIsInPMKIDList(struct rtllib_device
*ieee
, u8
*bssid
)
1186 if ((ieee
->PMKIDList
[i
].bUsed
) && (memcmp(ieee
->PMKIDList
[i
].Bssid
, bssid
, ETH_ALEN
) == 0))
1194 } while (i
< NUM_PMKID_CACHE
);
1196 if (i
== NUM_PMKID_CACHE
)
1209 inline struct sk_buff
*rtllib_association_req(struct rtllib_network
*beacon
,struct rtllib_device
*ieee
)
1211 struct sk_buff
*skb
;
1213 struct rtllib_assoc_request_frame
*hdr
;
1216 u8
* ht_cap_buf
= NULL
;
1218 u8
* realtek_ie_buf
=NULL
;
1219 u8 realtek_ie_len
=0;
1220 int wpa_ie_len
= ieee
->wpa_ie_len
;
1221 int wps_ie_len
= ieee
->wps_ie_len
;
1222 unsigned int ckip_ie_len
=0;
1223 unsigned int ccxrm_ie_len
=0;
1224 unsigned int cxvernum_ie_len
=0;
1225 struct rtllib_crypt_data
* crypt
;
1229 unsigned int rate_len
= (beacon
->rates_len
?(beacon
->rates_len
+2):0) + (beacon
->rates_ex_len
?(beacon
->rates_ex_len
)+2:0);
1231 unsigned int wmm_info_len
= beacon
->qos_data
.supported
?9:0;
1232 unsigned int turbo_info_len
= beacon
->Turbo_Enable
?9:0;
1235 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
1236 if (crypt
!= NULL
) {
1237 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&& ((0 == strcmp(crypt
->ops
->name
,"WEP") || wpa_ie_len
));
1242 if ((ieee
->rtllib_ap_sec_type
&& (ieee
->rtllib_ap_sec_type(ieee
)&SEC_ALG_TKIP
)) ||(ieee
->bForcedBgMode
== true))
1244 ieee
->pHTInfo
->bEnableHT
= 0;
1245 ieee
->mode
= WIRELESS_MODE_G
;
1248 if (ieee
->pHTInfo
->bCurrentHTSupport
&&ieee
->pHTInfo
->bEnableHT
)
1250 ht_cap_buf
= (u8
*)&(ieee
->pHTInfo
->SelfHTCap
);
1251 ht_cap_len
= sizeof(ieee
->pHTInfo
->SelfHTCap
);
1252 HTConstructCapabilityElement(ieee
, ht_cap_buf
, &ht_cap_len
, encrypt
, true);
1253 if (ieee
->pHTInfo
->bCurrentRT2RTAggregation
) {
1254 realtek_ie_buf
= ieee
->pHTInfo
->szRT2RTAggBuffer
;
1255 realtek_ie_len
= sizeof( ieee
->pHTInfo
->szRT2RTAggBuffer
);
1256 HTConstructRT2RTAggElement(ieee
, realtek_ie_buf
, &realtek_ie_len
);
1261 if (beacon
->bCkipSupported
)
1265 if (beacon
->bCcxRmEnable
)
1269 if ( beacon
->BssCcxVerNumber
>= 2 )
1271 cxvernum_ie_len
= 5+2;
1274 PMKCacheIdx
= SecIsInPMKIDList(ieee
, ieee
->current_network
.bssid
);
1275 if (PMKCacheIdx
>= 0)
1278 printk("[PMK cache]: WPA2 IE length: %x\n", wpa_ie_len
);
1280 len
= sizeof(struct rtllib_assoc_request_frame
)+ 2
1292 + ieee
->tx_headroom
;
1294 skb
= dev_alloc_skb(len
);
1299 skb_reserve(skb
, ieee
->tx_headroom
);
1301 hdr
= (struct rtllib_assoc_request_frame
*)
1302 skb_put(skb
, sizeof(struct rtllib_assoc_request_frame
)+2);
1305 hdr
->header
.frame_ctl
= RTLLIB_STYPE_ASSOC_REQ
;
1306 hdr
->header
.duration_id
= 37;
1307 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1308 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1309 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1311 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);
1313 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_ESS
);
1314 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1315 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1317 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1318 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1320 if (ieee
->short_slot
&& (beacon
->capability
&WLAN_CAPABILITY_SHORT_SLOT_TIME
))
1321 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1324 hdr
->listen_interval
= beacon
->listen_interval
;
1326 hdr
->info_element
[0].id
= MFIE_TYPE_SSID
;
1328 hdr
->info_element
[0].len
= beacon
->ssid_len
;
1329 tag
= skb_put(skb
, beacon
->ssid_len
);
1330 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1332 tag
= skb_put(skb
, rate_len
);
1334 if (beacon
->rates_len
){
1335 *tag
++ = MFIE_TYPE_RATES
;
1336 *tag
++ = beacon
->rates_len
;
1337 for (i
=0;i
<beacon
->rates_len
;i
++){
1338 *tag
++ = beacon
->rates
[i
];
1342 if (beacon
->rates_ex_len
){
1343 *tag
++ = MFIE_TYPE_RATES_EX
;
1344 *tag
++ = beacon
->rates_ex_len
;
1345 for (i
=0;i
<beacon
->rates_ex_len
;i
++){
1346 *tag
++ = beacon
->rates_ex
[i
];
1350 if ( beacon
->bCkipSupported
)
1352 static u8 AironetIeOui
[] = {0x00, 0x01, 0x66};
1353 u8 CcxAironetBuf
[30];
1354 struct octet_string osCcxAironetIE
;
1356 memset(CcxAironetBuf
, 0,30);
1357 osCcxAironetIE
.Octet
= CcxAironetBuf
;
1358 osCcxAironetIE
.Length
= sizeof(CcxAironetBuf
);
1359 memcpy(osCcxAironetIE
.Octet
, AironetIeOui
, sizeof(AironetIeOui
));
1361 osCcxAironetIE
.Octet
[IE_CISCO_FLAG_POSITION
] |= (SUPPORT_CKIP_PK
|SUPPORT_CKIP_MIC
) ;
1362 tag
= skb_put(skb
, ckip_ie_len
);
1363 *tag
++ = MFIE_TYPE_AIRONET
;
1364 *tag
++ = osCcxAironetIE
.Length
;
1365 memcpy(tag
,osCcxAironetIE
.Octet
,osCcxAironetIE
.Length
);
1366 tag
+= osCcxAironetIE
.Length
;
1369 if (beacon
->bCcxRmEnable
)
1371 static u8 CcxRmCapBuf
[] = {0x00, 0x40, 0x96, 0x01, 0x01, 0x00};
1372 struct octet_string osCcxRmCap
;
1374 osCcxRmCap
.Octet
= CcxRmCapBuf
;
1375 osCcxRmCap
.Length
= sizeof(CcxRmCapBuf
);
1376 tag
= skb_put(skb
,ccxrm_ie_len
);
1377 *tag
++ = MFIE_TYPE_GENERIC
;
1378 *tag
++ = osCcxRmCap
.Length
;
1379 memcpy(tag
,osCcxRmCap
.Octet
,osCcxRmCap
.Length
);
1380 tag
+= osCcxRmCap
.Length
;
1383 if ( beacon
->BssCcxVerNumber
>= 2 )
1385 u8 CcxVerNumBuf
[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1386 struct octet_string osCcxVerNum
;
1387 CcxVerNumBuf
[4] = beacon
->BssCcxVerNumber
;
1388 osCcxVerNum
.Octet
= CcxVerNumBuf
;
1389 osCcxVerNum
.Length
= sizeof(CcxVerNumBuf
);
1390 tag
= skb_put(skb
,cxvernum_ie_len
);
1391 *tag
++ = MFIE_TYPE_GENERIC
;
1392 *tag
++ = osCcxVerNum
.Length
;
1393 memcpy(tag
,osCcxVerNum
.Octet
,osCcxVerNum
.Length
);
1394 tag
+= osCcxVerNum
.Length
;
1396 if (ieee
->pHTInfo
->bCurrentHTSupport
&&ieee
->pHTInfo
->bEnableHT
){
1397 if (ieee
->pHTInfo
->ePeerHTSpecVer
!= HT_SPEC_VER_EWC
)
1399 tag
= skb_put(skb
, ht_cap_len
);
1400 *tag
++ = MFIE_TYPE_HT_CAP
;
1401 *tag
++ = ht_cap_len
- 2;
1402 memcpy(tag
, ht_cap_buf
,ht_cap_len
-2);
1403 tag
+= ht_cap_len
-2;
1409 tag
= skb_put(skb
, ieee
->wpa_ie_len
);
1410 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
1412 if (PMKCacheIdx
>= 0)
1414 tag
= skb_put(skb
, 18);
1417 memcpy((tag
+ 2), &ieee
->PMKIDList
[PMKCacheIdx
].PMKID
, 16);
1421 tag
= skb_put(skb
,wmm_info_len
);
1422 rtllib_WMM_Info(ieee
, &tag
);
1425 if (wps_ie_len
&& ieee
->wps_ie
) {
1426 tag
= skb_put(skb
, wps_ie_len
);
1427 memcpy(tag
, ieee
->wps_ie
, wps_ie_len
);
1430 tag
= skb_put(skb
,turbo_info_len
);
1432 rtllib_TURBO_Info(ieee
, &tag
);
1434 if (ieee
->pHTInfo
->bCurrentHTSupport
&&ieee
->pHTInfo
->bEnableHT
){
1435 if (ieee
->pHTInfo
->ePeerHTSpecVer
== HT_SPEC_VER_EWC
)
1437 tag
= skb_put(skb
, ht_cap_len
);
1438 *tag
++ = MFIE_TYPE_GENERIC
;
1439 *tag
++ = ht_cap_len
- 2;
1440 memcpy(tag
, ht_cap_buf
,ht_cap_len
- 2);
1441 tag
+= ht_cap_len
-2;
1444 if (ieee
->pHTInfo
->bCurrentRT2RTAggregation
){
1445 tag
= skb_put(skb
, realtek_ie_len
);
1446 *tag
++ = MFIE_TYPE_GENERIC
;
1447 *tag
++ = realtek_ie_len
- 2;
1448 memcpy(tag
, realtek_ie_buf
,realtek_ie_len
-2 );
1452 if (ieee
->assocreq_ies
){
1453 kfree(ieee
->assocreq_ies
);
1454 ieee
->assocreq_ies
= NULL
;
1456 ies
= &(hdr
->info_element
[0].id
);
1457 ieee
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
1458 ieee
->assocreq_ies
= kmalloc(ieee
->assocreq_ies_len
, GFP_ATOMIC
);
1459 if (ieee
->assocreq_ies
)
1460 memcpy(ieee
->assocreq_ies
, ies
, ieee
->assocreq_ies_len
);
1462 printk("%s()Warning: can't alloc memory for assocreq_ies\n", __func__
);
1463 ieee
->assocreq_ies_len
= 0;
1469 void rtllib_associate_abort(struct rtllib_device
*ieee
)
1472 unsigned long flags
;
1473 spin_lock_irqsave(&ieee
->lock
, flags
);
1475 ieee
->associate_seq
++;
1477 /* don't scan, and avoid to have the RX path possibily
1478 * try again to associate. Even do not react to AUTH or
1479 * ASSOC response. Just wait for the retry wq to be scheduled.
1480 * Here we will check if there are good nets to associate
1481 * with, so we retry or just get back to NO_LINK and scanning
1483 if (ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATING
){
1484 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1485 ieee
->softmac_stats
.no_auth_rs
++;
1487 RTLLIB_DEBUG_MGMT("Association failed\n");
1488 ieee
->softmac_stats
.no_ass_rs
++;
1491 ieee
->state
= RTLLIB_ASSOCIATING_RETRY
;
1493 queue_delayed_work_rsl(ieee
->wq
, &ieee
->associate_retry_wq
, \
1494 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME
);
1496 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1499 void rtllib_associate_abort_cb(unsigned long dev
)
1501 rtllib_associate_abort((struct rtllib_device
*) dev
);
1504 void rtllib_associate_step1(struct rtllib_device
*ieee
,u8
* daddr
)
1506 struct rtllib_network
*beacon
= &ieee
->current_network
;
1507 struct sk_buff
*skb
;
1509 RTLLIB_DEBUG_MGMT("Stopping scan\n");
1511 ieee
->softmac_stats
.tx_auth_rq
++;
1513 skb
=rtllib_authentication_req(beacon
, ieee
, 0,daddr
);
1516 rtllib_associate_abort(ieee
);
1518 ieee
->state
= RTLLIB_ASSOCIATING_AUTHENTICATING
;
1519 RTLLIB_DEBUG_MGMT("Sending authentication request\n");
1520 softmac_mgmt_xmit(skb
, ieee
);
1521 if (!timer_pending(&ieee
->associate_timer
)){
1522 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1523 add_timer(&ieee
->associate_timer
);
1528 void rtllib_auth_challenge(struct rtllib_device
*ieee
, u8
*challenge
, int chlen
)
1531 struct sk_buff
*skb
;
1532 struct rtllib_network
*beacon
= &ieee
->current_network
;
1534 ieee
->associate_seq
++;
1535 ieee
->softmac_stats
.tx_auth_rq
++;
1537 skb
= rtllib_authentication_req(beacon
, ieee
, chlen
+2,beacon
->bssid
);
1540 rtllib_associate_abort(ieee
);
1542 c
= skb_put(skb
, chlen
+2);
1543 *(c
++) = MFIE_TYPE_CHALLENGE
;
1545 memcpy(c
, challenge
, chlen
);
1547 RTLLIB_DEBUG_MGMT("Sending authentication challenge response\n");
1549 rtllib_encrypt_fragment(ieee
, skb
, sizeof(struct rtllib_hdr_3addr
));
1551 softmac_mgmt_xmit(skb
, ieee
);
1552 mod_timer(&ieee
->associate_timer
, jiffies
+ (HZ
/2));
1557 void rtllib_associate_step2(struct rtllib_device
*ieee
)
1559 struct sk_buff
* skb
;
1560 struct rtllib_network
*beacon
= &ieee
->current_network
;
1562 del_timer_sync(&ieee
->associate_timer
);
1564 RTLLIB_DEBUG_MGMT("Sending association request\n");
1566 ieee
->softmac_stats
.tx_ass_rq
++;
1567 skb
=rtllib_association_req(beacon
, ieee
);
1569 rtllib_associate_abort(ieee
);
1571 softmac_mgmt_xmit(skb
, ieee
);
1572 mod_timer(&ieee
->associate_timer
, jiffies
+ (HZ
/2));
1577 void rtllib_associate_complete_wq(void *data
)
1579 struct rtllib_device
*ieee
= (struct rtllib_device
*)container_of_work_rsl(data
, struct rtllib_device
, associate_complete_wq
);
1580 struct rt_pwr_save_ctrl
*pPSC
= (struct rt_pwr_save_ctrl
*)(&(ieee
->PowerSaveControl
));
1581 printk(KERN_INFO
"Associated successfully\n");
1582 if (ieee
->is_silent_reset
== 0){
1583 printk("normal associate\n");
1584 notify_wx_assoc_event(ieee
);
1587 netif_carrier_on(ieee
->dev
);
1588 ieee
->is_roaming
= false;
1589 if (rtllib_is_54g(&ieee
->current_network
) &&
1590 (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)){
1593 printk(KERN_INFO
"Using G rates:%d\n", ieee
->rate
);
1596 ieee
->SetWirelessMode(ieee
->dev
, IEEE_B
);
1597 printk(KERN_INFO
"Using B rates:%d\n", ieee
->rate
);
1599 if (ieee
->pHTInfo
->bCurrentHTSupport
&&ieee
->pHTInfo
->bEnableHT
)
1601 printk("Successfully associated, ht enabled\n");
1604 printk("Successfully associated, ht not enabled(%d, %d)\n",
1605 ieee
->pHTInfo
->bCurrentHTSupport
, ieee
->pHTInfo
->bEnableHT
);
1606 memset(ieee
->dot11HTOperationalRateSet
, 0, 16);
1608 ieee
->LinkDetectInfo
.SlotNum
= 2 * (1 + ieee
->current_network
.beacon_interval
/500);
1609 if (ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
==0||ieee
->LinkDetectInfo
.NumRecvDataInPeriod
==0 )
1611 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
= 1;
1612 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
= 1;
1614 pPSC
->LpsIdleCount
= 0;
1615 ieee
->link_change(ieee
->dev
);
1617 if (ieee
->is_silent_reset
== 1) {
1618 printk("silent reset associate\n");
1619 ieee
->is_silent_reset
= 0;
1622 if (ieee
->data_hard_resume
)
1623 ieee
->data_hard_resume(ieee
->dev
);
1627 static void rtllib_sta_send_associnfo(struct rtllib_device
*ieee
)
1632 union iwreq_data wrqu
;
1637 buf
= kmalloc(50 + 2 * (ieee
->assocreq_ies_len
+ ieee
->assocresp_ies_len
), GFP_ATOMIC
);
1641 len
= sprintf(buf
, "ASSOCINFO(");
1642 if (ieee
->assocreq_ies
) {
1643 len
+= sprintf(buf
+ len
, "ReqIEs=");
1644 for (i
= 0; i
< ieee
->assocreq_ies_len
; i
++) {
1645 len
+= sprintf(buf
+ len
, "%02x", ieee
->assocreq_ies
[i
]);
1648 if (ieee
->assocresp_ies
) {
1649 if (ieee
->assocreq_ies
)
1650 len
+= sprintf(buf
+ len
, " ");
1651 len
+= sprintf(buf
+ len
, "RespIEs=");
1652 for (i
= 0; i
< ieee
->assocresp_ies_len
; i
++) {
1653 len
+= sprintf(buf
+ len
, "%02x", ieee
->assocresp_ies
[i
]);
1656 len
+= sprintf(buf
+ len
, ")");
1658 if (len
> IW_CUSTOM_MAX
) {
1659 len
= sprintf(buf
, "ASSOCRESPIE=");
1660 for (i
= 0; i
< ieee
->assocresp_ies_len
; i
++) {
1661 len
+= sprintf(buf
+ len
, "%02x", ieee
->assocresp_ies
[i
]);
1665 if (len
<= IW_CUSTOM_MAX
) {
1666 memset(&wrqu
, 0, sizeof(wrqu
));
1667 wrqu
.data
.length
= len
;
1668 wireless_send_event(ieee
->dev
, IWEVCUSTOM
, &wrqu
, buf
);
1674 void rtllib_associate_complete(struct rtllib_device
*ieee
)
1676 del_timer_sync(&ieee
->associate_timer
);
1678 ieee
->state
= RTLLIB_LINKED
;
1679 rtllib_sta_send_associnfo(ieee
);
1681 queue_work_rsl(ieee
->wq
, &ieee
->associate_complete_wq
);
1684 void rtllib_associate_procedure_wq(void *data
)
1686 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
, struct rtllib_device
, associate_procedure_wq
);
1687 rtllib_stop_scan_syncro(ieee
);
1688 if (ieee
->rtllib_ips_leave
!= NULL
)
1689 ieee
->rtllib_ips_leave(ieee
->dev
);
1690 down(&ieee
->wx_sem
);
1692 if (ieee
->data_hard_stop
)
1693 ieee
->data_hard_stop(ieee
->dev
);
1695 rtllib_stop_scan(ieee
);
1696 RT_TRACE(COMP_DBG
, "===>%s(), chan:%d\n", __func__
, ieee
->current_network
.channel
);
1697 HTSetConnectBwMode(ieee
, HT_CHANNEL_WIDTH_20
, HT_EXTCHNL_OFFSET_NO_EXT
);
1698 if (ieee
->eRFPowerState
== eRfOff
)
1700 RT_TRACE(COMP_DBG
, "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n",__func__
);
1701 if (ieee
->rtllib_ips_leave_wq
!= NULL
)
1702 ieee
->rtllib_ips_leave_wq(ieee
->dev
);
1706 ieee
->associate_seq
= 1;
1708 rtllib_associate_step1(ieee
, ieee
->current_network
.bssid
);
1713 inline void rtllib_softmac_new_net(struct rtllib_device
*ieee
, struct rtllib_network
*net
)
1715 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+1];
1716 int tmp_ssid_len
= 0;
1718 short apset
,ssidset
,ssidbroad
,apmatch
,ssidmatch
;
1720 /* we are interested in new new only if we are not associated
1721 * and we are not associating / authenticating
1723 if (ieee
->state
!= RTLLIB_NOLINK
)
1726 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
& WLAN_CAPABILITY_ESS
))
1729 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
& WLAN_CAPABILITY_IBSS
))
1732 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && (net
->channel
> ieee
->ibss_maxjoin_chal
)) {
1735 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
)
1737 /* if the user specified the AP MAC, we need also the essid
1738 * This could be obtained by beacons or, if the network does not
1739 * broadcast it, it can be put manually.
1741 apset
= ieee
->wap_set
;
1742 ssidset
= ieee
->ssid_set
;
1743 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0]== '\0');
1744 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
, ETH_ALEN
)==0);
1746 ssidmatch
= (ieee
->current_network
.ssid_len
== net
->hidden_ssid_len
)&&\
1747 (!strncmp(ieee
->current_network
.ssid
, net
->hidden_ssid
, net
->hidden_ssid_len
));
1748 if (net
->hidden_ssid_len
> 0)
1750 strncpy(net
->ssid
, net
->hidden_ssid
, net
->hidden_ssid_len
);
1751 net
->ssid_len
= net
->hidden_ssid_len
;
1756 ssidmatch
= (ieee
->current_network
.ssid_len
== net
->ssid_len
)&&\
1757 (!strncmp(ieee
->current_network
.ssid
, net
->ssid
, net
->ssid_len
));
1759 if ( /* if the user set the AP check if match.
1760 * if the network does not broadcast essid we check the user supplyed ANY essid
1761 * if the network does broadcast and the user does not set essid it is OK
1762 * if the network does broadcast and the user did set essid chech if essid match
1764 ( apset
&& apmatch
&&
1765 ((ssidset
&& ssidbroad
&& ssidmatch
) || (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
)) )
1766 /* if the ap is not set, check that the user set the bssid
1767 * and the network does bradcast and that those two bssid matches
1769 || (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
) || (ieee
->is_roaming
&& ssidset
&& ssidbroad
&& ssidmatch
)
1771 /* if the essid is hidden replace it with the
1772 * essid provided by the user.
1775 strncpy(tmp_ssid
, ieee
->current_network
.ssid
, IW_ESSID_MAX_SIZE
);
1776 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1778 memcpy(&ieee
->current_network
, net
, sizeof(struct rtllib_network
));
1780 strncpy(ieee
->current_network
.ssid
, tmp_ssid
, IW_ESSID_MAX_SIZE
);
1781 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1783 printk(KERN_INFO
"Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n",ieee
->current_network
.ssid
,ieee
->current_network
.channel
, ieee
->current_network
.qos_data
.supported
, ieee
->pHTInfo
->bEnableHT
, ieee
->current_network
.bssht
.bdSupportHT
, ieee
->current_network
.mode
, ieee
->current_network
.flags
);
1785 if ((rtllib_act_scanning(ieee
, false)) && !(ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)){
1786 rtllib_stop_scan_syncro(ieee
);
1789 ieee
->hwscan_ch_bk
= ieee
->current_network
.channel
;
1790 HTResetIOTSetting(ieee
->pHTInfo
);
1792 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
1793 /* Join the network for the first time */
1794 ieee
->AsocRetryCount
= 0;
1795 if ((ieee
->current_network
.qos_data
.supported
== 1) &&
1796 ieee
->current_network
.bssht
.bdSupportHT
)
1797 HTResetSelfAndSavePeerSetting(ieee
, &(ieee
->current_network
));
1799 ieee
->pHTInfo
->bCurrentHTSupport
= false;
1801 ieee
->state
= RTLLIB_ASSOCIATING
;
1802 if (ieee
->LedControlHandler
!= NULL
)
1803 ieee
->LedControlHandler(ieee
->dev
, LED_CTL_START_TO_LINK
);
1804 queue_delayed_work_rsl(ieee
->wq
, &ieee
->associate_procedure_wq
, 0);
1806 if (rtllib_is_54g(&ieee
->current_network
) &&
1807 (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)){
1809 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
1810 printk(KERN_INFO
"Using G rates\n");
1813 ieee
->SetWirelessMode(ieee
->dev
, IEEE_B
);
1814 printk(KERN_INFO
"Using B rates\n");
1816 memset(ieee
->dot11HTOperationalRateSet
, 0, 16);
1817 ieee
->state
= RTLLIB_LINKED
;
1825 void rtllib_softmac_check_all_nets(struct rtllib_device
*ieee
)
1827 unsigned long flags
;
1828 struct rtllib_network
*target
;
1830 spin_lock_irqsave(&ieee
->lock
, flags
);
1832 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1834 /* if the state become different that NOLINK means
1835 * we had found what we are searching for
1838 if (ieee
->state
!= RTLLIB_NOLINK
)
1841 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+ ieee
->scan_age
, jiffies
))
1842 rtllib_softmac_new_net(ieee
, target
);
1845 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1850 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1852 struct rtllib_authentication
*a
;
1854 if (skb
->len
< (sizeof(struct rtllib_authentication
)-sizeof(struct rtllib_info_element
))){
1855 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n",skb
->len
);
1859 a
= (struct rtllib_authentication
*) skb
->data
;
1860 if (skb
->len
> (sizeof(struct rtllib_authentication
) +3)){
1861 t
= skb
->data
+ sizeof(struct rtllib_authentication
);
1863 if (*(t
++) == MFIE_TYPE_CHALLENGE
){
1865 *challenge
= (u8
*)kmalloc(*chlen
, GFP_ATOMIC
);
1866 memcpy(*challenge
, t
, *chlen
);
1870 return cpu_to_le16(a
->status
);
1875 int auth_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1877 struct rtllib_authentication
*a
;
1879 if (skb
->len
< (sizeof(struct rtllib_authentication
)-sizeof(struct rtllib_info_element
))){
1880 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",skb
->len
);
1883 a
= (struct rtllib_authentication
*) skb
->data
;
1885 memcpy(dest
,a
->header
.addr2
, ETH_ALEN
);
1887 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1888 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1890 return WLAN_STATUS_SUCCESS
;
1893 static short probe_rq_parse(struct rtllib_device
*ieee
, struct sk_buff
*skb
, u8
*src
)
1900 struct rtllib_hdr_3addr
*header
=
1901 (struct rtllib_hdr_3addr
*) skb
->data
;
1903 if (skb
->len
< sizeof (struct rtllib_hdr_3addr
))
1904 return -1; /* corrupted */
1905 if ((memcmp(header
->addr3
,ieee
->current_network
.bssid
,ETH_ALEN
) != 0)&&
1906 (memcmp(header
->addr3
,"\xff\xff\xff\xff\xff\xff",ETH_ALEN
) != 0)) {
1910 if (memcmp(header
->addr3
,ieee
->current_network
.bssid
,ETH_ALEN
) == 0) {
1913 if (memcmp(header
->addr3
,"\xff\xff\xff\xff\xff\xff",ETH_ALEN
) == 0) {
1915 memcpy(src
,header
->addr2
, ETH_ALEN
);
1917 skbend
= (u8
*)skb
->data
+ skb
->len
;
1919 tag
= skb
->data
+ sizeof (struct rtllib_hdr_3addr
);
1921 while (tag
+1 < skbend
){
1927 tag
++; /* point to the len field */
1928 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1929 tag
++; /* point to the next tag */
1932 if (ssidlen
== 0) return 1;
1934 if (!ssid
) return 1; /* ssid not found in tagged param */
1935 return (!strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
));
1939 int assoc_rq_parse(struct sk_buff
*skb
,u8
* dest
)
1941 struct rtllib_assoc_request_frame
*a
;
1943 if (skb
->len
< (sizeof(struct rtllib_assoc_request_frame
) -
1944 sizeof(struct rtllib_info_element
))) {
1946 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d \n", skb
->len
);
1950 a
= (struct rtllib_assoc_request_frame
*) skb
->data
;
1952 memcpy(dest
,a
->header
.addr2
,ETH_ALEN
);
1957 static inline u16
assoc_parse(struct rtllib_device
*ieee
, struct sk_buff
*skb
, int *aid
)
1959 struct rtllib_assoc_response_frame
*response_head
;
1962 if (skb
->len
< sizeof(struct rtllib_assoc_response_frame
)){
1963 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1967 response_head
= (struct rtllib_assoc_response_frame
*) skb
->data
;
1968 *aid
= le16_to_cpu(response_head
->aid
) & 0x3fff;
1970 status_code
= le16_to_cpu(response_head
->status
);
1971 if ((status_code
==WLAN_STATUS_ASSOC_DENIED_RATES
|| \
1972 status_code
==WLAN_STATUS_CAPS_UNSUPPORTED
)&&
1973 ((ieee
->mode
== IEEE_G
) &&
1974 (ieee
->current_network
.mode
== IEEE_N_24G
) &&
1975 (ieee
->AsocRetryCount
++ < (RT_ASOC_RETRY_LIMIT
-1)))) {
1976 ieee
->pHTInfo
->IOTAction
|= HT_IOT_ACT_PURE_N_MODE
;
1978 ieee
->AsocRetryCount
= 0;
1981 return le16_to_cpu(response_head
->status
);
1984 void rtllib_rx_probe_rq(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
1987 ieee
->softmac_stats
.rx_probe_rq
++;
1988 if (probe_rq_parse(ieee
, skb
, dest
) > 0){
1989 ieee
->softmac_stats
.tx_probe_rs
++;
1990 rtllib_resp_to_probe(ieee
, dest
);
1994 static inline void rtllib_rx_auth_rq(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
1998 ieee
->softmac_stats
.rx_auth_rq
++;
2000 if ((status
= auth_rq_parse(skb
, dest
))!= -1){
2001 rtllib_resp_to_auth(ieee
, status
, dest
);
2006 static inline void rtllib_rx_assoc_rq(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
2011 ieee
->softmac_stats
.rx_ass_rq
++;
2012 if (assoc_rq_parse(skb
,dest
) != -1){
2013 rtllib_resp_to_assoc_rq(ieee
, dest
);
2016 printk(KERN_INFO
"New client associated: "MAC_FMT
"\n", MAC_ARG(dest
));
2020 void rtllib_sta_ps_send_null_frame(struct rtllib_device
*ieee
, short pwr
)
2023 struct sk_buff
*buf
= rtllib_null_func(ieee
, pwr
);
2026 softmac_ps_mgmt_xmit(buf
, ieee
);
2030 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device
*ieee
)
2033 struct sk_buff
*buf
= rtllib_pspoll_func(ieee
);
2036 softmac_ps_mgmt_xmit(buf
, ieee
);
2040 static short rtllib_sta_ps_sleep(struct rtllib_device
*ieee
, u64
*time
)
2042 int timeout
= ieee
->ps_timeout
;
2044 struct rt_pwr_save_ctrl
*pPSC
= (struct rt_pwr_save_ctrl
*)(&(ieee
->PowerSaveControl
));
2045 /*if (ieee->ps == RTLLIB_PS_DISABLED ||
2046 ieee->iw_mode != IW_MODE_INFRA ||
2047 ieee->state != RTLLIB_LINKED)
2052 if (ieee
->LPSDelayCnt
)
2054 ieee
->LPSDelayCnt
--;
2058 dtim
= ieee
->current_network
.dtim_data
;
2059 if (!(dtim
& RTLLIB_DTIM_VALID
))
2061 timeout
= ieee
->current_network
.beacon_interval
;
2062 ieee
->current_network
.dtim_data
= RTLLIB_DTIM_INVALID
;
2063 /* there's no need to nofity AP that I find you buffered with broadcast packet */
2064 if (dtim
& (RTLLIB_DTIM_UCAST
& ieee
->ps
))
2067 if (!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
))){
2070 if (!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
))){
2073 if ((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
2074 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
2078 if (ieee
->bAwakePktSent
== true) {
2079 pPSC
->LPSAwakeIntvl
= 1;
2083 if (pPSC
->LPSAwakeIntvl
== 0)
2084 pPSC
->LPSAwakeIntvl
= 1;
2085 if (pPSC
->RegMaxLPSAwakeIntvl
== 0)
2087 else if (pPSC
->RegMaxLPSAwakeIntvl
== 0xFF)
2088 MaxPeriod
= ieee
->current_network
.dtim_period
;
2090 MaxPeriod
= pPSC
->RegMaxLPSAwakeIntvl
;
2091 pPSC
->LPSAwakeIntvl
= (pPSC
->LPSAwakeIntvl
>= MaxPeriod
) ? MaxPeriod
: (pPSC
->LPSAwakeIntvl
+ 1);
2094 u8 LPSAwakeIntvl_tmp
= 0;
2095 u8 period
= ieee
->current_network
.dtim_period
;
2096 u8 count
= ieee
->current_network
.tim
.tim_count
;
2098 if (pPSC
->LPSAwakeIntvl
> period
)
2099 LPSAwakeIntvl_tmp
= period
+ (pPSC
->LPSAwakeIntvl
- period
) -((pPSC
->LPSAwakeIntvl
-period
)%period
);
2101 LPSAwakeIntvl_tmp
= pPSC
->LPSAwakeIntvl
;
2104 if (pPSC
->LPSAwakeIntvl
> ieee
->current_network
.tim
.tim_count
)
2105 LPSAwakeIntvl_tmp
= count
+ (pPSC
->LPSAwakeIntvl
- count
) -((pPSC
->LPSAwakeIntvl
-count
)%period
);
2107 LPSAwakeIntvl_tmp
= pPSC
->LPSAwakeIntvl
;
2110 *time
= ieee
->current_network
.last_dtim_sta_time
2111 + MSECS(ieee
->current_network
.beacon_interval
* LPSAwakeIntvl_tmp
);
2120 inline void rtllib_sta_ps(struct rtllib_device
*ieee
)
2126 unsigned long flags
,flags2
;
2128 spin_lock_irqsave(&ieee
->lock
, flags
);
2130 if ((ieee
->ps
== RTLLIB_PS_DISABLED
||
2131 ieee
->iw_mode
!= IW_MODE_INFRA
||
2132 ieee
->state
!= RTLLIB_LINKED
)){
2134 RT_TRACE(COMP_DBG
, "=====>%s(): no need to ps,wake up!! ieee->ps is %d,ieee->iw_mode is %d,ieee->state is %d\n",
2135 __func__
,ieee
->ps
,ieee
->iw_mode
,ieee
->state
);
2136 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2138 rtllib_sta_wakeup(ieee
, 1);
2140 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2143 sleep
= rtllib_sta_ps_sleep(ieee
, &time
);
2144 /* 2 wake, 1 sleep, 0 do nothing */
2150 if (ieee
->sta_sleep
== LPS_IS_SLEEP
){
2151 ieee
->enter_sleep_state(ieee
->dev
, time
);
2154 else if (ieee
->sta_sleep
== LPS_IS_WAKE
){
2155 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2157 if (ieee
->ps_is_queue_empty(ieee
->dev
)){
2158 ieee
->sta_sleep
= LPS_WAIT_NULL_DATA_SEND
;
2159 ieee
->ack_tx_to_ieee
= 1;
2160 rtllib_sta_ps_send_null_frame(ieee
,1);
2161 ieee
->ps_time
= time
;
2163 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2167 ieee
->bAwakePktSent
= false;
2169 }else if (sleep
== 2){
2170 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2172 rtllib_sta_wakeup(ieee
,1);
2174 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2178 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2182 void rtllib_sta_wakeup(struct rtllib_device
*ieee
, short nl
)
2184 if (ieee
->sta_sleep
== LPS_IS_WAKE
){
2186 if (ieee
->pHTInfo
->IOTAction
& HT_IOT_ACT_NULL_DATA_POWER_SAVING
)
2188 ieee
->ack_tx_to_ieee
= 1;
2189 rtllib_sta_ps_send_null_frame(ieee
, 0);
2193 ieee
->ack_tx_to_ieee
= 1;
2194 rtllib_sta_ps_send_pspoll_frame(ieee
);
2201 if (ieee
->sta_sleep
== LPS_IS_SLEEP
)
2202 ieee
->sta_wake_up(ieee
->dev
);
2205 ieee->ack_tx_to_ieee = 1;
2206 printk("%s(3): notify AP we are awaked ++++++++++ SendNullFunctionData\n", __func__);
2207 rtllib_sta_ps_send_null_frame(ieee, 0);
2209 if (ieee
->pHTInfo
->IOTAction
& HT_IOT_ACT_NULL_DATA_POWER_SAVING
)
2211 ieee
->ack_tx_to_ieee
= 1;
2212 rtllib_sta_ps_send_null_frame(ieee
, 0);
2216 ieee
->ack_tx_to_ieee
= 1;
2217 ieee
->polling
= true;
2218 rtllib_sta_ps_send_pspoll_frame(ieee
);
2222 ieee
->sta_sleep
= LPS_IS_WAKE
;
2223 ieee
->polling
= false;
2227 void rtllib_ps_tx_ack(struct rtllib_device
*ieee
, short success
)
2229 unsigned long flags
,flags2
;
2231 spin_lock_irqsave(&ieee
->lock
, flags
);
2233 if (ieee
->sta_sleep
== LPS_WAIT_NULL_DATA_SEND
){
2234 /* Null frame with PS bit set */
2236 ieee
->sta_sleep
= LPS_IS_SLEEP
;
2237 ieee
->enter_sleep_state(ieee
->dev
, ieee
->ps_time
);
2239 /* if the card report not success we can't be sure the AP
2240 * has not RXed so we can't assume the AP believe us awake
2242 } else {/* 21112005 - tx again null without PS bit if lost */
2244 if ((ieee
->sta_sleep
== LPS_IS_WAKE
) && !success
){
2245 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2246 if (ieee
->pHTInfo
->IOTAction
& HT_IOT_ACT_NULL_DATA_POWER_SAVING
)
2248 rtllib_sta_ps_send_null_frame(ieee
, 0);
2252 rtllib_sta_ps_send_pspoll_frame(ieee
);
2254 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2257 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2260 void rtllib_process_action(struct rtllib_device
* ieee
, struct sk_buff
* skb
)
2262 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2263 u8
* act
= rtllib_get_payload((struct rtllib_hdr
*)header
);
2267 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "error to get payload of action frame\n");
2277 rtllib_rx_ADDBAReq(ieee
, skb
);
2280 rtllib_rx_ADDBARsp(ieee
, skb
);
2283 rtllib_rx_DELBA(ieee
, skb
);
2293 inline int rtllib_rx_assoc_resp(struct rtllib_device
*ieee
, struct sk_buff
*skb
, struct rtllib_rx_stats
*rx_stats
)
2298 struct rtllib_assoc_response_frame
*assoc_resp
;
2299 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2301 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2302 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2304 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2305 ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATED
&&
2306 (ieee
->iw_mode
== IW_MODE_INFRA
))
2308 if (0 == (errcode
=assoc_parse(ieee
,skb
, &aid
))){
2309 struct rtllib_network
*network
= kzalloc(sizeof(struct rtllib_network
), GFP_ATOMIC
);
2313 memset(network
,0,sizeof(*network
));
2314 ieee
->state
=RTLLIB_LINKED
;
2315 ieee
->assoc_id
= aid
;
2316 ieee
->softmac_stats
.rx_ass_ok
++;
2317 /* station support qos */
2318 /* Let the register setting defaultly with Legacy station */
2319 assoc_resp
= (struct rtllib_assoc_response_frame
*)skb
->data
;
2320 if (ieee
->current_network
.qos_data
.supported
== 1) {
2321 if (rtllib_parse_info_param(ieee
,assoc_resp
->info_element
,\
2322 rx_stats
->len
- sizeof(*assoc_resp
),\
2329 memcpy(ieee
->pHTInfo
->PeerHTCapBuf
, network
->bssht
.bdHTCapBuf
, network
->bssht
.bdHTCapLen
);
2330 memcpy(ieee
->pHTInfo
->PeerHTInfoBuf
, network
->bssht
.bdHTInfoBuf
, network
->bssht
.bdHTInfoLen
);
2332 if (ieee
->handle_assoc_response
!= NULL
)
2333 ieee
->handle_assoc_response(ieee
->dev
, (struct rtllib_assoc_response_frame
*)header
, network
);
2337 if (ieee
->assocresp_ies
){
2338 kfree(ieee
->assocresp_ies
);
2339 ieee
->assocresp_ies
= NULL
;
2341 ies
= &(assoc_resp
->info_element
[0].id
);
2342 ieee
->assocresp_ies_len
= (skb
->data
+ skb
->len
) - ies
;
2343 ieee
->assocresp_ies
= kmalloc(ieee
->assocresp_ies_len
, GFP_ATOMIC
);
2344 if (ieee
->assocresp_ies
)
2345 memcpy(ieee
->assocresp_ies
, ies
, ieee
->assocresp_ies_len
);
2347 printk("%s()Warning: can't alloc memory for assocresp_ies\n", __func__
);
2348 ieee
->assocresp_ies_len
= 0;
2350 rtllib_associate_complete(ieee
);
2352 /* aid could not been allocated */
2353 ieee
->softmac_stats
.rx_ass_err
++;
2355 "Association response status code 0x%x\n",
2358 "Association response status code 0x%x\n",
2360 if (ieee
->AsocRetryCount
< RT_ASOC_RETRY_LIMIT
) {
2361 queue_delayed_work_rsl(ieee
->wq
, &ieee
->associate_procedure_wq
, 0);
2363 rtllib_associate_abort(ieee
);
2371 inline int rtllib_rx_auth(struct rtllib_device
*ieee
, struct sk_buff
*skb
, struct rtllib_rx_stats
*rx_stats
)
2376 bool bSupportNmode
= true, bHalfSupportNmode
= false;
2378 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
){
2379 if (ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATING
&&
2380 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2381 RTLLIB_DEBUG_MGMT("Received authentication response");
2383 if (0 == (errcode
=auth_parse(skb
, &challenge
, &chlen
))) {
2384 if (ieee
->open_wep
|| !challenge
){
2385 ieee
->state
= RTLLIB_ASSOCIATING_AUTHENTICATED
;
2386 ieee
->softmac_stats
.rx_auth_rs_ok
++;
2387 if (!(ieee
->pHTInfo
->IOTAction
&HT_IOT_ACT_PURE_N_MODE
))
2389 if (!ieee
->GetNmodeSupportBySecCfg(ieee
->dev
))
2391 if (IsHTHalfNmodeAPs(ieee
))
2393 bSupportNmode
= true;
2394 bHalfSupportNmode
= true;
2398 bSupportNmode
= false;
2399 bHalfSupportNmode
= false;
2403 /* Dummy wirless mode setting to avoid encryption issue */
2404 if (bSupportNmode
) {
2405 ieee
->SetWirelessMode(ieee
->dev
, \
2406 ieee
->current_network
.mode
);
2409 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
2412 if (ieee
->current_network
.mode
== IEEE_N_24G
&& bHalfSupportNmode
== true)
2414 printk("===============>entern half N mode\n");
2415 ieee
->bHalfWirelessN24GMode
= true;
2418 ieee
->bHalfWirelessN24GMode
= false;
2420 rtllib_associate_step2(ieee
);
2422 rtllib_auth_challenge(ieee
, challenge
, chlen
);
2425 ieee
->softmac_stats
.rx_auth_rs_err
++;
2426 RTLLIB_DEBUG_MGMT("Authentication respose status code 0x%x",errcode
);
2428 printk("Authentication respose status code 0x%x",errcode
);
2429 rtllib_associate_abort(ieee
);
2432 }else if (ieee
->iw_mode
== IW_MODE_MASTER
){
2433 rtllib_rx_auth_rq(ieee
, skb
);
2440 inline int rtllib_rx_deauth(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
2442 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2444 if (memcmp(header
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
) != 0)
2447 /* FIXME for now repeat all the association procedure
2448 * both for disassociation and deauthentication
2450 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2451 ieee
->state
== RTLLIB_LINKED
&&
2452 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2453 printk(KERN_INFO
"==========>received disassoc/deauth(%x) "
2454 "frame, reason code:%x\n",
2455 WLAN_FC_GET_STYPE(header
->frame_ctl
),
2456 ((struct rtllib_disassoc
*)skb
->data
)->reason
);
2457 ieee
->state
= RTLLIB_ASSOCIATING
;
2458 ieee
->softmac_stats
.reassoc
++;
2459 ieee
->is_roaming
= true;
2460 ieee
->LinkDetectInfo
.bBusyTraffic
= false;
2461 rtllib_disassociate(ieee
);
2462 RemovePeerTS(ieee
, header
->addr2
);
2463 if (ieee
->LedControlHandler
!= NULL
)
2464 ieee
->LedControlHandler(ieee
->dev
, LED_CTL_START_TO_LINK
);
2466 if (!(ieee
->rtllib_ap_sec_type(ieee
)&(SEC_ALG_CCMP
|SEC_ALG_TKIP
)))
2467 queue_delayed_work_rsl(ieee
->wq
, &ieee
->associate_procedure_wq
, 5);
2473 inline int rtllib_rx_frame_softmac(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
2474 struct rtllib_rx_stats
*rx_stats
, u16 type
,
2477 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2479 if (!ieee
->proto_started
)
2482 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2484 case RTLLIB_STYPE_ASSOC_RESP
:
2485 case RTLLIB_STYPE_REASSOC_RESP
:
2487 if (rtllib_rx_assoc_resp(ieee
, skb
, rx_stats
) == 1)
2492 case RTLLIB_STYPE_ASSOC_REQ
:
2493 case RTLLIB_STYPE_REASSOC_REQ
:
2495 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2496 ieee
->iw_mode
== IW_MODE_MASTER
)
2498 rtllib_rx_assoc_rq(ieee
, skb
);
2501 case RTLLIB_STYPE_AUTH
:
2503 rtllib_rx_auth(ieee
, skb
, rx_stats
);
2506 case RTLLIB_STYPE_DISASSOC
:
2507 case RTLLIB_STYPE_DEAUTH
:
2509 rtllib_rx_deauth(ieee
, skb
);
2513 case RTLLIB_STYPE_MANAGE_ACT
:
2514 rtllib_process_action(ieee
,skb
);
2524 /* following are for a simplier TX queue management.
2525 * Instead of using netif_[stop/wake]_queue the driver
2526 * will uses these two function (plus a reset one), that
2527 * will internally uses the kernel netif_* and takes
2528 * care of the ieee802.11 fragmentation.
2529 * So the driver receives a fragment per time and might
2530 * call the stop function when it want without take care
2531 * to have enought room to TX an entire packet.
2532 * This might be useful if each fragment need it's own
2533 * descriptor, thus just keep a total free memory > than
2534 * the max fragmentation treshold is not enought.. If the
2535 * ieee802.11 stack passed a TXB struct then you needed
2536 * to keep N free descriptors where
2537 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2538 * In this way you need just one and the 802.11 stack
2539 * will take care of buffering fragments and pass them to
2540 * to the driver later, when it wakes the queue.
2542 void rtllib_softmac_xmit(struct rtllib_txb
*txb
, struct rtllib_device
*ieee
)
2545 unsigned int queue_index
= txb
->queue_index
;
2546 unsigned long flags
;
2548 struct cb_desc
*tcb_desc
= NULL
;
2549 unsigned long queue_len
= 0;
2551 spin_lock_irqsave(&ieee
->lock
,flags
);
2553 /* called with 2nd parm 0, no tx mgmt lock required */
2554 rtllib_sta_wakeup(ieee
,0);
2556 /* update the tx status */
2557 tcb_desc
= (struct cb_desc
*)(txb
->fragments
[0]->cb
+ MAX_DEV_ADDR_SIZE
);
2558 if (tcb_desc
->bMulticast
) {
2559 ieee
->stats
.multicast
++;
2562 /* if xmit available, just xmit it immediately, else just insert it to the wait queue */
2563 for (i
= 0; i
< txb
->nr_frags
; i
++) {
2564 queue_len
= skb_queue_len(&ieee
->skb_waitQ
[queue_index
]);
2565 if ((queue_len
!= 0) ||\
2566 (!ieee
->check_nic_enough_desc(ieee
->dev
,queue_index
))||\
2567 (ieee
->queue_stop
)) {
2568 /* insert the skb packet to the wait queue */
2569 /* as for the completion function, it does not need
2570 * to check it any more.
2572 if (queue_len
< 200)
2574 skb_queue_tail(&ieee
->skb_waitQ
[queue_index
], txb
->fragments
[i
]);
2576 kfree_skb(txb
->fragments
[i
]);
2579 ieee
->softmac_data_hard_start_xmit(
2581 ieee
->dev
,ieee
->rate
);
2585 rtllib_txb_free(txb
);
2587 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2591 /* called with ieee->lock acquired */
2592 void rtllib_resume_tx(struct rtllib_device
*ieee
)
2595 for (i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
; i
++) {
2597 if (ieee
->queue_stop
){
2598 ieee
->tx_pending
.frag
= i
;
2602 ieee
->softmac_data_hard_start_xmit(
2603 ieee
->tx_pending
.txb
->fragments
[i
],
2604 ieee
->dev
,ieee
->rate
);
2605 ieee
->stats
.tx_packets
++;
2609 rtllib_txb_free(ieee
->tx_pending
.txb
);
2610 ieee
->tx_pending
.txb
= NULL
;
2614 void rtllib_reset_queue(struct rtllib_device
*ieee
)
2616 unsigned long flags
;
2618 spin_lock_irqsave(&ieee
->lock
,flags
);
2619 init_mgmt_queue(ieee
);
2620 if (ieee
->tx_pending
.txb
){
2621 rtllib_txb_free(ieee
->tx_pending
.txb
);
2622 ieee
->tx_pending
.txb
= NULL
;
2624 ieee
->queue_stop
= 0;
2625 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2629 void rtllib_wake_queue(struct rtllib_device
*ieee
)
2632 unsigned long flags
;
2633 struct sk_buff
*skb
;
2634 struct rtllib_hdr_3addr
*header
;
2636 spin_lock_irqsave(&ieee
->lock
,flags
);
2637 if (! ieee
->queue_stop
) goto exit
;
2639 ieee
->queue_stop
= 0;
2641 if (ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
){
2642 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))){
2644 header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2646 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2648 if (ieee
->seq_ctrl
[0] == 0xFFF)
2649 ieee
->seq_ctrl
[0] = 0;
2651 ieee
->seq_ctrl
[0]++;
2653 ieee
->softmac_data_hard_start_xmit(skb
,ieee
->dev
,ieee
->basic_rate
);
2656 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2657 rtllib_resume_tx(ieee
);
2659 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)){
2660 ieee
->softmac_stats
.swtxawake
++;
2661 netif_wake_queue(ieee
->dev
);
2665 spin_unlock_irqrestore(&ieee
->lock
,flags
);
2669 void rtllib_stop_queue(struct rtllib_device
*ieee
)
2672 if (! netif_queue_stopped(ieee
->dev
)){
2673 netif_stop_queue(ieee
->dev
);
2674 ieee
->softmac_stats
.swtxstop
++;
2676 ieee
->queue_stop
= 1;
2680 void rtllib_stop_all_queues(struct rtllib_device
*ieee
)
2683 for (i
=0; i
< ieee
->dev
->num_tx_queues
; i
++)
2684 netdev_get_tx_queue(ieee
->dev
,i
)->trans_start
= jiffies
;
2686 netif_tx_stop_all_queues(ieee
->dev
);
2689 void rtllib_wake_all_queues(struct rtllib_device
*ieee
)
2691 netif_tx_wake_all_queues(ieee
->dev
);
2694 inline void rtllib_randomize_cell(struct rtllib_device
*ieee
)
2697 get_random_bytes(ieee
->current_network
.bssid
, ETH_ALEN
);
2699 /* an IBSS cell address must have the two less significant
2700 * bits of the first byte = 2
2702 ieee
->current_network
.bssid
[0] &= ~0x01;
2703 ieee
->current_network
.bssid
[0] |= 0x02;
2706 /* called in user context only */
2707 void rtllib_start_master_bss(struct rtllib_device
*ieee
)
2711 if (ieee
->current_network
.ssid_len
== 0){
2712 strncpy(ieee
->current_network
.ssid
,
2713 RTLLIB_DEFAULT_TX_ESSID
,
2716 ieee
->current_network
.ssid_len
= strlen(RTLLIB_DEFAULT_TX_ESSID
);
2720 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2722 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2723 ieee
->state
= RTLLIB_LINKED
;
2724 ieee
->link_change(ieee
->dev
);
2725 notify_wx_assoc_event(ieee
);
2727 if (ieee
->data_hard_resume
)
2728 ieee
->data_hard_resume(ieee
->dev
);
2730 netif_carrier_on(ieee
->dev
);
2733 void rtllib_start_monitor_mode(struct rtllib_device
*ieee
)
2735 /* reset hardware status */
2737 if (ieee
->data_hard_resume
)
2738 ieee
->data_hard_resume(ieee
->dev
);
2740 netif_carrier_on(ieee
->dev
);
2744 void rtllib_start_ibss_wq(void *data
)
2746 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
, struct rtllib_device
, start_ibss_wq
);
2747 /* iwconfig mode ad-hoc will schedule this and return
2748 * on the other hand this will block further iwconfig SET
2749 * operations because of the wx_sem hold.
2750 * Anyway some most set operations set a flag to speed-up
2751 * (abort) this wq (when syncro scanning) before sleeping
2754 if (!ieee
->proto_started
){
2755 printk("==========oh driver down return\n");
2758 down(&ieee
->wx_sem
);
2760 if (ieee
->current_network
.ssid_len
== 0){
2761 strcpy(ieee
->current_network
.ssid
,RTLLIB_DEFAULT_TX_ESSID
);
2762 ieee
->current_network
.ssid_len
= strlen(RTLLIB_DEFAULT_TX_ESSID
);
2766 ieee
->state
= RTLLIB_NOLINK
;
2767 ieee
->mode
= IEEE_G
;
2768 /* check if we have this cell in our network list */
2769 rtllib_softmac_check_all_nets(ieee
);
2772 /* if not then the state is not linked. Maybe the user swithced to
2773 * ad-hoc mode just after being in monitor mode, or just after
2774 * being very few time in managed mode (so the card have had no
2775 * time to scan all the chans..) or we have just run up the iface
2776 * after setting ad-hoc mode. So we have to give another try..
2777 * Here, in ibss mode, should be safe to do this without extra care
2778 * (in bss mode we had to make sure no-one tryed to associate when
2779 * we had just checked the ieee->state and we was going to start the
2780 * scan) beacause in ibss mode the rtllib_new_net function, when
2781 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2782 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2783 * scan, that will stop at the first round because it sees the state
2786 if (ieee
->state
== RTLLIB_NOLINK
)
2787 rtllib_start_scan_syncro(ieee
, 0);
2789 /* the network definitively is not here.. create a new cell */
2790 if (ieee
->state
== RTLLIB_NOLINK
){
2791 printk("creating new IBSS cell\n");
2792 ieee
->current_network
.channel
= ieee
->IbssStartChnl
;
2794 rtllib_randomize_cell(ieee
);
2796 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
){
2798 ieee
->current_network
.rates_len
= 4;
2800 ieee
->current_network
.rates
[0] = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_1MB
;
2801 ieee
->current_network
.rates
[1] = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_2MB
;
2802 ieee
->current_network
.rates
[2] = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_5MB
;
2803 ieee
->current_network
.rates
[3] = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_11MB
;
2806 ieee
->current_network
.rates_len
= 0;
2808 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
){
2809 ieee
->current_network
.rates_ex_len
= 8;
2811 /*ieee->current_network.rates_ex[0] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB;
2812 ieee->current_network.rates_ex[1] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB;
2813 ieee->current_network.rates_ex[2] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB;
2814 ieee->current_network.rates_ex[3] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB;
2815 ieee->current_network.rates_ex[4] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB;
2816 ieee->current_network.rates_ex[5] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB;
2817 ieee->current_network.rates_ex[6] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB;
2818 ieee->current_network.rates_ex[7] = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB;*/
2820 ieee
->current_network
.rates_ex
[0] = RTLLIB_OFDM_RATE_6MB
;
2821 ieee
->current_network
.rates_ex
[1] = RTLLIB_OFDM_RATE_9MB
;
2822 ieee
->current_network
.rates_ex
[2] = RTLLIB_OFDM_RATE_12MB
;
2823 ieee
->current_network
.rates_ex
[3] = RTLLIB_OFDM_RATE_18MB
;
2824 ieee
->current_network
.rates_ex
[4] = RTLLIB_OFDM_RATE_24MB
;
2825 ieee
->current_network
.rates_ex
[5] = RTLLIB_OFDM_RATE_36MB
;
2826 ieee
->current_network
.rates_ex
[6] = RTLLIB_OFDM_RATE_48MB
;
2827 ieee
->current_network
.rates_ex
[7] = RTLLIB_OFDM_RATE_54MB
;
2831 ieee
->current_network
.rates_ex_len
= 0;
2835 ieee
->current_network
.qos_data
.supported
= 0;
2836 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
2837 ieee
->current_network
.mode
= ieee
->mode
;
2838 ieee
->current_network
.atim_window
= 0;
2839 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2842 printk("%s(): ieee->mode = %d\n", __func__
, ieee
->mode
);
2843 if ((ieee
->mode
== IEEE_N_24G
) || (ieee
->mode
== IEEE_N_5G
))
2844 HTUseDefaultSetting(ieee
);
2846 ieee
->pHTInfo
->bCurrentHTSupport
= false;
2848 ieee
->SetHwRegHandler(ieee
->dev
, HW_VAR_MEDIA_STATUS
, (u8
*)(&ieee
->state
));
2850 ieee
->state
= RTLLIB_LINKED
;
2851 ieee
->link_change(ieee
->dev
);
2853 HTSetConnectBwMode(ieee
, HT_CHANNEL_WIDTH_20
, HT_EXTCHNL_OFFSET_NO_EXT
);
2854 if (ieee
->LedControlHandler
!= NULL
)
2855 ieee
->LedControlHandler(ieee
->dev
,LED_CTL_LINK
);
2857 rtllib_start_send_beacons(ieee
);
2859 notify_wx_assoc_event(ieee
);
2861 if (ieee
->data_hard_resume
)
2862 ieee
->data_hard_resume(ieee
->dev
);
2864 netif_carrier_on(ieee
->dev
);
2869 inline void rtllib_start_ibss(struct rtllib_device
*ieee
)
2871 queue_delayed_work_rsl(ieee
->wq
, &ieee
->start_ibss_wq
, MSECS(150));
2874 /* this is called only in user context, with wx_sem held */
2875 void rtllib_start_bss(struct rtllib_device
*ieee
)
2877 unsigned long flags
;
2878 if (IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
))
2880 if (! ieee
->bGlobalDomain
)
2885 /* check if we have already found the net we
2886 * are interested in (if any).
2887 * if not (we are disassociated and we are not
2888 * in associating / authenticating phase) start the background scanning.
2890 rtllib_softmac_check_all_nets(ieee
);
2892 /* ensure no-one start an associating process (thus setting
2893 * the ieee->state to rtllib_ASSOCIATING) while we
2894 * have just cheked it and we are going to enable scan.
2895 * The rtllib_new_net function is always called with
2896 * lock held (from both rtllib_softmac_check_all_nets and
2897 * the rx path), so we cannot be in the middle of such function
2899 spin_lock_irqsave(&ieee
->lock
, flags
);
2901 if (ieee
->state
== RTLLIB_NOLINK
) {
2902 rtllib_start_scan(ieee
);
2904 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2907 void rtllib_link_change_wq(void *data
)
2909 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
, struct rtllib_device
, link_change_wq
);
2910 ieee
->link_change(ieee
->dev
);
2912 /* called only in userspace context */
2913 void rtllib_disassociate(struct rtllib_device
*ieee
)
2915 netif_carrier_off(ieee
->dev
);
2916 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2917 rtllib_reset_queue(ieee
);
2919 if (ieee
->data_hard_stop
)
2920 ieee
->data_hard_stop(ieee
->dev
);
2921 if (IS_DOT11D_ENABLE(ieee
))
2923 ieee
->state
= RTLLIB_NOLINK
;
2924 ieee
->is_set_key
= false;
2927 queue_delayed_work_rsl(ieee
->wq
, &ieee
->link_change_wq
, 0);
2929 notify_wx_assoc_event(ieee
);
2932 void rtllib_associate_retry_wq(void *data
)
2934 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
, struct rtllib_device
, associate_retry_wq
);
2935 unsigned long flags
;
2937 down(&ieee
->wx_sem
);
2938 if (!ieee
->proto_started
)
2941 if (ieee
->state
!= RTLLIB_ASSOCIATING_RETRY
)
2944 /* until we do not set the state to RTLLIB_NOLINK
2945 * there are no possibility to have someone else trying
2946 * to start an association procdure (we get here with
2947 * ieee->state = RTLLIB_ASSOCIATING).
2948 * When we set the state to RTLLIB_NOLINK it is possible
2949 * that the RX path run an attempt to associate, but
2950 * both rtllib_softmac_check_all_nets and the
2951 * RX path works with ieee->lock held so there are no
2952 * problems. If we are still disassociated then start a scan.
2953 * the lock here is necessary to ensure no one try to start
2954 * an association procedure when we have just checked the
2955 * state and we are going to start the scan.
2957 ieee
->beinretry
= true;
2958 ieee
->state
= RTLLIB_NOLINK
;
2960 rtllib_softmac_check_all_nets(ieee
);
2962 spin_lock_irqsave(&ieee
->lock
, flags
);
2964 if (ieee
->state
== RTLLIB_NOLINK
)
2966 rtllib_start_scan(ieee
);
2968 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2970 ieee
->beinretry
= false;
2975 struct sk_buff
*rtllib_get_beacon_(struct rtllib_device
*ieee
)
2977 u8 broadcast_addr
[] = {0xff,0xff,0xff,0xff,0xff,0xff};
2979 struct sk_buff
*skb
;
2980 struct rtllib_probe_response
*b
;
2981 skb
= rtllib_probe_resp(ieee
, broadcast_addr
);
2986 b
= (struct rtllib_probe_response
*) skb
->data
;
2987 b
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_BEACON
);
2993 struct sk_buff
*rtllib_get_beacon(struct rtllib_device
*ieee
)
2995 struct sk_buff
*skb
;
2996 struct rtllib_probe_response
*b
;
2998 skb
= rtllib_get_beacon_(ieee
);
3002 b
= (struct rtllib_probe_response
*) skb
->data
;
3003 b
->header
.seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
3005 if (ieee
->seq_ctrl
[0] == 0xFFF)
3006 ieee
->seq_ctrl
[0] = 0;
3008 ieee
->seq_ctrl
[0]++;
3013 void rtllib_softmac_stop_protocol(struct rtllib_device
*ieee
, u8 mesh_flag
, u8 shutdown
)
3015 rtllib_stop_scan_syncro(ieee
);
3016 down(&ieee
->wx_sem
);
3017 rtllib_stop_protocol(ieee
,shutdown
);
3022 void rtllib_stop_protocol(struct rtllib_device
*ieee
, u8 shutdown
)
3024 if (!ieee
->proto_started
)
3028 ieee
->proto_started
= 0;
3029 ieee
->proto_stoppping
= 1;
3030 if (ieee
->rtllib_ips_leave
!= NULL
)
3031 ieee
->rtllib_ips_leave(ieee
->dev
);
3034 rtllib_stop_send_beacons(ieee
);
3035 del_timer_sync(&ieee
->associate_timer
);
3036 cancel_delayed_work(&ieee
->associate_retry_wq
);
3037 cancel_delayed_work(&ieee
->start_ibss_wq
);
3038 cancel_delayed_work(&ieee
->link_change_wq
);
3039 rtllib_stop_scan(ieee
);
3041 if (ieee
->state
<= RTLLIB_ASSOCIATING_AUTHENTICATED
)
3042 ieee
->state
= RTLLIB_NOLINK
;
3044 if (ieee
->state
== RTLLIB_LINKED
){
3045 if (ieee
->iw_mode
== IW_MODE_INFRA
)
3046 SendDisassociation(ieee
,1,deauth_lv_ss
);
3047 rtllib_disassociate(ieee
);
3052 ieee
->proto_stoppping
= 0;
3054 if (ieee
->assocreq_ies
) {
3055 kfree(ieee
->assocreq_ies
);
3056 ieee
->assocreq_ies
= NULL
;
3057 ieee
->assocreq_ies_len
= 0;
3059 if (ieee
->assocresp_ies
) {
3060 kfree(ieee
->assocresp_ies
);
3061 ieee
->assocresp_ies
= NULL
;
3062 ieee
->assocresp_ies_len
= 0;
3066 void rtllib_softmac_start_protocol(struct rtllib_device
*ieee
, u8 mesh_flag
)
3068 down(&ieee
->wx_sem
);
3069 rtllib_start_protocol(ieee
);
3073 void rtllib_start_protocol(struct rtllib_device
*ieee
)
3078 rtllib_update_active_chan_map(ieee
);
3080 if (ieee
->proto_started
)
3083 ieee
->proto_started
= 1;
3085 if (ieee
->current_network
.channel
== 0) {
3088 if (ch
> MAX_CHANNEL_NUMBER
)
3089 return; /* no channel found */
3090 } while(!ieee
->active_channel_map
[ch
]);
3091 ieee
->current_network
.channel
= ch
;
3094 if (ieee
->current_network
.beacon_interval
== 0)
3095 ieee
->current_network
.beacon_interval
= 100;
3097 for (i
= 0; i
< 17; i
++) {
3098 ieee
->last_rxseq_num
[i
] = -1;
3099 ieee
->last_rxfrag_num
[i
] = -1;
3100 ieee
->last_packet_time
[i
] = 0;
3103 if (ieee
->UpdateBeaconInterruptHandler
)
3104 ieee
->UpdateBeaconInterruptHandler(ieee
->dev
, false);
3107 /* if the user set the MAC of the ad-hoc cell and then
3108 * switch to managed mode, shall we make sure that association
3109 * attempts does not fail just because the user provide the essid
3110 * and the nic is still checking for the AP MAC ??
3112 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
3113 rtllib_start_bss(ieee
);
3114 } else if (ieee
->iw_mode
== IW_MODE_ADHOC
) {
3115 if (ieee
->UpdateBeaconInterruptHandler
)
3116 ieee
->UpdateBeaconInterruptHandler(ieee
->dev
, true);
3118 rtllib_start_ibss(ieee
);
3120 } else if (ieee
->iw_mode
== IW_MODE_MASTER
) {
3121 rtllib_start_master_bss(ieee
);
3122 } else if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
3123 rtllib_start_monitor_mode(ieee
);
3127 void rtllib_softmac_init(struct rtllib_device
*ieee
)
3130 memset(&ieee
->current_network
, 0, sizeof(struct rtllib_network
));
3132 ieee
->state
= RTLLIB_NOLINK
;
3133 for (i
= 0; i
< 5; i
++) {
3134 ieee
->seq_ctrl
[i
] = 0;
3136 ieee
->pDot11dInfo
= kmalloc(sizeof(struct rt_dot11d_info
), GFP_ATOMIC
);
3137 if (!ieee
->pDot11dInfo
)
3138 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "can't alloc memory for DOT11D\n");
3139 memset(ieee
->pDot11dInfo
, 0, sizeof(struct rt_dot11d_info
));
3140 ieee
->LinkDetectInfo
.SlotIndex
= 0;
3141 ieee
->LinkDetectInfo
.SlotNum
= 2;
3142 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
=0;
3143 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
=0;
3144 ieee
->LinkDetectInfo
.NumTxOkInPeriod
=0;
3145 ieee
->LinkDetectInfo
.NumRxOkInPeriod
=0;
3146 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
=0;
3147 ieee
->bIsAggregateFrame
= false;
3149 ieee
->queue_stop
= 0;
3150 ieee
->scanning_continue
= 0;
3151 ieee
->softmac_features
= 0;
3154 ieee
->proto_started
= 0;
3155 ieee
->proto_stoppping
= 0;
3156 ieee
->basic_rate
= RTLLIB_DEFAULT_BASIC_RATE
;
3158 ieee
->ps
= RTLLIB_PS_DISABLED
;
3159 ieee
->sta_sleep
= LPS_IS_WAKE
;
3161 ieee
->Regdot11HTOperationalRateSet
[0]= 0xff;
3162 ieee
->Regdot11HTOperationalRateSet
[1]= 0xff;
3163 ieee
->Regdot11HTOperationalRateSet
[4]= 0x01;
3165 ieee
->Regdot11TxHTOperationalRateSet
[0]= 0xff;
3166 ieee
->Regdot11TxHTOperationalRateSet
[1]= 0xff;
3167 ieee
->Regdot11TxHTOperationalRateSet
[4]= 0x01;
3169 ieee
->FirstIe_InScan
= false;
3170 ieee
->actscanning
= false;
3171 ieee
->beinretry
= false;
3172 ieee
->is_set_key
= false;
3173 init_mgmt_queue(ieee
);
3175 ieee
->sta_edca_param
[0] = 0x0000A403;
3176 ieee
->sta_edca_param
[1] = 0x0000A427;
3177 ieee
->sta_edca_param
[2] = 0x005E4342;
3178 ieee
->sta_edca_param
[3] = 0x002F3262;
3179 ieee
->aggregation
= true;
3180 ieee
->enable_rx_imm_BA
= 1;
3181 ieee
->tx_pending
.txb
= NULL
;
3183 _setup_timer(&ieee
->associate_timer
,
3184 rtllib_associate_abort_cb
,
3185 (unsigned long) ieee
);
3187 _setup_timer(&ieee
->beacon_timer
,
3188 rtllib_send_beacon_cb
,
3189 (unsigned long) ieee
);
3192 ieee
->wq
= create_workqueue(DRV_NAME
);
3194 INIT_DELAYED_WORK_RSL(&ieee
->link_change_wq
,(void*)rtllib_link_change_wq
,ieee
);
3195 INIT_DELAYED_WORK_RSL(&ieee
->start_ibss_wq
,(void*)rtllib_start_ibss_wq
,ieee
);
3196 INIT_WORK_RSL(&ieee
->associate_complete_wq
, (void*)rtllib_associate_complete_wq
,ieee
);
3197 INIT_DELAYED_WORK_RSL(&ieee
->associate_procedure_wq
, (void*)rtllib_associate_procedure_wq
,ieee
);
3198 INIT_DELAYED_WORK_RSL(&ieee
->softmac_scan_wq
,(void*)rtllib_softmac_scan_wq
,ieee
);
3199 INIT_DELAYED_WORK_RSL(&ieee
->softmac_hint11d_wq
,(void*)rtllib_softmac_hint11d_wq
,ieee
);
3200 INIT_DELAYED_WORK_RSL(&ieee
->associate_retry_wq
, (void*)rtllib_associate_retry_wq
,ieee
);
3201 INIT_WORK_RSL(&ieee
->wx_sync_scan_wq
,(void*)rtllib_wx_sync_scan_wq
,ieee
);
3203 sema_init(&ieee
->wx_sem
, 1);
3204 sema_init(&ieee
->scan_sem
, 1);
3205 sema_init(&ieee
->ips_sem
,1);
3207 spin_lock_init(&ieee
->mgmt_tx_lock
);
3208 spin_lock_init(&ieee
->beacon_lock
);
3210 tasklet_init(&ieee
->ps_task
,
3211 (void(*)(unsigned long)) rtllib_sta_ps
,
3212 (unsigned long)ieee
);
3216 void rtllib_softmac_free(struct rtllib_device
*ieee
)
3218 down(&ieee
->wx_sem
);
3219 if (NULL
!= ieee
->pDot11dInfo
)
3221 kfree(ieee
->pDot11dInfo
);
3222 ieee
->pDot11dInfo
= NULL
;
3224 del_timer_sync(&ieee
->associate_timer
);
3226 cancel_delayed_work(&ieee
->associate_retry_wq
);
3227 destroy_workqueue(ieee
->wq
);
3231 /********************************************************
3232 * Start of WPA code. *
3233 * this is stolen from the ipw2200 driver *
3234 ********************************************************/
3237 static int rtllib_wpa_enable(struct rtllib_device
*ieee
, int value
)
3239 /* This is called when wpa_supplicant loads and closes the driver
3241 printk("%s WPA\n",value
? "enabling" : "disabling");
3242 ieee
->wpa_enabled
= value
;
3243 memset(ieee
->ap_mac_addr
, 0, 6);
3248 void rtllib_wpa_assoc_frame(struct rtllib_device
*ieee
, char *wpa_ie
, int wpa_ie_len
)
3250 /* make sure WPA is enabled */
3251 rtllib_wpa_enable(ieee
, 1);
3253 rtllib_disassociate(ieee
);
3257 static int rtllib_wpa_mlme(struct rtllib_device
*ieee
, int command
, int reason
)
3263 case IEEE_MLME_STA_DEAUTH
:
3266 case IEEE_MLME_STA_DISASSOC
:
3267 rtllib_disassociate(ieee
);
3271 printk("Unknown MLME request: %d\n", command
);
3279 static int rtllib_wpa_set_wpa_ie(struct rtllib_device
*ieee
,
3280 struct ieee_param
*param
, int plen
)
3284 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
3285 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
3288 if (param
->u
.wpa_ie
.len
) {
3289 buf
= kmalloc(param
->u
.wpa_ie
.len
, GFP_KERNEL
);
3293 memcpy(buf
, param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
);
3294 kfree(ieee
->wpa_ie
);
3296 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
3298 kfree(ieee
->wpa_ie
);
3299 ieee
->wpa_ie
= NULL
;
3300 ieee
->wpa_ie_len
= 0;
3303 rtllib_wpa_assoc_frame(ieee
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
3307 #define AUTH_ALG_OPEN_SYSTEM 0x1
3308 #define AUTH_ALG_SHARED_KEY 0x2
3309 #define AUTH_ALG_LEAP 0x4
3310 static int rtllib_wpa_set_auth_algs(struct rtllib_device
*ieee
, int value
)
3313 struct rtllib_security sec
= {
3314 .flags
= SEC_AUTH_MODE
,
3318 if (value
& AUTH_ALG_SHARED_KEY
) {
3319 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
3321 ieee
->auth_mode
= 1;
3322 } else if (value
& AUTH_ALG_OPEN_SYSTEM
){
3323 sec
.auth_mode
= WLAN_AUTH_OPEN
;
3325 ieee
->auth_mode
= 0;
3327 else if (value
& AUTH_ALG_LEAP
){
3328 sec
.auth_mode
= WLAN_AUTH_LEAP
>> 6;
3330 ieee
->auth_mode
= 2;
3334 if (ieee
->set_security
)
3335 ieee
->set_security(ieee
->dev
, &sec
);
3340 static int rtllib_wpa_set_param(struct rtllib_device
*ieee
, u8 name
, u32 value
)
3343 unsigned long flags
;
3346 case IEEE_PARAM_WPA_ENABLED
:
3347 ret
= rtllib_wpa_enable(ieee
, value
);
3350 case IEEE_PARAM_TKIP_COUNTERMEASURES
:
3351 ieee
->tkip_countermeasures
=value
;
3354 case IEEE_PARAM_DROP_UNENCRYPTED
:
3358 * wpa_supplicant calls set_wpa_enabled when the driver
3359 * is loaded and unloaded, regardless of if WPA is being
3360 * used. No other calls are made which can be used to
3361 * determine if encryption will be used or not prior to
3362 * association being expected. If encryption is not being
3363 * used, drop_unencrypted is set to false, else true -- we
3364 * can use this to determine if the CAP_PRIVACY_ON bit should
3367 struct rtllib_security sec
= {
3368 .flags
= SEC_ENABLED
,
3371 ieee
->drop_unencrypted
= value
;
3372 /* We only change SEC_LEVEL for open mode. Others
3373 * are set by ipw_wpa_set_encryption.
3376 sec
.flags
|= SEC_LEVEL
;
3377 sec
.level
= SEC_LEVEL_0
;
3380 sec
.flags
|= SEC_LEVEL
;
3381 sec
.level
= SEC_LEVEL_1
;
3383 if (ieee
->set_security
)
3384 ieee
->set_security(ieee
->dev
, &sec
);
3388 case IEEE_PARAM_PRIVACY_INVOKED
:
3389 ieee
->privacy_invoked
=value
;
3392 case IEEE_PARAM_AUTH_ALGS
:
3393 ret
= rtllib_wpa_set_auth_algs(ieee
, value
);
3396 case IEEE_PARAM_IEEE_802_1X
:
3397 ieee
->ieee802_1x
=value
;
3399 case IEEE_PARAM_WPAX_SELECT
:
3400 spin_lock_irqsave(&ieee
->wpax_suitlist_lock
,flags
);
3401 spin_unlock_irqrestore(&ieee
->wpax_suitlist_lock
,flags
);
3405 printk("Unknown WPA param: %d\n",name
);
3412 /* implementation borrowed from hostap driver */
3413 static int rtllib_wpa_set_encryption(struct rtllib_device
*ieee
,
3414 struct ieee_param
*param
, int param_len
, u8 is_mesh
)
3417 struct rtllib_crypto_ops
*ops
;
3418 struct rtllib_crypt_data
**crypt
;
3420 struct rtllib_security sec
= {
3424 param
->u
.crypt
.err
= 0;
3425 param
->u
.crypt
.alg
[IEEE_CRYPT_ALG_NAME_LEN
- 1] = '\0';
3428 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
3429 param
->u
.crypt
.key_len
) {
3430 printk("Len mismatch %d, %d\n", param_len
,
3431 param
->u
.crypt
.key_len
);
3434 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
3435 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
3436 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
3437 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
3439 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
3444 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
3447 sec
.level
= SEC_LEVEL_0
;
3448 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
3449 rtllib_crypt_delayed_deinit(ieee
, crypt
);
3454 sec
.flags
|= SEC_ENABLED
;
3456 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3457 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
3458 strcmp(param
->u
.crypt
.alg
, "TKIP"))
3459 goto skip_host_crypt
;
3461 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3462 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
3463 request_module("rtllib_crypt_wep");
3464 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3465 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
3466 request_module("rtllib_crypt_tkip");
3467 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3468 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
3469 request_module("rtllib_crypt_ccmp");
3470 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3473 printk("unknown crypto alg '%s'\n", param
->u
.crypt
.alg
);
3474 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
3478 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
3479 struct rtllib_crypt_data
*new_crypt
;
3481 rtllib_crypt_delayed_deinit(ieee
, crypt
);
3483 new_crypt
= (struct rtllib_crypt_data
*)
3484 kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
3485 if (new_crypt
== NULL
) {
3489 memset(new_crypt
, 0, sizeof(struct rtllib_crypt_data
));
3490 new_crypt
->ops
= ops
;
3493 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
3495 if (new_crypt
->priv
== NULL
) {
3497 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
3505 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
3506 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
3507 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
3508 (*crypt
)->priv
) < 0) {
3509 printk("key setting failed\n");
3510 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
3516 if (param
->u
.crypt
.set_tx
) {
3517 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
3518 sec
.active_key
= param
->u
.crypt
.idx
;
3519 sec
.flags
|= SEC_ACTIVE_KEY
;
3521 sec
.flags
&= ~SEC_ACTIVE_KEY
;
3523 if (param
->u
.crypt
.alg
!= NULL
) {
3524 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
3526 param
->u
.crypt
.key_len
);
3527 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
3528 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
3530 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
3531 sec
.flags
|= SEC_LEVEL
;
3532 sec
.level
= SEC_LEVEL_1
;
3533 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
3534 sec
.flags
|= SEC_LEVEL
;
3535 sec
.level
= SEC_LEVEL_2
;
3536 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
3537 sec
.flags
|= SEC_LEVEL
;
3538 sec
.level
= SEC_LEVEL_3
;
3542 if (ieee
->set_security
)
3543 ieee
->set_security(ieee
->dev
, &sec
);
3545 /* Do not reset port if card is in Managed mode since resetting will
3546 * generate new IEEE 802.11 authentication which may end up in looping
3547 * with IEEE 802.1X. If your hardware requires a reset after WEP
3548 * configuration (for example... Prism2), implement the reset_port in
3549 * the callbacks structures used to initialize the 802.11 stack. */
3550 if (ieee
->reset_on_keychange
&&
3551 ieee
->iw_mode
!= IW_MODE_INFRA
&&
3553 ieee
->reset_port(ieee
->dev
)) {
3554 printk("reset_port failed\n");
3555 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
3562 inline struct sk_buff
*rtllib_disauth_skb( struct rtllib_network
*beacon
,
3563 struct rtllib_device
*ieee
, u16 asRsn
)
3565 struct sk_buff
*skb
;
3566 struct rtllib_disauth
*disauth
;
3567 int len
= sizeof(struct rtllib_disauth
) + ieee
->tx_headroom
;
3569 skb
= dev_alloc_skb(len
);
3574 skb_reserve(skb
, ieee
->tx_headroom
);
3576 disauth
= (struct rtllib_disauth
*) skb_put(skb
,sizeof(struct rtllib_disauth
));
3577 disauth
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_DEAUTH
);
3578 disauth
->header
.duration_id
= 0;
3580 memcpy(disauth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
3581 memcpy(disauth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
3582 memcpy(disauth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
3584 disauth
->reason
= cpu_to_le16(asRsn
);
3588 inline struct sk_buff
*rtllib_disassociate_skb( struct rtllib_network
*beacon
,
3589 struct rtllib_device
*ieee
, u16 asRsn
)
3591 struct sk_buff
*skb
;
3592 struct rtllib_disassoc
*disass
;
3593 int len
= sizeof(struct rtllib_disassoc
) + ieee
->tx_headroom
;
3594 skb
= dev_alloc_skb(len
);
3600 skb_reserve(skb
, ieee
->tx_headroom
);
3602 disass
= (struct rtllib_disassoc
*) skb_put(skb
,sizeof(struct rtllib_disassoc
));
3603 disass
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_DISASSOC
);
3604 disass
->header
.duration_id
= 0;
3606 memcpy(disass
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
3607 memcpy(disass
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
3608 memcpy(disass
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
3610 disass
->reason
= cpu_to_le16(asRsn
);
3614 void SendDisassociation(struct rtllib_device
*ieee
, bool deauth
, u16 asRsn
)
3616 struct rtllib_network
*beacon
= &ieee
->current_network
;
3617 struct sk_buff
*skb
;
3620 skb
= rtllib_disauth_skb(beacon
,ieee
,asRsn
);
3622 skb
= rtllib_disassociate_skb(beacon
,ieee
,asRsn
);
3626 softmac_mgmt_xmit(skb
, ieee
);
3630 u8
rtllib_ap_sec_type(struct rtllib_device
*ieee
)
3632 static u8 ccmp_ie
[4] = {0x00,0x50,0xf2,0x04};
3633 static u8 ccmp_rsn_ie
[4] = {0x00, 0x0f, 0xac, 0x04};
3634 int wpa_ie_len
= ieee
->wpa_ie_len
;
3635 struct rtllib_crypt_data
* crypt
;
3638 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
3639 encrypt
= (ieee
->current_network
.capability
& WLAN_CAPABILITY_PRIVACY
) ||\
3640 (ieee
->host_encrypt
&& crypt
&& crypt
->ops
&& \
3641 (0 == strcmp(crypt
->ops
->name
,"WEP")));
3644 if (encrypt
&& (wpa_ie_len
== 0)) {
3646 } else if ((wpa_ie_len
!= 0)) {
3647 if (((ieee
->wpa_ie
[0] == 0xdd) && (!memcmp(&(ieee
->wpa_ie
[14]),ccmp_ie
,4))) ||
3648 ((ieee
->wpa_ie
[0] == 0x30) && (!memcmp(&ieee
->wpa_ie
[10],ccmp_rsn_ie
, 4))))
3649 return SEC_ALG_CCMP
;
3651 return SEC_ALG_TKIP
;
3653 return SEC_ALG_NONE
;
3657 int rtllib_wpa_supplicant_ioctl(struct rtllib_device
*ieee
, struct iw_point
*p
, u8 is_mesh
)
3659 struct ieee_param
*param
;
3662 down(&ieee
->wx_sem
);
3664 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
){
3669 param
= (struct ieee_param
*)kmalloc(p
->length
, GFP_KERNEL
);
3674 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
3680 switch (param
->cmd
) {
3682 case IEEE_CMD_SET_WPA_PARAM
:
3683 ret
= rtllib_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
3684 param
->u
.wpa_param
.value
);
3687 case IEEE_CMD_SET_WPA_IE
:
3688 ret
= rtllib_wpa_set_wpa_ie(ieee
, param
, p
->length
);
3691 case IEEE_CMD_SET_ENCRYPTION
:
3692 ret
= rtllib_wpa_set_encryption(ieee
, param
, p
->length
, 0);
3696 ret
= rtllib_wpa_mlme(ieee
, param
->u
.mlme
.command
,
3697 param
->u
.mlme
.reason_code
);
3701 printk("Unknown WPA supplicant request: %d\n",param
->cmd
);
3706 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
3717 rtllib_MgntDisconnectIBSS(struct rtllib_device
* rtllib
)
3721 bool bFilterOutNonAssociatedBSSID
= false;
3723 rtllib
->state
= RTLLIB_NOLINK
;
3725 for (i
=0;i
<6;i
++) rtllib
->current_network
.bssid
[i
]= 0x55;
3727 rtllib
->OpMode
= RT_OP_MODE_NO_LINK
;
3728 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_BSSID
, rtllib
->current_network
.bssid
);
3729 OpMode
= RT_OP_MODE_NO_LINK
;
3730 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_MEDIA_STATUS
, &OpMode
);
3731 rtllib_stop_send_beacons(rtllib
);
3733 bFilterOutNonAssociatedBSSID
= false;
3734 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_CECHK_BSSID
, (u8
*)(&bFilterOutNonAssociatedBSSID
));
3735 notify_wx_assoc_event(rtllib
);
3740 rtllib_MlmeDisassociateRequest(
3741 struct rtllib_device
* rtllib
,
3749 RemovePeerTS(rtllib
, asSta
);
3752 if (memcpy(rtllib
->current_network
.bssid
,asSta
,6) == 0)
3754 rtllib
->state
= RTLLIB_NOLINK
;
3756 for (i
=0;i
<6;i
++) rtllib
->current_network
.bssid
[i
] = 0x22;
3757 OpMode
= RT_OP_MODE_NO_LINK
;
3758 rtllib
->OpMode
= RT_OP_MODE_NO_LINK
;
3759 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_MEDIA_STATUS
, (u8
*)(&OpMode
) );
3760 rtllib_disassociate(rtllib
);
3762 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_BSSID
, rtllib
->current_network
.bssid
);
3769 rtllib_MgntDisconnectAP(
3770 struct rtllib_device
* rtllib
,
3774 bool bFilterOutNonAssociatedBSSID
= false;
3776 bFilterOutNonAssociatedBSSID
= false;
3777 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_CECHK_BSSID
, (u8
*)(&bFilterOutNonAssociatedBSSID
));
3778 rtllib_MlmeDisassociateRequest( rtllib
, rtllib
->current_network
.bssid
, asRsn
);
3780 rtllib
->state
= RTLLIB_NOLINK
;
3784 rtllib_MgntDisconnect(
3785 struct rtllib_device
* rtllib
,
3789 if (rtllib
->ps
!= RTLLIB_PS_DISABLED
)
3791 rtllib
->sta_wake_up(rtllib
->dev
);
3794 if ( rtllib
->state
== RTLLIB_LINKED
)
3796 if ( rtllib
->iw_mode
== IW_MODE_ADHOC
)
3798 rtllib_MgntDisconnectIBSS(rtllib
);
3800 if ( rtllib
->iw_mode
== IW_MODE_INFRA
)
3802 rtllib_MgntDisconnectAP(rtllib
, asRsn
);
3810 void notify_wx_assoc_event(struct rtllib_device
*ieee
)
3812 union iwreq_data wrqu
;
3814 if (ieee
->cannot_notify
)
3817 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3818 if (ieee
->state
== RTLLIB_LINKED
)
3819 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
, ETH_ALEN
);
3822 printk("%s(): Tell user space disconnected\n",__func__
);
3823 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
3825 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);