rxtx.c 107 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * File: rxtx.c
 *
 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
 *
 * Author: Lyndon Chen
 *
 * Date: May 20, 2003
 *
 * Functions:
28
 *      s_vGenerateTxParameter - Generate tx dma required parameter.
29 30 31 32 33
 *      s_vGenerateMACHeader - Translate 802.3 to 802.11 header
 *      csBeacon_xmit - beacon tx function
 *      csMgmt_xmit - management tx function
 *      s_uGetDataDuration - get tx data required duration
 *      s_uFillDataHead- fulfill tx data duration header
34
 *      s_uGetRTSCTSDuration- get rtx/cts required duration
35 36 37
 *      s_uGetRTSCTSRsvTime- get rts/cts reserved time
 *      s_uGetTxRsvTime- get frame reserved time
 *      s_vFillCTSHead- fulfill CTS ctl header
38
 *      s_vFillFragParameter- Set fragment ctl parameter.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
 *      s_vFillRTSHead- fulfill RTS ctl header
 *      s_vFillTxKey- fulfill tx encrypt key
 *      s_vSWencryption- Software encrypt header
 *      vDMA0_tx_80211- tx 802.11 frame via dma0
 *      vGenerateFIFOHeader- Generate tx FIFO ctl header
 *
 * Revision History:
 *
 */

#include "device.h"
#include "rxtx.h"
#include "tether.h"
#include "card.h"
#include "bssdb.h"
#include "mac.h"
#include "baseband.h"
#include "michael.h"
#include "tkip.h"
#include "tcrc.h"
#include "wctl.h"
#include "hostap.h"
#include "rf.h"
#include "datarate.h"
#include "usbpipe.h"
#include "iocmd.h"
65

66
static int          msglevel                = MSG_LEVEL_INFO;
67

68
const u16 wTimeStampOff[2][MAX_RATE] = {
69 70 71 72
        {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
        {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
    };

73
const u16 wFB_Opt0[2][5] = {
74 75 76
        {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
        {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
    };
77
const u16 wFB_Opt1[2][5] = {
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
        {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
        {RATE_6M , RATE_6M,  RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
    };

#define RTSDUR_BB       0
#define RTSDUR_BA       1
#define RTSDUR_AA       2
#define CTSDUR_BA       3
#define RTSDUR_BA_F0    4
#define RTSDUR_AA_F0    5
#define RTSDUR_BA_F1    6
#define RTSDUR_AA_F1    7
#define CTSDUR_BA_F0    8
#define CTSDUR_BA_F1    9
#define DATADUR_B       10
#define DATADUR_A       11
#define DATADUR_A_F0    12
#define DATADUR_A_F1    13

97 98 99 100 101 102 103 104
static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
	u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);

static void *s_vGetFreeContext(struct vnt_private *pDevice);

static void s_vGenerateTxParameter(struct vnt_private *pDevice,
	u8 byPktType, u16 wCurrentRate,	void *pTxBufHead, void *pvRrvTime,
	void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
105
	struct ethhdr *psEthHeader);
106 107 108

static u32 s_uFillDataHead(struct vnt_private *pDevice,
	u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
109
	u32 uDMAIdx, int bNeedAck, u8 byFBOption);
110 111

static void s_vGenerateMACHeader(struct vnt_private *pDevice,
112
	u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
	int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);

static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
	u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
	u8 *pMICHDR);

static void s_vSWencryption(struct vnt_private *pDevice,
	PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);

static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
	u32 cbFrameLength, u16 wRate, int bNeedAck);

static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
	u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);

static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
	u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
	int bDisCRC, u16 wCurrentRate, u8 byFBOption);

static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
	void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
134
	struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
135 136

static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
137
	u8 byPktType, int bNeedAck);
138

139
static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
140 141
	u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
	int bNeedAck, u8 byFBOption);
142

143
static void *s_vGetFreeContext(struct vnt_private *pDevice)
144
{
145 146 147
	PUSB_SEND_CONTEXT pContext = NULL;
	PUSB_SEND_CONTEXT pReturnContext = NULL;
	int ii;
148 149 150 151 152

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");

    for (ii = 0; ii < pDevice->cbTD; ii++) {
        pContext = pDevice->apTD[ii];
153
        if (pContext->bBoolInUse == false) {
154
            pContext->bBoolInUse = true;
155
		memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
156 157 158 159 160 161 162
            pReturnContext = pContext;
            break;
        }
    }
    if ( ii == pDevice->cbTD ) {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
    }
163
    return (void *) pReturnContext;
164 165
}

166 167
static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
	u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
