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 requried parameter.
29 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
34 * s_uGetRTSCTSDuration- get rtx/cts requried duration
35 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
38 * s_vFillFragParameter- Set fragement ctl parameter.
39 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
65 #ifdef WPA_SM_Transtatus
69 /*--------------------- Static Definitions -------------------------*/
71 /*--------------------- Static Classes ----------------------------*/
73 /*--------------------- Static Variables --------------------------*/
74 //static int msglevel =MSG_LEVEL_DEBUG;
75 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 --------------------------*/
120 IN PBYTE pbyDestAddr
,
134 s_vGenerateTxParameter(
137 IN WORD wCurrentRate
,
145 IN PSEthernetHeader psEthHeader
154 IN WORD wCurrentRate
,
155 IN PVOID pTxDataHead
,
156 IN UINT cbFrameLength
,
160 IN UINT cbLastFragmentSize
,
170 s_vGenerateMACHeader (
172 IN PBYTE pbyBufferAddr
,
174 IN PSEthernetHeader psEthHeader
,
175 IN BOOL bNeedEncrypt
,
187 IN PSKeyItem pTransmitKey
,
197 IN PSKeyItem pTransmitKey
,
198 IN PBYTE pbyPayloadHead
,
207 IN UINT cbFrameLength
,
215 s_uGetRTSCTSRsvTime (
217 IN BYTE byRTSRsvType
,
219 IN UINT cbFrameLength
,
230 IN UINT cbFrameLength
,
233 IN WORD wCurrentRate
,
243 IN UINT cbFrameLength
,
246 IN PSEthernetHeader psEthHeader
,
247 IN WORD wCurrentRate
,
256 IN UINT cbFrameLength
,
261 IN UINT cbLastFragmentSize
,
269 s_uGetRTSCTSDuration (
272 IN UINT cbFrameLength
,
280 /*--------------------- Export Variables --------------------------*/
288 PUSB_SEND_CONTEXT pContext
= NULL
;
289 PUSB_SEND_CONTEXT pReturnContext
= NULL
;
292 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GetFreeContext()\n");
294 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
295 pContext
= pDevice
->apTD
[ii
];
296 if (pContext
->bBoolInUse
== FALSE
) {
297 pContext
->bBoolInUse
= TRUE
;
298 pReturnContext
= pContext
;
302 if ( ii
== pDevice
->cbTD
) {
303 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Free Tx Context\n");
305 return ((PVOID
) pReturnContext
);
311 s_vSaveTxPktInfo(PSDevice pDevice
, BYTE byPktNum
, PBYTE pbyDestAddr
, WORD wPktLength
, WORD wFIFOCtl
)
313 PSStatCounter pStatistic
=&(pDevice
->scStatistic
);
316 if (IS_BROADCAST_ADDRESS(pbyDestAddr
))
317 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_BROAD
;
318 else if (IS_MULTICAST_ADDRESS(pbyDestAddr
))
319 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_MULTI
;
321 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_UNI
;
323 pStatistic
->abyTxPktInfo
[byPktNum
].wLength
= wPktLength
;
324 pStatistic
->abyTxPktInfo
[byPktNum
].wFIFOCtl
= wFIFOCtl
;
325 memcpy(pStatistic
->abyTxPktInfo
[byPktNum
].abyDestAddr
, pbyDestAddr
, U_ETHER_ADDR_LEN
);
337 IN PSKeyItem pTransmitKey
,
343 PDWORD pdwIV
= (PDWORD
) pbyIVHead
;
344 PDWORD pdwExtIV
= (PDWORD
) ((PBYTE
)pbyIVHead
+4);
346 PS802_11Header pMACHeader
= (PS802_11Header
)pbyHdrBuf
;
347 DWORD dwRevIVCounter
;
352 if (pTransmitKey
== NULL
)
355 dwRevIVCounter
= cpu_to_le32(pDevice
->dwIVCounter
);
356 *pdwIV
= pDevice
->dwIVCounter
;
357 pDevice
->byKeyIndex
= pTransmitKey
->dwKeyIndex
& 0xf;
359 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
360 if (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
){
361 memcpy(pDevice
->abyPRNG
, (PBYTE
)&(dwRevIVCounter
), 3);
362 memcpy(pDevice
->abyPRNG
+3, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
364 memcpy(pbyBuf
, (PBYTE
)&(dwRevIVCounter
), 3);
365 memcpy(pbyBuf
+3, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
366 if(pTransmitKey
->uKeyLength
== WLAN_WEP40_KEYLEN
) {
367 memcpy(pbyBuf
+8, (PBYTE
)&(dwRevIVCounter
), 3);
368 memcpy(pbyBuf
+11, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
370 memcpy(pDevice
->abyPRNG
, pbyBuf
, 16);
372 // Append IV after Mac Header
373 *pdwIV
&= WEP_IV_MASK
;//00000000 11111111 11111111 11111111
374 *pdwIV
|= (pDevice
->byKeyIndex
<< 30);
375 *pdwIV
= cpu_to_le32(*pdwIV
);
376 pDevice
->dwIVCounter
++;
377 if (pDevice
->dwIVCounter
> WEP_IV_MASK
) {
378 pDevice
->dwIVCounter
= 0;
380 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
381 pTransmitKey
->wTSC15_0
++;
382 if (pTransmitKey
->wTSC15_0
== 0) {
383 pTransmitKey
->dwTSC47_16
++;
385 TKIPvMixKey(pTransmitKey
->abyKey
, pDevice
->abyCurrentNetAddr
,
386 pTransmitKey
->wTSC15_0
, pTransmitKey
->dwTSC47_16
, pDevice
->abyPRNG
);
387 memcpy(pbyBuf
, pDevice
->abyPRNG
, 16);
389 memcpy(pdwIV
, pDevice
->abyPRNG
, 3);
391 *(pbyIVHead
+3) = (BYTE
)(((pDevice
->byKeyIndex
<< 6) & 0xc0) | 0x20); // 0x20 is ExtIV
392 // Append IV&ExtIV after Mac Header
393 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
394 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV
);
396 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
397 pTransmitKey
->wTSC15_0
++;
398 if (pTransmitKey
->wTSC15_0
== 0) {
399 pTransmitKey
->dwTSC47_16
++;
401 memcpy(pbyBuf
, pTransmitKey
->abyKey
, 16);
405 *(pbyIVHead
+3) = (BYTE
)(((pDevice
->byKeyIndex
<< 6) & 0xc0) | 0x20); // 0x20 is ExtIV
406 *pdwIV
|= cpu_to_le16((WORD
)(pTransmitKey
->wTSC15_0
));
407 //Append IV&ExtIV after Mac Header
408 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
412 *((PBYTE
)(pMICHDR
+1)) = 0; // TxPriority
413 memcpy(pMICHDR
+2, &(pMACHeader
->abyAddr2
[0]), 6);
414 *((PBYTE
)(pMICHDR
+8)) = HIBYTE(HIWORD(pTransmitKey
->dwTSC47_16
));
415 *((PBYTE
)(pMICHDR
+9)) = LOBYTE(HIWORD(pTransmitKey
->dwTSC47_16
));
416 *((PBYTE
)(pMICHDR
+10)) = HIBYTE(LOWORD(pTransmitKey
->dwTSC47_16
));
417 *((PBYTE
)(pMICHDR
+11)) = LOBYTE(LOWORD(pTransmitKey
->dwTSC47_16
));
418 *((PBYTE
)(pMICHDR
+12)) = HIBYTE(pTransmitKey
->wTSC15_0
);
419 *((PBYTE
)(pMICHDR
+13)) = LOBYTE(pTransmitKey
->wTSC15_0
);
420 *((PBYTE
)(pMICHDR
+14)) = HIBYTE(wPayloadLen
);
421 *((PBYTE
)(pMICHDR
+15)) = LOBYTE(wPayloadLen
);
424 *((PBYTE
)(pMICHDR
+16)) = 0; // HLEN[15:8]
425 if (pDevice
->bLongHeader
) {
426 *((PBYTE
)(pMICHDR
+17)) = 28; // HLEN[7:0]
428 *((PBYTE
)(pMICHDR
+17)) = 22; // HLEN[7:0]
430 wValue
= cpu_to_le16(pMACHeader
->wFrameCtl
& 0xC78F);
431 memcpy(pMICHDR
+18, (PBYTE
)&wValue
, 2); // MSKFRACTL
432 memcpy(pMICHDR
+20, &(pMACHeader
->abyAddr1
[0]), 6);
433 memcpy(pMICHDR
+26, &(pMACHeader
->abyAddr2
[0]), 6);
436 memcpy(pMICHDR
+32, &(pMACHeader
->abyAddr3
[0]), 6);
437 wValue
= pMACHeader
->wSeqCtl
;
439 wValue
= cpu_to_le16(wValue
);
440 memcpy(pMICHDR
+38, (PBYTE
)&wValue
, 2); // MSKSEQCTL
441 if (pDevice
->bLongHeader
) {
442 memcpy(pMICHDR
+40, &(pMACHeader
->abyAddr4
[0]), 6);
452 IN PSKeyItem pTransmitKey
,
453 IN PBYTE pbyPayloadHead
,
458 DWORD dwICV
= 0xFFFFFFFFL
;
461 if (pTransmitKey
== NULL
)
464 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
465 //=======================================================================
466 // Append ICV after payload
467 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
468 pdwICV
= (PDWORD
)(pbyPayloadHead
+ wPayloadSize
);
469 // finally, we must invert dwCRC to get the correct answer
470 *pdwICV
= cpu_to_le32(~dwICV
);
472 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pTransmitKey
->uKeyLength
+ 3);
473 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
474 //=======================================================================
475 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
476 //=======================================================================
477 //Append ICV after payload
478 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
479 pdwICV
= (PDWORD
)(pbyPayloadHead
+ wPayloadSize
);
480 // finally, we must invert dwCRC to get the correct answer
481 *pdwICV
= cpu_to_le32(~dwICV
);
483 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
484 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
485 //=======================================================================
492 /*byPktType : PK_TYPE_11A 0
502 IN UINT cbFrameLength
,
507 UINT uDataTime
, uAckTime
;
509 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wRate
);
510 if (byPktType
== PK_TYPE_11B
) {//llb,CCK mode
511 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (WORD
)pDevice
->byTopCCKBasicRate
);
512 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
513 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (WORD
)pDevice
->byTopOFDMBasicRate
);
517 return (uDataTime
+ pDevice
->uSIFS
+ uAckTime
);
524 //byFreqType: 0=>5GHZ 1=>2.4GHZ
527 s_uGetRTSCTSRsvTime (
529 IN BYTE byRTSRsvType
,
531 IN UINT cbFrameLength
,
535 UINT uRrvTime
, uRTSTime
, uCTSTime
, uAckTime
, uDataTime
;
537 uRrvTime
= uRTSTime
= uCTSTime
= uAckTime
= uDataTime
= 0;
540 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wCurrentRate
);
541 if (byRTSRsvType
== 0) { //RTSTxRrvTime_bb
542 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
543 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
545 else if (byRTSRsvType
== 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
546 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
547 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
548 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
550 else if (byRTSRsvType
== 2) { //RTSTxRrvTime_aa
551 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopOFDMBasicRate
);
552 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
554 else if (byRTSRsvType
== 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
555 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
556 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
557 uRrvTime
= uCTSTime
+ uAckTime
+ uDataTime
+ 2*pDevice
->uSIFS
;
562 uRrvTime
= uRTSTime
+ uCTSTime
+ uAckTime
+ uDataTime
+ 3*pDevice
->uSIFS
;
566 //byFreqType 0: 5GHz, 1:2.4Ghz
572 IN UINT cbFrameLength
,
577 IN UINT cbLastFragmentSize
,
583 UINT uAckTime
=0, uNextPktTime
= 0;
586 if (uFragIdx
== (uMACfragNum
-1)) {
592 case DATADUR_B
: //DATADUR_B
593 if (((uMACfragNum
== 1)) || (bLastFrag
== 1)) {//Non Frag or Last Frag
595 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
596 return (pDevice
->uSIFS
+ uAckTime
);
601 else {//First Frag or Mid Frag
602 if (uFragIdx
== (uMACfragNum
-2)) {
603 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wRate
, bNeedAck
);
605 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
608 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
609 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
611 return (pDevice
->uSIFS
+ uNextPktTime
);
617 case DATADUR_A
: //DATADUR_A
618 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
620 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
621 return (pDevice
->uSIFS
+ uAckTime
);
626 else {//First Frag or Mid Frag
627 if(uFragIdx
== (uMACfragNum
-2)){
628 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wRate
, bNeedAck
);
630 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
633 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
634 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
636 return (pDevice
->uSIFS
+ uNextPktTime
);
641 case DATADUR_A_F0
: //DATADUR_A_F0
642 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
644 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
645 return (pDevice
->uSIFS
+ uAckTime
);
650 else { //First Frag or Mid Frag
651 if (byFBOption
== AUTO_FB_0
) {
652 if (wRate
< RATE_18M
)
654 else if (wRate
> RATE_54M
)
657 if(uFragIdx
== (uMACfragNum
-2)){
658 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
660 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
662 } else { // (byFBOption == AUTO_FB_1)
663 if (wRate
< RATE_18M
)
665 else if (wRate
> RATE_54M
)
668 if(uFragIdx
== (uMACfragNum
-2)){
669 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
671 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
676 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
677 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
679 return (pDevice
->uSIFS
+ uNextPktTime
);
684 case DATADUR_A_F1
: //DATADUR_A_F1
685 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
687 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
688 return (pDevice
->uSIFS
+ uAckTime
);
693 else { //First Frag or Mid Frag
694 if (byFBOption
== AUTO_FB_0
) {
695 if (wRate
< RATE_18M
)
697 else if (wRate
> RATE_54M
)
700 if(uFragIdx
== (uMACfragNum
-2)){
701 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
703 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
706 } else { // (byFBOption == AUTO_FB_1)
707 if (wRate
< RATE_18M
)
709 else if (wRate
> RATE_54M
)
712 if(uFragIdx
== (uMACfragNum
-2)){
713 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
715 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
719 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
720 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
722 return (pDevice
->uSIFS
+ uNextPktTime
);
736 //byFreqType: 0=>5GHZ 1=>2.4GHZ
739 s_uGetRTSCTSDuration (
742 IN UINT cbFrameLength
,
749 UINT uCTSTime
= 0, uDurTime
= 0;
754 case RTSDUR_BB
: //RTSDuration_bb
755 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
756 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
759 case RTSDUR_BA
: //RTSDuration_ba
760 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
761 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
764 case RTSDUR_AA
: //RTSDuration_aa
765 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
766 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
769 case CTSDUR_BA
: //CTSDuration_ba
770 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
773 case RTSDUR_BA_F0
: //RTSDuration_ba_f0
774 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
775 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
776 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
777 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
778 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
782 case RTSDUR_AA_F0
: //RTSDuration_aa_f0
783 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
784 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
785 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
786 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
787 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
791 case RTSDUR_BA_F1
: //RTSDuration_ba_f1
792 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
793 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
794 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
795 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
796 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
800 case RTSDUR_AA_F1
: //RTSDuration_aa_f1
801 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
802 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
803 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
804 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
805 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
809 case CTSDUR_BA_F0
: //CTSDuration_ba_f0
810 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
811 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
812 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
813 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
817 case CTSDUR_BA_F1
: //CTSDuration_ba_f1
818 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
819 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
820 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
821 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
841 IN WORD wCurrentRate
,
842 IN PVOID pTxDataHead
,
843 IN UINT cbFrameLength
,
847 IN UINT cbLastFragmentSize
,
853 if (pTxDataHead
== NULL
) {
857 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
858 if((uDMAIdx
==TYPE_ATIMDMA
)||(uDMAIdx
==TYPE_BEACONDMA
)) {
859 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
860 //Get SignalField,ServiceField,Length
861 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
862 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
864 //Get Duration and TimeStampOff
865 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
866 wCurrentRate
, bNeedAck
, uFragIdx
,
867 cbLastFragmentSize
, uMACfragNum
,
868 byFBOption
); //1: 2.4GHz
869 if(uDMAIdx
!=TYPE_ATIMDMA
) {
870 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
872 return (pBuf
->wDuration
);
874 else { // DATA & MANAGE Frame
875 if (byFBOption
== AUTO_FB_NONE
) {
876 PSTxDataHead_g pBuf
= (PSTxDataHead_g
)pTxDataHead
;
877 //Get SignalField,ServiceField,Length
878 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
879 (PWORD
)&(pBuf
->wTransmitLength_a
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
881 BBvCaculateParameter(pDevice
, cbFrameLength
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
882 (PWORD
)&(pBuf
->wTransmitLength_b
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
884 //Get Duration and TimeStamp
885 pBuf
->wDuration_a
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
,
886 byPktType
, wCurrentRate
, bNeedAck
, uFragIdx
,
887 cbLastFragmentSize
, uMACfragNum
,
888 byFBOption
); //1: 2.4GHz
889 pBuf
->wDuration_b
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
,
890 PK_TYPE_11B
, pDevice
->byTopCCKBasicRate
,
891 bNeedAck
, uFragIdx
, cbLastFragmentSize
,
892 uMACfragNum
, byFBOption
); //1: 2.4GHz
894 pBuf
->wTimeStampOff_a
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
895 pBuf
->wTimeStampOff_b
= wTimeStampOff
[pDevice
->byPreambleType
%2][pDevice
->byTopCCKBasicRate
%MAX_RATE
];
896 return (pBuf
->wDuration_a
);
899 PSTxDataHead_g_FB pBuf
= (PSTxDataHead_g_FB
)pTxDataHead
;
900 //Get SignalField,ServiceField,Length
901 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
902 (PWORD
)&(pBuf
->wTransmitLength_a
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
904 BBvCaculateParameter(pDevice
, cbFrameLength
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
905 (PWORD
)&(pBuf
->wTransmitLength_b
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
907 //Get Duration and TimeStamp
908 pBuf
->wDuration_a
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
909 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
910 pBuf
->wDuration_b
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
, PK_TYPE_11B
,
911 pDevice
->byTopCCKBasicRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
912 pBuf
->wDuration_a_f0
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F0
, cbFrameLength
, byPktType
,
913 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
914 pBuf
->wDuration_a_f1
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F1
, cbFrameLength
, byPktType
,
915 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
916 pBuf
->wTimeStampOff_a
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
917 pBuf
->wTimeStampOff_b
= wTimeStampOff
[pDevice
->byPreambleType
%2][pDevice
->byTopCCKBasicRate
%MAX_RATE
];
918 return (pBuf
->wDuration_a
);
919 } //if (byFBOption == AUTO_FB_NONE)
922 else if (byPktType
== PK_TYPE_11A
) {
923 if ((byFBOption
!= AUTO_FB_NONE
) && (uDMAIdx
!= TYPE_ATIMDMA
) && (uDMAIdx
!= TYPE_BEACONDMA
)) {
925 PSTxDataHead_a_FB pBuf
= (PSTxDataHead_a_FB
)pTxDataHead
;
926 //Get SignalField,ServiceField,Length
927 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
928 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
930 //Get Duration and TimeStampOff
931 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
932 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //0: 5GHz
933 pBuf
->wDuration_f0
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F0
, cbFrameLength
, byPktType
,
934 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //0: 5GHz
935 pBuf
->wDuration_f1
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F1
, cbFrameLength
, byPktType
,
936 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //0: 5GHz
937 if(uDMAIdx
!=TYPE_ATIMDMA
) {
938 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
940 return (pBuf
->wDuration
);
942 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
943 //Get SignalField,ServiceField,Length
944 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
945 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
947 //Get Duration and TimeStampOff
948 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
949 wCurrentRate
, bNeedAck
, uFragIdx
,
950 cbLastFragmentSize
, uMACfragNum
,
953 if(uDMAIdx
!=TYPE_ATIMDMA
) {
954 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
956 return (pBuf
->wDuration
);
959 else if (byPktType
== PK_TYPE_11B
) {
960 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
961 //Get SignalField,ServiceField,Length
962 BBvCaculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
963 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
965 //Get Duration and TimeStampOff
966 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
, byPktType
,
967 wCurrentRate
, bNeedAck
, uFragIdx
,
968 cbLastFragmentSize
, uMACfragNum
,
970 if (uDMAIdx
!= TYPE_ATIMDMA
) {
971 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
973 return (pBuf
->wDuration
);
987 IN UINT cbFrameLength
,
990 IN PSEthernetHeader psEthHeader
,
991 IN WORD wCurrentRate
,
995 UINT uRTSFrameLen
= 20;
1002 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
1003 // in this case we need to decrease its length by 4.
1007 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
1008 // Otherwise, we need to modified codes for them.
1009 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1010 if (byFBOption
== AUTO_FB_NONE
) {
1011 PSRTS_g pBuf
= (PSRTS_g
)pvRTS
;
1012 //Get SignalField,ServiceField,Length
1013 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1014 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1016 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1017 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
1018 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
1020 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
1022 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
1023 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
1024 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
1026 pBuf
->Data
.wDurationID
= pBuf
->wDuration_aa
;
1027 //Get RTS Frame body
1028 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1029 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1030 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1031 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1034 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1036 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1037 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1040 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1044 PSRTS_g_FB pBuf
= (PSRTS_g_FB
)pvRTS
;
1045 //Get SignalField,ServiceField,Length
1046 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1047 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1049 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1050 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
1051 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
1053 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
1055 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
1056 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
1057 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
1058 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
1059 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
1060 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
1061 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
1062 pBuf
->Data
.wDurationID
= pBuf
->wDuration_aa
;
1063 //Get RTS Frame body
1064 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1066 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1067 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1068 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1071 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1074 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1075 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1078 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1081 } // if (byFBOption == AUTO_FB_NONE)
1083 else if (byPktType
== PK_TYPE_11A
) {
1084 if (byFBOption
== AUTO_FB_NONE
) {
1085 PSRTS_ab pBuf
= (PSRTS_ab
)pvRTS
;
1086 //Get SignalField,ServiceField,Length
1087 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
1088 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
1090 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
1092 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1093 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
1094 //Get RTS Frame body
1095 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1097 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1098 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1099 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1102 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1105 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1106 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1109 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1114 PSRTS_a_FB pBuf
= (PSRTS_a_FB
)pvRTS
;
1115 //Get SignalField,ServiceField,Length
1116 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
1117 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
1119 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
1121 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1122 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
1123 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:
1124 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
1125 //Get RTS Frame body
1126 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1128 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1129 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1130 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1133 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1135 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1136 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1139 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1143 else if (byPktType
== PK_TYPE_11B
) {
1144 PSRTS_ab pBuf
= (PSRTS_ab
)pvRTS
;
1145 //Get SignalField,ServiceField,Length
1146 BBvCaculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1147 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
1149 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
1151 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BB
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1152 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
1153 //Get RTS Frame body
1154 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
1157 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1158 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1159 memcpy(&(pBuf
->Data
.abyRA
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1162 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1165 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1166 memcpy(&(pBuf
->Data
.abyTA
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1169 memcpy(&(pBuf
->Data
.abyTA
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1177 IN PSDevice pDevice
,
1181 IN UINT cbFrameLength
,
1184 IN WORD wCurrentRate
,
1188 UINT uCTSFrameLen
= 14;
1191 if (pvCTS
== NULL
) {
1196 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1197 // in this case we need to decrease its length by 4.
1201 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1202 if (byFBOption
!= AUTO_FB_NONE
&& uDMAIdx
!= TYPE_ATIMDMA
&& uDMAIdx
!= TYPE_BEACONDMA
) {
1204 PSCTS_FB pBuf
= (PSCTS_FB
)pvCTS
;
1205 //Get SignalField,ServiceField,Length
1206 BBvCaculateParameter(pDevice
, uCTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1207 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1209 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1210 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
1211 pBuf
->wDuration_ba
+= pDevice
->wCTSDuration
;
1212 pBuf
->wDuration_ba
= cpu_to_le16(pBuf
->wDuration_ba
);
1213 //Get CTSDuration_ba_f0
1214 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
1215 pBuf
->wCTSDuration_ba_f0
+= pDevice
->wCTSDuration
;
1216 pBuf
->wCTSDuration_ba_f0
= cpu_to_le16(pBuf
->wCTSDuration_ba_f0
);
1217 //Get CTSDuration_ba_f1
1218 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
1219 pBuf
->wCTSDuration_ba_f1
+= pDevice
->wCTSDuration
;
1220 pBuf
->wCTSDuration_ba_f1
= cpu_to_le16(pBuf
->wCTSDuration_ba_f1
);
1221 //Get CTS Frame body
1222 pBuf
->Data
.wDurationID
= pBuf
->wDuration_ba
;
1223 pBuf
->Data
.wFrameControl
= TYPE_CTL_CTS
;//0x00C4
1224 pBuf
->Data
.wReserved
= 0x0000;
1225 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyCurrentNetAddr
[0]), U_ETHER_ADDR_LEN
);
1226 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1227 PSCTS pBuf
= (PSCTS
)pvCTS
;
1228 //Get SignalField,ServiceField,Length
1229 BBvCaculateParameter(pDevice
, uCTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1230 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1232 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1233 //Get CTSDuration_ba
1234 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
1235 pBuf
->wDuration_ba
+= pDevice
->wCTSDuration
;
1236 pBuf
->wDuration_ba
= cpu_to_le16(pBuf
->wDuration_ba
);
1238 //Get CTS Frame body
1239 pBuf
->Data
.wDurationID
= pBuf
->wDuration_ba
;
1240 pBuf
->Data
.wFrameControl
= TYPE_CTL_CTS
;//0x00C4
1241 pBuf
->Data
.wReserved
= 0x0000;
1242 memcpy(&(pBuf
->Data
.abyRA
[0]), &(pDevice
->abyCurrentNetAddr
[0]), U_ETHER_ADDR_LEN
);
1255 * Generate FIFO control for MAC & Baseband controller
1259 * pDevice - Pointer to adpater
1260 * pTxDataHead - Transmit Data Buffer
1261 * pTxBufHead - pTxBufHead
1262 * pvRrvTime - pvRrvTime
1263 * pvRTS - RTS Buffer
1265 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1266 * bNeedACK - If need ACK
1267 * uDMAIdx - DMA Index
1271 * Return Value: none
1274 // UINT cbFrameSize,//Hdr+Payload+FCS
1277 s_vGenerateTxParameter (
1278 IN PSDevice pDevice
,
1280 IN WORD wCurrentRate
,
1281 IN PVOID pTxBufHead
,
1285 IN UINT cbFrameSize
,
1288 IN PSEthernetHeader psEthHeader
1291 UINT cbMACHdLen
= WLAN_HDR_ADDR3_LEN
; //24
1293 BOOL bDisCRC
= FALSE
;
1294 BYTE byFBOption
= AUTO_FB_NONE
;
1295 // WORD wCurrentRate = pDevice->wCurrentRate;
1297 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1298 PSTxBufHead pFifoHead
= (PSTxBufHead
)pTxBufHead
;
1299 pFifoHead
->wReserved
= wCurrentRate
;
1300 wFifoCtl
= pFifoHead
->wFIFOCtl
;
1302 if (wFifoCtl
& FIFOCTL_CRCDIS
) {
1306 if (wFifoCtl
& FIFOCTL_AUTO_FB_0
) {
1307 byFBOption
= AUTO_FB_0
;
1309 else if (wFifoCtl
& FIFOCTL_AUTO_FB_1
) {
1310 byFBOption
= AUTO_FB_1
;
1313 if (pDevice
->bLongHeader
)
1314 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1316 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1318 if (pvRTS
!= NULL
) { //RTS_need
1321 PSRrvTime_gRTS pBuf
= (PSRrvTime_gRTS
)pvRrvTime
;
1322 pBuf
->wRTSTxRrvTime_aa
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 2, byPktType
, cbFrameSize
, wCurrentRate
));//2:RTSTxRrvTime_aa, 1:2.4GHz
1323 pBuf
->wRTSTxRrvTime_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 1, byPktType
, cbFrameSize
, wCurrentRate
));//1:RTSTxRrvTime_ba, 1:2.4GHz
1324 pBuf
->wRTSTxRrvTime_bb
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 0, byPktType
, cbFrameSize
, wCurrentRate
));//0:RTSTxRrvTime_bb, 1:2.4GHz
1325 pBuf
->wTxRrvTime_a
= cpu_to_le16((WORD
) s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//2.4G OFDM
1326 pBuf
->wTxRrvTime_b
= cpu_to_le16((WORD
) s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
, bNeedACK
));//1:CCK
1329 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1331 else {//RTS_needless, PCF mode
1335 PSRrvTime_gCTS pBuf
= (PSRrvTime_gCTS
)pvRrvTime
;
1336 pBuf
->wTxRrvTime_a
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//2.4G OFDM
1337 pBuf
->wTxRrvTime_b
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
, bNeedACK
));//1:CCK
1338 pBuf
->wCTSTxRrvTime_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 3, byPktType
, cbFrameSize
, wCurrentRate
));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1341 s_vFillCTSHead(pDevice
, uDMAIdx
, byPktType
, pvCTS
, cbFrameSize
, bNeedACK
, bDisCRC
, wCurrentRate
, byFBOption
);
1344 else if (byPktType
== PK_TYPE_11A
) {
1346 if (pvRTS
!= NULL
) {//RTS_need, non PCF mode
1349 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1350 pBuf
->wRTSTxRrvTime
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 2, byPktType
, cbFrameSize
, wCurrentRate
));//2:RTSTxRrvTime_aa, 0:5GHz
1351 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//0:OFDM
1354 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1356 else if (pvRTS
== NULL
) {//RTS_needless, non PCF mode
1359 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1360 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11A
, cbFrameSize
, wCurrentRate
, bNeedACK
)); //0:OFDM
1364 else if (byPktType
== PK_TYPE_11B
) {
1366 if ((pvRTS
!= NULL
)) {//RTS_need, non PCF mode
1369 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1370 pBuf
->wRTSTxRrvTime
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 0, byPktType
, cbFrameSize
, wCurrentRate
));//0:RTSTxRrvTime_bb, 1:2.4GHz
1371 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, wCurrentRate
, bNeedACK
));//1:CCK
1374 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1376 else { //RTS_needless, non PCF mode
1379 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1380 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, wCurrentRate
, bNeedACK
)); //1:CCK
1384 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1387 PBYTE pbyBuffer,//point to pTxBufHead
1388 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1389 UINT cbFragmentSize,//Hdr+payoad+FCS
1394 s_bPacketToWirelessUsb(
1395 IN PSDevice pDevice
,
1397 IN PBYTE usbPacketBuf
,
1398 IN BOOL bNeedEncryption
,
1399 IN UINT uSkbPacketLen
,
1401 IN PSEthernetHeader psEthHeader
,
1403 IN PSKeyItem pTransmitKey
,
1405 IN WORD wCurrentRate
,
1406 OUT UINT
*pcbHeaderLen
,
1407 OUT UINT
*pcbTotalLen
1410 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1411 UINT cbFrameSize
,cbFrameBodySize
;
1412 PTX_BUFFER pTxBufHead
;
1414 UINT cbIVlen
=0,cbICVlen
=0,cbMIClen
=0,cbMACHdLen
=0,cbFCSlen
=4;
1417 PBYTE pbyType
,pbyMacHdr
,pbyIVHead
,pbyPayloadHead
,pbyTxBufferAddr
;
1418 BYTE abySNAP_RFC1042
[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1419 BYTE abySNAP_Bridgetunnel
[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1421 UINT cbHeaderLength
= 0,uPadding
= 0;
1423 PSMICHDRHead pMICHDR
;
1427 BYTE byFBOption
= AUTO_FB_NONE
,byFragType
;
1429 DWORD dwMICKey0
,dwMICKey1
,dwMIC_Priority
,dwCRC
;
1430 PDWORD pdwMIC_L
,pdwMIC_R
;
1431 BOOL bSoftWEP
= FALSE
;
1436 pvRrvTime
= pMICHDR
= pvRTS
= pvCTS
= pvTxDataHd
= NULL
;
1437 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) {
1438 if (((PSKeyTable
) (pTransmitKey
->pvKeyTable
))->bSoftWEP
== TRUE
) {
1444 pTxBufHead
= (PTX_BUFFER
) usbPacketBuf
;
1445 memset(pTxBufHead
, 0, sizeof(TX_BUFFER
));
1448 if (ntohs(psEthHeader
->wType
) > MAX_DATA_LEN
) {
1449 if (pDevice
->dwDiagRefCount
== 0) {
1458 cbFrameBodySize
= uSkbPacketLen
- U_HEADER_LEN
+ cb802_1_H_len
;
1461 pTxBufHead
->wFIFOCtl
|= (WORD
)(byPktType
<<8);
1463 if (pDevice
->dwDiagRefCount
!= 0) {
1465 pTxBufHead
->wFIFOCtl
= pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1466 } else { //if (pDevice->dwDiagRefCount != 0) {
1467 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1468 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1469 if (IS_MULTICAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0])) ||
1470 IS_BROADCAST_ADDRESS(&(psEthHeader
->abyDstAddr
[0]))) {
1472 pTxBufHead
->wFIFOCtl
= pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1476 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1480 // MSDUs in Infra mode always need ACK
1482 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1484 } //if (pDevice->dwDiagRefCount != 0) {
1486 pTxBufHead
->wTimeStamp
= DEFAULT_MSDU_LIFETIME_RES_64us
;
1489 if (pDevice
->bLongHeader
)
1490 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LHEAD
;
1492 if (pDevice
->bSoftwareGenCrcErr
) {
1493 pTxBufHead
->wFIFOCtl
|= FIFOCTL_CRCDIS
; // set tx descriptors to NO hardware CRC
1496 //Set FRAGCTL_MACHDCNT
1497 if (pDevice
->bLongHeader
) {
1498 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1500 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
;
1502 pTxBufHead
->wFragCtl
|= (WORD
)(cbMACHdLen
<< 10);
1504 //Set FIFOCTL_GrpAckPolicy
1505 if (pDevice
->bGrpAckPolicy
== TRUE
) {//0000 0100 0000 0000
1506 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1509 //Set Auto Fallback Ctl
1510 if (wCurrentRate
>= RATE_18M
) {
1511 if (pDevice
->byAutoFBCtrl
== AUTO_FB_0
) {
1512 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_0
;
1513 byFBOption
= AUTO_FB_0
;
1514 } else if (pDevice
->byAutoFBCtrl
== AUTO_FB_1
) {
1515 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_1
;
1516 byFBOption
= AUTO_FB_1
;
1520 if (bSoftWEP
!= TRUE
) {
1521 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) { //WEP enabled
1522 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) { //WEP40 or WEP104
1523 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1525 if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1526 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1527 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1529 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) { //CCMP
1530 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1536 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) {
1537 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
1541 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1542 cbIVlen
= 8;//IV+ExtIV
1546 if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
1547 cbIVlen
= 8;//RSN Header
1549 cbMICHDR
= sizeof(SMICHDRHead
);
1551 if (bSoftWEP
== FALSE
) {
1552 //MAC Header should be padding 0 to DW alignment.
1553 uPadding
= 4 - (cbMACHdLen
%4);
1558 cbFrameSize
= cbMACHdLen
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbICVlen
+ cbFCSlen
;
1560 if ( (bNeedACK
== FALSE
) ||(cbFrameSize
< pDevice
->wRTSThreshold
) ) {
1564 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_RTS
| FIFOCTL_LRETRY
);
1567 pbyTxBufferAddr
= (PBYTE
) &(pTxBufHead
->adwTxKey
[0]);
1568 wTxBufSize
= sizeof(STxBufHead
);
1569 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1570 if (byFBOption
== AUTO_FB_NONE
) {
1571 if (bRTS
== TRUE
) {//RTS_need
1572 pvRrvTime
= (PSRrvTime_gRTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1573 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
));
1574 pvRTS
= (PSRTS_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
);
1576 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g
));
1577 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g
) + sizeof(STxDataHead_g
);
1579 else { //RTS_needless
1580 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1581 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1583 pvCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
1584 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
));
1585 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
) + sizeof(STxDataHead_g
);
1589 if (bRTS
== TRUE
) {//RTS_need
1590 pvRrvTime
= (PSRrvTime_gRTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1591 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
));
1592 pvRTS
= (PSRTS_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
);
1594 pvTxDataHd
= (PSTxDataHead_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g_FB
));
1595 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g_FB
) + sizeof(STxDataHead_g_FB
);
1597 else if (bRTS
== FALSE
) { //RTS_needless
1598 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1599 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1601 pvCTS
= (PSCTS_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
1602 pvTxDataHd
= (PSTxDataHead_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS_FB
));
1603 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS_FB
) + sizeof(STxDataHead_g_FB
);
1607 else {//802.11a/b packet
1608 if (byFBOption
== AUTO_FB_NONE
) {
1609 if (bRTS
== TRUE
) {//RTS_need
1610 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1611 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1612 pvRTS
= (PSRTS_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1614 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_ab
));
1615 cbHeaderLength
= wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_ab
) + sizeof(STxDataHead_ab
);
1617 else if (bRTS
== FALSE
) { //RTS_needless, no MICHDR
1618 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1619 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1622 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1623 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_ab
);
1627 if (bRTS
== TRUE
) {//RTS_need
1628 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1629 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1630 pvRTS
= (PSRTS_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1632 pvTxDataHd
= (PSTxDataHead_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_a_FB
));
1633 cbHeaderLength
= wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_a_FB
) + sizeof(STxDataHead_a_FB
);
1635 else if (bRTS
== FALSE
) { //RTS_needless
1636 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1637 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1640 pvTxDataHd
= (PSTxDataHead_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1641 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_a_FB
);
1646 pbyMacHdr
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderLength
);
1647 pbyIVHead
= (PBYTE
)(pbyMacHdr
+ cbMACHdLen
+ uPadding
);
1648 pbyPayloadHead
= (PBYTE
)(pbyMacHdr
+ cbMACHdLen
+ uPadding
+ cbIVlen
);
1651 //=========================
1653 //=========================
1654 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Fragmentation...\n");
1655 byFragType
= FRAGCTL_NONFRAG
;
1656 //uDMAIdx = TYPE_AC0DMA;
1657 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1660 //Fill FIFO,RrvTime,RTS,and CTS
1661 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
, (PVOID
)pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pvCTS
,
1662 cbFrameSize
, bNeedACK
, uDMAIdx
, psEthHeader
);
1664 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, uDMAIdx
, bNeedACK
,
1665 0, 0, 1/*uMACfragNum*/, byFBOption
);
1666 // Generate TX MAC Header
1667 s_vGenerateMACHeader(pDevice
, pbyMacHdr
, (WORD
)uDuration
, psEthHeader
, bNeedEncryption
,
1668 byFragType
, uDMAIdx
, 0);
1670 if (bNeedEncryption
== TRUE
) {
1672 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1673 pbyMacHdr
, (WORD
)cbFrameBodySize
, (PBYTE
)pMICHDR
);
1675 if (pDevice
->bEnableHostWEP
) {
1676 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1677 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1682 if (ntohs(psEthHeader
->wType
) > MAX_DATA_LEN
) {
1683 if (pDevice
->dwDiagRefCount
== 0) {
1684 if ( (psEthHeader
->wType
== TYPE_PKT_IPX
) ||
1685 (psEthHeader
->wType
== cpu_to_le16(0xF380))) {
1686 memcpy((PBYTE
) (pbyPayloadHead
), &abySNAP_Bridgetunnel
[0], 6);
1688 memcpy((PBYTE
) (pbyPayloadHead
), &abySNAP_RFC1042
[0], 6);
1690 pbyType
= (PBYTE
) (pbyPayloadHead
+ 6);
1691 memcpy(pbyType
, &(psEthHeader
->wType
), sizeof(WORD
));
1693 memcpy((PBYTE
) (pbyPayloadHead
), &(psEthHeader
->wType
), sizeof(WORD
));
1700 if (pPacket
!= NULL
) {
1701 // Copy the Packet into a tx Buffer
1702 memcpy((pbyPayloadHead
+ cb802_1_H_len
),
1703 (pPacket
+ U_HEADER_LEN
),
1704 uSkbPacketLen
- U_HEADER_LEN
1708 // while bRelayPacketSend psEthHeader is point to header+payload
1709 memcpy((pbyPayloadHead
+ cb802_1_H_len
), ((PBYTE
)psEthHeader
)+U_HEADER_LEN
, uSkbPacketLen
- U_HEADER_LEN
);
1712 ASSERT(uLength
== cbNdisBodySize
);
1714 if ((bNeedEncryption
== TRUE
) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1716 ///////////////////////////////////////////////////////////////////
1718 if (pDevice
->sMgmtObj
.eAuthenMode
== WMAC_AUTH_WPANONE
) {
1719 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
1720 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
1722 else if ((pTransmitKey
->dwKeyIndex
& AUTHENTICATOR_KEY
) != 0) {
1723 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
1724 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
1727 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[24]);
1728 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[28]);
1730 // DO Software Michael
1731 MIC_vInit(dwMICKey0
, dwMICKey1
);
1732 MIC_vAppend((PBYTE
)&(psEthHeader
->abyDstAddr
[0]), 12);
1734 MIC_vAppend((PBYTE
)&dwMIC_Priority
, 4);
1735 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC KEY: %lX, %lX\n", dwMICKey0
, dwMICKey1
);
1737 ///////////////////////////////////////////////////////////////////
1739 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1740 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1741 // DBG_PRN_GRP12(("%02x ", *((PBYTE)((pbyPayloadHead + cb802_1_H_len) + ii))));
1743 //DBG_PRN_GRP12(("\n\n\n"));
1745 MIC_vAppend(pbyPayloadHead
, cbFrameBodySize
);
1747 pdwMIC_L
= (PDWORD
)(pbyPayloadHead
+ cbFrameBodySize
);
1748 pdwMIC_R
= (PDWORD
)(pbyPayloadHead
+ cbFrameBodySize
+ 4);
1750 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1753 if (pDevice
->bTxMICFail
== TRUE
) {
1756 pDevice
->bTxMICFail
= FALSE
;
1758 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1759 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1760 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1764 if (bSoftWEP
== TRUE
) {
1766 s_vSWencryption(pDevice
, pTransmitKey
, (pbyPayloadHead
), (WORD
)(cbFrameBodySize
+ cbMIClen
));
1768 } else if ( ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) && (bNeedEncryption
== TRUE
)) ||
1769 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) && (bNeedEncryption
== TRUE
)) ||
1770 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) && (bNeedEncryption
== TRUE
)) ) {
1771 cbFrameSize
-= cbICVlen
;
1774 if (pDevice
->bSoftwareGenCrcErr
== TRUE
) {
1778 dwCRC
= 0xFFFFFFFFL
;
1779 cbLen
= cbFrameSize
- cbFCSlen
;
1780 // calculate CRC, and wrtie CRC value to end of TD
1781 dwCRC
= CRCdwGetCrc32Ex(pbyMacHdr
, cbLen
, dwCRC
);
1782 pdwCRC
= (PDWORD
)(pbyMacHdr
+ cbLen
);
1783 // finally, we must invert dwCRC to get the correct answer
1788 cbFrameSize
-= cbFCSlen
;
1791 *pcbHeaderLen
= cbHeaderLength
;
1792 *pcbTotalLen
= cbHeaderLength
+ cbFrameSize
;
1795 //Set FragCtl in TxBufferHead
1796 pTxBufHead
->wFragCtl
|= (WORD
)byFragType
;
1807 * Translate 802.3 to 802.11 header
1811 * pDevice - Pointer to adpater
1812 * dwTxBufferAddr - Transmit Buffer
1813 * pPacket - Packet from upper layer
1814 * cbPacketSize - Transmit Data Length
1816 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1817 * pcbAppendPayload - size of append payload for 802.1H translation
1819 * Return Value: none
1824 s_vGenerateMACHeader (
1825 IN PSDevice pDevice
,
1826 IN PBYTE pbyBufferAddr
,
1828 IN PSEthernetHeader psEthHeader
,
1829 IN BOOL bNeedEncrypt
,
1835 PS802_11Header pMACHeader
= (PS802_11Header
)pbyBufferAddr
;
1837 memset(pMACHeader
, 0, (sizeof(S802_11Header
))); //- sizeof(pMACHeader->dwIV)));
1839 if (uDMAIdx
== TYPE_ATIMDMA
) {
1840 pMACHeader
->wFrameCtl
= TYPE_802_11_ATIM
;
1842 pMACHeader
->wFrameCtl
= TYPE_802_11_DATA
;
1845 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1846 memcpy(&(pMACHeader
->abyAddr1
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1847 memcpy(&(pMACHeader
->abyAddr2
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1848 memcpy(&(pMACHeader
->abyAddr3
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1849 pMACHeader
->wFrameCtl
|= FC_FROMDS
;
1852 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
1853 memcpy(&(pMACHeader
->abyAddr1
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1854 memcpy(&(pMACHeader
->abyAddr2
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1855 memcpy(&(pMACHeader
->abyAddr3
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1858 memcpy(&(pMACHeader
->abyAddr3
[0]), &(psEthHeader
->abyDstAddr
[0]), U_ETHER_ADDR_LEN
);
1859 memcpy(&(pMACHeader
->abyAddr2
[0]), &(psEthHeader
->abySrcAddr
[0]), U_ETHER_ADDR_LEN
);
1860 memcpy(&(pMACHeader
->abyAddr1
[0]), &(pDevice
->abyBSSID
[0]), U_ETHER_ADDR_LEN
);
1861 pMACHeader
->wFrameCtl
|= FC_TODS
;
1866 pMACHeader
->wFrameCtl
|= cpu_to_le16((WORD
)WLAN_SET_FC_ISWEP(1));
1868 pMACHeader
->wDurationID
= cpu_to_le16(wDuration
);
1870 if (pDevice
->bLongHeader
) {
1871 PWLAN_80211HDR_A4 pMACA4Header
= (PWLAN_80211HDR_A4
) pbyBufferAddr
;
1872 pMACHeader
->wFrameCtl
|= (FC_TODS
| FC_FROMDS
);
1873 memcpy(pMACA4Header
->abyAddr4
, pDevice
->abyBSSID
, WLAN_ADDR_LEN
);
1875 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1877 //Set FragNumber in Sequence Control
1878 pMACHeader
->wSeqCtl
|= cpu_to_le16((WORD
)uFragIdx
);
1880 if ((wFragType
== FRAGCTL_ENDFRAG
) || (wFragType
== FRAGCTL_NONFRAG
)) {
1881 pDevice
->wSeqCounter
++;
1882 if (pDevice
->wSeqCounter
> 0x0fff)
1883 pDevice
->wSeqCounter
= 0;
1886 if ((wFragType
== FRAGCTL_STAFRAG
) || (wFragType
== FRAGCTL_MIDFRAG
)) { //StartFrag or MidFrag
1887 pMACHeader
->wFrameCtl
|= FC_MOREFRAG
;
1896 * Request instructs a MAC to transmit a 802.11 management packet through
1897 * the adapter onto the medium.
1901 * hDeviceContext - Pointer to the adapter
1902 * pPacket - A pointer to a descriptor for the packet to transmit
1906 * Return Value: CMD_STATUS_PENDING if MAC Tx resource avaliable; otherwise FALSE
1910 CMD_STATUS
csMgmt_xmit(
1911 IN PSDevice pDevice
,
1912 IN PSTxMgmtPacket pPacket
1916 PBYTE pbyTxBufferAddr
;
1922 PS802_11Header pMACHeader
;
1924 UINT cbFrameBodySize
;
1926 BOOL bIsPSPOLL
= FALSE
;
1927 PSTxBufHead pTxBufHead
;
1936 SEthernetHeader sEthHeader
;
1939 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1940 WORD wCurrentRate
= RATE_1M
;
1941 PTX_BUFFER pTX_Buffer
;
1942 PUSB_SEND_CONTEXT pContext
;
1946 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
1948 if (NULL
== pContext
) {
1949 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
1950 return CMD_STATUS_RESOURCES
;
1953 pTX_Buffer
= (PTX_BUFFER
) (&pContext
->Data
[0]);
1954 pbyTxBufferAddr
= (PBYTE
)&(pTX_Buffer
->adwTxKey
[0]);
1955 cbFrameBodySize
= pPacket
->cbPayloadLen
;
1956 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
1957 wTxBufSize
= sizeof(STxBufHead
);
1958 memset(pTxBufHead
, 0, wTxBufSize
);
1960 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1961 wCurrentRate
= RATE_6M
;
1962 byPktType
= PK_TYPE_11A
;
1964 wCurrentRate
= RATE_1M
;
1965 byPktType
= PK_TYPE_11B
;
1968 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1969 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1970 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1971 // to set power here.
1972 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
1973 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
1975 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
1977 pDevice
->wCurrentRate
= wCurrentRate
;
1981 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
1982 pTxBufHead
->wFIFOCtl
= 0;
1984 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
1985 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1987 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
1988 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
1990 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
1991 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
1994 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
1995 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
1998 if (IS_MULTICAST_ADDRESS(&(pPacket
->p80211Header
->sA3
.abyAddr1
[0])) ||
1999 IS_BROADCAST_ADDRESS(&(pPacket
->p80211Header
->sA3
.abyAddr1
[0]))) {
2004 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2007 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
2008 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
2010 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
2011 //Set Preamble type always long
2012 //pDevice->byPreambleType = PREAMBLE_LONG;
2013 // probe-response don't retry
2014 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2015 // bNeedACK = FALSE;
2016 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2020 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
2022 if ((pPacket
->p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
2024 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
2026 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
2029 //Set FRAGCTL_MACHDCNT
2030 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)(cbMacHdLen
<< 10));
2033 // Although spec says MMPDU can be fragmented; In most case,
2034 // no one will send a MMPDU under fragmentation. With RTS may occur.
2035 pDevice
->bAES
= FALSE
; //Set FRAGCTL_WEPTYP
2037 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
2038 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
2041 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
2043 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
2044 cbIVlen
= 8;//IV+ExtIV
2047 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
2048 //We need to get seed here for filling TxKey entry.
2049 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2050 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2052 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
2053 cbIVlen
= 8;//RSN Header
2055 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
2056 pDevice
->bAES
= TRUE
;
2058 //MAC Header should be padding 0 to DW alignment.
2059 uPadding
= 4 - (cbMacHdLen
%4);
2063 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
;
2065 //Set FIFOCTL_GrpAckPolicy
2066 if (pDevice
->bGrpAckPolicy
== TRUE
) {//0000 0100 0000 0000
2067 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
2069 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2071 //Set RrvTime/RTS/CTS Buffer
2072 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
2074 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
2077 pCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
2078 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + sizeof(SCTS
));
2079 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + sizeof(SCTS
) + sizeof(STxDataHead_g
);
2081 else { // 802.11a/b packet
2082 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2086 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
2087 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_ab
) + sizeof(STxDataHead_ab
);
2090 memset((PVOID
)(pbyTxBufferAddr
+ wTxBufSize
), 0, (cbHeaderSize
- wTxBufSize
));
2092 memcpy(&(sEthHeader
.abyDstAddr
[0]), &(pPacket
->p80211Header
->sA3
.abyAddr1
[0]), U_ETHER_ADDR_LEN
);
2093 memcpy(&(sEthHeader
.abySrcAddr
[0]), &(pPacket
->p80211Header
->sA3
.abyAddr2
[0]), U_ETHER_ADDR_LEN
);
2094 //=========================
2096 //=========================
2097 pTxBufHead
->wFragCtl
|= (WORD
)FRAGCTL_NONFRAG
;
2100 //Fill FIFO,RrvTime,RTS,and CTS
2101 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
, pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pCTS
,
2102 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
);
2105 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
2106 0, 0, 1, AUTO_FB_NONE
);
2108 pMACHeader
= (PS802_11Header
) (pbyTxBufferAddr
+ cbHeaderSize
);
2110 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ cbFrameBodySize
;
2112 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
2114 PBYTE pbyPayloadHead
;
2116 PSKeyItem pTransmitKey
= NULL
;
2118 pbyIVHead
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
);
2119 pbyPayloadHead
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
2121 if ((pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
2122 (pDevice
->bLinkPass
== TRUE
)) {
2123 pbyBSSID
= pDevice
->abyBSSID
;
2125 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == FALSE
) {
2127 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == TRUE
) {
2128 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
2132 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get PTK.\n");
2137 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2138 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == FALSE
) {
2139 pTransmitKey
= NULL
;
2140 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KEY is NULL. OP Mode[%d]\n", pDevice
->eOPMode
);
2142 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
2146 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
2147 (PBYTE
)pMACHeader
, (WORD
)cbFrameBodySize
, NULL
);
2149 memcpy(pMACHeader
, pPacket
->p80211Header
, cbMacHdLen
);
2150 memcpy(pbyPayloadHead
, ((PBYTE
)(pPacket
->p80211Header
) + cbMacHdLen
),
2154 // Copy the Packet into a tx Buffer
2155 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
2158 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2159 pDevice
->wSeqCounter
++ ;
2160 if (pDevice
->wSeqCounter
> 0x0fff)
2161 pDevice
->wSeqCounter
= 0;
2164 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2165 // of FIFO control header.
2166 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2167 // in the same place of other packet's Duration-field).
2168 // And it will cause Cisco-AP to issue Disassociation-packet
2169 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
2170 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_a
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
2171 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_b
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
2173 ((PSTxDataHead_ab
)pvTxDataHd
)->wDuration
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
2178 pTX_Buffer
->wTxByteCount
= cpu_to_le16((WORD
)(cbReqCount
));
2179 pTX_Buffer
->byPKTNO
= (BYTE
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2180 pTX_Buffer
->byType
= 0x00;
2182 pContext
->pPacket
= NULL
;
2183 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2184 pContext
->uBufLen
= (WORD
)cbReqCount
+ 4; //USB header
2186 if (WLAN_GET_FC_TODS(pMACHeader
->wFrameCtl
) == 0) {
2187 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr1
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
2190 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr3
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
2193 PIPEnsSendBulkOut(pDevice
,pContext
);
2194 return CMD_STATUS_PENDING
;
2200 IN PSDevice pDevice
,
2201 IN PSTxMgmtPacket pPacket
2205 UINT cbFrameSize
= pPacket
->cbMPDULen
+ WLAN_FCS_LEN
;
2206 UINT cbHeaderSize
= 0;
2207 WORD wTxBufSize
= sizeof(STxShortBufHead
);
2208 PSTxShortBufHead pTxBufHead
;
2209 PS802_11Header pMACHeader
;
2210 PSTxDataHead_ab pTxDataHead
;
2212 UINT cbFrameBodySize
;
2214 PBEACON_BUFFER pTX_Buffer
;
2215 PBYTE pbyTxBufferAddr
;
2216 PUSB_SEND_CONTEXT pContext
;
2220 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2221 if (NULL
== pContext
) {
2222 status
= CMD_STATUS_RESOURCES
;
2223 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
2226 pTX_Buffer
= (PBEACON_BUFFER
) (&pContext
->Data
[0]);
2227 pbyTxBufferAddr
= (PBYTE
)&(pTX_Buffer
->wFIFOCtl
);
2229 cbFrameBodySize
= pPacket
->cbPayloadLen
;
2231 pTxBufHead
= (PSTxShortBufHead
) pbyTxBufferAddr
;
2232 wTxBufSize
= sizeof(STxShortBufHead
);
2233 memset(pTxBufHead
, 0, wTxBufSize
);
2235 if (pDevice
->byBBType
== BB_TYPE_11A
) {
2236 wCurrentRate
= RATE_6M
;
2237 pTxDataHead
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2238 //Get SignalField,ServiceField,Length
2239 BBvCaculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, PK_TYPE_11A
,
2240 (PWORD
)&(pTxDataHead
->wTransmitLength
), (PBYTE
)&(pTxDataHead
->byServiceField
), (PBYTE
)&(pTxDataHead
->bySignalField
)
2242 //Get Duration and TimeStampOff
2243 pTxDataHead
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameSize
, PK_TYPE_11A
,
2244 wCurrentRate
, FALSE
, 0, 0, 1, AUTO_FB_NONE
));
2245 pTxDataHead
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
2246 cbHeaderSize
= wTxBufSize
+ sizeof(STxDataHead_ab
);
2248 wCurrentRate
= RATE_1M
;
2249 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2250 pTxDataHead
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2251 //Get SignalField,ServiceField,Length
2252 BBvCaculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, PK_TYPE_11B
,
2253 (PWORD
)&(pTxDataHead
->wTransmitLength
), (PBYTE
)&(pTxDataHead
->byServiceField
), (PBYTE
)&(pTxDataHead
->bySignalField
)
2255 //Get Duration and TimeStampOff
2256 pTxDataHead
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameSize
, PK_TYPE_11B
,
2257 wCurrentRate
, FALSE
, 0, 0, 1, AUTO_FB_NONE
));
2258 pTxDataHead
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
2259 cbHeaderSize
= wTxBufSize
+ sizeof(STxDataHead_ab
);
2262 //Generate Beacon Header
2263 pMACHeader
= (PS802_11Header
)(pbyTxBufferAddr
+ cbHeaderSize
);
2264 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
2266 pMACHeader
->wDurationID
= 0;
2267 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2268 pDevice
->wSeqCounter
++ ;
2269 if (pDevice
->wSeqCounter
> 0x0fff)
2270 pDevice
->wSeqCounter
= 0;
2272 cbReqCount
= cbHeaderSize
+ WLAN_HDR_ADDR3_LEN
+ cbFrameBodySize
;
2274 pTX_Buffer
->wTxByteCount
= (WORD
)cbReqCount
;
2275 pTX_Buffer
->byPKTNO
= (BYTE
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2276 pTX_Buffer
->byType
= 0x01;
2278 pContext
->pPacket
= NULL
;
2279 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2280 pContext
->uBufLen
= (WORD
)cbReqCount
+ 4; //USB header
2282 PIPEnsSendBulkOut(pDevice
,pContext
);
2283 return CMD_STATUS_PENDING
;
2292 vDMA0_tx_80211(PSDevice pDevice
, struct sk_buff
*skb
) {
2294 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
2296 PBYTE pbyTxBufferAddr
;
2302 PS802_11Header pMACHeader
;
2304 UINT cbFrameBodySize
;
2306 BOOL bIsPSPOLL
= FALSE
;
2307 PSTxBufHead pTxBufHead
;
2316 DWORD dwMICKey0
, dwMICKey1
;
2317 DWORD dwMIC_Priority
;
2322 SEthernetHeader sEthHeader
;
2325 WORD wCurrentRate
= RATE_1M
;
2326 PUWLAN_80211HDR p80211Header
;
2327 UINT uNodeIndex
= 0;
2328 BOOL bNodeExist
= FALSE
;
2330 PSKeyItem pTransmitKey
= NULL
;
2332 PBYTE pbyPayloadHead
;
2334 UINT cbExtSuppRate
= 0;
2335 PTX_BUFFER pTX_Buffer
;
2336 PUSB_SEND_CONTEXT pContext
;
2340 pvRrvTime
= pMICHDR
= pvRTS
= pvCTS
= pvTxDataHd
= NULL
;
2342 if(skb
->len
<= WLAN_HDR_ADDR3_LEN
) {
2343 cbFrameBodySize
= 0;
2346 cbFrameBodySize
= skb
->len
- WLAN_HDR_ADDR3_LEN
;
2348 p80211Header
= (PUWLAN_80211HDR
)skb
->data
;
2350 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2352 if (NULL
== pContext
) {
2353 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0 TX...NO CONTEXT!\n");
2354 dev_kfree_skb_irq(skb
);
2358 pTX_Buffer
= (PTX_BUFFER
)(&pContext
->Data
[0]);
2359 pbyTxBufferAddr
= (PBYTE
)(&pTX_Buffer
->adwTxKey
[0]);
2360 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
2361 wTxBufSize
= sizeof(STxBufHead
);
2362 memset(pTxBufHead
, 0, wTxBufSize
);
2364 if (pDevice
->byBBType
== BB_TYPE_11A
) {
2365 wCurrentRate
= RATE_6M
;
2366 byPktType
= PK_TYPE_11A
;
2368 wCurrentRate
= RATE_1M
;
2369 byPktType
= PK_TYPE_11B
;
2372 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2373 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2374 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2375 // to set power here.
2376 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
2377 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
2379 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
2382 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header
->sA3
.wFrameCtl
);
2385 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
2386 pTxBufHead
->wFIFOCtl
= 0;
2388 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
2389 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2391 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
2392 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
2394 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
2395 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
2398 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
2399 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
2402 if (IS_MULTICAST_ADDRESS(&(p80211Header
->sA3
.abyAddr1
[0])) ||
2403 IS_BROADCAST_ADDRESS(&(p80211Header
->sA3
.abyAddr1
[0]))) {
2405 if (pDevice
->bEnableHostWEP
) {
2411 if (pDevice
->bEnableHostWEP
) {
2412 if (BSSbIsSTAInNodeDB(pDevice
, (PBYTE
)(p80211Header
->sA3
.abyAddr1
), &uNodeIndex
))
2416 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2419 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
2420 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
2422 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
2423 //Set Preamble type always long
2424 //pDevice->byPreambleType = PREAMBLE_LONG;
2426 // probe-response don't retry
2427 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2428 // bNeedACK = FALSE;
2429 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2433 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
2435 if ((p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
2437 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
2439 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
2442 // hostapd deamon ext support rate patch
2443 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
2445 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0) {
2446 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
;
2449 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0) {
2450 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
;
2453 if (cbExtSuppRate
>0) {
2454 cbFrameBodySize
= WLAN_ASSOCRESP_OFF_SUPP_RATES
;
2459 //Set FRAGCTL_MACHDCNT
2460 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)cbMacHdLen
<< 10);
2463 // Although spec says MMPDU can be fragmented; In most case,
2464 // no one will send a MMPDU under fragmentation. With RTS may occur.
2465 pDevice
->bAES
= FALSE
; //Set FRAGCTL_WEPTYP
2468 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
2469 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
2472 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
2474 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
2475 cbIVlen
= 8;//IV+ExtIV
2478 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
2479 //We need to get seed here for filling TxKey entry.
2480 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2481 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2483 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
2484 cbIVlen
= 8;//RSN Header
2486 cbMICHDR
= sizeof(SMICHDRHead
);
2487 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
2488 pDevice
->bAES
= TRUE
;
2490 //MAC Header should be padding 0 to DW alignment.
2491 uPadding
= 4 - (cbMacHdLen
%4);
2495 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
+ cbExtSuppRate
;
2497 //Set FIFOCTL_GrpAckPolicy
2498 if (pDevice
->bGrpAckPolicy
== TRUE
) {//0000 0100 0000 0000
2499 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
2501 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2504 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
2506 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
2507 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
2509 pvCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
2510 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
));
2511 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
) + sizeof(STxDataHead_g
);
2514 else {//802.11a/b packet
2516 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2517 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
2520 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
2521 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_ab
);
2523 memset((PVOID
)(pbyTxBufferAddr
+ wTxBufSize
), 0, (cbHeaderSize
- wTxBufSize
));
2524 memcpy(&(sEthHeader
.abyDstAddr
[0]), &(p80211Header
->sA3
.abyAddr1
[0]), U_ETHER_ADDR_LEN
);
2525 memcpy(&(sEthHeader
.abySrcAddr
[0]), &(p80211Header
->sA3
.abyAddr2
[0]), U_ETHER_ADDR_LEN
);
2526 //=========================
2528 //=========================
2529 pTxBufHead
->wFragCtl
|= (WORD
)FRAGCTL_NONFRAG
;
2532 //Fill FIFO,RrvTime,RTS,and CTS
2533 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
, pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pvCTS
,
2534 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
);
2537 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
2538 0, 0, 1, AUTO_FB_NONE
);
2540 pMACHeader
= (PS802_11Header
) (pbyTxBufferAddr
+ cbHeaderSize
);
2542 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbExtSuppRate
;
2544 pbyMacHdr
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
);
2545 pbyPayloadHead
= (PBYTE
)(pbyMacHdr
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
2546 pbyIVHead
= (PBYTE
)(pbyMacHdr
+ cbMacHdLen
+ uPadding
);
2548 // Copy the Packet into a tx Buffer
2549 memcpy(pbyMacHdr
, skb
->data
, cbMacHdLen
);
2551 // version set to 0, patch for hostapd deamon
2552 pMACHeader
->wFrameCtl
&= cpu_to_le16(0xfffc);
2553 memcpy(pbyPayloadHead
, (skb
->data
+ cbMacHdLen
), cbFrameBodySize
);
2555 // replace support rate, patch for hostapd deamon( only support 11M)
2556 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
2557 if (cbExtSuppRate
!= 0) {
2558 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0)
2559 memcpy((pbyPayloadHead
+ cbFrameBodySize
),
2560 pMgmt
->abyCurrSuppRates
,
2561 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
2563 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0)
2564 memcpy((pbyPayloadHead
+ cbFrameBodySize
) + ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
,
2565 pMgmt
->abyCurrExtSuppRates
,
2566 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
2572 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
2574 if (pDevice
->bEnableHostWEP
) {
2575 pTransmitKey
= &STempKey
;
2576 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2577 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2578 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2579 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2580 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2581 memcpy(pTransmitKey
->abyKey
,
2582 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2583 pTransmitKey
->uKeyLength
2587 if ((pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
2589 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
2590 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
2592 // DO Software Michael
2593 MIC_vInit(dwMICKey0
, dwMICKey1
);
2594 MIC_vAppend((PBYTE
)&(sEthHeader
.abyDstAddr
[0]), 12);
2596 MIC_vAppend((PBYTE
)&dwMIC_Priority
, 4);
2597 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0
, dwMICKey1
);
2599 uLength
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
;
2601 MIC_vAppend((pbyTxBufferAddr
+ uLength
), cbFrameBodySize
);
2603 pdwMIC_L
= (PDWORD
)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
);
2604 pdwMIC_R
= (PDWORD
)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
+ 4);
2606 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
2609 if (pDevice
->bTxMICFail
== TRUE
) {
2612 pDevice
->bTxMICFail
= FALSE
;
2615 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uLength: %d, %d\n", uLength
, cbFrameBodySize
);
2616 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"cbReqCount:%d, %d, %d, %d\n", cbReqCount
, cbHeaderSize
, uPadding
, cbIVlen
);
2617 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC:%lx, %lx\n", *pdwMIC_L
, *pdwMIC_R
);
2621 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
2622 pbyMacHdr
, (WORD
)cbFrameBodySize
, (PBYTE
)pMICHDR
);
2624 if (pDevice
->bEnableHostWEP
) {
2625 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
2626 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
2629 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
2630 s_vSWencryption(pDevice
, pTransmitKey
, pbyPayloadHead
, (WORD
)(cbFrameBodySize
+ cbMIClen
));
2634 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2635 pDevice
->wSeqCounter
++ ;
2636 if (pDevice
->wSeqCounter
> 0x0fff)
2637 pDevice
->wSeqCounter
= 0;
2641 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2642 // of FIFO control header.
2643 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2644 // in the same place of other packet's Duration-field).
2645 // And it will cause Cisco-AP to issue Disassociation-packet
2646 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
2647 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_a
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2648 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_b
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2650 ((PSTxDataHead_ab
)pvTxDataHd
)->wDuration
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2654 pTX_Buffer
->wTxByteCount
= cpu_to_le16((WORD
)(cbReqCount
));
2655 pTX_Buffer
->byPKTNO
= (BYTE
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2656 pTX_Buffer
->byType
= 0x00;
2658 pContext
->pPacket
= skb
;
2659 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2660 pContext
->uBufLen
= (WORD
)cbReqCount
+ 4; //USB header
2662 if (WLAN_GET_FC_TODS(pMACHeader
->wFrameCtl
) == 0) {
2663 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr1
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
2666 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr3
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
2668 PIPEnsSendBulkOut(pDevice
,pContext
);
2676 //TYPE_AC0DMA data tx
2679 * Tx packet via AC0DMA(DMA1)
2683 * pDevice - Pointer to the adapter
2684 * skb - Pointer to tx skb packet
2688 * Return Value: NULL
2695 IN PSDevice pDevice
,
2697 IN
struct sk_buff
*skb
2700 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
2701 UINT BytesToWrite
=0,uHeaderLen
= 0;
2702 UINT uNodeIndex
= 0;
2703 BYTE byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2706 BOOL bNeedEncryption
= FALSE
;
2707 PSKeyItem pTransmitKey
= NULL
;
2710 BOOL bTKIP_UseGTK
= FALSE
;
2711 BOOL bNeedDeAuth
= FALSE
;
2713 BOOL bNodeExist
= FALSE
;
2714 PUSB_SEND_CONTEXT pContext
;
2715 BOOL fConvertedPacket
;
2716 PTX_BUFFER pTX_Buffer
;
2718 WORD wKeepRate
= pDevice
->wCurrentRate
;
2719 struct net_device_stats
* pStats
= &pDevice
->stats
;
2720 //#ifdef WPA_SM_Transtatus
2721 // extern SWPAResult wpa_Result;
2723 BOOL bTxeapol_key
= FALSE
;
2726 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
2728 if (pDevice
->uAssocCount
== 0) {
2729 dev_kfree_skb_irq(skb
);
2733 if (IS_MULTICAST_ADDRESS((PBYTE
)(skb
->data
))) {
2736 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
2738 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skb
);
2739 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
2741 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
2744 // muticast/broadcast data rate
2746 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2747 pDevice
->wCurrentRate
= RATE_2M
;
2749 pDevice
->wCurrentRate
= RATE_24M
;
2750 // long preamble type
2751 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2755 if (BSSbIsSTAInNodeDB(pDevice
, (PBYTE
)(skb
->data
), &uNodeIndex
)) {
2757 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bPSEnable
) {
2759 skb_queue_tail(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
, skb
);
2761 pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
++;
2763 wAID
= pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
;
2764 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
2765 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set:pMgmt->abyPSTxMap[%d]= %d\n",
2766 (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
2770 // AP rate decided from node
2771 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2772 // tx preamble decided from node
2774 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2775 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2778 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2784 if (bNodeExist
== FALSE
) {
2785 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Unknown STA not found in node DB \n");
2786 dev_kfree_skb_irq(skb
);
2791 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2793 if (pContext
== NULL
) {
2794 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
" pContext == NULL\n");
2795 dev_kfree_skb_irq(skb
);
2796 return STATUS_RESOURCES
;
2799 memcpy(pDevice
->sTxEthHeader
.abyDstAddr
, (PBYTE
)(skb
->data
), U_HEADER_LEN
);
2801 //mike add:station mode check eapol-key challenge--->
2803 BYTE Protocol_Version
; //802.1x Authentication
2804 BYTE Packet_Type
; //802.1x Authentication
2805 BYTE Descriptor_type
;
2808 Protocol_Version
= skb
->data
[U_HEADER_LEN
];
2809 Packet_Type
= skb
->data
[U_HEADER_LEN
+1];
2810 Descriptor_type
= skb
->data
[U_HEADER_LEN
+1+1+2];
2811 Key_info
= (skb
->data
[U_HEADER_LEN
+1+1+2+1] << 8)|(skb
->data
[U_HEADER_LEN
+1+1+2+2]);
2812 if (pDevice
->sTxEthHeader
.wType
== TYPE_PKT_802_1x
) {
2813 if(((Protocol_Version
==1) ||(Protocol_Version
==2)) &&
2814 (Packet_Type
==3)) { //802.1x OR eapol-key challenge frame transfer
2815 bTxeapol_key
= TRUE
;
2816 if(!(Key_info
& BIT3
) && //WPA or RSN group-key challenge
2817 (Key_info
& BIT8
) && (Key_info
& BIT9
)) { //send 2/2 key
2818 if(Descriptor_type
==254) {
2819 pDevice
->fWPA_Authened
= TRUE
;
2823 pDevice
->fWPA_Authened
= TRUE
;
2824 PRINT_K("WPA2(re-keying) ");
2826 PRINT_K("Authentication completed!!\n");
2828 else if((Key_info
& BIT3
) && (Descriptor_type
==2) && //RSN pairse-key challenge
2829 (Key_info
& BIT8
) && (Key_info
& BIT9
)) {
2830 pDevice
->fWPA_Authened
= TRUE
;
2831 PRINT_K("WPA2 Authentication completed!!\n");
2836 //mike add:station mode check eapol-key challenge<---
2838 if (pDevice
->bEncryptionEnable
== TRUE
) {
2839 bNeedEncryption
= TRUE
;
2842 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
2843 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2844 pbyBSSID
= pDevice
->abyBSSID
;
2846 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == FALSE
) {
2848 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == TRUE
) {
2849 bTKIP_UseGTK
= TRUE
;
2850 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2854 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get PTK.\n");
2857 }else if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2859 pbyBSSID
= pDevice
->sTxEthHeader
.abyDstAddr
; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2860 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS Serach Key: \n");
2861 for (ii
= 0; ii
< 6; ii
++)
2862 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"%x \n", *(pbyBSSID
+ii
));
2863 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"\n");
2866 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == TRUE
)
2870 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2871 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == FALSE
) {
2872 pTransmitKey
= NULL
;
2873 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2874 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2877 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"NOT IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2879 bTKIP_UseGTK
= TRUE
;
2880 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2885 if (pDevice
->bEnableHostWEP
) {
2886 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"acdma0: STA index %d\n", uNodeIndex
);
2887 if (pDevice
->bEncryptionEnable
== TRUE
) {
2888 pTransmitKey
= &STempKey
;
2889 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2890 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2891 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2892 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2893 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2894 memcpy(pTransmitKey
->abyKey
,
2895 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2896 pTransmitKey
->uKeyLength
2901 byPktType
= (BYTE
)pDevice
->byPacketType
;
2903 if (pDevice
->bFixRate
) {
2904 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2905 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2906 pDevice
->wCurrentRate
= RATE_11M
;
2908 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
2911 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2912 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2913 pDevice
->wCurrentRate
= RATE_6M
;
2915 if (pDevice
->uConnectionRate
>= RATE_54M
)
2916 pDevice
->wCurrentRate
= RATE_54M
;
2918 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
2923 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2924 // Adhoc Tx rate decided from node DB
2925 if (IS_MULTICAST_ADDRESS(&(pDevice
->sTxEthHeader
.abyDstAddr
[0]))) {
2926 // Multicast use highest data rate
2927 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2929 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2932 if(BSSbIsSTAInNodeDB(pDevice
, &(pDevice
->sTxEthHeader
.abyDstAddr
[0]), &uNodeIndex
)) {
2933 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2934 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2935 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2939 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2941 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex
, pDevice
->wCurrentRate
);
2944 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2945 pDevice
->wCurrentRate
= RATE_2M
;
2947 pDevice
->wCurrentRate
= RATE_24M
; // refer to vMgrCreateOwnIBSS()'s
2948 // abyCurrExtSuppRates[]
2949 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2950 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Not Found Node use highest basic Rate.....\n");
2954 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
2955 // Infra STA rate decided from AP Node, index = 0
2956 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2960 if (pDevice
->sTxEthHeader
.wType
== TYPE_PKT_802_1x
) {
2961 if (pDevice
->byBBType
!= BB_TYPE_11A
) {
2962 pDevice
->wCurrentRate
= RATE_1M
;
2963 pDevice
->byACKRate
= RATE_1M
;
2964 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2965 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2967 pDevice
->wCurrentRate
= RATE_6M
;
2968 pDevice
->byACKRate
= RATE_6M
;
2969 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2970 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2974 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dma_tx: pDevice->wCurrentRate = %d \n", pDevice
->wCurrentRate
);
2976 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2977 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2980 if (pDevice
->wCurrentRate
<= RATE_11M
) {
2981 byPktType
= PK_TYPE_11B
;
2984 if (bNeedEncryption
== TRUE
) {
2985 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ntohs Pkt Type=%04x\n", ntohs(pDevice
->sTxEthHeader
.wType
));
2986 if ((pDevice
->sTxEthHeader
.wType
) == TYPE_PKT_802_1x
) {
2987 bNeedEncryption
= FALSE
;
2988 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pkt Type=%04x\n", (pDevice
->sTxEthHeader
.wType
));
2989 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2990 if (pTransmitKey
== NULL
) {
2991 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Don't Find TX KEY\n");
2994 if (bTKIP_UseGTK
== TRUE
) {
2995 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"error: KEY is GTK!!~~\n");
2998 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%lX]\n", pTransmitKey
->dwKeyIndex
);
2999 bNeedEncryption
= TRUE
;
3004 if (pDevice
->byCntMeasure
== 2) {
3006 pDevice
->s802_11Counter
.TKIPCounterMeasuresInvoked
++;
3009 if (pDevice
->bEnableHostWEP
) {
3010 if ((uNodeIndex
!= 0) &&
3011 (pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
& PAIRWISE_KEY
)) {
3012 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%lX]\n", pTransmitKey
->dwKeyIndex
);
3013 bNeedEncryption
= TRUE
;
3020 if((pDevice
->fWPA_Authened
== FALSE
) &&
3021 ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
)||(pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
))){
3022 dev_kfree_skb_irq(skb
);
3023 pStats
->tx_dropped
++;
3024 return STATUS_FAILURE
;
3026 else if (pTransmitKey
== NULL
) {
3027 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return no tx key\n");
3028 dev_kfree_skb_irq(skb
);
3029 pStats
->tx_dropped
++;
3030 return STATUS_FAILURE
;
3033 if (pTransmitKey
== NULL
) {
3034 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return no tx key\n");
3035 dev_kfree_skb_irq(skb
);
3036 pStats
->tx_dropped
++;
3037 return STATUS_FAILURE
;
3044 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
3045 (PBYTE
)(&pContext
->Data
[0]), bNeedEncryption
,
3046 skb
->len
, uDMAIdx
, &pDevice
->sTxEthHeader
,
3047 (PBYTE
)skb
->data
, pTransmitKey
, uNodeIndex
,
3048 pDevice
->wCurrentRate
,
3049 &uHeaderLen
, &BytesToWrite
3052 if (fConvertedPacket
== FALSE
) {
3053 pContext
->bBoolInUse
= FALSE
;
3054 dev_kfree_skb_irq(skb
);
3055 return STATUS_FAILURE
;
3058 if ( pDevice
->bEnablePSMode
== TRUE
) {
3059 if ( !pDevice
->bPSModeTxBurst
) {
3060 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_MAC_DISPOWERSAVING
, NULL
);
3061 pDevice
->bPSModeTxBurst
= TRUE
;
3065 pTX_Buffer
= (PTX_BUFFER
)&(pContext
->Data
[0]);
3066 pTX_Buffer
->byPKTNO
= (BYTE
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
3067 pTX_Buffer
->wTxByteCount
= (WORD
)BytesToWrite
;
3069 pContext
->pPacket
= skb
;
3070 pContext
->Type
= CONTEXT_DATA_PACKET
;
3071 pContext
->uBufLen
= (WORD
)BytesToWrite
+ 4 ; //USB header
3073 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pContext
->sEthHeader
.abyDstAddr
[0]),(WORD
) (BytesToWrite
-uHeaderLen
),pTX_Buffer
->wFIFOCtl
);
3075 status
= PIPEnsSendBulkOut(pDevice
,pContext
);
3077 if (bNeedDeAuth
== TRUE
) {
3078 WORD wReason
= WLAN_MGMT_REASON_MIC_FAILURE
;
3080 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_DEAUTH
, (PBYTE
)&wReason
);
3083 if(status
!=STATUS_PENDING
) {
3084 pContext
->bBoolInUse
= FALSE
;
3085 dev_kfree_skb_irq(skb
);
3086 return STATUS_FAILURE
;
3097 * Relay packet send (AC1DMA) from rx dpc.
3101 * pDevice - Pointer to the adapter
3102 * pPacket - Pointer to rx packet
3103 * cbPacketSize - rx ethernet frame size
3107 * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE
3113 IN PSDevice pDevice
,
3114 IN PBYTE pbySkbData
,
3119 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
3120 UINT BytesToWrite
=0,uHeaderLen
= 0;
3121 BYTE byPktType
= PK_TYPE_11B
;
3122 BOOL bNeedEncryption
= FALSE
;
3124 PSKeyItem pTransmitKey
= NULL
;
3126 PUSB_SEND_CONTEXT pContext
;
3128 BOOL fConvertedPacket
;
3129 PTX_BUFFER pTX_Buffer
;
3131 WORD wKeepRate
= pDevice
->wCurrentRate
;
3135 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
3137 if (NULL
== pContext
) {
3141 memcpy(pDevice
->sTxEthHeader
.abyDstAddr
, (PBYTE
)pbySkbData
, U_HEADER_LEN
);
3143 if (pDevice
->bEncryptionEnable
== TRUE
) {
3144 bNeedEncryption
= TRUE
;
3146 pbyBSSID
= pDevice
->abyBroadcastAddr
;
3147 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == FALSE
) {
3148 pTransmitKey
= NULL
;
3149 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
3151 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
3155 if (pDevice
->bEnableHostWEP
) {
3156 if (uNodeIndex
>= 0) {
3157 pTransmitKey
= &STempKey
;
3158 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
3159 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
3160 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
3161 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
3162 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
3163 memcpy(pTransmitKey
->abyKey
,
3164 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
3165 pTransmitKey
->uKeyLength
3170 if ( bNeedEncryption
&& (pTransmitKey
== NULL
) ) {
3171 pContext
->bBoolInUse
= FALSE
;
3175 byPktTyp
= (BYTE
)pDevice
->byPacketType
;
3177 if (pDevice
->bFixRate
) {
3178 if (pDevice
->byBBType
== BB_TYPE_11B
) {
3179 if (pDevice
->uConnectionRate
>= RATE_11M
) {
3180 pDevice
->wCurrentRate
= RATE_11M
;
3182 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
3185 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
3186 (pDevice
->uConnectionRate
<= RATE_6M
)) {
3187 pDevice
->wCurrentRate
= RATE_6M
;
3189 if (pDevice
->uConnectionRate
>= RATE_54M
)
3190 pDevice
->wCurrentRate
= RATE_54M
;
3192 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
3197 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
3201 if (wKeepRate
!= pDevice
->wCurrentRate
) {
3202 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
3205 if (pDevice
->wCurrentRate
<= RATE_11M
)
3206 byPktType
= PK_TYPE_11B
;
3208 BytesToWrite
= uDataLen
+ U_CRC_LEN
;
3209 // Convert the packet to an usb frame and copy into our buffer
3210 // and send the irp.
3212 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
3213 (PBYTE
)(&pContext
->Data
[0]), bNeedEncryption
,
3214 uDataLen
, TYPE_AC0DMA
, &pDevice
->sTxEthHeader
,
3215 pbySkbData
, pTransmitKey
, uNodeIndex
,
3216 pDevice
->wCurrentRate
,
3217 &uHeaderLen
, &BytesToWrite
3220 if (fConvertedPacket
== FALSE
) {
3221 pContext
->bBoolInUse
= FALSE
;
3225 pTX_Buffer
= (PTX_BUFFER
)&(pContext
->Data
[0]);
3226 pTX_Buffer
->byPKTNO
= (BYTE
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
3227 pTX_Buffer
->wTxByteCount
= (WORD
)BytesToWrite
;
3229 pContext
->pPacket
= NULL
;
3230 pContext
->Type
= CONTEXT_DATA_PACKET
;
3231 pContext
->uBufLen
= (WORD
)BytesToWrite
+ 4 ; //USB header
3233 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pContext
->sEthHeader
.abyDstAddr
[0]),(WORD
) (BytesToWrite
-uHeaderLen
),pTX_Buffer
->wFIFOCtl
);
3235 status
= PIPEnsSendBulkOut(pDevice
,pContext
);