2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
28 * s_vGenerateTxParameter - Generate tx dma required parameter.
29 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Caculate fragment number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts required duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragment ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
66 /*--------------------- Static Definitions -------------------------*/
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
71 //static int msglevel =MSG_LEVEL_DEBUG;
72 static int msglevel
=MSG_LEVEL_INFO
;
77 /*--------------------- Static Functions --------------------------*/
79 /*--------------------- Static Definitions -------------------------*/
80 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
81 // packet size >= 256 -> direct send
83 const WORD wTimeStampOff
[2][MAX_RATE
] = {
84 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
85 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
88 const WORD wFB_Opt0
[2][5] = {
89 {RATE_12M
, RATE_18M
, RATE_24M
, RATE_36M
, RATE_48M
}, // fallback_rate0
90 {RATE_12M
, RATE_12M
, RATE_18M
, RATE_24M
, RATE_36M
}, // fallback_rate1
92 const WORD wFB_Opt1
[2][5] = {
93 {RATE_12M
, RATE_18M
, RATE_24M
, RATE_24M
, RATE_36M
}, // fallback_rate0
94 {RATE_6M
, RATE_6M
, RATE_12M
, RATE_12M
, RATE_18M
}, // fallback_rate1
102 #define RTSDUR_BA_F0 4
103 #define RTSDUR_AA_F0 5
104 #define RTSDUR_BA_F1 6
105 #define RTSDUR_AA_F1 7
106 #define CTSDUR_BA_F0 8
107 #define CTSDUR_BA_F1 9
110 #define DATADUR_A_F0 12
111 #define DATADUR_A_F1 13
113 /*--------------------- Static Functions --------------------------*/
123 PSKeyItem pTransmitKey
,
140 PSEthernetHeader psEthHeader
,
147 s_vGenerateTxParameter(
157 PSEthernetHeader psEthHeader
,
163 static void s_vFillFragParameter(
178 PBYTE pbyTxBufferAddr
,
179 UINT cbFrameBodySize
,
182 PSEthernetHeader psEthHeader
,
185 PSKeyItem pTransmitKey
,
201 UINT cbLastFragmentSize
,
208 /*--------------------- Export Variables --------------------------*/
218 PSKeyItem pTransmitKey
,
224 PDWORD pdwIV
= (PDWORD
) pbyIVHead
;
225 PDWORD pdwExtIV
= (PDWORD
) ((PBYTE
)pbyIVHead
+4);
227 PS802_11Header pMACHeader
= (PS802_11Header
)pbyHdrBuf
;
228 DWORD dwRevIVCounter
;
234 if (pTransmitKey
== NULL
)
237 dwRevIVCounter
= cpu_to_le32(pDevice
->dwIVCounter
);
238 *pdwIV
= pDevice
->dwIVCounter
;
239 byKeyIndex
= pTransmitKey
->dwKeyIndex
& 0xf;
241 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
242 if (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
){
243 memcpy(pDevice
->abyPRNG
, (PBYTE
)&(dwRevIVCounter
), 3);
244 memcpy(pDevice
->abyPRNG
+3, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
246 memcpy(pbyBuf
, (PBYTE
)&(dwRevIVCounter
), 3);
247 memcpy(pbyBuf
+3, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
248 if(pTransmitKey
->uKeyLength
== WLAN_WEP40_KEYLEN
) {
249 memcpy(pbyBuf
+8, (PBYTE
)&(dwRevIVCounter
), 3);
250 memcpy(pbyBuf
+11, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
252 memcpy(pDevice
->abyPRNG
, pbyBuf
, 16);
254 // Append IV after Mac Header
255 *pdwIV
&= WEP_IV_MASK
;//00000000 11111111 11111111 11111111
256 *pdwIV
|= (byKeyIndex
<< 30);
257 *pdwIV
= cpu_to_le32(*pdwIV
);
258 pDevice
->dwIVCounter
++;
259 if (pDevice
->dwIVCounter
> WEP_IV_MASK
) {
260 pDevice
->dwIVCounter
= 0;
262 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
263 pTransmitKey
->wTSC15_0
++;
264 if (pTransmitKey
->wTSC15_0
== 0) {
265 pTransmitKey
->dwTSC47_16
++;
267 TKIPvMixKey(pTransmitKey
->abyKey
, pDevice
->abyCurrentNetAddr
,
268 pTransmitKey
->wTSC15_0
, pTransmitKey
->dwTSC47_16
, pDevice
->abyPRNG
);
269 memcpy(pbyBuf
, pDevice
->abyPRNG
, 16);
271 memcpy(pdwIV
, pDevice
->abyPRNG
, 3);
273 *(pbyIVHead
+3) = (BYTE
)(((byKeyIndex
<< 6) & 0xc0) | 0x20); // 0x20 is ExtIV
274 // Append IV&ExtIV after Mac Header
275 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
276 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV
);
278 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
279 pTransmitKey
->wTSC15_0
++;
280 if (pTransmitKey
->wTSC15_0
== 0) {
281 pTransmitKey
->dwTSC47_16
++;
283 memcpy(pbyBuf
, pTransmitKey
->abyKey
, 16);
287 *(pbyIVHead
+3) = (BYTE
)(((byKeyIndex
<< 6) & 0xc0) | 0x20); // 0x20 is ExtIV
288 *pdwIV
|= cpu_to_le16((WORD
)(pTransmitKey
->wTSC15_0
));
289 //Append IV&ExtIV after Mac Header
290 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
294 *((PBYTE
)(pMICHDR
+1)) = 0; // TxPriority
295 memcpy(pMICHDR
+2, &(pMACHeader
->abyAddr2
[0]), 6);
296 *((PBYTE
)(pMICHDR
+8)) = HIBYTE(HIWORD(pTransmitKey
->dwTSC47_16
));
297 *((PBYTE
)(pMICHDR
+9)) = LOBYTE(HIWORD(pTransmitKey
->dwTSC47_16
));
298 *((PBYTE
)(pMICHDR
+10)) = HIBYTE(LOWORD(pTransmitKey
->dwTSC47_16
));
299 *((PBYTE
)(pMICHDR
+11)) = LOBYTE(LOWORD(pTransmitKey
->dwTSC47_16
));
300 *((PBYTE
)(pMICHDR
+12)) = HIBYTE(pTransmitKey
->wTSC15_0
);
301 *((PBYTE
)(pMICHDR
+13)) = LOBYTE(pTransmitKey
->wTSC15_0
);
302 *((PBYTE
)(pMICHDR
+14)) = HIBYTE(wPayloadLen
);
303 *((PBYTE
)(pMICHDR
+15)) = LOBYTE(wPayloadLen
);
306 *((PBYTE
)(pMICHDR
+16)) = 0; // HLEN[15:8]
307 if (pDevice
->bLongHeader
) {
308 *((PBYTE
)(pMICHDR
+17)) = 28; // HLEN[7:0]
310 *((PBYTE
)(pMICHDR
+17)) = 22; // HLEN[7:0]
312 wValue
= cpu_to_le16(pMACHeader
->wFrameCtl
& 0xC78F);
313 memcpy(pMICHDR
+18, (PBYTE
)&wValue
, 2); // MSKFRACTL
314 memcpy(pMICHDR
+20, &(pMACHeader
->abyAddr1
[0]), 6);
315 memcpy(pMICHDR
+26, &(pMACHeader
->abyAddr2
[0]), 6);
318 memcpy(pMICHDR
+32, &(pMACHeader
->abyAddr3
[0]), 6);
319 wValue
= pMACHeader
->wSeqCtl
;
321 wValue
= cpu_to_le16(wValue
);
322 memcpy(pMICHDR
+38, (PBYTE
)&wValue
, 2); // MSKSEQCTL
323 if (pDevice
->bLongHeader
) {
324 memcpy(pMICHDR
+40, &(pMACHeader
->abyAddr4
[0]), 6);
334 PSKeyItem pTransmitKey
,
335 PBYTE pbyPayloadHead
,
340 DWORD dwICV
= 0xFFFFFFFFL
;
343 if (pTransmitKey
== NULL
)
346 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
347 //=======================================================================
348 // Append ICV after payload
349 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
350 pdwICV
= (PDWORD
)(pbyPayloadHead
+ wPayloadSize
);
351 // finally, we must invert dwCRC to get the correct answer
352 *pdwICV
= cpu_to_le32(~dwICV
);
354 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pTransmitKey
->uKeyLength
+ 3);
355 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
356 //=======================================================================
357 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
358 //=======================================================================
359 //Append ICV after payload
360 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
361 pdwICV
= (PDWORD
)(pbyPayloadHead
+ wPayloadSize
);
362 // finally, we must invert dwCRC to get the correct answer
363 *pdwICV
= cpu_to_le32(~dwICV
);
365 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
366 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
367 //=======================================================================
374 /*byPktType : PK_TYPE_11A 0
389 UINT uDataTime
, uAckTime
;
391 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wRate
);
393 //printk("s_uGetTxRsvTime is %d\n",uDataTime);
395 if (byPktType
== PK_TYPE_11B
) {//llb,CCK mode
396 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (WORD
)pDevice
->byTopCCKBasicRate
);
397 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
398 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (WORD
)pDevice
->byTopOFDMBasicRate
);
402 return (uDataTime
+ pDevice
->uSIFS
+ uAckTime
);
409 //byFreqType: 0=>5GHZ 1=>2.4GHZ
412 s_uGetRTSCTSRsvTime (
420 UINT uRrvTime
, uRTSTime
, uCTSTime
, uAckTime
, uDataTime
;
422 uRrvTime
= uRTSTime
= uCTSTime
= uAckTime
= uDataTime
= 0;
425 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wCurrentRate
);
426 if (byRTSRsvType
== 0) { //RTSTxRrvTime_bb
427 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
428 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
430 else if (byRTSRsvType
== 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
431 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
432 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
433 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
435 else if (byRTSRsvType
== 2) { //RTSTxRrvTime_aa
436 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopOFDMBasicRate
);
437 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
439 else if (byRTSRsvType
== 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
440 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
441 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
442 uRrvTime
= uCTSTime
+ uAckTime
+ uDataTime
+ 2*pDevice
->uSIFS
;
447 uRrvTime
= uRTSTime
+ uCTSTime
+ uAckTime
+ uDataTime
+ 3*pDevice
->uSIFS
;
451 //byFreqType 0: 5GHz, 1:2.4Ghz
462 UINT cbLastFragmentSize
,
468 UINT uAckTime
=0, uNextPktTime
= 0;
472 if (uFragIdx
== (uMACfragNum
-1)) {
479 case DATADUR_B
: //DATADUR_B
480 if (((uMACfragNum
== 1)) || (bLastFrag
== 1)) {//Non Frag or Last Frag
482 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
483 return (pDevice
->uSIFS
+ uAckTime
);
488 else {//First Frag or Mid Frag
489 if (uFragIdx
== (uMACfragNum
-2)) {
490 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wRate
, bNeedAck
);
492 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
495 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
496 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
498 return (pDevice
->uSIFS
+ uNextPktTime
);
503 case DATADUR_A
: //DATADUR_A
504 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
506 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
507 return (pDevice
->uSIFS
+ uAckTime
);
512 else {//First Frag or Mid Frag
513 if(uFragIdx
== (uMACfragNum
-2)){
514 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wRate
, bNeedAck
);
516 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
519 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
520 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
522 return (pDevice
->uSIFS
+ uNextPktTime
);
527 case DATADUR_A_F0
: //DATADUR_A_F0
528 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
530 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
531 return (pDevice
->uSIFS
+ uAckTime
);
536 else { //First Frag or Mid Frag
537 if (byFBOption
== AUTO_FB_0
) {
538 if (wRate
< RATE_18M
)
540 else if (wRate
> RATE_54M
)
543 if(uFragIdx
== (uMACfragNum
-2)){
544 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
546 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
548 } else { // (byFBOption == AUTO_FB_1)
549 if (wRate
< RATE_18M
)
551 else if (wRate
> RATE_54M
)
554 if(uFragIdx
== (uMACfragNum
-2)){
555 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
557 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
562 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
563 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
565 return (pDevice
->uSIFS
+ uNextPktTime
);
570 case DATADUR_A_F1
: //DATADUR_A_F1
571 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
573 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
574 return (pDevice
->uSIFS
+ uAckTime
);
579 else { //First Frag or Mid Frag
580 if (byFBOption
== AUTO_FB_0
) {
581 if (wRate
< RATE_18M
)
583 else if (wRate
> RATE_54M
)
586 if(uFragIdx
== (uMACfragNum
-2)){
587 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
589 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
592 } else { // (byFBOption == AUTO_FB_1)
593 if (wRate
< RATE_18M
)
595 else if (wRate
> RATE_54M
)
598 if(uFragIdx
== (uMACfragNum
-2)){
599 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
601 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
605 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
606 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
608 return (pDevice
->uSIFS
+ uNextPktTime
);
622 //byFreqType: 0=>5GHZ 1=>2.4GHZ
625 s_uGetRTSCTSDuration (
635 UINT uCTSTime
= 0, uDurTime
= 0;
640 case RTSDUR_BB
: //RTSDuration_bb
641 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
642 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
645 case RTSDUR_BA
: //RTSDuration_ba
646 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
647 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
650 case RTSDUR_AA
: //RTSDuration_aa
651 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
652 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
655 case CTSDUR_BA
: //CTSDuration_ba
656 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
659 case RTSDUR_BA_F0
: //RTSDuration_ba_f0
660 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
661 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
662 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
663 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
664 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
668 case RTSDUR_AA_F0
: //RTSDuration_aa_f0
669 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
670 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
671 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
672 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
673 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
677 case RTSDUR_BA_F1
: //RTSDuration_ba_f1
678 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
679 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
680 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
681 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
682 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
686 case RTSDUR_AA_F1
: //RTSDuration_aa_f1
687 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
688 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
689 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
690 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
691 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
695 case CTSDUR_BA_F0
: //CTSDuration_ba_f0
696 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
697 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
698 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
699 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
703 case CTSDUR_BA_F1
: //CTSDuration_ba_f1
704 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
705 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
706 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
707 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
731 UINT cbLastFragmentSize
,
739 if (pTxDataHead
== NULL
) {
743 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
744 if (byFBOption
== AUTO_FB_NONE
) {
745 PSTxDataHead_g pBuf
= (PSTxDataHead_g
)pTxDataHead
;
746 //Get SignalField,ServiceField,Length
747 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
748 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
750 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
751 BBvCaculateParameter(pDevice
, cbFrameLength
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
752 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
754 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
755 //Get Duration and TimeStamp
756 pBuf
->wDuration_a
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
,
757 byPktType
, wCurrentRate
, bNeedAck
, uFragIdx
,
758 cbLastFragmentSize
, uMACfragNum
,
759 byFBOption
)); //1: 2.4GHz
760 pBuf
->wDuration_b
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
,
761 PK_TYPE_11B
, pDevice
->byTopCCKBasicRate
,
762 bNeedAck
, uFragIdx
, cbLastFragmentSize
,
763 uMACfragNum
, byFBOption
)); //1: 2.4
765 pBuf
->wTimeStampOff_a
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
]);
766 pBuf
->wTimeStampOff_b
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][pDevice
->byTopCCKBasicRate
%MAX_RATE
]);
768 return (pBuf
->wDuration_a
);
771 PSTxDataHead_g_FB pBuf
= (PSTxDataHead_g_FB
)pTxDataHead
;
772 //Get SignalField,ServiceField,Length
773 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
774 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
776 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
777 BBvCaculateParameter(pDevice
, cbFrameLength
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
778 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
780 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
781 //Get Duration and TimeStamp
782 pBuf
->wDuration_a
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
783 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //1: 2.4GHz
784 pBuf
->wDuration_b
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
, PK_TYPE_11B
,
785 pDevice
->byTopCCKBasicRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //1: 2.4GHz
786 pBuf
->wDuration_a_f0
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F0
, cbFrameLength
, byPktType
,
787 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //1: 2.4GHz
788 pBuf
->wDuration_a_f1
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F1
, cbFrameLength
, byPktType
,
789 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //1: 2.4GHz
791 pBuf
->wTimeStampOff_a
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
]);
792 pBuf
->wTimeStampOff_b
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][pDevice
->byTopCCKBasicRate
%MAX_RATE
]);
794 return (pBuf
->wDuration_a
);
795 } //if (byFBOption == AUTO_FB_NONE)
797 else if (byPktType
== PK_TYPE_11A
) {
798 if ((byFBOption
!= AUTO_FB_NONE
)) {
800 PSTxDataHead_a_FB pBuf
= (PSTxDataHead_a_FB
)pTxDataHead
;
801 //Get SignalField,ServiceField,Length
802 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
803 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
805 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
806 //Get Duration and TimeStampOff
808 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
809 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //0: 5GHz
810 pBuf
->wDuration_f0
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F0
, cbFrameLength
, byPktType
,
811 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //0: 5GHz
812 pBuf
->wDuration_f1
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F1
, cbFrameLength
, byPktType
,
813 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
)); //0: 5GHz
814 pBuf
->wTimeStampOff
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
]);
815 return (pBuf
->wDuration
);
817 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
818 //Get SignalField,ServiceField,Length
819 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
820 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
822 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
823 //Get Duration and TimeStampOff
825 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
826 wCurrentRate
, bNeedAck
, uFragIdx
,
827 cbLastFragmentSize
, uMACfragNum
,
830 pBuf
->wTimeStampOff
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
]);
831 return (pBuf
->wDuration
);
835 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
836 //Get SignalField,ServiceField,Length
837 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
838 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
840 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
841 //Get Duration and TimeStampOff
842 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
, byPktType
,
843 wCurrentRate
, bNeedAck
, uFragIdx
,
844 cbLastFragmentSize
, uMACfragNum
,
846 pBuf
->wTimeStampOff
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
]);
847 return (pBuf
->wDuration
);
862 PSEthernetHeader psEthHeader
,
867 UINT uRTSFrameLen
= 20;
874 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
875 // in this case we need to decrease its length by 4.
879 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
880 // Otherwise, we need to modify codes for them.
881 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
882 if (byFBOption
== AUTO_FB_NONE
) {
883 PSRTS_g pBuf
= (PSRTS_g
)pvRTS
;
884 //Get SignalField,ServiceField,Length
885 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
886 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
888 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
889 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
890 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
892 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
894 pBuf
->wDuration_bb
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BB
, cbFrameLength
, PK_TYPE_11B
, pDevice
->byTopCCKBasicRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
895 pBuf
->wDuration_aa
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
896 pBuf
->wDuration_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
898 pBuf
->Data
.wDurationID
= pBuf
->wDuration_aa
;
900 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
901 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
902 (pDevice
->eOPMode
== OP_MODE_AP
)) {
903 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
906 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
908 if (pDevice
->eOPMode
== OP_MODE_AP
) {
909 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
912 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
916 PSRTS_g_FB pBuf
= (PSRTS_g_FB
)pvRTS
;
917 //Get SignalField,ServiceField,Length
918 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
919 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
921 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
922 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
923 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
925 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
928 pBuf
->wDuration_bb
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BB
, cbFrameLength
, PK_TYPE_11B
, pDevice
->byTopCCKBasicRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
929 pBuf
->wDuration_aa
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
930 pBuf
->wDuration_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
931 pBuf
->wRTSDuration_ba_f0
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BA_F0
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
932 pBuf
->wRTSDuration_aa_f0
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA_F0
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
933 pBuf
->wRTSDuration_ba_f1
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BA_F1
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
934 pBuf
->wRTSDuration_aa_f1
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA_F1
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
935 pBuf
->Data
.wDurationID
= pBuf
->wDuration_aa
;
937 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
939 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
940 (pDevice
->eOPMode
== OP_MODE_AP
)) {
941 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
944 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
947 if (pDevice
->eOPMode
== OP_MODE_AP
) {
948 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
951 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
954 } // if (byFBOption == AUTO_FB_NONE)
956 else if (byPktType
== PK_TYPE_11A
) {
957 if (byFBOption
== AUTO_FB_NONE
) {
958 PSRTS_ab pBuf
= (PSRTS_ab
)pvRTS
;
959 //Get SignalField,ServiceField,Length
960 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
961 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
963 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
965 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
966 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
968 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
970 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
971 (pDevice
->eOPMode
== OP_MODE_AP
)) {
972 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
975 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
978 if (pDevice
->eOPMode
== OP_MODE_AP
) {
979 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
982 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
987 PSRTS_a_FB pBuf
= (PSRTS_a_FB
)pvRTS
;
988 //Get SignalField,ServiceField,Length
989 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
990 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
992 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
994 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
995 pBuf
->wRTSDuration_f0
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA_F0
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
996 pBuf
->wRTSDuration_f1
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA_F1
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //7:RTSDuration_aa_f1, 0:5G, 0:
997 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
999 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1001 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1002 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1003 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
1006 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1008 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1009 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1012 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
1016 else if (byPktType
== PK_TYPE_11B
) {
1017 PSRTS_ab pBuf
= (PSRTS_ab
)pvRTS
;
1018 //Get SignalField,ServiceField,Length
1019 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1020 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
1022 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
1024 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BB
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1025 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
1026 //Get RTS Frame body
1027 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1030 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1031 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1032 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
1035 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1038 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1039 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1042 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
1061 UINT uCTSFrameLen
= 14;
1064 if (pvCTS
== NULL
) {
1069 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1070 // in this case we need to decrease its length by 4.
1074 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1075 if (byFBOption
!= AUTO_FB_NONE
&& uDMAIdx
!= TYPE_ATIMDMA
&& uDMAIdx
!= TYPE_BEACONDMA
) {
1077 PSCTS_FB pBuf
= (PSCTS_FB
)pvCTS
;
1078 //Get SignalField,ServiceField,Length
1079 BBvCaculateParameter(pDevice
, uCTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1080 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1084 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1086 pBuf
->wDuration_ba
= (WORD
)s_uGetRTSCTSDuration(pDevice
, CTSDUR_BA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1087 pBuf
->wDuration_ba
+= pDevice
->wCTSDuration
;
1088 pBuf
->wDuration_ba
= cpu_to_le16(pBuf
->wDuration_ba
);
1089 //Get CTSDuration_ba_f0
1090 pBuf
->wCTSDuration_ba_f0
= (WORD
)s_uGetRTSCTSDuration(pDevice
, CTSDUR_BA_F0
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
1091 pBuf
->wCTSDuration_ba_f0
+= pDevice
->wCTSDuration
;
1092 pBuf
->wCTSDuration_ba_f0
= cpu_to_le16(pBuf
->wCTSDuration_ba_f0
);
1093 //Get CTSDuration_ba_f1
1094 pBuf
->wCTSDuration_ba_f1
= (WORD
)s_uGetRTSCTSDuration(pDevice
, CTSDUR_BA_F1
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
1095 pBuf
->wCTSDuration_ba_f1
+= pDevice
->wCTSDuration
;
1096 pBuf
->wCTSDuration_ba_f1
= cpu_to_le16(pBuf
->wCTSDuration_ba_f1
);
1097 //Get CTS Frame body
1098 pBuf
->Data
.wDurationID
= pBuf
->wDuration_ba
;
1099 pBuf
->Data
.wFrameControl
= TYPE_CTL_CTS
;//0x00C4
1100 pBuf
->Data
.wReserved
= 0x0000;
1101 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyCurrentNetAddr
[0]), ETH_ALEN
);
1103 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1104 PSCTS pBuf
= (PSCTS
)pvCTS
;
1105 //Get SignalField,ServiceField,Length
1106 BBvCaculateParameter(pDevice
, uCTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1107 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1109 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1110 //Get CTSDuration_ba
1111 pBuf
->wDuration_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, CTSDUR_BA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1112 pBuf
->wDuration_ba
+= pDevice
->wCTSDuration
;
1113 pBuf
->wDuration_ba
= cpu_to_le16(pBuf
->wDuration_ba
);
1115 //Get CTS Frame body
1116 pBuf
->Data
.wDurationID
= pBuf
->wDuration_ba
;
1117 pBuf
->Data
.wFrameControl
= TYPE_CTL_CTS
;//0x00C4
1118 pBuf
->Data
.wReserved
= 0x0000;
1119 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyCurrentNetAddr
[0]), ETH_ALEN
);
1132 * Generate FIFO control for MAC & Baseband controller
1136 * pDevice - Pointer to adapter
1137 * pTxDataHead - Transmit Data Buffer
1138 * pTxBufHead - pTxBufHead
1139 * pvRrvTime - pvRrvTime
1140 * pvRTS - RTS Buffer
1142 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1143 * bNeedACK - If need ACK
1144 * uDescIdx - Desc Index
1148 * Return Value: none
1151 // UINT cbFrameSize,//Hdr+Payload+FCS
1154 s_vGenerateTxParameter (
1164 PSEthernetHeader psEthHeader
,
1168 UINT cbMACHdLen
= WLAN_HDR_ADDR3_LEN
; //24
1170 BOOL bDisCRC
= FALSE
;
1171 BYTE byFBOption
= AUTO_FB_NONE
;
1172 // WORD wCurrentRate = pDevice->wCurrentRate;
1174 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1175 PSTxBufHead pFifoHead
= (PSTxBufHead
)pTxBufHead
;
1176 pFifoHead
->wReserved
= wCurrentRate
;
1177 wFifoCtl
= pFifoHead
->wFIFOCtl
;
1179 if (wFifoCtl
& FIFOCTL_CRCDIS
) {
1183 if (wFifoCtl
& FIFOCTL_AUTO_FB_0
) {
1184 byFBOption
= AUTO_FB_0
;
1186 else if (wFifoCtl
& FIFOCTL_AUTO_FB_1
) {
1187 byFBOption
= AUTO_FB_1
;
1190 if (pDevice
->bLongHeader
)
1191 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1193 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1195 if (pvRTS
!= NULL
) { //RTS_need
1198 PSRrvTime_gRTS pBuf
= (PSRrvTime_gRTS
)pvRrvTime
;
1199 pBuf
->wRTSTxRrvTime_aa
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 2, byPktType
, cbFrameSize
, wCurrentRate
));//2:RTSTxRrvTime_aa, 1:2.4GHz
1200 pBuf
->wRTSTxRrvTime_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 1, byPktType
, cbFrameSize
, wCurrentRate
));//1:RTSTxRrvTime_ba, 1:2.4GHz
1201 pBuf
->wRTSTxRrvTime_bb
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 0, byPktType
, cbFrameSize
, wCurrentRate
));//0:RTSTxRrvTime_bb, 1:2.4GHz
1202 pBuf
->wTxRrvTime_a
= cpu_to_le16((WORD
) s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//2.4G OFDM
1203 pBuf
->wTxRrvTime_b
= cpu_to_le16((WORD
) s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
, bNeedACK
));//1:CCK
1206 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1208 else {//RTS_needless, PCF mode
1212 PSRrvTime_gCTS pBuf
= (PSRrvTime_gCTS
)pvRrvTime
;
1213 pBuf
->wTxRrvTime_a
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//2.4G OFDM
1214 pBuf
->wTxRrvTime_b
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
, bNeedACK
));//1:CCK
1215 pBuf
->wCTSTxRrvTime_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 3, byPktType
, cbFrameSize
, wCurrentRate
));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1220 s_vFillCTSHead(pDevice
, uDMAIdx
, byPktType
, pvCTS
, cbFrameSize
, bNeedACK
, bDisCRC
, wCurrentRate
, byFBOption
);
1223 else if (byPktType
== PK_TYPE_11A
) {
1225 if (pvRTS
!= NULL
) {//RTS_need, non PCF mode
1228 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1229 pBuf
->wRTSTxRrvTime
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 2, byPktType
, cbFrameSize
, wCurrentRate
));//2:RTSTxRrvTime_aa, 0:5GHz
1230 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//0:OFDM
1233 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1235 else if (pvRTS
== NULL
) {//RTS_needless, non PCF mode
1238 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1239 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11A
, cbFrameSize
, wCurrentRate
, bNeedACK
)); //0:OFDM
1243 else if (byPktType
== PK_TYPE_11B
) {
1245 if ((pvRTS
!= NULL
)) {//RTS_need, non PCF mode
1248 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1249 pBuf
->wRTSTxRrvTime
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 0, byPktType
, cbFrameSize
, wCurrentRate
));//0:RTSTxRrvTime_bb, 1:2.4GHz
1250 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, wCurrentRate
, bNeedACK
));//1:CCK
1253 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1255 else { //RTS_needless, non PCF mode
1258 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1259 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, wCurrentRate
, bNeedACK
)); //1:CCK
1263 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1266 PBYTE pbyBuffer,//point to pTxBufHead
1267 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1268 UINT cbFragmentSize,//Hdr+payoad+FCS
1272 s_vFillFragParameter(
1281 PSTxBufHead pTxBufHead
= (PSTxBufHead
) pbyBuffer
;
1282 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
1284 if (uTxType
== TYPE_SYNCDMA
) {
1285 //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1286 PSTxSyncDesc ptdCurr
= (PSTxSyncDesc
)pvtdCurr
;
1288 //Set FIFOCtl & TimeStamp in TxSyncDesc
1289 ptdCurr
->m_wFIFOCtl
= pTxBufHead
->wFIFOCtl
;
1290 ptdCurr
->m_wTimeStamp
= pTxBufHead
->wTimeStamp
;
1291 //Set TSR1 & ReqCount in TxDescHead
1292 ptdCurr
->m_td1TD1
.wReqCount
= cpu_to_le16((WORD
)(cbReqCount
));
1293 if (wFragType
== FRAGCTL_ENDFRAG
) { //Last Fragmentation
1294 ptdCurr
->m_td1TD1
.byTCR
|= (TCR_STP
| TCR_EDP
| EDMSDU
);
1297 ptdCurr
->m_td1TD1
.byTCR
|= (TCR_STP
| TCR_EDP
);
1301 //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1302 PSTxDesc ptdCurr
= (PSTxDesc
)pvtdCurr
;
1303 //Set TSR1 & ReqCount in TxDescHead
1304 ptdCurr
->m_td1TD1
.wReqCount
= cpu_to_le16((WORD
)(cbReqCount
));
1305 if (wFragType
== FRAGCTL_ENDFRAG
) { //Last Fragmentation
1306 ptdCurr
->m_td1TD1
.byTCR
|= (TCR_STP
| TCR_EDP
| EDMSDU
);
1309 ptdCurr
->m_td1TD1
.byTCR
|= (TCR_STP
| TCR_EDP
);
1313 pTxBufHead
->wFragCtl
|= (WORD
)wFragType
;//0x0001; //0000 0000 0000 0001
1315 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
1323 PBYTE pbyTxBufferAddr
,
1324 UINT cbFrameBodySize
,
1327 PSEthernetHeader psEthHeader
,
1330 PSKeyItem pTransmitKey
,
1337 UINT cbFragmentSize
; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1338 UINT cbFragPayloadSize
;
1339 UINT cbLastFragmentSize
; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1340 UINT cbLastFragPayloadSize
;
1342 PBYTE pbyPayloadHead
;
1345 WORD wFragType
; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
1348 // UINT uKeyEntryIdx = NUM_KEY_ENTRY+1;
1349 // BYTE byKeySel = 0xFF;
1354 UINT cb802_1_H_len
= 0;
1360 DWORD dwMICKey0
, dwMICKey1
;
1361 DWORD dwMIC_Priority
;
1364 DWORD dwSafeMIC_L
, dwSafeMIC_R
; //Fix "Last Frag Size" < "MIC length".
1365 BOOL bMIC2Frag
= FALSE
;
1366 UINT uMICFragLen
= 0;
1367 UINT uMACfragNum
= 1;
1369 UINT cbReqCount
= 0;
1376 PSTxBufHead psTxBufHd
= (PSTxBufHead
) pbyTxBufferAddr
;
1378 UINT cbHeaderLength
= 0;
1380 PSMICHDRHead pMICHDR
;
1384 WORD wTxBufSize
; // FFinfo size
1385 UINT uTotalCopyLength
= 0;
1386 BYTE byFBOption
= AUTO_FB_NONE
;
1387 BOOL bIsWEP256
= FALSE
;
1388 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1391 pvRrvTime
= pMICHDR
= pvRTS
= pvCTS
= pvTxDataHd
= NULL
;
1393 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
1394 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1395 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1397 if (IS_MULTICAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0])) ||
1398 IS_BROADCAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0]))) {
1407 // MSDUs in Infra mode always need ACK
1412 if (pDevice
->bLongHeader
)
1413 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1415 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
;
1418 if ((bNeedEncrypt
== TRUE
) && (pTransmitKey
!= NULL
)) {
1419 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
1422 if (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
) {
1426 if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1427 cbIVlen
= 8;//IV+ExtIV
1431 if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
1432 cbIVlen
= 8;//RSN Header
1434 cbMICHDR
= sizeof(SMICHDRHead
);
1436 if (pDevice
->byLocalID
> REV_ID_VT3253_A1
) {
1437 //MAC Header should be padding 0 to DW alignment.
1438 uPadding
= 4 - (cbMACHdLen
%4);
1444 cbFrameSize
= cbMACHdLen
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbICVlen
+ cbFCSlen
;
1446 if ((bNeedACK
== FALSE
) ||
1447 (cbFrameSize
< pDevice
->wRTSThreshold
) ||
1448 ((cbFrameSize
>= pDevice
->wFragmentationThreshold
) && (pDevice
->wFragmentationThreshold
<= pDevice
->wRTSThreshold
))
1454 psTxBufHd
->wFIFOCtl
|= (FIFOCTL_RTS
| FIFOCTL_LRETRY
);
1457 // Use for AUTO FALL BACK
1459 if (psTxBufHd
->wFIFOCtl
& FIFOCTL_AUTO_FB_0
) {
1460 byFBOption
= AUTO_FB_0
;
1462 else if (psTxBufHd
->wFIFOCtl
& FIFOCTL_AUTO_FB_1
) {
1463 byFBOption
= AUTO_FB_1
;
1466 //////////////////////////////////////////////////////
1467 //Set RrvTime/RTS/CTS Buffer
1468 wTxBufSize
= sizeof(STxBufHead
);
1469 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1471 if (byFBOption
== AUTO_FB_NONE
) {
1472 if (bRTS
== TRUE
) {//RTS_need
1473 pvRrvTime
= (PSRrvTime_gRTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1474 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
));
1475 pvRTS
= (PSRTS_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
);
1477 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g
));
1478 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g
) + sizeof(STxDataHead_g
);
1480 else { //RTS_needless
1481 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1482 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1484 pvCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
1485 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
));
1486 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
) + sizeof(STxDataHead_g
);
1490 if (bRTS
== TRUE
) {//RTS_need
1491 pvRrvTime
= (PSRrvTime_gRTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1492 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
));
1493 pvRTS
= (PSRTS_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
);
1495 pvTxDataHd
= (PSTxDataHead_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g_FB
));
1496 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g_FB
) + sizeof(STxDataHead_g_FB
);
1498 else { //RTS_needless
1499 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1500 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1502 pvCTS
= (PSCTS_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
1503 pvTxDataHd
= (PSTxDataHead_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS_FB
));
1504 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS_FB
) + sizeof(STxDataHead_g_FB
);
1508 else {//802.11a/b packet
1510 if (byFBOption
== AUTO_FB_NONE
) {
1512 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1513 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1514 pvRTS
= (PSRTS_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1516 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_ab
));
1517 cbHeaderLength
= wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_ab
) + sizeof(STxDataHead_ab
);
1519 else { //RTS_needless, need MICHDR
1520 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1521 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1524 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1525 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_ab
);
1529 if (bRTS
== TRUE
) {//RTS_need
1530 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1531 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1532 pvRTS
= (PSRTS_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1534 pvTxDataHd
= (PSTxDataHead_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_a_FB
));
1535 cbHeaderLength
= wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_a_FB
) + sizeof(STxDataHead_a_FB
);
1537 else { //RTS_needless
1538 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1539 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1542 pvTxDataHd
= (PSTxDataHead_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1543 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_a_FB
);
1547 memset((void *)(pbyTxBufferAddr
+ wTxBufSize
), 0, (cbHeaderLength
- wTxBufSize
));
1549 //////////////////////////////////////////////////////////////////
1550 if ((bNeedEncrypt
== TRUE
) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1551 if (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) {
1552 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
1553 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
1555 else if ((pTransmitKey
->dwKeyIndex
& AUTHENTICATOR_KEY
) != 0) {
1556 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
1557 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
1560 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[24]);
1561 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[28]);
1563 // DO Software Michael
1564 MIC_vInit(dwMICKey0
, dwMICKey1
);
1565 MIC_vAppend((PBYTE
)&(psEthHeader
->abyDstAddr
[0]), 12);
1567 MIC_vAppend((PBYTE
)&dwMIC_Priority
, 4);
1568 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC KEY: %lX, %lX\n", dwMICKey0
, dwMICKey1
);
1571 ///////////////////////////////////////////////////////////////////
1573 pbyMacHdr
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderLength
);
1574 pbyPayloadHead
= (PBYTE
)(pbyMacHdr
+ cbMACHdLen
+ uPadding
+ cbIVlen
);
1575 pbyIVHead
= (PBYTE
)(pbyMacHdr
+ cbMACHdLen
+ uPadding
);
1577 if ((cbFrameSize
> pDevice
->wFragmentationThreshold
) && (bNeedACK
== TRUE
) && (bIsWEP256
== FALSE
)) {
1579 // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
1580 cbFragmentSize
= pDevice
->wFragmentationThreshold
;
1581 cbFragPayloadSize
= cbFragmentSize
- cbMACHdLen
- cbIVlen
- cbICVlen
- cbFCSlen
;
1582 //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
1583 uMACfragNum
= (WORD
) ((cbFrameBodySize
+ cbMIClen
) / cbFragPayloadSize
);
1584 cbLastFragPayloadSize
= (cbFrameBodySize
+ cbMIClen
) % cbFragPayloadSize
;
1585 if (cbLastFragPayloadSize
== 0) {
1586 cbLastFragPayloadSize
= cbFragPayloadSize
;
1590 //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
1591 cbLastFragmentSize
= cbMACHdLen
+ cbLastFragPayloadSize
+ cbIVlen
+ cbICVlen
+ cbFCSlen
;
1593 for (uFragIdx
= 0; uFragIdx
< uMACfragNum
; uFragIdx
++) {
1594 if (uFragIdx
== 0) {
1595 //=========================
1596 // Start Fragmentation
1597 //=========================
1598 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Start Fragmentation...\n");
1599 wFragType
= FRAGCTL_STAFRAG
;
1602 //Fill FIFO,RrvTime,RTS,and CTS
1603 s_vGenerateTxParameter(pDevice
, byPktType
, (void *)psTxBufHd
, pvRrvTime
, pvRTS
, pvCTS
,
1604 cbFragmentSize
, bNeedACK
, uDMAIdx
, psEthHeader
, pDevice
->wCurrentRate
);
1606 uDuration
= s_uFillDataHead(pDevice
, byPktType
, pvTxDataHd
, cbFragmentSize
, uDMAIdx
, bNeedACK
,
1607 uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
, pDevice
->wCurrentRate
);
1608 // Generate TX MAC Header
1609 vGenerateMACHeader(pDevice
, pbyMacHdr
, (WORD
)uDuration
, psEthHeader
, bNeedEncrypt
,
1610 wFragType
, uDMAIdx
, uFragIdx
);
1612 if (bNeedEncrypt
== TRUE
) {
1614 s_vFillTxKey(pDevice
, (PBYTE
)(psTxBufHd
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1615 pbyMacHdr
, (WORD
)cbFragPayloadSize
, (PBYTE
)pMICHDR
);
1616 //Fill IV(ExtIV,RSNHDR)
1617 if (pDevice
->bEnableHostWEP
) {
1618 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1619 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1625 if (ntohs(psEthHeader
->wType
) > ETH_DATA_LEN
) {
1626 if ((psEthHeader
->wType
== TYPE_PKT_IPX
) ||
1627 (psEthHeader
->wType
== cpu_to_le16(0xF380))) {
1628 memcpy((PBYTE
) (pbyPayloadHead
), &pDevice
->abySNAP_Bridgetunnel
[0], 6);
1631 memcpy((PBYTE
) (pbyPayloadHead
), &pDevice
->abySNAP_RFC1042
[0], 6);
1633 pbyType
= (PBYTE
) (pbyPayloadHead
+ 6);
1634 memcpy(pbyType
, &(psEthHeader
->wType
), sizeof(WORD
));
1638 cbReqCount
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
+ cbFragPayloadSize
;
1639 //---------------------------
1640 // S/W or H/W Encryption
1641 //---------------------------
1643 //if (pDevice->bAES) {
1644 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1646 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
1647 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1651 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
1652 pbyBuffer
= (PBYTE
)pHeadTD
->pTDInfo
->buf
;
1654 uLength
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
+ cb802_1_H_len
;
1655 //copy TxBufferHeader + MacHeader to desc
1656 memcpy(pbyBuffer
, (void *)psTxBufHd
, uLength
);
1658 // Copy the Packet into a tx Buffer
1659 memcpy((pbyBuffer
+ uLength
), (pPacket
+ 14), (cbFragPayloadSize
- cb802_1_H_len
));
1662 uTotalCopyLength
+= cbFragPayloadSize
- cb802_1_H_len
;
1664 if ((bNeedEncrypt
== TRUE
) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1665 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Start MIC: %d\n", cbFragPayloadSize
);
1666 MIC_vAppend((pbyBuffer
+ uLength
- cb802_1_H_len
), cbFragPayloadSize
);
1670 //---------------------------
1672 //---------------------------
1673 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1675 s_vSWencryption(pDevice
, pTransmitKey
, (pbyBuffer
+ uLength
- cb802_1_H_len
), (WORD
)cbFragPayloadSize
);
1676 cbReqCount
+= cbICVlen
;
1680 ptdCurr
= (PSTxDesc
)pHeadTD
;
1681 //--------------------
1682 //1.Set TSR1 & ReqCount in TxDescHead
1683 //2.Set FragCtl in TxBufferHead
1684 //3.Set Frame Control
1685 //4.Set Sequence Control
1686 //5.Get S/W generate FCS
1687 //--------------------
1688 s_vFillFragParameter(pDevice
, pbyBuffer
, uDMAIdx
, (void *)ptdCurr
, wFragType
, cbReqCount
);
1690 ptdCurr
->pTDInfo
->dwReqCount
= cbReqCount
- uPadding
;
1691 ptdCurr
->pTDInfo
->dwHeaderLength
= cbHeaderLength
;
1692 ptdCurr
->pTDInfo
->skb_dma
= ptdCurr
->pTDInfo
->buf_dma
;
1693 ptdCurr
->buff_addr
= cpu_to_le32(ptdCurr
->pTDInfo
->skb_dma
);
1694 pDevice
->iTDUsed
[uDMAIdx
]++;
1695 pHeadTD
= ptdCurr
->next
;
1697 else if (uFragIdx
== (uMACfragNum
-1)) {
1698 //=========================
1699 // Last Fragmentation
1700 //=========================
1701 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Last Fragmentation...\n");
1702 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1704 wFragType
= FRAGCTL_ENDFRAG
;
1706 //Fill FIFO,RrvTime,RTS,and CTS
1707 s_vGenerateTxParameter(pDevice
, byPktType
, (void *)psTxBufHd
, pvRrvTime
, pvRTS
, pvCTS
,
1708 cbLastFragmentSize
, bNeedACK
, uDMAIdx
, psEthHeader
, pDevice
->wCurrentRate
);
1710 uDuration
= s_uFillDataHead(pDevice
, byPktType
, pvTxDataHd
, cbLastFragmentSize
, uDMAIdx
, bNeedACK
,
1711 uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
, pDevice
->wCurrentRate
);
1713 // Generate TX MAC Header
1714 vGenerateMACHeader(pDevice
, pbyMacHdr
, (WORD
)uDuration
, psEthHeader
, bNeedEncrypt
,
1715 wFragType
, uDMAIdx
, uFragIdx
);
1717 if (bNeedEncrypt
== TRUE
) {
1719 s_vFillTxKey(pDevice
, (PBYTE
)(psTxBufHd
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1720 pbyMacHdr
, (WORD
)cbLastFragPayloadSize
, (PBYTE
)pMICHDR
);
1722 if (pDevice
->bEnableHostWEP
) {
1723 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1724 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1730 cbReqCount
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
+ cbLastFragPayloadSize
;
1731 //---------------------------
1732 // S/W or H/W Encryption
1733 //---------------------------
1737 pbyBuffer
= (PBYTE
)pHeadTD
->pTDInfo
->buf
;
1738 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1740 uLength
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
;
1742 //copy TxBufferHeader + MacHeader to desc
1743 memcpy(pbyBuffer
, (void *)psTxBufHd
, uLength
);
1745 // Copy the Packet into a tx Buffer
1746 if (bMIC2Frag
== FALSE
) {
1748 memcpy((pbyBuffer
+ uLength
),
1749 (pPacket
+ 14 + uTotalCopyLength
),
1750 (cbLastFragPayloadSize
- cbMIClen
)
1752 //TODO check uTmpLen !
1753 uTmpLen
= cbLastFragPayloadSize
- cbMIClen
;
1756 if ((bNeedEncrypt
== TRUE
) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1757 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
1758 uMICFragLen
, cbLastFragPayloadSize
, uTmpLen
);
1760 if (bMIC2Frag
== FALSE
) {
1762 MIC_vAppend((pbyBuffer
+ uLength
), uTmpLen
);
1763 pdwMIC_L
= (PDWORD
)(pbyBuffer
+ uLength
+ uTmpLen
);
1764 pdwMIC_R
= (PDWORD
)(pbyBuffer
+ uLength
+ uTmpLen
+ 4);
1765 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1766 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Last MIC:%lX, %lX\n", *pdwMIC_L
, *pdwMIC_R
);
1768 if (uMICFragLen
>= 4) {
1769 memcpy((pbyBuffer
+ uLength
), ((PBYTE
)&dwSafeMIC_R
+ (uMICFragLen
- 4)),
1770 (cbMIClen
- uMICFragLen
));
1771 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"LAST: uMICFragLen >= 4: %X, %d\n",
1772 *(PBYTE
)((PBYTE
)&dwSafeMIC_R
+ (uMICFragLen
- 4)),
1773 (cbMIClen
- uMICFragLen
));
1776 memcpy((pbyBuffer
+ uLength
), ((PBYTE
)&dwSafeMIC_L
+ uMICFragLen
),
1778 memcpy((pbyBuffer
+ uLength
+ (4 - uMICFragLen
)), &dwSafeMIC_R
, 4);
1779 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"LAST: uMICFragLen < 4: %X, %d\n",
1780 *(PBYTE
)((PBYTE
)&dwSafeMIC_R
+ uMICFragLen
- 4),
1781 (cbMIClen
- uMICFragLen
));
1784 for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii - 8 - 24)));
1787 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1792 ASSERT(uTmpLen
== (cbLastFragPayloadSize
- cbMIClen
));
1796 //---------------------------
1798 //---------------------------
1799 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1801 s_vSWencryption(pDevice
, pTransmitKey
, (pbyBuffer
+ uLength
), (WORD
)cbLastFragPayloadSize
);
1802 cbReqCount
+= cbICVlen
;
1806 ptdCurr
= (PSTxDesc
)pHeadTD
;
1808 //--------------------
1809 //1.Set TSR1 & ReqCount in TxDescHead
1810 //2.Set FragCtl in TxBufferHead
1811 //3.Set Frame Control
1812 //4.Set Sequence Control
1813 //5.Get S/W generate FCS
1814 //--------------------
1817 s_vFillFragParameter(pDevice
, pbyBuffer
, uDMAIdx
, (void *)ptdCurr
, wFragType
, cbReqCount
);
1819 ptdCurr
->pTDInfo
->dwReqCount
= cbReqCount
- uPadding
;
1820 ptdCurr
->pTDInfo
->dwHeaderLength
= cbHeaderLength
;
1821 ptdCurr
->pTDInfo
->skb_dma
= ptdCurr
->pTDInfo
->buf_dma
;
1822 ptdCurr
->buff_addr
= cpu_to_le32(ptdCurr
->pTDInfo
->skb_dma
);
1823 pDevice
->iTDUsed
[uDMAIdx
]++;
1824 pHeadTD
= ptdCurr
->next
;
1828 //=========================
1829 // Middle Fragmentation
1830 //=========================
1831 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Middle Fragmentation...\n");
1832 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1834 wFragType
= FRAGCTL_MIDFRAG
;
1836 //Fill FIFO,RrvTime,RTS,and CTS
1837 s_vGenerateTxParameter(pDevice
, byPktType
, (void *)psTxBufHd
, pvRrvTime
, pvRTS
, pvCTS
,
1838 cbFragmentSize
, bNeedACK
, uDMAIdx
, psEthHeader
, pDevice
->wCurrentRate
);
1840 uDuration
= s_uFillDataHead(pDevice
, byPktType
, pvTxDataHd
, cbFragmentSize
, uDMAIdx
, bNeedACK
,
1841 uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
, pDevice
->wCurrentRate
);
1843 // Generate TX MAC Header
1844 vGenerateMACHeader(pDevice
, pbyMacHdr
, (WORD
)uDuration
, psEthHeader
, bNeedEncrypt
,
1845 wFragType
, uDMAIdx
, uFragIdx
);
1848 if (bNeedEncrypt
== TRUE
) {
1850 s_vFillTxKey(pDevice
, (PBYTE
)(psTxBufHd
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1851 pbyMacHdr
, (WORD
)cbFragPayloadSize
, (PBYTE
)pMICHDR
);
1853 if (pDevice
->bEnableHostWEP
) {
1854 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1855 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1859 cbReqCount
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
+ cbFragPayloadSize
;
1860 //---------------------------
1861 // S/W or H/W Encryption
1862 //---------------------------
1864 //if (pDevice->bAES) {
1865 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1867 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
1868 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1871 pbyBuffer
= (PBYTE
)pHeadTD
->pTDInfo
->buf
;
1872 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1875 uLength
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
;
1877 //copy TxBufferHeader + MacHeader to desc
1878 memcpy(pbyBuffer
, (void *)psTxBufHd
, uLength
);
1880 // Copy the Packet into a tx Buffer
1881 memcpy((pbyBuffer
+ uLength
),
1882 (pPacket
+ 14 + uTotalCopyLength
),
1885 uTmpLen
= cbFragPayloadSize
;
1887 uTotalCopyLength
+= uTmpLen
;
1889 if ((bNeedEncrypt
== TRUE
) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1891 MIC_vAppend((pbyBuffer
+ uLength
), uTmpLen
);
1893 if (uTmpLen
< cbFragPayloadSize
) {
1895 uMICFragLen
= cbFragPayloadSize
- uTmpLen
;
1896 ASSERT(uMICFragLen
< cbMIClen
);
1898 pdwMIC_L
= (PDWORD
)(pbyBuffer
+ uLength
+ uTmpLen
);
1899 pdwMIC_R
= (PDWORD
)(pbyBuffer
+ uLength
+ uTmpLen
+ 4);
1900 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1901 dwSafeMIC_L
= *pdwMIC_L
;
1902 dwSafeMIC_R
= *pdwMIC_R
;
1904 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
1905 uMICFragLen
, cbFragPayloadSize
, uTmpLen
);
1906 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fill MIC in Middle frag [%d]\n", uMICFragLen
);
1908 for (ii = 0; ii < uMICFragLen; ii++) {
1909 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength + uTmpLen) + ii)));
1911 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1913 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get MIC:%lX, %lX\n", *pdwMIC_L
, *pdwMIC_R
);
1915 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Middle frag len: %d\n", uTmpLen
);
1917 for (ii = 0; ii < uTmpLen; ii++) {
1918 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
1920 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1924 ASSERT(uTmpLen
== (cbFragPayloadSize
));
1927 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1929 s_vSWencryption(pDevice
, pTransmitKey
, (pbyBuffer
+ uLength
), (WORD
)cbFragPayloadSize
);
1930 cbReqCount
+= cbICVlen
;
1934 ptdCurr
= (PSTxDesc
)pHeadTD
;
1936 //--------------------
1937 //1.Set TSR1 & ReqCount in TxDescHead
1938 //2.Set FragCtl in TxBufferHead
1939 //3.Set Frame Control
1940 //4.Set Sequence Control
1941 //5.Get S/W generate FCS
1942 //--------------------
1944 s_vFillFragParameter(pDevice
, pbyBuffer
, uDMAIdx
, (void *)ptdCurr
, wFragType
, cbReqCount
);
1946 ptdCurr
->pTDInfo
->dwReqCount
= cbReqCount
- uPadding
;
1947 ptdCurr
->pTDInfo
->dwHeaderLength
= cbHeaderLength
;
1948 ptdCurr
->pTDInfo
->skb_dma
= ptdCurr
->pTDInfo
->buf_dma
;
1949 ptdCurr
->buff_addr
= cpu_to_le32(ptdCurr
->pTDInfo
->skb_dma
);
1950 pDevice
->iTDUsed
[uDMAIdx
]++;
1951 pHeadTD
= ptdCurr
->next
;
1953 } // for (uMACfragNum)
1956 //=========================
1958 //=========================
1959 //DBG_PRTGRP03(("No Fragmentation...\n"));
1960 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1961 wFragType
= FRAGCTL_NONFRAG
;
1963 //Set FragCtl in TxBufferHead
1964 psTxBufHd
->wFragCtl
|= (WORD
)wFragType
;
1966 //Fill FIFO,RrvTime,RTS,and CTS
1967 s_vGenerateTxParameter(pDevice
, byPktType
, (void *)psTxBufHd
, pvRrvTime
, pvRTS
, pvCTS
,
1968 cbFrameSize
, bNeedACK
, uDMAIdx
, psEthHeader
, pDevice
->wCurrentRate
);
1970 uDuration
= s_uFillDataHead(pDevice
, byPktType
, pvTxDataHd
, cbFrameSize
, uDMAIdx
, bNeedACK
,
1971 0, 0, uMACfragNum
, byFBOption
, pDevice
->wCurrentRate
);
1973 // Generate TX MAC Header
1974 vGenerateMACHeader(pDevice
, pbyMacHdr
, (WORD
)uDuration
, psEthHeader
, bNeedEncrypt
,
1975 wFragType
, uDMAIdx
, 0);
1977 if (bNeedEncrypt
== TRUE
) {
1979 s_vFillTxKey(pDevice
, (PBYTE
)(psTxBufHd
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1980 pbyMacHdr
, (WORD
)cbFrameBodySize
, (PBYTE
)pMICHDR
);
1982 if (pDevice
->bEnableHostWEP
) {
1983 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1984 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1989 if (ntohs(psEthHeader
->wType
) > ETH_DATA_LEN
) {
1990 if ((psEthHeader
->wType
== TYPE_PKT_IPX
) ||
1991 (psEthHeader
->wType
== cpu_to_le16(0xF380))) {
1992 memcpy((PBYTE
) (pbyPayloadHead
), &pDevice
->abySNAP_Bridgetunnel
[0], 6);
1995 memcpy((PBYTE
) (pbyPayloadHead
), &pDevice
->abySNAP_RFC1042
[0], 6);
1997 pbyType
= (PBYTE
) (pbyPayloadHead
+ 6);
1998 memcpy(pbyType
, &(psEthHeader
->wType
), sizeof(WORD
));
2002 cbReqCount
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
);
2003 //---------------------------
2004 // S/W or H/W Encryption
2005 //---------------------------
2007 //if (pDevice->bAES) {
2008 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
2009 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFrameBodySize);
2012 pbyBuffer
= (PBYTE
)pHeadTD
->pTDInfo
->buf
;
2013 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
2015 uLength
= cbHeaderLength
+ cbMACHdLen
+ uPadding
+ cbIVlen
+ cb802_1_H_len
;
2017 //copy TxBufferHeader + MacHeader to desc
2018 memcpy(pbyBuffer
, (void *)psTxBufHd
, uLength
);
2020 // Copy the Packet into a tx Buffer
2021 memcpy((pbyBuffer
+ uLength
),
2023 cbFrameBodySize
- cb802_1_H_len
2026 if ((bNeedEncrypt
== TRUE
) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)){
2028 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Length:%d, %d\n", cbFrameBodySize
- cb802_1_H_len
, uLength
);
2030 for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
2031 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
2033 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2036 MIC_vAppend((pbyBuffer
+ uLength
- cb802_1_H_len
), cbFrameBodySize
);
2038 pdwMIC_L
= (PDWORD
)(pbyBuffer
+ uLength
- cb802_1_H_len
+ cbFrameBodySize
);
2039 pdwMIC_R
= (PDWORD
)(pbyBuffer
+ uLength
- cb802_1_H_len
+ cbFrameBodySize
+ 4);
2041 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
2045 if (pDevice
->bTxMICFail
== TRUE
) {
2048 pDevice
->bTxMICFail
= FALSE
;
2051 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uLength: %d, %d\n", uLength
, cbFrameBodySize
);
2052 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"cbReqCount:%d, %d, %d, %d\n", cbReqCount
, cbHeaderLength
, uPadding
, cbIVlen
);
2053 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC:%lx, %lx\n", *pdwMIC_L
, *pdwMIC_R
);
2055 for (ii = 0; ii < 8; ii++) {
2056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((PBYTE)(pdwMIC_L) + ii)));
2058 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2064 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)){
2066 s_vSWencryption(pDevice
, pTransmitKey
, (pbyBuffer
+ uLength
- cb802_1_H_len
),
2067 (WORD
)(cbFrameBodySize
+ cbMIClen
));
2068 cbReqCount
+= cbICVlen
;
2073 ptdCurr
= (PSTxDesc
)pHeadTD
;
2075 ptdCurr
->pTDInfo
->dwReqCount
= cbReqCount
- uPadding
;
2076 ptdCurr
->pTDInfo
->dwHeaderLength
= cbHeaderLength
;
2077 ptdCurr
->pTDInfo
->skb_dma
= ptdCurr
->pTDInfo
->buf_dma
;
2078 ptdCurr
->buff_addr
= cpu_to_le32(ptdCurr
->pTDInfo
->skb_dma
);
2079 //Set TSR1 & ReqCount in TxDescHead
2080 ptdCurr
->m_td1TD1
.byTCR
|= (TCR_STP
| TCR_EDP
| EDMSDU
);
2081 ptdCurr
->m_td1TD1
.wReqCount
= cpu_to_le16((WORD
)(cbReqCount
));
2083 pDevice
->iTDUsed
[uDMAIdx
]++;
2086 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
2087 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
2090 *puMACfragNum
= uMACfragNum
;
2091 //DBG_PRTGRP03(("s_cbFillTxBufHead END\n"));
2092 return cbHeaderLength
;
2097 vGenerateFIFOHeader (
2100 PBYTE pbyTxBufferAddr
,
2105 PSEthernetHeader psEthHeader
,
2107 PSKeyItem pTransmitKey
,
2113 UINT wTxBufSize
; // FFinfo size
2117 PSTxBufHead pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
2119 wTxBufSize
= sizeof(STxBufHead
);
2121 memset(pTxBufHead
, 0, wTxBufSize
);
2122 //Set FIFOCTL_NEEDACK
2124 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
2125 (pDevice
->eOPMode
== OP_MODE_AP
)) {
2126 if (IS_MULTICAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0])) ||
2127 IS_BROADCAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0]))) {
2129 pTxBufHead
->wFIFOCtl
= pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
2133 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2138 // MSDUs in Infra mode always need ACK
2140 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2145 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
2146 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us
);
2149 if (pDevice
->bLongHeader
)
2150 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LHEAD
;
2152 //Set FIFOCTL_GENINT
2154 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GENINT
;
2157 //Set FIFOCTL_ISDMA0
2158 if (TYPE_TXDMA0
== uDMAIdx
) {
2159 pTxBufHead
->wFIFOCtl
|= FIFOCTL_ISDMA0
;
2162 //Set FRAGCTL_MACHDCNT
2163 if (pDevice
->bLongHeader
) {
2164 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
2166 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
2168 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)(cbMacHdLen
<< 10));
2171 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
2174 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
2175 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2177 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
2178 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
2180 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
2181 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
2183 //Set FIFOCTL_GrpAckPolicy
2184 if (pDevice
->bGrpAckPolicy
== TRUE
) {//0000 0100 0000 0000
2185 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
2188 //Set Auto Fallback Ctl
2189 if (pDevice
->wCurrentRate
>= RATE_18M
) {
2190 if (pDevice
->byAutoFBCtrl
== AUTO_FB_0
) {
2191 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_0
;
2192 } else if (pDevice
->byAutoFBCtrl
== AUTO_FB_1
) {
2193 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_1
;
2197 //Set FRAGCTL_WEPTYP
2198 pDevice
->bAES
= FALSE
;
2200 //Set FRAGCTL_WEPTYP
2201 if (pDevice
->byLocalID
> REV_ID_VT3253_A1
) {
2202 if ((bNeedEncrypt
) && (pTransmitKey
!= NULL
)) { //WEP enabled
2203 if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
2204 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
2206 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) { //WEP40 or WEP104
2207 if (pTransmitKey
->uKeyLength
!= WLAN_WEP232_KEYLEN
)
2208 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
2210 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) { //CCMP
2211 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
2217 //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2219 //if (pDevice->wCurrentRate <= 3)
2221 // RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
2225 RFbSetPower(pDevice
, pDevice
->wCurrentRate
, pDevice
->byCurrentCh
);
2227 //if (pDevice->wCurrentRate == 3)
2228 //pDevice->byCurPwr = 46;
2229 pTxBufHead
->byTxPower
= pDevice
->byCurPwr
;
2235 if(pDevice->bEnableHostWEP)
2236 pTxBufHead->wFragCtl &= ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
2238 *pcbHeaderSize
= s_cbFillTxBufHead(pDevice
, byPktType
, pbyTxBufferAddr
, cbPayloadSize
,
2239 uDMAIdx
, pHeadTD
, psEthHeader
, pPacket
, bNeedEncrypt
,
2240 pTransmitKey
, uNodeIndex
, puMACfragNum
);
2251 * Translate 802.3 to 802.11 header
2255 * pDevice - Pointer to adapter
2256 * dwTxBufferAddr - Transmit Buffer
2257 * pPacket - Packet from upper layer
2258 * cbPacketSize - Transmit Data Length
2260 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
2261 * pcbAppendPayload - size of append payload for 802.1H translation
2263 * Return Value: none
2268 vGenerateMACHeader (
2270 PBYTE pbyBufferAddr
,
2272 PSEthernetHeader psEthHeader
,
2279 PS802_11Header pMACHeader
= (PS802_11Header
)pbyBufferAddr
;
2281 memset(pMACHeader
, 0, (sizeof(S802_11Header
))); //- sizeof(pMACHeader->dwIV)));
2283 if (uDMAIdx
== TYPE_ATIMDMA
) {
2284 pMACHeader
->wFrameCtl
= TYPE_802_11_ATIM
;
2286 pMACHeader
->wFrameCtl
= TYPE_802_11_DATA
;
2289 if (pDevice
->eOPMode
== OP_MODE_AP
) {
2290 memcpy(&(pMACHeader
->abyAddr1
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
2291 memcpy(&(pMACHeader
->abyAddr2
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
2292 memcpy(&(pMACHeader
->abyAddr3
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
2293 pMACHeader
->wFrameCtl
|= FC_FROMDS
;
2296 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2297 memcpy(&(pMACHeader
->abyAddr1
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
2298 memcpy(&(pMACHeader
->abyAddr2
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
2299 memcpy(&(pMACHeader
->abyAddr3
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
2302 memcpy(&(pMACHeader
->abyAddr3
[0]), &(psEthHeader
->abyDstAddr
[0]), ETH_ALEN
);
2303 memcpy(&(pMACHeader
->abyAddr2
[0]), &(psEthHeader
->abySrcAddr
[0]), ETH_ALEN
);
2304 memcpy(&(pMACHeader
->abyAddr1
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
2305 pMACHeader
->wFrameCtl
|= FC_TODS
;
2310 pMACHeader
->wFrameCtl
|= cpu_to_le16((WORD
)WLAN_SET_FC_ISWEP(1));
2312 pMACHeader
->wDurationID
= cpu_to_le16(wDuration
);
2314 if (pDevice
->bLongHeader
) {
2315 PWLAN_80211HDR_A4 pMACA4Header
= (PWLAN_80211HDR_A4
) pbyBufferAddr
;
2316 pMACHeader
->wFrameCtl
|= (FC_TODS
| FC_FROMDS
);
2317 memcpy(pMACA4Header
->abyAddr4
, pDevice
->abyBSSID
, WLAN_ADDR_LEN
);
2319 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2321 //Set FragNumber in Sequence Control
2322 pMACHeader
->wSeqCtl
|= cpu_to_le16((WORD
)uFragIdx
);
2324 if ((wFragType
== FRAGCTL_ENDFRAG
) || (wFragType
== FRAGCTL_NONFRAG
)) {
2325 pDevice
->wSeqCounter
++;
2326 if (pDevice
->wSeqCounter
> 0x0fff)
2327 pDevice
->wSeqCounter
= 0;
2330 if ((wFragType
== FRAGCTL_STAFRAG
) || (wFragType
== FRAGCTL_MIDFRAG
)) { //StartFrag or MidFrag
2331 pMACHeader
->wFrameCtl
|= FC_MOREFRAG
;
2340 CMD_STATUS
csMgmt_xmit(PSDevice pDevice
, PSTxMgmtPacket pPacket
) {
2344 PBYTE pbyTxBufferAddr
;
2350 PS802_11Header pMACHeader
;
2352 UINT cbFrameBodySize
;
2354 BOOL bIsPSPOLL
= FALSE
;
2355 PSTxBufHead pTxBufHead
;
2364 SEthernetHeader sEthHeader
;
2367 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
2368 WORD wCurrentRate
= RATE_1M
;
2371 if (AVAIL_TD(pDevice
, TYPE_TXDMA0
) <= 0) {
2372 return CMD_STATUS_RESOURCES
;
2375 pFrstTD
= pDevice
->apCurrTD
[TYPE_TXDMA0
];
2376 pbyTxBufferAddr
= (PBYTE
)pFrstTD
->pTDInfo
->buf
;
2377 cbFrameBodySize
= pPacket
->cbPayloadLen
;
2378 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
2379 wTxBufSize
= sizeof(STxBufHead
);
2380 memset(pTxBufHead
, 0, wTxBufSize
);
2382 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) {
2383 wCurrentRate
= RATE_6M
;
2384 byPktType
= PK_TYPE_11A
;
2386 wCurrentRate
= RATE_1M
;
2387 byPktType
= PK_TYPE_11B
;
2390 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2391 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2392 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2393 // to set power here.
2394 if (pDevice
->pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
2396 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
2398 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
2400 pTxBufHead
->byTxPower
= pDevice
->byCurPwr
;
2401 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2402 if (pDevice
->byFOETuning
) {
2403 if ((pPacket
->p80211Header
->sA3
.wFrameCtl
& TYPE_DATE_NULL
) == TYPE_DATE_NULL
) {
2404 wCurrentRate
= RATE_24M
;
2405 byPktType
= PK_TYPE_11GA
;
2410 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
2411 pTxBufHead
->wFIFOCtl
= 0;
2413 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
2414 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2416 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
2417 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
2419 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
2420 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
2423 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
2424 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
2427 if (IS_MULTICAST_ADDRESS(&(pPacket
->p80211Header
->sA3
.abyAddr1
[0])) ||
2428 IS_BROADCAST_ADDRESS(&(pPacket
->p80211Header
->sA3
.abyAddr1
[0]))) {
2433 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2436 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
2437 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
2439 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
2440 //Set Preamble type always long
2441 //pDevice->byPreambleType = PREAMBLE_LONG;
2442 // probe-response don't retry
2443 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2444 // bNeedACK = FALSE;
2445 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2449 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
2451 if ((pPacket
->p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
2453 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
2455 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
2458 //Set FRAGCTL_MACHDCNT
2459 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)(cbMacHdLen
<< 10));
2462 // Although spec says MMPDU can be fragmented; In most case,
2463 // no one will send a MMPDU under fragmentation. With RTS may occur.
2464 pDevice
->bAES
= FALSE
; //Set FRAGCTL_WEPTYP
2466 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
2467 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
2470 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
2472 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
2473 cbIVlen
= 8;//IV+ExtIV
2476 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
2477 //We need to get seed here for filling TxKey entry.
2478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2481 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
2482 cbIVlen
= 8;//RSN Header
2484 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
2485 pDevice
->bAES
= TRUE
;
2487 //MAC Header should be padding 0 to DW alignment.
2488 uPadding
= 4 - (cbMacHdLen
%4);
2492 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
;
2494 //Set FIFOCTL_GrpAckPolicy
2495 if (pDevice
->bGrpAckPolicy
== TRUE
) {//0000 0100 0000 0000
2496 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
2498 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2500 //Set RrvTime/RTS/CTS Buffer
2501 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
2503 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
2506 pCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
2507 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + sizeof(SCTS
));
2508 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + sizeof(SCTS
) + sizeof(STxDataHead_g
);
2510 else { // 802.11a/b packet
2511 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2515 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
2516 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_ab
) + sizeof(STxDataHead_ab
);
2519 memset((void *)(pbyTxBufferAddr
+ wTxBufSize
), 0, (cbHeaderSize
- wTxBufSize
));
2521 memcpy(&(sEthHeader
.abyDstAddr
[0]), &(pPacket
->p80211Header
->sA3
.abyAddr1
[0]), ETH_ALEN
);
2522 memcpy(&(sEthHeader
.abySrcAddr
[0]), &(pPacket
->p80211Header
->sA3
.abyAddr2
[0]), ETH_ALEN
);
2523 //=========================
2525 //=========================
2526 pTxBufHead
->wFragCtl
|= (WORD
)FRAGCTL_NONFRAG
;
2529 //Fill FIFO,RrvTime,RTS,and CTS
2530 s_vGenerateTxParameter(pDevice
, byPktType
, pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pCTS
,
2531 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
, wCurrentRate
);
2534 uDuration
= s_uFillDataHead(pDevice
, byPktType
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
2535 0, 0, 1, AUTO_FB_NONE
, wCurrentRate
);
2537 pMACHeader
= (PS802_11Header
) (pbyTxBufferAddr
+ cbHeaderSize
);
2539 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ cbFrameBodySize
;
2541 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
2543 PBYTE pbyPayloadHead
;
2545 PSKeyItem pTransmitKey
= NULL
;
2547 pbyIVHead
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
);
2548 pbyPayloadHead
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
2551 //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet.
2552 //s_vFillTxKey(pDevice, (PBYTE)pTxBufHead->adwTxKey, NULL);
2554 //Fill IV(ExtIV,RSNHDR)
2555 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
2556 //---------------------------
2557 // S/W or H/W Encryption
2558 //---------------------------
2560 //if (pDevice->bAES) {
2561 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, (PBYTE)pMACHeader, (WORD)cbFrameBodySize);
2564 if ((pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
2565 (pDevice
->bLinkPass
== TRUE
)) {
2566 pbyBSSID
= pDevice
->abyBSSID
;
2568 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == FALSE
) {
2570 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == TRUE
) {
2571 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
2575 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get PTK.\n");
2580 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2581 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == FALSE
) {
2582 pTransmitKey
= NULL
;
2583 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KEY is NULL. OP Mode[%d]\n", pDevice
->eOPMode
);
2585 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
2589 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
2590 (PBYTE
)pMACHeader
, (WORD
)cbFrameBodySize
, NULL
);
2592 memcpy(pMACHeader
, pPacket
->p80211Header
, cbMacHdLen
);
2593 memcpy(pbyPayloadHead
, ((PBYTE
)(pPacket
->p80211Header
) + cbMacHdLen
),
2597 // Copy the Packet into a tx Buffer
2598 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
2601 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2602 pDevice
->wSeqCounter
++ ;
2603 if (pDevice
->wSeqCounter
> 0x0fff)
2604 pDevice
->wSeqCounter
= 0;
2607 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2608 // of FIFO control header.
2609 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2610 // in the same place of other packet's Duration-field).
2611 // And it will cause Cisco-AP to issue Disassociation-packet
2612 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
2613 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_a
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
2614 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_b
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
2616 ((PSTxDataHead_ab
)pvTxDataHd
)->wDuration
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
2621 // first TD is the only TD
2622 //Set TSR1 & ReqCount in TxDescHead
2623 pFrstTD
->m_td1TD1
.byTCR
= (TCR_STP
| TCR_EDP
| EDMSDU
);
2624 pFrstTD
->pTDInfo
->skb_dma
= pFrstTD
->pTDInfo
->buf_dma
;
2625 pFrstTD
->m_td1TD1
.wReqCount
= cpu_to_le16((WORD
)(cbReqCount
));
2626 pFrstTD
->buff_addr
= cpu_to_le32(pFrstTD
->pTDInfo
->skb_dma
);
2627 pFrstTD
->pTDInfo
->byFlags
= 0;
2629 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
)) {
2631 MACbPSWakeup(pDevice
->PortOffset
);
2633 pDevice
->bPWBitOn
= FALSE
;
2636 pFrstTD
->m_td0TD0
.f1Owner
= OWNED_BY_NIC
;
2639 pDevice
->iTDUsed
[TYPE_TXDMA0
]++;
2641 if (AVAIL_TD(pDevice
, TYPE_TXDMA0
) <= 1) {
2642 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" available td0 <= 1\n");
2645 pDevice
->apCurrTD
[TYPE_TXDMA0
] = pFrstTD
->next
;
2647 //printk("SCAN:CurrentRate is %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
2651 pDevice
->nTxDataTimeCout
=0; //2008-8-21 chester <add> for send null packet
2654 // Poll Transmit the adapter
2655 MACvTransmit0(pDevice
->PortOffset
);
2657 return CMD_STATUS_PENDING
;
2662 CMD_STATUS
csBeacon_xmit(PSDevice pDevice
, PSTxMgmtPacket pPacket
) {
2665 PBYTE pbyBuffer
= (PBYTE
)pDevice
->tx_beacon_bufs
;
2666 UINT cbFrameSize
= pPacket
->cbMPDULen
+ WLAN_FCS_LEN
;
2667 UINT cbHeaderSize
= 0;
2668 WORD wTxBufSize
= sizeof(STxShortBufHead
);
2669 PSTxShortBufHead pTxBufHead
= (PSTxShortBufHead
) pbyBuffer
;
2670 PSTxDataHead_ab pTxDataHead
= (PSTxDataHead_ab
) (pbyBuffer
+ wTxBufSize
);
2671 PS802_11Header pMACHeader
;
2676 memset(pTxBufHead
, 0, wTxBufSize
);
2678 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) {
2679 wCurrentRate
= RATE_6M
;
2680 byPktType
= PK_TYPE_11A
;
2682 wCurrentRate
= RATE_2M
;
2683 byPktType
= PK_TYPE_11B
;
2686 //Set Preamble type always long
2687 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2689 //Set FIFOCTL_GENINT
2691 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GENINT
;
2694 //Set packet type & Get Duration
2695 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
2696 pTxDataHead
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameSize
, byPktType
,
2697 wCurrentRate
, FALSE
, 0, 0, 1, AUTO_FB_NONE
));
2699 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
2700 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2701 pTxDataHead
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameSize
, byPktType
,
2702 wCurrentRate
, FALSE
, 0, 0, 1, AUTO_FB_NONE
));
2705 BBvCaculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, byPktType
,
2706 (PWORD
)&(wLen
), (PBYTE
)&(pTxDataHead
->byServiceField
), (PBYTE
)&(pTxDataHead
->bySignalField
)
2708 pTxDataHead
->wTransmitLength
= cpu_to_le16(wLen
);
2710 pTxDataHead
->wTimeStampOff
= cpu_to_le16(wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
]);
2711 cbHeaderSize
= wTxBufSize
+ sizeof(STxDataHead_ab
);
2713 //Generate Beacon Header
2714 pMACHeader
= (PS802_11Header
)(pbyBuffer
+ cbHeaderSize
);
2715 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
2717 pMACHeader
->wDurationID
= 0;
2718 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2719 pDevice
->wSeqCounter
++ ;
2720 if (pDevice
->wSeqCounter
> 0x0fff)
2721 pDevice
->wSeqCounter
= 0;
2723 // Set Beacon buffer length
2724 pDevice
->wBCNBufLen
= pPacket
->cbMPDULen
+ cbHeaderSize
;
2726 MACvSetCurrBCNTxDescAddr(pDevice
->PortOffset
, (pDevice
->tx_beacon_dma
));
2728 MACvSetCurrBCNLength(pDevice
->PortOffset
, pDevice
->wBCNBufLen
);
2729 // Set auto Transmit on
2730 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
2731 // Poll Transmit the adapter
2732 MACvTransmitBCN(pDevice
->PortOffset
);
2734 return CMD_STATUS_PENDING
;
2742 PSKeyItem pTransmitKey
,
2743 UINT cbFrameBodySize
,
2744 PSEthernetHeader psEthHeader
2749 UINT cbFragmentSize
; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
2750 UINT cbFragPayloadSize
;
2751 UINT cbLastFragPayloadSize
;
2756 UINT uMACfragNum
= 1;
2761 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
2762 (pDevice
->eOPMode
== OP_MODE_AP
)) {
2763 if (IS_MULTICAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0])) ||
2764 IS_BROADCAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0]))) {
2772 // MSDUs in Infra mode always need ACK
2776 if (pDevice
->bLongHeader
)
2777 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
2779 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
;
2782 if (pDevice
->bEncryptionEnable
== TRUE
) {
2784 if (pTransmitKey
== NULL
) {
2785 if ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) ||
2786 (pDevice
->pMgmt
->eAuthenMode
< WMAC_AUTH_WPA
)) {
2789 } else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
2790 cbIVlen
= 8;//IV+ExtIV
2793 } else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
2794 cbIVlen
= 8;//RSN Header
2797 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
2800 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
2801 cbIVlen
= 8;//IV+ExtIV
2804 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
2805 cbIVlen
= 8;//RSN Header
2810 cbFrameSize
= cbMACHdLen
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbICVlen
+ cbFCSlen
;
2812 if ((cbFrameSize
> pDevice
->wFragmentationThreshold
) && (bNeedACK
== TRUE
)) {
2814 cbFragmentSize
= pDevice
->wFragmentationThreshold
;
2815 cbFragPayloadSize
= cbFragmentSize
- cbMACHdLen
- cbIVlen
- cbICVlen
- cbFCSlen
;
2816 uMACfragNum
= (WORD
) ((cbFrameBodySize
+ cbMIClen
) / cbFragPayloadSize
);
2817 cbLastFragPayloadSize
= (cbFrameBodySize
+ cbMIClen
) % cbFragPayloadSize
;
2818 if (cbLastFragPayloadSize
== 0) {
2819 cbLastFragPayloadSize
= cbFragPayloadSize
;
2829 vDMA0_tx_80211(PSDevice pDevice
, struct sk_buff
*skb
, PBYTE pbMPDU
, UINT cbMPDULen
) {
2833 PBYTE pbyTxBufferAddr
;
2839 PS802_11Header pMACHeader
;
2841 UINT cbFrameBodySize
;
2843 BOOL bIsPSPOLL
= FALSE
;
2844 PSTxBufHead pTxBufHead
;
2853 DWORD dwMICKey0
, dwMICKey1
;
2854 DWORD dwMIC_Priority
;
2859 SEthernetHeader sEthHeader
;
2862 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
2863 WORD wCurrentRate
= RATE_1M
;
2864 PUWLAN_80211HDR p80211Header
;
2865 UINT uNodeIndex
= 0;
2866 BOOL bNodeExist
= FALSE
;
2868 PSKeyItem pTransmitKey
= NULL
;
2870 PBYTE pbyPayloadHead
;
2873 UINT cbExtSuppRate
= 0;
2877 pvRrvTime
= pMICHDR
= pvRTS
= pvCTS
= pvTxDataHd
= NULL
;
2879 if(cbMPDULen
<= WLAN_HDR_ADDR3_LEN
) {
2880 cbFrameBodySize
= 0;
2883 cbFrameBodySize
= cbMPDULen
- WLAN_HDR_ADDR3_LEN
;
2885 p80211Header
= (PUWLAN_80211HDR
)pbMPDU
;
2888 pFrstTD
= pDevice
->apCurrTD
[TYPE_TXDMA0
];
2889 pbyTxBufferAddr
= (PBYTE
)pFrstTD
->pTDInfo
->buf
;
2890 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
2891 wTxBufSize
= sizeof(STxBufHead
);
2892 memset(pTxBufHead
, 0, wTxBufSize
);
2894 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) {
2895 wCurrentRate
= RATE_6M
;
2896 byPktType
= PK_TYPE_11A
;
2898 wCurrentRate
= RATE_1M
;
2899 byPktType
= PK_TYPE_11B
;
2902 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2903 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2904 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2905 // to set power here.
2906 if (pDevice
->pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
2907 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
2909 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
2911 pTxBufHead
->byTxPower
= pDevice
->byCurPwr
;
2913 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2914 if (pDevice
->byFOETuning
) {
2915 if ((p80211Header
->sA3
.wFrameCtl
& TYPE_DATE_NULL
) == TYPE_DATE_NULL
) {
2916 wCurrentRate
= RATE_24M
;
2917 byPktType
= PK_TYPE_11GA
;
2921 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header
->sA3
.wFrameCtl
);
2924 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
2925 pTxBufHead
->wFIFOCtl
= 0;
2927 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
2928 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2930 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
2931 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
2933 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
2934 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
2937 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
2938 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
2941 if (IS_MULTICAST_ADDRESS(&(p80211Header
->sA3
.abyAddr1
[0])) ||
2942 IS_BROADCAST_ADDRESS(&(p80211Header
->sA3
.abyAddr1
[0]))) {
2944 if (pDevice
->bEnableHostWEP
) {
2950 if (pDevice
->bEnableHostWEP
) {
2951 if (BSSDBbIsSTAInNodeDB(pDevice
->pMgmt
, (PBYTE
)(p80211Header
->sA3
.abyAddr1
), &uNodeIndex
))
2955 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2958 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
2959 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
2961 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
2962 //Set Preamble type always long
2963 //pDevice->byPreambleType = PREAMBLE_LONG;
2965 // probe-response don't retry
2966 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2967 // bNeedACK = FALSE;
2968 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2972 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
2974 if ((p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
2976 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
2978 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
2981 // hostapd deamon ext support rate patch
2982 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
2984 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0) {
2985 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
;
2988 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0) {
2989 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
;
2992 if (cbExtSuppRate
>0) {
2993 cbFrameBodySize
= WLAN_ASSOCRESP_OFF_SUPP_RATES
;
2998 //Set FRAGCTL_MACHDCNT
2999 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)cbMacHdLen
<< 10);
3002 // Although spec says MMPDU can be fragmented; In most case,
3003 // no one will send a MMPDU under fragmentation. With RTS may occur.
3004 pDevice
->bAES
= FALSE
; //Set FRAGCTL_WEPTYP
3007 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
3008 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
3011 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
3013 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
3014 cbIVlen
= 8;//IV+ExtIV
3017 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
3018 //We need to get seed here for filling TxKey entry.
3019 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
3020 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
3022 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
3023 cbIVlen
= 8;//RSN Header
3025 cbMICHDR
= sizeof(SMICHDRHead
);
3026 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
3027 pDevice
->bAES
= TRUE
;
3029 //MAC Header should be padding 0 to DW alignment.
3030 uPadding
= 4 - (cbMacHdLen
%4);
3034 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
+ cbExtSuppRate
;
3036 //Set FIFOCTL_GrpAckPolicy
3037 if (pDevice
->bGrpAckPolicy
== TRUE
) {//0000 0100 0000 0000
3038 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
3040 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
3043 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
3045 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
3046 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
3048 pvCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
3049 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
));
3050 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
) + sizeof(STxDataHead_g
);
3053 else {//802.11a/b packet
3055 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
3056 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
3059 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
3060 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_ab
);
3064 memset((void *)(pbyTxBufferAddr
+ wTxBufSize
), 0, (cbHeaderSize
- wTxBufSize
));
3065 memcpy(&(sEthHeader
.abyDstAddr
[0]), &(p80211Header
->sA3
.abyAddr1
[0]), ETH_ALEN
);
3066 memcpy(&(sEthHeader
.abySrcAddr
[0]), &(p80211Header
->sA3
.abyAddr2
[0]), ETH_ALEN
);
3067 //=========================
3069 //=========================
3070 pTxBufHead
->wFragCtl
|= (WORD
)FRAGCTL_NONFRAG
;
3073 //Fill FIFO,RrvTime,RTS,and CTS
3074 s_vGenerateTxParameter(pDevice
, byPktType
, pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pvCTS
,
3075 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
, wCurrentRate
);
3078 uDuration
= s_uFillDataHead(pDevice
, byPktType
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
3079 0, 0, 1, AUTO_FB_NONE
, wCurrentRate
);
3081 pMACHeader
= (PS802_11Header
) (pbyTxBufferAddr
+ cbHeaderSize
);
3083 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbExtSuppRate
;
3085 pbyMacHdr
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
);
3086 pbyPayloadHead
= (PBYTE
)(pbyMacHdr
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
3087 pbyIVHead
= (PBYTE
)(pbyMacHdr
+ cbMacHdLen
+ uPadding
);
3089 // Copy the Packet into a tx Buffer
3090 memcpy(pbyMacHdr
, pbMPDU
, cbMacHdLen
);
3092 // version set to 0, patch for hostapd deamon
3093 pMACHeader
->wFrameCtl
&= cpu_to_le16(0xfffc);
3094 memcpy(pbyPayloadHead
, (pbMPDU
+ cbMacHdLen
), cbFrameBodySize
);
3096 // replace support rate, patch for hostapd deamon( only support 11M)
3097 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
3098 if (cbExtSuppRate
!= 0) {
3099 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0)
3100 memcpy((pbyPayloadHead
+ cbFrameBodySize
),
3101 pMgmt
->abyCurrSuppRates
,
3102 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
3104 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0)
3105 memcpy((pbyPayloadHead
+ cbFrameBodySize
) + ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
,
3106 pMgmt
->abyCurrExtSuppRates
,
3107 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
3113 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
3115 if (pDevice
->bEnableHostWEP
) {
3116 pTransmitKey
= &STempKey
;
3117 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
3118 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
3119 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
3120 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
3121 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
3122 memcpy(pTransmitKey
->abyKey
,
3123 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
3124 pTransmitKey
->uKeyLength
3128 if ((pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
3130 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
3131 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
3133 // DO Software Michael
3134 MIC_vInit(dwMICKey0
, dwMICKey1
);
3135 MIC_vAppend((PBYTE
)&(sEthHeader
.abyDstAddr
[0]), 12);
3137 MIC_vAppend((PBYTE
)&dwMIC_Priority
, 4);
3138 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0
, dwMICKey1
);
3140 uLength
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
;
3142 MIC_vAppend((pbyTxBufferAddr
+ uLength
), cbFrameBodySize
);
3144 pdwMIC_L
= (PDWORD
)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
);
3145 pdwMIC_R
= (PDWORD
)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
+ 4);
3147 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
3150 if (pDevice
->bTxMICFail
== TRUE
) {
3153 pDevice
->bTxMICFail
= FALSE
;
3156 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uLength: %d, %d\n", uLength
, cbFrameBodySize
);
3157 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"cbReqCount:%d, %d, %d, %d\n", cbReqCount
, cbHeaderSize
, uPadding
, cbIVlen
);
3158 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC:%lx, %lx\n", *pdwMIC_L
, *pdwMIC_R
);
3163 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
3164 pbyMacHdr
, (WORD
)cbFrameBodySize
, (PBYTE
)pMICHDR
);
3166 if (pDevice
->bEnableHostWEP
) {
3167 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
3168 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
3171 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
3172 s_vSWencryption(pDevice
, pTransmitKey
, pbyPayloadHead
, (WORD
)(cbFrameBodySize
+ cbMIClen
));
3176 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
3177 pDevice
->wSeqCounter
++ ;
3178 if (pDevice
->wSeqCounter
> 0x0fff)
3179 pDevice
->wSeqCounter
= 0;
3183 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
3184 // of FIFO control header.
3185 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
3186 // in the same place of other packet's Duration-field).
3187 // And it will cause Cisco-AP to issue Disassociation-packet
3188 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
3189 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_a
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
3190 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_b
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
3192 ((PSTxDataHead_ab
)pvTxDataHd
)->wDuration
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
3197 // first TD is the only TD
3198 //Set TSR1 & ReqCount in TxDescHead
3199 pFrstTD
->pTDInfo
->skb
= skb
;
3200 pFrstTD
->m_td1TD1
.byTCR
= (TCR_STP
| TCR_EDP
| EDMSDU
);
3201 pFrstTD
->pTDInfo
->skb_dma
= pFrstTD
->pTDInfo
->buf_dma
;
3202 pFrstTD
->m_td1TD1
.wReqCount
= cpu_to_le16(cbReqCount
);
3203 pFrstTD
->buff_addr
= cpu_to_le32(pFrstTD
->pTDInfo
->skb_dma
);
3204 pFrstTD
->pTDInfo
->byFlags
= 0;
3205 pFrstTD
->pTDInfo
->byFlags
|= TD_FLAGS_PRIV_SKB
;
3207 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
)) {
3209 MACbPSWakeup(pDevice
->PortOffset
);
3211 pDevice
->bPWBitOn
= FALSE
;
3214 pFrstTD
->m_td0TD0
.f1Owner
= OWNED_BY_NIC
;
3217 pDevice
->iTDUsed
[TYPE_TXDMA0
]++;
3219 if (AVAIL_TD(pDevice
, TYPE_TXDMA0
) <= 1) {
3220 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" available td0 <= 1\n");
3223 pDevice
->apCurrTD
[TYPE_TXDMA0
] = pFrstTD
->next
;
3225 // Poll Transmit the adapter
3226 MACvTransmit0(pDevice
->PortOffset
);