168
{
169
	PSStatCounter pStatistic = &pDevice->scStatistic;
170

171
    if (is_broadcast_ether_addr(pbyDestAddr))
172
        pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
173
    else if (is_multicast_ether_addr(pbyDestAddr))
174 175 176 177 178 179
        pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
    else
        pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;

    pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
    pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
180 181 182
    memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
	   pbyDestAddr,
	   ETH_ALEN);
183 184
}

185 186 187
static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
	u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
	u16 wPayloadLen, u8 *pMICHDR)
188
{
189 190 191
	u32 *pdwIV = (u32 *)pbyIVHead;
	u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
	u16 wValue;
192
	struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
193
	u32 dwRevIVCounter;
194 195 196 197 198 199 200 201 202 203 204

    //Fill TXKEY
    if (pTransmitKey == NULL)
        return;

    dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
    *pdwIV = pDevice->dwIVCounter;
    pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;

    if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
        if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
205
            memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
206
            memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
207
        } else {
208
            memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
209
            memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
210
            if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
211
                memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
212
                memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
213
            }
214
            memcpy(pDevice->abyPRNG, pbyBuf, 16);
215 216 217
        }
        // Append IV after Mac Header
        *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
218
	*pdwIV |= (u32)pDevice->byKeyIndex << 30;
219 220 221 222 223 224 225 226 227 228 229 230
        *pdwIV = cpu_to_le32(*pdwIV);
        pDevice->dwIVCounter++;
        if (pDevice->dwIVCounter > WEP_IV_MASK) {
            pDevice->dwIVCounter = 0;
        }
    } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
        pTransmitKey->wTSC15_0++;
        if (pTransmitKey->wTSC15_0 == 0) {
            pTransmitKey->dwTSC47_16++;
        }
        TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
                    pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
231
        memcpy(pbyBuf, pDevice->abyPRNG, 16);
232
        // Make IV
233
        memcpy(pdwIV, pDevice->abyPRNG, 3);
234

235
        *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
236 237
        // Append IV&ExtIV after Mac Header
        *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
238 239
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
		*pdwExtIV);
240 241 242 243 244 245

    } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
        pTransmitKey->wTSC15_0++;
        if (pTransmitKey->wTSC15_0 == 0) {
            pTransmitKey->dwTSC47_16++;
        }
246
        memcpy(pbyBuf, pTransmitKey->abyKey, 16);
247 248 249

        // Make IV
        *pdwIV = 0;
250
        *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
251
        *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
252 253 254 255 256
        //Append IV&ExtIV after Mac Header
        *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);

        //Fill MICHDR0
        *pMICHDR = 0x59;
257
        *((u8 *)(pMICHDR+1)) = 0; // TxPriority
258
        memcpy(pMICHDR+2, &(pMACHeader->addr2[0]), 6);
