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 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Caculate fragement number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts requried duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragement ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
52 #if !defined(__DEVICE_H__)
55 #if !defined(__RXTX_H__)
58 #if !defined(__TETHER_H__)
61 #if !defined(__CARD_H__)
64 #if !defined(__BSSDB_H__)
67 #if !defined(__MAC_H__)
70 #if !defined(__BASEBAND_H__)
73 #if !defined(__UMEM_H__)
76 #if !defined(__MICHAEL_H__)
79 #if !defined(__TKIP_H__)
82 #if !defined(__TCRC_H__)
85 #if !defined(__WCTL_H__)
88 #if !defined(__WROUTE_H__)
91 #if !defined(__TBIT_H__)
94 #if !defined(__HOSTAP_H__)
97 #if !defined(__RF_H__)
101 /*--------------------- Static Definitions -------------------------*/
103 /*--------------------- Static Classes ----------------------------*/
105 /*--------------------- Static Variables --------------------------*/
106 //static int msglevel =MSG_LEVEL_DEBUG;
107 static int msglevel =MSG_LEVEL_INFO;
112 /*--------------------- Static Functions --------------------------*/
114 /*--------------------- Static Definitions -------------------------*/
115 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
116 // packet size >= 256 -> direct send
118 const WORD wTimeStampOff[2][MAX_RATE] = {
119 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
120 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
123 const WORD wFB_Opt0[2][5] = {
124 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
125 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
127 const WORD wFB_Opt1[2][5] = {
128 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
129 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
137 #define RTSDUR_BA_F0 4
138 #define RTSDUR_AA_F0 5
139 #define RTSDUR_BA_F1 6
140 #define RTSDUR_AA_F1 7
141 #define CTSDUR_BA_F0 8
142 #define CTSDUR_BA_F1 9
145 #define DATADUR_A_F0 12
146 #define DATADUR_A_F1 13
148 /*--------------------- Static Functions --------------------------*/
158 IN PSKeyItem pTransmitKey,
172 IN UINT cbFrameLength,
175 IN PSEthernetHeader psEthHeader,
176 IN WORD wCurrentRate,
182 s_vGenerateTxParameter(
192 IN PSEthernetHeader psEthHeader,
198 static void s_vFillFragParameter(
213 IN PBYTE pbyTxBufferAddr,
214 IN UINT cbFrameBodySize,
217 IN PSEthernetHeader psEthHeader,
219 IN BOOL bNeedEncrypt,
220 IN PSKeyItem pTransmitKey,
222 OUT PUINT puMACfragNum
231 IN PVOID pTxDataHead,
232 IN UINT cbFrameLength,
236 IN UINT cbLastFragmentSize,
243 /*--------------------- Export Variables --------------------------*/
253 IN PSKeyItem pTransmitKey,
259 PDWORD pdwIV = (PDWORD) pbyIVHead;
260 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
262 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
263 DWORD dwRevIVCounter;
269 if (pTransmitKey == NULL)
272 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
273 *pdwIV = pDevice->dwIVCounter;
274 byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
276 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
277 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
278 MEMvCopy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
279 MEMvCopy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
281 MEMvCopy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
282 MEMvCopy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
283 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
284 MEMvCopy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
285 MEMvCopy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
287 MEMvCopy(pDevice->abyPRNG, pbyBuf, 16);
289 // Append IV after Mac Header
290 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
291 *pdwIV |= (byKeyIndex << 30);
292 *pdwIV = cpu_to_le32(*pdwIV);
293 pDevice->dwIVCounter++;
294 if (pDevice->dwIVCounter > WEP_IV_MASK) {
295 pDevice->dwIVCounter = 0;
297 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
298 pTransmitKey->wTSC15_0++;
299 if (pTransmitKey->wTSC15_0 == 0) {
300 pTransmitKey->dwTSC47_16++;
302 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
303 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
304 MEMvCopy(pbyBuf, pDevice->abyPRNG, 16);
306 MEMvCopy(pdwIV, pDevice->abyPRNG, 3);
308 *(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
309 // Append IV&ExtIV after Mac Header
310 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
311 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
313 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
314 pTransmitKey->wTSC15_0++;
315 if (pTransmitKey->wTSC15_0 == 0) {
316 pTransmitKey->dwTSC47_16++;
318 MEMvCopy(pbyBuf, pTransmitKey->abyKey, 16);
322 *(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
323 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
324 //Append IV&ExtIV after Mac Header
325 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
329 *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
330 MEMvCopy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
331 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
332 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
333 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
334 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
335 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
336 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
337 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
338 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
341 *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
342 if (pDevice->bLongHeader) {
343 *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
345 *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
347 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
348 MEMvCopy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
349 MEMvCopy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
350 MEMvCopy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
353 MEMvCopy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
354 wValue = pMACHeader->wSeqCtl;
356 wValue = cpu_to_le16(wValue);
357 MEMvCopy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
358 if (pDevice->bLongHeader) {
359 MEMvCopy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
369 IN PSKeyItem pTransmitKey,
370 IN PBYTE pbyPayloadHead,
375 DWORD dwICV = 0xFFFFFFFFL;
378 if (pTransmitKey == NULL)
381 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
382 //=======================================================================
383 // Append ICV after payload
384 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
385 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
386 // finally, we must invert dwCRC to get the correct answer
387 *pdwICV = cpu_to_le32(~dwICV);
389 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
390 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
391 //=======================================================================
392 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
393 //=======================================================================
394 //Append ICV after payload
395 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
396 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
397 // finally, we must invert dwCRC to get the correct answer
398 *pdwICV = cpu_to_le32(~dwICV);
400 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
401 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
402 //=======================================================================
409 /*byPktTyp : PK_TYPE_11A 0
419 IN UINT cbFrameLength,
424 UINT uDataTime, uAckTime;
426 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, cbFrameLength, wRate);
428 //printk("s_uGetTxRsvTime is %d\n",uDataTime);
430 if (byPktTyp == PK_TYPE_11B) {//llb,CCK mode
431 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, (WORD)pDevice->byTopCCKBasicRate);
432 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
433 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, (WORD)pDevice->byTopOFDMBasicRate);
437 return (uDataTime + pDevice->uSIFS + uAckTime);
444 //byFreqType: 0=>5GHZ 1=>2.4GHZ
447 s_uGetRTSCTSRsvTime (
449 IN BYTE byRTSRsvType,
451 IN UINT cbFrameLength,
455 UINT uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
457 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
460 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, cbFrameLength, wCurrentRate);
461 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
462 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 20, pDevice->byTopCCKBasicRate);
463 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopCCKBasicRate);
465 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
466 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 20, pDevice->byTopCCKBasicRate);
467 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopCCKBasicRate);
468 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopOFDMBasicRate);
470 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
471 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 20, pDevice->byTopOFDMBasicRate);
472 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopOFDMBasicRate);
474 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
475 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopCCKBasicRate);
476 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopOFDMBasicRate);
477 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
482 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
486 //byFreqType 0: 5GHz, 1:2.4Ghz
492 IN UINT cbFrameLength,
497 IN UINT cbLastFragmentSize,
503 UINT uAckTime =0, uNextPktTime = 0;
507 if (uFragIdx == (uMACfragNum-1)) {
514 case DATADUR_B: //DATADUR_B
515 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
517 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
518 return (pDevice->uSIFS + uAckTime);
523 else {//First Frag or Mid Frag
524 if (uFragIdx == (uMACfragNum-2)) {
525 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
527 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
530 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
531 return (pDevice->uSIFS + uAckTime + uNextPktTime);
533 return (pDevice->uSIFS + uNextPktTime);
538 case DATADUR_A: //DATADUR_A
539 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
541 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
542 return (pDevice->uSIFS + uAckTime);
547 else {//First Frag or Mid Frag
548 if(uFragIdx == (uMACfragNum-2)){
549 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
551 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
554 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
555 return (pDevice->uSIFS + uAckTime + uNextPktTime);
557 return (pDevice->uSIFS + uNextPktTime);
562 case DATADUR_A_F0: //DATADUR_A_F0
563 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
565 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
566 return (pDevice->uSIFS + uAckTime);
571 else { //First Frag or Mid Frag
572 if (byFBOption == AUTO_FB_0) {
573 if (wRate < RATE_18M)
575 else if (wRate > RATE_54M)
578 if(uFragIdx == (uMACfragNum-2)){
579 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
581 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
583 } else { // (byFBOption == AUTO_FB_1)
584 if (wRate < RATE_18M)
586 else if (wRate > RATE_54M)
589 if(uFragIdx == (uMACfragNum-2)){
590 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
592 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
597 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
598 return (pDevice->uSIFS + uAckTime + uNextPktTime);
600 return (pDevice->uSIFS + uNextPktTime);
605 case DATADUR_A_F1: //DATADUR_A_F1
606 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
608 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
609 return (pDevice->uSIFS + uAckTime);
614 else { //First Frag or Mid Frag
615 if (byFBOption == AUTO_FB_0) {
616 if (wRate < RATE_18M)
618 else if (wRate > RATE_54M)
621 if(uFragIdx == (uMACfragNum-2)){
622 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
624 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
627 } else { // (byFBOption == AUTO_FB_1)
628 if (wRate < RATE_18M)
630 else if (wRate > RATE_54M)
633 if(uFragIdx == (uMACfragNum-2)){
634 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
636 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
640 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
641 return (pDevice->uSIFS + uAckTime + uNextPktTime);
643 return (pDevice->uSIFS + uNextPktTime);
657 //byFreqType: 0=>5GHZ 1=>2.4GHZ
660 s_uGetRTSCTSDuration (
663 IN UINT cbFrameLength,
670 UINT uCTSTime = 0, uDurTime = 0;
675 case RTSDUR_BB: //RTSDuration_bb
676 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
677 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
680 case RTSDUR_BA: //RTSDuration_ba
681 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
682 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
685 case RTSDUR_AA: //RTSDuration_aa
686 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
687 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
690 case CTSDUR_BA: //CTSDuration_ba
691 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
694 case RTSDUR_BA_F0: //RTSDuration_ba_f0
695 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
696 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
697 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
698 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
699 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
703 case RTSDUR_AA_F0: //RTSDuration_aa_f0
704 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
705 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
706 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
707 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
708 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
712 case RTSDUR_BA_F1: //RTSDuration_ba_f1
713 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
714 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
715 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
716 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
717 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
721 case RTSDUR_AA_F1: //RTSDuration_aa_f1
722 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
723 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
724 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
725 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
726 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
730 case CTSDUR_BA_F0: //CTSDuration_ba_f0
731 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
732 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
733 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
734 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
738 case CTSDUR_BA_F1: //CTSDuration_ba_f1
739 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
740 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
741 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
742 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
761 IN PVOID pTxDataHead,
762 IN UINT cbFrameLength,
766 IN UINT cbLastFragmentSize,
774 if (pTxDataHead == NULL) {
778 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
779 if (byFBOption == AUTO_FB_NONE) {
780 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
781 //Get SignalField,ServiceField,Length
782 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
783 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
785 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
786 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
787 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
789 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
790 //Get Duration and TimeStamp
791 pBuf->wDuration_a = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
792 byPktTyp, wCurrentRate, bNeedAck, uFragIdx,
793 cbLastFragmentSize, uMACfragNum,
794 byFBOption)); //1: 2.4GHz
795 pBuf->wDuration_b = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
796 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
797 bNeedAck, uFragIdx, cbLastFragmentSize,
798 uMACfragNum, byFBOption)); //1: 2.4
800 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
801 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
803 return (pBuf->wDuration_a);
806 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
807 //Get SignalField,ServiceField,Length
808 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
809 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
811 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
812 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
813 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
815 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
816 //Get Duration and TimeStamp
817 pBuf->wDuration_a = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktTyp,
818 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
819 pBuf->wDuration_b = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
820 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
821 pBuf->wDuration_a_f0 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktTyp,
822 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
823 pBuf->wDuration_a_f1 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktTyp,
824 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
826 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
827 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
829 return (pBuf->wDuration_a);
830 } //if (byFBOption == AUTO_FB_NONE)
832 else if (byPktTyp == PK_TYPE_11A) {
833 if ((byFBOption != AUTO_FB_NONE)) {
835 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
836 //Get SignalField,ServiceField,Length
837 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
838 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
840 pBuf->wTransmitLength = cpu_to_le16(wLen);
841 //Get Duration and TimeStampOff
843 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktTyp,
844 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
845 pBuf->wDuration_f0 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktTyp,
846 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
847 pBuf->wDuration_f1 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktTyp,
848 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
849 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
850 return (pBuf->wDuration);
852 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
853 //Get SignalField,ServiceField,Length
854 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
855 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
857 pBuf->wTransmitLength = cpu_to_le16(wLen);
858 //Get Duration and TimeStampOff
860 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktTyp,
861 wCurrentRate, bNeedAck, uFragIdx,
862 cbLastFragmentSize, uMACfragNum,
865 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
866 return (pBuf->wDuration);
870 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
871 //Get SignalField,ServiceField,Length
872 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
873 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
875 pBuf->wTransmitLength = cpu_to_le16(wLen);
876 //Get Duration and TimeStampOff
877 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktTyp,
878 wCurrentRate, bNeedAck, uFragIdx,
879 cbLastFragmentSize, uMACfragNum,
881 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
882 return (pBuf->wDuration);
894 IN UINT cbFrameLength,
897 IN PSEthernetHeader psEthHeader,
898 IN WORD wCurrentRate,
902 UINT uRTSFrameLen = 20;
905 // dummy code, only to avoid compiler warning message
906 UNREFERENCED_PARAMETER(bNeedAck);
912 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
913 // in this case we need to decrease its length by 4.
917 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
918 // Otherwise, we need to modified codes for them.
919 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
920 if (byFBOption == AUTO_FB_NONE) {
921 PSRTS_g pBuf = (PSRTS_g)pvRTS;
922 //Get SignalField,ServiceField,Length
923 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
924 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
926 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
927 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
928 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
930 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
932 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
933 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
934 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
936 pBuf->Data.wDurationID = pBuf->wDuration_aa;
938 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
939 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
940 (pDevice->eOPMode == OP_MODE_AP)) {
941 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
944 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
946 if (pDevice->eOPMode == OP_MODE_AP) {
947 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
950 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
954 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
955 //Get SignalField,ServiceField,Length
956 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
957 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
959 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
960 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
961 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
963 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
966 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
967 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
968 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
969 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
970 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
971 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
972 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
973 pBuf->Data.wDurationID = pBuf->wDuration_aa;
975 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
977 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
978 (pDevice->eOPMode == OP_MODE_AP)) {
979 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
982 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
985 if (pDevice->eOPMode == OP_MODE_AP) {
986 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
989 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
992 } // if (byFBOption == AUTO_FB_NONE)
994 else if (byPktTyp == PK_TYPE_11A) {
995 if (byFBOption == AUTO_FB_NONE) {
996 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
997 //Get SignalField,ServiceField,Length
998 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
999 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1001 pBuf->wTransmitLength = cpu_to_le16(wLen);
1003 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1004 pBuf->Data.wDurationID = pBuf->wDuration;
1005 //Get RTS Frame body
1006 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1008 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1009 (pDevice->eOPMode == OP_MODE_AP)) {
1010 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1013 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1016 if (pDevice->eOPMode == OP_MODE_AP) {
1017 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1020 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1025 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
1026 //Get SignalField,ServiceField,Length
1027 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
1028 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1030 pBuf->wTransmitLength = cpu_to_le16(wLen);
1032 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1033 pBuf->wRTSDuration_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
1034 pBuf->wRTSDuration_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
1035 pBuf->Data.wDurationID = pBuf->wDuration;
1036 //Get RTS Frame body
1037 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1039 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1040 (pDevice->eOPMode == OP_MODE_AP)) {
1041 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1044 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1046 if (pDevice->eOPMode == OP_MODE_AP) {
1047 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1050 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1054 else if (byPktTyp == PK_TYPE_11B) {
1055 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1056 //Get SignalField,ServiceField,Length
1057 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1058 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1060 pBuf->wTransmitLength = cpu_to_le16(wLen);
1062 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1063 pBuf->Data.wDurationID = pBuf->wDuration;
1064 //Get RTS Frame body
1065 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1068 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1069 (pDevice->eOPMode == OP_MODE_AP)) {
1070 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1073 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1076 if (pDevice->eOPMode == OP_MODE_AP) {
1077 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1080 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1088 IN PSDevice pDevice,
1092 IN UINT cbFrameLength,
1095 IN WORD wCurrentRate,
1099 UINT uCTSFrameLen = 14;
1102 if (pvCTS == NULL) {
1107 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1108 // in this case we need to decrease its length by 4.
1112 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
1113 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1115 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1116 //Get SignalField,ServiceField,Length
1117 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1118 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1122 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1124 pBuf->wDuration_ba = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1125 pBuf->wDuration_ba += pDevice->wCTSDuration;
1126 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1127 //Get CTSDuration_ba_f0
1128 pBuf->wCTSDuration_ba_f0 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
1129 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1130 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1131 //Get CTSDuration_ba_f1
1132 pBuf->wCTSDuration_ba_f1 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
1133 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1134 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1135 //Get CTS Frame body
1136 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1137 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1138 pBuf->Data.wReserved = 0x0000;
1139 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1141 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1142 PSCTS pBuf = (PSCTS)pvCTS;
1143 //Get SignalField,ServiceField,Length
1144 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1145 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1147 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1148 //Get CTSDuration_ba
1149 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1150 pBuf->wDuration_ba += pDevice->wCTSDuration;
1151 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1153 //Get CTS Frame body
1154 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1155 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1156 pBuf->Data.wReserved = 0x0000;
1157 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1170 * Generate FIFO control for MAC & Baseband controller
1174 * pDevice - Pointer to adpater
1175 * pTxDataHead - Transmit Data Buffer
1176 * pTxBufHead - pTxBufHead
1177 * pvRrvTime - pvRrvTime
1178 * pvRTS - RTS Buffer
1180 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1181 * bNeedACK - If need ACK
1182 * uDescIdx - Desc Index
1186 * Return Value: none
1189 // UINT cbFrameSize,//Hdr+Payload+FCS
1192 s_vGenerateTxParameter (
1193 IN PSDevice pDevice,
1195 IN PVOID pTxBufHead,
1199 IN UINT cbFrameSize,
1202 IN PSEthernetHeader psEthHeader,
1203 IN WORD wCurrentRate
1206 UINT cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1208 BOOL bDisCRC = FALSE;
1209 BYTE byFBOption = AUTO_FB_NONE;
1210 // WORD wCurrentRate = pDevice->wCurrentRate;
1212 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1213 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1214 pFifoHead->wReserved = wCurrentRate;
1215 wFifoCtl = pFifoHead->wFIFOCtl;
1217 if (wFifoCtl & FIFOCTL_CRCDIS) {
1221 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1222 byFBOption = AUTO_FB_0;
1224 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1225 byFBOption = AUTO_FB_1;
1228 if (pDevice->bLongHeader)
1229 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1231 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
1233 if (pvRTS != NULL) { //RTS_need
1236 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1237 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktTyp, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1238 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktTyp, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1239 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktTyp, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1240 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktTyp, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1241 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1244 s_vFillRTSHead(pDevice, byPktTyp, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1246 else {//RTS_needless, PCF mode
1250 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1251 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktTyp, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1252 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1253 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktTyp, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1258 s_vFillCTSHead(pDevice, uDMAIdx, byPktTyp, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1261 else if (byPktTyp == PK_TYPE_11A) {
1263 if (pvRTS != NULL) {//RTS_need, non PCF mode
1266 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1267 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktTyp, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1268 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktTyp, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1271 s_vFillRTSHead(pDevice, byPktTyp, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1273 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1276 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1277 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1281 else if (byPktTyp == PK_TYPE_11B) {
1283 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1286 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1287 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktTyp, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1288 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1291 s_vFillRTSHead(pDevice, byPktTyp, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1293 else { //RTS_needless, non PCF mode
1296 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1297 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1301 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1304 PBYTE pbyBuffer,//point to pTxBufHead
1305 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1306 UINT cbFragmentSize,//Hdr+payoad+FCS
1310 s_vFillFragParameter(
1311 IN PSDevice pDevice,
1319 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
1320 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
1322 if (uTxType == TYPE_SYNCDMA) {
1323 //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1324 PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
1326 //Set FIFOCtl & TimeStamp in TxSyncDesc
1327 ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
1328 ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
1329 //Set TSR1 & ReqCount in TxDescHead
1330 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
1331 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1332 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1335 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1339 //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1340 PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
1341 //Set TSR1 & ReqCount in TxDescHead
1342 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
1343 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1344 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1347 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1351 pTxBufHead->wFragCtl |= (WORD)wFragType;//0x0001; //0000 0000 0000 0001
1353 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
1359 IN PSDevice pDevice,
1361 IN PBYTE pbyTxBufferAddr,
1362 IN UINT cbFrameBodySize,
1364 IN PSTxDesc pHeadTD,
1365 IN PSEthernetHeader psEthHeader,
1367 IN BOOL bNeedEncrypt,
1368 IN PSKeyItem pTransmitKey,
1370 OUT PUINT puMACfragNum
1375 UINT cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1376 UINT cbFragPayloadSize;
1377 UINT cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1378 UINT cbLastFragPayloadSize;
1380 PBYTE pbyPayloadHead;
1383 WORD wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
1386 // UINT uKeyEntryIdx = NUM_KEY_ENTRY+1;
1387 // BYTE byKeySel = 0xFF;
1392 UINT cb802_1_H_len = 0;
1398 DWORD dwMICKey0, dwMICKey1;
1399 DWORD dwMIC_Priority;
1402 DWORD dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
1403 BOOL bMIC2Frag = FALSE;
1404 UINT uMICFragLen = 0;
1405 UINT uMACfragNum = 1;
1407 UINT cbReqCount = 0;
1414 PSTxBufHead psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
1416 UINT cbHeaderLength = 0;
1418 PSMICHDRHead pMICHDR;
1422 WORD wTxBufSize; // FFinfo size
1423 UINT uTotalCopyLength = 0;
1424 BYTE byFBOption = AUTO_FB_NONE;
1425 BOOL bIsWEP256 = FALSE;
1426 PSMgmtObject pMgmt = pDevice->pMgmt;
1429 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1431 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
1432 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1433 (pDevice->eOPMode == OP_MODE_AP)) {
1435 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
1436 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
1445 // MSDUs in Infra mode always need ACK
1450 if (pDevice->bLongHeader)
1451 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1453 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1456 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL)) {
1457 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1460 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
1464 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1465 cbIVlen = 8;//IV+ExtIV
1469 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1470 cbIVlen = 8;//RSN Header
1472 cbMICHDR = sizeof(SMICHDRHead);
1474 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1475 //MAC Header should be padding 0 to DW alignment.
1476 uPadding = 4 - (cbMACHdLen%4);
1482 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1484 if ((bNeedACK == FALSE) ||
1485 (cbFrameSize < pDevice->wRTSThreshold) ||
1486 ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
1492 psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1495 // Use for AUTO FALL BACK
1497 if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1498 byFBOption = AUTO_FB_0;
1500 else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1501 byFBOption = AUTO_FB_1;
1504 //////////////////////////////////////////////////////
1505 //Set RrvTime/RTS/CTS Buffer
1506 wTxBufSize = sizeof(STxBufHead);
1507 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {//802.11g packet
1509 if (byFBOption == AUTO_FB_NONE) {
1510 if (bRTS == TRUE) {//RTS_need
1511 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1512 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1513 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1515 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1516 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1518 else { //RTS_needless
1519 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1520 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1522 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1523 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1524 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1528 if (bRTS == TRUE) {//RTS_need
1529 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1530 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1531 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1533 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1534 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1536 else { //RTS_needless
1537 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1538 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1540 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1541 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1542 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1546 else {//802.11a/b packet
1548 if (byFBOption == AUTO_FB_NONE) {
1550 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1551 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1552 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1554 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1555 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1557 else { //RTS_needless, need MICHDR
1558 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1559 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1562 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1563 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1567 if (bRTS == TRUE) {//RTS_need
1568 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1569 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1570 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1572 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1573 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1575 else { //RTS_needless
1576 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1577 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1580 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1581 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1585 ZERO_MEMORY((PVOID)(pbyTxBufferAddr + wTxBufSize), (cbHeaderLength - wTxBufSize));
1587 //////////////////////////////////////////////////////////////////
1588 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1589 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
1590 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1591 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1593 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1594 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1595 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1598 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1599 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1601 // DO Software Michael
1602 MIC_vInit(dwMICKey0, dwMICKey1);
1603 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1605 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1606 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1609 ///////////////////////////////////////////////////////////////////
1611 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1612 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1613 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1615 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == TRUE) && (bIsWEP256 == FALSE)) {
1617 // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
1618 cbFragmentSize = pDevice->wFragmentationThreshold;
1619 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
1620 //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
1621 uMACfragNum = (WORD) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
1622 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
1623 if (cbLastFragPayloadSize == 0) {
1624 cbLastFragPayloadSize = cbFragPayloadSize;
1628 //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
1629 cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
1631 for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx ++) {
1632 if (uFragIdx == 0) {
1633 //=========================
1634 // Start Fragmentation
1635 //=========================
1636 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start Fragmentation...\n");
1637 wFragType = FRAGCTL_STAFRAG;
1640 //Fill FIFO,RrvTime,RTS,and CTS
1641 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1642 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1644 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1645 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1646 // Generate TX MAC Header
1647 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1648 wFragType, uDMAIdx, uFragIdx);
1650 if (bNeedEncrypt == TRUE) {
1652 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1653 pbyMacHdr, (WORD)cbFragPayloadSize, (PBYTE)pMICHDR);
1654 //Fill IV(ExtIV,RSNHDR)
1655 if (pDevice->bEnableHostWEP) {
1656 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1657 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1663 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
1664 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1665 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1666 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1669 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1671 pbyType = (PBYTE) (pbyPayloadHead + 6);
1672 MEMvCopy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1676 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1677 //---------------------------
1678 // S/W or H/W Encryption
1679 //---------------------------
1681 //if (pDevice->bAES) {
1682 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1684 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (PVOID)psTxBufHd, byKeySel,
1685 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1689 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
1690 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1692 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1693 //copy TxBufferHeader + MacHeader to desc
1694 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1696 // Copy the Packet into a tx Buffer
1697 MEMvCopy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
1700 uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
1702 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1703 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start MIC: %d\n", cbFragPayloadSize);
1704 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
1708 //---------------------------
1710 //---------------------------
1711 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1713 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (WORD)cbFragPayloadSize);
1714 cbReqCount += cbICVlen;
1718 ptdCurr = (PSTxDesc)pHeadTD;
1719 //--------------------
1720 //1.Set TSR1 & ReqCount in TxDescHead
1721 //2.Set FragCtl in TxBufferHead
1722 //3.Set Frame Control
1723 //4.Set Sequence Control
1724 //5.Get S/W generate FCS
1725 //--------------------
1726 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1728 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1729 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1730 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1731 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1732 pDevice->iTDUsed[uDMAIdx]++;
1733 pHeadTD = ptdCurr->next;
1735 else if (uFragIdx == (uMACfragNum-1)) {
1736 //=========================
1737 // Last Fragmentation
1738 //=========================
1739 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last Fragmentation...\n");
1740 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1742 wFragType = FRAGCTL_ENDFRAG;
1744 //Fill FIFO,RrvTime,RTS,and CTS
1745 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1746 cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1748 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
1749 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1751 // Generate TX MAC Header
1752 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1753 wFragType, uDMAIdx, uFragIdx);
1755 if (bNeedEncrypt == TRUE) {
1757 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1758 pbyMacHdr, (WORD)cbLastFragPayloadSize, (PBYTE)pMICHDR);
1760 if (pDevice->bEnableHostWEP) {
1761 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1762 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1768 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
1769 //---------------------------
1770 // S/W or H/W Encryption
1771 //---------------------------
1775 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1776 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1778 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1780 //copy TxBufferHeader + MacHeader to desc
1781 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1783 // Copy the Packet into a tx Buffer
1784 if (bMIC2Frag == FALSE) {
1786 MEMvCopy((pbyBuffer + uLength),
1787 (pPacket + 14 + uTotalCopyLength),
1788 (cbLastFragPayloadSize - cbMIClen)
1790 //TODO check uTmpLen !
1791 uTmpLen = cbLastFragPayloadSize - cbMIClen;
1794 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1795 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
1796 uMICFragLen, cbLastFragPayloadSize, uTmpLen);
1798 if (bMIC2Frag == FALSE) {
1800 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1801 pdwMIC_L = (PDWORD)(pbyBuffer + uLength + uTmpLen);
1802 pdwMIC_R = (PDWORD)(pbyBuffer + uLength + uTmpLen + 4);
1803 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1804 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1806 if (uMICFragLen >= 4) {
1807 MEMvCopy((pbyBuffer + uLength), ((PBYTE)&dwSafeMIC_R + (uMICFragLen - 4)),
1808 (cbMIClen - uMICFragLen));
1809 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen >= 4: %X, %d\n",
1810 *(PBYTE)((PBYTE)&dwSafeMIC_R + (uMICFragLen - 4)),
1811 (cbMIClen - uMICFragLen));
1814 MEMvCopy((pbyBuffer + uLength), ((PBYTE)&dwSafeMIC_L + uMICFragLen),
1816 MEMvCopy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
1817 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen < 4: %X, %d\n",
1818 *(PBYTE)((PBYTE)&dwSafeMIC_R + uMICFragLen - 4),
1819 (cbMIClen - uMICFragLen));
1822 for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
1823 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii - 8 - 24)));
1825 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1830 ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
1834 //---------------------------
1836 //---------------------------
1837 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1839 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (WORD)cbLastFragPayloadSize);
1840 cbReqCount += cbICVlen;
1844 ptdCurr = (PSTxDesc)pHeadTD;
1846 //--------------------
1847 //1.Set TSR1 & ReqCount in TxDescHead
1848 //2.Set FragCtl in TxBufferHead
1849 //3.Set Frame Control
1850 //4.Set Sequence Control
1851 //5.Get S/W generate FCS
1852 //--------------------
1855 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1857 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1858 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1859 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1860 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1861 pDevice->iTDUsed[uDMAIdx]++;
1862 pHeadTD = ptdCurr->next;
1866 //=========================
1867 // Middle Fragmentation
1868 //=========================
1869 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle Fragmentation...\n");
1870 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1872 wFragType = FRAGCTL_MIDFRAG;
1874 //Fill FIFO,RrvTime,RTS,and CTS
1875 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1876 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1878 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1879 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1881 // Generate TX MAC Header
1882 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1883 wFragType, uDMAIdx, uFragIdx);
1886 if (bNeedEncrypt == TRUE) {
1888 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1889 pbyMacHdr, (WORD)cbFragPayloadSize, (PBYTE)pMICHDR);
1891 if (pDevice->bEnableHostWEP) {
1892 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1893 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1897 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1898 //---------------------------
1899 // S/W or H/W Encryption
1900 //---------------------------
1902 //if (pDevice->bAES) {
1903 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1905 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (PVOID)psTxBufHd, byKeySel,
1906 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1909 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1910 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1913 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1915 //copy TxBufferHeader + MacHeader to desc
1916 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1918 // Copy the Packet into a tx Buffer
1919 MEMvCopy((pbyBuffer + uLength),
1920 (pPacket + 14 + uTotalCopyLength),
1923 uTmpLen = cbFragPayloadSize;
1925 uTotalCopyLength += uTmpLen;
1927 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1929 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1931 if (uTmpLen < cbFragPayloadSize) {
1933 uMICFragLen = cbFragPayloadSize - uTmpLen;
1934 ASSERT(uMICFragLen < cbMIClen);
1936 pdwMIC_L = (PDWORD)(pbyBuffer + uLength + uTmpLen);
1937 pdwMIC_R = (PDWORD)(pbyBuffer + uLength + uTmpLen + 4);
1938 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1939 dwSafeMIC_L = *pdwMIC_L;
1940 dwSafeMIC_R = *pdwMIC_R;
1942 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
1943 uMICFragLen, cbFragPayloadSize, uTmpLen);
1944 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MIC in Middle frag [%d]\n", uMICFragLen);
1946 for (ii = 0; ii < uMICFragLen; ii++) {
1947 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength + uTmpLen) + ii)));
1949 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1951 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1953 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle frag len: %d\n", uTmpLen);
1955 for (ii = 0; ii < uTmpLen; ii++) {
1956 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
1958 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1962 ASSERT(uTmpLen == (cbFragPayloadSize));
1965 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1967 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (WORD)cbFragPayloadSize);
1968 cbReqCount += cbICVlen;
1972 ptdCurr = (PSTxDesc)pHeadTD;
1974 //--------------------
1975 //1.Set TSR1 & ReqCount in TxDescHead
1976 //2.Set FragCtl in TxBufferHead
1977 //3.Set Frame Control
1978 //4.Set Sequence Control
1979 //5.Get S/W generate FCS
1980 //--------------------
1982 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1984 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1985 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1986 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1987 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1988 pDevice->iTDUsed[uDMAIdx]++;
1989 pHeadTD = ptdCurr->next;
1991 } // for (uMACfragNum)
1994 //=========================
1996 //=========================
1997 //DEVICE_PRTGRP03(("No Fragmentation...\n"));
1998 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1999 wFragType = FRAGCTL_NONFRAG;
2001 //Set FragCtl in TxBufferHead
2002 psTxBufHd->wFragCtl |= (WORD)wFragType;
2004 //Fill FIFO,RrvTime,RTS,and CTS
2005 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
2006 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
2008 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
2009 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
2011 // Generate TX MAC Header
2012 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
2013 wFragType, uDMAIdx, 0);
2015 if (bNeedEncrypt == TRUE) {
2017 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
2018 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
2020 if (pDevice->bEnableHostWEP) {
2021 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2022 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2027 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
2028 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
2029 (psEthHeader->wType == cpu_to_le16(0xF380))) {
2030 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
2033 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
2035 pbyType = (PBYTE) (pbyPayloadHead + 6);
2036 MEMvCopy(pbyType, &(psEthHeader->wType), sizeof(WORD));
2040 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
2041 //---------------------------
2042 // S/W or H/W Encryption
2043 //---------------------------
2045 //if (pDevice->bAES) {
2046 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
2047 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFrameBodySize);
2050 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
2051 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
2053 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
2055 //copy TxBufferHeader + MacHeader to desc
2056 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
2058 // Copy the Packet into a tx Buffer
2059 MEMvCopy((pbyBuffer + uLength),
2061 cbFrameBodySize - cb802_1_H_len
2064 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)){
2066 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
2068 for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
2069 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
2071 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2074 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
2076 pdwMIC_L = (PDWORD)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
2077 pdwMIC_R = (PDWORD)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
2079 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2083 if (pDevice->bTxMICFail == TRUE) {
2086 pDevice->bTxMICFail = FALSE;
2089 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2090 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
2091 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2093 for (ii = 0; ii < 8; ii++) {
2094 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((PBYTE)(pdwMIC_L) + ii)));
2096 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2102 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)){
2104 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
2105 (WORD)(cbFrameBodySize + cbMIClen));
2106 cbReqCount += cbICVlen;
2111 ptdCurr = (PSTxDesc)pHeadTD;
2113 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
2114 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
2115 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
2116 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
2117 //Set TSR1 & ReqCount in TxDescHead
2118 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
2119 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
2121 pDevice->iTDUsed[uDMAIdx]++;
2124 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
2125 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
2128 *puMACfragNum = uMACfragNum;
2129 //DEVICE_PRTGRP03(("s_cbFillTxBufHead END\n"));
2130 return cbHeaderLength;
2135 vGenerateFIFOHeader (
2136 IN PSDevice pDevice,
2138 IN PBYTE pbyTxBufferAddr,
2139 IN BOOL bNeedEncrypt,
2140 IN UINT cbPayloadSize,
2142 IN PSTxDesc pHeadTD,
2143 IN PSEthernetHeader psEthHeader,
2145 IN PSKeyItem pTransmitKey,
2147 OUT PUINT puMACfragNum,
2148 OUT PUINT pcbHeaderSize
2151 UINT wTxBufSize; // FFinfo size
2155 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2157 wTxBufSize = sizeof(STxBufHead);
2159 ZERO_MEMORY(pTxBufHead, wTxBufSize);
2160 //Set FIFOCTL_NEEDACK
2162 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2163 (pDevice->eOPMode == OP_MODE_AP)) {
2164 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
2165 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
2167 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
2171 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2176 // MSDUs in Infra mode always need ACK
2178 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2183 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2184 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2187 if (pDevice->bLongHeader)
2188 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
2190 //Set FIFOCTL_GENINT
2192 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2195 //Set FIFOCTL_ISDMA0
2196 if (TYPE_TXDMA0 == uDMAIdx) {
2197 pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
2200 //Set FRAGCTL_MACHDCNT
2201 if (pDevice->bLongHeader) {
2202 cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
2204 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2206 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2209 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2212 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2213 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2215 else if (byPktTyp == PK_TYPE_11GB) {//0000 0010 0000 0000
2216 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2218 else if (byPktTyp == PK_TYPE_11GA) {//0000 0011 0000 0000
2219 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2221 //Set FIFOCTL_GrpAckPolicy
2222 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2223 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2226 //Set Auto Fallback Ctl
2227 if (pDevice->wCurrentRate >= RATE_18M) {
2228 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
2229 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
2230 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
2231 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
2235 //Set FRAGCTL_WEPTYP
2236 pDevice->bAES = FALSE;
2238 //Set FRAGCTL_WEPTYP
2239 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
2240 if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
2241 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2242 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2244 else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
2245 if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
2246 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2248 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
2249 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2255 //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2257 //if (pDevice->wCurrentRate <= 3)
2259 // RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
2263 RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
2265 //if (pDevice->wCurrentRate == 3)
2266 //pDevice->byCurPwr = 46;
2267 pTxBufHead->byTxPower = pDevice->byCurPwr;
2273 if(pDevice->bEnableHostWEP)
2274 pTxBufHead->wFragCtl &= ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
2276 *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktTyp, pbyTxBufferAddr, cbPayloadSize,
2277 uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
2278 pTransmitKey, uNodeIndex, puMACfragNum);
2289 * Translate 802.3 to 802.11 header
2293 * pDevice - Pointer to adpater
2294 * dwTxBufferAddr - Transmit Buffer
2295 * pPacket - Packet from upper layer
2296 * cbPacketSize - Transmit Data Length
2298 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
2299 * pcbAppendPayload - size of append payload for 802.1H translation
2301 * Return Value: none
2306 vGenerateMACHeader (
2307 IN PSDevice pDevice,
2308 IN PBYTE pbyBufferAddr,
2310 IN PSEthernetHeader psEthHeader,
2311 IN BOOL bNeedEncrypt,
2317 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
2319 ZERO_MEMORY(pMACHeader, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
2321 if (uDMAIdx == TYPE_ATIMDMA) {
2322 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
2324 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
2327 if (pDevice->eOPMode == OP_MODE_AP) {
2328 MEMvCopy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2329 MEMvCopy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2330 MEMvCopy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2331 pMACHeader->wFrameCtl |= FC_FROMDS;
2334 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2335 MEMvCopy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2336 MEMvCopy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2337 MEMvCopy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2340 MEMvCopy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2341 MEMvCopy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2342 MEMvCopy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2343 pMACHeader->wFrameCtl |= FC_TODS;
2348 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
2350 pMACHeader->wDurationID = cpu_to_le16(wDuration);
2352 if (pDevice->bLongHeader) {
2353 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
2354 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
2355 MEMvCopy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
2357 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2359 //Set FragNumber in Sequence Control
2360 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
2362 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
2363 pDevice->wSeqCounter++;
2364 if (pDevice->wSeqCounter > 0x0fff)
2365 pDevice->wSeqCounter = 0;
2368 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
2369 pMACHeader->wFrameCtl |= FC_MOREFRAG;
2378 CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2382 PBYTE pbyTxBufferAddr;
2388 PS802_11Header pMACHeader;
2390 UINT cbFrameBodySize;
2392 BOOL bIsPSPOLL = FALSE;
2393 PSTxBufHead pTxBufHead;
2402 SEthernetHeader sEthHeader;
2405 PSMgmtObject pMgmt = pDevice->pMgmt;
2406 WORD wCurrentRate = RATE_1M;
2409 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2410 return CMD_STATUS_RESOURCES;
2413 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2414 pbyTxBufferAddr = (PBYTE)pFrstTD->pTDInfo->buf;
2415 cbFrameBodySize = pPacket->cbPayloadLen;
2416 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2417 wTxBufSize = sizeof(STxBufHead);
2418 memset(pTxBufHead, 0, wTxBufSize);
2420 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2421 wCurrentRate = RATE_6M;
2422 byPktTyp = PK_TYPE_11A;
2424 wCurrentRate = RATE_1M;
2425 byPktTyp = PK_TYPE_11B;
2428 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2429 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2430 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2431 // to set power here.
2432 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2434 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2436 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2438 pTxBufHead->byTxPower = pDevice->byCurPwr;
2439 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2440 if (pDevice->byFOETuning) {
2441 if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2442 wCurrentRate = RATE_24M;
2443 byPktTyp = PK_TYPE_11GA;
2448 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2449 pTxBufHead->wFIFOCtl = 0;
2451 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2452 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2454 else if (byPktTyp == PK_TYPE_11GB) {//0000 0010 0000 0000
2455 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2457 else if (byPktTyp == PK_TYPE_11GA) {//0000 0011 0000 0000
2458 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2461 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2462 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2465 if (IS_MULTICAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0])) ||
2466 IS_BROADCAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0]))) {
2471 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2474 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2475 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2477 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2478 //Set Preamble type always long
2479 //pDevice->byPreambleType = PREAMBLE_LONG;
2480 // probe-response don't retry
2481 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2482 // bNeedACK = FALSE;
2483 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2487 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2489 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2491 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2493 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2496 //Set FRAGCTL_MACHDCNT
2497 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2500 // Although spec says MMPDU can be fragmented; In most case,
2501 // no one will send a MMPDU under fragmentation. With RTS may occur.
2502 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2504 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2505 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2508 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2510 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2511 cbIVlen = 8;//IV+ExtIV
2514 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2515 //We need to get seed here for filling TxKey entry.
2516 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2517 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2519 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2520 cbIVlen = 8;//RSN Header
2522 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2523 pDevice->bAES = TRUE;
2525 //MAC Header should be padding 0 to DW alignment.
2526 uPadding = 4 - (cbMacHdLen%4);
2530 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2532 //Set FIFOCTL_GrpAckPolicy
2533 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2534 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2536 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2538 //Set RrvTime/RTS/CTS Buffer
2539 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {//802.11g packet
2541 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2544 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2545 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2546 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2548 else { // 802.11a/b packet
2549 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2553 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2554 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2557 ZERO_MEMORY((PVOID)(pbyTxBufferAddr + wTxBufSize), (cbHeaderSize - wTxBufSize));
2559 MEMvCopy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
2560 MEMvCopy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
2561 //=========================
2563 //=========================
2564 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2567 //Fill FIFO,RrvTime,RTS,and CTS
2568 s_vGenerateTxParameter(pDevice, byPktTyp, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2569 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2572 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2573 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2575 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2577 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2579 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2581 PBYTE pbyPayloadHead;
2583 PSKeyItem pTransmitKey = NULL;
2585 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2586 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2589 //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet.
2590 //s_vFillTxKey(pDevice, (PBYTE)pTxBufHead->adwTxKey, NULL);
2592 //Fill IV(ExtIV,RSNHDR)
2593 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
2594 //---------------------------
2595 // S/W or H/W Encryption
2596 //---------------------------
2598 //if (pDevice->bAES) {
2599 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, (PBYTE)pMACHeader, (WORD)cbFrameBodySize);
2602 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2603 (pDevice->bLinkPass == TRUE)) {
2604 pbyBSSID = pDevice->abyBSSID;
2606 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2608 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2609 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2613 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2618 pbyBSSID = pDevice->abyBroadcastAddr;
2619 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2620 pTransmitKey = NULL;
2621 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2623 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2627 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2628 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2630 MEMvCopy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2631 MEMvCopy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2635 // Copy the Packet into a tx Buffer
2636 MEMvCopy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2639 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2640 pDevice->wSeqCounter++ ;
2641 if (pDevice->wSeqCounter > 0x0fff)
2642 pDevice->wSeqCounter = 0;
2645 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2646 // of FIFO control header.
2647 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2648 // in the same place of other packet's Duration-field).
2649 // And it will cause Cisco-AP to issue Disassociation-packet
2650 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
2651 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2652 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2654 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2659 // first TD is the only TD
2660 //Set TSR1 & ReqCount in TxDescHead
2661 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
2662 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
2663 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
2664 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2665 pFrstTD->pTDInfo->byFlags = 0;
2667 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2669 MACbPSWakeup(pDevice->PortOffset);
2671 pDevice->bPWBitOn = FALSE;
2674 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2677 pDevice->iTDUsed[TYPE_TXDMA0]++;
2679 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
2680 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
2683 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
2685 //printk("SCAN:CurrentRate is %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
2689 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2692 // Poll Transmit the adapter
2693 MACvTransmit0(pDevice->PortOffset);
2695 return CMD_STATUS_PENDING;
2700 CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2703 PBYTE pbyBuffer = (PBYTE)pDevice->tx_beacon_bufs;
2704 UINT cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2705 UINT cbHeaderSize = 0;
2706 WORD wTxBufSize = sizeof(STxShortBufHead);
2707 PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
2708 PSTxDataHead_ab pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
2709 PS802_11Header pMACHeader;
2714 memset(pTxBufHead, 0, wTxBufSize);
2716 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2717 wCurrentRate = RATE_6M;
2718 byPktTyp = PK_TYPE_11A;
2720 wCurrentRate = RATE_2M;
2721 byPktTyp = PK_TYPE_11B;
2724 //Set Preamble type always long
2725 pDevice->byPreambleType = PREAMBLE_LONG;
2727 //Set FIFOCTL_GENINT
2729 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2732 //Set packet type & Get Duration
2733 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2734 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktTyp,
2735 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2737 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2738 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2739 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktTyp,
2740 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2743 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktTyp,
2744 (PWORD)&(wLen), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2746 pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
2748 pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
2749 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2751 //Generate Beacon Header
2752 pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
2753 MEMvCopy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2755 pMACHeader->wDurationID = 0;
2756 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2757 pDevice->wSeqCounter++ ;
2758 if (pDevice->wSeqCounter > 0x0fff)
2759 pDevice->wSeqCounter = 0;
2761 // Set Beacon buffer length
2762 pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
2764 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
2766 MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
2767 // Set auto Transmit on
2768 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2769 // Poll Transmit the adapter
2770 MACvTransmitBCN(pDevice->PortOffset);
2772 return CMD_STATUS_PENDING;
2779 IN PSDevice pDevice,
2780 IN PSKeyItem pTransmitKey,
2781 IN UINT cbFrameBodySize,
2782 IN PSEthernetHeader psEthHeader
2787 UINT cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
2788 UINT cbFragPayloadSize;
2789 UINT cbLastFragPayloadSize;
2794 UINT uMACfragNum = 1;
2799 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2800 (pDevice->eOPMode == OP_MODE_AP)) {
2801 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
2802 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
2810 // MSDUs in Infra mode always need ACK
2814 if (pDevice->bLongHeader)
2815 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
2817 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
2820 if (pDevice->bEncryptionEnable == TRUE) {
2822 if (pTransmitKey == NULL) {
2823 if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
2824 (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
2827 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2828 cbIVlen = 8;//IV+ExtIV
2831 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2832 cbIVlen = 8;//RSN Header
2835 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
2838 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2839 cbIVlen = 8;//IV+ExtIV
2842 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
2843 cbIVlen = 8;//RSN Header
2848 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
2850 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == TRUE)) {
2852 cbFragmentSize = pDevice->wFragmentationThreshold;
2853 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
2854 uMACfragNum = (WORD) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
2855 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
2856 if (cbLastFragPayloadSize == 0) {
2857 cbLastFragPayloadSize = cbFragPayloadSize;
2867 vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, PBYTE pbMPDU, UINT cbMPDULen) {
2871 PBYTE pbyTxBufferAddr;
2877 PS802_11Header pMACHeader;
2879 UINT cbFrameBodySize;
2881 BOOL bIsPSPOLL = FALSE;
2882 PSTxBufHead pTxBufHead;
2891 DWORD dwMICKey0, dwMICKey1;
2892 DWORD dwMIC_Priority;
2897 SEthernetHeader sEthHeader;
2900 PSMgmtObject pMgmt = pDevice->pMgmt;
2901 WORD wCurrentRate = RATE_1M;
2902 PUWLAN_80211HDR p80211Header;
2903 UINT uNodeIndex = 0;
2904 BOOL bNodeExist = FALSE;
2906 PSKeyItem pTransmitKey = NULL;
2908 PBYTE pbyPayloadHead;
2911 UINT cbExtSuppRate = 0;
2915 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2917 if(cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
2918 cbFrameBodySize = 0;
2921 cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
2923 p80211Header = (PUWLAN_80211HDR)pbMPDU;
2926 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2927 pbyTxBufferAddr = (PBYTE)pFrstTD->pTDInfo->buf;
2928 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2929 wTxBufSize = sizeof(STxBufHead);
2930 memset(pTxBufHead, 0, wTxBufSize);
2932 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2933 wCurrentRate = RATE_6M;
2934 byPktTyp = PK_TYPE_11A;
2936 wCurrentRate = RATE_1M;
2937 byPktTyp = PK_TYPE_11B;
2940 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2941 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2942 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2943 // to set power here.
2944 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2945 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2947 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2949 pTxBufHead->byTxPower = pDevice->byCurPwr;
2951 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2952 if (pDevice->byFOETuning) {
2953 if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2954 wCurrentRate = RATE_24M;
2955 byPktTyp = PK_TYPE_11GA;
2959 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2962 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2963 pTxBufHead->wFIFOCtl = 0;
2965 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2966 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2968 else if (byPktTyp == PK_TYPE_11GB) {//0000 0010 0000 0000
2969 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2971 else if (byPktTyp == PK_TYPE_11GA) {//0000 0011 0000 0000
2972 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2975 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2976 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2979 if (IS_MULTICAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0])) ||
2980 IS_BROADCAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0]))) {
2982 if (pDevice->bEnableHostWEP) {
2988 if (pDevice->bEnableHostWEP) {
2989 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2993 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2996 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2997 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2999 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
3000 //Set Preamble type always long
3001 //pDevice->byPreambleType = PREAMBLE_LONG;
3003 // probe-response don't retry
3004 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
3005 // bNeedACK = FALSE;
3006 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
3010 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
3012 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
3014 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
3016 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
3019 // hostapd deamon ext support rate patch
3020 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
3022 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
3023 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
3026 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
3027 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3030 if (cbExtSuppRate >0) {
3031 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
3036 //Set FRAGCTL_MACHDCNT
3037 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
3040 // Although spec says MMPDU can be fragmented; In most case,
3041 // no one will send a MMPDU under fragmentation. With RTS may occur.
3042 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
3045 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3046 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
3049 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
3051 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
3052 cbIVlen = 8;//IV+ExtIV
3055 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
3056 //We need to get seed here for filling TxKey entry.
3057 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
3058 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
3060 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
3061 cbIVlen = 8;//RSN Header
3063 cbMICHDR = sizeof(SMICHDRHead);
3064 pTxBufHead->wFragCtl |= FRAGCTL_AES;
3065 pDevice->bAES = TRUE;
3067 //MAC Header should be padding 0 to DW alignment.
3068 uPadding = 4 - (cbMacHdLen%4);
3072 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
3074 //Set FIFOCTL_GrpAckPolicy
3075 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
3076 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
3078 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
3081 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {//802.11g packet
3083 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
3084 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
3086 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
3087 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
3088 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
3091 else {//802.11a/b packet
3093 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
3094 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
3097 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
3098 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
3102 ZERO_MEMORY((PVOID)(pbyTxBufferAddr + wTxBufSize), (cbHeaderSize - wTxBufSize));
3103 MEMvCopy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
3104 MEMvCopy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
3105 //=========================
3107 //=========================
3108 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
3111 //Fill FIFO,RrvTime,RTS,and CTS
3112 s_vGenerateTxParameter(pDevice, byPktTyp, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
3113 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
3116 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
3117 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
3119 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
3121 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
3123 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
3124 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
3125 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
3127 // Copy the Packet into a tx Buffer
3128 memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
3130 // version set to 0, patch for hostapd deamon
3131 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
3132 memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
3134 // replace support rate, patch for hostapd deamon( only support 11M)
3135 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
3136 if (cbExtSuppRate != 0) {
3137 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
3138 memcpy((pbyPayloadHead + cbFrameBodySize),
3139 pMgmt->abyCurrSuppRates,
3140 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
3142 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
3143 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
3144 pMgmt->abyCurrExtSuppRates,
3145 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3151 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3153 if (pDevice->bEnableHostWEP) {
3154 pTransmitKey = &STempKey;
3155 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3156 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3157 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3158 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3159 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3160 memcpy(pTransmitKey->abyKey,
3161 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3162 pTransmitKey->uKeyLength
3166 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
3168 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
3169 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
3171 // DO Software Michael
3172 MIC_vInit(dwMICKey0, dwMICKey1);
3173 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
3175 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
3176 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
3178 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
3180 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
3182 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
3183 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
3185 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
3188 if (pDevice->bTxMICFail == TRUE) {
3191 pDevice->bTxMICFail = FALSE;
3194 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
3195 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
3196 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
3201 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
3202 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
3204 if (pDevice->bEnableHostWEP) {
3205 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
3206 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
3209 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
3210 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
3214 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
3215 pDevice->wSeqCounter++ ;
3216 if (pDevice->wSeqCounter > 0x0fff)
3217 pDevice->wSeqCounter = 0;
3221 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
3222 // of FIFO control header.
3223 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
3224 // in the same place of other packet's Duration-field).
3225 // And it will cause Cisco-AP to issue Disassociation-packet
3226 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
3227 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
3228 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
3230 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
3235 // first TD is the only TD
3236 //Set TSR1 & ReqCount in TxDescHead
3237 pFrstTD->pTDInfo->skb = skb;
3238 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
3239 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
3240 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
3241 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
3242 pFrstTD->pTDInfo->byFlags = 0;
3243 pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
3245 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
3247 MACbPSWakeup(pDevice->PortOffset);
3249 pDevice->bPWBitOn = FALSE;
3252 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
3255 pDevice->iTDUsed[TYPE_TXDMA0]++;
3257 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
3258 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
3261 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
3263 // Poll Transmit the adapter
3264 MACvTransmit0(pDevice->PortOffset);