2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
28 * s_vGenerateTxParameter - Generate tx dma required parameter.
29 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
34 * s_uGetRTSCTSDuration- get rtx/cts required duration
35 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
38 * s_vFillFragParameter- Set fragment ctl parameter.
39 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
66 /*--------------------- Static Definitions -------------------------*/
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
71 static int msglevel = MSG_LEVEL_INFO;
73 /*--------------------- Static Functions --------------------------*/
75 /*--------------------- Static Definitions -------------------------*/
77 const WORD wTimeStampOff[2][MAX_RATE] = {
78 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
79 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
82 const WORD wFB_Opt0[2][5] = {
83 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
84 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
86 const WORD wFB_Opt1[2][5] = {
87 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
88 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
96 #define RTSDUR_BA_F0 4
97 #define RTSDUR_AA_F0 5
98 #define RTSDUR_BA_F1 6
99 #define RTSDUR_AA_F1 7
100 #define CTSDUR_BA_F0 8
101 #define CTSDUR_BA_F1 9
104 #define DATADUR_A_F0 12
105 #define DATADUR_A_F1 13
107 /*--------------------- Static Functions --------------------------*/
128 s_vGenerateTxParameter(
136 unsigned int cbFrameSize,
138 unsigned int uDMAIdx,
139 PSEthernetHeader psEthHeader
143 static unsigned int s_uFillDataHead(
148 unsigned int cbFrameLength,
149 unsigned int uDMAIdx,
151 unsigned int uFragIdx,
152 unsigned int cbLastFragmentSize,
153 unsigned int uMACfragNum,
162 s_vGenerateMACHeader (
166 PSEthernetHeader psEthHeader,
169 unsigned int uDMAIdx,
170 unsigned int uFragIdx
179 PSKeyItem pTransmitKey,
189 PSKeyItem pTransmitKey,
190 PBYTE pbyPayloadHead,
194 static unsigned int s_uGetTxRsvTime(
197 unsigned int cbFrameLength,
203 static unsigned int s_uGetRTSCTSRsvTime(
207 unsigned int cbFrameLength,
215 unsigned int uDMAIdx,
218 unsigned int cbFrameLength,
231 unsigned int cbFrameLength,
234 PSEthernetHeader psEthHeader,
239 static unsigned int s_uGetDataDuration(
242 unsigned int cbFrameLength,
246 unsigned int uFragIdx,
247 unsigned int cbLastFragmentSize,
248 unsigned int uMACfragNum,
255 s_uGetRTSCTSDuration (
258 unsigned int cbFrameLength,
266 /*--------------------- Export Variables --------------------------*/
274 PUSB_SEND_CONTEXT pContext = NULL;
275 PUSB_SEND_CONTEXT pReturnContext = NULL;
278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
280 for (ii = 0; ii < pDevice->cbTD; ii++) {
281 pContext = pDevice->apTD[ii];
282 if (pContext->bBoolInUse == FALSE) {
283 pContext->bBoolInUse = TRUE;
284 pReturnContext = pContext;
288 if ( ii == pDevice->cbTD ) {
289 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
291 return (void *) pReturnContext;
297 s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLength, WORD wFIFOCtl)
299 PSStatCounter pStatistic=&(pDevice->scStatistic);
301 if (is_broadcast_ether_addr(pbyDestAddr))
302 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
303 else if (is_multicast_ether_addr(pbyDestAddr))
304 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
306 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
308 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
309 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
310 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
321 PSKeyItem pTransmitKey,
327 PDWORD pdwIV = (PDWORD) pbyIVHead;
328 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
330 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
331 DWORD dwRevIVCounter;
336 if (pTransmitKey == NULL)
339 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
340 *pdwIV = pDevice->dwIVCounter;
341 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
343 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
344 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
345 memcpy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
346 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
348 memcpy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
349 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
350 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
351 memcpy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
352 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
354 memcpy(pDevice->abyPRNG, pbyBuf, 16);
356 // Append IV after Mac Header
357 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
358 *pdwIV |= (unsigned long)pDevice->byKeyIndex << 30;
359 *pdwIV = cpu_to_le32(*pdwIV);
360 pDevice->dwIVCounter++;
361 if (pDevice->dwIVCounter > WEP_IV_MASK) {
362 pDevice->dwIVCounter = 0;
364 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
365 pTransmitKey->wTSC15_0++;
366 if (pTransmitKey->wTSC15_0 == 0) {
367 pTransmitKey->dwTSC47_16++;
369 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
370 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
371 memcpy(pbyBuf, pDevice->abyPRNG, 16);
373 memcpy(pdwIV, pDevice->abyPRNG, 3);
375 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
376 // Append IV&ExtIV after Mac Header
377 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
380 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
381 pTransmitKey->wTSC15_0++;
382 if (pTransmitKey->wTSC15_0 == 0) {
383 pTransmitKey->dwTSC47_16++;
385 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
389 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
390 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
391 //Append IV&ExtIV after Mac Header
392 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
396 *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
397 memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
398 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
399 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
400 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
401 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
402 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
403 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
404 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
405 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
408 *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
409 if (pDevice->bLongHeader) {
410 *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
412 *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
414 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
415 memcpy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
416 memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
417 memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
420 memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
421 wValue = pMACHeader->wSeqCtl;
423 wValue = cpu_to_le16(wValue);
424 memcpy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
425 if (pDevice->bLongHeader) {
426 memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
436 PSKeyItem pTransmitKey,
437 PBYTE pbyPayloadHead,
441 unsigned int cbICVlen = 4;
442 DWORD dwICV = 0xFFFFFFFFL;
445 if (pTransmitKey == NULL)
448 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
449 //=======================================================================
450 // Append ICV after payload
451 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
452 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
453 // finally, we must invert dwCRC to get the correct answer
454 *pdwICV = cpu_to_le32(~dwICV);
456 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
457 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
458 //=======================================================================
459 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
460 //=======================================================================
461 //Append ICV after payload
462 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
463 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
464 // finally, we must invert dwCRC to get the correct answer
465 *pdwICV = cpu_to_le32(~dwICV);
467 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
468 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
469 //=======================================================================
476 /*byPktType : PK_TYPE_11A 0
486 unsigned int cbFrameLength,
491 unsigned int uDataTime, uAckTime;
493 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
494 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
495 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopCCKBasicRate);
496 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
497 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopOFDMBasicRate);
501 return (uDataTime + pDevice->uSIFS + uAckTime);
508 //byFreqType: 0=>5GHZ 1=>2.4GHZ
511 s_uGetRTSCTSRsvTime (
515 unsigned int cbFrameLength,
519 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
521 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
524 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
525 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
526 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
527 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
529 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
530 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
531 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
532 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
534 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
535 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
536 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
538 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
539 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
540 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
541 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
546 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
550 //byFreqType 0: 5GHz, 1:2.4Ghz
556 unsigned int cbFrameLength,
560 unsigned int uFragIdx,
561 unsigned int cbLastFragmentSize,
562 unsigned int uMACfragNum,
567 unsigned int uAckTime = 0, uNextPktTime = 0;
569 if (uFragIdx == (uMACfragNum-1)) {
575 case DATADUR_B: //DATADUR_B
576 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
578 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
579 return (pDevice->uSIFS + uAckTime);
584 else {//First Frag or Mid Frag
585 if (uFragIdx == (uMACfragNum-2)) {
586 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
588 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
591 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
592 return (pDevice->uSIFS + uAckTime + uNextPktTime);
594 return (pDevice->uSIFS + uNextPktTime);
600 case DATADUR_A: //DATADUR_A
601 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
603 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
604 return (pDevice->uSIFS + uAckTime);
609 else {//First Frag or Mid Frag
610 if(uFragIdx == (uMACfragNum-2)){
611 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
613 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
616 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
617 return (pDevice->uSIFS + uAckTime + uNextPktTime);
619 return (pDevice->uSIFS + uNextPktTime);
624 case DATADUR_A_F0: //DATADUR_A_F0
625 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
627 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
628 return (pDevice->uSIFS + uAckTime);
633 else { //First Frag or Mid Frag
634 if (byFBOption == AUTO_FB_0) {
635 if (wRate < RATE_18M)
637 else if (wRate > RATE_54M)
640 if(uFragIdx == (uMACfragNum-2)){
641 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
643 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
645 } else { // (byFBOption == AUTO_FB_1)
646 if (wRate < RATE_18M)
648 else if (wRate > RATE_54M)
651 if(uFragIdx == (uMACfragNum-2)){
652 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
654 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
659 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
660 return (pDevice->uSIFS + uAckTime + uNextPktTime);
662 return (pDevice->uSIFS + uNextPktTime);
667 case DATADUR_A_F1: //DATADUR_A_F1
668 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
670 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
671 return (pDevice->uSIFS + uAckTime);
676 else { //First Frag or Mid Frag
677 if (byFBOption == AUTO_FB_0) {
678 if (wRate < RATE_18M)
680 else if (wRate > RATE_54M)
683 if(uFragIdx == (uMACfragNum-2)){
684 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
686 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
689 } else { // (byFBOption == AUTO_FB_1)
690 if (wRate < RATE_18M)
692 else if (wRate > RATE_54M)
695 if(uFragIdx == (uMACfragNum-2)){
696 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
698 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
702 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
703 return (pDevice->uSIFS + uAckTime + uNextPktTime);
705 return (pDevice->uSIFS + uNextPktTime);
719 //byFreqType: 0=>5GHZ 1=>2.4GHZ
722 s_uGetRTSCTSDuration (
725 unsigned int cbFrameLength,
732 unsigned int uCTSTime = 0, uDurTime = 0;
737 case RTSDUR_BB: //RTSDuration_bb
738 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
739 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
742 case RTSDUR_BA: //RTSDuration_ba
743 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
744 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
747 case RTSDUR_AA: //RTSDuration_aa
748 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
749 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
752 case CTSDUR_BA: //CTSDuration_ba
753 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
756 case RTSDUR_BA_F0: //RTSDuration_ba_f0
757 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
758 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
759 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
760 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
761 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
765 case RTSDUR_AA_F0: //RTSDuration_aa_f0
766 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
767 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
768 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
769 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
770 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
774 case RTSDUR_BA_F1: //RTSDuration_ba_f1
775 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
776 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
777 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
778 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
779 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
783 case RTSDUR_AA_F1: //RTSDuration_aa_f1
784 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
785 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
786 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
787 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
788 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
792 case CTSDUR_BA_F0: //CTSDuration_ba_f0
793 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
794 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
795 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
796 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
800 case CTSDUR_BA_F1: //CTSDuration_ba_f1
801 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
802 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
803 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
804 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
826 unsigned int cbFrameLength,
827 unsigned int uDMAIdx,
829 unsigned int uFragIdx,
830 unsigned int cbLastFragmentSize,
831 unsigned int uMACfragNum,
836 if (pTxDataHead == NULL) {
840 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
841 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
842 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
843 //Get SignalField,ServiceField,Length
844 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
845 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
847 //Get Duration and TimeStampOff
848 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
849 wCurrentRate, bNeedAck, uFragIdx,
850 cbLastFragmentSize, uMACfragNum,
851 byFBOption); //1: 2.4GHz
852 if(uDMAIdx!=TYPE_ATIMDMA) {
853 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
855 return (pBuf->wDuration);
857 else { // DATA & MANAGE Frame
858 if (byFBOption == AUTO_FB_NONE) {
859 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
860 //Get SignalField,ServiceField,Length
861 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
862 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
864 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
865 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
867 //Get Duration and TimeStamp
868 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
869 byPktType, wCurrentRate, bNeedAck, uFragIdx,
870 cbLastFragmentSize, uMACfragNum,
871 byFBOption); //1: 2.4GHz
872 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
873 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
874 bNeedAck, uFragIdx, cbLastFragmentSize,
875 uMACfragNum, byFBOption); //1: 2.4GHz
877 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
878 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
879 return (pBuf->wDuration_a);
882 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
883 //Get SignalField,ServiceField,Length
884 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
885 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
887 BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
888 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
890 //Get Duration and TimeStamp
891 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
892 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
893 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
894 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
895 pBuf->wDuration_a_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
896 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
897 pBuf->wDuration_a_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
898 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
899 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
900 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
901 return (pBuf->wDuration_a);
902 } //if (byFBOption == AUTO_FB_NONE)
905 else if (byPktType == PK_TYPE_11A) {
906 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
908 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
909 //Get SignalField,ServiceField,Length
910 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
911 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
913 //Get Duration and TimeStampOff
914 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
915 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
916 pBuf->wDuration_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
917 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
918 pBuf->wDuration_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
919 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
920 if(uDMAIdx!=TYPE_ATIMDMA) {
921 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
923 return (pBuf->wDuration);
925 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
926 //Get SignalField,ServiceField,Length
927 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
928 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
930 //Get Duration and TimeStampOff
931 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
932 wCurrentRate, bNeedAck, uFragIdx,
933 cbLastFragmentSize, uMACfragNum,
936 if(uDMAIdx!=TYPE_ATIMDMA) {
937 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
939 return (pBuf->wDuration);
942 else if (byPktType == PK_TYPE_11B) {
943 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
944 //Get SignalField,ServiceField,Length
945 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
946 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
948 //Get Duration and TimeStampOff
949 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
950 wCurrentRate, bNeedAck, uFragIdx,
951 cbLastFragmentSize, uMACfragNum,
953 if (uDMAIdx != TYPE_ATIMDMA) {
954 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
956 return (pBuf->wDuration);
970 unsigned int cbFrameLength,
973 PSEthernetHeader psEthHeader,
978 unsigned int uRTSFrameLen = 20;
985 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
986 // in this case we need to decrease its length by 4.
990 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
991 // Otherwise, we need to modified codes for them.
992 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
993 if (byFBOption == AUTO_FB_NONE) {
994 PSRTS_g pBuf = (PSRTS_g)pvRTS;
995 //Get SignalField,ServiceField,Length
996 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
997 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
999 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1000 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1001 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1003 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1005 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
1006 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
1007 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1009 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1010 //Get RTS Frame body
1011 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1013 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1014 (pDevice->eOPMode == OP_MODE_AP)) {
1015 memcpy(&(pBuf->Data.abyRA[0]),
1016 &(psEthHeader->abyDstAddr[0]),
1020 memcpy(&(pBuf->Data.abyRA[0]),
1021 &(pDevice->abyBSSID[0]),
1024 if (pDevice->eOPMode == OP_MODE_AP) {
1025 memcpy(&(pBuf->Data.abyTA[0]),
1026 &(pDevice->abyBSSID[0]),
1030 memcpy(&(pBuf->Data.abyTA[0]),
1031 &(psEthHeader->abySrcAddr[0]),
1036 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
1037 //Get SignalField,ServiceField,Length
1038 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1039 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1041 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1042 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1043 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1045 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1047 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
1048 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
1049 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
1050 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
1051 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
1052 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
1053 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
1054 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1055 //Get RTS Frame body
1056 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1058 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1059 (pDevice->eOPMode == OP_MODE_AP)) {
1060 memcpy(&(pBuf->Data.abyRA[0]),
1061 &(psEthHeader->abyDstAddr[0]),
1065 memcpy(&(pBuf->Data.abyRA[0]),
1066 &(pDevice->abyBSSID[0]),
1070 if (pDevice->eOPMode == OP_MODE_AP) {
1071 memcpy(&(pBuf->Data.abyTA[0]),
1072 &(pDevice->abyBSSID[0]),
1076 memcpy(&(pBuf->Data.abyTA[0]),
1077 &(psEthHeader->abySrcAddr[0]),
1081 } // if (byFBOption == AUTO_FB_NONE)
1083 else if (byPktType == PK_TYPE_11A) {
1084 if (byFBOption == AUTO_FB_NONE) {
1085 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1086 //Get SignalField,ServiceField,Length
1087 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1088 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1090 pBuf->wTransmitLength = cpu_to_le16(wLen);
1092 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1093 pBuf->Data.wDurationID = pBuf->wDuration;
1094 //Get RTS Frame body
1095 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1097 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1098 (pDevice->eOPMode == OP_MODE_AP)) {
1099 memcpy(&(pBuf->Data.abyRA[0]),
1100 &(psEthHeader->abyDstAddr[0]),
1103 memcpy(&(pBuf->Data.abyRA[0]),
1104 &(pDevice->abyBSSID[0]),
1108 if (pDevice->eOPMode == OP_MODE_AP) {
1109 memcpy(&(pBuf->Data.abyTA[0]),
1110 &(pDevice->abyBSSID[0]),
1113 memcpy(&(pBuf->Data.abyTA[0]),
1114 &(psEthHeader->abySrcAddr[0]),
1120 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
1121 //Get SignalField,ServiceField,Length
1122 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1123 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1125 pBuf->wTransmitLength = cpu_to_le16(wLen);
1127 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1128 pBuf->wRTSDuration_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
1129 pBuf->wRTSDuration_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
1130 pBuf->Data.wDurationID = pBuf->wDuration;
1131 //Get RTS Frame body
1132 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1134 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1135 (pDevice->eOPMode == OP_MODE_AP)) {
1136 memcpy(&(pBuf->Data.abyRA[0]),
1137 &(psEthHeader->abyDstAddr[0]),
1140 memcpy(&(pBuf->Data.abyRA[0]),
1141 &(pDevice->abyBSSID[0]),
1144 if (pDevice->eOPMode == OP_MODE_AP) {
1145 memcpy(&(pBuf->Data.abyTA[0]),
1146 &(pDevice->abyBSSID[0]),
1149 memcpy(&(pBuf->Data.abyTA[0]),
1150 &(psEthHeader->abySrcAddr[0]),
1155 else if (byPktType == PK_TYPE_11B) {
1156 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1157 //Get SignalField,ServiceField,Length
1158 BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1159 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1161 pBuf->wTransmitLength = cpu_to_le16(wLen);
1163 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1164 pBuf->Data.wDurationID = pBuf->wDuration;
1165 //Get RTS Frame body
1166 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1168 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1169 (pDevice->eOPMode == OP_MODE_AP)) {
1170 memcpy(&(pBuf->Data.abyRA[0]),
1171 &(psEthHeader->abyDstAddr[0]),
1175 memcpy(&(pBuf->Data.abyRA[0]),
1176 &(pDevice->abyBSSID[0]),
1180 if (pDevice->eOPMode == OP_MODE_AP) {
1181 memcpy(&(pBuf->Data.abyTA[0]),
1182 &(pDevice->abyBSSID[0]),
1185 memcpy(&(pBuf->Data.abyTA[0]),
1186 &(psEthHeader->abySrcAddr[0]),
1196 unsigned int uDMAIdx,
1199 unsigned int cbFrameLength,
1206 unsigned int uCTSFrameLen = 14;
1209 if (pvCTS == NULL) {
1214 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1215 // in this case we need to decrease its length by 4.
1219 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1220 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1222 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1223 //Get SignalField,ServiceField,Length
1224 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1225 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1227 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1228 pBuf->wDuration_ba = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1229 pBuf->wDuration_ba += pDevice->wCTSDuration;
1230 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1231 //Get CTSDuration_ba_f0
1232 pBuf->wCTSDuration_ba_f0 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
1233 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1234 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1235 //Get CTSDuration_ba_f1
1236 pBuf->wCTSDuration_ba_f1 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
1237 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1238 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1239 //Get CTS Frame body
1240 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1241 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1242 pBuf->Data.wReserved = 0x0000;
1243 memcpy(&(pBuf->Data.abyRA[0]),
1244 &(pDevice->abyCurrentNetAddr[0]),
1246 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1247 PSCTS pBuf = (PSCTS)pvCTS;
1248 //Get SignalField,ServiceField,Length
1249 BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1250 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1252 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1253 //Get CTSDuration_ba
1254 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1255 pBuf->wDuration_ba += pDevice->wCTSDuration;
1256 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1258 //Get CTS Frame body
1259 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1260 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1261 pBuf->Data.wReserved = 0x0000;
1262 memcpy(&(pBuf->Data.abyRA[0]),
1263 &(pDevice->abyCurrentNetAddr[0]),
1272 * Generate FIFO control for MAC & Baseband controller
1276 * pDevice - Pointer to adpater
1277 * pTxDataHead - Transmit Data Buffer
1278 * pTxBufHead - pTxBufHead
1279 * pvRrvTime - pvRrvTime
1280 * pvRTS - RTS Buffer
1282 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1283 * bNeedACK - If need ACK
1284 * uDMAIdx - DMA Index
1288 * Return Value: none
1294 s_vGenerateTxParameter (
1302 unsigned int cbFrameSize,
1304 unsigned int uDMAIdx,
1305 PSEthernetHeader psEthHeader
1308 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
1310 BOOL bDisCRC = FALSE;
1311 BYTE byFBOption = AUTO_FB_NONE;
1312 // WORD wCurrentRate = pDevice->wCurrentRate;
1314 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1315 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1316 pFifoHead->wReserved = wCurrentRate;
1317 wFifoCtl = pFifoHead->wFIFOCtl;
1319 if (wFifoCtl & FIFOCTL_CRCDIS) {
1323 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1324 byFBOption = AUTO_FB_0;
1326 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1327 byFBOption = AUTO_FB_1;
1330 if (pDevice->bLongHeader)
1331 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1333 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1335 if (pvRTS != NULL) { //RTS_need
1338 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1339 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1340 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1341 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1342 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1343 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1346 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1348 else {//RTS_needless, PCF mode
1352 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1353 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1354 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1355 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1358 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1361 else if (byPktType == PK_TYPE_11A) {
1363 if (pvRTS != NULL) {//RTS_need, non PCF mode
1366 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1367 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1368 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1371 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1373 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1376 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1377 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1381 else if (byPktType == PK_TYPE_11B) {
1383 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1386 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1387 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1388 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1391 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1393 else { //RTS_needless, non PCF mode
1396 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1397 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1401 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1404 PBYTE pbyBuffer,//point to pTxBufHead
1405 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1406 unsigned int cbFragmentSize,//Hdr+payoad+FCS
1411 s_bPacketToWirelessUsb(
1415 BOOL bNeedEncryption,
1416 unsigned int uSkbPacketLen,
1417 unsigned int uDMAIdx,
1418 PSEthernetHeader psEthHeader,
1420 PSKeyItem pTransmitKey,
1421 unsigned int uNodeIndex,
1423 unsigned int *pcbHeaderLen,
1424 unsigned int *pcbTotalLen
1427 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1428 unsigned int cbFrameSize, cbFrameBodySize;
1429 PTX_BUFFER pTxBufHead;
1430 unsigned int cb802_1_H_len;
1431 unsigned int cbIVlen = 0, cbICVlen = 0, cbMIClen = 0,
1432 cbMACHdLen = 0, cbFCSlen = 4;
1433 unsigned int cbMICHDR = 0;
1435 PBYTE pbyType,pbyMacHdr,pbyIVHead,pbyPayloadHead,pbyTxBufferAddr;
1436 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1437 BYTE abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1438 unsigned int uDuration;
1439 unsigned int cbHeaderLength = 0, uPadding = 0;
1441 PSMICHDRHead pMICHDR;
1445 BYTE byFBOption = AUTO_FB_NONE,byFragType;
1447 DWORD dwMICKey0,dwMICKey1,dwMIC_Priority,dwCRC;
1448 PDWORD pdwMIC_L,pdwMIC_R;
1449 BOOL bSoftWEP = FALSE;
1454 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1455 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1456 if (((PSKeyTable) (pTransmitKey->pvKeyTable))->bSoftWEP == TRUE) {
1462 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
1463 memset(pTxBufHead, 0, sizeof(TX_BUFFER));
1466 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1467 if (pDevice->dwDiagRefCount == 0) {
1476 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
1479 pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8);
1481 if (pDevice->dwDiagRefCount != 0) {
1483 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1484 } else { //if (pDevice->dwDiagRefCount != 0) {
1485 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1486 (pDevice->eOPMode == OP_MODE_AP)) {
1487 if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) {
1489 pTxBufHead->wFIFOCtl =
1490 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1493 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1497 // MSDUs in Infra mode always need ACK
1499 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1501 } //if (pDevice->dwDiagRefCount != 0) {
1503 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1506 if (pDevice->bLongHeader)
1507 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1509 if (pDevice->bSoftwareGenCrcErr) {
1510 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1513 //Set FRAGCTL_MACHDCNT
1514 if (pDevice->bLongHeader) {
1515 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1517 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1519 pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10);
1521 //Set FIFOCTL_GrpAckPolicy
1522 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
1523 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1526 //Set Auto Fallback Ctl
1527 if (wCurrentRate >= RATE_18M) {
1528 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1529 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1530 byFBOption = AUTO_FB_0;
1531 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1532 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1533 byFBOption = AUTO_FB_1;
1537 if (bSoftWEP != TRUE) {
1538 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1539 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1540 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1542 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1543 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1544 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1546 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1547 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1553 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1554 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1558 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1559 cbIVlen = 8;//IV+ExtIV
1563 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1564 cbIVlen = 8;//RSN Header
1566 cbMICHDR = sizeof(SMICHDRHead);
1568 if (bSoftWEP == FALSE) {
1569 //MAC Header should be padding 0 to DW alignment.
1570 uPadding = 4 - (cbMACHdLen%4);
1575 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1577 if ( (bNeedACK == FALSE) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1581 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1584 pbyTxBufferAddr = (PBYTE) &(pTxBufHead->adwTxKey[0]);
1585 wTxBufSize = sizeof(STxBufHead);
1586 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1587 if (byFBOption == AUTO_FB_NONE) {
1588 if (bRTS == TRUE) {//RTS_need
1589 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1590 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1591 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1593 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1594 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1596 else { //RTS_needless
1597 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1598 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1600 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1601 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1602 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1606 if (bRTS == TRUE) {//RTS_need
1607 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1608 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1609 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1611 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1612 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1614 else if (bRTS == FALSE) { //RTS_needless
1615 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1616 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1618 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1619 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1620 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1624 else {//802.11a/b packet
1625 if (byFBOption == AUTO_FB_NONE) {
1626 if (bRTS == TRUE) {//RTS_need
1627 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1628 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1629 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1631 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1632 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1634 else if (bRTS == FALSE) { //RTS_needless, no MICHDR
1635 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1636 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1639 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1640 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1644 if (bRTS == TRUE) {//RTS_need
1645 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1646 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1647 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1649 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1650 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1652 else if (bRTS == FALSE) { //RTS_needless
1653 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1654 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1657 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1658 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1663 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1664 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1665 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1668 //=========================
1670 //=========================
1671 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1672 byFragType = FRAGCTL_NONFRAG;
1673 //uDMAIdx = TYPE_AC0DMA;
1674 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1677 //Fill FIFO,RrvTime,RTS,and CTS
1678 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1679 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
1680 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1682 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1683 0, 0, 1/*uMACfragNum*/, byFBOption);
1684 // Generate TX MAC Header
1685 s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption,
1686 byFragType, uDMAIdx, 0);
1688 if (bNeedEncryption == TRUE) {
1690 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1691 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
1693 if (pDevice->bEnableHostWEP) {
1694 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1695 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1700 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1701 if (pDevice->dwDiagRefCount == 0) {
1702 if ((psEthHeader->wType == cpu_to_be16(ETH_P_IPX)) ||
1703 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1704 memcpy((PBYTE) (pbyPayloadHead),
1705 abySNAP_Bridgetunnel, 6);
1707 memcpy((PBYTE) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1709 pbyType = (PBYTE) (pbyPayloadHead + 6);
1710 memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1712 memcpy((PBYTE) (pbyPayloadHead), &(psEthHeader->wType), sizeof(WORD));
1719 if (pPacket != NULL) {
1720 // Copy the Packet into a tx Buffer
1721 memcpy((pbyPayloadHead + cb802_1_H_len),
1722 (pPacket + ETH_HLEN),
1723 uSkbPacketLen - ETH_HLEN
1727 // while bRelayPacketSend psEthHeader is point to header+payload
1728 memcpy((pbyPayloadHead + cb802_1_H_len), ((PBYTE)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
1731 ASSERT(uLength == cbNdisBodySize);
1733 if ((bNeedEncryption == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1735 ///////////////////////////////////////////////////////////////////
1737 if (pDevice->sMgmtObj.eAuthenMode == WMAC_AUTH_WPANONE) {
1738 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1739 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1741 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1742 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1743 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1746 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1747 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1749 // DO Software Michael
1750 MIC_vInit(dwMICKey0, dwMICKey1);
1751 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1753 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1756 ///////////////////////////////////////////////////////////////////
1758 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1759 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1760 // DBG_PRN_GRP12(("%02x ", *((PBYTE)((pbyPayloadHead + cb802_1_H_len) + ii))));
1762 //DBG_PRN_GRP12(("\n\n\n"));
1764 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1766 pdwMIC_L = (PDWORD)(pbyPayloadHead + cbFrameBodySize);
1767 pdwMIC_R = (PDWORD)(pbyPayloadHead + cbFrameBodySize + 4);
1769 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1772 if (pDevice->bTxMICFail == TRUE) {
1775 pDevice->bTxMICFail = FALSE;
1777 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1778 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1779 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1783 if (bSoftWEP == TRUE) {
1785 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen));
1787 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == TRUE)) ||
1788 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == TRUE)) ||
1789 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == TRUE)) ) {
1790 cbFrameSize -= cbICVlen;
1793 if (pDevice->bSoftwareGenCrcErr == TRUE) {
1797 dwCRC = 0xFFFFFFFFL;
1798 cbLen = cbFrameSize - cbFCSlen;
1799 // calculate CRC, and wrtie CRC value to end of TD
1800 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
1801 pdwCRC = (PDWORD)(pbyMacHdr + cbLen);
1802 // finally, we must invert dwCRC to get the correct answer
1807 cbFrameSize -= cbFCSlen;
1810 *pcbHeaderLen = cbHeaderLength;
1811 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1814 //Set FragCtl in TxBufferHead
1815 pTxBufHead->wFragCtl |= (WORD)byFragType;
1826 * Translate 802.3 to 802.11 header
1830 * pDevice - Pointer to adapter
1831 * dwTxBufferAddr - Transmit Buffer
1832 * pPacket - Packet from upper layer
1833 * cbPacketSize - Transmit Data Length
1835 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1836 * pcbAppendPayload - size of append payload for 802.1H translation
1838 * Return Value: none
1843 s_vGenerateMACHeader (
1845 PBYTE pbyBufferAddr,
1847 PSEthernetHeader psEthHeader,
1850 unsigned int uDMAIdx,
1851 unsigned int uFragIdx
1854 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
1856 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
1858 if (uDMAIdx == TYPE_ATIMDMA) {
1859 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
1861 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
1864 if (pDevice->eOPMode == OP_MODE_AP) {
1865 memcpy(&(pMACHeader->abyAddr1[0]),
1866 &(psEthHeader->abyDstAddr[0]),
1868 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1869 memcpy(&(pMACHeader->abyAddr3[0]),
1870 &(psEthHeader->abySrcAddr[0]),
1872 pMACHeader->wFrameCtl |= FC_FROMDS;
1874 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1875 memcpy(&(pMACHeader->abyAddr1[0]),
1876 &(psEthHeader->abyDstAddr[0]),
1878 memcpy(&(pMACHeader->abyAddr2[0]),
1879 &(psEthHeader->abySrcAddr[0]),
1881 memcpy(&(pMACHeader->abyAddr3[0]),
1882 &(pDevice->abyBSSID[0]),
1885 memcpy(&(pMACHeader->abyAddr3[0]),
1886 &(psEthHeader->abyDstAddr[0]),
1888 memcpy(&(pMACHeader->abyAddr2[0]),
1889 &(psEthHeader->abySrcAddr[0]),
1891 memcpy(&(pMACHeader->abyAddr1[0]),
1892 &(pDevice->abyBSSID[0]),
1894 pMACHeader->wFrameCtl |= FC_TODS;
1899 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
1901 pMACHeader->wDurationID = cpu_to_le16(wDuration);
1903 if (pDevice->bLongHeader) {
1904 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1905 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
1906 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
1908 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1910 //Set FragNumber in Sequence Control
1911 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
1913 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1914 pDevice->wSeqCounter++;
1915 if (pDevice->wSeqCounter > 0x0fff)
1916 pDevice->wSeqCounter = 0;
1919 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1920 pMACHeader->wFrameCtl |= FC_MOREFRAG;
1929 * Request instructs a MAC to transmit a 802.11 management packet through
1930 * the adapter onto the medium.
1934 * hDeviceContext - Pointer to the adapter
1935 * pPacket - A pointer to a descriptor for the packet to transmit
1939 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise FALSE
1943 CMD_STATUS csMgmt_xmit(
1945 PSTxMgmtPacket pPacket
1949 PBYTE pbyTxBufferAddr;
1953 unsigned int uDuration;
1954 unsigned int cbReqCount;
1955 PS802_11Header pMACHeader;
1956 unsigned int cbHeaderSize;
1957 unsigned int cbFrameBodySize;
1959 BOOL bIsPSPOLL = FALSE;
1960 PSTxBufHead pTxBufHead;
1961 unsigned int cbFrameSize;
1962 unsigned int cbIVlen = 0;
1963 unsigned int cbICVlen = 0;
1964 unsigned int cbMIClen = 0;
1965 unsigned int cbFCSlen = 4;
1966 unsigned int uPadding = 0;
1968 unsigned int cbMacHdLen;
1969 SEthernetHeader sEthHeader;
1972 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1973 WORD wCurrentRate = RATE_1M;
1974 PTX_BUFFER pTX_Buffer;
1975 PUSB_SEND_CONTEXT pContext;
1979 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1981 if (NULL == pContext) {
1982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1983 return CMD_STATUS_RESOURCES;
1986 pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
1987 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->adwTxKey[0]);
1988 cbFrameBodySize = pPacket->cbPayloadLen;
1989 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1990 wTxBufSize = sizeof(STxBufHead);
1991 memset(pTxBufHead, 0, wTxBufSize);
1993 if (pDevice->byBBType == BB_TYPE_11A) {
1994 wCurrentRate = RATE_6M;
1995 byPktType = PK_TYPE_11A;
1997 wCurrentRate = RATE_1M;
1998 byPktType = PK_TYPE_11B;
2001 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2002 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2003 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2004 // to set power here.
2005 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2006 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2008 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2010 pDevice->wCurrentRate = wCurrentRate;
2014 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2015 pTxBufHead->wFIFOCtl = 0;
2017 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2018 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2020 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2021 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2023 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2024 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2027 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2028 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2030 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
2035 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2038 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2039 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2041 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2042 //Set Preamble type always long
2043 //pDevice->byPreambleType = PREAMBLE_LONG;
2044 // probe-response don't retry
2045 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2046 // bNeedACK = FALSE;
2047 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2051 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2053 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2055 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2057 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2060 //Set FRAGCTL_MACHDCNT
2061 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2064 // Although spec says MMPDU can be fragmented; In most case,
2065 // no one will send a MMPDU under fragmentation. With RTS may occur.
2066 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2068 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2069 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2072 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2074 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2075 cbIVlen = 8;//IV+ExtIV
2078 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2079 //We need to get seed here for filling TxKey entry.
2080 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2081 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2083 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2084 cbIVlen = 8;//RSN Header
2086 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2087 pDevice->bAES = TRUE;
2089 //MAC Header should be padding 0 to DW alignment.
2090 uPadding = 4 - (cbMacHdLen%4);
2094 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2096 //Set FIFOCTL_GrpAckPolicy
2097 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2098 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2100 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2102 //Set RrvTime/RTS/CTS Buffer
2103 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2105 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2108 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2109 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2110 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2112 else { // 802.11a/b packet
2113 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2117 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2118 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2121 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
2122 (cbHeaderSize - wTxBufSize));
2124 memcpy(&(sEthHeader.abyDstAddr[0]),
2125 &(pPacket->p80211Header->sA3.abyAddr1[0]),
2127 memcpy(&(sEthHeader.abySrcAddr[0]),
2128 &(pPacket->p80211Header->sA3.abyAddr2[0]),
2130 //=========================
2132 //=========================
2133 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2136 //Fill FIFO,RrvTime,RTS,and CTS
2137 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2138 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2141 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2142 0, 0, 1, AUTO_FB_NONE);
2144 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2146 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2148 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2150 PBYTE pbyPayloadHead;
2152 PSKeyItem pTransmitKey = NULL;
2154 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2155 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2157 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2158 (pDevice->bLinkPass == TRUE)) {
2159 pbyBSSID = pDevice->abyBSSID;
2161 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2163 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2173 pbyBSSID = pDevice->abyBroadcastAddr;
2174 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2175 pTransmitKey = NULL;
2176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2182 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2183 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2185 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2186 memcpy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2190 // Copy the Packet into a tx Buffer
2191 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2194 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2195 pDevice->wSeqCounter++ ;
2196 if (pDevice->wSeqCounter > 0x0fff)
2197 pDevice->wSeqCounter = 0;
2200 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2201 // of FIFO control header.
2202 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2203 // in the same place of other packet's Duration-field).
2204 // And it will cause Cisco-AP to issue Disassociation-packet
2205 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2206 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2207 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2209 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2214 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2215 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2216 pTX_Buffer->byType = 0x00;
2218 pContext->pPacket = NULL;
2219 pContext->Type = CONTEXT_MGMT_PACKET;
2220 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2222 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2223 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2226 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2229 PIPEnsSendBulkOut(pDevice,pContext);
2230 return CMD_STATUS_PENDING;
2237 PSTxMgmtPacket pPacket
2241 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2242 unsigned int cbHeaderSize = 0;
2243 WORD wTxBufSize = sizeof(STxShortBufHead);
2244 PSTxShortBufHead pTxBufHead;
2245 PS802_11Header pMACHeader;
2246 PSTxDataHead_ab pTxDataHead;
2248 unsigned int cbFrameBodySize;
2249 unsigned int cbReqCount;
2250 PBEACON_BUFFER pTX_Buffer;
2251 PBYTE pbyTxBufferAddr;
2252 PUSB_SEND_CONTEXT pContext;
2256 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2257 if (NULL == pContext) {
2258 status = CMD_STATUS_RESOURCES;
2259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
2262 pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
2263 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->wFIFOCtl);
2265 cbFrameBodySize = pPacket->cbPayloadLen;
2267 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
2268 wTxBufSize = sizeof(STxShortBufHead);
2269 memset(pTxBufHead, 0, wTxBufSize);
2271 if (pDevice->byBBType == BB_TYPE_11A) {
2272 wCurrentRate = RATE_6M;
2273 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2274 //Get SignalField,ServiceField,Length
2275 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
2276 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2278 //Get Duration and TimeStampOff
2279 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
2280 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2281 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2282 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2284 wCurrentRate = RATE_1M;
2285 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2286 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2287 //Get SignalField,ServiceField,Length
2288 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
2289 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2291 //Get Duration and TimeStampOff
2292 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
2293 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2294 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2295 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2298 //Generate Beacon Header
2299 pMACHeader = (PS802_11Header)(pbyTxBufferAddr + cbHeaderSize);
2300 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2302 pMACHeader->wDurationID = 0;
2303 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2304 pDevice->wSeqCounter++ ;
2305 if (pDevice->wSeqCounter > 0x0fff)
2306 pDevice->wSeqCounter = 0;
2308 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
2310 pTX_Buffer->wTxByteCount = (WORD)cbReqCount;
2311 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2312 pTX_Buffer->byType = 0x01;
2314 pContext->pPacket = NULL;
2315 pContext->Type = CONTEXT_MGMT_PACKET;
2316 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2318 PIPEnsSendBulkOut(pDevice,pContext);
2319 return CMD_STATUS_PENDING;
2328 vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2330 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2332 PBYTE pbyTxBufferAddr;
2336 unsigned int uDuration;
2337 unsigned int cbReqCount;
2338 PS802_11Header pMACHeader;
2339 unsigned int cbHeaderSize;
2340 unsigned int cbFrameBodySize;
2342 BOOL bIsPSPOLL = FALSE;
2343 PSTxBufHead pTxBufHead;
2344 unsigned int cbFrameSize;
2345 unsigned int cbIVlen = 0;
2346 unsigned int cbICVlen = 0;
2347 unsigned int cbMIClen = 0;
2348 unsigned int cbFCSlen = 4;
2349 unsigned int uPadding = 0;
2350 unsigned int cbMICHDR = 0;
2351 unsigned int uLength = 0;
2352 DWORD dwMICKey0, dwMICKey1;
2353 DWORD dwMIC_Priority;
2357 unsigned int cbMacHdLen;
2358 SEthernetHeader sEthHeader;
2361 WORD wCurrentRate = RATE_1M;
2362 PUWLAN_80211HDR p80211Header;
2363 unsigned int uNodeIndex = 0;
2364 BOOL bNodeExist = FALSE;
2366 PSKeyItem pTransmitKey = NULL;
2368 PBYTE pbyPayloadHead;
2370 unsigned int cbExtSuppRate = 0;
2371 PTX_BUFFER pTX_Buffer;
2372 PUSB_SEND_CONTEXT pContext;
2376 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2378 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
2379 cbFrameBodySize = 0;
2382 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
2384 p80211Header = (PUWLAN_80211HDR)skb->data;
2386 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2388 if (NULL == pContext) {
2389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
2390 dev_kfree_skb_irq(skb);
2394 pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
2395 pbyTxBufferAddr = (PBYTE)(&pTX_Buffer->adwTxKey[0]);
2396 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2397 wTxBufSize = sizeof(STxBufHead);
2398 memset(pTxBufHead, 0, wTxBufSize);
2400 if (pDevice->byBBType == BB_TYPE_11A) {
2401 wCurrentRate = RATE_6M;
2402 byPktType = PK_TYPE_11A;
2404 wCurrentRate = RATE_1M;
2405 byPktType = PK_TYPE_11B;
2408 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2409 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2410 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2411 // to set power here.
2412 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2413 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2415 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2418 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2421 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2422 pTxBufHead->wFIFOCtl = 0;
2424 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2425 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2427 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2428 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2430 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2431 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2434 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2435 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2437 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
2439 if (pDevice->bEnableHostWEP) {
2445 if (pDevice->bEnableHostWEP) {
2446 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2450 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2453 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2454 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2456 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2457 //Set Preamble type always long
2458 //pDevice->byPreambleType = PREAMBLE_LONG;
2460 // probe-response don't retry
2461 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2462 // bNeedACK = FALSE;
2463 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2467 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2469 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2471 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2473 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2476 // hostapd daemon ext support rate patch
2477 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2479 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2480 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2483 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2484 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2487 if (cbExtSuppRate >0) {
2488 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2493 //Set FRAGCTL_MACHDCNT
2494 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
2497 // Although spec says MMPDU can be fragmented; In most case,
2498 // no one will send a MMPDU under fragmentation. With RTS may occur.
2499 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2502 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2503 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2506 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2508 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2509 cbIVlen = 8;//IV+ExtIV
2512 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2513 //We need to get seed here for filling TxKey entry.
2514 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2515 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2517 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2518 cbIVlen = 8;//RSN Header
2520 cbMICHDR = sizeof(SMICHDRHead);
2521 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2522 pDevice->bAES = TRUE;
2524 //MAC Header should be padding 0 to DW alignment.
2525 uPadding = 4 - (cbMacHdLen%4);
2529 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2531 //Set FIFOCTL_GrpAckPolicy
2532 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2533 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2535 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2538 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2540 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2541 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2543 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
2544 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
2545 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
2548 else {//802.11a/b packet
2550 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2551 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2554 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2555 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2557 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
2558 (cbHeaderSize - wTxBufSize));
2559 memcpy(&(sEthHeader.abyDstAddr[0]),
2560 &(p80211Header->sA3.abyAddr1[0]),
2562 memcpy(&(sEthHeader.abySrcAddr[0]),
2563 &(p80211Header->sA3.abyAddr2[0]),
2565 //=========================
2567 //=========================
2568 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2571 //Fill FIFO,RrvTime,RTS,and CTS
2572 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2573 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2576 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2577 0, 0, 1, AUTO_FB_NONE);
2579 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2581 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2583 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
2584 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2585 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
2587 // Copy the Packet into a tx Buffer
2588 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2590 // version set to 0, patch for hostapd deamon
2591 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
2592 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2594 // replace support rate, patch for hostapd daemon( only support 11M)
2595 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2596 if (cbExtSuppRate != 0) {
2597 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2598 memcpy((pbyPayloadHead + cbFrameBodySize),
2599 pMgmt->abyCurrSuppRates,
2600 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2602 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2603 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2604 pMgmt->abyCurrExtSuppRates,
2605 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2611 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2613 if (pDevice->bEnableHostWEP) {
2614 pTransmitKey = &STempKey;
2615 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2616 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2617 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2618 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2619 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2620 memcpy(pTransmitKey->abyKey,
2621 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2622 pTransmitKey->uKeyLength
2626 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2628 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
2629 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
2631 // DO Software Michael
2632 MIC_vInit(dwMICKey0, dwMICKey1);
2633 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
2635 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
2636 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
2638 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2640 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2642 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2643 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2645 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2648 if (pDevice->bTxMICFail == TRUE) {
2651 pDevice->bTxMICFail = FALSE;
2654 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2660 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2661 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
2663 if (pDevice->bEnableHostWEP) {
2664 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2665 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2668 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
2669 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
2673 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2674 pDevice->wSeqCounter++ ;
2675 if (pDevice->wSeqCounter > 0x0fff)
2676 pDevice->wSeqCounter = 0;
2680 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2681 // of FIFO control header.
2682 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2683 // in the same place of other packet's Duration-field).
2684 // And it will cause Cisco-AP to issue Disassociation-packet
2685 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2686 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2687 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2689 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2693 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2694 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2695 pTX_Buffer->byType = 0x00;
2697 pContext->pPacket = skb;
2698 pContext->Type = CONTEXT_MGMT_PACKET;
2699 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2701 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2702 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2705 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2707 PIPEnsSendBulkOut(pDevice,pContext);
2715 //TYPE_AC0DMA data tx
2718 * Tx packet via AC0DMA(DMA1)
2722 * pDevice - Pointer to the adapter
2723 * skb - Pointer to tx skb packet
2727 * Return Value: NULL
2730 int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2732 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2733 unsigned int BytesToWrite = 0, uHeaderLen = 0;
2734 unsigned int uNodeIndex = 0;
2735 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2738 BOOL bNeedEncryption = FALSE;
2739 PSKeyItem pTransmitKey = NULL;
2742 BOOL bTKIP_UseGTK = FALSE;
2743 BOOL bNeedDeAuth = FALSE;
2745 BOOL bNodeExist = FALSE;
2746 PUSB_SEND_CONTEXT pContext;
2747 BOOL fConvertedPacket;
2748 PTX_BUFFER pTX_Buffer;
2749 unsigned int status;
2750 WORD wKeepRate = pDevice->wCurrentRate;
2751 struct net_device_stats* pStats = &pDevice->stats;
2752 BOOL bTxeapol_key = FALSE;
2755 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2757 if (pDevice->uAssocCount == 0) {
2758 dev_kfree_skb_irq(skb);
2762 if (is_multicast_ether_addr((PBYTE)(skb->data))) {
2765 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2767 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2768 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2770 pMgmt->abyPSTxMap[0] |= byMask[0];
2773 // multicast/broadcast data rate
2775 if (pDevice->byBBType != BB_TYPE_11A)
2776 pDevice->wCurrentRate = RATE_2M;
2778 pDevice->wCurrentRate = RATE_24M;
2779 // long preamble type
2780 pDevice->byPreambleType = PREAMBLE_SHORT;
2784 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data), &uNodeIndex)) {
2786 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2788 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2790 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2792 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2793 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2794 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2795 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2799 // AP rate decided from node
2800 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2801 // tx preamble decided from node
2803 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2804 pDevice->byPreambleType = pDevice->byShortPreamble;
2807 pDevice->byPreambleType = PREAMBLE_LONG;
2813 if (bNodeExist == FALSE) {
2814 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2815 dev_kfree_skb_irq(skb);
2820 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2822 if (pContext == NULL) {
2823 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2824 dev_kfree_skb_irq(skb);
2825 return STATUS_RESOURCES;
2828 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), ETH_HLEN);
2830 //mike add:station mode check eapol-key challenge--->
2832 BYTE Protocol_Version; //802.1x Authentication
2833 BYTE Packet_Type; //802.1x Authentication
2834 BYTE Descriptor_type;
2837 Protocol_Version = skb->data[ETH_HLEN];
2838 Packet_Type = skb->data[ETH_HLEN+1];
2839 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2840 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2841 if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) {
2842 /* 802.1x OR eapol-key challenge frame transfer */
2843 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2844 (Packet_Type == 3)) {
2845 bTxeapol_key = TRUE;
2846 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2847 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2848 if(Descriptor_type==254) {
2849 pDevice->fWPA_Authened = TRUE;
2853 pDevice->fWPA_Authened = TRUE;
2854 PRINT_K("WPA2(re-keying) ");
2856 PRINT_K("Authentication completed!!\n");
2858 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
2859 (Key_info & BIT8) && (Key_info & BIT9)) {
2860 pDevice->fWPA_Authened = TRUE;
2861 PRINT_K("WPA2 Authentication completed!!\n");
2866 //mike add:station mode check eapol-key challenge<---
2868 if (pDevice->bEncryptionEnable == TRUE) {
2869 bNeedEncryption = TRUE;
2872 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2873 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2874 pbyBSSID = pDevice->abyBSSID;
2876 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2878 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2879 bTKIP_UseGTK = TRUE;
2880 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2884 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2887 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2889 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2890 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2891 for (ii = 0; ii< 6; ii++)
2892 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2893 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2896 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2900 pbyBSSID = pDevice->abyBroadcastAddr;
2901 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2902 pTransmitKey = NULL;
2903 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2904 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2907 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2909 bTKIP_UseGTK = TRUE;
2910 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2915 if (pDevice->bEnableHostWEP) {
2916 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2917 if (pDevice->bEncryptionEnable == TRUE) {
2918 pTransmitKey = &STempKey;
2919 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2920 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2921 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2922 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2923 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2924 memcpy(pTransmitKey->abyKey,
2925 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2926 pTransmitKey->uKeyLength
2931 byPktType = (BYTE)pDevice->byPacketType;
2933 if (pDevice->bFixRate) {
2934 if (pDevice->byBBType == BB_TYPE_11B) {
2935 if (pDevice->uConnectionRate >= RATE_11M) {
2936 pDevice->wCurrentRate = RATE_11M;
2938 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2941 if ((pDevice->byBBType == BB_TYPE_11A) &&
2942 (pDevice->uConnectionRate <= RATE_6M)) {
2943 pDevice->wCurrentRate = RATE_6M;
2945 if (pDevice->uConnectionRate >= RATE_54M)
2946 pDevice->wCurrentRate = RATE_54M;
2948 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2953 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2954 // Adhoc Tx rate decided from node DB
2955 if (is_multicast_ether_addr(pDevice->sTxEthHeader.abyDstAddr)) {
2956 // Multicast use highest data rate
2957 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2959 pDevice->byPreambleType = pDevice->byShortPreamble;
2962 if(BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.abyDstAddr[0]), &uNodeIndex)) {
2963 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2964 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2965 pDevice->byPreambleType = pDevice->byShortPreamble;
2969 pDevice->byPreambleType = PREAMBLE_LONG;
2971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2974 if (pDevice->byBBType != BB_TYPE_11A)
2975 pDevice->wCurrentRate = RATE_2M;
2977 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2978 // abyCurrExtSuppRates[]
2979 pDevice->byPreambleType = PREAMBLE_SHORT;
2980 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2984 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2985 // Infra STA rate decided from AP Node, index = 0
2986 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2990 if (pDevice->sTxEthHeader.wType == cpu_to_be16(ETH_P_PAE)) {
2991 if (pDevice->byBBType != BB_TYPE_11A) {
2992 pDevice->wCurrentRate = RATE_1M;
2993 pDevice->byACKRate = RATE_1M;
2994 pDevice->byTopCCKBasicRate = RATE_1M;
2995 pDevice->byTopOFDMBasicRate = RATE_6M;
2997 pDevice->wCurrentRate = RATE_6M;
2998 pDevice->byACKRate = RATE_6M;
2999 pDevice->byTopCCKBasicRate = RATE_1M;
3000 pDevice->byTopOFDMBasicRate = RATE_6M;
3004 DBG_PRT(MSG_LEVEL_DEBUG,
3005 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
3006 pDevice->wCurrentRate);
3008 if (wKeepRate != pDevice->wCurrentRate) {
3009 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
3012 if (pDevice->wCurrentRate <= RATE_11M) {
3013 byPktType = PK_TYPE_11B;
3016 if (bNeedEncryption == TRUE) {
3017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
3018 if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) {
3019 bNeedEncryption = FALSE;
3020 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
3021 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
3022 if (pTransmitKey == NULL) {
3023 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
3026 if (bTKIP_UseGTK == TRUE) {
3027 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
3030 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3031 bNeedEncryption = TRUE;
3036 if (pDevice->byCntMeasure == 2) {
3038 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
3041 if (pDevice->bEnableHostWEP) {
3042 if ((uNodeIndex != 0) &&
3043 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
3044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3045 bNeedEncryption = TRUE;
3051 if (pTransmitKey == NULL) {
3052 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
3053 dev_kfree_skb_irq(skb);
3054 pStats->tx_dropped++;
3055 return STATUS_FAILURE;
3060 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3061 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3062 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
3063 (PBYTE)skb->data, pTransmitKey, uNodeIndex,
3064 pDevice->wCurrentRate,
3065 &uHeaderLen, &BytesToWrite
3068 if (fConvertedPacket == FALSE) {
3069 pContext->bBoolInUse = FALSE;
3070 dev_kfree_skb_irq(skb);
3071 return STATUS_FAILURE;
3074 if ( pDevice->bEnablePSMode == TRUE ) {
3075 if ( !pDevice->bPSModeTxBurst ) {
3076 bScheduleCommand((void *) pDevice,
3077 WLAN_CMD_MAC_DISPOWERSAVING,
3079 pDevice->bPSModeTxBurst = TRUE;
3083 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3084 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3085 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3087 pContext->pPacket = skb;
3088 pContext->Type = CONTEXT_DATA_PACKET;
3089 pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
3091 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3093 status = PIPEnsSendBulkOut(pDevice,pContext);
3095 if (bNeedDeAuth == TRUE) {
3096 WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE;
3098 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason);
3101 if(status!=STATUS_PENDING) {
3102 pContext->bBoolInUse = FALSE;
3103 dev_kfree_skb_irq(skb);
3104 return STATUS_FAILURE;
3115 * Relay packet send (AC1DMA) from rx dpc.
3119 * pDevice - Pointer to the adapter
3120 * pPacket - Pointer to rx packet
3121 * cbPacketSize - rx ethernet frame size
3125 * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE
3133 unsigned int uDataLen,
3134 unsigned int uNodeIndex
3137 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
3138 unsigned int BytesToWrite = 0, uHeaderLen = 0;
3139 BYTE byPktType = PK_TYPE_11B;
3140 BOOL bNeedEncryption = FALSE;
3142 PSKeyItem pTransmitKey = NULL;
3144 PUSB_SEND_CONTEXT pContext;
3146 BOOL fConvertedPacket;
3147 PTX_BUFFER pTX_Buffer;
3148 unsigned int status;
3149 WORD wKeepRate = pDevice->wCurrentRate;
3153 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
3155 if (NULL == pContext) {
3159 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN);
3161 if (pDevice->bEncryptionEnable == TRUE) {
3162 bNeedEncryption = TRUE;
3164 pbyBSSID = pDevice->abyBroadcastAddr;
3165 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
3166 pTransmitKey = NULL;
3167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
3169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
3173 if (pDevice->bEnableHostWEP) {
3174 if (uNodeIndex < MAX_NODE_NUM + 1) {
3175 pTransmitKey = &STempKey;
3176 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3177 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3178 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3179 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3180 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3181 memcpy(pTransmitKey->abyKey,
3182 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3183 pTransmitKey->uKeyLength
3188 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
3189 pContext->bBoolInUse = FALSE;
3193 byPktTyp = (BYTE)pDevice->byPacketType;
3195 if (pDevice->bFixRate) {
3196 if (pDevice->byBBType == BB_TYPE_11B) {
3197 if (pDevice->uConnectionRate >= RATE_11M) {
3198 pDevice->wCurrentRate = RATE_11M;
3200 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3203 if ((pDevice->byBBType == BB_TYPE_11A) &&
3204 (pDevice->uConnectionRate <= RATE_6M)) {
3205 pDevice->wCurrentRate = RATE_6M;
3207 if (pDevice->uConnectionRate >= RATE_54M)
3208 pDevice->wCurrentRate = RATE_54M;
3210 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3215 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
3218 if (wKeepRate != pDevice->wCurrentRate) {
3219 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
3222 if (pDevice->wCurrentRate <= RATE_11M)
3223 byPktType = PK_TYPE_11B;
3225 BytesToWrite = uDataLen + ETH_FCS_LEN;
3227 // Convert the packet to an usb frame and copy into our buffer
3228 // and send the irp.
3230 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3231 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3232 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
3233 pbySkbData, pTransmitKey, uNodeIndex,
3234 pDevice->wCurrentRate,
3235 &uHeaderLen, &BytesToWrite
3238 if (fConvertedPacket == FALSE) {
3239 pContext->bBoolInUse = FALSE;
3243 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3244 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3245 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3247 pContext->pPacket = NULL;
3248 pContext->Type = CONTEXT_DATA_PACKET;
3249 pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
3251 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3253 status = PIPEnsSendBulkOut(pDevice,pContext);