259 260 261 262 263 264 265 266
        *((u8 *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
        *((u8 *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
        *((u8 *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
        *((u8 *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
        *((u8 *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
        *((u8 *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
        *((u8 *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
        *((u8 *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
267 268

        //Fill MICHDR1
269
        *((u8 *)(pMICHDR+16)) = 0; // HLEN[15:8]
270
        if (pDevice->bLongHeader) {
271
            *((u8 *)(pMICHDR+17)) = 28; // HLEN[7:0]
272
        } else {
273
            *((u8 *)(pMICHDR+17)) = 22; // HLEN[7:0]
274
        }
275
        wValue = cpu_to_le16(pMACHeader->frame_control & 0xC78F);
276
        memcpy(pMICHDR+18, (u8 *)&wValue, 2); // MSKFRACTL
277 278
        memcpy(pMICHDR+20, &(pMACHeader->addr1[0]), 6);
        memcpy(pMICHDR+26, &(pMACHeader->addr2[0]), 6);
279 280

        //Fill MICHDR2
281 282
        memcpy(pMICHDR+32, &(pMACHeader->addr3[0]), 6);
        wValue = pMACHeader->seq_ctrl;
283 284
        wValue &= 0x000F;
        wValue = cpu_to_le16(wValue);
285
        memcpy(pMICHDR+38, (u8 *)&wValue, 2); // MSKSEQCTL
286
        if (pDevice->bLongHeader) {
287
            memcpy(pMICHDR+40, &(pMACHeader->addr4[0]), 6);
288 289 290 291
        }
    }
}

292 293
static void s_vSWencryption(struct vnt_private *pDevice,
	PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
294
{
295 296 297
	u32 cbICVlen = 4;
	u32 dwICV = 0xffffffff;
	u32 *pdwICV;
298 299 300 301 302 303 304 305

    if (pTransmitKey == NULL)
        return;

    if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
        //=======================================================================
        // Append ICV after payload
        dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
306
        pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
307 308 309 310 311 312 313 314 315 316
        // finally, we must invert dwCRC to get the correct answer
        *pdwICV = cpu_to_le32(~dwICV);
        // RC4 encryption
        rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
        rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
        //=======================================================================
    } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
        //=======================================================================
        //Append ICV after payload
        dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
317
        pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
318 319 320 321 322 323 324 325 326 327 328 329 330 331
        // finally, we must invert dwCRC to get the correct answer
        *pdwICV = cpu_to_le32(~dwICV);
        // RC4 encryption
        rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
        rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
        //=======================================================================
    }
}

/*byPktType : PK_TYPE_11A     0
             PK_TYPE_11B     1
             PK_TYPE_11GB    2
             PK_TYPE_11GA    3
*/
332 333
static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
	u32 cbFrameLength, u16 wRate, int bNeedAck)
334
{
335
	u32 uDataTime, uAckTime;
336 337 338

    uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
    if (byPktType == PK_TYPE_11B) {//llb,CCK mode
339
        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
340
    } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
341
        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
342 343 344 345 346 347 348 349 350 351 352
    }

    if (bNeedAck) {
        return (uDataTime + pDevice->uSIFS + uAckTime);
    }
    else {
        return uDataTime;
    }
}

//byFreqType: 0=>5GHZ 1=>2.4GHZ
353 354
static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
	u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
355
{
356
	u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386

    uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;

    uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
    if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
        uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
        uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
    }
    else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
        uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
    }
    else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
        uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
        uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
    }
    else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
        uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
        uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
        return uRrvTime;
    }

    //RTSRrvTime
    uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
    return uRrvTime;
}

//byFreqType 0: 5GHz, 1:2.4Ghz
387
static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
388
	u8 byPktType, int bNeedAck)
389
{
390
	u32 uAckTime = 0;
391

392 393 394 395 396 397 398 399 400
	if (bNeedAck) {
		if (byDurType == DATADUR_B)
			uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
				byPktType, 14, pDevice->byTopCCKBasicRate);
		else
			uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
				byPktType, 14, pDevice->byTopOFDMBasicRate);
		return pDevice->uSIFS + uAckTime;
	}
401 402 403 404 405

	return 0;
}

//byFreqType: 0=>5GHZ 1=>2.4GHZ
406
static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
407 408
	u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
	u8 byFBOption)
409
{
410
	u32 uCTSTime = 0, uDurTime = 0;
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

    switch (byDurType) {

    case RTSDUR_BB:    //RTSDuration_bb
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
        uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
        break;

    case RTSDUR_BA:    //RTSDuration_ba
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
        uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
        break;

    case RTSDUR_AA:    //RTSDuration_aa
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
        uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
        break;

    case CTSDUR_BA:    //CTSDuration_ba
        uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
        break;

    case RTSDUR_BA_F0: //RTSDuration_ba_f0
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
        }
        break;

    case RTSDUR_AA_F0: //RTSDuration_aa_f0
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
        }
        break;

    case RTSDUR_BA_F1: //RTSDuration_ba_f1
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
        }
        break;

    case RTSDUR_AA_F1: //RTSDuration_aa_f1
        uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
        }
        break;

    case CTSDUR_BA_F0: //CTSDuration_ba_f0
        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
        }
        break;

    case CTSDUR_BA_F1: //CTSDuration_ba_f1
        if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
        } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
            uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
        }
        break;

    default:
        break;
    }

489
	return cpu_to_le16((u16)uDurTime);
490 491
}

492 493
static u32 s_uFillDataHead(struct vnt_private *pDevice,
	u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
494
	u32 uDMAIdx, int bNeedAck, u8 byFBOption)
495 496 497 498 499 500 501
{

    if (pTxDataHead == NULL) {
        return 0;
    }

    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
502
	if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
503 504
		struct vnt_tx_datahead_ab *pBuf =
			(struct vnt_tx_datahead_ab *)pTxDataHead;
505
            //Get SignalField,ServiceField,Length
506
            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
507
                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
508 509
            );
            //Get Duration and TimeStampOff
510 511
		pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
					byPktType, bNeedAck);
512 513 514 515 516 517 518
            if(uDMAIdx!=TYPE_ATIMDMA) {
                pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
            }
            return (pBuf->wDuration);
        }
        else { // DATA & MANAGE Frame
            if (byFBOption == AUTO_FB_NONE) {
519 520
		struct vnt_tx_datahead_g *pBuf =
				(struct vnt_tx_datahead_g *)pTxDataHead;
521
                //Get SignalField,ServiceField,Length
522
                BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
523
                    (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
524
                );
525
                BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
526
                    (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
527 528
                );
                //Get Duration and TimeStamp
529 530 531 532
		pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
							byPktType, bNeedAck);
		pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
							PK_TYPE_11B, bNeedAck);
