Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux...
[linux-btrfs-devel.git] / drivers / staging / vt6655 / rxtx.c
blob6935b37d5444dbade814e0b66190a35203c0fd97
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
19 * File: rxtx.c
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
23 * Author: Lyndon Chen
25 * Date: May 20, 2003
27 * Functions:
28 * s_vGenerateTxParameter - Generate tx dma required parameter.
29 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Caculate fragment number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts required duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragment ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
47 * Revision History:
51 #include "device.h"
52 #include "rxtx.h"
53 #include "tether.h"
54 #include "card.h"
55 #include "bssdb.h"
56 #include "mac.h"
57 #include "baseband.h"
58 #include "michael.h"
59 #include "tkip.h"
60 #include "tcrc.h"
61 #include "wctl.h"
62 #include "wroute.h"
63 #include "hostap.h"
64 #include "rf.h"
66 /*--------------------- Static Definitions -------------------------*/
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
71 //static int msglevel =MSG_LEVEL_DEBUG;
72 static int msglevel =MSG_LEVEL_INFO;
74 #define PLICE_DEBUG
77 /*--------------------- Static Functions --------------------------*/
79 /*--------------------- Static Definitions -------------------------*/
80 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
81 // packet size >= 256 -> direct send
83 const unsigned short wTimeStampOff[2][MAX_RATE] = {
84 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
85 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
88 const unsigned short wFB_Opt0[2][5] = {
89 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
90 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
92 const unsigned short wFB_Opt1[2][5] = {
93 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
94 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
98 #define RTSDUR_BB 0
99 #define RTSDUR_BA 1
100 #define RTSDUR_AA 2
101 #define CTSDUR_BA 3
102 #define RTSDUR_BA_F0 4
103 #define RTSDUR_AA_F0 5
104 #define RTSDUR_BA_F1 6
105 #define RTSDUR_AA_F1 7
106 #define CTSDUR_BA_F0 8
107 #define CTSDUR_BA_F1 9
108 #define DATADUR_B 10
109 #define DATADUR_A 11
110 #define DATADUR_A_F0 12
111 #define DATADUR_A_F1 13
113 /*--------------------- Static Functions --------------------------*/
117 static
118 void
119 s_vFillTxKey(
120 PSDevice pDevice,
121 unsigned char *pbyBuf,
122 unsigned char *pbyIVHead,
123 PSKeyItem pTransmitKey,
124 unsigned char *pbyHdrBuf,
125 unsigned short wPayloadLen,
126 unsigned char *pMICHDR
131 static
132 void
133 s_vFillRTSHead(
134 PSDevice pDevice,
135 unsigned char byPktType,
136 void * pvRTS,
137 unsigned int cbFrameLength,
138 bool bNeedAck,
139 bool bDisCRC,
140 PSEthernetHeader psEthHeader,
141 unsigned short wCurrentRate,
142 unsigned char byFBOption
145 static
146 void
147 s_vGenerateTxParameter(
148 PSDevice pDevice,
149 unsigned char byPktType,
150 void * pTxBufHead,
151 void * pvRrvTime,
152 void * pvRTS,
153 void * pvCTS,
154 unsigned int cbFrameSize,
155 bool bNeedACK,
156 unsigned int uDMAIdx,
157 PSEthernetHeader psEthHeader,
158 unsigned short wCurrentRate
163 static void s_vFillFragParameter(
164 PSDevice pDevice,
165 unsigned char *pbyBuffer,
166 unsigned int uTxType,
167 void * pvtdCurr,
168 unsigned short wFragType,
169 unsigned int cbReqCount
173 static unsigned int
174 s_cbFillTxBufHead(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
175 unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
176 PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
177 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum);
180 static
181 unsigned int
182 s_uFillDataHead (
183 PSDevice pDevice,
184 unsigned char byPktType,
185 void * pTxDataHead,
186 unsigned int cbFrameLength,
187 unsigned int uDMAIdx,
188 bool bNeedAck,
189 unsigned int uFragIdx,
190 unsigned int cbLastFragmentSize,
191 unsigned int uMACfragNum,
192 unsigned char byFBOption,
193 unsigned short wCurrentRate
197 /*--------------------- Export Variables --------------------------*/
201 static
202 void
203 s_vFillTxKey (
204 PSDevice pDevice,
205 unsigned char *pbyBuf,
206 unsigned char *pbyIVHead,
207 PSKeyItem pTransmitKey,
208 unsigned char *pbyHdrBuf,
209 unsigned short wPayloadLen,
210 unsigned char *pMICHDR
213 unsigned long *pdwIV = (unsigned long *) pbyIVHead;
214 unsigned long *pdwExtIV = (unsigned long *) ((unsigned char *)pbyIVHead+4);
215 unsigned short wValue;
216 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
217 unsigned long dwRevIVCounter;
218 unsigned char byKeyIndex = 0;
222 //Fill TXKEY
223 if (pTransmitKey == NULL)
224 return;
226 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
227 *pdwIV = pDevice->dwIVCounter;
228 byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
230 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
231 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
232 memcpy(pDevice->abyPRNG, (unsigned char *)&(dwRevIVCounter), 3);
233 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
234 } else {
235 memcpy(pbyBuf, (unsigned char *)&(dwRevIVCounter), 3);
236 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
237 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
238 memcpy(pbyBuf+8, (unsigned char *)&(dwRevIVCounter), 3);
239 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
241 memcpy(pDevice->abyPRNG, pbyBuf, 16);
243 // Append IV after Mac Header
244 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
245 *pdwIV |= (byKeyIndex << 30);
246 *pdwIV = cpu_to_le32(*pdwIV);
247 pDevice->dwIVCounter++;
248 if (pDevice->dwIVCounter > WEP_IV_MASK) {
249 pDevice->dwIVCounter = 0;
251 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
252 pTransmitKey->wTSC15_0++;
253 if (pTransmitKey->wTSC15_0 == 0) {
254 pTransmitKey->dwTSC47_16++;
256 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
257 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
258 memcpy(pbyBuf, pDevice->abyPRNG, 16);
259 // Make IV
260 memcpy(pdwIV, pDevice->abyPRNG, 3);
262 *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
263 // Append IV&ExtIV after Mac Header
264 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
267 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
268 pTransmitKey->wTSC15_0++;
269 if (pTransmitKey->wTSC15_0 == 0) {
270 pTransmitKey->dwTSC47_16++;
272 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
274 // Make IV
275 *pdwIV = 0;
276 *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
277 *pdwIV |= cpu_to_le16((unsigned short)(pTransmitKey->wTSC15_0));
278 //Append IV&ExtIV after Mac Header
279 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
281 //Fill MICHDR0
282 *pMICHDR = 0x59;
283 *((unsigned char *)(pMICHDR+1)) = 0; // TxPriority
284 memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
285 *((unsigned char *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
286 *((unsigned char *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
287 *((unsigned char *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
288 *((unsigned char *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
289 *((unsigned char *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
290 *((unsigned char *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
291 *((unsigned char *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
292 *((unsigned char *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
294 //Fill MICHDR1
295 *((unsigned char *)(pMICHDR+16)) = 0; // HLEN[15:8]
296 if (pDevice->bLongHeader) {
297 *((unsigned char *)(pMICHDR+17)) = 28; // HLEN[7:0]
298 } else {
299 *((unsigned char *)(pMICHDR+17)) = 22; // HLEN[7:0]
301 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
302 memcpy(pMICHDR+18, (unsigned char *)&wValue, 2); // MSKFRACTL
303 memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
304 memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
306 //Fill MICHDR2
307 memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
308 wValue = pMACHeader->wSeqCtl;
309 wValue &= 0x000F;
310 wValue = cpu_to_le16(wValue);
311 memcpy(pMICHDR+38, (unsigned char *)&wValue, 2); // MSKSEQCTL
312 if (pDevice->bLongHeader) {
313 memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
319 static
320 void
321 s_vSWencryption (
322 PSDevice pDevice,
323 PSKeyItem pTransmitKey,
324 unsigned char *pbyPayloadHead,
325 unsigned short wPayloadSize
328 unsigned int cbICVlen = 4;
329 unsigned long dwICV = 0xFFFFFFFFL;
330 unsigned long *pdwICV;
332 if (pTransmitKey == NULL)
333 return;
335 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
336 //=======================================================================
337 // Append ICV after payload
338 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
339 pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
340 // finally, we must invert dwCRC to get the correct answer
341 *pdwICV = cpu_to_le32(~dwICV);
342 // RC4 encryption
343 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
344 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
345 //=======================================================================
346 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
347 //=======================================================================
348 //Append ICV after payload
349 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
350 pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
351 // finally, we must invert dwCRC to get the correct answer
352 *pdwICV = cpu_to_le32(~dwICV);
353 // RC4 encryption
354 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
355 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
356 //=======================================================================
363 /*byPktType : PK_TYPE_11A 0
364 PK_TYPE_11B 1
365 PK_TYPE_11GB 2
366 PK_TYPE_11GA 3
368 static
369 unsigned int
370 s_uGetTxRsvTime (
371 PSDevice pDevice,
372 unsigned char byPktType,
373 unsigned int cbFrameLength,
374 unsigned short wRate,
375 bool bNeedAck
378 unsigned int uDataTime, uAckTime;
380 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
381 #ifdef PLICE_DEBUG
382 //printk("s_uGetTxRsvTime is %d\n",uDataTime);
383 #endif
384 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
385 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
386 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
387 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
390 if (bNeedAck) {
391 return (uDataTime + pDevice->uSIFS + uAckTime);
393 else {
394 return uDataTime;
398 //byFreqType: 0=>5GHZ 1=>2.4GHZ
399 static
400 unsigned int
401 s_uGetRTSCTSRsvTime (
402 PSDevice pDevice,
403 unsigned char byRTSRsvType,
404 unsigned char byPktType,
405 unsigned int cbFrameLength,
406 unsigned short wCurrentRate
409 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
411 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
414 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
415 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
416 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
417 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
419 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
420 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
421 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
422 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
424 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
425 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
426 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
428 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
429 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
430 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
431 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
432 return uRrvTime;
435 //RTSRrvTime
436 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
437 return uRrvTime;
440 //byFreqType 0: 5GHz, 1:2.4Ghz
441 static
442 unsigned int
443 s_uGetDataDuration (
444 PSDevice pDevice,
445 unsigned char byDurType,
446 unsigned int cbFrameLength,
447 unsigned char byPktType,
448 unsigned short wRate,
449 bool bNeedAck,
450 unsigned int uFragIdx,
451 unsigned int cbLastFragmentSize,
452 unsigned int uMACfragNum,
453 unsigned char byFBOption
456 bool bLastFrag = 0;
457 unsigned int uAckTime =0, uNextPktTime = 0;
461 if (uFragIdx == (uMACfragNum-1)) {
462 bLastFrag = 1;
466 switch (byDurType) {
468 case DATADUR_B: //DATADUR_B
469 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
470 if (bNeedAck) {
471 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
472 return (pDevice->uSIFS + uAckTime);
473 } else {
474 return 0;
477 else {//First Frag or Mid Frag
478 if (uFragIdx == (uMACfragNum-2)) {
479 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
480 } else {
481 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
483 if (bNeedAck) {
484 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
485 return (pDevice->uSIFS + uAckTime + uNextPktTime);
486 } else {
487 return (pDevice->uSIFS + uNextPktTime);
490 break;
492 case DATADUR_A: //DATADUR_A
493 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
494 if(bNeedAck){
495 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
496 return (pDevice->uSIFS + uAckTime);
497 } else {
498 return 0;
501 else {//First Frag or Mid Frag
502 if(uFragIdx == (uMACfragNum-2)){
503 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
504 } else {
505 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
507 if(bNeedAck){
508 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
509 return (pDevice->uSIFS + uAckTime + uNextPktTime);
510 } else {
511 return (pDevice->uSIFS + uNextPktTime);
514 break;
516 case DATADUR_A_F0: //DATADUR_A_F0
517 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
518 if(bNeedAck){
519 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
520 return (pDevice->uSIFS + uAckTime);
521 } else {
522 return 0;
525 else { //First Frag or Mid Frag
526 if (byFBOption == AUTO_FB_0) {
527 if (wRate < RATE_18M)
528 wRate = RATE_18M;
529 else if (wRate > RATE_54M)
530 wRate = RATE_54M;
532 if(uFragIdx == (uMACfragNum-2)){
533 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
534 } else {
535 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
537 } else { // (byFBOption == AUTO_FB_1)
538 if (wRate < RATE_18M)
539 wRate = RATE_18M;
540 else if (wRate > RATE_54M)
541 wRate = RATE_54M;
543 if(uFragIdx == (uMACfragNum-2)){
544 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
545 } else {
546 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
550 if(bNeedAck){
551 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
552 return (pDevice->uSIFS + uAckTime + uNextPktTime);
553 } else {
554 return (pDevice->uSIFS + uNextPktTime);
557 break;
559 case DATADUR_A_F1: //DATADUR_A_F1
560 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
561 if(bNeedAck){
562 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
563 return (pDevice->uSIFS + uAckTime);
564 } else {
565 return 0;
568 else { //First Frag or Mid Frag
569 if (byFBOption == AUTO_FB_0) {
570 if (wRate < RATE_18M)
571 wRate = RATE_18M;
572 else if (wRate > RATE_54M)
573 wRate = RATE_54M;
575 if(uFragIdx == (uMACfragNum-2)){
576 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
577 } else {
578 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
581 } else { // (byFBOption == AUTO_FB_1)
582 if (wRate < RATE_18M)
583 wRate = RATE_18M;
584 else if (wRate > RATE_54M)
585 wRate = RATE_54M;
587 if(uFragIdx == (uMACfragNum-2)){
588 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
589 } else {
590 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
593 if(bNeedAck){
594 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
595 return (pDevice->uSIFS + uAckTime + uNextPktTime);
596 } else {
597 return (pDevice->uSIFS + uNextPktTime);
600 break;
602 default:
603 break;
606 ASSERT(false);
607 return 0;
611 //byFreqType: 0=>5GHZ 1=>2.4GHZ
612 static
613 unsigned int
614 s_uGetRTSCTSDuration (
615 PSDevice pDevice,
616 unsigned char byDurType,
617 unsigned int cbFrameLength,
618 unsigned char byPktType,
619 unsigned short wRate,
620 bool bNeedAck,
621 unsigned char byFBOption
624 unsigned int uCTSTime = 0, uDurTime = 0;
627 switch (byDurType) {
629 case RTSDUR_BB: //RTSDuration_bb
630 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
631 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
632 break;
634 case RTSDUR_BA: //RTSDuration_ba
635 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
636 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
637 break;
639 case RTSDUR_AA: //RTSDuration_aa
640 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
641 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
642 break;
644 case CTSDUR_BA: //CTSDuration_ba
645 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
646 break;
648 case RTSDUR_BA_F0: //RTSDuration_ba_f0
649 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
650 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
651 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
652 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
653 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
655 break;
657 case RTSDUR_AA_F0: //RTSDuration_aa_f0
658 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
659 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
660 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
661 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
662 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
664 break;
666 case RTSDUR_BA_F1: //RTSDuration_ba_f1
667 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
668 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
669 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
670 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
671 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
673 break;
675 case RTSDUR_AA_F1: //RTSDuration_aa_f1
676 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
677 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
678 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
679 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
680 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
682 break;
684 case CTSDUR_BA_F0: //CTSDuration_ba_f0
685 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
686 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
687 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
688 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
690 break;
692 case CTSDUR_BA_F1: //CTSDuration_ba_f1
693 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
694 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
695 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
696 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
698 break;
700 default:
701 break;
704 return uDurTime;
710 static
711 unsigned int
712 s_uFillDataHead (
713 PSDevice pDevice,
714 unsigned char byPktType,
715 void * pTxDataHead,
716 unsigned int cbFrameLength,
717 unsigned int uDMAIdx,
718 bool bNeedAck,
719 unsigned int uFragIdx,
720 unsigned int cbLastFragmentSize,
721 unsigned int uMACfragNum,
722 unsigned char byFBOption,
723 unsigned short wCurrentRate
726 unsigned short wLen = 0x0000;
728 if (pTxDataHead == NULL) {
729 return 0;
732 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
733 if (byFBOption == AUTO_FB_NONE) {
734 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
735 //Get SignalField,ServiceField,Length
736 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
737 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
739 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
740 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
741 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
743 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
744 //Get Duration and TimeStamp
745 pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
746 byPktType, wCurrentRate, bNeedAck, uFragIdx,
747 cbLastFragmentSize, uMACfragNum,
748 byFBOption)); //1: 2.4GHz
749 pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
750 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
751 bNeedAck, uFragIdx, cbLastFragmentSize,
752 uMACfragNum, byFBOption)); //1: 2.4
754 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
755 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
757 return (pBuf->wDuration_a);
758 } else {
759 // Auto Fallback
760 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
761 //Get SignalField,ServiceField,Length
762 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
763 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
765 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
766 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
767 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
769 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
770 //Get Duration and TimeStamp
771 pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
772 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
773 pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
774 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
775 pBuf->wDuration_a_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
776 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
777 pBuf->wDuration_a_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
778 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
780 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
781 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
783 return (pBuf->wDuration_a);
784 } //if (byFBOption == AUTO_FB_NONE)
786 else if (byPktType == PK_TYPE_11A) {
787 if ((byFBOption != AUTO_FB_NONE)) {
788 // Auto Fallback
789 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
790 //Get SignalField,ServiceField,Length
791 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
792 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
794 pBuf->wTransmitLength = cpu_to_le16(wLen);
795 //Get Duration and TimeStampOff
797 pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
798 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
799 pBuf->wDuration_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
800 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
801 pBuf->wDuration_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
802 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
803 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
804 return (pBuf->wDuration);
805 } else {
806 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
807 //Get SignalField,ServiceField,Length
808 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
809 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
811 pBuf->wTransmitLength = cpu_to_le16(wLen);
812 //Get Duration and TimeStampOff
814 pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
815 wCurrentRate, bNeedAck, uFragIdx,
816 cbLastFragmentSize, uMACfragNum,
817 byFBOption));
819 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
820 return (pBuf->wDuration);
823 else {
824 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
825 //Get SignalField,ServiceField,Length
826 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
827 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
829 pBuf->wTransmitLength = cpu_to_le16(wLen);
830 //Get Duration and TimeStampOff
831 pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
832 wCurrentRate, bNeedAck, uFragIdx,
833 cbLastFragmentSize, uMACfragNum,
834 byFBOption));
835 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
836 return (pBuf->wDuration);
838 return 0;
842 static
843 void
844 s_vFillRTSHead (
845 PSDevice pDevice,
846 unsigned char byPktType,
847 void * pvRTS,
848 unsigned int cbFrameLength,
849 bool bNeedAck,
850 bool bDisCRC,
851 PSEthernetHeader psEthHeader,
852 unsigned short wCurrentRate,
853 unsigned char byFBOption
856 unsigned int uRTSFrameLen = 20;
857 unsigned short wLen = 0x0000;
859 if (pvRTS == NULL)
860 return;
862 if (bDisCRC) {
863 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
864 // in this case we need to decrease its length by 4.
865 uRTSFrameLen -= 4;
868 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
869 // Otherwise, we need to modify codes for them.
870 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
871 if (byFBOption == AUTO_FB_NONE) {
872 PSRTS_g pBuf = (PSRTS_g)pvRTS;
873 //Get SignalField,ServiceField,Length
874 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
875 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
877 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
878 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
879 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
881 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
882 //Get Duration
883 pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
884 pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
885 pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
887 pBuf->Data.wDurationID = pBuf->wDuration_aa;
888 //Get RTS Frame body
889 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
890 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
891 (pDevice->eOPMode == OP_MODE_AP)) {
892 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
894 else {
895 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
897 if (pDevice->eOPMode == OP_MODE_AP) {
898 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
900 else {
901 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
904 else {
905 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
906 //Get SignalField,ServiceField,Length
907 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
908 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
910 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
911 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
912 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
914 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
916 //Get Duration
917 pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
918 pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
919 pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
920 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
921 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
922 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
923 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
924 pBuf->Data.wDurationID = pBuf->wDuration_aa;
925 //Get RTS Frame body
926 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
928 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
929 (pDevice->eOPMode == OP_MODE_AP)) {
930 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
932 else {
933 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
936 if (pDevice->eOPMode == OP_MODE_AP) {
937 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
939 else {
940 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
943 } // if (byFBOption == AUTO_FB_NONE)
945 else if (byPktType == PK_TYPE_11A) {
946 if (byFBOption == AUTO_FB_NONE) {
947 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
948 //Get SignalField,ServiceField,Length
949 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
950 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
952 pBuf->wTransmitLength = cpu_to_le16(wLen);
953 //Get Duration
954 pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
955 pBuf->Data.wDurationID = pBuf->wDuration;
956 //Get RTS Frame body
957 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
959 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
960 (pDevice->eOPMode == OP_MODE_AP)) {
961 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
963 else {
964 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
967 if (pDevice->eOPMode == OP_MODE_AP) {
968 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
970 else {
971 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
975 else {
976 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
977 //Get SignalField,ServiceField,Length
978 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
979 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
981 pBuf->wTransmitLength = cpu_to_le16(wLen);
982 //Get Duration
983 pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
984 pBuf->wRTSDuration_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
985 pBuf->wRTSDuration_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
986 pBuf->Data.wDurationID = pBuf->wDuration;
987 //Get RTS Frame body
988 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
990 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
991 (pDevice->eOPMode == OP_MODE_AP)) {
992 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
994 else {
995 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
997 if (pDevice->eOPMode == OP_MODE_AP) {
998 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1000 else {
1001 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
1005 else if (byPktType == PK_TYPE_11B) {
1006 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1007 //Get SignalField,ServiceField,Length
1008 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1009 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
1011 pBuf->wTransmitLength = cpu_to_le16(wLen);
1012 //Get Duration
1013 pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1014 pBuf->Data.wDurationID = pBuf->wDuration;
1015 //Get RTS Frame body
1016 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1019 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1020 (pDevice->eOPMode == OP_MODE_AP)) {
1021 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
1023 else {
1024 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1027 if (pDevice->eOPMode == OP_MODE_AP) {
1028 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1030 else {
1031 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
1036 static
1037 void
1038 s_vFillCTSHead (
1039 PSDevice pDevice,
1040 unsigned int uDMAIdx,
1041 unsigned char byPktType,
1042 void * pvCTS,
1043 unsigned int cbFrameLength,
1044 bool bNeedAck,
1045 bool bDisCRC,
1046 unsigned short wCurrentRate,
1047 unsigned char byFBOption
1050 unsigned int uCTSFrameLen = 14;
1051 unsigned short wLen = 0x0000;
1053 if (pvCTS == NULL) {
1054 return;
1057 if (bDisCRC) {
1058 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1059 // in this case we need to decrease its length by 4.
1060 uCTSFrameLen -= 4;
1063 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1064 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1065 // Auto Fall back
1066 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1067 //Get SignalField,ServiceField,Length
1068 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1069 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
1073 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1075 pBuf->wDuration_ba = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1076 pBuf->wDuration_ba += pDevice->wCTSDuration;
1077 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1078 //Get CTSDuration_ba_f0
1079 pBuf->wCTSDuration_ba_f0 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
1080 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1081 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1082 //Get CTSDuration_ba_f1
1083 pBuf->wCTSDuration_ba_f1 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
1084 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1085 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1086 //Get CTS Frame body
1087 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1088 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1089 pBuf->Data.wReserved = 0x0000;
1090 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
1092 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1093 PSCTS pBuf = (PSCTS)pvCTS;
1094 //Get SignalField,ServiceField,Length
1095 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1096 (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
1098 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1099 //Get CTSDuration_ba
1100 pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1101 pBuf->wDuration_ba += pDevice->wCTSDuration;
1102 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1104 //Get CTS Frame body
1105 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1106 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1107 pBuf->Data.wReserved = 0x0000;
1108 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
1120 * Description:
1121 * Generate FIFO control for MAC & Baseband controller
1123 * Parameters:
1124 * In:
1125 * pDevice - Pointer to adapter
1126 * pTxDataHead - Transmit Data Buffer
1127 * pTxBufHead - pTxBufHead
1128 * pvRrvTime - pvRrvTime
1129 * pvRTS - RTS Buffer
1130 * pCTS - CTS Buffer
1131 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1132 * bNeedACK - If need ACK
1133 * uDescIdx - Desc Index
1134 * Out:
1135 * none
1137 * Return Value: none
1140 // unsigned int cbFrameSize,//Hdr+Payload+FCS
1141 static
1142 void
1143 s_vGenerateTxParameter (
1144 PSDevice pDevice,
1145 unsigned char byPktType,
1146 void * pTxBufHead,
1147 void * pvRrvTime,
1148 void * pvRTS,
1149 void * pvCTS,
1150 unsigned int cbFrameSize,
1151 bool bNeedACK,
1152 unsigned int uDMAIdx,
1153 PSEthernetHeader psEthHeader,
1154 unsigned short wCurrentRate
1157 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1158 unsigned short wFifoCtl;
1159 bool bDisCRC = false;
1160 unsigned char byFBOption = AUTO_FB_NONE;
1161 // unsigned short wCurrentRate = pDevice->wCurrentRate;
1163 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1164 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1165 pFifoHead->wReserved = wCurrentRate;
1166 wFifoCtl = pFifoHead->wFIFOCtl;
1168 if (wFifoCtl & FIFOCTL_CRCDIS) {
1169 bDisCRC = true;
1172 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1173 byFBOption = AUTO_FB_0;
1175 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1176 byFBOption = AUTO_FB_1;
1179 if (pDevice->bLongHeader)
1180 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1182 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1184 if (pvRTS != NULL) { //RTS_need
1185 //Fill RsvTime
1186 if (pvRrvTime) {
1187 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1188 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1189 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1190 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1191 pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1192 pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1194 //Fill RTS
1195 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1197 else {//RTS_needless, PCF mode
1199 //Fill RsvTime
1200 if (pvRrvTime) {
1201 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1202 pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1203 pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1204 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1208 //Fill CTS
1209 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1212 else if (byPktType == PK_TYPE_11A) {
1214 if (pvRTS != NULL) {//RTS_need, non PCF mode
1215 //Fill RsvTime
1216 if (pvRrvTime) {
1217 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1218 pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1219 pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1221 //Fill RTS
1222 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1224 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1225 //Fill RsvTime
1226 if (pvRrvTime) {
1227 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1228 pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1232 else if (byPktType == PK_TYPE_11B) {
1234 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1235 //Fill RsvTime
1236 if (pvRrvTime) {
1237 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1238 pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1239 pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1241 //Fill RTS
1242 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1244 else { //RTS_needless, non PCF mode
1245 //Fill RsvTime
1246 if (pvRrvTime) {
1247 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1248 pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1252 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1255 unsigned char *pbyBuffer,//point to pTxBufHead
1256 unsigned short wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1257 unsigned int cbFragmentSize,//Hdr+payoad+FCS
1259 static
1260 void
1261 s_vFillFragParameter(
1262 PSDevice pDevice,
1263 unsigned char *pbyBuffer,
1264 unsigned int uTxType,
1265 void * pvtdCurr,
1266 unsigned short wFragType,
1267 unsigned int cbReqCount
1270 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
1271 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
1273 if (uTxType == TYPE_SYNCDMA) {
1274 //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1275 PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
1277 //Set FIFOCtl & TimeStamp in TxSyncDesc
1278 ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
1279 ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
1280 //Set TSR1 & ReqCount in TxDescHead
1281 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1282 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1283 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1285 else {
1286 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1289 else {
1290 //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1291 PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
1292 //Set TSR1 & ReqCount in TxDescHead
1293 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1294 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1295 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1297 else {
1298 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1302 pTxBufHead->wFragCtl |= (unsigned short)wFragType;//0x0001; //0000 0000 0000 0001
1304 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
1307 static unsigned int
1308 s_cbFillTxBufHead(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
1309 unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
1310 PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
1311 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum)
1313 unsigned int cbMACHdLen;
1314 unsigned int cbFrameSize;
1315 unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1316 unsigned int cbFragPayloadSize;
1317 unsigned int cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1318 unsigned int cbLastFragPayloadSize;
1319 unsigned int uFragIdx;
1320 unsigned char *pbyPayloadHead;
1321 unsigned char *pbyIVHead;
1322 unsigned char *pbyMacHdr;
1323 unsigned short wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
1324 unsigned int uDuration;
1325 unsigned char *pbyBuffer;
1326 // unsigned int uKeyEntryIdx = NUM_KEY_ENTRY+1;
1327 // unsigned char byKeySel = 0xFF;
1328 unsigned int cbIVlen = 0;
1329 unsigned int cbICVlen = 0;
1330 unsigned int cbMIClen = 0;
1331 unsigned int cbFCSlen = 4;
1332 unsigned int cb802_1_H_len = 0;
1333 unsigned int uLength = 0;
1334 unsigned int uTmpLen = 0;
1335 // unsigned char abyTmp[8];
1336 // unsigned long dwCRC;
1337 unsigned int cbMICHDR = 0;
1338 unsigned long dwMICKey0, dwMICKey1;
1339 unsigned long dwMIC_Priority;
1340 unsigned long *pdwMIC_L;
1341 unsigned long *pdwMIC_R;
1342 unsigned long dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
1343 bool bMIC2Frag = false;
1344 unsigned int uMICFragLen = 0;
1345 unsigned int uMACfragNum = 1;
1346 unsigned int uPadding = 0;
1347 unsigned int cbReqCount = 0;
1349 bool bNeedACK;
1350 bool bRTS;
1351 bool bIsAdhoc;
1352 unsigned char *pbyType;
1353 PSTxDesc ptdCurr;
1354 PSTxBufHead psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
1355 // unsigned int tmpDescIdx;
1356 unsigned int cbHeaderLength = 0;
1357 void * pvRrvTime;
1358 PSMICHDRHead pMICHDR;
1359 void * pvRTS;
1360 void * pvCTS;
1361 void * pvTxDataHd;
1362 unsigned short wTxBufSize; // FFinfo size
1363 unsigned int uTotalCopyLength = 0;
1364 unsigned char byFBOption = AUTO_FB_NONE;
1365 bool bIsWEP256 = false;
1366 PSMgmtObject pMgmt = pDevice->pMgmt;
1369 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1371 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
1372 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1373 (pDevice->eOPMode == OP_MODE_AP)) {
1375 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
1376 bNeedACK = false;
1377 else
1378 bNeedACK = true;
1379 bIsAdhoc = true;
1381 else {
1382 // MSDUs in Infra mode always need ACK
1383 bNeedACK = true;
1384 bIsAdhoc = false;
1387 if (pDevice->bLongHeader)
1388 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1389 else
1390 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1393 if ((bNeedEncrypt == true) && (pTransmitKey != NULL)) {
1394 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1395 cbIVlen = 4;
1396 cbICVlen = 4;
1397 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
1398 bIsWEP256 = true;
1401 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1402 cbIVlen = 8;//IV+ExtIV
1403 cbMIClen = 8;
1404 cbICVlen = 4;
1406 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1407 cbIVlen = 8;//RSN Header
1408 cbICVlen = 8;//MIC
1409 cbMICHDR = sizeof(SMICHDRHead);
1411 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1412 //MAC Header should be padding 0 to DW alignment.
1413 uPadding = 4 - (cbMACHdLen%4);
1414 uPadding %= 4;
1419 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1421 if ((bNeedACK == false) ||
1422 (cbFrameSize < pDevice->wRTSThreshold) ||
1423 ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
1425 bRTS = false;
1427 else {
1428 bRTS = true;
1429 psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1432 // Use for AUTO FALL BACK
1434 if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1435 byFBOption = AUTO_FB_0;
1437 else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1438 byFBOption = AUTO_FB_1;
1441 //////////////////////////////////////////////////////
1442 //Set RrvTime/RTS/CTS Buffer
1443 wTxBufSize = sizeof(STxBufHead);
1444 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1446 if (byFBOption == AUTO_FB_NONE) {
1447 if (bRTS == true) {//RTS_need
1448 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1449 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1450 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1451 pvCTS = NULL;
1452 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1453 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1455 else { //RTS_needless
1456 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1457 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1458 pvRTS = NULL;
1459 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1460 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1461 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1463 } else {
1464 // Auto Fall Back
1465 if (bRTS == true) {//RTS_need
1466 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1467 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1468 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1469 pvCTS = NULL;
1470 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1471 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1473 else { //RTS_needless
1474 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1475 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1476 pvRTS = NULL;
1477 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1478 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1479 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1481 } // Auto Fall Back
1483 else {//802.11a/b packet
1485 if (byFBOption == AUTO_FB_NONE) {
1486 if (bRTS == true) {
1487 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1488 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1489 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1490 pvCTS = NULL;
1491 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1492 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1494 else { //RTS_needless, need MICHDR
1495 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1496 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1497 pvRTS = NULL;
1498 pvCTS = NULL;
1499 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1500 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1502 } else {
1503 // Auto Fall Back
1504 if (bRTS == true) {//RTS_need
1505 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1506 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1507 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1508 pvCTS = NULL;
1509 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1510 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1512 else { //RTS_needless
1513 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1514 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1515 pvRTS = NULL;
1516 pvCTS = NULL;
1517 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1518 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1520 } // Auto Fall Back
1522 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1524 //////////////////////////////////////////////////////////////////
1525 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1526 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
1527 dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
1528 dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
1530 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1531 dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
1532 dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
1534 else {
1535 dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[24]);
1536 dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[28]);
1538 // DO Software Michael
1539 MIC_vInit(dwMICKey0, dwMICKey1);
1540 MIC_vAppend((unsigned char *)&(psEthHeader->abyDstAddr[0]), 12);
1541 dwMIC_Priority = 0;
1542 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
1543 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1546 ///////////////////////////////////////////////////////////////////
1548 pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderLength);
1549 pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1550 pbyIVHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding);
1552 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true) && (bIsWEP256 == false)) {
1553 // Fragmentation
1554 // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
1555 cbFragmentSize = pDevice->wFragmentationThreshold;
1556 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
1557 //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
1558 uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
1559 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
1560 if (cbLastFragPayloadSize == 0) {
1561 cbLastFragPayloadSize = cbFragPayloadSize;
1562 } else {
1563 uMACfragNum++;
1565 //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
1566 cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
1568 for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx ++) {
1569 if (uFragIdx == 0) {
1570 //=========================
1571 // Start Fragmentation
1572 //=========================
1573 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start Fragmentation...\n");
1574 wFragType = FRAGCTL_STAFRAG;
1577 //Fill FIFO,RrvTime,RTS,and CTS
1578 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1579 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1580 //Fill DataHead
1581 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1582 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1583 // Generate TX MAC Header
1584 vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
1585 wFragType, uDMAIdx, uFragIdx);
1587 if (bNeedEncrypt == true) {
1588 //Fill TXKEY
1589 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1590 pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
1591 //Fill IV(ExtIV,RSNHDR)
1592 if (pDevice->bEnableHostWEP) {
1593 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1594 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1599 // 802.1H
1600 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1601 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1602 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1603 memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1605 else {
1606 memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1608 pbyType = (unsigned char *) (pbyPayloadHead + 6);
1609 memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
1610 cb802_1_H_len = 8;
1613 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1614 //---------------------------
1615 // S/W or H/W Encryption
1616 //---------------------------
1617 //Fill MICHDR
1618 //if (pDevice->bAES) {
1619 // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFragPayloadSize);
1621 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
1622 // pbyPayloadHead, (unsigned short)cbFragPayloadSize, uDMAIdx);
1626 //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
1627 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1629 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1630 //copy TxBufferHeader + MacHeader to desc
1631 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1633 // Copy the Packet into a tx Buffer
1634 memcpy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
1637 uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
1639 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1640 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start MIC: %d\n", cbFragPayloadSize);
1641 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
1645 //---------------------------
1646 // S/W Encryption
1647 //---------------------------
1648 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1649 if (bNeedEncrypt) {
1650 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (unsigned short)cbFragPayloadSize);
1651 cbReqCount += cbICVlen;
1655 ptdCurr = (PSTxDesc)pHeadTD;
1656 //--------------------
1657 //1.Set TSR1 & ReqCount in TxDescHead
1658 //2.Set FragCtl in TxBufferHead
1659 //3.Set Frame Control
1660 //4.Set Sequence Control
1661 //5.Get S/W generate FCS
1662 //--------------------
1663 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
1665 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1666 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1667 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1668 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1669 pDevice->iTDUsed[uDMAIdx]++;
1670 pHeadTD = ptdCurr->next;
1672 else if (uFragIdx == (uMACfragNum-1)) {
1673 //=========================
1674 // Last Fragmentation
1675 //=========================
1676 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last Fragmentation...\n");
1677 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1679 wFragType = FRAGCTL_ENDFRAG;
1681 //Fill FIFO,RrvTime,RTS,and CTS
1682 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1683 cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1684 //Fill DataHead
1685 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
1686 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1688 // Generate TX MAC Header
1689 vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
1690 wFragType, uDMAIdx, uFragIdx);
1692 if (bNeedEncrypt == true) {
1693 //Fill TXKEY
1694 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1695 pbyMacHdr, (unsigned short)cbLastFragPayloadSize, (unsigned char *)pMICHDR);
1697 if (pDevice->bEnableHostWEP) {
1698 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1699 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1705 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
1706 //---------------------------
1707 // S/W or H/W Encryption
1708 //---------------------------
1712 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1713 //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1715 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1717 //copy TxBufferHeader + MacHeader to desc
1718 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1720 // Copy the Packet into a tx Buffer
1721 if (bMIC2Frag == false) {
1723 memcpy((pbyBuffer + uLength),
1724 (pPacket + 14 + uTotalCopyLength),
1725 (cbLastFragPayloadSize - cbMIClen)
1727 //TODO check uTmpLen !
1728 uTmpLen = cbLastFragPayloadSize - cbMIClen;
1731 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1732 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
1733 uMICFragLen, cbLastFragPayloadSize, uTmpLen);
1735 if (bMIC2Frag == false) {
1736 if (uTmpLen != 0)
1737 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1738 pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
1739 pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
1740 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1741 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1742 } else {
1743 if (uMICFragLen >= 4) {
1744 memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
1745 (cbMIClen - uMICFragLen));
1746 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen >= 4: %X, %d\n",
1747 *(unsigned char *)((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
1748 (cbMIClen - uMICFragLen));
1750 } else {
1751 memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_L + uMICFragLen),
1752 (4 - uMICFragLen));
1753 memcpy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
1754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen < 4: %X, %d\n",
1755 *(unsigned char *)((unsigned char *)&dwSafeMIC_R + uMICFragLen - 4),
1756 (cbMIClen - uMICFragLen));
1759 for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
1760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii - 8 - 24)));
1762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1765 MIC_vUnInit();
1766 } else {
1767 ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
1771 //---------------------------
1772 // S/W Encryption
1773 //---------------------------
1774 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1775 if (bNeedEncrypt) {
1776 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbLastFragPayloadSize);
1777 cbReqCount += cbICVlen;
1781 ptdCurr = (PSTxDesc)pHeadTD;
1783 //--------------------
1784 //1.Set TSR1 & ReqCount in TxDescHead
1785 //2.Set FragCtl in TxBufferHead
1786 //3.Set Frame Control
1787 //4.Set Sequence Control
1788 //5.Get S/W generate FCS
1789 //--------------------
1792 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
1794 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1795 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1796 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1797 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1798 pDevice->iTDUsed[uDMAIdx]++;
1799 pHeadTD = ptdCurr->next;
1802 else {
1803 //=========================
1804 // Middle Fragmentation
1805 //=========================
1806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle Fragmentation...\n");
1807 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1809 wFragType = FRAGCTL_MIDFRAG;
1811 //Fill FIFO,RrvTime,RTS,and CTS
1812 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1813 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1814 //Fill DataHead
1815 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1816 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1818 // Generate TX MAC Header
1819 vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
1820 wFragType, uDMAIdx, uFragIdx);
1823 if (bNeedEncrypt == true) {
1824 //Fill TXKEY
1825 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1826 pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
1828 if (pDevice->bEnableHostWEP) {
1829 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1830 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1834 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1835 //---------------------------
1836 // S/W or H/W Encryption
1837 //---------------------------
1838 //Fill MICHDR
1839 //if (pDevice->bAES) {
1840 // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFragPayloadSize);
1842 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
1843 // pbyPayloadHead, (unsigned short)cbFragPayloadSize, uDMAIdx);
1846 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1847 //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1850 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1852 //copy TxBufferHeader + MacHeader to desc
1853 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1855 // Copy the Packet into a tx Buffer
1856 memcpy((pbyBuffer + uLength),
1857 (pPacket + 14 + uTotalCopyLength),
1858 cbFragPayloadSize
1860 uTmpLen = cbFragPayloadSize;
1862 uTotalCopyLength += uTmpLen;
1864 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1866 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1868 if (uTmpLen < cbFragPayloadSize) {
1869 bMIC2Frag = true;
1870 uMICFragLen = cbFragPayloadSize - uTmpLen;
1871 ASSERT(uMICFragLen < cbMIClen);
1873 pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
1874 pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
1875 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1876 dwSafeMIC_L = *pdwMIC_L;
1877 dwSafeMIC_R = *pdwMIC_R;
1879 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
1880 uMICFragLen, cbFragPayloadSize, uTmpLen);
1881 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MIC in Middle frag [%d]\n", uMICFragLen);
1883 for (ii = 0; ii < uMICFragLen; ii++) {
1884 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength + uTmpLen) + ii)));
1886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1890 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle frag len: %d\n", uTmpLen);
1892 for (ii = 0; ii < uTmpLen; ii++) {
1893 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
1895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1898 } else {
1899 ASSERT(uTmpLen == (cbFragPayloadSize));
1902 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1903 if (bNeedEncrypt) {
1904 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbFragPayloadSize);
1905 cbReqCount += cbICVlen;
1909 ptdCurr = (PSTxDesc)pHeadTD;
1911 //--------------------
1912 //1.Set TSR1 & ReqCount in TxDescHead
1913 //2.Set FragCtl in TxBufferHead
1914 //3.Set Frame Control
1915 //4.Set Sequence Control
1916 //5.Get S/W generate FCS
1917 //--------------------
1919 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
1921 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1922 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1923 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1924 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1925 pDevice->iTDUsed[uDMAIdx]++;
1926 pHeadTD = ptdCurr->next;
1928 } // for (uMACfragNum)
1930 else {
1931 //=========================
1932 // No Fragmentation
1933 //=========================
1934 //DBG_PRTGRP03(("No Fragmentation...\n"));
1935 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1936 wFragType = FRAGCTL_NONFRAG;
1938 //Set FragCtl in TxBufferHead
1939 psTxBufHd->wFragCtl |= (unsigned short)wFragType;
1941 //Fill FIFO,RrvTime,RTS,and CTS
1942 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1943 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1944 //Fill DataHead
1945 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1946 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1948 // Generate TX MAC Header
1949 vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
1950 wFragType, uDMAIdx, 0);
1952 if (bNeedEncrypt == true) {
1953 //Fill TXKEY
1954 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1955 pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
1957 if (pDevice->bEnableHostWEP) {
1958 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1959 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1963 // 802.1H
1964 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1965 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1966 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1967 memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1969 else {
1970 memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1972 pbyType = (unsigned char *) (pbyPayloadHead + 6);
1973 memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
1974 cb802_1_H_len = 8;
1977 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
1978 //---------------------------
1979 // S/W or H/W Encryption
1980 //---------------------------
1981 //Fill MICHDR
1982 //if (pDevice->bAES) {
1983 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
1984 // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFrameBodySize);
1987 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1988 //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
1990 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1992 //copy TxBufferHeader + MacHeader to desc
1993 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1995 // Copy the Packet into a tx Buffer
1996 memcpy((pbyBuffer + uLength),
1997 (pPacket + 14),
1998 cbFrameBodySize - cb802_1_H_len
2001 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)){
2003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
2005 for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
2006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
2008 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2011 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
2013 pdwMIC_L = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
2014 pdwMIC_R = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
2016 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2017 MIC_vUnInit();
2020 if (pDevice->bTxMICFail == true) {
2021 *pdwMIC_L = 0;
2022 *pdwMIC_R = 0;
2023 pDevice->bTxMICFail = false;
2026 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2027 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
2028 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2030 for (ii = 0; ii < 8; ii++) {
2031 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((unsigned char *)(pdwMIC_L) + ii)));
2033 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2039 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)){
2040 if (bNeedEncrypt) {
2041 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
2042 (unsigned short)(cbFrameBodySize + cbMIClen));
2043 cbReqCount += cbICVlen;
2048 ptdCurr = (PSTxDesc)pHeadTD;
2050 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
2051 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
2052 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
2053 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
2054 //Set TSR1 & ReqCount in TxDescHead
2055 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
2056 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
2058 pDevice->iTDUsed[uDMAIdx]++;
2061 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
2062 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
2065 *puMACfragNum = uMACfragNum;
2066 //DBG_PRTGRP03(("s_cbFillTxBufHead END\n"));
2067 return cbHeaderLength;
2071 void
2072 vGenerateFIFOHeader(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
2073 bool bNeedEncrypt, unsigned int cbPayloadSize, unsigned int uDMAIdx,
2074 PSTxDesc pHeadTD, PSEthernetHeader psEthHeader, unsigned char *pPacket,
2075 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum,
2076 unsigned int *pcbHeaderSize)
2078 unsigned int wTxBufSize; // FFinfo size
2079 bool bNeedACK;
2080 bool bIsAdhoc;
2081 unsigned short cbMacHdLen;
2082 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2084 wTxBufSize = sizeof(STxBufHead);
2086 memset(pTxBufHead, 0, wTxBufSize);
2087 //Set FIFOCTL_NEEDACK
2089 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2090 (pDevice->eOPMode == OP_MODE_AP)) {
2091 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0]))) {
2092 bNeedACK = false;
2093 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
2095 else {
2096 bNeedACK = true;
2097 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2099 bIsAdhoc = true;
2101 else {
2102 // MSDUs in Infra mode always need ACK
2103 bNeedACK = true;
2104 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2105 bIsAdhoc = false;
2109 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2110 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2112 //Set FIFOCTL_LHEAD
2113 if (pDevice->bLongHeader)
2114 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
2116 //Set FIFOCTL_GENINT
2118 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2121 //Set FIFOCTL_ISDMA0
2122 if (TYPE_TXDMA0 == uDMAIdx) {
2123 pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
2126 //Set FRAGCTL_MACHDCNT
2127 if (pDevice->bLongHeader) {
2128 cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
2129 } else {
2130 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2132 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
2134 //Set packet type
2135 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2138 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2139 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2141 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2142 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2144 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2145 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2147 //Set FIFOCTL_GrpAckPolicy
2148 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
2149 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2152 //Set Auto Fallback Ctl
2153 if (pDevice->wCurrentRate >= RATE_18M) {
2154 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
2155 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
2156 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
2157 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
2161 //Set FRAGCTL_WEPTYP
2162 pDevice->bAES = false;
2164 //Set FRAGCTL_WEPTYP
2165 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
2166 if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
2167 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2168 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2170 else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
2171 if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
2172 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2174 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
2175 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2180 #ifdef PLICE_DEBUG
2181 //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2183 //if (pDevice->wCurrentRate <= 3)
2185 // RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
2187 //else
2189 RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
2190 #endif
2191 //if (pDevice->wCurrentRate == 3)
2192 //pDevice->byCurPwr = 46;
2193 pTxBufHead->byTxPower = pDevice->byCurPwr;
2199 if(pDevice->bEnableHostWEP)
2200 pTxBufHead->wFragCtl &= ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
2202 *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
2203 uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
2204 pTransmitKey, uNodeIndex, puMACfragNum);
2206 return;
2214 * Description:
2215 * Translate 802.3 to 802.11 header
2217 * Parameters:
2218 * In:
2219 * pDevice - Pointer to adapter
2220 * dwTxBufferAddr - Transmit Buffer
2221 * pPacket - Packet from upper layer
2222 * cbPacketSize - Transmit Data Length
2223 * Out:
2224 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
2225 * pcbAppendPayload - size of append payload for 802.1H translation
2227 * Return Value: none
2231 void
2232 vGenerateMACHeader (
2233 PSDevice pDevice,
2234 unsigned char *pbyBufferAddr,
2235 unsigned short wDuration,
2236 PSEthernetHeader psEthHeader,
2237 bool bNeedEncrypt,
2238 unsigned short wFragType,
2239 unsigned int uDMAIdx,
2240 unsigned int uFragIdx
2243 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
2245 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
2247 if (uDMAIdx == TYPE_ATIMDMA) {
2248 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
2249 } else {
2250 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
2253 if (pDevice->eOPMode == OP_MODE_AP) {
2254 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
2255 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
2256 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
2257 pMACHeader->wFrameCtl |= FC_FROMDS;
2259 else {
2260 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2261 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
2262 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
2263 memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
2265 else {
2266 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
2267 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
2268 memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
2269 pMACHeader->wFrameCtl |= FC_TODS;
2273 if (bNeedEncrypt)
2274 pMACHeader->wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_ISWEP(1));
2276 pMACHeader->wDurationID = cpu_to_le16(wDuration);
2278 if (pDevice->bLongHeader) {
2279 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
2280 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
2281 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
2283 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2285 //Set FragNumber in Sequence Control
2286 pMACHeader->wSeqCtl |= cpu_to_le16((unsigned short)uFragIdx);
2288 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
2289 pDevice->wSeqCounter++;
2290 if (pDevice->wSeqCounter > 0x0fff)
2291 pDevice->wSeqCounter = 0;
2294 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
2295 pMACHeader->wFrameCtl |= FC_MOREFRAG;
2304 CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2306 PSTxDesc pFrstTD;
2307 unsigned char byPktType;
2308 unsigned char *pbyTxBufferAddr;
2309 void * pvRTS;
2310 PSCTS pCTS;
2311 void * pvTxDataHd;
2312 unsigned int uDuration;
2313 unsigned int cbReqCount;
2314 PS802_11Header pMACHeader;
2315 unsigned int cbHeaderSize;
2316 unsigned int cbFrameBodySize;
2317 bool bNeedACK;
2318 bool bIsPSPOLL = false;
2319 PSTxBufHead pTxBufHead;
2320 unsigned int cbFrameSize;
2321 unsigned int cbIVlen = 0;
2322 unsigned int cbICVlen = 0;
2323 unsigned int cbMIClen = 0;
2324 unsigned int cbFCSlen = 4;
2325 unsigned int uPadding = 0;
2326 unsigned short wTxBufSize;
2327 unsigned int cbMacHdLen;
2328 SEthernetHeader sEthHeader;
2329 void * pvRrvTime;
2330 void * pMICHDR;
2331 PSMgmtObject pMgmt = pDevice->pMgmt;
2332 unsigned short wCurrentRate = RATE_1M;
2335 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2336 return CMD_STATUS_RESOURCES;
2339 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2340 pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
2341 cbFrameBodySize = pPacket->cbPayloadLen;
2342 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2343 wTxBufSize = sizeof(STxBufHead);
2344 memset(pTxBufHead, 0, wTxBufSize);
2346 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2347 wCurrentRate = RATE_6M;
2348 byPktType = PK_TYPE_11A;
2349 } else {
2350 wCurrentRate = RATE_1M;
2351 byPktType = PK_TYPE_11B;
2354 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2355 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2356 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2357 // to set power here.
2358 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2360 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2361 } else {
2362 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2364 pTxBufHead->byTxPower = pDevice->byCurPwr;
2365 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2366 if (pDevice->byFOETuning) {
2367 if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2368 wCurrentRate = RATE_24M;
2369 byPktType = PK_TYPE_11GA;
2373 //Set packet type
2374 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2375 pTxBufHead->wFIFOCtl = 0;
2377 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2378 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2380 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2381 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2383 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2384 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2387 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2388 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2391 if (is_multicast_ether_addr(&(pPacket->p80211Header->sA3.abyAddr1[0])))
2392 bNeedACK = false;
2393 else {
2394 bNeedACK = true;
2395 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2398 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2399 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2401 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2402 //Set Preamble type always long
2403 //pDevice->byPreambleType = PREAMBLE_LONG;
2404 // probe-response don't retry
2405 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2406 // bNeedACK = false;
2407 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2411 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2413 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2414 bIsPSPOLL = true;
2415 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2416 } else {
2417 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2420 //Set FRAGCTL_MACHDCNT
2421 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
2423 // Notes:
2424 // Although spec says MMPDU can be fragmented; In most case,
2425 // no one will send a MMPDU under fragmentation. With RTS may occur.
2426 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2428 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2429 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2430 cbIVlen = 4;
2431 cbICVlen = 4;
2432 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2434 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2435 cbIVlen = 8;//IV+ExtIV
2436 cbMIClen = 8;
2437 cbICVlen = 4;
2438 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2439 //We need to get seed here for filling TxKey entry.
2440 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2441 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2443 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2444 cbIVlen = 8;//RSN Header
2445 cbICVlen = 8;//MIC
2446 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2447 pDevice->bAES = true;
2449 //MAC Header should be padding 0 to DW alignment.
2450 uPadding = 4 - (cbMacHdLen%4);
2451 uPadding %= 4;
2454 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2456 //Set FIFOCTL_GrpAckPolicy
2457 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
2458 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2460 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2462 //Set RrvTime/RTS/CTS Buffer
2463 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2465 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2466 pMICHDR = NULL;
2467 pvRTS = NULL;
2468 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2469 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2470 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2472 else { // 802.11a/b packet
2473 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2474 pMICHDR = NULL;
2475 pvRTS = NULL;
2476 pCTS = NULL;
2477 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2478 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2481 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
2483 memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
2484 memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
2485 //=========================
2486 // No Fragmentation
2487 //=========================
2488 pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
2491 //Fill FIFO,RrvTime,RTS,and CTS
2492 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2493 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2495 //Fill DataHead
2496 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2497 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2499 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2501 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2503 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2504 unsigned char *pbyIVHead;
2505 unsigned char *pbyPayloadHead;
2506 unsigned char *pbyBSSID;
2507 PSKeyItem pTransmitKey = NULL;
2509 pbyIVHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2510 pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2512 //Fill TXKEY
2513 //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet.
2514 //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
2516 //Fill IV(ExtIV,RSNHDR)
2517 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
2518 //---------------------------
2519 // S/W or H/W Encryption
2520 //---------------------------
2521 //Fill MICHDR
2522 //if (pDevice->bAES) {
2523 // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize);
2525 do {
2526 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2527 (pDevice->bLinkPass == true)) {
2528 pbyBSSID = pDevice->abyBSSID;
2529 // get pairwise key
2530 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2531 // get group key
2532 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2534 break;
2536 } else {
2537 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2538 break;
2541 // get group key
2542 pbyBSSID = pDevice->abyBroadcastAddr;
2543 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2544 pTransmitKey = NULL;
2545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2546 } else {
2547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2549 } while(false);
2550 //Fill TXKEY
2551 s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2552 (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize, NULL);
2554 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2555 memcpy(pbyPayloadHead, ((unsigned char *)(pPacket->p80211Header) + cbMacHdLen),
2556 cbFrameBodySize);
2558 else {
2559 // Copy the Packet into a tx Buffer
2560 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2563 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2564 pDevice->wSeqCounter++ ;
2565 if (pDevice->wSeqCounter > 0x0fff)
2566 pDevice->wSeqCounter = 0;
2568 if (bIsPSPOLL) {
2569 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2570 // of FIFO control header.
2571 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2572 // in the same place of other packet's Duration-field).
2573 // And it will cause Cisco-AP to issue Disassociation-packet
2574 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2575 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2576 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2577 } else {
2578 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2583 // first TD is the only TD
2584 //Set TSR1 & ReqCount in TxDescHead
2585 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
2586 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
2587 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
2588 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2589 pFrstTD->pTDInfo->byFlags = 0;
2591 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2592 // Disable PS
2593 MACbPSWakeup(pDevice->PortOffset);
2595 pDevice->bPWBitOn = false;
2597 wmb();
2598 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2599 wmb();
2601 pDevice->iTDUsed[TYPE_TXDMA0]++;
2603 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
2604 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
2607 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
2608 #ifdef PLICE_DEBUG
2609 //printk("SCAN:CurrentRate is %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
2610 #endif
2612 #ifdef TxInSleep
2613 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2614 #endif
2616 // Poll Transmit the adapter
2617 MACvTransmit0(pDevice->PortOffset);
2619 return CMD_STATUS_PENDING;
2624 CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2626 unsigned char byPktType;
2627 unsigned char *pbyBuffer = (unsigned char *)pDevice->tx_beacon_bufs;
2628 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2629 unsigned int cbHeaderSize = 0;
2630 unsigned short wTxBufSize = sizeof(STxShortBufHead);
2631 PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
2632 PSTxDataHead_ab pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
2633 PS802_11Header pMACHeader;
2634 unsigned short wCurrentRate;
2635 unsigned short wLen = 0x0000;
2638 memset(pTxBufHead, 0, wTxBufSize);
2640 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2641 wCurrentRate = RATE_6M;
2642 byPktType = PK_TYPE_11A;
2643 } else {
2644 wCurrentRate = RATE_2M;
2645 byPktType = PK_TYPE_11B;
2648 //Set Preamble type always long
2649 pDevice->byPreambleType = PREAMBLE_LONG;
2651 //Set FIFOCTL_GENINT
2653 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2656 //Set packet type & Get Duration
2657 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2658 pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktType,
2659 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
2661 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2662 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2663 pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktType,
2664 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
2667 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktType,
2668 (unsigned short *)&(wLen), (unsigned char *)&(pTxDataHead->byServiceField), (unsigned char *)&(pTxDataHead->bySignalField)
2670 pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
2671 //Get TimeStampOff
2672 pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
2673 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2675 //Generate Beacon Header
2676 pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
2677 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2679 pMACHeader->wDurationID = 0;
2680 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2681 pDevice->wSeqCounter++ ;
2682 if (pDevice->wSeqCounter > 0x0fff)
2683 pDevice->wSeqCounter = 0;
2685 // Set Beacon buffer length
2686 pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
2688 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
2690 MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
2691 // Set auto Transmit on
2692 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2693 // Poll Transmit the adapter
2694 MACvTransmitBCN(pDevice->PortOffset);
2696 return CMD_STATUS_PENDING;
2701 unsigned int
2702 cbGetFragCount (
2703 PSDevice pDevice,
2704 PSKeyItem pTransmitKey,
2705 unsigned int cbFrameBodySize,
2706 PSEthernetHeader psEthHeader
2709 unsigned int cbMACHdLen;
2710 unsigned int cbFrameSize;
2711 unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
2712 unsigned int cbFragPayloadSize;
2713 unsigned int cbLastFragPayloadSize;
2714 unsigned int cbIVlen = 0;
2715 unsigned int cbICVlen = 0;
2716 unsigned int cbMIClen = 0;
2717 unsigned int cbFCSlen = 4;
2718 unsigned int uMACfragNum = 1;
2719 bool bNeedACK;
2723 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2724 (pDevice->eOPMode == OP_MODE_AP)) {
2725 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
2726 bNeedACK = false;
2727 else
2728 bNeedACK = true;
2730 else {
2731 // MSDUs in Infra mode always need ACK
2732 bNeedACK = true;
2735 if (pDevice->bLongHeader)
2736 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
2737 else
2738 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
2741 if (pDevice->bEncryptionEnable == true) {
2743 if (pTransmitKey == NULL) {
2744 if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
2745 (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
2746 cbIVlen = 4;
2747 cbICVlen = 4;
2748 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2749 cbIVlen = 8;//IV+ExtIV
2750 cbMIClen = 8;
2751 cbICVlen = 4;
2752 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2753 cbIVlen = 8;//RSN Header
2754 cbICVlen = 8;//MIC
2756 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
2757 cbIVlen = 4;
2758 cbICVlen = 4;
2759 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2760 cbIVlen = 8;//IV+ExtIV
2761 cbMIClen = 8;
2762 cbICVlen = 4;
2763 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
2764 cbIVlen = 8;//RSN Header
2765 cbICVlen = 8;//MIC
2769 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
2771 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true)) {
2772 // Fragmentation
2773 cbFragmentSize = pDevice->wFragmentationThreshold;
2774 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
2775 uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
2776 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
2777 if (cbLastFragPayloadSize == 0) {
2778 cbLastFragPayloadSize = cbFragPayloadSize;
2779 } else {
2780 uMACfragNum++;
2783 return uMACfragNum;
2787 void
2788 vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, unsigned char *pbMPDU, unsigned int cbMPDULen) {
2790 PSTxDesc pFrstTD;
2791 unsigned char byPktType;
2792 unsigned char *pbyTxBufferAddr;
2793 void * pvRTS;
2794 void * pvCTS;
2795 void * pvTxDataHd;
2796 unsigned int uDuration;
2797 unsigned int cbReqCount;
2798 PS802_11Header pMACHeader;
2799 unsigned int cbHeaderSize;
2800 unsigned int cbFrameBodySize;
2801 bool bNeedACK;
2802 bool bIsPSPOLL = false;
2803 PSTxBufHead pTxBufHead;
2804 unsigned int cbFrameSize;
2805 unsigned int cbIVlen = 0;
2806 unsigned int cbICVlen = 0;
2807 unsigned int cbMIClen = 0;
2808 unsigned int cbFCSlen = 4;
2809 unsigned int uPadding = 0;
2810 unsigned int cbMICHDR = 0;
2811 unsigned int uLength = 0;
2812 unsigned long dwMICKey0, dwMICKey1;
2813 unsigned long dwMIC_Priority;
2814 unsigned long *pdwMIC_L;
2815 unsigned long *pdwMIC_R;
2816 unsigned short wTxBufSize;
2817 unsigned int cbMacHdLen;
2818 SEthernetHeader sEthHeader;
2819 void * pvRrvTime;
2820 void * pMICHDR;
2821 PSMgmtObject pMgmt = pDevice->pMgmt;
2822 unsigned short wCurrentRate = RATE_1M;
2823 PUWLAN_80211HDR p80211Header;
2824 unsigned int uNodeIndex = 0;
2825 bool bNodeExist = false;
2826 SKeyItem STempKey;
2827 PSKeyItem pTransmitKey = NULL;
2828 unsigned char *pbyIVHead;
2829 unsigned char *pbyPayloadHead;
2830 unsigned char *pbyMacHdr;
2832 unsigned int cbExtSuppRate = 0;
2833 // PWLAN_IE pItem;
2836 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2838 if(cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
2839 cbFrameBodySize = 0;
2841 else {
2842 cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
2844 p80211Header = (PUWLAN_80211HDR)pbMPDU;
2847 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2848 pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
2849 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2850 wTxBufSize = sizeof(STxBufHead);
2851 memset(pTxBufHead, 0, wTxBufSize);
2853 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2854 wCurrentRate = RATE_6M;
2855 byPktType = PK_TYPE_11A;
2856 } else {
2857 wCurrentRate = RATE_1M;
2858 byPktType = PK_TYPE_11B;
2861 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2862 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2863 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2864 // to set power here.
2865 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2866 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2867 } else {
2868 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2870 pTxBufHead->byTxPower = pDevice->byCurPwr;
2872 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2873 if (pDevice->byFOETuning) {
2874 if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2875 wCurrentRate = RATE_24M;
2876 byPktType = PK_TYPE_11GA;
2880 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2882 //Set packet type
2883 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2884 pTxBufHead->wFIFOCtl = 0;
2886 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2887 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2889 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2890 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2892 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2893 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2896 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2897 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2900 if (is_multicast_ether_addr(&(p80211Header->sA3.abyAddr1[0]))) {
2901 bNeedACK = false;
2902 if (pDevice->bEnableHostWEP) {
2903 uNodeIndex = 0;
2904 bNodeExist = true;
2907 else {
2908 if (pDevice->bEnableHostWEP) {
2909 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (unsigned char *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2910 bNodeExist = true;
2912 bNeedACK = true;
2913 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2916 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2917 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2919 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2920 //Set Preamble type always long
2921 //pDevice->byPreambleType = PREAMBLE_LONG;
2923 // probe-response don't retry
2924 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2925 // bNeedACK = false;
2926 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2930 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2932 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2933 bIsPSPOLL = true;
2934 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2935 } else {
2936 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2939 // hostapd deamon ext support rate patch
2940 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2942 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2943 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2946 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2947 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2950 if (cbExtSuppRate >0) {
2951 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2956 //Set FRAGCTL_MACHDCNT
2957 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10);
2959 // Notes:
2960 // Although spec says MMPDU can be fragmented; In most case,
2961 // no one will send a MMPDU under fragmentation. With RTS may occur.
2962 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2965 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2966 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2967 cbIVlen = 4;
2968 cbICVlen = 4;
2969 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2971 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2972 cbIVlen = 8;//IV+ExtIV
2973 cbMIClen = 8;
2974 cbICVlen = 4;
2975 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2976 //We need to get seed here for filling TxKey entry.
2977 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2978 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2980 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2981 cbIVlen = 8;//RSN Header
2982 cbICVlen = 8;//MIC
2983 cbMICHDR = sizeof(SMICHDRHead);
2984 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2985 pDevice->bAES = true;
2987 //MAC Header should be padding 0 to DW alignment.
2988 uPadding = 4 - (cbMacHdLen%4);
2989 uPadding %= 4;
2992 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2994 //Set FIFOCTL_GrpAckPolicy
2995 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
2996 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2998 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
3001 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
3003 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
3004 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
3005 pvRTS = NULL;
3006 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
3007 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
3008 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
3011 else {//802.11a/b packet
3013 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
3014 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
3015 pvRTS = NULL;
3016 pvCTS = NULL;
3017 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
3018 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
3022 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
3023 memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
3024 memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
3025 //=========================
3026 // No Fragmentation
3027 //=========================
3028 pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
3031 //Fill FIFO,RrvTime,RTS,and CTS
3032 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
3033 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
3035 //Fill DataHead
3036 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
3037 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
3039 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
3041 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
3043 pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize);
3044 pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
3045 pbyIVHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding);
3047 // Copy the Packet into a tx Buffer
3048 memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
3050 // version set to 0, patch for hostapd deamon
3051 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
3052 memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
3054 // replace support rate, patch for hostapd deamon( only support 11M)
3055 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
3056 if (cbExtSuppRate != 0) {
3057 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
3058 memcpy((pbyPayloadHead + cbFrameBodySize),
3059 pMgmt->abyCurrSuppRates,
3060 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
3062 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
3063 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
3064 pMgmt->abyCurrExtSuppRates,
3065 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3070 // Set wep
3071 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3073 if (pDevice->bEnableHostWEP) {
3074 pTransmitKey = &STempKey;
3075 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3076 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3077 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3078 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3079 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3080 memcpy(pTransmitKey->abyKey,
3081 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3082 pTransmitKey->uKeyLength
3086 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
3088 dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
3089 dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
3091 // DO Software Michael
3092 MIC_vInit(dwMICKey0, dwMICKey1);
3093 MIC_vAppend((unsigned char *)&(sEthHeader.abyDstAddr[0]), 12);
3094 dwMIC_Priority = 0;
3095 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
3096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
3098 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
3100 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
3102 pdwMIC_L = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
3103 pdwMIC_R = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
3105 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
3106 MIC_vUnInit();
3108 if (pDevice->bTxMICFail == true) {
3109 *pdwMIC_L = 0;
3110 *pdwMIC_R = 0;
3111 pDevice->bTxMICFail = false;
3114 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
3115 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
3116 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
3121 s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
3122 pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
3124 if (pDevice->bEnableHostWEP) {
3125 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
3126 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
3129 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
3130 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (unsigned short)(cbFrameBodySize + cbMIClen));
3134 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
3135 pDevice->wSeqCounter++ ;
3136 if (pDevice->wSeqCounter > 0x0fff)
3137 pDevice->wSeqCounter = 0;
3140 if (bIsPSPOLL) {
3141 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
3142 // of FIFO control header.
3143 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
3144 // in the same place of other packet's Duration-field).
3145 // And it will cause Cisco-AP to issue Disassociation-packet
3146 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
3147 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
3148 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
3149 } else {
3150 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
3155 // first TD is the only TD
3156 //Set TSR1 & ReqCount in TxDescHead
3157 pFrstTD->pTDInfo->skb = skb;
3158 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
3159 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
3160 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
3161 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
3162 pFrstTD->pTDInfo->byFlags = 0;
3163 pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
3165 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
3166 // Disable PS
3167 MACbPSWakeup(pDevice->PortOffset);
3169 pDevice->bPWBitOn = false;
3171 wmb();
3172 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
3173 wmb();
3175 pDevice->iTDUsed[TYPE_TXDMA0]++;
3177 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
3178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
3181 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
3183 // Poll Transmit the adapter
3184 MACvTransmit0(pDevice->PortOffset);
3186 return;