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 u8 rsn_authen_cipher_suite
[16][4] = {
27 {0x00, 0x0F, 0xAC, 0x00},
28 {0x00, 0x0F, 0xAC, 0x01},
29 {0x00, 0x0F, 0xAC, 0x02},
30 {0x00, 0x0F, 0xAC, 0x03},
31 {0x00, 0x0F, 0xAC, 0x04},
32 {0x00, 0x0F, 0xAC, 0x05},
35 short rtllib_is_54g(struct rtllib_network
*net
)
37 return (net
->rates_ex_len
> 0) || (net
->rates_len
> 4);
40 short rtllib_is_shortslot(struct rtllib_network net
)
42 return net
.capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
;
45 /* returns the total length needed for pleacing the RATE MFIE
46 * tag and the EXTENDED RATE MFIE tag if needed.
47 * It encludes two bytes per tag for the tag itself and its len
49 unsigned int rtllib_MFIE_rate_len(struct rtllib_device
*ieee
)
51 unsigned int rate_len
= 0;
53 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
)
54 rate_len
= RTLLIB_CCK_RATE_LEN
+ 2;
56 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)
58 rate_len
+= RTLLIB_OFDM_RATE_LEN
+ 2;
63 /* pleace the MFIE rate, tag to the memory (double) poined.
64 * Then it updates the pointer so that
65 * it points after the new MFIE tag added.
67 void rtllib_MFIE_Brate(struct rtllib_device
*ieee
, u8
**tag_p
)
71 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
) {
72 *tag
++ = MFIE_TYPE_RATES
;
74 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_1MB
;
75 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_2MB
;
76 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_5MB
;
77 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_11MB
;
80 /* We may add an option for custom rates that specific HW
85 void rtllib_MFIE_Grate(struct rtllib_device
*ieee
, u8
**tag_p
)
89 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
) {
90 *tag
++ = MFIE_TYPE_RATES_EX
;
92 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_6MB
;
93 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_9MB
;
94 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_12MB
;
95 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_18MB
;
96 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_24MB
;
97 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_36MB
;
98 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_48MB
;
99 *tag
++ = RTLLIB_BASIC_RATE_MASK
| RTLLIB_OFDM_RATE_54MB
;
101 /* We may add an option for custom rates that specific HW might
106 void rtllib_WMM_Info(struct rtllib_device
*ieee
, u8
**tag_p
)
110 *tag
++ = MFIE_TYPE_GENERIC
;
122 void rtllib_TURBO_Info(struct rtllib_device
*ieee
, u8
**tag_p
)
126 *tag
++ = MFIE_TYPE_GENERIC
;
137 printk(KERN_ALERT
"This is enable turbo mode IE process\n");
140 void enqueue_mgmt(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
143 nh
= (ieee
->mgmt_queue_head
+ 1) % MGMT_QUEUE_NUM
;
146 * if the queue is full but we have newer frames then
147 * just overwrites the oldest.
149 * if (nh == ieee->mgmt_queue_tail)
152 ieee
->mgmt_queue_head
= nh
;
153 ieee
->mgmt_queue_ring
[nh
] = skb
;
157 struct sk_buff
*dequeue_mgmt(struct rtllib_device
*ieee
)
161 if (ieee
->mgmt_queue_tail
== ieee
->mgmt_queue_head
)
164 ret
= ieee
->mgmt_queue_ring
[ieee
->mgmt_queue_tail
];
166 ieee
->mgmt_queue_tail
=
167 (ieee
->mgmt_queue_tail
+1) % MGMT_QUEUE_NUM
;
172 void init_mgmt_queue(struct rtllib_device
*ieee
)
174 ieee
->mgmt_queue_tail
= ieee
->mgmt_queue_head
= 0;
179 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device
*ieee
)
186 for (i
= 0; i
< ieee
->current_network
.rates_len
; i
++) {
187 BasicRate
= ieee
->current_network
.rates
[i
]&0x7F;
188 if (!rtllib_is_cck_rate(BasicRate
)) {
189 if (QueryRate
== 0) {
190 QueryRate
= BasicRate
;
192 if (BasicRate
< QueryRate
)
193 QueryRate
= BasicRate
;
198 if (QueryRate
== 0) {
200 printk(KERN_INFO
"No BasicRate found!!\n");
205 u8
MgntQuery_MgntFrameTxRate(struct rtllib_device
*ieee
)
207 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
210 if (pHTInfo
->IOTAction
& HT_IOT_ACT_MGNT_USE_CCK_6M
)
213 rate
= ieee
->basic_rate
& 0x7f;
216 if (ieee
->mode
== IEEE_A
||
217 ieee
->mode
== IEEE_N_5G
||
218 (ieee
->mode
== IEEE_N_24G
&& !pHTInfo
->bCurSuppCCK
))
227 inline void softmac_mgmt_xmit(struct sk_buff
*skb
, struct rtllib_device
*ieee
)
230 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
231 struct rtllib_hdr_3addr
*header
=
232 (struct rtllib_hdr_3addr
*) skb
->data
;
234 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ 8);
235 spin_lock_irqsave(&ieee
->lock
, flags
);
237 /* called with 2nd param 0, no mgmt lock required */
238 rtllib_sta_wakeup(ieee
, 0);
240 if (header
->frame_ctl
== RTLLIB_STYPE_BEACON
)
241 tcb_desc
->queue_index
= BEACON_QUEUE
;
243 tcb_desc
->queue_index
= MGNT_QUEUE
;
245 if (ieee
->disable_mgnt_queue
)
246 tcb_desc
->queue_index
= HIGH_QUEUE
;
248 tcb_desc
->data_rate
= MgntQuery_MgntFrameTxRate(ieee
);
249 tcb_desc
->RATRIndex
= 7;
250 tcb_desc
->bTxDisableRateFallBack
= 1;
251 tcb_desc
->bTxUseDriverAssingedRate
= 1;
253 if (ieee
->queue_stop
) {
254 enqueue_mgmt(ieee
, skb
);
256 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0]<<4);
258 if (ieee
->seq_ctrl
[0] == 0xFFF)
259 ieee
->seq_ctrl
[0] = 0;
263 /* avoid watchdog triggers */
264 ieee
->softmac_data_hard_start_xmit(skb
, ieee
->dev
,
268 spin_unlock_irqrestore(&ieee
->lock
, flags
);
270 spin_unlock_irqrestore(&ieee
->lock
, flags
);
271 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags
);
273 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
275 if (ieee
->seq_ctrl
[0] == 0xFFF)
276 ieee
->seq_ctrl
[0] = 0;
280 /* check wether the managed packet queued greater than 5 */
281 if (!ieee
->check_nic_enough_desc(ieee
->dev
, tcb_desc
->queue_index
) ||
282 (skb_queue_len(&ieee
->skb_waitQ
[tcb_desc
->queue_index
]) != 0) ||
283 (ieee
->queue_stop
)) {
284 /* insert the skb packet to the management queue */
285 /* as for the completion function, it does not need
286 * to check it any more.
288 printk(KERN_INFO
"%s():insert to waitqueue, queue_index"
289 ":%d!\n", __func__
, tcb_desc
->queue_index
);
290 skb_queue_tail(&ieee
->skb_waitQ
[tcb_desc
->queue_index
],
293 ieee
->softmac_hard_start_xmit(skb
, ieee
->dev
);
295 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags
);
299 inline void softmac_ps_mgmt_xmit(struct sk_buff
*skb
,
300 struct rtllib_device
*ieee
)
302 short single
= ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
;
303 struct rtllib_hdr_3addr
*header
=
304 (struct rtllib_hdr_3addr
*) skb
->data
;
306 struct cb_desc
*tcb_desc
= (struct cb_desc
*)(skb
->cb
+ 8);
308 fc
= header
->frame_ctl
;
309 type
= WLAN_FC_GET_TYPE(fc
);
310 stype
= WLAN_FC_GET_STYPE(fc
);
313 if (stype
!= RTLLIB_STYPE_PSPOLL
)
314 tcb_desc
->queue_index
= MGNT_QUEUE
;
316 tcb_desc
->queue_index
= HIGH_QUEUE
;
318 if (ieee
->disable_mgnt_queue
)
319 tcb_desc
->queue_index
= HIGH_QUEUE
;
322 tcb_desc
->data_rate
= MgntQuery_MgntFrameTxRate(ieee
);
323 tcb_desc
->RATRIndex
= 7;
324 tcb_desc
->bTxDisableRateFallBack
= 1;
325 tcb_desc
->bTxUseDriverAssingedRate
= 1;
327 if (type
!= RTLLIB_FTYPE_CTL
) {
328 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
330 if (ieee
->seq_ctrl
[0] == 0xFFF)
331 ieee
->seq_ctrl
[0] = 0;
336 /* avoid watchdog triggers */
337 ieee
->softmac_data_hard_start_xmit(skb
, ieee
->dev
,
341 if (type
!= RTLLIB_FTYPE_CTL
) {
342 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
344 if (ieee
->seq_ctrl
[0] == 0xFFF)
345 ieee
->seq_ctrl
[0] = 0;
349 ieee
->softmac_hard_start_xmit(skb
, ieee
->dev
);
354 inline struct sk_buff
*rtllib_probe_req(struct rtllib_device
*ieee
)
356 unsigned int len
, rate_len
;
359 struct rtllib_probe_request
*req
;
361 len
= ieee
->current_network
.ssid_len
;
363 rate_len
= rtllib_MFIE_rate_len(ieee
);
365 skb
= dev_alloc_skb(sizeof(struct rtllib_probe_request
) +
366 2 + len
+ rate_len
+ ieee
->tx_headroom
);
371 skb_reserve(skb
, ieee
->tx_headroom
);
373 req
= (struct rtllib_probe_request
*) skb_put(skb
,
374 sizeof(struct rtllib_probe_request
));
375 req
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_PROBE_REQ
);
376 req
->header
.duration_id
= 0;
378 memset(req
->header
.addr1
, 0xff, ETH_ALEN
);
379 memcpy(req
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
380 memset(req
->header
.addr3
, 0xff, ETH_ALEN
);
382 tag
= (u8
*) skb_put(skb
, len
+ 2 + rate_len
);
384 *tag
++ = MFIE_TYPE_SSID
;
386 memcpy(tag
, ieee
->current_network
.ssid
, len
);
389 rtllib_MFIE_Brate(ieee
, &tag
);
390 rtllib_MFIE_Grate(ieee
, &tag
);
395 struct sk_buff
*rtllib_get_beacon_(struct rtllib_device
*ieee
);
397 void rtllib_send_beacon(struct rtllib_device
*ieee
)
402 skb
= rtllib_get_beacon_(ieee
);
405 softmac_mgmt_xmit(skb
, ieee
);
406 ieee
->softmac_stats
.tx_beacons
++;
409 if (ieee
->beacon_txing
&& ieee
->ieee_up
)
410 mod_timer(&ieee
->beacon_timer
, jiffies
+
411 (MSECS(ieee
->current_network
.beacon_interval
- 5)));
415 void rtllib_send_beacon_cb(unsigned long _ieee
)
417 struct rtllib_device
*ieee
=
418 (struct rtllib_device
*) _ieee
;
421 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
422 rtllib_send_beacon(ieee
);
423 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
428 * Enable network monitor mode, all rx packets will be received.
430 void rtllib_EnableNetMonitorMode(struct net_device
*dev
,
433 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
435 printk(KERN_INFO
"========>Enter Monitor Mode\n");
437 ieee
->AllowAllDestAddrHandler(dev
, true, !bInitState
);
443 * Disable network network monitor mode, only packets destinated to
444 * us will be received.
446 void rtllib_DisableNetMonitorMode(struct net_device
*dev
,
449 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
451 printk(KERN_INFO
"========>Exit Monitor Mode\n");
453 ieee
->AllowAllDestAddrHandler(dev
, false, !bInitState
);
459 * This enables the specialized promiscuous mode required by Intel.
460 * In this mode, Intel intends to hear traffics from/to other STAs in the
461 * same BSS. Therefore we don't have to disable checking BSSID and we only need
462 * to allow all dest. BUT: if we enable checking BSSID then we can't recv
463 * packets from other STA.
465 void rtllib_EnableIntelPromiscuousMode(struct net_device
*dev
,
468 bool bFilterOutNonAssociatedBSSID
= false;
470 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
472 printk(KERN_INFO
"========>Enter Intel Promiscuous Mode\n");
474 ieee
->AllowAllDestAddrHandler(dev
, true, !bInitState
);
475 ieee
->SetHwRegHandler(dev
, HW_VAR_CECHK_BSSID
,
476 (u8
*)&bFilterOutNonAssociatedBSSID
);
478 ieee
->bNetPromiscuousMode
= true;
484 * This disables the specialized promiscuous mode required by Intel.
485 * See MgntEnableIntelPromiscuousMode for detail.
487 void rtllib_DisableIntelPromiscuousMode(struct net_device
*dev
,
490 bool bFilterOutNonAssociatedBSSID
= true;
492 struct rtllib_device
*ieee
= netdev_priv_rsl(dev
);
494 printk(KERN_INFO
"========>Exit Intel Promiscuous Mode\n");
496 ieee
->AllowAllDestAddrHandler(dev
, false, !bInitState
);
497 ieee
->SetHwRegHandler(dev
, HW_VAR_CECHK_BSSID
,
498 (u8
*)&bFilterOutNonAssociatedBSSID
);
500 ieee
->bNetPromiscuousMode
= false;
503 void rtllib_send_probe(struct rtllib_device
*ieee
, u8 is_mesh
)
506 skb
= rtllib_probe_req(ieee
);
508 softmac_mgmt_xmit(skb
, ieee
);
509 ieee
->softmac_stats
.tx_probe_rq
++;
514 void rtllib_send_probe_requests(struct rtllib_device
*ieee
, u8 is_mesh
)
516 if (ieee
->active_scan
&& (ieee
->softmac_features
&
517 IEEE_SOFTMAC_PROBERQ
)) {
518 rtllib_send_probe(ieee
, 0);
519 rtllib_send_probe(ieee
, 0);
523 void rtllib_softmac_hint11d_wq(void *data
)
527 void rtllib_update_active_chan_map(struct rtllib_device
*ieee
)
529 memcpy(ieee
->active_channel_map
, GET_DOT11D_INFO(ieee
)->channel_map
,
530 MAX_CHANNEL_NUMBER
+1);
533 /* this performs syncro scan blocking the caller until all channels
534 * in the allowed channel map has been checked.
536 void rtllib_softmac_scan_syncro(struct rtllib_device
*ieee
, u8 is_mesh
)
538 union iwreq_data wrqu
;
541 rtllib_update_active_chan_map(ieee
);
543 ieee
->be_scan_inprogress
= true;
545 down(&ieee
->scan_sem
);
550 if (ch
> MAX_CHANNEL_NUMBER
)
551 goto out
; /* scan completed */
552 } while (!ieee
->active_channel_map
[ch
]);
554 /* this fuction can be called in two situations
555 * 1- We have switched to ad-hoc mode and we are
556 * performing a complete syncro scan before conclude
557 * there are no interesting cell and to create a
558 * new one. In this case the link state is
559 * RTLLIB_NOLINK until we found an interesting cell.
560 * If so the ieee8021_new_net, called by the RX path
561 * will set the state to RTLLIB_LINKED, so we stop
563 * 2- We are linked and the root uses run iwlist scan.
564 * So we switch to RTLLIB_LINKED_SCANNING to remember
565 * that we are still logically linked (not interested in
566 * new network events, despite for updating the net list,
567 * but we are temporarly 'unlinked' as the driver shall
568 * not filter RX frames and the channel is changing.
569 * So the only situation in witch are interested is to check
570 * if the state become LINKED because of the #1 situation
573 if (ieee
->state
== RTLLIB_LINKED
)
575 if (ieee
->sync_scan_hurryup
) {
576 printk(KERN_INFO
"============>sync_scan_hurryup out\n");
580 ieee
->set_chan(ieee
->dev
, ch
);
581 if (ieee
->active_channel_map
[ch
] == 1)
582 rtllib_send_probe_requests(ieee
, 0);
584 /* this prevent excessive time wait when we
585 * need to wait for a syncro scan to end..
587 msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME
);
590 ieee
->actscanning
= false;
591 ieee
->sync_scan_hurryup
= 0;
593 if (ieee
->state
>= RTLLIB_LINKED
) {
594 if (IS_DOT11D_ENABLE(ieee
))
595 DOT11D_ScanComplete(ieee
);
599 ieee
->be_scan_inprogress
= false;
601 memset(&wrqu
, 0, sizeof(wrqu
));
602 wireless_send_event(ieee
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
605 void rtllib_softmac_scan_wq(void *data
)
607 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
608 struct rtllib_device
, softmac_scan_wq
);
609 u8 last_channel
= ieee
->current_network
.channel
;
611 rtllib_update_active_chan_map(ieee
);
615 if (rtllib_act_scanning(ieee
, true) == true)
618 down(&ieee
->scan_sem
);
620 if (ieee
->eRFPowerState
== eRfOff
) {
621 printk(KERN_INFO
"======>%s():rf state is eRfOff, return\n",
627 ieee
->current_network
.channel
=
628 (ieee
->current_network
.channel
+ 1) %
630 if (ieee
->scan_watch_dog
++ > MAX_CHANNEL_NUMBER
) {
631 if (!ieee
->active_channel_map
[ieee
->current_network
.channel
])
632 ieee
->current_network
.channel
= 6;
633 goto out
; /* no good chans */
635 } while (!ieee
->active_channel_map
[ieee
->current_network
.channel
]);
637 if (ieee
->scanning_continue
== 0)
640 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
642 if (ieee
->active_channel_map
[ieee
->current_network
.channel
] == 1)
643 rtllib_send_probe_requests(ieee
, 0);
645 queue_delayed_work_rsl(ieee
->wq
, &ieee
->softmac_scan_wq
,
646 MSECS(RTLLIB_SOFTMAC_SCAN_TIME
));
652 if (IS_DOT11D_ENABLE(ieee
))
653 DOT11D_ScanComplete(ieee
);
654 ieee
->current_network
.channel
= last_channel
;
657 ieee
->actscanning
= false;
658 ieee
->scan_watch_dog
= 0;
659 ieee
->scanning_continue
= 0;
665 void rtllib_beacons_start(struct rtllib_device
*ieee
)
668 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
670 ieee
->beacon_txing
= 1;
671 rtllib_send_beacon(ieee
);
673 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
676 void rtllib_beacons_stop(struct rtllib_device
*ieee
)
680 spin_lock_irqsave(&ieee
->beacon_lock
, flags
);
682 ieee
->beacon_txing
= 0;
683 del_timer_sync(&ieee
->beacon_timer
);
685 spin_unlock_irqrestore(&ieee
->beacon_lock
, flags
);
690 void rtllib_stop_send_beacons(struct rtllib_device
*ieee
)
692 if (ieee
->stop_send_beacons
)
693 ieee
->stop_send_beacons(ieee
->dev
);
694 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
695 rtllib_beacons_stop(ieee
);
699 void rtllib_start_send_beacons(struct rtllib_device
*ieee
)
701 if (ieee
->start_send_beacons
)
702 ieee
->start_send_beacons(ieee
->dev
);
703 if (ieee
->softmac_features
& IEEE_SOFTMAC_BEACONS
)
704 rtllib_beacons_start(ieee
);
708 void rtllib_softmac_stop_scan(struct rtllib_device
*ieee
)
710 down(&ieee
->scan_sem
);
711 ieee
->scan_watch_dog
= 0;
712 if (ieee
->scanning_continue
== 1) {
713 ieee
->scanning_continue
= 0;
714 ieee
->actscanning
= 0;
716 cancel_delayed_work(&ieee
->softmac_scan_wq
);
722 void rtllib_stop_scan(struct rtllib_device
*ieee
)
724 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
725 rtllib_softmac_stop_scan(ieee
);
727 if (ieee
->rtllib_stop_hw_scan
)
728 ieee
->rtllib_stop_hw_scan(ieee
->dev
);
732 void rtllib_stop_scan_syncro(struct rtllib_device
*ieee
)
734 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
735 ieee
->sync_scan_hurryup
= 1;
737 if (ieee
->rtllib_stop_hw_scan
)
738 ieee
->rtllib_stop_hw_scan(ieee
->dev
);
742 bool rtllib_act_scanning(struct rtllib_device
*ieee
, bool sync_scan
)
744 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
746 return ieee
->be_scan_inprogress
;
748 return ieee
->actscanning
|| ieee
->be_scan_inprogress
;
750 return test_bit(STATUS_SCANNING
, &ieee
->status
);
754 /* called with ieee->lock held */
755 void rtllib_start_scan(struct rtllib_device
*ieee
)
757 RT_TRACE(COMP_DBG
, "===>%s()\n", __func__
);
758 if (ieee
->rtllib_ips_leave_wq
!= NULL
)
759 ieee
->rtllib_ips_leave_wq(ieee
->dev
);
761 if (IS_DOT11D_ENABLE(ieee
)) {
762 if (IS_COUNTRY_IE_VALID(ieee
))
763 RESET_CIE_WATCHDOG(ieee
);
765 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
766 if (ieee
->scanning_continue
== 0) {
767 ieee
->actscanning
= true;
768 ieee
->scanning_continue
= 1;
769 queue_delayed_work_rsl(ieee
->wq
,
770 &ieee
->softmac_scan_wq
, 0);
773 if (ieee
->rtllib_start_hw_scan
)
774 ieee
->rtllib_start_hw_scan(ieee
->dev
);
778 /* called with wx_sem held */
779 void rtllib_start_scan_syncro(struct rtllib_device
*ieee
, u8 is_mesh
)
781 if (IS_DOT11D_ENABLE(ieee
)) {
782 if (IS_COUNTRY_IE_VALID(ieee
))
783 RESET_CIE_WATCHDOG(ieee
);
785 ieee
->sync_scan_hurryup
= 0;
786 if (ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
) {
787 rtllib_softmac_scan_syncro(ieee
, is_mesh
);
789 if (ieee
->rtllib_start_hw_scan
)
790 ieee
->rtllib_start_hw_scan(ieee
->dev
);
794 inline struct sk_buff
*rtllib_authentication_req(struct rtllib_network
*beacon
,
795 struct rtllib_device
*ieee
, int challengelen
, u8
*daddr
)
798 struct rtllib_authentication
*auth
;
800 len
= sizeof(struct rtllib_authentication
) + challengelen
+
801 ieee
->tx_headroom
+ 4;
802 skb
= dev_alloc_skb(len
);
807 skb_reserve(skb
, ieee
->tx_headroom
);
809 auth
= (struct rtllib_authentication
*)
810 skb_put(skb
, sizeof(struct rtllib_authentication
));
812 auth
->header
.frame_ctl
= RTLLIB_STYPE_AUTH
;
814 auth
->header
.frame_ctl
|= RTLLIB_FCTL_WEP
;
816 auth
->header
.duration_id
= 0x013a;
817 memcpy(auth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
818 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
819 memcpy(auth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
820 if (ieee
->auth_mode
== 0)
821 auth
->algorithm
= WLAN_AUTH_OPEN
;
822 else if (ieee
->auth_mode
== 1)
823 auth
->algorithm
= WLAN_AUTH_SHARED_KEY
;
824 else if (ieee
->auth_mode
== 2)
825 auth
->algorithm
= WLAN_AUTH_OPEN
;
826 auth
->transaction
= cpu_to_le16(ieee
->associate_seq
);
827 ieee
->associate_seq
++;
829 auth
->status
= cpu_to_le16(WLAN_STATUS_SUCCESS
);
834 void constructWMMIE(u8
*wmmie
, u8
*wmm_len
, u8 oui_subtype
)
836 u8 szQoSOUI
[] = {221, 0, 0x00, 0x50, 0xf2, 0x02, 0, 1};
838 if (oui_subtype
== OUI_SUBTYPE_QOS_CAPABI
) {
840 szQoSOUI
[1] = *wmm_len
;
841 memcpy(wmmie
, szQoSOUI
, 3);
844 szQoSOUI
[1] = *wmm_len
+ 6;
845 szQoSOUI
[6] = oui_subtype
;
846 memcpy(wmmie
, szQoSOUI
, 8);
852 static struct sk_buff
*rtllib_probe_resp(struct rtllib_device
*ieee
, u8
*dest
)
856 struct rtllib_probe_response
*beacon_buf
;
857 struct sk_buff
*skb
= NULL
;
859 int atim_len
, erp_len
;
860 struct rtllib_crypt_data
*crypt
;
862 char *ssid
= ieee
->current_network
.ssid
;
863 int ssid_len
= ieee
->current_network
.ssid_len
;
864 int rate_len
= ieee
->current_network
.rates_len
+2;
865 int rate_ex_len
= ieee
->current_network
.rates_ex_len
;
866 int wpa_ie_len
= ieee
->wpa_ie_len
;
867 u8 erpinfo_content
= 0;
869 u8
*tmp_ht_cap_buf
= NULL
;
870 u8 tmp_ht_cap_len
= 0;
871 u8
*tmp_ht_info_buf
= NULL
;
872 u8 tmp_ht_info_len
= 0;
873 struct rt_hi_throughput
*pHTInfo
= ieee
->pHTInfo
;
874 u8
*tmp_generic_ie_buf
= NULL
;
875 u8 tmp_generic_ie_len
= 0;
880 if (ieee
->current_network
.capability
& WLAN_CAPABILITY_IBSS
)
885 if ((ieee
->current_network
.mode
== IEEE_G
) ||
886 (ieee
->current_network
.mode
== IEEE_N_24G
&&
887 ieee
->pHTInfo
->bCurSuppCCK
)) {
890 if (ieee
->current_network
.buseprotection
)
891 erpinfo_content
|= ERP_UseProtection
;
895 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
896 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
897 ((0 == strcmp(crypt
->ops
->name
, "WEP") || wpa_ie_len
));
898 if (ieee
->pHTInfo
->bCurrentHTSupport
) {
899 tmp_ht_cap_buf
= (u8
*) &(ieee
->pHTInfo
->SelfHTCap
);
900 tmp_ht_cap_len
= sizeof(ieee
->pHTInfo
->SelfHTCap
);
901 tmp_ht_info_buf
= (u8
*) &(ieee
->pHTInfo
->SelfHTInfo
);
902 tmp_ht_info_len
= sizeof(ieee
->pHTInfo
->SelfHTInfo
);
903 HTConstructCapabilityElement(ieee
, tmp_ht_cap_buf
,
904 &tmp_ht_cap_len
, encrypt
, false);
905 HTConstructInfoElement(ieee
, tmp_ht_info_buf
, &tmp_ht_info_len
,
908 if (pHTInfo
->bRegRT2RTAggregation
) {
909 tmp_generic_ie_buf
= ieee
->pHTInfo
->szRT2RTAggBuffer
;
911 sizeof(ieee
->pHTInfo
->szRT2RTAggBuffer
);
912 HTConstructRT2RTAggElement(ieee
, tmp_generic_ie_buf
,
913 &tmp_generic_ie_len
);
917 beacon_size
= sizeof(struct rtllib_probe_response
)+2+
918 ssid_len
+ 3 + rate_len
+ rate_ex_len
+ atim_len
+ erp_len
919 + wpa_ie_len
+ ieee
->tx_headroom
;
920 skb
= dev_alloc_skb(beacon_size
);
924 skb_reserve(skb
, ieee
->tx_headroom
);
926 beacon_buf
= (struct rtllib_probe_response
*) skb_put(skb
,
927 (beacon_size
- ieee
->tx_headroom
));
928 memcpy(beacon_buf
->header
.addr1
, dest
, ETH_ALEN
);
929 memcpy(beacon_buf
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
930 memcpy(beacon_buf
->header
.addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
932 beacon_buf
->header
.duration_id
= 0;
933 beacon_buf
->beacon_interval
=
934 cpu_to_le16(ieee
->current_network
.beacon_interval
);
935 beacon_buf
->capability
=
936 cpu_to_le16(ieee
->current_network
.capability
&
937 WLAN_CAPABILITY_IBSS
);
938 beacon_buf
->capability
|=
939 cpu_to_le16(ieee
->current_network
.capability
&
940 WLAN_CAPABILITY_SHORT_PREAMBLE
);
942 if (ieee
->short_slot
&& (ieee
->current_network
.capability
&
943 WLAN_CAPABILITY_SHORT_SLOT_TIME
))
944 cpu_to_le16((beacon_buf
->capability
|=
945 WLAN_CAPABILITY_SHORT_SLOT_TIME
));
947 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
949 beacon_buf
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
952 beacon_buf
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_PROBE_RESP
);
953 beacon_buf
->info_element
[0].id
= MFIE_TYPE_SSID
;
954 beacon_buf
->info_element
[0].len
= ssid_len
;
956 tag
= (u8
*) beacon_buf
->info_element
[0].data
;
958 memcpy(tag
, ssid
, ssid_len
);
962 *(tag
++) = MFIE_TYPE_RATES
;
963 *(tag
++) = rate_len
-2;
964 memcpy(tag
, ieee
->current_network
.rates
, rate_len
-2);
967 *(tag
++) = MFIE_TYPE_DS_SET
;
969 *(tag
++) = ieee
->current_network
.channel
;
973 *(tag
++) = MFIE_TYPE_IBSS_SET
;
975 val16
= cpu_to_le16(ieee
->current_network
.atim_window
);
976 memcpy((u8
*)tag
, (u8
*)&val16
, 2);
981 *(tag
++) = MFIE_TYPE_ERP
;
983 *(tag
++) = erpinfo_content
;
986 *(tag
++) = MFIE_TYPE_RATES_EX
;
987 *(tag
++) = rate_ex_len
-2;
988 memcpy(tag
, ieee
->current_network
.rates_ex
, rate_ex_len
-2);
989 tag
+= rate_ex_len
-2;
993 if (ieee
->iw_mode
== IW_MODE_ADHOC
)
994 memcpy(&ieee
->wpa_ie
[14], &ieee
->wpa_ie
[8], 4);
995 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
996 tag
+= ieee
->wpa_ie_len
;
1001 struct sk_buff
*rtllib_assoc_resp(struct rtllib_device
*ieee
, u8
*dest
)
1003 struct sk_buff
*skb
;
1006 struct rtllib_crypt_data
*crypt
;
1007 struct rtllib_assoc_response_frame
*assoc
;
1010 unsigned int rate_len
= rtllib_MFIE_rate_len(ieee
);
1011 int len
= sizeof(struct rtllib_assoc_response_frame
) + rate_len
+
1014 skb
= dev_alloc_skb(len
);
1019 skb_reserve(skb
, ieee
->tx_headroom
);
1021 assoc
= (struct rtllib_assoc_response_frame
*)
1022 skb_put(skb
, sizeof(struct rtllib_assoc_response_frame
));
1024 assoc
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP
);
1025 memcpy(assoc
->header
.addr1
, dest
, ETH_ALEN
);
1026 memcpy(assoc
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1027 memcpy(assoc
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1028 assoc
->capability
= cpu_to_le16(ieee
->iw_mode
== IW_MODE_MASTER
?
1029 WLAN_CAPABILITY_ESS
: WLAN_CAPABILITY_IBSS
);
1032 if (ieee
->short_slot
)
1033 assoc
->capability
|=
1034 cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1036 if (ieee
->host_encrypt
)
1037 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
1041 encrypt
= (crypt
&& crypt
->ops
);
1044 assoc
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1047 assoc
->aid
= cpu_to_le16(ieee
->assoc_id
);
1048 if (ieee
->assoc_id
== 0x2007)
1053 tag
= (u8
*) skb_put(skb
, rate_len
);
1054 rtllib_MFIE_Brate(ieee
, &tag
);
1055 rtllib_MFIE_Grate(ieee
, &tag
);
1060 struct sk_buff
*rtllib_auth_resp(struct rtllib_device
*ieee
, int status
,
1063 struct sk_buff
*skb
= NULL
;
1064 struct rtllib_authentication
*auth
;
1065 int len
= ieee
->tx_headroom
+ sizeof(struct rtllib_authentication
) + 1;
1066 skb
= dev_alloc_skb(len
);
1070 skb
->len
= sizeof(struct rtllib_authentication
);
1072 skb_reserve(skb
, ieee
->tx_headroom
);
1074 auth
= (struct rtllib_authentication
*)
1075 skb_put(skb
, sizeof(struct rtllib_authentication
));
1077 auth
->status
= cpu_to_le16(status
);
1078 auth
->transaction
= cpu_to_le16(2);
1079 auth
->algorithm
= cpu_to_le16(WLAN_AUTH_OPEN
);
1081 memcpy(auth
->header
.addr3
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1082 memcpy(auth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1083 memcpy(auth
->header
.addr1
, dest
, ETH_ALEN
);
1084 auth
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_AUTH
);
1090 struct sk_buff
*rtllib_null_func(struct rtllib_device
*ieee
, short pwr
)
1092 struct sk_buff
*skb
;
1093 struct rtllib_hdr_3addr
*hdr
;
1095 skb
= dev_alloc_skb(sizeof(struct rtllib_hdr_3addr
)+ieee
->tx_headroom
);
1099 skb_reserve(skb
, ieee
->tx_headroom
);
1101 hdr
= (struct rtllib_hdr_3addr
*)skb_put(skb
,
1102 sizeof(struct rtllib_hdr_3addr
));
1104 memcpy(hdr
->addr1
, ieee
->current_network
.bssid
, ETH_ALEN
);
1105 memcpy(hdr
->addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1106 memcpy(hdr
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
);
1108 hdr
->frame_ctl
= cpu_to_le16(RTLLIB_FTYPE_DATA
|
1109 RTLLIB_STYPE_NULLFUNC
| RTLLIB_FCTL_TODS
|
1110 (pwr
? RTLLIB_FCTL_PM
: 0));
1117 struct sk_buff
*rtllib_pspoll_func(struct rtllib_device
*ieee
)
1119 struct sk_buff
*skb
;
1120 struct rtllib_pspoll_hdr
*hdr
;
1122 skb
= dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr
)+ieee
->tx_headroom
);
1126 skb_reserve(skb
, ieee
->tx_headroom
);
1128 hdr
= (struct rtllib_pspoll_hdr
*)skb_put(skb
,
1129 sizeof(struct rtllib_pspoll_hdr
));
1131 memcpy(hdr
->bssid
, ieee
->current_network
.bssid
, ETH_ALEN
);
1132 memcpy(hdr
->ta
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1134 hdr
->aid
= cpu_to_le16(ieee
->assoc_id
| 0xc000);
1135 hdr
->frame_ctl
= cpu_to_le16(RTLLIB_FTYPE_CTL
| RTLLIB_STYPE_PSPOLL
|
1142 void rtllib_resp_to_assoc_rq(struct rtllib_device
*ieee
, u8
*dest
)
1144 struct sk_buff
*buf
= rtllib_assoc_resp(ieee
, dest
);
1147 softmac_mgmt_xmit(buf
, ieee
);
1151 void rtllib_resp_to_auth(struct rtllib_device
*ieee
, int s
, u8
*dest
)
1153 struct sk_buff
*buf
= rtllib_auth_resp(ieee
, s
, dest
);
1156 softmac_mgmt_xmit(buf
, ieee
);
1160 void rtllib_resp_to_probe(struct rtllib_device
*ieee
, u8
*dest
)
1163 struct sk_buff
*buf
= rtllib_probe_resp(ieee
, dest
);
1165 softmac_mgmt_xmit(buf
, ieee
);
1169 inline int SecIsInPMKIDList(struct rtllib_device
*ieee
, u8
*bssid
)
1174 if ((ieee
->PMKIDList
[i
].bUsed
) &&
1175 (memcmp(ieee
->PMKIDList
[i
].Bssid
, bssid
, ETH_ALEN
) == 0))
1179 } while (i
< NUM_PMKID_CACHE
);
1181 if (i
== NUM_PMKID_CACHE
)
1186 inline struct sk_buff
*rtllib_association_req(struct rtllib_network
*beacon
,
1187 struct rtllib_device
*ieee
)
1189 struct sk_buff
*skb
;
1190 struct rtllib_assoc_request_frame
*hdr
;
1193 u8
*ht_cap_buf
= NULL
;
1195 u8
*realtek_ie_buf
= NULL
;
1196 u8 realtek_ie_len
= 0;
1197 int wpa_ie_len
= ieee
->wpa_ie_len
;
1198 int wps_ie_len
= ieee
->wps_ie_len
;
1199 unsigned int ckip_ie_len
= 0;
1200 unsigned int ccxrm_ie_len
= 0;
1201 unsigned int cxvernum_ie_len
= 0;
1202 struct rtllib_crypt_data
*crypt
;
1206 unsigned int rate_len
= (beacon
->rates_len
?
1207 (beacon
->rates_len
+ 2) : 0) +
1208 (beacon
->rates_ex_len
? (beacon
->rates_ex_len
) +
1211 unsigned int wmm_info_len
= beacon
->qos_data
.supported
? 9 : 0;
1212 unsigned int turbo_info_len
= beacon
->Turbo_Enable
? 9 : 0;
1215 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
1217 encrypt
= ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
1218 ((0 == strcmp(crypt
->ops
->name
, "WEP") ||
1223 if ((ieee
->rtllib_ap_sec_type
&&
1224 (ieee
->rtllib_ap_sec_type(ieee
) & SEC_ALG_TKIP
)) ||
1225 (ieee
->bForcedBgMode
== true)) {
1226 ieee
->pHTInfo
->bEnableHT
= 0;
1227 ieee
->mode
= WIRELESS_MODE_G
;
1230 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1231 ht_cap_buf
= (u8
*)&(ieee
->pHTInfo
->SelfHTCap
);
1232 ht_cap_len
= sizeof(ieee
->pHTInfo
->SelfHTCap
);
1233 HTConstructCapabilityElement(ieee
, ht_cap_buf
, &ht_cap_len
,
1235 if (ieee
->pHTInfo
->bCurrentRT2RTAggregation
) {
1236 realtek_ie_buf
= ieee
->pHTInfo
->szRT2RTAggBuffer
;
1238 sizeof(ieee
->pHTInfo
->szRT2RTAggBuffer
);
1239 HTConstructRT2RTAggElement(ieee
, realtek_ie_buf
,
1244 if (beacon
->bCkipSupported
)
1246 if (beacon
->bCcxRmEnable
)
1248 if (beacon
->BssCcxVerNumber
>= 2)
1249 cxvernum_ie_len
= 5+2;
1251 PMKCacheIdx
= SecIsInPMKIDList(ieee
, ieee
->current_network
.bssid
);
1252 if (PMKCacheIdx
>= 0) {
1254 printk(KERN_INFO
"[PMK cache]: WPA2 IE length: %x\n",
1257 len
= sizeof(struct rtllib_assoc_request_frame
) + 2
1269 + ieee
->tx_headroom
;
1271 skb
= dev_alloc_skb(len
);
1276 skb_reserve(skb
, ieee
->tx_headroom
);
1278 hdr
= (struct rtllib_assoc_request_frame
*)
1279 skb_put(skb
, sizeof(struct rtllib_assoc_request_frame
) + 2);
1282 hdr
->header
.frame_ctl
= RTLLIB_STYPE_ASSOC_REQ
;
1283 hdr
->header
.duration_id
= 37;
1284 memcpy(hdr
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
1285 memcpy(hdr
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
1286 memcpy(hdr
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
1288 memcpy(ieee
->ap_mac_addr
, beacon
->bssid
, ETH_ALEN
);
1290 hdr
->capability
= cpu_to_le16(WLAN_CAPABILITY_ESS
);
1291 if (beacon
->capability
& WLAN_CAPABILITY_PRIVACY
)
1292 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_PRIVACY
);
1294 if (beacon
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
1295 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
1297 if (ieee
->short_slot
&&
1298 (beacon
->capability
&WLAN_CAPABILITY_SHORT_SLOT_TIME
))
1299 hdr
->capability
|= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1302 hdr
->listen_interval
= beacon
->listen_interval
;
1304 hdr
->info_element
[0].id
= MFIE_TYPE_SSID
;
1306 hdr
->info_element
[0].len
= beacon
->ssid_len
;
1307 tag
= skb_put(skb
, beacon
->ssid_len
);
1308 memcpy(tag
, beacon
->ssid
, beacon
->ssid_len
);
1310 tag
= skb_put(skb
, rate_len
);
1312 if (beacon
->rates_len
) {
1313 *tag
++ = MFIE_TYPE_RATES
;
1314 *tag
++ = beacon
->rates_len
;
1315 for (i
= 0; i
< beacon
->rates_len
; i
++)
1316 *tag
++ = beacon
->rates
[i
];
1319 if (beacon
->rates_ex_len
) {
1320 *tag
++ = MFIE_TYPE_RATES_EX
;
1321 *tag
++ = beacon
->rates_ex_len
;
1322 for (i
= 0; i
< beacon
->rates_ex_len
; i
++)
1323 *tag
++ = beacon
->rates_ex
[i
];
1326 if (beacon
->bCkipSupported
) {
1327 static u8 AironetIeOui
[] = {0x00, 0x01, 0x66};
1328 u8 CcxAironetBuf
[30];
1329 struct octet_string osCcxAironetIE
;
1331 memset(CcxAironetBuf
, 0, 30);
1332 osCcxAironetIE
.Octet
= CcxAironetBuf
;
1333 osCcxAironetIE
.Length
= sizeof(CcxAironetBuf
);
1334 memcpy(osCcxAironetIE
.Octet
, AironetIeOui
,
1335 sizeof(AironetIeOui
));
1337 osCcxAironetIE
.Octet
[IE_CISCO_FLAG_POSITION
] |=
1338 (SUPPORT_CKIP_PK
|SUPPORT_CKIP_MIC
);
1339 tag
= skb_put(skb
, ckip_ie_len
);
1340 *tag
++ = MFIE_TYPE_AIRONET
;
1341 *tag
++ = osCcxAironetIE
.Length
;
1342 memcpy(tag
, osCcxAironetIE
.Octet
, osCcxAironetIE
.Length
);
1343 tag
+= osCcxAironetIE
.Length
;
1346 if (beacon
->bCcxRmEnable
) {
1347 static u8 CcxRmCapBuf
[] = {0x00, 0x40, 0x96, 0x01, 0x01, 0x00};
1348 struct octet_string osCcxRmCap
;
1350 osCcxRmCap
.Octet
= CcxRmCapBuf
;
1351 osCcxRmCap
.Length
= sizeof(CcxRmCapBuf
);
1352 tag
= skb_put(skb
, ccxrm_ie_len
);
1353 *tag
++ = MFIE_TYPE_GENERIC
;
1354 *tag
++ = osCcxRmCap
.Length
;
1355 memcpy(tag
, osCcxRmCap
.Octet
, osCcxRmCap
.Length
);
1356 tag
+= osCcxRmCap
.Length
;
1359 if (beacon
->BssCcxVerNumber
>= 2) {
1360 u8 CcxVerNumBuf
[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1361 struct octet_string osCcxVerNum
;
1362 CcxVerNumBuf
[4] = beacon
->BssCcxVerNumber
;
1363 osCcxVerNum
.Octet
= CcxVerNumBuf
;
1364 osCcxVerNum
.Length
= sizeof(CcxVerNumBuf
);
1365 tag
= skb_put(skb
, cxvernum_ie_len
);
1366 *tag
++ = MFIE_TYPE_GENERIC
;
1367 *tag
++ = osCcxVerNum
.Length
;
1368 memcpy(tag
, osCcxVerNum
.Octet
, osCcxVerNum
.Length
);
1369 tag
+= osCcxVerNum
.Length
;
1371 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1372 if (ieee
->pHTInfo
->ePeerHTSpecVer
!= HT_SPEC_VER_EWC
) {
1373 tag
= skb_put(skb
, ht_cap_len
);
1374 *tag
++ = MFIE_TYPE_HT_CAP
;
1375 *tag
++ = ht_cap_len
- 2;
1376 memcpy(tag
, ht_cap_buf
, ht_cap_len
- 2);
1377 tag
+= ht_cap_len
- 2;
1382 tag
= skb_put(skb
, ieee
->wpa_ie_len
);
1383 memcpy(tag
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
1385 if (PMKCacheIdx
>= 0) {
1386 tag
= skb_put(skb
, 18);
1389 memcpy((tag
+ 2), &ieee
->PMKIDList
[PMKCacheIdx
].PMKID
,
1394 tag
= skb_put(skb
, wmm_info_len
);
1395 rtllib_WMM_Info(ieee
, &tag
);
1398 if (wps_ie_len
&& ieee
->wps_ie
) {
1399 tag
= skb_put(skb
, wps_ie_len
);
1400 memcpy(tag
, ieee
->wps_ie
, wps_ie_len
);
1403 tag
= skb_put(skb
, turbo_info_len
);
1405 rtllib_TURBO_Info(ieee
, &tag
);
1407 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1408 if (ieee
->pHTInfo
->ePeerHTSpecVer
== HT_SPEC_VER_EWC
) {
1409 tag
= skb_put(skb
, ht_cap_len
);
1410 *tag
++ = MFIE_TYPE_GENERIC
;
1411 *tag
++ = ht_cap_len
- 2;
1412 memcpy(tag
, ht_cap_buf
, ht_cap_len
- 2);
1413 tag
+= ht_cap_len
- 2;
1416 if (ieee
->pHTInfo
->bCurrentRT2RTAggregation
) {
1417 tag
= skb_put(skb
, realtek_ie_len
);
1418 *tag
++ = MFIE_TYPE_GENERIC
;
1419 *tag
++ = realtek_ie_len
- 2;
1420 memcpy(tag
, realtek_ie_buf
, realtek_ie_len
- 2);
1424 kfree(ieee
->assocreq_ies
);
1425 ieee
->assocreq_ies
= NULL
;
1426 ies
= &(hdr
->info_element
[0].id
);
1427 ieee
->assocreq_ies_len
= (skb
->data
+ skb
->len
) - ies
;
1428 ieee
->assocreq_ies
= kmalloc(ieee
->assocreq_ies_len
, GFP_ATOMIC
);
1429 if (ieee
->assocreq_ies
)
1430 memcpy(ieee
->assocreq_ies
, ies
, ieee
->assocreq_ies_len
);
1432 printk(KERN_INFO
"%s()Warning: can't alloc memory for assocreq"
1433 "_ies\n", __func__
);
1434 ieee
->assocreq_ies_len
= 0;
1439 void rtllib_associate_abort(struct rtllib_device
*ieee
)
1442 unsigned long flags
;
1443 spin_lock_irqsave(&ieee
->lock
, flags
);
1445 ieee
->associate_seq
++;
1447 /* don't scan, and avoid to have the RX path possibily
1448 * try again to associate. Even do not react to AUTH or
1449 * ASSOC response. Just wait for the retry wq to be scheduled.
1450 * Here we will check if there are good nets to associate
1451 * with, so we retry or just get back to NO_LINK and scanning
1453 if (ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATING
) {
1454 RTLLIB_DEBUG_MGMT("Authentication failed\n");
1455 ieee
->softmac_stats
.no_auth_rs
++;
1457 RTLLIB_DEBUG_MGMT("Association failed\n");
1458 ieee
->softmac_stats
.no_ass_rs
++;
1461 ieee
->state
= RTLLIB_ASSOCIATING_RETRY
;
1463 queue_delayed_work_rsl(ieee
->wq
, &ieee
->associate_retry_wq
,
1464 RTLLIB_SOFTMAC_ASSOC_RETRY_TIME
);
1466 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1469 void rtllib_associate_abort_cb(unsigned long dev
)
1471 rtllib_associate_abort((struct rtllib_device
*) dev
);
1474 void rtllib_associate_step1(struct rtllib_device
*ieee
, u8
* daddr
)
1476 struct rtllib_network
*beacon
= &ieee
->current_network
;
1477 struct sk_buff
*skb
;
1479 RTLLIB_DEBUG_MGMT("Stopping scan\n");
1481 ieee
->softmac_stats
.tx_auth_rq
++;
1483 skb
= rtllib_authentication_req(beacon
, ieee
, 0, daddr
);
1486 rtllib_associate_abort(ieee
);
1488 ieee
->state
= RTLLIB_ASSOCIATING_AUTHENTICATING
;
1489 RTLLIB_DEBUG_MGMT("Sending authentication request\n");
1490 softmac_mgmt_xmit(skb
, ieee
);
1491 if (!timer_pending(&ieee
->associate_timer
)) {
1492 ieee
->associate_timer
.expires
= jiffies
+ (HZ
/ 2);
1493 add_timer(&ieee
->associate_timer
);
1498 void rtllib_auth_challenge(struct rtllib_device
*ieee
, u8
*challenge
, int chlen
)
1501 struct sk_buff
*skb
;
1502 struct rtllib_network
*beacon
= &ieee
->current_network
;
1504 ieee
->associate_seq
++;
1505 ieee
->softmac_stats
.tx_auth_rq
++;
1507 skb
= rtllib_authentication_req(beacon
, ieee
, chlen
+ 2, beacon
->bssid
);
1510 rtllib_associate_abort(ieee
);
1512 c
= skb_put(skb
, chlen
+2);
1513 *(c
++) = MFIE_TYPE_CHALLENGE
;
1515 memcpy(c
, challenge
, chlen
);
1517 RTLLIB_DEBUG_MGMT("Sending authentication challenge "
1520 rtllib_encrypt_fragment(ieee
, skb
,
1521 sizeof(struct rtllib_hdr_3addr
));
1523 softmac_mgmt_xmit(skb
, ieee
);
1524 mod_timer(&ieee
->associate_timer
, jiffies
+ (HZ
/2));
1529 void rtllib_associate_step2(struct rtllib_device
*ieee
)
1531 struct sk_buff
*skb
;
1532 struct rtllib_network
*beacon
= &ieee
->current_network
;
1534 del_timer_sync(&ieee
->associate_timer
);
1536 RTLLIB_DEBUG_MGMT("Sending association request\n");
1538 ieee
->softmac_stats
.tx_ass_rq
++;
1539 skb
= rtllib_association_req(beacon
, ieee
);
1541 rtllib_associate_abort(ieee
);
1543 softmac_mgmt_xmit(skb
, ieee
);
1544 mod_timer(&ieee
->associate_timer
, jiffies
+ (HZ
/2));
1549 void rtllib_associate_complete_wq(void *data
)
1551 struct rtllib_device
*ieee
= (struct rtllib_device
*)
1552 container_of_work_rsl(data
,
1553 struct rtllib_device
,
1554 associate_complete_wq
);
1555 struct rt_pwr_save_ctrl
*pPSC
= (struct rt_pwr_save_ctrl
*)
1556 (&(ieee
->PowerSaveControl
));
1557 printk(KERN_INFO
"Associated successfully\n");
1558 if (ieee
->is_silent_reset
== 0) {
1559 printk(KERN_INFO
"normal associate\n");
1560 notify_wx_assoc_event(ieee
);
1563 netif_carrier_on(ieee
->dev
);
1564 ieee
->is_roaming
= false;
1565 if (rtllib_is_54g(&ieee
->current_network
) &&
1566 (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)) {
1568 printk(KERN_INFO
"Using G rates:%d\n", ieee
->rate
);
1571 ieee
->SetWirelessMode(ieee
->dev
, IEEE_B
);
1572 printk(KERN_INFO
"Using B rates:%d\n", ieee
->rate
);
1574 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
) {
1575 printk(KERN_INFO
"Successfully associated, ht enabled\n");
1578 printk(KERN_INFO
"Successfully associated, ht not "
1579 "enabled(%d, %d)\n",
1580 ieee
->pHTInfo
->bCurrentHTSupport
,
1581 ieee
->pHTInfo
->bEnableHT
);
1582 memset(ieee
->dot11HTOperationalRateSet
, 0, 16);
1584 ieee
->LinkDetectInfo
.SlotNum
= 2 * (1 +
1585 ieee
->current_network
.beacon_interval
/
1587 if (ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
== 0 ||
1588 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
== 0) {
1589 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
= 1;
1590 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
= 1;
1592 pPSC
->LpsIdleCount
= 0;
1593 ieee
->link_change(ieee
->dev
);
1595 if (ieee
->is_silent_reset
== 1) {
1596 printk(KERN_INFO
"silent reset associate\n");
1597 ieee
->is_silent_reset
= 0;
1600 if (ieee
->data_hard_resume
)
1601 ieee
->data_hard_resume(ieee
->dev
);
1605 static void rtllib_sta_send_associnfo(struct rtllib_device
*ieee
)
1609 void rtllib_associate_complete(struct rtllib_device
*ieee
)
1611 del_timer_sync(&ieee
->associate_timer
);
1613 ieee
->state
= RTLLIB_LINKED
;
1614 rtllib_sta_send_associnfo(ieee
);
1616 queue_work_rsl(ieee
->wq
, &ieee
->associate_complete_wq
);
1619 void rtllib_associate_procedure_wq(void *data
)
1621 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
1622 struct rtllib_device
,
1623 associate_procedure_wq
);
1624 rtllib_stop_scan_syncro(ieee
);
1625 if (ieee
->rtllib_ips_leave
!= NULL
)
1626 ieee
->rtllib_ips_leave(ieee
->dev
);
1627 down(&ieee
->wx_sem
);
1629 if (ieee
->data_hard_stop
)
1630 ieee
->data_hard_stop(ieee
->dev
);
1632 rtllib_stop_scan(ieee
);
1633 RT_TRACE(COMP_DBG
, "===>%s(), chan:%d\n", __func__
,
1634 ieee
->current_network
.channel
);
1635 HTSetConnectBwMode(ieee
, HT_CHANNEL_WIDTH_20
, HT_EXTCHNL_OFFSET_NO_EXT
);
1636 if (ieee
->eRFPowerState
== eRfOff
) {
1637 RT_TRACE(COMP_DBG
, "=============>%s():Rf state is eRfOff,"
1638 " schedule ipsleave wq again,return\n", __func__
);
1639 if (ieee
->rtllib_ips_leave_wq
!= NULL
)
1640 ieee
->rtllib_ips_leave_wq(ieee
->dev
);
1644 ieee
->associate_seq
= 1;
1646 rtllib_associate_step1(ieee
, ieee
->current_network
.bssid
);
1651 inline void rtllib_softmac_new_net(struct rtllib_device
*ieee
,
1652 struct rtllib_network
*net
)
1654 u8 tmp_ssid
[IW_ESSID_MAX_SIZE
+ 1];
1655 int tmp_ssid_len
= 0;
1657 short apset
, ssidset
, ssidbroad
, apmatch
, ssidmatch
;
1659 /* we are interested in new new only if we are not associated
1660 * and we are not associating / authenticating
1662 if (ieee
->state
!= RTLLIB_NOLINK
)
1665 if ((ieee
->iw_mode
== IW_MODE_INFRA
) && !(net
->capability
&
1666 WLAN_CAPABILITY_ESS
))
1669 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) && !(net
->capability
&
1670 WLAN_CAPABILITY_IBSS
))
1673 if ((ieee
->iw_mode
== IW_MODE_ADHOC
) &&
1674 (net
->channel
> ieee
->ibss_maxjoin_chal
))
1676 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
) {
1677 /* if the user specified the AP MAC, we need also the essid
1678 * This could be obtained by beacons or, if the network does not
1679 * broadcast it, it can be put manually.
1681 apset
= ieee
->wap_set
;
1682 ssidset
= ieee
->ssid_set
;
1683 ssidbroad
= !(net
->ssid_len
== 0 || net
->ssid
[0] == '\0');
1684 apmatch
= (memcmp(ieee
->current_network
.bssid
, net
->bssid
,
1687 ssidmatch
= (ieee
->current_network
.ssid_len
==
1688 net
->hidden_ssid_len
) &&
1689 (!strncmp(ieee
->current_network
.ssid
,
1690 net
->hidden_ssid
, net
->hidden_ssid_len
));
1691 if (net
->hidden_ssid_len
> 0) {
1692 strncpy(net
->ssid
, net
->hidden_ssid
,
1693 net
->hidden_ssid_len
);
1694 net
->ssid_len
= net
->hidden_ssid_len
;
1699 (ieee
->current_network
.ssid_len
== net
->ssid_len
) &&
1700 (!strncmp(ieee
->current_network
.ssid
, net
->ssid
,
1703 /* if the user set the AP check if match.
1704 * if the network does not broadcast essid we check the
1705 * user supplyed ANY essid
1706 * if the network does broadcast and the user does not set
1708 * if the network does broadcast and the user did set essid
1709 * check if essid match
1710 * if the ap is not set, check that the user set the bssid
1711 * and the network does bradcast and that those two bssid match
1713 if ((apset
&& apmatch
&&
1714 ((ssidset
&& ssidbroad
&& ssidmatch
) ||
1715 (ssidbroad
&& !ssidset
) || (!ssidbroad
&& ssidset
))) ||
1716 (!apset
&& ssidset
&& ssidbroad
&& ssidmatch
) ||
1717 (ieee
->is_roaming
&& ssidset
&& ssidbroad
&& ssidmatch
)) {
1718 /* if the essid is hidden replace it with the
1719 * essid provided by the user.
1722 strncpy(tmp_ssid
, ieee
->current_network
.ssid
,
1724 tmp_ssid_len
= ieee
->current_network
.ssid_len
;
1726 memcpy(&ieee
->current_network
, net
,
1727 sizeof(struct rtllib_network
));
1729 strncpy(ieee
->current_network
.ssid
, tmp_ssid
,
1731 ieee
->current_network
.ssid_len
= tmp_ssid_len
;
1733 printk(KERN_INFO
"Linking with %s,channel:%d, qos:%d, "
1734 "myHT:%d, networkHT:%d, mode:%x cur_net.flags"
1735 ":0x%x\n", ieee
->current_network
.ssid
,
1736 ieee
->current_network
.channel
,
1737 ieee
->current_network
.qos_data
.supported
,
1738 ieee
->pHTInfo
->bEnableHT
,
1739 ieee
->current_network
.bssht
.bdSupportHT
,
1740 ieee
->current_network
.mode
,
1741 ieee
->current_network
.flags
);
1743 if ((rtllib_act_scanning(ieee
, false)) &&
1744 !(ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
))
1745 rtllib_stop_scan_syncro(ieee
);
1747 ieee
->hwscan_ch_bk
= ieee
->current_network
.channel
;
1748 HTResetIOTSetting(ieee
->pHTInfo
);
1750 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
1751 /* Join the network for the first time */
1752 ieee
->AsocRetryCount
= 0;
1753 if ((ieee
->current_network
.qos_data
.supported
== 1) &&
1754 ieee
->current_network
.bssht
.bdSupportHT
)
1755 HTResetSelfAndSavePeerSetting(ieee
,
1756 &(ieee
->current_network
));
1758 ieee
->pHTInfo
->bCurrentHTSupport
=
1761 ieee
->state
= RTLLIB_ASSOCIATING
;
1762 if (ieee
->LedControlHandler
!= NULL
)
1763 ieee
->LedControlHandler(ieee
->dev
,
1764 LED_CTL_START_TO_LINK
);
1765 queue_delayed_work_rsl(ieee
->wq
,
1766 &ieee
->associate_procedure_wq
, 0);
1768 if (rtllib_is_54g(&ieee
->current_network
) &&
1769 (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)) {
1771 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
1772 printk(KERN_INFO
"Using G rates\n");
1775 ieee
->SetWirelessMode(ieee
->dev
, IEEE_B
);
1776 printk(KERN_INFO
"Using B rates\n");
1778 memset(ieee
->dot11HTOperationalRateSet
, 0, 16);
1779 ieee
->state
= RTLLIB_LINKED
;
1785 void rtllib_softmac_check_all_nets(struct rtllib_device
*ieee
)
1787 unsigned long flags
;
1788 struct rtllib_network
*target
;
1790 spin_lock_irqsave(&ieee
->lock
, flags
);
1792 list_for_each_entry(target
, &ieee
->network_list
, list
) {
1794 /* if the state become different that NOLINK means
1795 * we had found what we are searching for
1798 if (ieee
->state
!= RTLLIB_NOLINK
)
1801 if (ieee
->scan_age
== 0 || time_after(target
->last_scanned
+
1802 ieee
->scan_age
, jiffies
))
1803 rtllib_softmac_new_net(ieee
, target
);
1805 spin_unlock_irqrestore(&ieee
->lock
, flags
);
1808 static inline u16
auth_parse(struct sk_buff
*skb
, u8
** challenge
, int *chlen
)
1810 struct rtllib_authentication
*a
;
1812 if (skb
->len
< (sizeof(struct rtllib_authentication
) -
1813 sizeof(struct rtllib_info_element
))) {
1814 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1818 a
= (struct rtllib_authentication
*) skb
->data
;
1819 if (skb
->len
> (sizeof(struct rtllib_authentication
) + 3)) {
1820 t
= skb
->data
+ sizeof(struct rtllib_authentication
);
1822 if (*(t
++) == MFIE_TYPE_CHALLENGE
) {
1824 *challenge
= kmalloc(*chlen
, GFP_ATOMIC
);
1825 memcpy(*challenge
, t
, *chlen
); /*TODO - check here*/
1828 return cpu_to_le16(a
->status
);
1831 int auth_rq_parse(struct sk_buff
*skb
, u8
*dest
)
1833 struct rtllib_authentication
*a
;
1835 if (skb
->len
< (sizeof(struct rtllib_authentication
) -
1836 sizeof(struct rtllib_info_element
))) {
1837 RTLLIB_DEBUG_MGMT("invalid len in auth request: %d\n",
1841 a
= (struct rtllib_authentication
*) skb
->data
;
1843 memcpy(dest
, a
->header
.addr2
, ETH_ALEN
);
1845 if (le16_to_cpu(a
->algorithm
) != WLAN_AUTH_OPEN
)
1846 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
;
1848 return WLAN_STATUS_SUCCESS
;
1851 static short probe_rq_parse(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1858 struct rtllib_hdr_3addr
*header
=
1859 (struct rtllib_hdr_3addr
*) skb
->data
;
1862 if (skb
->len
< sizeof(struct rtllib_hdr_3addr
))
1863 return -1; /* corrupted */
1866 (memcmp(header
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
) != 0) &&
1867 (memcmp(header
->addr3
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0);
1871 memcpy(src
, header
->addr2
, ETH_ALEN
);
1873 skbend
= (u8
*)skb
->data
+ skb
->len
;
1875 tag
= skb
->data
+ sizeof(struct rtllib_hdr_3addr
);
1877 while (tag
+ 1 < skbend
) {
1880 ssidlen
= *(tag
+ 1);
1883 tag
++; /* point to the len field */
1884 tag
= tag
+ *(tag
); /* point to the last data byte of the tag */
1885 tag
++; /* point to the next tag */
1892 return 1; /* ssid not found in tagged param */
1894 return !strncmp(ssid
, ieee
->current_network
.ssid
, ssidlen
);
1897 int assoc_rq_parse(struct sk_buff
*skb
, u8
*dest
)
1899 struct rtllib_assoc_request_frame
*a
;
1901 if (skb
->len
< (sizeof(struct rtllib_assoc_request_frame
) -
1902 sizeof(struct rtllib_info_element
))) {
1904 RTLLIB_DEBUG_MGMT("invalid len in auth request:%d\n", skb
->len
);
1908 a
= (struct rtllib_assoc_request_frame
*) skb
->data
;
1910 memcpy(dest
, a
->header
.addr2
, ETH_ALEN
);
1915 static inline u16
assoc_parse(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
1918 struct rtllib_assoc_response_frame
*response_head
;
1921 if (skb
->len
< sizeof(struct rtllib_assoc_response_frame
)) {
1922 RTLLIB_DEBUG_MGMT("invalid len in auth resp: %d\n", skb
->len
);
1926 response_head
= (struct rtllib_assoc_response_frame
*) skb
->data
;
1927 *aid
= le16_to_cpu(response_head
->aid
) & 0x3fff;
1929 status_code
= le16_to_cpu(response_head
->status
);
1930 if ((status_code
== WLAN_STATUS_ASSOC_DENIED_RATES
||
1931 status_code
== WLAN_STATUS_CAPS_UNSUPPORTED
) &&
1932 ((ieee
->mode
== IEEE_G
) &&
1933 (ieee
->current_network
.mode
== IEEE_N_24G
) &&
1934 (ieee
->AsocRetryCount
++ < (RT_ASOC_RETRY_LIMIT
-1)))) {
1935 ieee
->pHTInfo
->IOTAction
|= HT_IOT_ACT_PURE_N_MODE
;
1937 ieee
->AsocRetryCount
= 0;
1940 return le16_to_cpu(response_head
->status
);
1943 void rtllib_rx_probe_rq(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
1946 ieee
->softmac_stats
.rx_probe_rq
++;
1947 if (probe_rq_parse(ieee
, skb
, dest
) > 0) {
1948 ieee
->softmac_stats
.tx_probe_rs
++;
1949 rtllib_resp_to_probe(ieee
, dest
);
1953 static inline void rtllib_rx_auth_rq(struct rtllib_device
*ieee
,
1954 struct sk_buff
*skb
)
1958 ieee
->softmac_stats
.rx_auth_rq
++;
1960 status
= auth_rq_parse(skb
, dest
);
1962 rtllib_resp_to_auth(ieee
, status
, dest
);
1965 static inline void rtllib_rx_assoc_rq(struct rtllib_device
*ieee
,
1966 struct sk_buff
*skb
)
1971 ieee
->softmac_stats
.rx_ass_rq
++;
1972 if (assoc_rq_parse(skb
, dest
) != -1)
1973 rtllib_resp_to_assoc_rq(ieee
, dest
);
1975 printk(KERN_INFO
"New client associated: "MAC_FMT
"\n", MAC_ARG(dest
));
1978 void rtllib_sta_ps_send_null_frame(struct rtllib_device
*ieee
, short pwr
)
1981 struct sk_buff
*buf
= rtllib_null_func(ieee
, pwr
);
1984 softmac_ps_mgmt_xmit(buf
, ieee
);
1987 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device
*ieee
)
1989 struct sk_buff
*buf
= rtllib_pspoll_func(ieee
);
1992 softmac_ps_mgmt_xmit(buf
, ieee
);
1995 static short rtllib_sta_ps_sleep(struct rtllib_device
*ieee
, u64
*time
)
1997 int timeout
= ieee
->ps_timeout
;
1999 struct rt_pwr_save_ctrl
*pPSC
= (struct rt_pwr_save_ctrl
*)
2000 (&(ieee
->PowerSaveControl
));
2002 if (ieee
->LPSDelayCnt
) {
2003 ieee
->LPSDelayCnt
--;
2007 dtim
= ieee
->current_network
.dtim_data
;
2008 if (!(dtim
& RTLLIB_DTIM_VALID
))
2010 timeout
= ieee
->current_network
.beacon_interval
;
2011 ieee
->current_network
.dtim_data
= RTLLIB_DTIM_INVALID
;
2012 /* there's no need to nofity AP that I find you buffered
2013 * with broadcast packet */
2014 if (dtim
& (RTLLIB_DTIM_UCAST
& ieee
->ps
))
2017 if (!time_after(jiffies
, ieee
->dev
->trans_start
+ MSECS(timeout
)))
2019 if (!time_after(jiffies
, ieee
->last_rx_ps_time
+ MSECS(timeout
)))
2021 if ((ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) &&
2022 (ieee
->mgmt_queue_tail
!= ieee
->mgmt_queue_head
))
2026 if (ieee
->bAwakePktSent
== true) {
2027 pPSC
->LPSAwakeIntvl
= 1;
2031 if (pPSC
->LPSAwakeIntvl
== 0)
2032 pPSC
->LPSAwakeIntvl
= 1;
2033 if (pPSC
->RegMaxLPSAwakeIntvl
== 0)
2035 else if (pPSC
->RegMaxLPSAwakeIntvl
== 0xFF)
2036 MaxPeriod
= ieee
->current_network
.dtim_period
;
2038 MaxPeriod
= pPSC
->RegMaxLPSAwakeIntvl
;
2039 pPSC
->LPSAwakeIntvl
= (pPSC
->LPSAwakeIntvl
>=
2040 MaxPeriod
) ? MaxPeriod
:
2041 (pPSC
->LPSAwakeIntvl
+ 1);
2044 u8 LPSAwakeIntvl_tmp
= 0;
2045 u8 period
= ieee
->current_network
.dtim_period
;
2046 u8 count
= ieee
->current_network
.tim
.tim_count
;
2048 if (pPSC
->LPSAwakeIntvl
> period
)
2049 LPSAwakeIntvl_tmp
= period
+
2050 (pPSC
->LPSAwakeIntvl
-
2052 ((pPSC
->LPSAwakeIntvl
-period
) %
2055 LPSAwakeIntvl_tmp
= pPSC
->LPSAwakeIntvl
;
2058 if (pPSC
->LPSAwakeIntvl
>
2059 ieee
->current_network
.tim
.tim_count
)
2060 LPSAwakeIntvl_tmp
= count
+
2061 (pPSC
->LPSAwakeIntvl
- count
) -
2062 ((pPSC
->LPSAwakeIntvl
-count
)%period
);
2064 LPSAwakeIntvl_tmp
= pPSC
->LPSAwakeIntvl
;
2067 *time
= ieee
->current_network
.last_dtim_sta_time
2068 + MSECS(ieee
->current_network
.beacon_interval
*
2078 inline void rtllib_sta_ps(struct rtllib_device
*ieee
)
2082 unsigned long flags
, flags2
;
2084 spin_lock_irqsave(&ieee
->lock
, flags
);
2086 if ((ieee
->ps
== RTLLIB_PS_DISABLED
||
2087 ieee
->iw_mode
!= IW_MODE_INFRA
||
2088 ieee
->state
!= RTLLIB_LINKED
)) {
2089 RT_TRACE(COMP_DBG
, "=====>%s(): no need to ps,wake up!! "
2090 "ieee->ps is %d, ieee->iw_mode is %d, ieee->state"
2091 " is %d\n", __func__
, ieee
->ps
, ieee
->iw_mode
,
2093 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2094 rtllib_sta_wakeup(ieee
, 1);
2096 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2098 sleep
= rtllib_sta_ps_sleep(ieee
, &time
);
2099 /* 2 wake, 1 sleep, 0 do nothing */
2103 if (ieee
->sta_sleep
== LPS_IS_SLEEP
) {
2104 ieee
->enter_sleep_state(ieee
->dev
, time
);
2105 } else if (ieee
->sta_sleep
== LPS_IS_WAKE
) {
2106 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2108 if (ieee
->ps_is_queue_empty(ieee
->dev
)) {
2109 ieee
->sta_sleep
= LPS_WAIT_NULL_DATA_SEND
;
2110 ieee
->ack_tx_to_ieee
= 1;
2111 rtllib_sta_ps_send_null_frame(ieee
, 1);
2112 ieee
->ps_time
= time
;
2114 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2118 ieee
->bAwakePktSent
= false;
2120 } else if (sleep
== 2) {
2121 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2123 rtllib_sta_wakeup(ieee
, 1);
2125 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2129 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2133 void rtllib_sta_wakeup(struct rtllib_device
*ieee
, short nl
)
2135 if (ieee
->sta_sleep
== LPS_IS_WAKE
) {
2137 if (ieee
->pHTInfo
->IOTAction
&
2138 HT_IOT_ACT_NULL_DATA_POWER_SAVING
) {
2139 ieee
->ack_tx_to_ieee
= 1;
2140 rtllib_sta_ps_send_null_frame(ieee
, 0);
2142 ieee
->ack_tx_to_ieee
= 1;
2143 rtllib_sta_ps_send_pspoll_frame(ieee
);
2150 if (ieee
->sta_sleep
== LPS_IS_SLEEP
)
2151 ieee
->sta_wake_up(ieee
->dev
);
2153 if (ieee
->pHTInfo
->IOTAction
&
2154 HT_IOT_ACT_NULL_DATA_POWER_SAVING
) {
2155 ieee
->ack_tx_to_ieee
= 1;
2156 rtllib_sta_ps_send_null_frame(ieee
, 0);
2158 ieee
->ack_tx_to_ieee
= 1;
2159 ieee
->polling
= true;
2160 rtllib_sta_ps_send_pspoll_frame(ieee
);
2164 ieee
->sta_sleep
= LPS_IS_WAKE
;
2165 ieee
->polling
= false;
2169 void rtllib_ps_tx_ack(struct rtllib_device
*ieee
, short success
)
2171 unsigned long flags
, flags2
;
2173 spin_lock_irqsave(&ieee
->lock
, flags
);
2175 if (ieee
->sta_sleep
== LPS_WAIT_NULL_DATA_SEND
) {
2176 /* Null frame with PS bit set */
2178 ieee
->sta_sleep
= LPS_IS_SLEEP
;
2179 ieee
->enter_sleep_state(ieee
->dev
, ieee
->ps_time
);
2181 /* if the card report not success we can't be sure the AP
2182 * has not RXed so we can't assume the AP believe us awake
2184 } else {/* 21112005 - tx again null without PS bit if lost */
2186 if ((ieee
->sta_sleep
== LPS_IS_WAKE
) && !success
) {
2187 spin_lock_irqsave(&ieee
->mgmt_tx_lock
, flags2
);
2188 if (ieee
->pHTInfo
->IOTAction
&
2189 HT_IOT_ACT_NULL_DATA_POWER_SAVING
)
2190 rtllib_sta_ps_send_null_frame(ieee
, 0);
2192 rtllib_sta_ps_send_pspoll_frame(ieee
);
2193 spin_unlock_irqrestore(&ieee
->mgmt_tx_lock
, flags2
);
2196 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2199 void rtllib_process_action(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
2201 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2202 u8
*act
= rtllib_get_payload((struct rtllib_hdr
*)header
);
2206 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "error to get payload of "
2217 rtllib_rx_ADDBAReq(ieee
, skb
);
2220 rtllib_rx_ADDBARsp(ieee
, skb
);
2223 rtllib_rx_DELBA(ieee
, skb
);
2233 inline int rtllib_rx_assoc_resp(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
2234 struct rtllib_rx_stats
*rx_stats
)
2239 struct rtllib_assoc_response_frame
*assoc_resp
;
2240 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2242 RTLLIB_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
2243 WLAN_FC_GET_STYPE(header
->frame_ctl
));
2245 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2246 ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATED
&&
2247 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2248 errcode
= assoc_parse(ieee
, skb
, &aid
);
2250 struct rtllib_network
*network
=
2251 kzalloc(sizeof(struct rtllib_network
),
2256 memset(network
, 0, sizeof(*network
));
2257 ieee
->state
= RTLLIB_LINKED
;
2258 ieee
->assoc_id
= aid
;
2259 ieee
->softmac_stats
.rx_ass_ok
++;
2260 /* station support qos */
2261 /* Let the register setting default with Legacy station */
2262 assoc_resp
= (struct rtllib_assoc_response_frame
*)skb
->data
;
2263 if (ieee
->current_network
.qos_data
.supported
== 1) {
2264 if (rtllib_parse_info_param(ieee
, assoc_resp
->info_element
,
2265 rx_stats
->len
- sizeof(*assoc_resp
),
2266 network
, rx_stats
)) {
2270 memcpy(ieee
->pHTInfo
->PeerHTCapBuf
,
2271 network
->bssht
.bdHTCapBuf
,
2272 network
->bssht
.bdHTCapLen
);
2273 memcpy(ieee
->pHTInfo
->PeerHTInfoBuf
,
2274 network
->bssht
.bdHTInfoBuf
,
2275 network
->bssht
.bdHTInfoLen
);
2277 if (ieee
->handle_assoc_response
!= NULL
)
2278 ieee
->handle_assoc_response(ieee
->dev
,
2279 (struct rtllib_assoc_response_frame
*)header
,
2284 kfree(ieee
->assocresp_ies
);
2285 ieee
->assocresp_ies
= NULL
;
2286 ies
= &(assoc_resp
->info_element
[0].id
);
2287 ieee
->assocresp_ies_len
= (skb
->data
+ skb
->len
) - ies
;
2288 ieee
->assocresp_ies
= kmalloc(ieee
->assocresp_ies_len
,
2290 if (ieee
->assocresp_ies
)
2291 memcpy(ieee
->assocresp_ies
, ies
,
2292 ieee
->assocresp_ies_len
);
2294 printk(KERN_INFO
"%s()Warning: can't alloc "
2295 "memory for assocresp_ies\n", __func__
);
2296 ieee
->assocresp_ies_len
= 0;
2298 rtllib_associate_complete(ieee
);
2300 /* aid could not been allocated */
2301 ieee
->softmac_stats
.rx_ass_err
++;
2302 printk(KERN_INFO
"Association response status code 0x%x\n",
2305 "Association response status code 0x%x\n",
2307 if (ieee
->AsocRetryCount
< RT_ASOC_RETRY_LIMIT
)
2308 queue_delayed_work_rsl(ieee
->wq
,
2309 &ieee
->associate_procedure_wq
, 0);
2311 rtllib_associate_abort(ieee
);
2317 inline int rtllib_rx_auth(struct rtllib_device
*ieee
, struct sk_buff
*skb
,
2318 struct rtllib_rx_stats
*rx_stats
)
2323 bool bSupportNmode
= true, bHalfSupportNmode
= false;
2325 if (ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) {
2326 if (ieee
->state
== RTLLIB_ASSOCIATING_AUTHENTICATING
&&
2327 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2328 RTLLIB_DEBUG_MGMT("Received authentication response");
2330 errcode
= auth_parse(skb
, &challenge
, &chlen
);
2332 if (ieee
->open_wep
|| !challenge
) {
2333 ieee
->state
= RTLLIB_ASSOCIATING_AUTHENTICATED
;
2334 ieee
->softmac_stats
.rx_auth_rs_ok
++;
2335 if (!(ieee
->pHTInfo
->IOTAction
&
2336 HT_IOT_ACT_PURE_N_MODE
)) {
2337 if (!ieee
->GetNmodeSupportBySecCfg(ieee
->dev
)) {
2338 if (IsHTHalfNmodeAPs(ieee
)) {
2339 bSupportNmode
= true;
2340 bHalfSupportNmode
= true;
2342 bSupportNmode
= false;
2343 bHalfSupportNmode
= false;
2347 /* Dummy wirless mode setting to avoid
2348 * encryption issue */
2349 if (bSupportNmode
) {
2350 ieee
->SetWirelessMode(ieee
->dev
,
2351 ieee
->current_network
.mode
);
2354 ieee
->SetWirelessMode(ieee
->dev
,
2358 if (ieee
->current_network
.mode
==
2360 bHalfSupportNmode
== true) {
2361 printk(KERN_INFO
"======>enter "
2363 ieee
->bHalfWirelessN24GMode
=
2366 ieee
->bHalfWirelessN24GMode
=
2369 rtllib_associate_step2(ieee
);
2371 rtllib_auth_challenge(ieee
, challenge
,
2375 ieee
->softmac_stats
.rx_auth_rs_err
++;
2376 RTLLIB_DEBUG_MGMT("Authentication respose"
2377 " status code 0x%x", errcode
);
2379 printk(KERN_INFO
"Authentication respose "
2380 "status code 0x%x", errcode
);
2381 rtllib_associate_abort(ieee
);
2384 } else if (ieee
->iw_mode
== IW_MODE_MASTER
) {
2385 rtllib_rx_auth_rq(ieee
, skb
);
2391 inline int rtllib_rx_deauth(struct rtllib_device
*ieee
, struct sk_buff
*skb
)
2393 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2395 if (memcmp(header
->addr3
, ieee
->current_network
.bssid
, ETH_ALEN
) != 0)
2398 /* FIXME for now repeat all the association procedure
2399 * both for disassociation and deauthentication
2401 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2402 ieee
->state
== RTLLIB_LINKED
&&
2403 (ieee
->iw_mode
== IW_MODE_INFRA
)) {
2404 printk(KERN_INFO
"==========>received disassoc/deauth(%x) "
2405 "frame, reason code:%x\n",
2406 WLAN_FC_GET_STYPE(header
->frame_ctl
),
2407 ((struct rtllib_disassoc
*)skb
->data
)->reason
);
2408 ieee
->state
= RTLLIB_ASSOCIATING
;
2409 ieee
->softmac_stats
.reassoc
++;
2410 ieee
->is_roaming
= true;
2411 ieee
->LinkDetectInfo
.bBusyTraffic
= false;
2412 rtllib_disassociate(ieee
);
2413 RemovePeerTS(ieee
, header
->addr2
);
2414 if (ieee
->LedControlHandler
!= NULL
)
2415 ieee
->LedControlHandler(ieee
->dev
,
2416 LED_CTL_START_TO_LINK
);
2418 if (!(ieee
->rtllib_ap_sec_type(ieee
) &
2419 (SEC_ALG_CCMP
|SEC_ALG_TKIP
)))
2420 queue_delayed_work_rsl(ieee
->wq
,
2421 &ieee
->associate_procedure_wq
, 5);
2426 inline int rtllib_rx_frame_softmac(struct rtllib_device
*ieee
,
2427 struct sk_buff
*skb
,
2428 struct rtllib_rx_stats
*rx_stats
, u16 type
,
2431 struct rtllib_hdr_3addr
*header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2433 if (!ieee
->proto_started
)
2436 switch (WLAN_FC_GET_STYPE(header
->frame_ctl
)) {
2437 case RTLLIB_STYPE_ASSOC_RESP
:
2438 case RTLLIB_STYPE_REASSOC_RESP
:
2439 if (rtllib_rx_assoc_resp(ieee
, skb
, rx_stats
) == 1)
2442 case RTLLIB_STYPE_ASSOC_REQ
:
2443 case RTLLIB_STYPE_REASSOC_REQ
:
2444 if ((ieee
->softmac_features
& IEEE_SOFTMAC_ASSOCIATE
) &&
2445 ieee
->iw_mode
== IW_MODE_MASTER
)
2446 rtllib_rx_assoc_rq(ieee
, skb
);
2448 case RTLLIB_STYPE_AUTH
:
2449 rtllib_rx_auth(ieee
, skb
, rx_stats
);
2451 case RTLLIB_STYPE_DISASSOC
:
2452 case RTLLIB_STYPE_DEAUTH
:
2453 rtllib_rx_deauth(ieee
, skb
);
2455 case RTLLIB_STYPE_MANAGE_ACT
:
2456 rtllib_process_action(ieee
, skb
);
2465 /* following are for a simplier TX queue management.
2466 * Instead of using netif_[stop/wake]_queue the driver
2467 * will uses these two function (plus a reset one), that
2468 * will internally uses the kernel netif_* and takes
2469 * care of the ieee802.11 fragmentation.
2470 * So the driver receives a fragment per time and might
2471 * call the stop function when it want without take care
2472 * to have enought room to TX an entire packet.
2473 * This might be useful if each fragment need it's own
2474 * descriptor, thus just keep a total free memory > than
2475 * the max fragmentation treshold is not enought.. If the
2476 * ieee802.11 stack passed a TXB struct then you needed
2477 * to keep N free descriptors where
2478 * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD
2479 * In this way you need just one and the 802.11 stack
2480 * will take care of buffering fragments and pass them to
2481 * to the driver later, when it wakes the queue.
2483 void rtllib_softmac_xmit(struct rtllib_txb
*txb
, struct rtllib_device
*ieee
)
2486 unsigned int queue_index
= txb
->queue_index
;
2487 unsigned long flags
;
2489 struct cb_desc
*tcb_desc
= NULL
;
2490 unsigned long queue_len
= 0;
2492 spin_lock_irqsave(&ieee
->lock
, flags
);
2494 /* called with 2nd parm 0, no tx mgmt lock required */
2495 rtllib_sta_wakeup(ieee
, 0);
2497 /* update the tx status */
2498 tcb_desc
= (struct cb_desc
*)(txb
->fragments
[0]->cb
+
2500 if (tcb_desc
->bMulticast
)
2501 ieee
->stats
.multicast
++;
2503 /* if xmit available, just xmit it immediately, else just insert it to
2505 for (i
= 0; i
< txb
->nr_frags
; i
++) {
2506 queue_len
= skb_queue_len(&ieee
->skb_waitQ
[queue_index
]);
2507 if ((queue_len
!= 0) ||\
2508 (!ieee
->check_nic_enough_desc(ieee
->dev
, queue_index
)) ||
2509 (ieee
->queue_stop
)) {
2510 /* insert the skb packet to the wait queue */
2511 /* as for the completion function, it does not need
2512 * to check it any more.
2514 if (queue_len
< 200)
2515 skb_queue_tail(&ieee
->skb_waitQ
[queue_index
],
2518 kfree_skb(txb
->fragments
[i
]);
2520 ieee
->softmac_data_hard_start_xmit(
2522 ieee
->dev
, ieee
->rate
);
2526 rtllib_txb_free(txb
);
2528 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2532 /* called with ieee->lock acquired */
2533 void rtllib_resume_tx(struct rtllib_device
*ieee
)
2536 for (i
= ieee
->tx_pending
.frag
; i
< ieee
->tx_pending
.txb
->nr_frags
;
2539 if (ieee
->queue_stop
) {
2540 ieee
->tx_pending
.frag
= i
;
2544 ieee
->softmac_data_hard_start_xmit(
2545 ieee
->tx_pending
.txb
->fragments
[i
],
2546 ieee
->dev
, ieee
->rate
);
2547 ieee
->stats
.tx_packets
++;
2551 rtllib_txb_free(ieee
->tx_pending
.txb
);
2552 ieee
->tx_pending
.txb
= NULL
;
2556 void rtllib_reset_queue(struct rtllib_device
*ieee
)
2558 unsigned long flags
;
2560 spin_lock_irqsave(&ieee
->lock
, flags
);
2561 init_mgmt_queue(ieee
);
2562 if (ieee
->tx_pending
.txb
) {
2563 rtllib_txb_free(ieee
->tx_pending
.txb
);
2564 ieee
->tx_pending
.txb
= NULL
;
2566 ieee
->queue_stop
= 0;
2567 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2571 void rtllib_wake_queue(struct rtllib_device
*ieee
)
2574 unsigned long flags
;
2575 struct sk_buff
*skb
;
2576 struct rtllib_hdr_3addr
*header
;
2578 spin_lock_irqsave(&ieee
->lock
, flags
);
2579 if (!ieee
->queue_stop
)
2582 ieee
->queue_stop
= 0;
2584 if (ieee
->softmac_features
& IEEE_SOFTMAC_SINGLE_QUEUE
) {
2585 while (!ieee
->queue_stop
&& (skb
= dequeue_mgmt(ieee
))) {
2587 header
= (struct rtllib_hdr_3addr
*) skb
->data
;
2589 header
->seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2591 if (ieee
->seq_ctrl
[0] == 0xFFF)
2592 ieee
->seq_ctrl
[0] = 0;
2594 ieee
->seq_ctrl
[0]++;
2596 ieee
->softmac_data_hard_start_xmit(skb
, ieee
->dev
,
2600 if (!ieee
->queue_stop
&& ieee
->tx_pending
.txb
)
2601 rtllib_resume_tx(ieee
);
2603 if (!ieee
->queue_stop
&& netif_queue_stopped(ieee
->dev
)) {
2604 ieee
->softmac_stats
.swtxawake
++;
2605 netif_wake_queue(ieee
->dev
);
2609 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2613 void rtllib_stop_queue(struct rtllib_device
*ieee
)
2616 if (!netif_queue_stopped(ieee
->dev
)) {
2617 netif_stop_queue(ieee
->dev
);
2618 ieee
->softmac_stats
.swtxstop
++;
2620 ieee
->queue_stop
= 1;
2624 void rtllib_stop_all_queues(struct rtllib_device
*ieee
)
2627 for (i
= 0; i
< ieee
->dev
->num_tx_queues
; i
++)
2628 netdev_get_tx_queue(ieee
->dev
, i
)->trans_start
= jiffies
;
2630 netif_tx_stop_all_queues(ieee
->dev
);
2633 void rtllib_wake_all_queues(struct rtllib_device
*ieee
)
2635 netif_tx_wake_all_queues(ieee
->dev
);
2638 inline void rtllib_randomize_cell(struct rtllib_device
*ieee
)
2641 get_random_bytes(ieee
->current_network
.bssid
, ETH_ALEN
);
2643 /* an IBSS cell address must have the two less significant
2644 * bits of the first byte = 2
2646 ieee
->current_network
.bssid
[0] &= ~0x01;
2647 ieee
->current_network
.bssid
[0] |= 0x02;
2650 /* called in user context only */
2651 void rtllib_start_master_bss(struct rtllib_device
*ieee
)
2655 if (ieee
->current_network
.ssid_len
== 0) {
2656 strncpy(ieee
->current_network
.ssid
,
2657 RTLLIB_DEFAULT_TX_ESSID
,
2660 ieee
->current_network
.ssid_len
=
2661 strlen(RTLLIB_DEFAULT_TX_ESSID
);
2665 memcpy(ieee
->current_network
.bssid
, ieee
->dev
->dev_addr
, ETH_ALEN
);
2667 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
2668 ieee
->state
= RTLLIB_LINKED
;
2669 ieee
->link_change(ieee
->dev
);
2670 notify_wx_assoc_event(ieee
);
2672 if (ieee
->data_hard_resume
)
2673 ieee
->data_hard_resume(ieee
->dev
);
2675 netif_carrier_on(ieee
->dev
);
2678 void rtllib_start_monitor_mode(struct rtllib_device
*ieee
)
2680 /* reset hardware status */
2682 if (ieee
->data_hard_resume
)
2683 ieee
->data_hard_resume(ieee
->dev
);
2685 netif_carrier_on(ieee
->dev
);
2689 void rtllib_start_ibss_wq(void *data
)
2691 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
2692 struct rtllib_device
, start_ibss_wq
);
2693 /* iwconfig mode ad-hoc will schedule this and return
2694 * on the other hand this will block further iwconfig SET
2695 * operations because of the wx_sem hold.
2696 * Anyway some most set operations set a flag to speed-up
2697 * (abort) this wq (when syncro scanning) before sleeping
2700 if (!ieee
->proto_started
) {
2701 printk(KERN_INFO
"==========oh driver down return\n");
2704 down(&ieee
->wx_sem
);
2706 if (ieee
->current_network
.ssid_len
== 0) {
2707 strcpy(ieee
->current_network
.ssid
, RTLLIB_DEFAULT_TX_ESSID
);
2708 ieee
->current_network
.ssid_len
= strlen(RTLLIB_DEFAULT_TX_ESSID
);
2712 ieee
->state
= RTLLIB_NOLINK
;
2713 ieee
->mode
= IEEE_G
;
2714 /* check if we have this cell in our network list */
2715 rtllib_softmac_check_all_nets(ieee
);
2718 /* if not then the state is not linked. Maybe the user swithced to
2719 * ad-hoc mode just after being in monitor mode, or just after
2720 * being very few time in managed mode (so the card have had no
2721 * time to scan all the chans..) or we have just run up the iface
2722 * after setting ad-hoc mode. So we have to give another try..
2723 * Here, in ibss mode, should be safe to do this without extra care
2724 * (in bss mode we had to make sure no-one tryed to associate when
2725 * we had just checked the ieee->state and we was going to start the
2726 * scan) beacause in ibss mode the rtllib_new_net function, when
2727 * finds a good net, just set the ieee->state to RTLLIB_LINKED,
2728 * so, at worst, we waste a bit of time to initiate an unneeded syncro
2729 * scan, that will stop at the first round because it sees the state
2732 if (ieee
->state
== RTLLIB_NOLINK
)
2733 rtllib_start_scan_syncro(ieee
, 0);
2735 /* the network definitively is not here.. create a new cell */
2736 if (ieee
->state
== RTLLIB_NOLINK
) {
2737 printk(KERN_INFO
"creating new IBSS cell\n");
2738 ieee
->current_network
.channel
= ieee
->IbssStartChnl
;
2740 rtllib_randomize_cell(ieee
);
2742 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
) {
2744 ieee
->current_network
.rates_len
= 4;
2746 ieee
->current_network
.rates
[0] =
2747 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_1MB
;
2748 ieee
->current_network
.rates
[1] =
2749 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_2MB
;
2750 ieee
->current_network
.rates
[2] =
2751 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_5MB
;
2752 ieee
->current_network
.rates
[3] =
2753 RTLLIB_BASIC_RATE_MASK
| RTLLIB_CCK_RATE_11MB
;
2756 ieee
->current_network
.rates_len
= 0;
2758 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
) {
2759 ieee
->current_network
.rates_ex_len
= 8;
2761 ieee
->current_network
.rates_ex
[0] =
2762 RTLLIB_OFDM_RATE_6MB
;
2763 ieee
->current_network
.rates_ex
[1] =
2764 RTLLIB_OFDM_RATE_9MB
;
2765 ieee
->current_network
.rates_ex
[2] =
2766 RTLLIB_OFDM_RATE_12MB
;
2767 ieee
->current_network
.rates_ex
[3] =
2768 RTLLIB_OFDM_RATE_18MB
;
2769 ieee
->current_network
.rates_ex
[4] =
2770 RTLLIB_OFDM_RATE_24MB
;
2771 ieee
->current_network
.rates_ex
[5] =
2772 RTLLIB_OFDM_RATE_36MB
;
2773 ieee
->current_network
.rates_ex
[6] =
2774 RTLLIB_OFDM_RATE_48MB
;
2775 ieee
->current_network
.rates_ex
[7] =
2776 RTLLIB_OFDM_RATE_54MB
;
2780 ieee
->current_network
.rates_ex_len
= 0;
2784 ieee
->current_network
.qos_data
.supported
= 0;
2785 ieee
->SetWirelessMode(ieee
->dev
, IEEE_G
);
2786 ieee
->current_network
.mode
= ieee
->mode
;
2787 ieee
->current_network
.atim_window
= 0;
2788 ieee
->current_network
.capability
= WLAN_CAPABILITY_IBSS
;
2791 printk(KERN_INFO
"%s(): ieee->mode = %d\n", __func__
, ieee
->mode
);
2792 if ((ieee
->mode
== IEEE_N_24G
) || (ieee
->mode
== IEEE_N_5G
))
2793 HTUseDefaultSetting(ieee
);
2795 ieee
->pHTInfo
->bCurrentHTSupport
= false;
2797 ieee
->SetHwRegHandler(ieee
->dev
, HW_VAR_MEDIA_STATUS
,
2798 (u8
*)(&ieee
->state
));
2800 ieee
->state
= RTLLIB_LINKED
;
2801 ieee
->link_change(ieee
->dev
);
2803 HTSetConnectBwMode(ieee
, HT_CHANNEL_WIDTH_20
, HT_EXTCHNL_OFFSET_NO_EXT
);
2804 if (ieee
->LedControlHandler
!= NULL
)
2805 ieee
->LedControlHandler(ieee
->dev
, LED_CTL_LINK
);
2807 rtllib_start_send_beacons(ieee
);
2809 notify_wx_assoc_event(ieee
);
2811 if (ieee
->data_hard_resume
)
2812 ieee
->data_hard_resume(ieee
->dev
);
2814 netif_carrier_on(ieee
->dev
);
2819 inline void rtllib_start_ibss(struct rtllib_device
*ieee
)
2821 queue_delayed_work_rsl(ieee
->wq
, &ieee
->start_ibss_wq
, MSECS(150));
2824 /* this is called only in user context, with wx_sem held */
2825 void rtllib_start_bss(struct rtllib_device
*ieee
)
2827 unsigned long flags
;
2828 if (IS_DOT11D_ENABLE(ieee
) && !IS_COUNTRY_IE_VALID(ieee
)) {
2829 if (!ieee
->bGlobalDomain
)
2832 /* check if we have already found the net we
2833 * are interested in (if any).
2834 * if not (we are disassociated and we are not
2835 * in associating / authenticating phase) start the background scanning.
2837 rtllib_softmac_check_all_nets(ieee
);
2839 /* ensure no-one start an associating process (thus setting
2840 * the ieee->state to rtllib_ASSOCIATING) while we
2841 * have just cheked it and we are going to enable scan.
2842 * The rtllib_new_net function is always called with
2843 * lock held (from both rtllib_softmac_check_all_nets and
2844 * the rx path), so we cannot be in the middle of such function
2846 spin_lock_irqsave(&ieee
->lock
, flags
);
2848 if (ieee
->state
== RTLLIB_NOLINK
)
2849 rtllib_start_scan(ieee
);
2850 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2853 void rtllib_link_change_wq(void *data
)
2855 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
2856 struct rtllib_device
, link_change_wq
);
2857 ieee
->link_change(ieee
->dev
);
2859 /* called only in userspace context */
2860 void rtllib_disassociate(struct rtllib_device
*ieee
)
2862 netif_carrier_off(ieee
->dev
);
2863 if (ieee
->softmac_features
& IEEE_SOFTMAC_TX_QUEUE
)
2864 rtllib_reset_queue(ieee
);
2866 if (ieee
->data_hard_stop
)
2867 ieee
->data_hard_stop(ieee
->dev
);
2868 if (IS_DOT11D_ENABLE(ieee
))
2870 ieee
->state
= RTLLIB_NOLINK
;
2871 ieee
->is_set_key
= false;
2874 queue_delayed_work_rsl(ieee
->wq
, &ieee
->link_change_wq
, 0);
2876 notify_wx_assoc_event(ieee
);
2879 void rtllib_associate_retry_wq(void *data
)
2881 struct rtllib_device
*ieee
= container_of_dwork_rsl(data
,
2882 struct rtllib_device
, associate_retry_wq
);
2883 unsigned long flags
;
2885 down(&ieee
->wx_sem
);
2886 if (!ieee
->proto_started
)
2889 if (ieee
->state
!= RTLLIB_ASSOCIATING_RETRY
)
2892 /* until we do not set the state to RTLLIB_NOLINK
2893 * there are no possibility to have someone else trying
2894 * to start an association procdure (we get here with
2895 * ieee->state = RTLLIB_ASSOCIATING).
2896 * When we set the state to RTLLIB_NOLINK it is possible
2897 * that the RX path run an attempt to associate, but
2898 * both rtllib_softmac_check_all_nets and the
2899 * RX path works with ieee->lock held so there are no
2900 * problems. If we are still disassociated then start a scan.
2901 * the lock here is necessary to ensure no one try to start
2902 * an association procedure when we have just checked the
2903 * state and we are going to start the scan.
2905 ieee
->beinretry
= true;
2906 ieee
->state
= RTLLIB_NOLINK
;
2908 rtllib_softmac_check_all_nets(ieee
);
2910 spin_lock_irqsave(&ieee
->lock
, flags
);
2912 if (ieee
->state
== RTLLIB_NOLINK
)
2913 rtllib_start_scan(ieee
);
2914 spin_unlock_irqrestore(&ieee
->lock
, flags
);
2916 ieee
->beinretry
= false;
2921 struct sk_buff
*rtllib_get_beacon_(struct rtllib_device
*ieee
)
2923 u8 broadcast_addr
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2925 struct sk_buff
*skb
;
2926 struct rtllib_probe_response
*b
;
2927 skb
= rtllib_probe_resp(ieee
, broadcast_addr
);
2932 b
= (struct rtllib_probe_response
*) skb
->data
;
2933 b
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_BEACON
);
2939 struct sk_buff
*rtllib_get_beacon(struct rtllib_device
*ieee
)
2941 struct sk_buff
*skb
;
2942 struct rtllib_probe_response
*b
;
2944 skb
= rtllib_get_beacon_(ieee
);
2948 b
= (struct rtllib_probe_response
*) skb
->data
;
2949 b
->header
.seq_ctl
= cpu_to_le16(ieee
->seq_ctrl
[0] << 4);
2951 if (ieee
->seq_ctrl
[0] == 0xFFF)
2952 ieee
->seq_ctrl
[0] = 0;
2954 ieee
->seq_ctrl
[0]++;
2959 void rtllib_softmac_stop_protocol(struct rtllib_device
*ieee
, u8 mesh_flag
,
2962 rtllib_stop_scan_syncro(ieee
);
2963 down(&ieee
->wx_sem
);
2964 rtllib_stop_protocol(ieee
, shutdown
);
2969 void rtllib_stop_protocol(struct rtllib_device
*ieee
, u8 shutdown
)
2971 if (!ieee
->proto_started
)
2975 ieee
->proto_started
= 0;
2976 ieee
->proto_stoppping
= 1;
2977 if (ieee
->rtllib_ips_leave
!= NULL
)
2978 ieee
->rtllib_ips_leave(ieee
->dev
);
2981 rtllib_stop_send_beacons(ieee
);
2982 del_timer_sync(&ieee
->associate_timer
);
2983 cancel_delayed_work(&ieee
->associate_retry_wq
);
2984 cancel_delayed_work(&ieee
->start_ibss_wq
);
2985 cancel_delayed_work(&ieee
->link_change_wq
);
2986 rtllib_stop_scan(ieee
);
2988 if (ieee
->state
<= RTLLIB_ASSOCIATING_AUTHENTICATED
)
2989 ieee
->state
= RTLLIB_NOLINK
;
2991 if (ieee
->state
== RTLLIB_LINKED
) {
2992 if (ieee
->iw_mode
== IW_MODE_INFRA
)
2993 SendDisassociation(ieee
, 1, deauth_lv_ss
);
2994 rtllib_disassociate(ieee
);
2999 ieee
->proto_stoppping
= 0;
3001 kfree(ieee
->assocreq_ies
);
3002 ieee
->assocreq_ies
= NULL
;
3003 ieee
->assocreq_ies_len
= 0;
3004 kfree(ieee
->assocresp_ies
);
3005 ieee
->assocresp_ies
= NULL
;
3006 ieee
->assocresp_ies_len
= 0;
3009 void rtllib_softmac_start_protocol(struct rtllib_device
*ieee
, u8 mesh_flag
)
3011 down(&ieee
->wx_sem
);
3012 rtllib_start_protocol(ieee
);
3016 void rtllib_start_protocol(struct rtllib_device
*ieee
)
3021 rtllib_update_active_chan_map(ieee
);
3023 if (ieee
->proto_started
)
3026 ieee
->proto_started
= 1;
3028 if (ieee
->current_network
.channel
== 0) {
3031 if (ch
> MAX_CHANNEL_NUMBER
)
3032 return; /* no channel found */
3033 } while (!ieee
->active_channel_map
[ch
]);
3034 ieee
->current_network
.channel
= ch
;
3037 if (ieee
->current_network
.beacon_interval
== 0)
3038 ieee
->current_network
.beacon_interval
= 100;
3040 for (i
= 0; i
< 17; i
++) {
3041 ieee
->last_rxseq_num
[i
] = -1;
3042 ieee
->last_rxfrag_num
[i
] = -1;
3043 ieee
->last_packet_time
[i
] = 0;
3046 if (ieee
->UpdateBeaconInterruptHandler
)
3047 ieee
->UpdateBeaconInterruptHandler(ieee
->dev
, false);
3050 /* if the user set the MAC of the ad-hoc cell and then
3051 * switch to managed mode, shall we make sure that association
3052 * attempts does not fail just because the user provide the essid
3053 * and the nic is still checking for the AP MAC ??
3055 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
3056 rtllib_start_bss(ieee
);
3057 } else if (ieee
->iw_mode
== IW_MODE_ADHOC
) {
3058 if (ieee
->UpdateBeaconInterruptHandler
)
3059 ieee
->UpdateBeaconInterruptHandler(ieee
->dev
, true);
3061 rtllib_start_ibss(ieee
);
3063 } else if (ieee
->iw_mode
== IW_MODE_MASTER
) {
3064 rtllib_start_master_bss(ieee
);
3065 } else if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
3066 rtllib_start_monitor_mode(ieee
);
3070 void rtllib_softmac_init(struct rtllib_device
*ieee
)
3073 memset(&ieee
->current_network
, 0, sizeof(struct rtllib_network
));
3075 ieee
->state
= RTLLIB_NOLINK
;
3076 for (i
= 0; i
< 5; i
++)
3077 ieee
->seq_ctrl
[i
] = 0;
3078 ieee
->pDot11dInfo
= kmalloc(sizeof(struct rt_dot11d_info
), GFP_ATOMIC
);
3079 if (!ieee
->pDot11dInfo
)
3080 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "can't alloc memory for DOT11D\n");
3081 memset(ieee
->pDot11dInfo
, 0, sizeof(struct rt_dot11d_info
));
3082 ieee
->LinkDetectInfo
.SlotIndex
= 0;
3083 ieee
->LinkDetectInfo
.SlotNum
= 2;
3084 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
= 0;
3085 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
= 0;
3086 ieee
->LinkDetectInfo
.NumTxOkInPeriod
= 0;
3087 ieee
->LinkDetectInfo
.NumRxOkInPeriod
= 0;
3088 ieee
->LinkDetectInfo
.NumRxUnicastOkInPeriod
= 0;
3089 ieee
->bIsAggregateFrame
= false;
3091 ieee
->queue_stop
= 0;
3092 ieee
->scanning_continue
= 0;
3093 ieee
->softmac_features
= 0;
3096 ieee
->proto_started
= 0;
3097 ieee
->proto_stoppping
= 0;
3098 ieee
->basic_rate
= RTLLIB_DEFAULT_BASIC_RATE
;
3100 ieee
->ps
= RTLLIB_PS_DISABLED
;
3101 ieee
->sta_sleep
= LPS_IS_WAKE
;
3103 ieee
->Regdot11HTOperationalRateSet
[0] = 0xff;
3104 ieee
->Regdot11HTOperationalRateSet
[1] = 0xff;
3105 ieee
->Regdot11HTOperationalRateSet
[4] = 0x01;
3107 ieee
->Regdot11TxHTOperationalRateSet
[0] = 0xff;
3108 ieee
->Regdot11TxHTOperationalRateSet
[1] = 0xff;
3109 ieee
->Regdot11TxHTOperationalRateSet
[4] = 0x01;
3111 ieee
->FirstIe_InScan
= false;
3112 ieee
->actscanning
= false;
3113 ieee
->beinretry
= false;
3114 ieee
->is_set_key
= false;
3115 init_mgmt_queue(ieee
);
3117 ieee
->sta_edca_param
[0] = 0x0000A403;
3118 ieee
->sta_edca_param
[1] = 0x0000A427;
3119 ieee
->sta_edca_param
[2] = 0x005E4342;
3120 ieee
->sta_edca_param
[3] = 0x002F3262;
3121 ieee
->aggregation
= true;
3122 ieee
->enable_rx_imm_BA
= 1;
3123 ieee
->tx_pending
.txb
= NULL
;
3125 _setup_timer(&ieee
->associate_timer
,
3126 rtllib_associate_abort_cb
,
3127 (unsigned long) ieee
);
3129 _setup_timer(&ieee
->beacon_timer
,
3130 rtllib_send_beacon_cb
,
3131 (unsigned long) ieee
);
3134 ieee
->wq
= create_workqueue(DRV_NAME
);
3136 INIT_DELAYED_WORK_RSL(&ieee
->link_change_wq
,
3137 (void *)rtllib_link_change_wq
, ieee
);
3138 INIT_DELAYED_WORK_RSL(&ieee
->start_ibss_wq
,
3139 (void *)rtllib_start_ibss_wq
, ieee
);
3140 INIT_WORK_RSL(&ieee
->associate_complete_wq
,
3141 (void *)rtllib_associate_complete_wq
, ieee
);
3142 INIT_DELAYED_WORK_RSL(&ieee
->associate_procedure_wq
,
3143 (void *)rtllib_associate_procedure_wq
, ieee
);
3144 INIT_DELAYED_WORK_RSL(&ieee
->softmac_scan_wq
,
3145 (void *)rtllib_softmac_scan_wq
, ieee
);
3146 INIT_DELAYED_WORK_RSL(&ieee
->softmac_hint11d_wq
,
3147 (void *)rtllib_softmac_hint11d_wq
, ieee
);
3148 INIT_DELAYED_WORK_RSL(&ieee
->associate_retry_wq
,
3149 (void *)rtllib_associate_retry_wq
, ieee
);
3150 INIT_WORK_RSL(&ieee
->wx_sync_scan_wq
, (void *)rtllib_wx_sync_scan_wq
,
3153 sema_init(&ieee
->wx_sem
, 1);
3154 sema_init(&ieee
->scan_sem
, 1);
3155 sema_init(&ieee
->ips_sem
, 1);
3157 spin_lock_init(&ieee
->mgmt_tx_lock
);
3158 spin_lock_init(&ieee
->beacon_lock
);
3160 tasklet_init(&ieee
->ps_task
,
3161 (void(*)(unsigned long)) rtllib_sta_ps
,
3162 (unsigned long)ieee
);
3166 void rtllib_softmac_free(struct rtllib_device
*ieee
)
3168 down(&ieee
->wx_sem
);
3169 if (NULL
!= ieee
->pDot11dInfo
) {
3170 kfree(ieee
->pDot11dInfo
);
3171 ieee
->pDot11dInfo
= NULL
;
3173 del_timer_sync(&ieee
->associate_timer
);
3175 cancel_delayed_work(&ieee
->associate_retry_wq
);
3176 destroy_workqueue(ieee
->wq
);
3180 /********************************************************
3181 * Start of WPA code. *
3182 * this is stolen from the ipw2200 driver *
3183 ********************************************************/
3186 static int rtllib_wpa_enable(struct rtllib_device
*ieee
, int value
)
3188 /* This is called when wpa_supplicant loads and closes the driver
3190 printk(KERN_INFO
"%s WPA\n", value
? "enabling" : "disabling");
3191 ieee
->wpa_enabled
= value
;
3192 memset(ieee
->ap_mac_addr
, 0, 6);
3197 void rtllib_wpa_assoc_frame(struct rtllib_device
*ieee
, char *wpa_ie
,
3200 /* make sure WPA is enabled */
3201 rtllib_wpa_enable(ieee
, 1);
3203 rtllib_disassociate(ieee
);
3207 static int rtllib_wpa_mlme(struct rtllib_device
*ieee
, int command
, int reason
)
3213 case IEEE_MLME_STA_DEAUTH
:
3216 case IEEE_MLME_STA_DISASSOC
:
3217 rtllib_disassociate(ieee
);
3221 printk(KERN_INFO
"Unknown MLME request: %d\n", command
);
3229 static int rtllib_wpa_set_wpa_ie(struct rtllib_device
*ieee
,
3230 struct ieee_param
*param
, int plen
)
3234 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
3235 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
3238 if (param
->u
.wpa_ie
.len
) {
3239 buf
= kmalloc(param
->u
.wpa_ie
.len
, GFP_KERNEL
);
3243 memcpy(buf
, param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
);
3244 kfree(ieee
->wpa_ie
);
3246 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
3248 kfree(ieee
->wpa_ie
);
3249 ieee
->wpa_ie
= NULL
;
3250 ieee
->wpa_ie_len
= 0;
3253 rtllib_wpa_assoc_frame(ieee
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
3257 #define AUTH_ALG_OPEN_SYSTEM 0x1
3258 #define AUTH_ALG_SHARED_KEY 0x2
3259 #define AUTH_ALG_LEAP 0x4
3260 static int rtllib_wpa_set_auth_algs(struct rtllib_device
*ieee
, int value
)
3263 struct rtllib_security sec
= {
3264 .flags
= SEC_AUTH_MODE
,
3268 if (value
& AUTH_ALG_SHARED_KEY
) {
3269 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
3271 ieee
->auth_mode
= 1;
3272 } else if (value
& AUTH_ALG_OPEN_SYSTEM
) {
3273 sec
.auth_mode
= WLAN_AUTH_OPEN
;
3275 ieee
->auth_mode
= 0;
3276 } else if (value
& AUTH_ALG_LEAP
) {
3277 sec
.auth_mode
= WLAN_AUTH_LEAP
>> 6;
3279 ieee
->auth_mode
= 2;
3283 if (ieee
->set_security
)
3284 ieee
->set_security(ieee
->dev
, &sec
);
3289 static int rtllib_wpa_set_param(struct rtllib_device
*ieee
, u8 name
, u32 value
)
3292 unsigned long flags
;
3295 case IEEE_PARAM_WPA_ENABLED
:
3296 ret
= rtllib_wpa_enable(ieee
, value
);
3299 case IEEE_PARAM_TKIP_COUNTERMEASURES
:
3300 ieee
->tkip_countermeasures
= value
;
3303 case IEEE_PARAM_DROP_UNENCRYPTED
:
3307 * wpa_supplicant calls set_wpa_enabled when the driver
3308 * is loaded and unloaded, regardless of if WPA is being
3309 * used. No other calls are made which can be used to
3310 * determine if encryption will be used or not prior to
3311 * association being expected. If encryption is not being
3312 * used, drop_unencrypted is set to false, else true -- we
3313 * can use this to determine if the CAP_PRIVACY_ON bit should
3316 struct rtllib_security sec
= {
3317 .flags
= SEC_ENABLED
,
3320 ieee
->drop_unencrypted
= value
;
3321 /* We only change SEC_LEVEL for open mode. Others
3322 * are set by ipw_wpa_set_encryption.
3325 sec
.flags
|= SEC_LEVEL
;
3326 sec
.level
= SEC_LEVEL_0
;
3328 sec
.flags
|= SEC_LEVEL
;
3329 sec
.level
= SEC_LEVEL_1
;
3331 if (ieee
->set_security
)
3332 ieee
->set_security(ieee
->dev
, &sec
);
3336 case IEEE_PARAM_PRIVACY_INVOKED
:
3337 ieee
->privacy_invoked
= value
;
3340 case IEEE_PARAM_AUTH_ALGS
:
3341 ret
= rtllib_wpa_set_auth_algs(ieee
, value
);
3344 case IEEE_PARAM_IEEE_802_1X
:
3345 ieee
->ieee802_1x
= value
;
3347 case IEEE_PARAM_WPAX_SELECT
:
3348 spin_lock_irqsave(&ieee
->wpax_suitlist_lock
, flags
);
3349 spin_unlock_irqrestore(&ieee
->wpax_suitlist_lock
, flags
);
3353 printk(KERN_INFO
"Unknown WPA param: %d\n", name
);
3360 /* implementation borrowed from hostap driver */
3361 static int rtllib_wpa_set_encryption(struct rtllib_device
*ieee
,
3362 struct ieee_param
*param
, int param_len
,
3366 struct rtllib_crypto_ops
*ops
;
3367 struct rtllib_crypt_data
**crypt
;
3369 struct rtllib_security sec
= {
3373 param
->u
.crypt
.err
= 0;
3374 param
->u
.crypt
.alg
[IEEE_CRYPT_ALG_NAME_LEN
- 1] = '\0';
3377 (int) ((char *) param
->u
.crypt
.key
- (char *) param
) +
3378 param
->u
.crypt
.key_len
) {
3379 printk(KERN_INFO
"Len mismatch %d, %d\n", param_len
,
3380 param
->u
.crypt
.key_len
);
3383 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
3384 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
3385 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
3386 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
3388 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
3393 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
3396 sec
.level
= SEC_LEVEL_0
;
3397 sec
.flags
|= SEC_ENABLED
| SEC_LEVEL
;
3398 rtllib_crypt_delayed_deinit(ieee
, crypt
);
3403 sec
.flags
|= SEC_ENABLED
;
3405 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
3406 if (!(ieee
->host_encrypt
|| ieee
->host_decrypt
) &&
3407 strcmp(param
->u
.crypt
.alg
, "TKIP"))
3408 goto skip_host_crypt
;
3410 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3411 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
3412 request_module("rtllib_crypt_wep");
3413 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3414 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
3415 request_module("rtllib_crypt_tkip");
3416 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3417 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
3418 request_module("rtllib_crypt_ccmp");
3419 ops
= rtllib_get_crypto_ops(param
->u
.crypt
.alg
);
3422 printk(KERN_INFO
"unknown crypto alg '%s'\n",
3423 param
->u
.crypt
.alg
);
3424 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_UNKNOWN_ALG
;
3428 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
3429 struct rtllib_crypt_data
*new_crypt
;
3431 rtllib_crypt_delayed_deinit(ieee
, crypt
);
3433 new_crypt
= (struct rtllib_crypt_data
*)
3434 kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
3435 if (new_crypt
== NULL
) {
3439 memset(new_crypt
, 0, sizeof(struct rtllib_crypt_data
));
3440 new_crypt
->ops
= ops
;
3443 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
3445 if (new_crypt
->priv
== NULL
) {
3447 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CRYPT_INIT_FAILED
;
3455 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
3456 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
3457 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
3458 (*crypt
)->priv
) < 0) {
3459 printk(KERN_INFO
"key setting failed\n");
3460 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_KEY_SET_FAILED
;
3466 if (param
->u
.crypt
.set_tx
) {
3467 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
3468 sec
.active_key
= param
->u
.crypt
.idx
;
3469 sec
.flags
|= SEC_ACTIVE_KEY
;
3471 sec
.flags
&= ~SEC_ACTIVE_KEY
;
3473 if (param
->u
.crypt
.alg
!= NULL
) {
3474 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
3476 param
->u
.crypt
.key_len
);
3477 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
3478 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
3480 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
3481 sec
.flags
|= SEC_LEVEL
;
3482 sec
.level
= SEC_LEVEL_1
;
3483 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
3484 sec
.flags
|= SEC_LEVEL
;
3485 sec
.level
= SEC_LEVEL_2
;
3486 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
3487 sec
.flags
|= SEC_LEVEL
;
3488 sec
.level
= SEC_LEVEL_3
;
3492 if (ieee
->set_security
)
3493 ieee
->set_security(ieee
->dev
, &sec
);
3495 /* Do not reset port if card is in Managed mode since resetting will
3496 * generate new IEEE 802.11 authentication which may end up in looping
3497 * with IEEE 802.1X. If your hardware requires a reset after WEP
3498 * configuration (for example... Prism2), implement the reset_port in
3499 * the callbacks structures used to initialize the 802.11 stack. */
3500 if (ieee
->reset_on_keychange
&&
3501 ieee
->iw_mode
!= IW_MODE_INFRA
&&
3503 ieee
->reset_port(ieee
->dev
)) {
3504 printk(KERN_INFO
"reset_port failed\n");
3505 param
->u
.crypt
.err
= IEEE_CRYPT_ERR_CARD_CONF_FAILED
;
3512 inline struct sk_buff
*rtllib_disauth_skb(struct rtllib_network
*beacon
,
3513 struct rtllib_device
*ieee
, u16 asRsn
)
3515 struct sk_buff
*skb
;
3516 struct rtllib_disauth
*disauth
;
3517 int len
= sizeof(struct rtllib_disauth
) + ieee
->tx_headroom
;
3519 skb
= dev_alloc_skb(len
);
3523 skb_reserve(skb
, ieee
->tx_headroom
);
3525 disauth
= (struct rtllib_disauth
*) skb_put(skb
,
3526 sizeof(struct rtllib_disauth
));
3527 disauth
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_DEAUTH
);
3528 disauth
->header
.duration_id
= 0;
3530 memcpy(disauth
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
3531 memcpy(disauth
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
3532 memcpy(disauth
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
3534 disauth
->reason
= cpu_to_le16(asRsn
);
3538 inline struct sk_buff
*rtllib_disassociate_skb(struct rtllib_network
*beacon
,
3539 struct rtllib_device
*ieee
, u16 asRsn
)
3541 struct sk_buff
*skb
;
3542 struct rtllib_disassoc
*disass
;
3543 int len
= sizeof(struct rtllib_disassoc
) + ieee
->tx_headroom
;
3544 skb
= dev_alloc_skb(len
);
3549 skb_reserve(skb
, ieee
->tx_headroom
);
3551 disass
= (struct rtllib_disassoc
*) skb_put(skb
,
3552 sizeof(struct rtllib_disassoc
));
3553 disass
->header
.frame_ctl
= cpu_to_le16(RTLLIB_STYPE_DISASSOC
);
3554 disass
->header
.duration_id
= 0;
3556 memcpy(disass
->header
.addr1
, beacon
->bssid
, ETH_ALEN
);
3557 memcpy(disass
->header
.addr2
, ieee
->dev
->dev_addr
, ETH_ALEN
);
3558 memcpy(disass
->header
.addr3
, beacon
->bssid
, ETH_ALEN
);
3560 disass
->reason
= cpu_to_le16(asRsn
);
3564 void SendDisassociation(struct rtllib_device
*ieee
, bool deauth
, u16 asRsn
)
3566 struct rtllib_network
*beacon
= &ieee
->current_network
;
3567 struct sk_buff
*skb
;
3570 skb
= rtllib_disauth_skb(beacon
, ieee
, asRsn
);
3572 skb
= rtllib_disassociate_skb(beacon
, ieee
, asRsn
);
3575 softmac_mgmt_xmit(skb
, ieee
);
3578 u8
rtllib_ap_sec_type(struct rtllib_device
*ieee
)
3580 static u8 ccmp_ie
[4] = {0x00, 0x50, 0xf2, 0x04};
3581 static u8 ccmp_rsn_ie
[4] = {0x00, 0x0f, 0xac, 0x04};
3582 int wpa_ie_len
= ieee
->wpa_ie_len
;
3583 struct rtllib_crypt_data
*crypt
;
3586 crypt
= ieee
->crypt
[ieee
->tx_keyidx
];
3587 encrypt
= (ieee
->current_network
.capability
& WLAN_CAPABILITY_PRIVACY
)
3588 || (ieee
->host_encrypt
&& crypt
&& crypt
->ops
&&
3589 (0 == strcmp(crypt
->ops
->name
, "WEP")));
3592 if (encrypt
&& (wpa_ie_len
== 0)) {
3594 } else if ((wpa_ie_len
!= 0)) {
3595 if (((ieee
->wpa_ie
[0] == 0xdd) &&
3596 (!memcmp(&(ieee
->wpa_ie
[14]), ccmp_ie
, 4))) ||
3597 ((ieee
->wpa_ie
[0] == 0x30) &&
3598 (!memcmp(&ieee
->wpa_ie
[10], ccmp_rsn_ie
, 4))))
3599 return SEC_ALG_CCMP
;
3601 return SEC_ALG_TKIP
;
3603 return SEC_ALG_NONE
;
3607 int rtllib_wpa_supplicant_ioctl(struct rtllib_device
*ieee
, struct iw_point
*p
,
3610 struct ieee_param
*param
;
3613 down(&ieee
->wx_sem
);
3615 if (p
->length
< sizeof(struct ieee_param
) || !p
->pointer
) {
3620 param
= kmalloc(p
->length
, GFP_KERNEL
);
3621 if (param
== NULL
) {
3625 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
3631 switch (param
->cmd
) {
3632 case IEEE_CMD_SET_WPA_PARAM
:
3633 ret
= rtllib_wpa_set_param(ieee
, param
->u
.wpa_param
.name
,
3634 param
->u
.wpa_param
.value
);
3637 case IEEE_CMD_SET_WPA_IE
:
3638 ret
= rtllib_wpa_set_wpa_ie(ieee
, param
, p
->length
);
3641 case IEEE_CMD_SET_ENCRYPTION
:
3642 ret
= rtllib_wpa_set_encryption(ieee
, param
, p
->length
, 0);
3646 ret
= rtllib_wpa_mlme(ieee
, param
->u
.mlme
.command
,
3647 param
->u
.mlme
.reason_code
);
3651 printk(KERN_INFO
"Unknown WPA supplicant request: %d\n",
3657 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
3667 void rtllib_MgntDisconnectIBSS(struct rtllib_device
*rtllib
)
3671 bool bFilterOutNonAssociatedBSSID
= false;
3673 rtllib
->state
= RTLLIB_NOLINK
;
3675 for (i
= 0; i
< 6; i
++)
3676 rtllib
->current_network
.bssid
[i
] = 0x55;
3678 rtllib
->OpMode
= RT_OP_MODE_NO_LINK
;
3679 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_BSSID
,
3680 rtllib
->current_network
.bssid
);
3681 OpMode
= RT_OP_MODE_NO_LINK
;
3682 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_MEDIA_STATUS
, &OpMode
);
3683 rtllib_stop_send_beacons(rtllib
);
3685 bFilterOutNonAssociatedBSSID
= false;
3686 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_CECHK_BSSID
,
3687 (u8
*)(&bFilterOutNonAssociatedBSSID
));
3688 notify_wx_assoc_event(rtllib
);
3692 void rtllib_MlmeDisassociateRequest(struct rtllib_device
*rtllib
, u8
*asSta
,
3698 RemovePeerTS(rtllib
, asSta
);
3701 if (memcpy(rtllib
->current_network
.bssid
, asSta
, 6) == 0) {
3702 rtllib
->state
= RTLLIB_NOLINK
;
3704 for (i
= 0; i
< 6; i
++)
3705 rtllib
->current_network
.bssid
[i
] = 0x22;
3706 OpMode
= RT_OP_MODE_NO_LINK
;
3707 rtllib
->OpMode
= RT_OP_MODE_NO_LINK
;
3708 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_MEDIA_STATUS
,
3710 rtllib_disassociate(rtllib
);
3712 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_BSSID
,
3713 rtllib
->current_network
.bssid
);
3720 rtllib_MgntDisconnectAP(
3721 struct rtllib_device
*rtllib
,
3725 bool bFilterOutNonAssociatedBSSID
= false;
3727 bFilterOutNonAssociatedBSSID
= false;
3728 rtllib
->SetHwRegHandler(rtllib
->dev
, HW_VAR_CECHK_BSSID
,
3729 (u8
*)(&bFilterOutNonAssociatedBSSID
));
3730 rtllib_MlmeDisassociateRequest(rtllib
, rtllib
->current_network
.bssid
,
3733 rtllib
->state
= RTLLIB_NOLINK
;
3736 bool rtllib_MgntDisconnect(struct rtllib_device
*rtllib
, u8 asRsn
)
3738 if (rtllib
->ps
!= RTLLIB_PS_DISABLED
)
3739 rtllib
->sta_wake_up(rtllib
->dev
);
3741 if (rtllib
->state
== RTLLIB_LINKED
) {
3742 if (rtllib
->iw_mode
== IW_MODE_ADHOC
)
3743 rtllib_MgntDisconnectIBSS(rtllib
);
3744 if (rtllib
->iw_mode
== IW_MODE_INFRA
)
3745 rtllib_MgntDisconnectAP(rtllib
, asRsn
);
3752 void notify_wx_assoc_event(struct rtllib_device
*ieee
)
3754 union iwreq_data wrqu
;
3756 if (ieee
->cannot_notify
)
3759 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3760 if (ieee
->state
== RTLLIB_LINKED
)
3761 memcpy(wrqu
.ap_addr
.sa_data
, ieee
->current_network
.bssid
,
3765 printk(KERN_INFO
"%s(): Tell user space disconnected\n",
3767 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
3769 wireless_send_event(ieee
->dev
, SIOCGIWAP
, &wrqu
, NULL
);