533 534 535 536 537 538

                pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
                pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
                return (pBuf->wDuration_a);
             } else {
                // Auto Fallback
539 540
		struct vnt_tx_datahead_g_fb *pBuf =
			(struct vnt_tx_datahead_g_fb *)pTxDataHead;
541
                //Get SignalField,ServiceField,Length
542
                BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
543
                    (u16 *)&(pBuf->wTransmitLength_a), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
544
                );
545
                BBvCalculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
546
                    (u16 *)&(pBuf->wTransmitLength_b), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
547 548
                );
                //Get Duration and TimeStamp
549 550 551 552 553 554 555 556
		pBuf->wDuration_a = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
							byPktType, bNeedAck);
		pBuf->wDuration_b = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
							PK_TYPE_11B, bNeedAck);
		pBuf->wDuration_a_f0 = (u16)s_uGetDataDuration(pDevice,
					DATADUR_A_F0, byPktType, bNeedAck);
		pBuf->wDuration_a_f1 = (u16)s_uGetDataDuration(pDevice,
					DATADUR_A_F1, byPktType, bNeedAck);
557 558 559 560 561 562 563 564 565
                pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
                pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
                return (pBuf->wDuration_a);
            } //if (byFBOption == AUTO_FB_NONE)
        }
    }
    else if (byPktType == PK_TYPE_11A) {
        if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
            // Auto Fallback
566 567
		struct vnt_tx_datahead_a_fb *pBuf =
			(struct vnt_tx_datahead_a_fb *)pTxDataHead;
568
            //Get SignalField,ServiceField,Length
569
            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
570
                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
571 572
            );
            //Get Duration and TimeStampOff
573 574 575 576 577 578
		pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
					byPktType, bNeedAck);
		pBuf->wDuration_f0 = (u16)s_uGetDataDuration(pDevice,
				DATADUR_A_F0, byPktType, bNeedAck);
		pBuf->wDuration_f1 = (u16)s_uGetDataDuration(pDevice,
				DATADUR_A_F1, byPktType, bNeedAck);
579 580 581 582 583
            if(uDMAIdx!=TYPE_ATIMDMA) {
                pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
            }
            return (pBuf->wDuration);
        } else {
584 585
		struct vnt_tx_datahead_ab *pBuf =
			(struct vnt_tx_datahead_ab *)pTxDataHead;
586
            //Get SignalField,ServiceField,Length
587
            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
588
                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
589 590
            );
            //Get Duration and TimeStampOff
591 592
		pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_A,
				byPktType, bNeedAck);
593 594 595 596 597 598 599 600

            if(uDMAIdx!=TYPE_ATIMDMA) {
                pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
            }
            return (pBuf->wDuration);
        }
    }
    else if (byPktType == PK_TYPE_11B) {
601 602
		struct vnt_tx_datahead_ab *pBuf =
			(struct vnt_tx_datahead_ab *)pTxDataHead;
603
            //Get SignalField,ServiceField,Length
604
            BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
605
                (u16 *)&(pBuf->wTransmitLength), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
606 607
            );
            //Get Duration and TimeStampOff
608 609
		pBuf->wDuration = (u16)s_uGetDataDuration(pDevice, DATADUR_B,
				byPktType, bNeedAck);
610 611 612 613 614 615 616 617
            if (uDMAIdx != TYPE_ATIMDMA) {
                pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
            }
            return (pBuf->wDuration);
    }
    return 0;
}

618 619
static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
	void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
620
	struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
621
{
622 623
	u32 uRTSFrameLen = 20;
	u16 wLen = 0;
624 625 626 627 628 629 630 631 632 633

    if (pvRTS == NULL)
    	return;

    if (bDisCRC) {
        // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
        // in this case we need to decrease its length by 4.
        uRTSFrameLen -= 4;
    }

634
    // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
635 636 637
    //       Otherwise, we need to modified codes for them.
    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
        if (byFBOption == AUTO_FB_NONE) {
638
		struct vnt_rts_g *pBuf = (struct vnt_rts_g *)pvRTS;
639
            //Get SignalField,ServiceField,Length
640
            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
641
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
642 643
            );
            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
644
            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
645
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
646 647 648
            );
            pBuf->wTransmitLength_a = cpu_to_le16(wLen);
            //Get Duration
649 650 651 652 653 654 655 656 657
		pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
			cbFrameLength, PK_TYPE_11B,
			pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
		pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
			cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
		pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
			cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
