8 extern zd_80211Obj_t dot11Obj
;
11 extern u8 OfdmRateTbl_11A
[12];
13 extern u8 OfdmRateTbl
[12];
33 case RATE_1M
: /* 1M bps */
34 *(pLenInUs
) = Len
<< 3;
37 case RATE_2M
: /* 2M bps */
38 *(pLenInUs
) = Len
<< 2;
41 case RATE_5M
: /* 5.5M bps */
42 *(pLenInUs
) = (u16
)(((u32
)Len
<< 4)/11);
43 Remainder
= (((u32
)Len
<< 4) % 11);
49 case RATE_11M
: /* 11M bps */
50 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/11);
51 Remainder
= (((u32
)Len
<< 3) % 11);
52 Delta
= 11 - Remainder
;
61 #if !(defined(GCCK) && defined(OFDM))
62 case RATE_16M
: // 16.5M bps
63 *(pLenInUs
) = (u16
)(((u32
)Len
<< 4)/33);
64 Remainder
= (((u32
)Len
<< 4) % 33);
65 Delta
= 33 - Remainder
;
70 else if ( (Delta
>= 16) && (Delta
< 32) ){
73 else if ( Delta
>= 32 ){
79 case RATE_22M
: // 22M bps
80 *(pLenInUs
) = (u16
)(((u32
)Len
<< 2)/11);
81 Remainder
= (((u32
)Len
<< 2) % 11);
82 Delta
= 11 - Remainder
;
87 else if ( (Delta
>= 4) && (Delta
< 8) ){
90 else if ( Delta
>= 8 ){
98 case RATE_27M
: // 27.5 bps
99 *(pLenInUs
) = (u16
)(((u32
)Len
<< 4)/55);
100 Remainder
= (((u32
)Len
<< 4) % 55);
101 Delta
= 55 - Remainder
;
106 else if ( (Delta
>= 16) && (Delta
< 32) ){
107 *(pService
) |= BIT_7
;
111 else if ( (Delta
>= 32) && (Delta
< 48) ){
112 *(pService
) |= BIT_6
;
114 else if ( Delta
>= 48 ){
115 *(pService
) |= (BIT_6
| BIT_7
);
120 case RATE_33M
: // 33M bps
121 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/33);
122 Remainder
= (((u32
)Len
<< 3) % 33);
123 Delta
= 33 - Remainder
;
128 else if ( (Delta
>= 8) && (Delta
< 16) ){
129 *(pService
) |= BIT_7
;
131 else if ( (Delta
>= 16) && (Delta
< 24) ){
132 *(pService
) |= BIT_6
;
134 else if ( (Delta
>= 24) && (Delta
< 32) ){
135 *(pService
) |= (BIT_6
| BIT_7
);
137 else if ( Delta
>= 32 ){
138 *(pService
) |= BIT_5
;
143 case RATE_38M
: // 38.5M bps
144 *(pLenInUs
) = (u16
)(((u32
)Len
<< 4)/77);
145 Remainder
= (((u32
)Len
<< 4) % 77);
146 Delta
= 77 - Remainder
;
151 else if ( (Delta
>= 16) && (Delta
< 32) ){
152 *(pService
) |= BIT_7
;
156 else if ( (Delta
>= 32) && (Delta
< 48) ){
157 *(pService
) |= BIT_6
;
159 else if ( (Delta
>= 48) && (Delta
< 64) ){
160 *(pService
) |= (BIT_6
| BIT_7
);
162 else if ( Delta
>= 64){
163 *(pService
) |= BIT_5
;
168 case RATE_44M
: // 44M bps
169 *(pLenInUs
) = (u16
)(((u32
)Len
<< 1)/11);
170 Remainder
= (((u32
)Len
<< 1) % 11);
171 Delta
= 11 - Remainder
;
176 else if ( (Delta
>= 2) && (Delta
< 4) ){
177 *(pService
) |= BIT_7
;
179 else if ( (Delta
>= 4) && (Delta
< 6) ){
180 *(pService
) |= BIT_6
;
182 else if ( (Delta
>= 6) && (Delta
< 8) ){
183 *(pService
) |= (BIT_6
| BIT_7
);
185 else if ( (Delta
>= 8) && (Delta
< 10) ){
186 *(pService
) |= BIT_5
;
188 else if ( Delta
>= 10 ){
189 *(pService
) |= (BIT_5
| BIT_7
);
194 case RATE_49M
: // 49.5M bps
195 *(pLenInUs
) = (u16
)(((u32
)Len
<< 4)/99);
196 Remainder
= (((u32
)Len
<< 4) % 99);
197 Delta
= 99 - Remainder
;
202 else if ( (Delta
>= 16) && (Delta
< 32) ){
203 *(pService
) |= BIT_7
;
205 else if ( (Delta
>= 32) && (Delta
< 48) ){
206 *(pService
) |= BIT_6
;
208 else if ( (Delta
>= 48) && (Delta
< 64) ){
209 *(pService
) |= (BIT_6
| BIT_7
);
213 else if ( (Delta
>= 64) && (Delta
< 80) ){
214 *(pService
) |= BIT_5
;
216 else if ( (Delta
>= 80) && (Delta
< 96) ){
217 *(pService
) |= (BIT_5
| BIT_7
);
219 else if ( Delta
>= 96 ){
220 *(pService
) |= (BIT_5
| BIT_6
);
225 case RATE_55M
: // 55M bps
226 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/55);
227 Remainder
= (((u32
)Len
<< 3) % 55);
228 Delta
= 55 - Remainder
;
233 else if ( (Delta
>= 8) && (Delta
< 16) ){
234 *(pService
) |= BIT_7
;
236 else if ( (Delta
>= 16) && (Delta
< 24) ){
237 *(pService
) |= BIT_6
;
239 else if ( (Delta
>= 24) && (Delta
< 32) ){
240 *(pService
) |= (BIT_6
| BIT_7
);
242 else if ( (Delta
>= 32) && (Delta
< 40) ){
243 *(pService
) |= BIT_5
;
245 else if ( (Delta
>= 40) && (Delta
< 48) ){
246 *(pService
) |= (BIT_5
| BIT_7
);
248 else if ( Delta
>= 48 ){
249 *(pService
) |= (BIT_5
| BIT_6
);
254 case RATE_60M
: // 60.5M bps
255 *(pLenInUs
) = (u16
)(((u32
)Len
<< 4)/121);
256 Remainder
= (((u32
)Len
<< 4) % 121);
257 Delta
= 121 - Remainder
;
262 else if ( (Delta
>= 16) && (Delta
< 32) ){
263 *(pService
) |= BIT_7
;
265 else if ( (Delta
>= 32) && (Delta
< 48) ){
266 *(pService
) |= BIT_6
;
268 else if ( (Delta
>= 48) && (Delta
< 64) ){
269 *(pService
) |= (BIT_6
| BIT_7
);
271 else if ( (Delta
>= 64) && (Delta
< 80) ){
272 *(pService
) |= BIT_5
;
274 else if ( (Delta
>= 80) && (Delta
< 96) ){
275 *(pService
) |= (BIT_5
| BIT_7
);
277 else if ( (Delta
>= 96) && (Delta
< 112) ){
278 *(pService
) |= (BIT_5
| BIT_6
);
280 else if ( Delta
>= 112 ){
281 *(pService
) |= (BIT_5
| BIT_6
| BIT_7
);
286 case 13: // 8.25M bps
287 *(pLenInUs
) = (u16
)(((u32
)Len
* 32)/33);
288 Remainder
= (((u32
)Len
* 32) % 33);
289 Delta
= 33 - Remainder
;
295 *(pService
) |= BIT_7
;
302 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/6);
306 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/9);
309 case RATE_12M
: // 12M
310 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/12);
313 case RATE_18M
: // 18M
314 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/18);
317 case RATE_24M
: // 24M
318 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/24);
321 case RATE_36M
: // 36M
322 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/36);
326 case RATE_48M
: // 48M
327 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/48);
330 case RATE_54M
: // 54M
331 *(pLenInUs
) = (u16
)(((u32
)Len
<< 3)/54);
336 printk(KERN_ERR
"zd1205: Invalid RF module parameter\n");
341 char DbgStr100
[]="TKIP:";
342 char DbgStr101
[]="CtrlSetting";
343 char DbgStr102
[]="EncryType";
345 __inline
unsigned long
347 struct zd1205_private
*macp
,
348 zd1205_SwTcb_t
*pSwTcb
,
349 wla_Header_t
*pWlaHdr
,
350 ctrl_Set_parm_t
*pSetParms
353 zd1205_Ctrl_Set_t
*pCtrlSet
= pSwTcb
->pHwCtrlPtr
;
361 u8 Rate
= pSetParms
->Rate
;
362 u8 Preamble
= pSetParms
->Preamble
;
363 u32 CurrFragLen
= pSetParms
->CurrFragLen
;
364 u32 NextFragLen
= pSetParms
->NextFragLen
;
365 u8 encryType
= pSetParms
->encryType
;
366 //u8 vapId = pSetParms->vapId;
369 u8 EnCipher
= ((pWlaHdr
->FrameCtrl
[1] & ENCRY_BIT
) ? 1 : 0);
370 u16 FragNum
= (pWlaHdr
->SeqCtrl
[0] & 0x0F);
371 card_Setting_t
*pCardSettting
= &macp
->cardSetting
;
372 u16 FrameType
= pWlaHdr
->FrameCtrl
[0];
378 memset(pCtrlSet
,0,sizeof(zd1205_Ctrl_Set_t
));
380 if (Rate
> macp
->AdapterMaxRate
)
381 Rate
= macp
->AdapterMaxRate
;
383 if ((FrameType
& 0x0c) == MANAGEMENT
){
385 Rate
= dot11Obj
.BasicRate
;
387 if ((FrameType
& 0x0c) == DATA
){
388 write_str(DbgStr101
, EnCipher
);
391 if(macp
->RF_Mode
== UW2453_RF
)
396 else if ((FrameType
== PROBE_RSP
) || (FrameType
== PROBE_REQ
)){
397 // Ensure Site-Survey smooth
398 if(PURE_A_MODE
!= pCardSettting
->MacMode
) {
402 else if(PURE_A_MODE
== pCardSettting
->MacMode
) {
410 if (FrameType
== PS_POLL
){
411 // For compatibility with D-Link AP
412 if(PURE_A_MODE
!= pCardSettting
->MacMode
) {
416 else if(PURE_A_MODE
== pCardSettting
->MacMode
) {
423 if ((Rate
== RATE_1M
) && (Preamble
== 1)){ //1M && short preamble
427 if (macp
->bFixedRate
){
429 Rate
= pCardSettting
->FixedRate
;
433 //FPRINT_V("zdinline Rate", Rate);
436 pCtrlSet
->CtrlSetting
[0] = (Rate
| (Preamble
<< 5));
438 if (Rate
< RATE_6M
){ //CCK frame
439 pCtrlSet
->CtrlSetting
[0] = (Rate
| (Preamble
<< 5));
442 if ((macp
->TxOFDMCnt
> 0) && (macp
->TxOFDMCnt
< cTX_SENT_LEN
))
452 if (Rate
== RATE_48M
){
453 if (macp
->TxOFDMType
!= cTX_48M
)
455 macp
->TxOFDMType
= cTX_48M
;
457 else if (Rate
== RATE_54M
){
458 if (macp
->TxOFDMType
!= cTX_54M
)
460 macp
->TxOFDMType
= cTX_54M
;
463 if (macp
->TxOFDMType
!= cTX_OFDM
)
465 macp
->TxOFDMType
= cTX_OFDM
;
469 if(PURE_A_MODE
!= pCardSettting
->MacMode
)
470 pCtrlSet
->CtrlSetting
[0] = OfdmRateTbl
[Rate
];
471 else if(PURE_A_MODE
== pCardSettting
->MacMode
) {
472 pCtrlSet
->CtrlSetting
[0] = OfdmRateTbl_11A
[Rate
];
480 //keep current Tx rate
481 pCardSettting
->CurrTxRate
= TxRate
;
485 if (!pCardSettting
->SwCipher
){
486 write_str(DbgStr102
, encryType
);
491 Len
= CurrFragLen
+ 36; /* Header(24) + CRC32(4) + IV(4) + ICV(4) */
492 NextLen
= NextFragLen
+ 36;
500 write_str(DbgStr100
, CurrFragLen
);
501 Len
= CurrFragLen
+ 40; /* Header(24) + CRC32(4) + IV(4) + EIV(4) + ICV(4) */
502 NextLen
= NextFragLen
+ 40;
509 Len
= CurrFragLen
+ 44; /* Header(24) + CRC32(4) + IV(4) + ExtendedIV(4) + MIC(8) */
510 NextLen
= NextFragLen
+ 44;
514 //FPRINT_V("Len", Len);
518 printk(KERN_DEBUG
"error encryType = %x\n", encryType
);
522 else { //use software encryption
523 if (pCardSettting
->DynKeyMode
== DYN_KEY_TKIP
){
524 if ((pWlaHdr
->DA
[0] & BIT_0
) && (pCardSettting
->WpaBcKeyLen
!= 32)) { //multicast
525 Len
= CurrFragLen
+ 32; // Header(24) + CRC32(4) + IV(4), ICV was packed under payload
527 NextLen
= NextFragLen
+ 32;
530 Len
= CurrFragLen
+ 36; // Header(24) + CRC32(4) + IV(4) + ExtendIV(4), ICV was packed under payload
531 NextLen
= NextFragLen
+ 36;
535 Len
= CurrFragLen
+ 32; // Header(24) + CRC32(4) + IV(4), ICV was packed under payload
536 NextLen
= NextFragLen
+ 32;
541 Len
= CurrFragLen
+ 28; /* Header(24) + CRC32(4) */
542 NextLen
= NextFragLen
+ 28;
549 /* Corret some exceptions */
550 if (FrameType
== PS_POLL
){
551 Len
= CurrFragLen
+ 20; // Header(16) + CRC32(4)
554 /* Corret some exceptions */
555 if (NextFragLen
== 0)
558 pCtrlSet
->CtrlSetting
[1] = (u8
)Len
; /* low byte */
559 pCtrlSet
->CtrlSetting
[2] = (u8
)(Len
>> 8); /* high byte */
561 /* TCB physical address */
562 pCtrlSet
->CtrlSetting
[3] = (u8
)(pSwTcb
->TcbPhys
);
563 pCtrlSet
->CtrlSetting
[4] = (u8
)(pSwTcb
->TcbPhys
>> 8);
564 pCtrlSet
->CtrlSetting
[5] = (u8
)(pSwTcb
->TcbPhys
>> 16);
565 pCtrlSet
->CtrlSetting
[6] = (u8
)(pSwTcb
->TcbPhys
>> 24);
567 pCtrlSet
->CtrlSetting
[7] = 0x00;
568 pCtrlSet
->CtrlSetting
[8] = 0x00;
569 pCtrlSet
->CtrlSetting
[9] = 0x00;
570 pCtrlSet
->CtrlSetting
[10] = 0x00;
577 if (macp
->bTxBurstEnable
){
578 if (macp
->activeTxQ
->count
> 0){
579 // AT LEAST one packet in ActiveChainList
580 macp
->TxBurstCount
++;
581 if (macp
->TxBurstCount
== 3) // only 3 packets
582 macp
->TxBurstCount
= 0;
585 // recount again, next packet will back off
586 macp
->TxBurstCount
= 0;
590 if (macp
->TxBurstCount
== 0){
591 tmp
|= BIT_0
; //need back off
594 tmp
&= ~BIT_0
; //burst, no need back off
597 pCtrlSet
->CtrlSetting
[0] |= BIT_7
;
602 if (pWlaHdr
->DA
[0] & BIT_0
){ /* Multicast */
611 if (FrameType
== PS_POLL
) //AP don't send PS_POLL
616 if ((pCardSettting
->BssType
== INDEPENDENT_BSS
) && (!bMgtFrame
)){
617 if (zd1205_DestPowerSave(macp
, &pWlaHdr
->DA
[0])){
623 if (Len
> pCardSettting
->RTSThreshold
){
624 if ((!bMgtFrame
) && (!bGroupAddr
)) {
625 if(PURE_A_MODE
!= macp
->cardSetting
.MacMode
)
627 else if(PURE_A_MODE
== macp
->cardSetting
.MacMode
)
632 #if (defined(GCCK) && defined(OFDM))
634 if (TxRate
> RATE_11M
&& PURE_A_MODE
!= macp
->cardSetting
.MacMode
){
637 // need to send RTS or CTS, in OFDM only send CTS, in CCK send RTS
641 //else if ((dot11Obj.ConfigFlag & ENABLE_PROTECTION_SET) && dot11Obj.bDisProtection==0)
642 else if ((dot11Obj
.ConfigFlag
& ENABLE_PROTECTION_SET
))
644 // id SelfCTS on, force send CTS when OFDM
650 if ((EnCipher
) && (!pCardSettting
->SwCipher
)){
655 if ((macp
->bTxBurstEnable
)){
657 // bBusrt off, this is the first one, force send CTS
660 // bBusrt on, this is the burst one, no need CTS
664 pCtrlSet
->CtrlSetting
[11] = tmp
;
667 pCtrlSet
->CtrlSetting
[12] = pWlaHdr
->DA
[0];
668 pCtrlSet
->CtrlSetting
[13] = pWlaHdr
->DA
[1];
669 pCtrlSet
->CtrlSetting
[14] = pWlaHdr
->DA
[2];
670 pCtrlSet
->CtrlSetting
[15] = pWlaHdr
->DA
[3];
671 pCtrlSet
->CtrlSetting
[16] = pWlaHdr
->DA
[4];
672 pCtrlSet
->CtrlSetting
[17] = pWlaHdr
->DA
[5];
674 if (FrameType
== DATA
){
675 macp
->TotalTxDataFrmBytes
+= Len
;
676 if (pCtrlSet
->CtrlSetting
[12] & BIT_0
){
677 macp
->txMulticastFrm
++;
678 macp
->txMulticastOctets
+= CurrFragLen
;
681 macp
->txUnicastFrm
++;
682 macp
->txUnicastOctets
+= CurrFragLen
;
683 macp
->txDataPerSec
+= CurrFragLen
;
691 pCtrlSet
->CtrlSetting
[18] = (u8
)NextLen
;
692 pCtrlSet
->CtrlSetting
[19] = (u8
)(NextLen
>> 8);
694 #elif defined(ZD1211B)
695 pSwTcb
->LengthDiff
= LengthDiff
;
699 Cal_Us_Service(TxRate
, Len
, &LenInUs
, &Service
);
701 if (macp
->bTxBurstEnable
)
703 LenInUs
= LenInUs
* 4;
705 pCtrlSet
->CtrlSetting
[20] = (u8
)LenInUs
;
706 pCtrlSet
->CtrlSetting
[21] = (u8
)(LenInUs
>> 8);
709 #if !(defined(GCCK) && defined(OFDM))
710 pCtrlSet
->CtrlSetting
[22] = Service
;
713 pCtrlSet
->CtrlSetting
[22] = Service
;
716 pCtrlSet
->CtrlSetting
[22] = 0;
724 Cal_Us_Service(TxRate
, NextLen
, &NextLenInUs
, &Service
);
725 pCtrlSet
->CtrlSetting
[23] = (u8
)NextLenInUs
;
726 pCtrlSet
->CtrlSetting
[24] = (u8
)(NextLenInUs
>> 8);
730 // backup NextLen, because OFDM use these 2 bytes as total length,
731 // so we backup here for Retry fail use.
732 pCtrlSet
->CtrlSetting
[26] = (u8
)NextLen
;
733 pCtrlSet
->CtrlSetting
[27] = (u8
)(NextLen
>> 8);
741 #define LOW8(v16) ((u8)( (v16) & 0xFF))
742 #define HIGH8(v16) ((u8)(((v16)>>8) & 0xFF))
748 if(Result
< 0 ) Result
*= -1;
755 struct zd1205_private
*macp
,
756 zd1205_SwTcb_t
*pSwTcb
,
757 wla_Header_t
*pWlaHdr
,
761 zd1205_Header_t
*pHdr
;
764 pHdr
= pSwTcb
->pHwHeaderPtr
;
767 memcpy(&pHdr
->MacHeader
[0], (u8
*)pWlaHdr
, hdrLen
);