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 <linux/uaccess.h>
26 short rtllib_is_54g(struct rtllib_network
*net
)
28 return (net
->rates_ex_len
> 0) || (net
->rates_len
> 4);
31 short rtllib_is_shortslot(struct rtllib_network net
)
33 return net
.capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
;
36 /* returns the total length needed for pleacing the RATE MFIE
37 * tag and the EXTENDED RATE MFIE tag if needed.
38 * It encludes two bytes per tag for the tag itself and its len
40 static unsigned int rtllib_MFIE_rate_len(struct rtllib_device
*ieee
)
42 unsigned int rate_len
= 0;
44 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
)
45 rate_len
= RTLLIB_CCK_RATE_LEN
+ 2;
47 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)
49 rate_len
+= RTLLIB_OFDM_RATE_LEN
+ 2;
54 /* pleace the MFIE rate, tag to the memory (double) poined.
55 * Then it updates the pointer so that
56 * it points after the new MFIE tag added.
58 static void rtllib_MFIE_Brate(struct rtllib_device
*ieee
, u8
**tag_p
)
62 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
) {
63 *tag
++ = MFIE_TYPE_RATES
;
65 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_1MB
;
66 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_2MB
;
67 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_5MB
;
68 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_11MB
;
71 /* We may add an option for custom rates that specific HW
76 static void rtllib_MFIE_Grate(struct rtllib_device
*ieee
, u8
**tag_p
)
80 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
) {
81 *tag
++ = MFIE_TYPE_RATES_EX
;
83 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_6MB
;
84 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_9MB
;
85 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_12MB
;
86 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_18MB
;
87 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_24MB
;
88 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_36MB
;
89 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_48MB
;
90 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_54MB
;
92 /* We may add an option for custom rates that specific HW might
97 static void rtllib_WMM_Info(struct rtllib_device
*ieee
, u8
**tag_p
)
101 *tag
++ = MFIE_TYPE_GENERIC
;
113 void rtllib_TURBO_Info(struct rtllib_device
*ieee
, u8
**tag_p
)
117 *tag
++ = MFIE_TYPE_GENERIC
;
128 printk(KERN_ALERT
"This is enable turbo mode IE process\n");
131 static void enqueue_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
134 nh
= (ieee
->mgmt_queue_head
+ 1) % MGMT_QUEUE_NUM
;
137 * if the queue is full but we have newer frames then
138 * just overwrites the oldest.
140 * if (nh == ieee->mgmt_queue_tail)
143 ieee
->mgmt_queue_head
= nh
;
144 ieee
->mgmt_queue_ring
[nh
] = skb
;
148 static struct sk_buff
*dequeue_mgmt(struct rtllib_device
*ieee
)
152 if (ieee
->mgmt_queue_tail
== ieee
->mgmt_queue_head
)
155 ret
= ieee
->mgmt_queue_ring
[ieee
->mgmt_queue_tail
];
157 ieee
->mgmt_queue_tail
=
158 (ieee
->mgmt_queue_tail
+1) % MGMT_QUEUE_NUM
;
163 static void init_mgmt_queue(struct rtllib_device
*ieee
)
165 ieee
->mgmt_queue_tail
= ieee
->mgmt_queue_head
= 0;
170 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device
*ieee
)
177 for (i
= 0; i
< ieee
->current_network
.rates_len
; i
++) {
178 BasicRate
= ieee
->current_network
.rates
[i
]&0x7F;
179 if (!rtllib_is_cck_rate(BasicRate
)) {
180 if (QueryRate
== 0) {
181 QueryRate
= BasicRate
;
183 if (BasicRate
< QueryRate
)
184 QueryRate
= BasicRate
;
189 if (QueryRate
== 0) {
191 printk(KERN_INFO
"No BasicRate found!!\n");
196 u8
MgntQuery_MgntFrameTxRate(struct rtllib_device
*ieee
)
198 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
201 if (pHTInfo
->IOTAction
& HT_IOT_ACT_MGNT_USE_CCK_6M
)
204 rate
= ieee
->basic_rate
& 0x7f;
207 if (ieee
->mode
== IEEE_A
||
208 ieee
->mode
== IEEE_N_5G
||
209 (ieee
->mode
== IEEE_N_24G
&& !pHTInfo
->bCurSuppCCK
))
218 inline void softmac_mgmt_xmit(struct sk_buff
*skb
, struct rtllib_device
*ieee
)
221 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
222 struct rtllib_hdr_3addr
*header
=
223 (struct rtllib_hdr_3addr
*) skb
->data
;
225 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ 8);
226 spin_lock_irqsave(&ieee
->lock
, flags
);
228 /* called with 2nd param 0, no mgmt lock required */
229 rtllib_sta_wakeup(ieee
, 0);
231 if (header
->frame_ctl
== RTLLIB_STYPE_BEACON
)
232 tcb_desc
->queue_index
= BEACON_QUEUE
;
234 tcb_desc
->queue_index
= MGNT_QUEUE
;
236 if (ieee
->disable_mgnt_queue
)
237 tcb_desc
->queue_index
= HIGH_QUEUE
;
239 tcb_desc
->data_rate
= MgntQuery_MgntFrameTxRate(ieee
);
240 tcb_desc
->RATRIndex
= 7;
241 tcb_desc
->bTxDisableRateFallBack
= 1;
242 tcb_desc
->bTxUseDriverAssingedRate
= 1;
244 if (ieee
->queue_stop
) {
245 enqueue_mgmt(ieee
, skb
);
247 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4);
249 if (ieee
->seq_ctrl
[0] == 0xFFF)
250 ieee
->seq_ctrl
[0] = 0;
254 /* avoid watchdog triggers */
255 ieee
->softmac_data_hard_start_xmit(skb
, ieee
->dev
,
259 spin_unlock_irqrestore(&ieee
->lock
, flags
);
261 spin_unlock_irqrestore(&ieee
->lock
, flags
);
262 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags
);
264 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
266 if (ieee
->seq_ctrl
[0] == 0xFFF)
267 ieee
->seq_ctrl
[0] = 0;
271 /* check wether the managed packet queued greater than 5 */
272 if (!ieee
->check_nic_enough_desc(ieee
->dev
, tcb_desc
->queue_index
) ||
273 (skb_queue_len(&ieee
->skb_waitQ
[tcb_desc
->queue_index
]) != 0) ||
274 (ieee
->queue_stop
)) {
275 /* insert the skb packet to the management queue */
276 /* as for the completion function, it does not need
277 * to check it any more.
279 printk(KERN_INFO
"%s():insert to waitqueue, queue_index"
280 ":%d!\n", __func__
, tcb_desc
->queue_index
);
281 skb_queue_tail(&ieee
->skb_waitQ
[tcb_desc
->queue_index
],
284 ieee
->softmac_hard_start_xmit(skb
, ieee
->dev
);
286 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags
);
290 inline void softmac_ps_mgmt_xmit(struct sk_buff
*skb
,
291 struct rtllib_device
*ieee
)
293 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
294 struct rtllib_hdr_3addr
*header
=
295 (struct rtllib_hdr_3addr
*) skb
->data
;
297 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ 8);
299 fc
= header
->frame_ctl
;
300 type
= WLAN_FC_GET_TYPE(fc
);
301 stype
= WLAN_FC_GET_STYPE(fc
);
304 if (stype
!= RTLLIB_STYPE_PSPOLL
)
305 tcb_desc
->queue_index
= MGNT_QUEUE
;
307 tcb_desc
->queue_index
= HIGH_QUEUE
;
309 if (ieee
->disable_mgnt_queue
)
310 tcb_desc
->queue_index
= HIGH_QUEUE
;
313 tcb_desc
->data_rate
= MgntQuery_MgntFrameTxRate(ieee
);
314 tcb_desc
->RATRIndex
= 7;
315 tcb_desc
->bTxDisableRateFallBack
= 1;
316 tcb_desc
->bTxUseDriverAssingedRate
= 1;
318 if (type
!= RTLLIB_FTYPE_CTL
) {
319 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
321 if (ieee
->seq_ctrl
[0] == 0xFFF)
322 ieee
->seq_ctrl
[0] = 0;
327 /* avoid watchdog triggers */
328 ieee
->softmac_data_hard_start_xmit(skb
, ieee
->dev
,
332 if (type
!= RTLLIB_FTYPE_CTL
) {
333 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
335 if (ieee
->seq_ctrl
[0] == 0xFFF)
336 ieee
->seq_ctrl
[0] = 0;
340 ieee
->softmac_hard_start_xmit(skb
, ieee
->dev
);
345 inline struct sk_buff
*rtllib_probe_req(struct rtllib_device
*ieee
)
347 unsigned int len
, rate_len
;
350 struct rtllib_probe_request
*req
;
352 len
= ieee
->current_network
.ssid_len
;
354 rate_len
= rtllib_MFIE_rate_len(ieee
);
356 skb
= dev_alloc_skb(sizeof(struct rtllib_probe_request
) +
357 2 + len
+ rate_len
+ ieee
->tx_headroom
);
362 skb_reserve(skb
, ieee
->tx_headroom
);
364 req
= (struct rtllib_probe_request
*) skb_put(skb
,
365 sizeof(struct rtllib_probe_request
));
366 req
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_PROBE_REQ
);
367 req
->header
.duration_id
= 0;
369 memset(req
->header
.addr1
, 0xff, ETH_ALEN
);
370 memcpy(req
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
371 memset(req
->header
.addr3
, 0xff, ETH_ALEN
);
373 tag
= (u8
*) skb_put(skb
, len
+ 2 + rate_len
);
375 *tag
++ = MFIE_TYPE_SSID
;
377 memcpy(tag
, ieee
->current_network
.ssid
, len
);
380 rtllib_MFIE_Brate(ieee
, &tag
);
381 rtllib_MFIE_Grate(ieee
, &tag
);
386 struct sk_buff
*rtllib_get_beacon_(struct rtllib_device
*ieee
);
388 static void rtllib_send_beacon(struct rtllib_device
*ieee
)
393 skb
= rtllib_get_beacon_(ieee
);
396 softmac_mgmt_xmit(skb
, ieee
);
397 ieee
->softmac_stats
.tx_beacons
++;
400 if (ieee
->beacon_txing
&& ieee
->ieee_up
)
401 mod_timer(&ieee
->beacon_timer
, jiffies
+
402 (MSECS(ieee
->current_network
.beacon_interval
- 5)));
406 static void rtllib_send_beacon_cb(unsigned long _ieee
)
408 struct rtllib_device
*ieee
=
409 (struct rtllib_device
*) _ieee
;
412 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
413 rtllib_send_beacon(ieee
);
414 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
419 * Enable network monitor mode, all rx packets will be received.
421 void rtllib_EnableNetMonitorMode(struct net_device
*dev
,
424 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
426 printk(KERN_INFO
"========>Enter Monitor Mode\n");
428 ieee
->AllowAllDestAddrHandler(dev
, true, !bInitState
);
434 * Disable network network monitor mode, only packets destinated to
435 * us will be received.
437 void rtllib_DisableNetMonitorMode(struct net_device
*dev
,
440 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
442 printk(KERN_INFO
"========>Exit Monitor Mode\n");
444 ieee
->AllowAllDestAddrHandler(dev
, false, !bInitState
);
450 * This enables the specialized promiscuous mode required by Intel.
451 * In this mode, Intel intends to hear traffics from/to other STAs in the
452 * same BSS. Therefore we don't have to disable checking BSSID and we only need
453 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
454 * packets from other STA.
456 void rtllib_EnableIntelPromiscuousMode(struct net_device
*dev
,
459 bool bFilterOutNonAssociatedBSSID
= false;
461 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
463 printk(KERN_INFO
"========>Enter Intel Promiscuous Mode\n");
465 ieee
->AllowAllDestAddrHandler(dev
, true, !bInitState
);
466 ieee
->SetHwRegHandler(dev
, HW_VAR_CECHK_BSSID
,
467 (u8
*)&bFilterOutNonAssociatedBSSID
);
469 ieee
->bNetPromiscuousMode
= true;
475 * This disables the specialized promiscuous mode required by Intel.
476 * See MgntEnableIntelPromiscuousMode for detail.
478 void rtllib_DisableIntelPromiscuousMode(struct net_device
*dev
,
481 bool bFilterOutNonAssociatedBSSID
= true;
483 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
485 printk(KERN_INFO
"========>Exit Intel Promiscuous Mode\n");
487 ieee
->AllowAllDestAddrHandler(dev
, false, !bInitState
);
488 ieee
->SetHwRegHandler(dev
, HW_VAR_CECHK_BSSID
,
489 (u8
*)&bFilterOutNonAssociatedBSSID
);
491 ieee
->bNetPromiscuousMode
= false;
494 static void rtllib_send_probe(struct rtllib_device
*ieee
, u8 is_mesh
)
497 skb
= rtllib_probe_req(ieee
);
499 softmac_mgmt_xmit(skb
, ieee
);
500 ieee
->softmac_stats
.tx_probe_rq
++;
505 void rtllib_send_probe_requests(struct rtllib_device
*ieee
, u8 is_mesh
)
507 if (ieee
->active_scan
&& (ieee
->softmac_features
&
508 IEEE_SOFTMAC_PROBERQ
)) {
509 rtllib_send_probe(ieee
, 0);
510 rtllib_send_probe(ieee
, 0);
514 static void rtllib_softmac_hint11d_wq(void *data
)
518 void rtllib_update_active_chan_map(struct rtllib_device
*ieee
)
520 memcpy(ieee
->active_channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
,
521 MAX_CHANNEL_NUMBER
+1);
524 /* this performs syncro scan blocking the caller until all channels
525 * in the allowed channel map has been checked.
527 void rtllib_softmac_scan_syncro(struct rtllib_device
*ieee
, u8 is_mesh
)
529 union iwreq_data wrqu
;
532 rtllib_update_active_chan_map(ieee
);
534 ieee
->be_scan_inprogress
= true;
536 down(&ieee
->scan_sem
);
541 if (ch
> MAX_CHANNEL_NUMBER
)
542 goto out
; /* scan completed */
543 } while (!ieee
->active_channel_map
[ch
]);
545 /* this fuction can be called in two situations
546 * 1- We have switched to ad-hoc mode and we are
547 * performing a complete syncro scan before conclude
548 * there are no interesting cell and to create a
549 * new one. In this case the link state is
550 * RTLLIB_NOLINK until we found an interesting cell.
551 * If so the ieee8021_new_net, called by the RX path
552 * will set the state to RTLLIB_LINKED, so we stop
554 * 2- We are linked and the root uses run iwlist scan.
555 * So we switch to RTLLIB_LINKED_SCANNING to remember
556 * that we are still logically linked (not interested in
557 * new network events, despite for updating the net list,
558 * but we are temporarly 'unlinked' as the driver shall
559 * not filter RX frames and the channel is changing.
560 * So the only situation in witch are interested is to check
561 * if the state become LINKED because of the #1 situation
564 if (ieee
->state
== RTLLIB_LINKED
)
566 if (ieee
->sync_scan_hurryup
) {
567 printk(KERN_INFO
"============>sync_scan_hurryup out\n");
571 ieee
->set_chan(ieee
->dev
, ch
);
572 if (ieee
->active_channel_map
[ch
] == 1)
573 rtllib_send_probe_requests(ieee
, 0);
575 /* this prevent excessive time wait when we
576 * need to wait for a syncro scan to end..
578 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME
);
581 ieee
->actscanning
= false;
582 ieee
->sync_scan_hurryup
= 0;
584 if (ieee
->state
>= RTLLIB_LINKED
) {
585 if (IS_DOT11D_ENABLE(ieee
))
586 DOT11D_ScanComplete(ieee
);
590 ieee
->be_scan_inprogress
= false;
592 memset(&wrqu
, 0, sizeof(wrqu
));
593 wireless_send_event(ieee
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
596 static void rtllib_softmac_scan_wq(void *data
)
598 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
599 struct rtllib_device
, softmac_scan_wq
);
600 u8 last_channel
= ieee
->current_network
.channel
;
602 rtllib_update_active_chan_map(ieee
);
606 if (rtllib_act_scanning(ieee
, true) == true)
609 down(&ieee
->scan_sem
);
611 if (ieee
->eRFPowerState
== eRfOff
) {
612 printk(KERN_INFO
"======>%s():rf state is eRfOff, return\n",
618 ieee
->current_network
.channel
=
619 (ieee
->current_network
.channel
+ 1) %
621 if (ieee
->scan_watch_dog
++ > MAX_CHANNEL_NUMBER
) {
622 if (!ieee
->active_channel_map
[ieee
->current_network
.channel
])
623 ieee
->current_network
.channel
= 6;
624 goto out
; /* no good chans */
626 } while (!ieee
->active_channel_map
[ieee
->current_network
.channel
]);
628 if (ieee
->scanning_continue
== 0)
631 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
633 if (ieee
->active_channel_map
[ieee
->current_network
.channel
] == 1)
634 rtllib_send_probe_requests(ieee
, 0);
636 queue_delayed_work_rsl(ieee
->wq
, &ieee
->softmac_scan_wq
,
637 MSECS(RTLLIB_SOFTMAC_SCAN_TIME
));
643 if (IS_DOT11D_ENABLE(ieee
))
644 DOT11D_ScanComplete(ieee
);
645 ieee
->current_network
.channel
= last_channel
;
648 ieee
->actscanning
= false;
649 ieee
->scan_watch_dog
= 0;
650 ieee
->scanning_continue
= 0;
656 static void rtllib_beacons_start(struct rtllib_device
*ieee
)
659 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
661 ieee
->beacon_txing
= 1;
662 rtllib_send_beacon(ieee
);
664 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
667 static void rtllib_beacons_stop(struct rtllib_device
*ieee
)
671 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
673 ieee
->beacon_txing
= 0;
674 del_timer_sync(&ieee
->beacon_timer
);
676 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
681 void rtllib_stop_send_beacons(struct rtllib_device
*ieee
)
683 if (ieee
->stop_send_beacons
)
684 ieee
->stop_send_beacons(ieee
->dev
);
685 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
686 rtllib_beacons_stop(ieee
);
690 void rtllib_start_send_beacons(struct rtllib_device
*ieee
)
692 if (ieee
->start_send_beacons
)
693 ieee
->start_send_beacons(ieee
->dev
);
694 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
695 rtllib_beacons_start(ieee
);
699 static void rtllib_softmac_stop_scan(struct rtllib_device
*ieee
)
701 down(&ieee
->scan_sem
);
702 ieee
->scan_watch_dog
= 0;
703 if (ieee
->scanning_continue
== 1) {
704 ieee
->scanning_continue
= 0;
705 ieee
->actscanning
= 0;
707 cancel_delayed_work(&ieee
->softmac_scan_wq
);
713 void rtllib_stop_scan(struct rtllib_device
*ieee
)
715 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
716 rtllib_softmac_stop_scan(ieee
);
718 if (ieee
->rtllib_stop_hw_scan
)
719 ieee
->rtllib_stop_hw_scan(ieee
->dev
);
723 void rtllib_stop_scan_syncro(struct rtllib_device
*ieee
)
725 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
726 ieee
->sync_scan_hurryup
= 1;
728 if (ieee
->rtllib_stop_hw_scan
)
729 ieee
->rtllib_stop_hw_scan(ieee
->dev
);
733 bool rtllib_act_scanning(struct rtllib_device
*ieee
, bool sync_scan
)
735 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
737 return ieee
->be_scan_inprogress
;
739 return ieee
->actscanning
|| ieee
->be_scan_inprogress
;
741 return test_bit(STATUS_SCANNING
, &ieee
->status
);
745 /* called with ieee->lock held */
746 static void rtllib_start_scan(struct rtllib_device
*ieee
)
748 RT_TRACE(COMP_DBG
, "===>%s()\n", __func__
);
749 if (ieee
->rtllib_ips_leave_wq
!= NULL
)
750 ieee
->rtllib_ips_leave_wq(ieee
->dev
);
752 if (IS_DOT11D_ENABLE(ieee
)) {
753 if (IS_COUNTRY_IE_VALID(ieee
))
754 RESET_CIE_WATCHDOG(ieee
);
756 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
757 if (ieee
->scanning_continue
== 0) {
758 ieee
->actscanning
= true;
759 ieee
->scanning_continue
= 1;
760 queue_delayed_work_rsl(ieee
->wq
,
761 &ieee
->softmac_scan_wq
, 0);
764 if (ieee
->rtllib_start_hw_scan
)
765 ieee
->rtllib_start_hw_scan(ieee
->dev
);
769 /* called with wx_sem held */
770 void rtllib_start_scan_syncro(struct rtllib_device
*ieee
, u8 is_mesh
)
772 if (IS_DOT11D_ENABLE(ieee
)) {
773 if (IS_COUNTRY_IE_VALID(ieee
))
774 RESET_CIE_WATCHDOG(ieee
);
776 ieee
->sync_scan_hurryup
= 0;
777 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
778 rtllib_softmac_scan_syncro(ieee
, is_mesh
);
780 if (ieee
->rtllib_start_hw_scan
)
781 ieee
->rtllib_start_hw_scan(ieee
->dev
);
785 inline struct sk_buff
*rtllib_authentication_req(struct rtllib_network
*beacon
,
786 struct rtllib_device
*ieee
, int challengelen
, u8
*daddr
)
789 struct rtllib_authentication
*auth
;
791 len
= sizeof(struct rtllib_authentication
) + challengelen
+
792 ieee
->tx_headroom
+ 4;
793 skb
= dev_alloc_skb(len
);
798 skb_reserve(skb
, ieee
->tx_headroom
);
800 auth
= (struct rtllib_authentication
*)
801 skb_put(skb
, sizeof(struct rtllib_authentication
));
803 auth
->header
.frame_ctl
= RTLLIB_STYPE_AUTH
;
805 auth
->header
.frame_ctl
|= RTLLIB_FCTL_WEP
;
807 auth
->header
.duration_id
= 0x013a;
808 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
809 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
810 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
811 if (ieee
->auth_mode
== 0)
812 auth
->algorithm
= WLAN_AUTH_OPEN
;
813 else if (ieee
->auth_mode
== 1)
814 auth
->algorithm
= WLAN_AUTH_SHARED_KEY
;
815 else if (ieee
->auth_mode
== 2)
816 auth
->algorithm
= WLAN_AUTH_OPEN
;
817 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
818 ieee
->associate_seq
++;
820 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
825 static struct sk_buff
*rtllib_probe_resp(struct rtllib_device
*ieee
, u8
*dest
)
829 struct rtllib_probe_response
*beacon_buf
;
830 struct sk_buff
*skb
= NULL
;
832 int atim_len
, erp_len
;
833 struct rtllib_crypt_data
*crypt
;
835 char *ssid
= ieee
->current_network
.ssid
;
836 int ssid_len
= ieee
->current_network
.ssid_len
;
837 int rate_len
= ieee
->current_network
.rates_len
+2;
838 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
839 int wpa_ie_len
= ieee
->wpa_ie_len
;
840 u8 erpinfo_content
= 0;
842 u8
*tmp_ht_cap_buf
= NULL
;
843 u8 tmp_ht_cap_len
= 0;
844 u8
*tmp_ht_info_buf
= NULL
;
845 u8 tmp_ht_info_len
= 0;
846 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
847 u8
*tmp_generic_ie_buf
= NULL
;
848 u8 tmp_generic_ie_len
= 0;
853 if (ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
858 if ((ieee
->current_network
.mode
== IEEE_G
) ||
859 (ieee
->current_network
.mode
== IEEE_N_24G
&&
860 ieee
->pHTInfo
->bCurSuppCCK
)) {
863 if (ieee
->current_network
.buseprotection
)
864 erpinfo_content
|= ERP_UseProtection
;
868 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
869 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
870 ((0 == strcmp(crypt
->ops
->name
, "WEP") || wpa_ie_len
));
871 if (ieee
->pHTInfo
->bCurrentHTSupport
) {
872 tmp_ht_cap_buf
= (u8
*) &(ieee
->pHTInfo
->SelfHTCap
);
873 tmp_ht_cap_len
= sizeof(ieee
->pHTInfo
->SelfHTCap
);
874 tmp_ht_info_buf
= (u8
*) &(ieee
->pHTInfo
->SelfHTInfo
);
875 tmp_ht_info_len
= sizeof(ieee
->pHTInfo
->SelfHTInfo
);
876 HTConstructCapabilityElement(ieee
, tmp_ht_cap_buf
,
877 &tmp_ht_cap_len
, encrypt
, false);
878 HTConstructInfoElement(ieee
, tmp_ht_info_buf
, &tmp_ht_info_len
,
881 if (pHTInfo
->bRegRT2RTAggregation
) {
882 tmp_generic_ie_buf
= ieee
->pHTInfo
->szRT2RTAggBuffer
;
884 sizeof(ieee
->pHTInfo
->szRT2RTAggBuffer
);
885 HTConstructRT2RTAggElement(ieee
, tmp_generic_ie_buf
,
886 &tmp_generic_ie_len
);
890 beacon_size
= sizeof(struct rtllib_probe_response
)+2+
891 ssid_len
+ 3 + rate_len
+ rate_ex_len
+ atim_len
+ erp_len
892 + wpa_ie_len
+ ieee
->tx_headroom
;
893 skb
= dev_alloc_skb(beacon_size
);
897 skb_reserve(skb
, ieee
->tx_headroom
);
899 beacon_buf
= (struct rtllib_probe_response
*) skb_put(skb
,
900 (beacon_size
- ieee
->tx_headroom
));
901 memcpy(beacon_buf
->header
.addr1
, dest
, ETH_ALEN
);
902 memcpy(beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
903 memcpy(beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
905 beacon_buf
->header
.duration_id
= 0;
906 beacon_buf
->beacon_interval
=
907 cpu_to_le16(ieee
->current_network
.beacon_interval
);
908 beacon_buf
->capability
=
909 cpu_to_le16(ieee
->current_network
.capability
&
910 WLAN_CAPABILITY_IBSS
);
911 beacon_buf
->capability
|=
912 cpu_to_le16(ieee
->current_network
.capability
&
913 WLAN_CAPABILITY_SHORT_PREAMBLE
);
915 if (ieee
->short_slot
&& (ieee
->current_network
.capability
&
916 WLAN_CAPABILITY_SHORT_SLOT_TIME
))
917 cpu_to_le16((beacon_buf
->capability
|=
918 WLAN_CAPABILITY_SHORT_SLOT_TIME
));
920 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
922 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
925 beacon_buf
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_PROBE_RESP
);
926 beacon_buf
->info_element
[0].id
= MFIE_TYPE_SSID
;
927 beacon_buf
->info_element
[0].len
= ssid_len
;
929 tag
= (u8
*) beacon_buf
->info_element
[0].data
;
931 memcpy(tag
, ssid
, ssid_len
);
935 *(tag
++) = MFIE_TYPE_RATES
;
936 *(tag
++) = rate_len
-2;
937 memcpy(tag
, ieee
->current_network
.rates
, rate_len
-2);
940 *(tag
++) = MFIE_TYPE_DS_SET
;
942 *(tag
++) = ieee
->current_network
.channel
;
946 *(tag
++) = MFIE_TYPE_IBSS_SET
;
948 val16
= cpu_to_le16(ieee
->current_network
.atim_window
);
949 memcpy((u8
*)tag
, (u8
*)&val16
, 2);
954 *(tag
++) = MFIE_TYPE_ERP
;
956 *(tag
++) = erpinfo_content
;
959 *(tag
++) = MFIE_TYPE_RATES_EX
;
960 *(tag
++) = rate_ex_len
-2;
961 memcpy(tag
, ieee
->current_network
.rates_ex
, rate_ex_len
-2);
962 tag
+= rate_ex_len
-2;
966 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
967 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
968 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
969 tag
+= ieee
->wpa_ie_len
;
974 static struct sk_buff
*rtllib_assoc_resp(struct rtllib_device
*ieee
, u8
*dest
)
979 struct rtllib_crypt_data
*crypt
;
980 struct rtllib_assoc_response_frame
*assoc
;
983 unsigned int rate_len
= rtllib_MFIE_rate_len(ieee
);
984 int len
= sizeof(struct rtllib_assoc_response_frame
) + rate_len
+
987 skb
= dev_alloc_skb(len
);
992 skb_reserve(skb
, ieee
->tx_headroom
);
994 assoc
= (struct rtllib_assoc_response_frame
*)
995 skb_put(skb
, sizeof(struct rtllib_assoc_response_frame
));
997 assoc
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP
);
998 memcpy(assoc
->header
.addr1
, dest
, ETH_ALEN
);
999 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1000 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1001 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
1002 WLAN_CAPABILITY_ESS
: WLAN_CAPABILITY_IBSS
);
1005 if (ieee
->short_slot
)
1006 assoc
->capability
|=
1007 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1009 if (ieee
->host_encrypt
)
1010 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
1014 encrypt
= (crypt
&& crypt
->ops
);
1017 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1020 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
1021 if (ieee
->assoc_id
== 0x2007)
1026 tag
= (u8
*) skb_put(skb
, rate_len
);
1027 rtllib_MFIE_Brate(ieee
, &tag
);
1028 rtllib_MFIE_Grate(ieee
, &tag
);
1033 static struct sk_buff
*rtllib_auth_resp(struct rtllib_device
*ieee
, int status
,
1036 struct sk_buff
*skb
= NULL
;
1037 struct rtllib_authentication
*auth
;
1038 int len
= ieee
->tx_headroom
+ sizeof(struct rtllib_authentication
) + 1;
1039 skb
= dev_alloc_skb(len
);
1043 skb
->len
= sizeof(struct rtllib_authentication
);
1045 skb_reserve(skb
, ieee
->tx_headroom
);
1047 auth
= (struct rtllib_authentication
*)
1048 skb_put(skb
, sizeof(struct rtllib_authentication
));
1050 auth
->status
= cpu_to_le16(status
);
1051 auth
->transaction
= cpu_to_le16(2);
1052 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
1054 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1055 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1056 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
1057 auth
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_AUTH
);
1063 static struct sk_buff
*rtllib_null_func(struct rtllib_device
*ieee
, short pwr
)
1065 struct sk_buff
*skb
;
1066 struct rtllib_hdr_3addr
*hdr
;
1068 skb
= dev_alloc_skb(sizeof(struct rtllib_hdr_3addr
)+ieee
->tx_headroom
);
1072 skb_reserve(skb
, ieee
->tx_headroom
);
1074 hdr
= (struct rtllib_hdr_3addr
*)skb_put(skb
,
1075 sizeof(struct rtllib_hdr_3addr
));
1077 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
1078 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1079 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
1081 hdr
->frame_ctl
= cpu_to_le16(RTLLIB_FTYPE_DATA
|
1082 RTLLIB_STYPE_NULLFUNC
| RTLLIB_FCTL_TODS
|
1083 (pwr
? RTLLIB_FCTL_PM
: 0));
1090 static struct sk_buff
*rtllib_pspoll_func(struct rtllib_device
*ieee
)
1092 struct sk_buff
*skb
;
1093 struct rtllib_pspoll_hdr
*hdr
;
1095 skb
= dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr
)+ieee
->tx_headroom
);
1099 skb_reserve(skb
, ieee
->tx_headroom
);
1101 hdr
= (struct rtllib_pspoll_hdr
*)skb_put(skb
,
1102 sizeof(struct rtllib_pspoll_hdr
));
1104 memcpy(hdr
->bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
1105 memcpy(hdr
->ta
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1107 hdr
->aid
= cpu_to_le16(ieee
->assoc_id
| 0xc000);
1108 hdr
->frame_ctl
= cpu_to_le16(RTLLIB_FTYPE_CTL
| RTLLIB_STYPE_PSPOLL
|
1115 static void rtllib_resp_to_assoc_rq(struct rtllib_device
*ieee
, u8
*dest
)
1117 struct sk_buff
*buf
= rtllib_assoc_resp(ieee
, dest
);
1120 softmac_mgmt_xmit(buf
, ieee
);
1124 static void rtllib_resp_to_auth(struct rtllib_device
*ieee
, int s
, u8
*dest
)
1126 struct sk_buff
*buf
= rtllib_auth_resp(ieee
, s
, dest
);
1129 softmac_mgmt_xmit(buf
, ieee
);
1133 static void rtllib_resp_to_probe(struct rtllib_device
*ieee
, u8
*dest
)
1136 struct sk_buff
*buf
= rtllib_probe_resp(ieee
, dest
);
1138 softmac_mgmt_xmit(buf
, ieee
);
1142 inline int SecIsInPMKIDList(struct rtllib_device
*ieee
, u8
*bssid
)
1147 if ((ieee
->PMKIDList
[i
].bUsed
) &&
1148 (memcmp(ieee
->PMKIDList
[i
].Bssid
, bssid
, ETH_ALEN
) == 0))
1152 } while (i
< NUM_PMKID_CACHE
);
1154 if (i
== NUM_PMKID_CACHE
)
1159 inline struct sk_buff
*rtllib_association_req(struct rtllib_network
*beacon
,
1160 struct rtllib_device
*ieee
)
1162 struct sk_buff
*skb
;
1163 struct rtllib_assoc_request_frame
*hdr
;
1166 u8
*ht_cap_buf
= NULL
;
1168 u8
*realtek_ie_buf
= NULL
;
1169 u8 realtek_ie_len
= 0;
1170 int wpa_ie_len
= ieee
->wpa_ie_len
;
1171 int wps_ie_len
= ieee
->wps_ie_len
;
1172 unsigned int ckip_ie_len
= 0;
1173 unsigned int ccxrm_ie_len
= 0;
1174 unsigned int cxvernum_ie_len
= 0;
1175 struct rtllib_crypt_data
*crypt
;
1179 unsigned int rate_len
= (beacon
->rates_len
?
1180 (beacon
->rates_len
+ 2) : 0) +
1181 (beacon
->rates_ex_len
? (beacon
->rates_ex_len
) +
1184 unsigned int wmm_info_len
= beacon
->qos_data
.supported
? 9 : 0;
1185 unsigned int turbo_info_len
= beacon
->Turbo_Enable
? 9 : 0;
1188 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
1190 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
1191 ((0 == strcmp(crypt
->ops
->name
, "WEP") ||
1196 if ((ieee
->rtllib_ap_sec_type
&&
1197 (ieee
->rtllib_ap_sec_type(ieee
) & SEC_ALG_TKIP
)) ||
1198 (ieee
->bForcedBgMode
== true)) {
1199 ieee
->pHTInfo
->bEnableHT
= 0;
1200 ieee
->mode
= WIRELESS_MODE_G
;
1203 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1204 ht_cap_buf
= (u8
*)&(ieee
->pHTInfo
->SelfHTCap
);
1205 ht_cap_len
= sizeof(ieee
->pHTInfo
->SelfHTCap
);
1206 HTConstructCapabilityElement(ieee
, ht_cap_buf
, &ht_cap_len
,
1208 if (ieee
->pHTInfo
->bCurrentRT2RTAggregation
) {
1209 realtek_ie_buf
= ieee
->pHTInfo
->szRT2RTAggBuffer
;
1211 sizeof(ieee
->pHTInfo
->szRT2RTAggBuffer
);
1212 HTConstructRT2RTAggElement(ieee
, realtek_ie_buf
,
1217 if (beacon
->bCkipSupported
)
1219 if (beacon
->bCcxRmEnable
)
1221 if (beacon
->BssCcxVerNumber
>= 2)
1222 cxvernum_ie_len
= 5+2;
1224 PMKCacheIdx
= SecIsInPMKIDList(ieee
, ieee
->current_network
.bssid
);
1225 if (PMKCacheIdx
>= 0) {
1227 printk(KERN_INFO
"[PMK cache]: WPA2 IE length: %x\n",
1230 len
= sizeof(struct rtllib_assoc_request_frame
) + 2
1242 + ieee
->tx_headroom
;
1244 skb
= dev_alloc_skb(len
);
1249 skb_reserve(skb
, ieee
->tx_headroom
);
1251 hdr
= (struct rtllib_assoc_request_frame
*)
1252 skb_put(skb
, sizeof(struct rtllib_assoc_request_frame
) + 2);
1255 hdr
->header
.frame_ctl
= RTLLIB_STYPE_ASSOC_REQ
;
1256 hdr
->header
.duration_id
= 37;
1257 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1258 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1259 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1261 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);
1263 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_ESS
);
1264 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1265 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1267 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1268 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1270 if (ieee
->short_slot
&&
1271 (beacon
->capability
&WLAN_CAPABILITY_SHORT_SLOT_TIME
))
1272 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1275 hdr
->listen_interval
= beacon
->listen_interval
;
1277 hdr
->info_element
[0].id
= MFIE_TYPE_SSID
;
1279 hdr
->info_element
[0].len
= beacon
->ssid_len
;
1280 tag
= skb_put(skb
, beacon
->ssid_len
);
1281 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1283 tag
= skb_put(skb
, rate_len
);
1285 if (beacon
->rates_len
) {
1286 *tag
++ = MFIE_TYPE_RATES
;
1287 *tag
++ = beacon
->rates_len
;
1288 for (i
= 0; i
< beacon
->rates_len
; i
++)
1289 *tag
++ = beacon
->rates
[i
];
1292 if (beacon
->rates_ex_len
) {
1293 *tag
++ = MFIE_TYPE_RATES_EX
;
1294 *tag
++ = beacon
->rates_ex_len
;
1295 for (i
= 0; i
< beacon
->rates_ex_len
; i
++)
1296 *tag
++ = beacon
->rates_ex
[i
];
1299 if (beacon
->bCkipSupported
) {
1300 static u8 AironetIeOui
[] = {0x00, 0x01, 0x66};
1301 u8 CcxAironetBuf
[30];
1302 struct octet_string osCcxAironetIE
;
1304 memset(CcxAironetBuf
, 0, 30);
1305 osCcxAironetIE
.Octet
= CcxAironetBuf
;
1306 osCcxAironetIE
.Length
= sizeof(CcxAironetBuf
);
1307 memcpy(osCcxAironetIE
.Octet
, AironetIeOui
,
1308 sizeof(AironetIeOui
));
1310 osCcxAironetIE
.Octet
[IE_CISCO_FLAG_POSITION
] |=
1311 (SUPPORT_CKIP_PK
|SUPPORT_CKIP_MIC
);
1312 tag
= skb_put(skb
, ckip_ie_len
);
1313 *tag
++ = MFIE_TYPE_AIRONET
;
1314 *tag
++ = osCcxAironetIE
.Length
;
1315 memcpy(tag
, osCcxAironetIE
.Octet
, osCcxAironetIE
.Length
);
1316 tag
+= osCcxAironetIE
.Length
;
1319 if (beacon
->bCcxRmEnable
) {
1320 static u8 CcxRmCapBuf
[] = {0x00, 0x40, 0x96, 0x01, 0x01, 0x00};
1321 struct octet_string osCcxRmCap
;
1323 osCcxRmCap
.Octet
= CcxRmCapBuf
;
1324 osCcxRmCap
.Length
= sizeof(CcxRmCapBuf
);
1325 tag
= skb_put(skb
, ccxrm_ie_len
);
1326 *tag
++ = MFIE_TYPE_GENERIC
;
1327 *tag
++ = osCcxRmCap
.Length
;
1328 memcpy(tag
, osCcxRmCap
.Octet
, osCcxRmCap
.Length
);
1329 tag
+= osCcxRmCap
.Length
;
1332 if (beacon
->BssCcxVerNumber
>= 2) {
1333 u8 CcxVerNumBuf
[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1334 struct octet_string osCcxVerNum
;
1335 CcxVerNumBuf
[4] = beacon
->BssCcxVerNumber
;
1336 osCcxVerNum
.Octet
= CcxVerNumBuf
;
1337 osCcxVerNum
.Length
= sizeof(CcxVerNumBuf
);
1338 tag
= skb_put(skb
, cxvernum_ie_len
);
1339 *tag
++ = MFIE_TYPE_GENERIC
;
1340 *tag
++ = osCcxVerNum
.Length
;
1341 memcpy(tag
, osCcxVerNum
.Octet
, osCcxVerNum
.Length
);
1342 tag
+= osCcxVerNum
.Length
;
1344 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1345 if (ieee
->pHTInfo
->ePeerHTSpecVer
!= HT_SPEC_VER_EWC
) {
1346 tag
= skb_put(skb
, ht_cap_len
);
1347 *tag
++ = MFIE_TYPE_HT_CAP
;
1348 *tag
++ = ht_cap_len
- 2;
1349 memcpy(tag
, ht_cap_buf
, ht_cap_len
- 2);
1350 tag
+= ht_cap_len
- 2;
1355 tag
= skb_put(skb
, ieee
->wpa_ie_len
);
1356 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
1358 if (PMKCacheIdx
>= 0) {
1359 tag
= skb_put(skb
, 18);
1362 memcpy((tag
+ 2), &ieee
->PMKIDList
[PMKCacheIdx
].PMKID
,
1367 tag
= skb_put(skb
, wmm_info_len
);
1368 rtllib_WMM_Info(ieee
, &tag
);
1371 if (wps_ie_len
&& ieee
->wps_ie
) {
1372 tag
= skb_put(skb
, wps_ie_len
);
1373 memcpy(tag
, ieee
->wps_ie
, wps_ie_len
);
1376 tag
= skb_put(skb
, turbo_info_len
);
1378 rtllib_TURBO_Info(ieee
, &tag
);
1380 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1381 if (ieee
->pHTInfo
->ePeerHTSpecVer
== HT_SPEC_VER_EWC
) {
1382 tag
= skb_put(skb
, ht_cap_len
);
1383 *tag
++ = MFIE_TYPE_GENERIC
;
1384 *tag
++ = ht_cap_len
- 2;
1385 memcpy(tag
, ht_cap_buf
, ht_cap_len
- 2);
1386 tag
+= ht_cap_len
- 2;
1389 if (ieee
->pHTInfo
->bCurrentRT2RTAggregation
) {
1390 tag
= skb_put(skb
, realtek_ie_len
);
1391 *tag
++ = MFIE_TYPE_GENERIC
;
1392 *tag
++ = realtek_ie_len
- 2;
1393 memcpy(tag
, realtek_ie_buf
, realtek_ie_len
- 2);
1397 kfree(ieee
->assocreq_ies
);
1398 ieee
->assocreq_ies
= NULL
;
1399 ies
= &(hdr
->info_element
[0].id
);
1400 ieee
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
1401 ieee
->assocreq_ies
= kmalloc(ieee
->assocreq_ies_len
, GFP_ATOMIC
);
1402 if (ieee
->assocreq_ies
)
1403 memcpy(ieee
->assocreq_ies
, ies
, ieee
->assocreq_ies_len
);
1405 printk(KERN_INFO
"%s()Warning: can't alloc memory for assocreq"
1406 "_ies\n", __func__
);
1407 ieee
->assocreq_ies_len
= 0;
1412 void rtllib_associate_abort(struct rtllib_device
*ieee
)
1415 unsigned long flags
;
1416 spin_lock_irqsave(&ieee
->lock
, flags
);
1418 ieee
->associate_seq
++;
1420 /* don't scan, and avoid to have the RX path possibily
1421 * try again to associate. Even do not react to AUTH or
1422 * ASSOC response. Just wait for the retry wq to be scheduled.
1423 * Here we will check if there are good nets to associate
1424 * with, so we retry or just get back to NO_LINK and scanning
1426 if (ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATING
) {
1427 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1428 ieee
->softmac_stats
.no_auth_rs
++;
1430 RTLLIB_DEBUG_MGMT("Association failed\n");
1431 ieee
->softmac_stats
.no_ass_rs
++;
1434 ieee
->state
= RTLLIB_ASSOCIATING_RETRY
;
1436 queue_delayed_work_rsl(ieee
->wq
, &ieee
->associate_retry_wq
,
1437 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME
);
1439 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1442 static void rtllib_associate_abort_cb(unsigned long dev
)
1444 rtllib_associate_abort((struct rtllib_device
*) dev
);
1447 static void rtllib_associate_step1(struct rtllib_device
*ieee
, u8
* daddr
)
1449 struct rtllib_network
*beacon
= &ieee
->current_network
;
1450 struct sk_buff
*skb
;
1452 RTLLIB_DEBUG_MGMT("Stopping scan\n");
1454 ieee
->softmac_stats
.tx_auth_rq
++;
1456 skb
= rtllib_authentication_req(beacon
, ieee
, 0, daddr
);
1459 rtllib_associate_abort(ieee
);
1461 ieee
->state
= RTLLIB_ASSOCIATING_AUTHENTICATING
;
1462 RTLLIB_DEBUG_MGMT("Sending authentication request\n");
1463 softmac_mgmt_xmit(skb
, ieee
);
1464 if (!timer_pending(&ieee
->associate_timer
)) {
1465 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1466 add_timer(&ieee
->associate_timer
);
1471 static void rtllib_auth_challenge(struct rtllib_device
*ieee
, u8
*challenge
, int chlen
)
1474 struct sk_buff
*skb
;
1475 struct rtllib_network
*beacon
= &ieee
->current_network
;
1477 ieee
->associate_seq
++;
1478 ieee
->softmac_stats
.tx_auth_rq
++;
1480 skb
= rtllib_authentication_req(beacon
, ieee
, chlen
+ 2, beacon
->bssid
);
1483 rtllib_associate_abort(ieee
);
1485 c
= skb_put(skb
, chlen
+2);
1486 *(c
++) = MFIE_TYPE_CHALLENGE
;
1488 memcpy(c
, challenge
, chlen
);
1490 RTLLIB_DEBUG_MGMT("Sending authentication challenge "
1493 rtllib_encrypt_fragment(ieee
, skb
,
1494 sizeof(struct rtllib_hdr_3addr
));
1496 softmac_mgmt_xmit(skb
, ieee
);
1497 mod_timer(&ieee
->associate_timer
, jiffies
+ (HZ
/2));
1502 static void rtllib_associate_step2(struct rtllib_device
*ieee
)
1504 struct sk_buff
*skb
;
1505 struct rtllib_network
*beacon
= &ieee
->current_network
;
1507 del_timer_sync(&ieee
->associate_timer
);
1509 RTLLIB_DEBUG_MGMT("Sending association request\n");
1511 ieee
->softmac_stats
.tx_ass_rq
++;
1512 skb
= rtllib_association_req(beacon
, ieee
);
1514 rtllib_associate_abort(ieee
);
1516 softmac_mgmt_xmit(skb
, ieee
);
1517 mod_timer(&ieee
->associate_timer
, jiffies
+ (HZ
/2));
1522 static void rtllib_associate_complete_wq(void *data
)
1524 struct rtllib_device
*ieee
= (struct rtllib_device
*)
1525 container_of_work_rsl(data
,
1526 struct rtllib_device
,
1527 associate_complete_wq
);
1528 struct rt_pwr_save_ctrl
*pPSC
= (struct rt_pwr_save_ctrl
*)
1529 (&(ieee
->PowerSaveControl
));
1530 printk(KERN_INFO
"Associated successfully\n");
1531 if (ieee
->is_silent_reset
== 0) {
1532 printk(KERN_INFO
"normal associate\n");
1533 notify_wx_assoc_event(ieee
);
1536 netif_carrier_on(ieee
->dev
);
1537 ieee
->is_roaming
= false;
1538 if (rtllib_is_54g(&ieee
->current_network
) &&
1539 (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)) {
1541 printk(KERN_INFO
"Using G rates:%d\n", ieee
->rate
);
1544 ieee
->SetWirelessMode(ieee
->dev
, IEEE_B
);
1545 printk(KERN_INFO
"Using B rates:%d\n", ieee
->rate
);
1547 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1548 printk(KERN_INFO
"Successfully associated, ht enabled\n");
1551 printk(KERN_INFO
"Successfully associated, ht not "
1552 "enabled(%d, %d)\n",
1553 ieee
->pHTInfo
->bCurrentHTSupport
,
1554 ieee
->pHTInfo
->bEnableHT
);
1555 memset(ieee
->dot11HTOperationalRateSet
, 0, 16);
1557 ieee
->LinkDetectInfo
.SlotNum
= 2 * (1 +
1558 ieee
->current_network
.beacon_interval
/
1560 if (ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
== 0 ||
1561 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
== 0) {
1562 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
= 1;
1563 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
= 1;
1565 pPSC
->LpsIdleCount
= 0;
1566 ieee
->link_change(ieee
->dev
);
1568 if (ieee
->is_silent_reset
== 1) {
1569 printk(KERN_INFO
"silent reset associate\n");
1570 ieee
->is_silent_reset
= 0;
1573 if (ieee
->data_hard_resume
)
1574 ieee
->data_hard_resume(ieee
->dev
);
1578 static void rtllib_sta_send_associnfo(struct rtllib_device
*ieee
)
1582 static void rtllib_associate_complete(struct rtllib_device
*ieee
)
1584 del_timer_sync(&ieee
->associate_timer
);
1586 ieee
->state
= RTLLIB_LINKED
;
1587 rtllib_sta_send_associnfo(ieee
);
1589 queue_work_rsl(ieee
->wq
, &ieee
->associate_complete_wq
);
1592 static void rtllib_associate_procedure_wq(void *data
)
1594 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
1595 struct rtllib_device
,
1596 associate_procedure_wq
);
1597 rtllib_stop_scan_syncro(ieee
);
1598 if (ieee
->rtllib_ips_leave
!= NULL
)
1599 ieee
->rtllib_ips_leave(ieee
->dev
);
1600 down(&ieee
->wx_sem
);
1602 if (ieee
->data_hard_stop
)
1603 ieee
->data_hard_stop(ieee
->dev
);
1605 rtllib_stop_scan(ieee
);
1606 RT_TRACE(COMP_DBG
, "===>%s(), chan:%d\n", __func__
,
1607 ieee
->current_network
.channel
);
1608 HTSetConnectBwMode(ieee
, HT_CHANNEL_WIDTH_20
, HT_EXTCHNL_OFFSET_NO_EXT
);
1609 if (ieee
->eRFPowerState
== eRfOff
) {
1610 RT_TRACE(COMP_DBG
, "=============>%s():Rf state is eRfOff,"
1611 " schedule ipsleave wq again,return\n", __func__
);
1612 if (ieee
->rtllib_ips_leave_wq
!= NULL
)
1613 ieee
->rtllib_ips_leave_wq(ieee
->dev
);
1617 ieee
->associate_seq
= 1;
1619 rtllib_associate_step1(ieee
, ieee
->current_network
.bssid
);
1624 inline void rtllib_softmac_new_net(struct rtllib_device
*ieee
,
1625 struct rtllib_network
*net
)
1627 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+ 1];
1628 int tmp_ssid_len
= 0;
1630 short apset
, ssidset
, ssidbroad
, apmatch
, ssidmatch
;
1632 /* we are interested in new new only if we are not associated
1633 * and we are not associating / authenticating
1635 if (ieee
->state
!= RTLLIB_NOLINK
)
1638 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
&
1639 WLAN_CAPABILITY_ESS
))
1642 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
&
1643 WLAN_CAPABILITY_IBSS
))
1646 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) &&
1647 (net
->channel
> ieee
->ibss_maxjoin_chal
))
1649 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
) {
1650 /* if the user specified the AP MAC, we need also the essid
1651 * This could be obtained by beacons or, if the network does not
1652 * broadcast it, it can be put manually.
1654 apset
= ieee
->wap_set
;
1655 ssidset
= ieee
->ssid_set
;
1656 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0] == '\0');
1657 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
,
1660 ssidmatch
= (ieee
->current_network
.ssid_len
==
1661 net
->hidden_ssid_len
) &&
1662 (!strncmp(ieee
->current_network
.ssid
,
1663 net
->hidden_ssid
, net
->hidden_ssid_len
));
1664 if (net
->hidden_ssid_len
> 0) {
1665 strncpy(net
->ssid
, net
->hidden_ssid
,
1666 net
->hidden_ssid_len
);
1667 net
->ssid_len
= net
->hidden_ssid_len
;
1672 (ieee
->current_network
.ssid_len
== net
->ssid_len
) &&
1673 (!strncmp(ieee
->current_network
.ssid
, net
->ssid
,
1676 /* if the user set the AP check if match.
1677 * if the network does not broadcast essid we check the
1678 * user supplyed ANY essid
1679 * if the network does broadcast and the user does not set
1681 * if the network does broadcast and the user did set essid
1682 * check if essid match
1683 * if the ap is not set, check that the user set the bssid
1684 * and the network does bradcast and that those two bssid match
1686 if ((apset
&& apmatch
&&
1687 ((ssidset
&& ssidbroad
&& ssidmatch
) ||
1688 (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
))) ||
1689 (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
) ||
1690 (ieee
->is_roaming
&& ssidset
&& ssidbroad
&& ssidmatch
)) {
1691 /* if the essid is hidden replace it with the
1692 * essid provided by the user.
1695 strncpy(tmp_ssid
, ieee
->current_network
.ssid
,
1697 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1699 memcpy(&ieee
->current_network
, net
,
1700 sizeof(struct rtllib_network
));
1702 strncpy(ieee
->current_network
.ssid
, tmp_ssid
,
1704 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1706 printk(KERN_INFO
"Linking with %s,channel:%d, qos:%d, "
1707 "myHT:%d, networkHT:%d, mode:%x cur_net.flags"
1708 ":0x%x\n", ieee
->current_network
.ssid
,
1709 ieee
->current_network
.channel
,
1710 ieee
->current_network
.qos_data
.supported
,
1711 ieee
->pHTInfo
->bEnableHT
,
1712 ieee
->current_network
.bssht
.bdSupportHT
,
1713 ieee
->current_network
.mode
,
1714 ieee
->current_network
.flags
);
1716 if ((rtllib_act_scanning(ieee
, false)) &&
1717 !(ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
))
1718 rtllib_stop_scan_syncro(ieee
);
1720 ieee
->hwscan_ch_bk
= ieee
->current_network
.channel
;
1721 HTResetIOTSetting(ieee
->pHTInfo
);
1723 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
1724 /* Join the network for the first time */
1725 ieee
->AsocRetryCount
= 0;
1726 if ((ieee
->current_network
.qos_data
.supported
== 1) &&
1727 ieee
->current_network
.bssht
.bdSupportHT
)
1728 HTResetSelfAndSavePeerSetting(ieee
,
1729 &(ieee
->current_network
));
1731 ieee
->pHTInfo
->bCurrentHTSupport
=
1734 ieee
->state
= RTLLIB_ASSOCIATING
;
1735 if (ieee
->LedControlHandler
!= NULL
)
1736 ieee
->LedControlHandler(ieee
->dev
,
1737 LED_CTL_START_TO_LINK
);
1738 queue_delayed_work_rsl(ieee
->wq
,
1739 &ieee
->associate_procedure_wq
, 0);
1741 if (rtllib_is_54g(&ieee
->current_network
) &&
1742 (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)) {
1744 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
1745 printk(KERN_INFO
"Using G rates\n");
1748 ieee
->SetWirelessMode(ieee
->dev
, IEEE_B
);
1749 printk(KERN_INFO
"Using B rates\n");
1751 memset(ieee
->dot11HTOperationalRateSet
, 0, 16);
1752 ieee
->state
= RTLLIB_LINKED
;
1758 void rtllib_softmac_check_all_nets(struct rtllib_device
*ieee
)
1760 unsigned long flags
;
1761 struct rtllib_network
*target
;
1763 spin_lock_irqsave(&ieee
->lock
, flags
);
1765 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1767 /* if the state become different that NOLINK means
1768 * we had found what we are searching for
1771 if (ieee
->state
!= RTLLIB_NOLINK
)
1774 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+
1775 ieee
->scan_age
, jiffies
))
1776 rtllib_softmac_new_net(ieee
, target
);
1778 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1781 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1783 struct rtllib_authentication
*a
;
1785 if (skb
->len
< (sizeof(struct rtllib_authentication
) -
1786 sizeof(struct rtllib_info_element
))) {
1787 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1791 a
= (struct rtllib_authentication
*) skb
->data
;
1792 if (skb
->len
> (sizeof(struct rtllib_authentication
) + 3)) {
1793 t
= skb
->data
+ sizeof(struct rtllib_authentication
);
1795 if (*(t
++) == MFIE_TYPE_CHALLENGE
) {
1797 *challenge
= kmalloc(*chlen
, GFP_ATOMIC
);
1798 memcpy(*challenge
, t
, *chlen
); /*TODO - check here*/
1801 return cpu_to_le16(a
->status
);
1804 static int auth_rq_parse(struct sk_buff
*skb
, u8
*dest
)
1806 struct rtllib_authentication
*a
;
1808 if (skb
->len
< (sizeof(struct rtllib_authentication
) -
1809 sizeof(struct rtllib_info_element
))) {
1810 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",
1814 a
= (struct rtllib_authentication
*) skb
->data
;
1816 memcpy(dest
, a
->header
.addr2
, ETH_ALEN
);
1818 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1819 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1821 return WLAN_STATUS_SUCCESS
;
1824 static short probe_rq_parse(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1831 struct rtllib_hdr_3addr
*header
=
1832 (struct rtllib_hdr_3addr
*) skb
->data
;
1835 if (skb
->len
< sizeof(struct rtllib_hdr_3addr
))
1836 return -1; /* corrupted */
1839 (memcmp(header
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
) != 0) &&
1840 (memcmp(header
->addr3
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0);
1844 memcpy(src
, header
->addr2
, ETH_ALEN
);
1846 skbend
= (u8
*)skb
->data
+ skb
->len
;
1848 tag
= skb
->data
+ sizeof(struct rtllib_hdr_3addr
);
1850 while (tag
+ 1 < skbend
) {
1853 ssidlen
= *(tag
+ 1);
1856 tag
++; /* point to the len field */
1857 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1858 tag
++; /* point to the next tag */
1865 return 1; /* ssid not found in tagged param */
1867 return !strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
);
1870 static int assoc_rq_parse(struct sk_buff
*skb
, u8
*dest
)
1872 struct rtllib_assoc_request_frame
*a
;
1874 if (skb
->len
< (sizeof(struct rtllib_assoc_request_frame
) -
1875 sizeof(struct rtllib_info_element
))) {
1877 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d\n", skb
->len
);
1881 a
= (struct rtllib_assoc_request_frame
*) skb
->data
;
1883 memcpy(dest
, a
->header
.addr2
, ETH_ALEN
);
1888 static inline u16
assoc_parse(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1891 struct rtllib_assoc_response_frame
*response_head
;
1894 if (skb
->len
< sizeof(struct rtllib_assoc_response_frame
)) {
1895 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1899 response_head
= (struct rtllib_assoc_response_frame
*) skb
->data
;
1900 *aid
= le16_to_cpu(response_head
->aid
) & 0x3fff;
1902 status_code
= le16_to_cpu(response_head
->status
);
1903 if ((status_code
== WLAN_STATUS_ASSOC_DENIED_RATES
||
1904 status_code
== WLAN_STATUS_CAPS_UNSUPPORTED
) &&
1905 ((ieee
->mode
== IEEE_G
) &&
1906 (ieee
->current_network
.mode
== IEEE_N_24G
) &&
1907 (ieee
->AsocRetryCount
++ < (RT_ASOC_RETRY_LIMIT
-1)))) {
1908 ieee
->pHTInfo
->IOTAction
|= HT_IOT_ACT_PURE_N_MODE
;
1910 ieee
->AsocRetryCount
= 0;
1913 return le16_to_cpu(response_head
->status
);
1916 void rtllib_rx_probe_rq(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
1919 ieee
->softmac_stats
.rx_probe_rq
++;
1920 if (probe_rq_parse(ieee
, skb
, dest
) > 0) {
1921 ieee
->softmac_stats
.tx_probe_rs
++;
1922 rtllib_resp_to_probe(ieee
, dest
);
1926 static inline void rtllib_rx_auth_rq(struct rtllib_device
*ieee
,
1927 struct sk_buff
*skb
)
1931 ieee
->softmac_stats
.rx_auth_rq
++;
1933 status
= auth_rq_parse(skb
, dest
);
1935 rtllib_resp_to_auth(ieee
, status
, dest
);
1938 static inline void rtllib_rx_assoc_rq(struct rtllib_device
*ieee
,
1939 struct sk_buff
*skb
)
1944 ieee
->softmac_stats
.rx_ass_rq
++;
1945 if (assoc_rq_parse(skb
, dest
) != -1)
1946 rtllib_resp_to_assoc_rq(ieee
, dest
);
1948 printk(KERN_INFO
"New client associated: %pM\n", dest
);
1951 void rtllib_sta_ps_send_null_frame(struct rtllib_device
*ieee
, short pwr
)
1954 struct sk_buff
*buf
= rtllib_null_func(ieee
, pwr
);
1957 softmac_ps_mgmt_xmit(buf
, ieee
);
1960 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device
*ieee
)
1962 struct sk_buff
*buf
= rtllib_pspoll_func(ieee
);
1965 softmac_ps_mgmt_xmit(buf
, ieee
);
1968 static short rtllib_sta_ps_sleep(struct rtllib_device
*ieee
, u64
*time
)
1970 int timeout
= ieee
->ps_timeout
;
1972 struct rt_pwr_save_ctrl
*pPSC
= (struct rt_pwr_save_ctrl
*)
1973 (&(ieee
->PowerSaveControl
));
1975 if (ieee
->LPSDelayCnt
) {
1976 ieee
->LPSDelayCnt
--;
1980 dtim
= ieee
->current_network
.dtim_data
;
1981 if (!(dtim
& RTLLIB_DTIM_VALID
))
1983 timeout
= ieee
->current_network
.beacon_interval
;
1984 ieee
->current_network
.dtim_data
= RTLLIB_DTIM_INVALID
;
1985 /* there's no need to nofity AP that I find you buffered
1986 * with broadcast packet */
1987 if (dtim
& (RTLLIB_DTIM_UCAST
& ieee
->ps
))
1990 if (!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
)))
1992 if (!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
)))
1994 if ((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
1995 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
1999 if (ieee
->bAwakePktSent
== true) {
2000 pPSC
->LPSAwakeIntvl
= 1;
2004 if (pPSC
->LPSAwakeIntvl
== 0)
2005 pPSC
->LPSAwakeIntvl
= 1;
2006 if (pPSC
->RegMaxLPSAwakeIntvl
== 0)
2008 else if (pPSC
->RegMaxLPSAwakeIntvl
== 0xFF)
2009 MaxPeriod
= ieee
->current_network
.dtim_period
;
2011 MaxPeriod
= pPSC
->RegMaxLPSAwakeIntvl
;
2012 pPSC
->LPSAwakeIntvl
= (pPSC
->LPSAwakeIntvl
>=
2013 MaxPeriod
) ? MaxPeriod
:
2014 (pPSC
->LPSAwakeIntvl
+ 1);
2017 u8 LPSAwakeIntvl_tmp
= 0;
2018 u8 period
= ieee
->current_network
.dtim_period
;
2019 u8 count
= ieee
->current_network
.tim
.tim_count
;
2021 if (pPSC
->LPSAwakeIntvl
> period
)
2022 LPSAwakeIntvl_tmp
= period
+
2023 (pPSC
->LPSAwakeIntvl
-
2025 ((pPSC
->LPSAwakeIntvl
-period
) %
2028 LPSAwakeIntvl_tmp
= pPSC
->LPSAwakeIntvl
;
2031 if (pPSC
->LPSAwakeIntvl
>
2032 ieee
->current_network
.tim
.tim_count
)
2033 LPSAwakeIntvl_tmp
= count
+
2034 (pPSC
->LPSAwakeIntvl
- count
) -
2035 ((pPSC
->LPSAwakeIntvl
-count
)%period
);
2037 LPSAwakeIntvl_tmp
= pPSC
->LPSAwakeIntvl
;
2040 *time
= ieee
->current_network
.last_dtim_sta_time
2041 + MSECS(ieee
->current_network
.beacon_interval
*
2051 static inline void rtllib_sta_ps(struct rtllib_device
*ieee
)
2055 unsigned long flags
, flags2
;
2057 spin_lock_irqsave(&ieee
->lock
, flags
);
2059 if ((ieee
->ps
== RTLLIB_PS_DISABLED
||
2060 ieee
->iw_mode
!= IW_MODE_INFRA
||
2061 ieee
->state
!= RTLLIB_LINKED
)) {
2062 RT_TRACE(COMP_DBG
, "=====>%s(): no need to ps,wake up!! "
2063 "ieee->ps is %d, ieee->iw_mode is %d, ieee->state"
2064 " is %d\n", __func__
, ieee
->ps
, ieee
->iw_mode
,
2066 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2067 rtllib_sta_wakeup(ieee
, 1);
2069 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2071 sleep
= rtllib_sta_ps_sleep(ieee
, &time
);
2072 /* 2 wake, 1 sleep, 0 do nothing */
2076 if (ieee
->sta_sleep
== LPS_IS_SLEEP
) {
2077 ieee
->enter_sleep_state(ieee
->dev
, time
);
2078 } else if (ieee
->sta_sleep
== LPS_IS_WAKE
) {
2079 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2081 if (ieee
->ps_is_queue_empty(ieee
->dev
)) {
2082 ieee
->sta_sleep
= LPS_WAIT_NULL_DATA_SEND
;
2083 ieee
->ack_tx_to_ieee
= 1;
2084 rtllib_sta_ps_send_null_frame(ieee
, 1);
2085 ieee
->ps_time
= time
;
2087 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2091 ieee
->bAwakePktSent
= false;
2093 } else if (sleep
== 2) {
2094 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2096 rtllib_sta_wakeup(ieee
, 1);
2098 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2102 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2106 void rtllib_sta_wakeup(struct rtllib_device
*ieee
, short nl
)
2108 if (ieee
->sta_sleep
== LPS_IS_WAKE
) {
2110 if (ieee
->pHTInfo
->IOTAction
&
2111 HT_IOT_ACT_NULL_DATA_POWER_SAVING
) {
2112 ieee
->ack_tx_to_ieee
= 1;
2113 rtllib_sta_ps_send_null_frame(ieee
, 0);
2115 ieee
->ack_tx_to_ieee
= 1;
2116 rtllib_sta_ps_send_pspoll_frame(ieee
);
2123 if (ieee
->sta_sleep
== LPS_IS_SLEEP
)
2124 ieee
->sta_wake_up(ieee
->dev
);
2126 if (ieee
->pHTInfo
->IOTAction
&
2127 HT_IOT_ACT_NULL_DATA_POWER_SAVING
) {
2128 ieee
->ack_tx_to_ieee
= 1;
2129 rtllib_sta_ps_send_null_frame(ieee
, 0);
2131 ieee
->ack_tx_to_ieee
= 1;
2132 ieee
->polling
= true;
2133 rtllib_sta_ps_send_pspoll_frame(ieee
);
2137 ieee
->sta_sleep
= LPS_IS_WAKE
;
2138 ieee
->polling
= false;
2142 void rtllib_ps_tx_ack(struct rtllib_device
*ieee
, short success
)
2144 unsigned long flags
, flags2
;
2146 spin_lock_irqsave(&ieee
->lock
, flags
);
2148 if (ieee
->sta_sleep
== LPS_WAIT_NULL_DATA_SEND
) {
2149 /* Null frame with PS bit set */
2151 ieee
->sta_sleep
= LPS_IS_SLEEP
;
2152 ieee
->enter_sleep_state(ieee
->dev
, ieee
->ps_time
);
2154 /* if the card report not success we can't be sure the AP
2155 * has not RXed so we can't assume the AP believe us awake
2157 } else {/* 21112005 - tx again null without PS bit if lost */
2159 if ((ieee
->sta_sleep
== LPS_IS_WAKE
) && !success
) {
2160 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2161 if (ieee
->pHTInfo
->IOTAction
&
2162 HT_IOT_ACT_NULL_DATA_POWER_SAVING
)
2163 rtllib_sta_ps_send_null_frame(ieee
, 0);
2165 rtllib_sta_ps_send_pspoll_frame(ieee
);
2166 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2169 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2172 static void rtllib_process_action(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
2174 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2175 u8
*act
= rtllib_get_payload((struct rtllib_hdr
*)header
);
2179 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "error to get payload of "
2190 rtllib_rx_ADDBAReq(ieee
, skb
);
2193 rtllib_rx_ADDBARsp(ieee
, skb
);
2196 rtllib_rx_DELBA(ieee
, skb
);
2206 inline int rtllib_rx_assoc_resp(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
2207 struct rtllib_rx_stats
*rx_stats
)
2212 struct rtllib_assoc_response_frame
*assoc_resp
;
2213 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2215 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2216 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2218 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2219 ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATED
&&
2220 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2221 errcode
= assoc_parse(ieee
, skb
, &aid
);
2223 struct rtllib_network
*network
=
2224 kzalloc(sizeof(struct rtllib_network
),
2229 memset(network
, 0, sizeof(*network
));
2230 ieee
->state
= RTLLIB_LINKED
;
2231 ieee
->assoc_id
= aid
;
2232 ieee
->softmac_stats
.rx_ass_ok
++;
2233 /* station support qos */
2234 /* Let the register setting default with Legacy station */
2235 assoc_resp
= (struct rtllib_assoc_response_frame
*)skb
->data
;
2236 if (ieee
->current_network
.qos_data
.supported
== 1) {
2237 if (rtllib_parse_info_param(ieee
, assoc_resp
->info_element
,
2238 rx_stats
->len
- sizeof(*assoc_resp
),
2239 network
, rx_stats
)) {
2243 memcpy(ieee
->pHTInfo
->PeerHTCapBuf
,
2244 network
->bssht
.bdHTCapBuf
,
2245 network
->bssht
.bdHTCapLen
);
2246 memcpy(ieee
->pHTInfo
->PeerHTInfoBuf
,
2247 network
->bssht
.bdHTInfoBuf
,
2248 network
->bssht
.bdHTInfoLen
);
2250 if (ieee
->handle_assoc_response
!= NULL
)
2251 ieee
->handle_assoc_response(ieee
->dev
,
2252 (struct rtllib_assoc_response_frame
*)header
,
2257 kfree(ieee
->assocresp_ies
);
2258 ieee
->assocresp_ies
= NULL
;
2259 ies
= &(assoc_resp
->info_element
[0].id
);
2260 ieee
->assocresp_ies_len
= (skb
->data
+ skb
->len
) - ies
;
2261 ieee
->assocresp_ies
= kmalloc(ieee
->assocresp_ies_len
,
2263 if (ieee
->assocresp_ies
)
2264 memcpy(ieee
->assocresp_ies
, ies
,
2265 ieee
->assocresp_ies_len
);
2267 printk(KERN_INFO
"%s()Warning: can't alloc "
2268 "memory for assocresp_ies\n", __func__
);
2269 ieee
->assocresp_ies_len
= 0;
2271 rtllib_associate_complete(ieee
);
2273 /* aid could not been allocated */
2274 ieee
->softmac_stats
.rx_ass_err
++;
2275 printk(KERN_INFO
"Association response status code 0x%x\n",
2278 "Association response status code 0x%x\n",
2280 if (ieee
->AsocRetryCount
< RT_ASOC_RETRY_LIMIT
)
2281 queue_delayed_work_rsl(ieee
->wq
,
2282 &ieee
->associate_procedure_wq
, 0);
2284 rtllib_associate_abort(ieee
);
2290 inline int rtllib_rx_auth(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
2291 struct rtllib_rx_stats
*rx_stats
)
2296 bool bSupportNmode
= true, bHalfSupportNmode
= false;
2298 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) {
2299 if (ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATING
&&
2300 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2301 RTLLIB_DEBUG_MGMT("Received authentication response");
2303 errcode
= auth_parse(skb
, &challenge
, &chlen
);
2305 if (ieee
->open_wep
|| !challenge
) {
2306 ieee
->state
= RTLLIB_ASSOCIATING_AUTHENTICATED
;
2307 ieee
->softmac_stats
.rx_auth_rs_ok
++;
2308 if (!(ieee
->pHTInfo
->IOTAction
&
2309 HT_IOT_ACT_PURE_N_MODE
)) {
2310 if (!ieee
->GetNmodeSupportBySecCfg(ieee
->dev
)) {
2311 if (IsHTHalfNmodeAPs(ieee
)) {
2312 bSupportNmode
= true;
2313 bHalfSupportNmode
= true;
2315 bSupportNmode
= false;
2316 bHalfSupportNmode
= false;
2320 /* Dummy wirless mode setting to avoid
2321 * encryption issue */
2322 if (bSupportNmode
) {
2323 ieee
->SetWirelessMode(ieee
->dev
,
2324 ieee
->current_network
.mode
);
2327 ieee
->SetWirelessMode(ieee
->dev
,
2331 if (ieee
->current_network
.mode
==
2333 bHalfSupportNmode
== true) {
2334 printk(KERN_INFO
"======>enter "
2336 ieee
->bHalfWirelessN24GMode
=
2339 ieee
->bHalfWirelessN24GMode
=
2342 rtllib_associate_step2(ieee
);
2344 rtllib_auth_challenge(ieee
, challenge
,
2348 ieee
->softmac_stats
.rx_auth_rs_err
++;
2349 RTLLIB_DEBUG_MGMT("Authentication respose"
2350 " status code 0x%x", errcode
);
2352 printk(KERN_INFO
"Authentication respose "
2353 "status code 0x%x", errcode
);
2354 rtllib_associate_abort(ieee
);
2357 } else if (ieee
->iw_mode
== IW_MODE_MASTER
) {
2358 rtllib_rx_auth_rq(ieee
, skb
);
2364 inline int rtllib_rx_deauth(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
2366 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2368 if (memcmp(header
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
) != 0)
2371 /* FIXME for now repeat all the association procedure
2372 * both for disassociation and deauthentication
2374 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2375 ieee
->state
== RTLLIB_LINKED
&&
2376 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2377 printk(KERN_INFO
"==========>received disassoc/deauth(%x) "
2378 "frame, reason code:%x\n",
2379 WLAN_FC_GET_STYPE(header
->frame_ctl
),
2380 ((struct rtllib_disassoc
*)skb
->data
)->reason
);
2381 ieee
->state
= RTLLIB_ASSOCIATING
;
2382 ieee
->softmac_stats
.reassoc
++;
2383 ieee
->is_roaming
= true;
2384 ieee
->LinkDetectInfo
.bBusyTraffic
= false;
2385 rtllib_disassociate(ieee
);
2386 RemovePeerTS(ieee
, header
->addr2
);
2387 if (ieee
->LedControlHandler
!= NULL
)
2388 ieee
->LedControlHandler(ieee
->dev
,
2389 LED_CTL_START_TO_LINK
);
2391 if (!(ieee
->rtllib_ap_sec_type(ieee
) &
2392 (SEC_ALG_CCMP
|SEC_ALG_TKIP
)))
2393 queue_delayed_work_rsl(ieee
->wq
,
2394 &ieee
->associate_procedure_wq
, 5);
2399 inline int rtllib_rx_frame_softmac(struct rtllib_device
*ieee
,
2400 struct sk_buff
*skb
,
2401 struct rtllib_rx_stats
*rx_stats
, u16 type
,
2404 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2406 if (!ieee
->proto_started
)
2409 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2410 case RTLLIB_STYPE_ASSOC_RESP
:
2411 case RTLLIB_STYPE_REASSOC_RESP
:
2412 if (rtllib_rx_assoc_resp(ieee
, skb
, rx_stats
) == 1)
2415 case RTLLIB_STYPE_ASSOC_REQ
:
2416 case RTLLIB_STYPE_REASSOC_REQ
:
2417 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2418 ieee
->iw_mode
== IW_MODE_MASTER
)
2419 rtllib_rx_assoc_rq(ieee
, skb
);
2421 case RTLLIB_STYPE_AUTH
:
2422 rtllib_rx_auth(ieee
, skb
, rx_stats
);
2424 case RTLLIB_STYPE_DISASSOC
:
2425 case RTLLIB_STYPE_DEAUTH
:
2426 rtllib_rx_deauth(ieee
, skb
);
2428 case RTLLIB_STYPE_MANAGE_ACT
:
2429 rtllib_process_action(ieee
, skb
);
2438 /* following are for a simplier TX queue management.
2439 * Instead of using netif_[stop/wake]_queue the driver
2440 * will uses these two function (plus a reset one), that
2441 * will internally uses the kernel netif_* and takes
2442 * care of the ieee802.11 fragmentation.
2443 * So the driver receives a fragment per time and might
2444 * call the stop function when it want without take care
2445 * to have enought room to TX an entire packet.
2446 * This might be useful if each fragment need it's own
2447 * descriptor, thus just keep a total free memory > than
2448 * the max fragmentation treshold is not enought.. If the
2449 * ieee802.11 stack passed a TXB struct then you needed
2450 * to keep N free descriptors where
2451 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2452 * In this way you need just one and the 802.11 stack
2453 * will take care of buffering fragments and pass them to
2454 * to the driver later, when it wakes the queue.
2456 void rtllib_softmac_xmit(struct rtllib_txb
*txb
, struct rtllib_device
*ieee
)
2459 unsigned int queue_index
= txb
->queue_index
;
2460 unsigned long flags
;
2462 struct cb_desc
*tcb_desc
= NULL
;
2463 unsigned long queue_len
= 0;
2465 spin_lock_irqsave(&ieee
->lock
, flags
);
2467 /* called with 2nd parm 0, no tx mgmt lock required */
2468 rtllib_sta_wakeup(ieee
, 0);
2470 /* update the tx status */
2471 tcb_desc
= (struct cb_desc
*)(txb
->fragments
[0]->cb
+
2473 if (tcb_desc
->bMulticast
)
2474 ieee
->stats
.multicast
++;
2476 /* if xmit available, just xmit it immediately, else just insert it to
2478 for (i
= 0; i
< txb
->nr_frags
; i
++) {
2479 queue_len
= skb_queue_len(&ieee
->skb_waitQ
[queue_index
]);
2480 if ((queue_len
!= 0) ||\
2481 (!ieee
->check_nic_enough_desc(ieee
->dev
, queue_index
)) ||
2482 (ieee
->queue_stop
)) {
2483 /* insert the skb packet to the wait queue */
2484 /* as for the completion function, it does not need
2485 * to check it any more.
2487 if (queue_len
< 200)
2488 skb_queue_tail(&ieee
->skb_waitQ
[queue_index
],
2491 kfree_skb(txb
->fragments
[i
]);
2493 ieee
->softmac_data_hard_start_xmit(
2495 ieee
->dev
, ieee
->rate
);
2499 rtllib_txb_free(txb
);
2501 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2505 /* called with ieee->lock acquired */
2506 static void rtllib_resume_tx(struct rtllib_device
*ieee
)
2509 for (i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
;
2512 if (ieee
->queue_stop
) {
2513 ieee
->tx_pending
.frag
= i
;
2517 ieee
->softmac_data_hard_start_xmit(
2518 ieee
->tx_pending
.txb
->fragments
[i
],
2519 ieee
->dev
, ieee
->rate
);
2520 ieee
->stats
.tx_packets
++;
2524 rtllib_txb_free(ieee
->tx_pending
.txb
);
2525 ieee
->tx_pending
.txb
= NULL
;
2529 void rtllib_reset_queue(struct rtllib_device
*ieee
)
2531 unsigned long flags
;
2533 spin_lock_irqsave(&ieee
->lock
, flags
);
2534 init_mgmt_queue(ieee
);
2535 if (ieee
->tx_pending
.txb
) {
2536 rtllib_txb_free(ieee
->tx_pending
.txb
);
2537 ieee
->tx_pending
.txb
= NULL
;
2539 ieee
->queue_stop
= 0;
2540 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2544 void rtllib_wake_queue(struct rtllib_device
*ieee
)
2547 unsigned long flags
;
2548 struct sk_buff
*skb
;
2549 struct rtllib_hdr_3addr
*header
;
2551 spin_lock_irqsave(&ieee
->lock
, flags
);
2552 if (!ieee
->queue_stop
)
2555 ieee
->queue_stop
= 0;
2557 if (ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) {
2558 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))) {
2560 header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2562 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2564 if (ieee
->seq_ctrl
[0] == 0xFFF)
2565 ieee
->seq_ctrl
[0] = 0;
2567 ieee
->seq_ctrl
[0]++;
2569 ieee
->softmac_data_hard_start_xmit(skb
, ieee
->dev
,
2573 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2574 rtllib_resume_tx(ieee
);
2576 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)) {
2577 ieee
->softmac_stats
.swtxawake
++;
2578 netif_wake_queue(ieee
->dev
);
2582 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2586 void rtllib_stop_queue(struct rtllib_device
*ieee
)
2589 if (!netif_queue_stopped(ieee
->dev
)) {
2590 netif_stop_queue(ieee
->dev
);
2591 ieee
->softmac_stats
.swtxstop
++;
2593 ieee
->queue_stop
= 1;
2597 void rtllib_stop_all_queues(struct rtllib_device
*ieee
)
2600 for (i
= 0; i
< ieee
->dev
->num_tx_queues
; i
++)
2601 netdev_get_tx_queue(ieee
->dev
, i
)->trans_start
= jiffies
;
2603 netif_tx_stop_all_queues(ieee
->dev
);
2606 void rtllib_wake_all_queues(struct rtllib_device
*ieee
)
2608 netif_tx_wake_all_queues(ieee
->dev
);
2611 inline void rtllib_randomize_cell(struct rtllib_device
*ieee
)
2614 get_random_bytes(ieee
->current_network
.bssid
, ETH_ALEN
);
2616 /* an IBSS cell address must have the two less significant
2617 * bits of the first byte = 2
2619 ieee
->current_network
.bssid
[0] &= ~0x01;
2620 ieee
->current_network
.bssid
[0] |= 0x02;
2623 /* called in user context only */
2624 void rtllib_start_master_bss(struct rtllib_device
*ieee
)
2628 if (ieee
->current_network
.ssid_len
== 0) {
2629 strncpy(ieee
->current_network
.ssid
,
2630 RTLLIB_DEFAULT_TX_ESSID
,
2633 ieee
->current_network
.ssid_len
=
2634 strlen(RTLLIB_DEFAULT_TX_ESSID
);
2638 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2640 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2641 ieee
->state
= RTLLIB_LINKED
;
2642 ieee
->link_change(ieee
->dev
);
2643 notify_wx_assoc_event(ieee
);
2645 if (ieee
->data_hard_resume
)
2646 ieee
->data_hard_resume(ieee
->dev
);
2648 netif_carrier_on(ieee
->dev
);
2651 static void rtllib_start_monitor_mode(struct rtllib_device
*ieee
)
2653 /* reset hardware status */
2655 if (ieee
->data_hard_resume
)
2656 ieee
->data_hard_resume(ieee
->dev
);
2658 netif_carrier_on(ieee
->dev
);
2662 static void rtllib_start_ibss_wq(void *data
)
2664 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
2665 struct rtllib_device
, start_ibss_wq
);
2666 /* iwconfig mode ad-hoc will schedule this and return
2667 * on the other hand this will block further iwconfig SET
2668 * operations because of the wx_sem hold.
2669 * Anyway some most set operations set a flag to speed-up
2670 * (abort) this wq (when syncro scanning) before sleeping
2673 if (!ieee
->proto_started
) {
2674 printk(KERN_INFO
"==========oh driver down return\n");
2677 down(&ieee
->wx_sem
);
2679 if (ieee
->current_network
.ssid_len
== 0) {
2680 strcpy(ieee
->current_network
.ssid
, RTLLIB_DEFAULT_TX_ESSID
);
2681 ieee
->current_network
.ssid_len
= strlen(RTLLIB_DEFAULT_TX_ESSID
);
2685 ieee
->state
= RTLLIB_NOLINK
;
2686 ieee
->mode
= IEEE_G
;
2687 /* check if we have this cell in our network list */
2688 rtllib_softmac_check_all_nets(ieee
);
2691 /* if not then the state is not linked. Maybe the user swithced to
2692 * ad-hoc mode just after being in monitor mode, or just after
2693 * being very few time in managed mode (so the card have had no
2694 * time to scan all the chans..) or we have just run up the iface
2695 * after setting ad-hoc mode. So we have to give another try..
2696 * Here, in ibss mode, should be safe to do this without extra care
2697 * (in bss mode we had to make sure no-one tryed to associate when
2698 * we had just checked the ieee->state and we was going to start the
2699 * scan) beacause in ibss mode the rtllib_new_net function, when
2700 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2701 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2702 * scan, that will stop at the first round because it sees the state
2705 if (ieee
->state
== RTLLIB_NOLINK
)
2706 rtllib_start_scan_syncro(ieee
, 0);
2708 /* the network definitively is not here.. create a new cell */
2709 if (ieee
->state
== RTLLIB_NOLINK
) {
2710 printk(KERN_INFO
"creating new IBSS cell\n");
2711 ieee
->current_network
.channel
= ieee
->IbssStartChnl
;
2713 rtllib_randomize_cell(ieee
);
2715 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
) {
2717 ieee
->current_network
.rates_len
= 4;
2719 ieee
->current_network
.rates
[0] =
2720 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_1MB
;
2721 ieee
->current_network
.rates
[1] =
2722 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_2MB
;
2723 ieee
->current_network
.rates
[2] =
2724 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_5MB
;
2725 ieee
->current_network
.rates
[3] =
2726 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_11MB
;
2729 ieee
->current_network
.rates_len
= 0;
2731 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
) {
2732 ieee
->current_network
.rates_ex_len
= 8;
2734 ieee
->current_network
.rates_ex
[0] =
2735 RTLLIB_OFDM_RATE_6MB
;
2736 ieee
->current_network
.rates_ex
[1] =
2737 RTLLIB_OFDM_RATE_9MB
;
2738 ieee
->current_network
.rates_ex
[2] =
2739 RTLLIB_OFDM_RATE_12MB
;
2740 ieee
->current_network
.rates_ex
[3] =
2741 RTLLIB_OFDM_RATE_18MB
;
2742 ieee
->current_network
.rates_ex
[4] =
2743 RTLLIB_OFDM_RATE_24MB
;
2744 ieee
->current_network
.rates_ex
[5] =
2745 RTLLIB_OFDM_RATE_36MB
;
2746 ieee
->current_network
.rates_ex
[6] =
2747 RTLLIB_OFDM_RATE_48MB
;
2748 ieee
->current_network
.rates_ex
[7] =
2749 RTLLIB_OFDM_RATE_54MB
;
2753 ieee
->current_network
.rates_ex_len
= 0;
2757 ieee
->current_network
.qos_data
.supported
= 0;
2758 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
2759 ieee
->current_network
.mode
= ieee
->mode
;
2760 ieee
->current_network
.atim_window
= 0;
2761 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2764 printk(KERN_INFO
"%s(): ieee->mode = %d\n", __func__
, ieee
->mode
);
2765 if ((ieee
->mode
== IEEE_N_24G
) || (ieee
->mode
== IEEE_N_5G
))
2766 HTUseDefaultSetting(ieee
);
2768 ieee
->pHTInfo
->bCurrentHTSupport
= false;
2770 ieee
->SetHwRegHandler(ieee
->dev
, HW_VAR_MEDIA_STATUS
,
2771 (u8
*)(&ieee
->state
));
2773 ieee
->state
= RTLLIB_LINKED
;
2774 ieee
->link_change(ieee
->dev
);
2776 HTSetConnectBwMode(ieee
, HT_CHANNEL_WIDTH_20
, HT_EXTCHNL_OFFSET_NO_EXT
);
2777 if (ieee
->LedControlHandler
!= NULL
)
2778 ieee
->LedControlHandler(ieee
->dev
, LED_CTL_LINK
);
2780 rtllib_start_send_beacons(ieee
);
2782 notify_wx_assoc_event(ieee
);
2784 if (ieee
->data_hard_resume
)
2785 ieee
->data_hard_resume(ieee
->dev
);
2787 netif_carrier_on(ieee
->dev
);
2792 inline void rtllib_start_ibss(struct rtllib_device
*ieee
)
2794 queue_delayed_work_rsl(ieee
->wq
, &ieee
->start_ibss_wq
, MSECS(150));
2797 /* this is called only in user context, with wx_sem held */
2798 void rtllib_start_bss(struct rtllib_device
*ieee
)
2800 unsigned long flags
;
2801 if (IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
)) {
2802 if (!ieee
->bGlobalDomain
)
2805 /* check if we have already found the net we
2806 * are interested in (if any).
2807 * if not (we are disassociated and we are not
2808 * in associating / authenticating phase) start the background scanning.
2810 rtllib_softmac_check_all_nets(ieee
);
2812 /* ensure no-one start an associating process (thus setting
2813 * the ieee->state to rtllib_ASSOCIATING) while we
2814 * have just cheked it and we are going to enable scan.
2815 * The rtllib_new_net function is always called with
2816 * lock held (from both rtllib_softmac_check_all_nets and
2817 * the rx path), so we cannot be in the middle of such function
2819 spin_lock_irqsave(&ieee
->lock
, flags
);
2821 if (ieee
->state
== RTLLIB_NOLINK
)
2822 rtllib_start_scan(ieee
);
2823 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2826 static void rtllib_link_change_wq(void *data
)
2828 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
2829 struct rtllib_device
, link_change_wq
);
2830 ieee
->link_change(ieee
->dev
);
2832 /* called only in userspace context */
2833 void rtllib_disassociate(struct rtllib_device
*ieee
)
2835 netif_carrier_off(ieee
->dev
);
2836 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2837 rtllib_reset_queue(ieee
);
2839 if (ieee
->data_hard_stop
)
2840 ieee
->data_hard_stop(ieee
->dev
);
2841 if (IS_DOT11D_ENABLE(ieee
))
2843 ieee
->state
= RTLLIB_NOLINK
;
2844 ieee
->is_set_key
= false;
2847 queue_delayed_work_rsl(ieee
->wq
, &ieee
->link_change_wq
, 0);
2849 notify_wx_assoc_event(ieee
);
2852 static void rtllib_associate_retry_wq(void *data
)
2854 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
2855 struct rtllib_device
, associate_retry_wq
);
2856 unsigned long flags
;
2858 down(&ieee
->wx_sem
);
2859 if (!ieee
->proto_started
)
2862 if (ieee
->state
!= RTLLIB_ASSOCIATING_RETRY
)
2865 /* until we do not set the state to RTLLIB_NOLINK
2866 * there are no possibility to have someone else trying
2867 * to start an association procdure (we get here with
2868 * ieee->state = RTLLIB_ASSOCIATING).
2869 * When we set the state to RTLLIB_NOLINK it is possible
2870 * that the RX path run an attempt to associate, but
2871 * both rtllib_softmac_check_all_nets and the
2872 * RX path works with ieee->lock held so there are no
2873 * problems. If we are still disassociated then start a scan.
2874 * the lock here is necessary to ensure no one try to start
2875 * an association procedure when we have just checked the
2876 * state and we are going to start the scan.
2878 ieee
->beinretry
= true;
2879 ieee
->state
= RTLLIB_NOLINK
;
2881 rtllib_softmac_check_all_nets(ieee
);
2883 spin_lock_irqsave(&ieee
->lock
, flags
);
2885 if (ieee
->state
== RTLLIB_NOLINK
)
2886 rtllib_start_scan(ieee
);
2887 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2889 ieee
->beinretry
= false;
2894 struct sk_buff
*rtllib_get_beacon_(struct rtllib_device
*ieee
)
2896 u8 broadcast_addr
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2898 struct sk_buff
*skb
;
2899 struct rtllib_probe_response
*b
;
2900 skb
= rtllib_probe_resp(ieee
, broadcast_addr
);
2905 b
= (struct rtllib_probe_response
*) skb
->data
;
2906 b
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_BEACON
);
2912 struct sk_buff
*rtllib_get_beacon(struct rtllib_device
*ieee
)
2914 struct sk_buff
*skb
;
2915 struct rtllib_probe_response
*b
;
2917 skb
= rtllib_get_beacon_(ieee
);
2921 b
= (struct rtllib_probe_response
*) skb
->data
;
2922 b
->header
.seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2924 if (ieee
->seq_ctrl
[0] == 0xFFF)
2925 ieee
->seq_ctrl
[0] = 0;
2927 ieee
->seq_ctrl
[0]++;
2932 void rtllib_softmac_stop_protocol(struct rtllib_device
*ieee
, u8 mesh_flag
,
2935 rtllib_stop_scan_syncro(ieee
);
2936 down(&ieee
->wx_sem
);
2937 rtllib_stop_protocol(ieee
, shutdown
);
2942 void rtllib_stop_protocol(struct rtllib_device
*ieee
, u8 shutdown
)
2944 if (!ieee
->proto_started
)
2948 ieee
->proto_started
= 0;
2949 ieee
->proto_stoppping
= 1;
2950 if (ieee
->rtllib_ips_leave
!= NULL
)
2951 ieee
->rtllib_ips_leave(ieee
->dev
);
2954 rtllib_stop_send_beacons(ieee
);
2955 del_timer_sync(&ieee
->associate_timer
);
2956 cancel_delayed_work(&ieee
->associate_retry_wq
);
2957 cancel_delayed_work(&ieee
->start_ibss_wq
);
2958 cancel_delayed_work(&ieee
->link_change_wq
);
2959 rtllib_stop_scan(ieee
);
2961 if (ieee
->state
<= RTLLIB_ASSOCIATING_AUTHENTICATED
)
2962 ieee
->state
= RTLLIB_NOLINK
;
2964 if (ieee
->state
== RTLLIB_LINKED
) {
2965 if (ieee
->iw_mode
== IW_MODE_INFRA
)
2966 SendDisassociation(ieee
, 1, deauth_lv_ss
);
2967 rtllib_disassociate(ieee
);
2972 ieee
->proto_stoppping
= 0;
2974 kfree(ieee
->assocreq_ies
);
2975 ieee
->assocreq_ies
= NULL
;
2976 ieee
->assocreq_ies_len
= 0;
2977 kfree(ieee
->assocresp_ies
);
2978 ieee
->assocresp_ies
= NULL
;
2979 ieee
->assocresp_ies_len
= 0;
2982 void rtllib_softmac_start_protocol(struct rtllib_device
*ieee
, u8 mesh_flag
)
2984 down(&ieee
->wx_sem
);
2985 rtllib_start_protocol(ieee
);
2989 void rtllib_start_protocol(struct rtllib_device
*ieee
)
2994 rtllib_update_active_chan_map(ieee
);
2996 if (ieee
->proto_started
)
2999 ieee
->proto_started
= 1;
3001 if (ieee
->current_network
.channel
== 0) {
3004 if (ch
> MAX_CHANNEL_NUMBER
)
3005 return; /* no channel found */
3006 } while (!ieee
->active_channel_map
[ch
]);
3007 ieee
->current_network
.channel
= ch
;
3010 if (ieee
->current_network
.beacon_interval
== 0)
3011 ieee
->current_network
.beacon_interval
= 100;
3013 for (i
= 0; i
< 17; i
++) {
3014 ieee
->last_rxseq_num
[i
] = -1;
3015 ieee
->last_rxfrag_num
[i
] = -1;
3016 ieee
->last_packet_time
[i
] = 0;
3019 if (ieee
->UpdateBeaconInterruptHandler
)
3020 ieee
->UpdateBeaconInterruptHandler(ieee
->dev
, false);
3023 /* if the user set the MAC of the ad-hoc cell and then
3024 * switch to managed mode, shall we make sure that association
3025 * attempts does not fail just because the user provide the essid
3026 * and the nic is still checking for the AP MAC ??
3028 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
3029 rtllib_start_bss(ieee
);
3030 } else if (ieee
->iw_mode
== IW_MODE_ADHOC
) {
3031 if (ieee
->UpdateBeaconInterruptHandler
)
3032 ieee
->UpdateBeaconInterruptHandler(ieee
->dev
, true);
3034 rtllib_start_ibss(ieee
);
3036 } else if (ieee
->iw_mode
== IW_MODE_MASTER
) {
3037 rtllib_start_master_bss(ieee
);
3038 } else if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
3039 rtllib_start_monitor_mode(ieee
);
3043 void rtllib_softmac_init(struct rtllib_device
*ieee
)
3046 memset(&ieee
->current_network
, 0, sizeof(struct rtllib_network
));
3048 ieee
->state
= RTLLIB_NOLINK
;
3049 for (i
= 0; i
< 5; i
++)
3050 ieee
->seq_ctrl
[i
] = 0;
3051 ieee
->pDot11dInfo
= kmalloc(sizeof(struct rt_dot11d_info
), GFP_ATOMIC
);
3052 if (!ieee
->pDot11dInfo
)
3053 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "can't alloc memory for DOT11D\n");
3054 memset(ieee
->pDot11dInfo
, 0, sizeof(struct rt_dot11d_info
));
3055 ieee
->LinkDetectInfo
.SlotIndex
= 0;
3056 ieee
->LinkDetectInfo
.SlotNum
= 2;
3057 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
= 0;
3058 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
= 0;
3059 ieee
->LinkDetectInfo
.NumTxOkInPeriod
= 0;
3060 ieee
->LinkDetectInfo
.NumRxOkInPeriod
= 0;
3061 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
= 0;
3062 ieee
->bIsAggregateFrame
= false;
3064 ieee
->queue_stop
= 0;
3065 ieee
->scanning_continue
= 0;
3066 ieee
->softmac_features
= 0;
3069 ieee
->proto_started
= 0;
3070 ieee
->proto_stoppping
= 0;
3071 ieee
->basic_rate
= RTLLIB_DEFAULT_BASIC_RATE
;
3073 ieee
->ps
= RTLLIB_PS_DISABLED
;
3074 ieee
->sta_sleep
= LPS_IS_WAKE
;
3076 ieee
->Regdot11HTOperationalRateSet
[0] = 0xff;
3077 ieee
->Regdot11HTOperationalRateSet
[1] = 0xff;
3078 ieee
->Regdot11HTOperationalRateSet
[4] = 0x01;
3080 ieee
->Regdot11TxHTOperationalRateSet
[0] = 0xff;
3081 ieee
->Regdot11TxHTOperationalRateSet
[1] = 0xff;
3082 ieee
->Regdot11TxHTOperationalRateSet
[4] = 0x01;
3084 ieee
->FirstIe_InScan
= false;
3085 ieee
->actscanning
= false;
3086 ieee
->beinretry
= false;
3087 ieee
->is_set_key
= false;
3088 init_mgmt_queue(ieee
);
3090 ieee
->sta_edca_param
[0] = 0x0000A403;
3091 ieee
->sta_edca_param
[1] = 0x0000A427;
3092 ieee
->sta_edca_param
[2] = 0x005E4342;
3093 ieee
->sta_edca_param
[3] = 0x002F3262;
3094 ieee
->aggregation
= true;
3095 ieee
->enable_rx_imm_BA
= 1;
3096 ieee
->tx_pending
.txb
= NULL
;
3098 _setup_timer(&ieee
->associate_timer
,
3099 rtllib_associate_abort_cb
,
3100 (unsigned long) ieee
);
3102 _setup_timer(&ieee
->beacon_timer
,
3103 rtllib_send_beacon_cb
,
3104 (unsigned long) ieee
);
3107 ieee
->wq
= create_workqueue(DRV_NAME
);
3109 INIT_DELAYED_WORK_RSL(&ieee
->link_change_wq
,
3110 (void *)rtllib_link_change_wq
, ieee
);
3111 INIT_DELAYED_WORK_RSL(&ieee
->start_ibss_wq
,
3112 (void *)rtllib_start_ibss_wq
, ieee
);
3113 INIT_WORK_RSL(&ieee
->associate_complete_wq
,
3114 (void *)rtllib_associate_complete_wq
, ieee
);
3115 INIT_DELAYED_WORK_RSL(&ieee
->associate_procedure_wq
,
3116 (void *)rtllib_associate_procedure_wq
, ieee
);
3117 INIT_DELAYED_WORK_RSL(&ieee
->softmac_scan_wq
,
3118 (void *)rtllib_softmac_scan_wq
, ieee
);
3119 INIT_DELAYED_WORK_RSL(&ieee
->softmac_hint11d_wq
,
3120 (void *)rtllib_softmac_hint11d_wq
, ieee
);
3121 INIT_DELAYED_WORK_RSL(&ieee
->associate_retry_wq
,
3122 (void *)rtllib_associate_retry_wq
, ieee
);
3123 INIT_WORK_RSL(&ieee
->wx_sync_scan_wq
, (void *)rtllib_wx_sync_scan_wq
,
3126 sema_init(&ieee
->wx_sem
, 1);
3127 sema_init(&ieee
->scan_sem
, 1);
3128 sema_init(&ieee
->ips_sem
, 1);
3130 spin_lock_init(&ieee
->mgmt_tx_lock
);
3131 spin_lock_init(&ieee
->beacon_lock
);
3133 tasklet_init(&ieee
->ps_task
,
3134 (void(*)(unsigned long)) rtllib_sta_ps
,
3135 (unsigned long)ieee
);
3139 void rtllib_softmac_free(struct rtllib_device
*ieee
)
3141 down(&ieee
->wx_sem
);
3142 if (NULL
!= ieee
->pDot11dInfo
) {
3143 kfree(ieee
->pDot11dInfo
);
3144 ieee
->pDot11dInfo
= NULL
;
3146 del_timer_sync(&ieee
->associate_timer
);
3148 cancel_delayed_work(&ieee
->associate_retry_wq
);
3149 destroy_workqueue(ieee
->wq
);
3153 /********************************************************
3154 * Start of WPA code. *
3155 * this is stolen from the ipw2200 driver *
3156 ********************************************************/
3159 static int rtllib_wpa_enable(struct rtllib_device
*ieee
, int value
)
3161 /* This is called when wpa_supplicant loads and closes the driver
3163 printk(KERN_INFO
"%s WPA\n", value
? "enabling" : "disabling");
3164 ieee
->wpa_enabled
= value
;
3165 memset(ieee
->ap_mac_addr
, 0, 6);
3170 static void rtllib_wpa_assoc_frame(struct rtllib_device
*ieee
, char *wpa_ie
,
3173 /* make sure WPA is enabled */
3174 rtllib_wpa_enable(ieee
, 1);
3176 rtllib_disassociate(ieee
);
3180 static int rtllib_wpa_mlme(struct rtllib_device
*ieee
, int command
, int reason
)
3186 case IEEE_MLME_STA_DEAUTH
:
3189 case IEEE_MLME_STA_DISASSOC
:
3190 rtllib_disassociate(ieee
);
3194 printk(KERN_INFO
"Unknown MLME request: %d\n", command
);
3202 static int rtllib_wpa_set_wpa_ie(struct rtllib_device
*ieee
,
3203 struct ieee_param
*param
, int plen
)
3207 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
3208 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
3211 if (param
->u
.wpa_ie
.len
) {
3212 buf
= kmalloc(param
->u
.wpa_ie
.len
, GFP_KERNEL
);
3216 memcpy(buf
, param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
);
3217 kfree(ieee
->wpa_ie
);
3219 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
3221 kfree(ieee
->wpa_ie
);
3222 ieee
->wpa_ie
= NULL
;
3223 ieee
->wpa_ie_len
= 0;
3226 rtllib_wpa_assoc_frame(ieee
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
3230 #define AUTH_ALG_OPEN_SYSTEM 0x1
3231 #define AUTH_ALG_SHARED_KEY 0x2
3232 #define AUTH_ALG_LEAP 0x4
3233 static int rtllib_wpa_set_auth_algs(struct rtllib_device
*ieee
, int value
)
3236 struct rtllib_security sec
= {
3237 .flags
= SEC_AUTH_MODE
,
3241 if (value
& AUTH_ALG_SHARED_KEY
) {
3242 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
3244 ieee
->auth_mode
= 1;
3245 } else if (value
& AUTH_ALG_OPEN_SYSTEM
) {
3246 sec
.auth_mode
= WLAN_AUTH_OPEN
;
3248 ieee
->auth_mode
= 0;
3249 } else if (value
& AUTH_ALG_LEAP
) {
3250 sec
.auth_mode
= WLAN_AUTH_LEAP
>> 6;
3252 ieee
->auth_mode
= 2;
3256 if (ieee
->set_security
)
3257 ieee
->set_security(ieee
->dev
, &sec
);
3262 static int rtllib_wpa_set_param(struct rtllib_device
*ieee
, u8 name
, u32 value
)
3265 unsigned long flags
;
3268 case IEEE_PARAM_WPA_ENABLED
:
3269 ret
= rtllib_wpa_enable(ieee
, value
);
3272 case IEEE_PARAM_TKIP_COUNTERMEASURES
:
3273 ieee
->tkip_countermeasures
= value
;
3276 case IEEE_PARAM_DROP_UNENCRYPTED
:
3280 * wpa_supplicant calls set_wpa_enabled when the driver
3281 * is loaded and unloaded, regardless of if WPA is being
3282 * used. No other calls are made which can be used to
3283 * determine if encryption will be used or not prior to
3284 * association being expected. If encryption is not being
3285 * used, drop_unencrypted is set to false, else true -- we
3286 * can use this to determine if the CAP_PRIVACY_ON bit should
3289 struct rtllib_security sec
= {
3290 .flags
= SEC_ENABLED
,
3293 ieee
->drop_unencrypted
= value
;
3294 /* We only change SEC_LEVEL for open mode. Others
3295 * are set by ipw_wpa_set_encryption.
3298 sec
.flags
|= SEC_LEVEL
;
3299 sec
.level
= SEC_LEVEL_0
;
3301 sec
.flags
|= SEC_LEVEL
;
3302 sec
.level
= SEC_LEVEL_1
;
3304 if (ieee
->set_security
)
3305 ieee
->set_security(ieee
->dev
, &sec
);
3309 case IEEE_PARAM_PRIVACY_INVOKED
:
3310 ieee
->privacy_invoked
= value
;
3313 case IEEE_PARAM_AUTH_ALGS
:
3314 ret
= rtllib_wpa_set_auth_algs(ieee
, value
);
3317 case IEEE_PARAM_IEEE_802_1X
:
3318 ieee
->ieee802_1x
= value
;
3320 case IEEE_PARAM_WPAX_SELECT
:
3321 spin_lock_irqsave(&ieee
->wpax_suitlist_lock
, flags
);
3322 spin_unlock_irqrestore(&ieee
->wpax_suitlist_lock
, flags
);
3326 printk(KERN_INFO
"Unknown WPA param: %d\n", name
);
3333 /* implementation borrowed from hostap driver */
3334 static int rtllib_wpa_set_encryption(struct rtllib_device
*ieee
,
3335 struct ieee_param
*param
, int param_len
,
3339 struct rtllib_crypto_ops
*ops
;
3340 struct rtllib_crypt_data
**crypt
;
3342 struct rtllib_security sec
= {
3346 param
->u
.crypt
.err
= 0;
3347 param
->u
.crypt
.alg
[IEEE_CRYPT_ALG_NAME_LEN
- 1] = '\0';
3350 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
3351 param
->u
.crypt
.key_len
) {
3352 printk(KERN_INFO
"Len mismatch %d, %d\n", param_len
,
3353 param
->u
.crypt
.key_len
);
3356 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
3357 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
3358 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
3359 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
3361 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
3366 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
3369 sec
.level
= SEC_LEVEL_0
;
3370 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
3371 rtllib_crypt_delayed_deinit(ieee
, crypt
);
3376 sec
.flags
|= SEC_ENABLED
;
3378 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3379 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
3380 strcmp(param
->u
.crypt
.alg
, "TKIP"))
3381 goto skip_host_crypt
;
3383 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3384 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
3385 request_module("rtllib_crypt_wep");
3386 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3387 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
3388 request_module("rtllib_crypt_tkip");
3389 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3390 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
3391 request_module("rtllib_crypt_ccmp");
3392 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3395 printk(KERN_INFO
"unknown crypto alg '%s'\n",
3396 param
->u
.crypt
.alg
);
3397 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
3401 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
3402 struct rtllib_crypt_data
*new_crypt
;
3404 rtllib_crypt_delayed_deinit(ieee
, crypt
);
3406 new_crypt
= (struct rtllib_crypt_data
*)
3407 kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
3408 if (new_crypt
== NULL
) {
3412 memset(new_crypt
, 0, sizeof(struct rtllib_crypt_data
));
3413 new_crypt
->ops
= ops
;
3416 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
3418 if (new_crypt
->priv
== NULL
) {
3420 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
3428 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
3429 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
3430 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
3431 (*crypt
)->priv
) < 0) {
3432 printk(KERN_INFO
"key setting failed\n");
3433 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
3439 if (param
->u
.crypt
.set_tx
) {
3440 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
3441 sec
.active_key
= param
->u
.crypt
.idx
;
3442 sec
.flags
|= SEC_ACTIVE_KEY
;
3444 sec
.flags
&= ~SEC_ACTIVE_KEY
;
3446 if (param
->u
.crypt
.alg
!= NULL
) {
3447 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
3449 param
->u
.crypt
.key_len
);
3450 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
3451 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
3453 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
3454 sec
.flags
|= SEC_LEVEL
;
3455 sec
.level
= SEC_LEVEL_1
;
3456 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
3457 sec
.flags
|= SEC_LEVEL
;
3458 sec
.level
= SEC_LEVEL_2
;
3459 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
3460 sec
.flags
|= SEC_LEVEL
;
3461 sec
.level
= SEC_LEVEL_3
;
3465 if (ieee
->set_security
)
3466 ieee
->set_security(ieee
->dev
, &sec
);
3468 /* Do not reset port if card is in Managed mode since resetting will
3469 * generate new IEEE 802.11 authentication which may end up in looping
3470 * with IEEE 802.1X. If your hardware requires a reset after WEP
3471 * configuration (for example... Prism2), implement the reset_port in
3472 * the callbacks structures used to initialize the 802.11 stack. */
3473 if (ieee
->reset_on_keychange
&&
3474 ieee
->iw_mode
!= IW_MODE_INFRA
&&
3476 ieee
->reset_port(ieee
->dev
)) {
3477 printk(KERN_INFO
"reset_port failed\n");
3478 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
3485 inline struct sk_buff
*rtllib_disauth_skb(struct rtllib_network
*beacon
,
3486 struct rtllib_device
*ieee
, u16 asRsn
)
3488 struct sk_buff
*skb
;
3489 struct rtllib_disauth
*disauth
;
3490 int len
= sizeof(struct rtllib_disauth
) + ieee
->tx_headroom
;
3492 skb
= dev_alloc_skb(len
);
3496 skb_reserve(skb
, ieee
->tx_headroom
);
3498 disauth
= (struct rtllib_disauth
*) skb_put(skb
,
3499 sizeof(struct rtllib_disauth
));
3500 disauth
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_DEAUTH
);
3501 disauth
->header
.duration_id
= 0;
3503 memcpy(disauth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
3504 memcpy(disauth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
3505 memcpy(disauth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
3507 disauth
->reason
= cpu_to_le16(asRsn
);
3511 inline struct sk_buff
*rtllib_disassociate_skb(struct rtllib_network
*beacon
,
3512 struct rtllib_device
*ieee
, u16 asRsn
)
3514 struct sk_buff
*skb
;
3515 struct rtllib_disassoc
*disass
;
3516 int len
= sizeof(struct rtllib_disassoc
) + ieee
->tx_headroom
;
3517 skb
= dev_alloc_skb(len
);
3522 skb_reserve(skb
, ieee
->tx_headroom
);
3524 disass
= (struct rtllib_disassoc
*) skb_put(skb
,
3525 sizeof(struct rtllib_disassoc
));
3526 disass
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_DISASSOC
);
3527 disass
->header
.duration_id
= 0;
3529 memcpy(disass
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
3530 memcpy(disass
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
3531 memcpy(disass
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
3533 disass
->reason
= cpu_to_le16(asRsn
);
3537 void SendDisassociation(struct rtllib_device
*ieee
, bool deauth
, u16 asRsn
)
3539 struct rtllib_network
*beacon
= &ieee
->current_network
;
3540 struct sk_buff
*skb
;
3543 skb
= rtllib_disauth_skb(beacon
, ieee
, asRsn
);
3545 skb
= rtllib_disassociate_skb(beacon
, ieee
, asRsn
);
3548 softmac_mgmt_xmit(skb
, ieee
);
3551 u8
rtllib_ap_sec_type(struct rtllib_device
*ieee
)
3553 static u8 ccmp_ie
[4] = {0x00, 0x50, 0xf2, 0x04};
3554 static u8 ccmp_rsn_ie
[4] = {0x00, 0x0f, 0xac, 0x04};
3555 int wpa_ie_len
= ieee
->wpa_ie_len
;
3556 struct rtllib_crypt_data
*crypt
;
3559 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
3560 encrypt
= (ieee
->current_network
.capability
& WLAN_CAPABILITY_PRIVACY
)
3561 || (ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
3562 (0 == strcmp(crypt
->ops
->name
, "WEP")));
3565 if (encrypt
&& (wpa_ie_len
== 0)) {
3567 } else if ((wpa_ie_len
!= 0)) {
3568 if (((ieee
->wpa_ie
[0] == 0xdd) &&
3569 (!memcmp(&(ieee
->wpa_ie
[14]), ccmp_ie
, 4))) ||
3570 ((ieee
->wpa_ie
[0] == 0x30) &&
3571 (!memcmp(&ieee
->wpa_ie
[10], ccmp_rsn_ie
, 4))))
3572 return SEC_ALG_CCMP
;
3574 return SEC_ALG_TKIP
;
3576 return SEC_ALG_NONE
;
3580 int rtllib_wpa_supplicant_ioctl(struct rtllib_device
*ieee
, struct iw_point
*p
,
3583 struct ieee_param
*param
;
3586 down(&ieee
->wx_sem
);
3588 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
) {
3593 param
= kmalloc(p
->length
, GFP_KERNEL
);
3594 if (param
== NULL
) {
3598 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
3604 switch (param
->cmd
) {
3605 case IEEE_CMD_SET_WPA_PARAM
:
3606 ret
= rtllib_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
3607 param
->u
.wpa_param
.value
);
3610 case IEEE_CMD_SET_WPA_IE
:
3611 ret
= rtllib_wpa_set_wpa_ie(ieee
, param
, p
->length
);
3614 case IEEE_CMD_SET_ENCRYPTION
:
3615 ret
= rtllib_wpa_set_encryption(ieee
, param
, p
->length
, 0);
3619 ret
= rtllib_wpa_mlme(ieee
, param
->u
.mlme
.command
,
3620 param
->u
.mlme
.reason_code
);
3624 printk(KERN_INFO
"Unknown WPA supplicant request: %d\n",
3630 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
3640 void rtllib_MgntDisconnectIBSS(struct rtllib_device
*rtllib
)
3644 bool bFilterOutNonAssociatedBSSID
= false;
3646 rtllib
->state
= RTLLIB_NOLINK
;
3648 for (i
= 0; i
< 6; i
++)
3649 rtllib
->current_network
.bssid
[i
] = 0x55;
3651 rtllib
->OpMode
= RT_OP_MODE_NO_LINK
;
3652 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_BSSID
,
3653 rtllib
->current_network
.bssid
);
3654 OpMode
= RT_OP_MODE_NO_LINK
;
3655 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_MEDIA_STATUS
, &OpMode
);
3656 rtllib_stop_send_beacons(rtllib
);
3658 bFilterOutNonAssociatedBSSID
= false;
3659 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_CECHK_BSSID
,
3660 (u8
*)(&bFilterOutNonAssociatedBSSID
));
3661 notify_wx_assoc_event(rtllib
);
3665 void rtllib_MlmeDisassociateRequest(struct rtllib_device
*rtllib
, u8
*asSta
,
3671 RemovePeerTS(rtllib
, asSta
);
3674 if (memcpy(rtllib
->current_network
.bssid
, asSta
, 6) == NULL
) {
3675 rtllib
->state
= RTLLIB_NOLINK
;
3677 for (i
= 0; i
< 6; i
++)
3678 rtllib
->current_network
.bssid
[i
] = 0x22;
3679 OpMode
= RT_OP_MODE_NO_LINK
;
3680 rtllib
->OpMode
= RT_OP_MODE_NO_LINK
;
3681 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_MEDIA_STATUS
,
3683 rtllib_disassociate(rtllib
);
3685 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_BSSID
,
3686 rtllib
->current_network
.bssid
);
3693 rtllib_MgntDisconnectAP(
3694 struct rtllib_device
*rtllib
,
3698 bool bFilterOutNonAssociatedBSSID
= false;
3700 bFilterOutNonAssociatedBSSID
= false;
3701 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_CECHK_BSSID
,
3702 (u8
*)(&bFilterOutNonAssociatedBSSID
));
3703 rtllib_MlmeDisassociateRequest(rtllib
, rtllib
->current_network
.bssid
,
3706 rtllib
->state
= RTLLIB_NOLINK
;
3709 bool rtllib_MgntDisconnect(struct rtllib_device
*rtllib
, u8 asRsn
)
3711 if (rtllib
->ps
!= RTLLIB_PS_DISABLED
)
3712 rtllib
->sta_wake_up(rtllib
->dev
);
3714 if (rtllib
->state
== RTLLIB_LINKED
) {
3715 if (rtllib
->iw_mode
== IW_MODE_ADHOC
)
3716 rtllib_MgntDisconnectIBSS(rtllib
);
3717 if (rtllib
->iw_mode
== IW_MODE_INFRA
)
3718 rtllib_MgntDisconnectAP(rtllib
, asRsn
);
3725 void notify_wx_assoc_event(struct rtllib_device
*ieee
)
3727 union iwreq_data wrqu
;
3729 if (ieee
->cannot_notify
)
3732 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3733 if (ieee
->state
== RTLLIB_LINKED
)
3734 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
,
3738 printk(KERN_INFO
"%s(): Tell user space disconnected\n",
3740 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
3742 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);