658 659 660 661 662 663 664 665 666 667 668 669 670 671
		pBuf->data.duration = pBuf->wDuration_aa;
		/*Get RTS Frame body */
		pBuf->data.frame_control = TYPE_CTL_RTS;

		if (pDevice->eOPMode == OP_MODE_ADHOC ||
				pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
		else
			memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);

		if (pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
		else
			memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
672 673
        }
        else {
674
		struct vnt_rts_g_fb *pBuf = (struct vnt_rts_g_fb *)pvRTS;
675
            //Get SignalField,ServiceField,Length
676
            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
677
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
678 679
            );
            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
680
            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
681
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_a), (u8 *)&(pBuf->bySignalField_a)
682 683 684
            );
            pBuf->wTransmitLength_a = cpu_to_le16(wLen);
            //Get Duration
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
		pBuf->wDuration_bb = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
			cbFrameLength, PK_TYPE_11B,
			pDevice->byTopCCKBasicRate, bNeedAck, byFBOption);
		pBuf->wDuration_aa = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
			cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
		pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
			cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
		pBuf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
			RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
			bNeedAck, byFBOption);
		pBuf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(pDevice,
			RTSDUR_AA_F0, cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
		pBuf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
			RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
			bNeedAck, byFBOption);
		pBuf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(pDevice,
			RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate,
			bNeedAck, byFBOption);
706 707 708 709 710 711 712 713 714 715 716 717 718 719
		pBuf->data.duration = pBuf->wDuration_aa;
		/*Get RTS Frame body*/
		pBuf->data.frame_control = TYPE_CTL_RTS;

		if (pDevice->eOPMode == OP_MODE_ADHOC ||
				pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
		else
			memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);

		if (pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
		else
			memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
720 721 722 723
        } // if (byFBOption == AUTO_FB_NONE)
    }
    else if (byPktType == PK_TYPE_11A) {
        if (byFBOption == AUTO_FB_NONE) {
724
		struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
725
            //Get SignalField,ServiceField,Length
726
            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
727
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
728 729 730
            );
            pBuf->wTransmitLength = cpu_to_le16(wLen);
            //Get Duration
731 732 733
		pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
			cbFrameLength, byPktType, wCurrentRate,
				bNeedAck, byFBOption);
734 735 736 737 738 739 740 741 742 743 744 745 746 747
		pBuf->data.duration = pBuf->wDuration;
		/* Get RTS Frame body */
		pBuf->data.frame_control = TYPE_CTL_RTS;

		if (pDevice->eOPMode == OP_MODE_ADHOC ||
				pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
		else
			memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);

		if (pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
		else
			memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
748 749
        }
        else {
750
		struct vnt_rts_a_fb *pBuf = (struct vnt_rts_a_fb *)pvRTS;
751
            //Get SignalField,ServiceField,Length
752
            BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
753
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
754 755 756
            );
            pBuf->wTransmitLength = cpu_to_le16(wLen);
            //Get Duration
757 758 759 760 761 762 763 764 765
		pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
			cbFrameLength, byPktType, wCurrentRate,
			bNeedAck, byFBOption);
		pBuf->wRTSDuration_f0 = s_uGetRTSCTSDuration(pDevice,
			RTSDUR_AA_F0, cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
		pBuf->wRTSDuration_f1 = s_uGetRTSCTSDuration(pDevice,
			RTSDUR_AA_F1, cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
766 767 768 769 770 771 772 773 774 775 776 777 778 779
		pBuf->data.duration = pBuf->wDuration;
		/* Get RTS Frame body */
		pBuf->data.frame_control = TYPE_CTL_RTS;

		if (pDevice->eOPMode == OP_MODE_ADHOC ||
				pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
		else
			memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);

		if (pDevice->eOPMode == OP_MODE_AP)
			memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
		else
			memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
780 781 782
        }
    }
    else if (byPktType == PK_TYPE_11B) {
783
	struct vnt_rts_ab *pBuf = (struct vnt_rts_ab *)pvRTS;
784
        //Get SignalField,ServiceField,Length
785
        BBvCalculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
786
            (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField), (u8 *)&(pBuf->bySignalField)
787 788 789
        );
        pBuf->wTransmitLength = cpu_to_le16(wLen);
        //Get Duration
790 791 792
	pBuf->wDuration = s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
		cbFrameLength, byPktType, wCurrentRate,
		bNeedAck, byFBOption);
793

794 795 796 797 798 799 800 801 802 803 804 805 806 807
	pBuf->data.duration = pBuf->wDuration;
	/* Get RTS Frame body */
	pBuf->data.frame_control = TYPE_CTL_RTS;

	if (pDevice->eOPMode == OP_MODE_ADHOC ||
			pDevice->eOPMode == OP_MODE_AP)
		memcpy(pBuf->data.ra, psEthHeader->h_dest, ETH_ALEN);
	else
		memcpy(pBuf->data.ra, pDevice->abyBSSID, ETH_ALEN);

	if (pDevice->eOPMode == OP_MODE_AP)
		memcpy(pBuf->data.ta, pDevice->abyBSSID, ETH_ALEN);
	else
		memcpy(pBuf->data.ta, psEthHeader->h_source, ETH_ALEN);
808 809 810
    }
}

811 812 813
static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
	u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
	int bDisCRC, u16 wCurrentRate, u8 byFBOption)
814
{
815 816
	u32 uCTSFrameLen = 14;
	u16 wLen = 0;
817 818 819 820 821 822 823 824 825 826 827 828 829 830

    if (pvCTS == NULL) {
        return;
    }

    if (bDisCRC) {
        // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
        // in this case we need to decrease its length by 4.
        uCTSFrameLen -= 4;
    }

    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
        if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
            // Auto Fall back
831
		struct vnt_cts_fb *pBuf = (struct vnt_cts_fb *)pvCTS;
832
            //Get SignalField,ServiceField,Length
833
            BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
834
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
835 836
            );
            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
837 838 839 840 841 842 843 844 845 846 847
		pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
			cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
		/* Get CTSDuration_ba_f0 */
		pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
			CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
			bNeedAck, byFBOption);
		/* Get CTSDuration_ba_f1 */
		pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
			CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
			bNeedAck, byFBOption);
848 849 850 851
		/* Get CTS Frame body */
		pBuf->data.duration = pBuf->wDuration_ba;
		pBuf->data.frame_control = TYPE_CTL_CTS;
		memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
852
        } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
853
		struct vnt_cts *pBuf = (struct vnt_cts *)pvCTS;
854
            //Get SignalField,ServiceField,Length
855
            BBvCalculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
856
                (u16 *)&(wLen), (u8 *)&(pBuf->byServiceField_b), (u8 *)&(pBuf->bySignalField_b)
857 858
            );
            pBuf->wTransmitLength_b = cpu_to_le16(wLen);
859 860 861 862
		/* Get CTSDuration_ba */
		pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
			CTSDUR_BA, cbFrameLength, byPktType,
			wCurrentRate, bNeedAck, byFBOption);
863 864 865 866
		/*Get CTS Frame body*/
		pBuf->data.duration = pBuf->wDuration_ba;
		pBuf->data.frame_control = TYPE_CTL_CTS;
		memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
        }
    }
}

/*+
 *
 * Description:
 *      Generate FIFO control for MAC & Baseband controller
 *
 * Parameters:
 *  In:
 *      pDevice         - Pointer to adpater
 *      pTxDataHead     - Transmit Data Buffer
 *      pTxBufHead      - pTxBufHead
 *      pvRrvTime        - pvRrvTime
 *      pvRTS            - RTS Buffer
 *      pCTS            - CTS Buffer
 *      cbFrameSize     - Transmit Data Length (Hdr+Payload+FCS)
 *      bNeedACK        - If need ACK
 *      uDMAIdx         - DMA Index
 *  Out:
 *      none
 *
 * Return Value: none
 *
-*/
893

894 895 896
static void s_vGenerateTxParameter(struct vnt_private *pDevice,
	u8 byPktType, u16 wCurrentRate,	void *pTxBufHead, void *pvRrvTime,
	void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
897
	struct ethhdr *psEthHeader)
898
{
899 900
	u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
	u16 wFifoCtl;
901
	int bDisCRC = false;
902
	u8 byFBOption = AUTO_FB_NONE;
903 904 905 906 907 908 909

    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
    PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
    pFifoHead->wReserved = wCurrentRate;
    wFifoCtl = pFifoHead->wFIFOCtl;

    if (wFifoCtl & FIFOCTL_CRCDIS) {
910
        bDisCRC = true;
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
    }

    if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
        byFBOption = AUTO_FB_0;
    }
    else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
        byFBOption = AUTO_FB_1;
    }

    if (pDevice->bLongHeader)
        cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;

    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {

        if (pvRTS != NULL) { //RTS_need
            //Fill RsvTime
            if (pvRrvTime) {
928 929
		struct vnt_rrv_time_rts *pBuf =
			(struct vnt_rrv_time_rts *)pvRrvTime;
930 931 932 933 934
                pBuf->wRTSTxRrvTime_aa = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
                pBuf->wRTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
                pBuf->wRTSTxRrvTime_bb = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
                pBuf->wTxRrvTime_a = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
                pBuf->wTxRrvTime_b = cpu_to_le16((u16) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
935 936 937 938 939 940 941 942
            }
            //Fill RTS
            s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
        }
        else {//RTS_needless, PCF mode

            //Fill RsvTime
            if (pvRrvTime) {
943 944
		struct vnt_rrv_time_cts *pBuf =
				(struct vnt_rrv_time_cts *)pvRrvTime;
945 946 947
                pBuf->wTxRrvTime_a = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
                pBuf->wTxRrvTime_b = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
                pBuf->wCTSTxRrvTime_ba = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
948 949 950 951 952 953 954 955 956 957
            }
            //Fill CTS
            s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
        }
    }
    else if (byPktType == PK_TYPE_11A) {

        if (pvRTS != NULL) {//RTS_need, non PCF mode
            //Fill RsvTime
            if (pvRrvTime) {
958 959
		struct vnt_rrv_time_ab *pBuf =
				(struct vnt_rrv_time_ab *)pvRrvTime;
960 961
                pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
962 963 964 965 966 967 968
            }
            //Fill RTS
            s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
        }
        else if (pvRTS == NULL) {//RTS_needless, non PCF mode
            //Fill RsvTime
            if (pvRrvTime) {
969 970
		struct vnt_rrv_time_ab *pBuf =
				(struct vnt_rrv_time_ab *)pvRrvTime;
971
                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
972 973 974 975 976 977 978 979
            }
        }
    }
    else if (byPktType == PK_TYPE_11B) {

        if ((pvRTS != NULL)) {//RTS_need, non PCF mode
            //Fill RsvTime
            if (pvRrvTime) {
980 981
		struct vnt_rrv_time_ab *pBuf =
				(struct vnt_rrv_time_ab *)pvRrvTime;
982 983
                pBuf->wRTSTxRrvTime = cpu_to_le16((u16)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
984 985 986 987 988 989 990
            }
            //Fill RTS
            s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
        }
        else { //RTS_needless, non PCF mode
            //Fill RsvTime
            if (pvRrvTime) {
991 992
		struct vnt_rrv_time_ab *pBuf =
				(struct vnt_rrv_time_ab *)pvRrvTime;
993
                pBuf->wTxRrvTime = cpu_to_le16((u16)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
994 995 996 997 998 999
            }
        }
    }
    //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
}
/*
1000
    u8 * pbyBuffer,//point to pTxBufHead
1001
    u16  wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1002
    unsigned int  cbFragmentSize,//Hdr+payoad+FCS
1003 1004
*/

1005
static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
1006 1007 1008 1009
	struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
	u32 uSkbPacketLen, u32 uDMAIdx,	struct ethhdr *psEthHeader,
	u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
	u32 *pcbHeaderLen, u32 *pcbTotalLen)
1010
{
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
	struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
	u32 cbFrameSize, cbFrameBodySize;
	u32 cb802_1_H_len;
	u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
	u32 cbFCSlen = 4, cbMICHDR = 0;
	int bNeedACK, bRTS;
	u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
	u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
	u8 abySNAP_Bridgetunnel[ETH_ALEN]
		= {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
	u32 uDuration;
	u32 cbHeaderLength = 0, uPadding = 0;
	void *pvRrvTime;
	PSMICHDRHead pMICHDR;
	void *pvRTS;
	void *pvCTS;
	void *pvTxDataHd;
	u8 byFBOption = AUTO_FB_NONE, byFragType;
	u16 wTxBufSize;
	u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
	u32 *pdwMIC_L, *pdwMIC_R;
1032
	int bSoftWEP = false;
1033 1034

	pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1035

1036
	if (bNeedEncryption && pTransmitKey->pvKeyTable) {
1037 1038
		if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
			bSoftWEP = true; /* WEP 256 */
1039
	}
1040 1041

    // Get pkt type
1042
    if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
1043 1044 1045 1046 1047 1048 1049 1050 1051
        if (pDevice->dwDiagRefCount == 0) {
            cb802_1_H_len = 8;
        } else {
            cb802_1_H_len = 2;
        }
    } else {
        cb802_1_H_len = 0;
    }

1052
    cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
1053 1054

    //Set packet type
1055
    pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
1056 1057

    if (pDevice->dwDiagRefCount != 0) {
1058
        bNeedACK = false;
1059 1060
        pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
    } else { //if (pDevice->dwDiagRefCount != 0) {
1061 1062
	if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
	    (pDevice->eOPMode == OP_MODE_AP)) {
1063
		if (is_multicast_ether_addr(psEthHeader->h_dest)) {
1064
			bNeedACK = false;
1065 1066 1067
			pTxBufHead->wFIFOCtl =
				pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
		} else {
1068
			bNeedACK = true;
1069 1070
			pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
		}
1071 1072 1073
        }
        else {
            // MSDUs in Infra mode always need ACK
1074
            bNeedACK = true;
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
            pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
        }
    } //if (pDevice->dwDiagRefCount != 0) {

    pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;

    //Set FIFOCTL_LHEAD
    if (pDevice->bLongHeader)
        pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;

    if (pDevice->bSoftwareGenCrcErr) {
        pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
    }

    //Set FRAGCTL_MACHDCNT
    if (pDevice->bLongHeader) {
        cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
    } else {
        cbMACHdLen = WLAN_HDR_ADDR3_LEN;
    }
1095
    pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
1096 1097

    //Set FIFOCTL_GrpAckPolicy
1098
    if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
        pTxBufHead->wFIFOCtl |=	FIFOCTL_GRPACK;
    }

    //Set Auto Fallback Ctl
    if (wCurrentRate >= RATE_18M) {
        if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
            pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
            byFBOption = AUTO_FB_0;
        } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
            pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
            byFBOption = AUTO_FB_1;
        }
    }

1113
    if (bSoftWEP != true) {
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
        if ((bNeedEncryption) && (pTransmitKey != NULL))  { //WEP enabled
            if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
                pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
            }
            if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
                pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
            }
            else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
                pTxBufHead->wFragCtl |= FRAGCTL_AES;
            }
        }
    }

    if ((bNeedEncryption) && (pTransmitKey != NULL))  {
        if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
            cbIVlen = 4;
            cbICVlen = 4;
        }
        else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
            cbIVlen = 8;//IV+ExtIV
            cbMIClen = 8;
            cbICVlen = 4;
        }
        if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
            cbIVlen = 8;//RSN Header
            cbICVlen = 8;//MIC
            cbMICHDR = sizeof(SMICHDRHead);
        }
1143
        if (bSoftWEP == false) {
1144 1145 1146 1147 1148 1149 1150 1151
            //MAC Header should be padding 0 to DW alignment.
            uPadding = 4 - (cbMACHdLen%4);
            uPadding %= 4;
        }
    }

    cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;

1152 1153
    if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
        bRTS = false;
1154
    } else {
1155
        bRTS = true;
1156 1157 1158
        pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
    }

1159
    pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
1160 1161 1162
    wTxBufSize = sizeof(STxBufHead);
    if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
        if (byFBOption == AUTO_FB_NONE) {
1163
            if (bRTS == true) {//RTS_need
1164 1165 1166 1167
		pvRrvTime = (struct vnt_rrv_time_rts *)
					(pbyTxBufferAddr + wTxBufSize);
		pMICHDR = (PSMICHDRHead)(pbyTxBufferAddr + wTxBufSize +
					sizeof(struct vnt_rrv_time_rts));
1168
		pvRTS = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
1169
				sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1170
                pvCTS = NULL;
1171 1172 1173
		pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
			wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
				cbMICHDR + sizeof(struct vnt_rts_g));
1174
		cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1175
			cbMICHDR + sizeof(struct vnt_rts_g) +
1176
				sizeof(struct vnt_tx_datahead_g);
1177 1178
            }
            else { //RTS_needless
1179 1180 1181 1182
		pvRrvTime = (struct vnt_rrv_time_cts *)
				(pbyTxBufferAddr + wTxBufSize);
		pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
			sizeof(struct vnt_rrv_time_cts));
1183
                pvRTS = NULL;
1184
		pvCTS = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
1185
				sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1186 1187 1188
		pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
			wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
				cbMICHDR + sizeof(struct vnt_cts));
1189 1190
		cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
			cbMICHDR + sizeof(struct vnt_cts) +
1191
				sizeof(struct vnt_tx_datahead_g);
1192 1193 1194
            }
        } else {
            // Auto Fall Back
1195
            if (bRTS == true) {//RTS_need
1196 1197 1198 1199
		pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
								wTxBufSize);
		pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize +
					sizeof(struct vnt_rrv_time_rts));
1200
		pvRTS = (struct vnt_rts_g_fb *) (pbyTxBufferAddr + wTxBufSize +
1201
				sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1202
                pvCTS = NULL;
1203 1204 1205
		pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
			wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
				cbMICHDR + sizeof(struct vnt_rts_g_fb));
1206 1207
		cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
			cbMICHDR + sizeof(struct vnt_rts_g_fb) +
1208
				sizeof(struct vnt_tx_datahead_g_fb);