Save sram context after changing MPU, DSP or core clocks
[linux-ginger.git] / drivers / staging / vt6655 / rxtx.c
blobed3070edcac13eee2944e4d27138b0cdbe6c3ec1
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 requried parameter.
29 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Caculate fragement number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts requried duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragement ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
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 WORD wTimeStampOff[2][MAX_RATE] = {
84 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
85 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
88 const WORD wFB_Opt0[2][5] = {
89 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
90 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
92 const WORD wFB_Opt1[2][5] = {
93 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
94 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
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 IN PSDevice pDevice,
121 IN PBYTE pbyBuf,
122 IN PBYTE pbyIVHead,
123 IN PSKeyItem pTransmitKey,
124 IN PBYTE pbyHdrBuf,
125 IN WORD wPayloadLen,
126 OUT PBYTE pMICHDR
131 static
132 VOID
133 s_vFillRTSHead(
134 IN PSDevice pDevice,
135 IN BYTE byPktType,
136 IN PVOID pvRTS,
137 IN UINT cbFrameLength,
138 IN BOOL bNeedAck,
139 IN BOOL bDisCRC,
140 IN PSEthernetHeader psEthHeader,
141 IN WORD wCurrentRate,
142 IN BYTE byFBOption
145 static
146 VOID
147 s_vGenerateTxParameter(
148 IN PSDevice pDevice,
149 IN BYTE byPktType,
150 IN PVOID pTxBufHead,
151 IN PVOID pvRrvTime,
152 IN PVOID pvRTS,
153 IN PVOID pvCTS,
154 IN UINT cbFrameSize,
155 IN BOOL bNeedACK,
156 IN UINT uDMAIdx,
157 IN PSEthernetHeader psEthHeader,
158 IN WORD wCurrentRate
163 static void s_vFillFragParameter(
164 IN PSDevice pDevice,
165 IN PBYTE pbyBuffer,
166 IN UINT uTxType,
167 IN PVOID pvtdCurr,
168 IN WORD wFragType,
169 IN UINT cbReqCount
173 static
174 UINT
175 s_cbFillTxBufHead (
176 IN PSDevice pDevice,
177 IN BYTE byPktType,
178 IN PBYTE pbyTxBufferAddr,
179 IN UINT cbFrameBodySize,
180 IN UINT uDMAIdx,
181 IN PSTxDesc pHeadTD,
182 IN PSEthernetHeader psEthHeader,
183 IN PBYTE pPacket,
184 IN BOOL bNeedEncrypt,
185 IN PSKeyItem pTransmitKey,
186 IN UINT uNodeIndex,
187 OUT PUINT puMACfragNum
191 static
192 UINT
193 s_uFillDataHead (
194 IN PSDevice pDevice,
195 IN BYTE byPktType,
196 IN PVOID pTxDataHead,
197 IN UINT cbFrameLength,
198 IN UINT uDMAIdx,
199 IN BOOL bNeedAck,
200 IN UINT uFragIdx,
201 IN UINT cbLastFragmentSize,
202 IN UINT uMACfragNum,
203 IN BYTE byFBOption,
204 IN WORD wCurrentRate
208 /*--------------------- Export Variables --------------------------*/
212 static
213 VOID
214 s_vFillTxKey (
215 IN PSDevice pDevice,
216 IN PBYTE pbyBuf,
217 IN PBYTE pbyIVHead,
218 IN PSKeyItem pTransmitKey,
219 IN PBYTE pbyHdrBuf,
220 IN WORD wPayloadLen,
221 OUT PBYTE pMICHDR
224 PDWORD pdwIV = (PDWORD) pbyIVHead;
225 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
226 WORD wValue;
227 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
228 DWORD dwRevIVCounter;
229 BYTE byKeyIndex = 0;
233 //Fill TXKEY
234 if (pTransmitKey == NULL)
235 return;
237 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
238 *pdwIV = pDevice->dwIVCounter;
239 byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
241 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
242 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
243 memcpy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
244 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
245 } else {
246 memcpy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
247 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
248 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
249 memcpy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
250 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
252 memcpy(pDevice->abyPRNG, pbyBuf, 16);
254 // Append IV after Mac Header
255 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
256 *pdwIV |= (byKeyIndex << 30);
257 *pdwIV = cpu_to_le32(*pdwIV);
258 pDevice->dwIVCounter++;
259 if (pDevice->dwIVCounter > WEP_IV_MASK) {
260 pDevice->dwIVCounter = 0;
262 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
263 pTransmitKey->wTSC15_0++;
264 if (pTransmitKey->wTSC15_0 == 0) {
265 pTransmitKey->dwTSC47_16++;
267 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
268 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
269 memcpy(pbyBuf, pDevice->abyPRNG, 16);
270 // Make IV
271 memcpy(pdwIV, pDevice->abyPRNG, 3);
273 *(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
274 // Append IV&ExtIV after Mac Header
275 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
276 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
278 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
279 pTransmitKey->wTSC15_0++;
280 if (pTransmitKey->wTSC15_0 == 0) {
281 pTransmitKey->dwTSC47_16++;
283 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
285 // Make IV
286 *pdwIV = 0;
287 *(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
288 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
289 //Append IV&ExtIV after Mac Header
290 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
292 //Fill MICHDR0
293 *pMICHDR = 0x59;
294 *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
295 memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
296 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
297 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
298 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
299 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
300 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
301 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
302 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
303 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
305 //Fill MICHDR1
306 *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
307 if (pDevice->bLongHeader) {
308 *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
309 } else {
310 *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
312 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
313 memcpy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
314 memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
315 memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
317 //Fill MICHDR2
318 memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
319 wValue = pMACHeader->wSeqCtl;
320 wValue &= 0x000F;
321 wValue = cpu_to_le16(wValue);
322 memcpy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
323 if (pDevice->bLongHeader) {
324 memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
330 static
331 VOID
332 s_vSWencryption (
333 IN PSDevice pDevice,
334 IN PSKeyItem pTransmitKey,
335 IN PBYTE pbyPayloadHead,
336 IN WORD wPayloadSize
339 UINT cbICVlen = 4;
340 DWORD dwICV = 0xFFFFFFFFL;
341 PDWORD pdwICV;
343 if (pTransmitKey == NULL)
344 return;
346 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
347 //=======================================================================
348 // Append ICV after payload
349 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
350 pdwICV = (PDWORD)(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, pTransmitKey->uKeyLength + 3);
355 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
356 //=======================================================================
357 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
358 //=======================================================================
359 //Append ICV after payload
360 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
361 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
362 // finally, we must invert dwCRC to get the correct answer
363 *pdwICV = cpu_to_le32(~dwICV);
364 // RC4 encryption
365 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
366 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
367 //=======================================================================
374 /*byPktType : PK_TYPE_11A 0
375 PK_TYPE_11B 1
376 PK_TYPE_11GB 2
377 PK_TYPE_11GA 3
379 static
380 UINT
381 s_uGetTxRsvTime (
382 IN PSDevice pDevice,
383 IN BYTE byPktType,
384 IN UINT cbFrameLength,
385 IN WORD wRate,
386 IN BOOL bNeedAck
389 UINT uDataTime, uAckTime;
391 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
392 #ifdef PLICE_DEBUG
393 //printk("s_uGetTxRsvTime is %d\n",uDataTime);
394 #endif
395 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
396 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopCCKBasicRate);
397 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
398 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopOFDMBasicRate);
401 if (bNeedAck) {
402 return (uDataTime + pDevice->uSIFS + uAckTime);
404 else {
405 return uDataTime;
409 //byFreqType: 0=>5GHZ 1=>2.4GHZ
410 static
411 UINT
412 s_uGetRTSCTSRsvTime (
413 IN PSDevice pDevice,
414 IN BYTE byRTSRsvType,
415 IN BYTE byPktType,
416 IN UINT cbFrameLength,
417 IN WORD wCurrentRate
420 UINT uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
422 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
425 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
426 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
427 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
428 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
430 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
431 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
432 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
433 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
435 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
436 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
437 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
439 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
440 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
441 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
442 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
443 return uRrvTime;
446 //RTSRrvTime
447 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
448 return uRrvTime;
451 //byFreqType 0: 5GHz, 1:2.4Ghz
452 static
453 UINT
454 s_uGetDataDuration (
455 IN PSDevice pDevice,
456 IN BYTE byDurType,
457 IN UINT cbFrameLength,
458 IN BYTE byPktType,
459 IN WORD wRate,
460 IN BOOL bNeedAck,
461 IN UINT uFragIdx,
462 IN UINT cbLastFragmentSize,
463 IN UINT uMACfragNum,
464 IN BYTE byFBOption
467 BOOL bLastFrag = 0;
468 UINT uAckTime =0, uNextPktTime = 0;
472 if (uFragIdx == (uMACfragNum-1)) {
473 bLastFrag = 1;
477 switch (byDurType) {
479 case DATADUR_B: //DATADUR_B
480 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
481 if (bNeedAck) {
482 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
483 return (pDevice->uSIFS + uAckTime);
484 } else {
485 return 0;
488 else {//First Frag or Mid Frag
489 if (uFragIdx == (uMACfragNum-2)) {
490 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
491 } else {
492 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
494 if (bNeedAck) {
495 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
496 return (pDevice->uSIFS + uAckTime + uNextPktTime);
497 } else {
498 return (pDevice->uSIFS + uNextPktTime);
501 break;
503 case DATADUR_A: //DATADUR_A
504 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
505 if(bNeedAck){
506 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
507 return (pDevice->uSIFS + uAckTime);
508 } else {
509 return 0;
512 else {//First Frag or Mid Frag
513 if(uFragIdx == (uMACfragNum-2)){
514 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
515 } else {
516 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
518 if(bNeedAck){
519 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
520 return (pDevice->uSIFS + uAckTime + uNextPktTime);
521 } else {
522 return (pDevice->uSIFS + uNextPktTime);
525 break;
527 case DATADUR_A_F0: //DATADUR_A_F0
528 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
529 if(bNeedAck){
530 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
531 return (pDevice->uSIFS + uAckTime);
532 } else {
533 return 0;
536 else { //First Frag or Mid Frag
537 if (byFBOption == AUTO_FB_0) {
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_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
545 } else {
546 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
548 } else { // (byFBOption == AUTO_FB_1)
549 if (wRate < RATE_18M)
550 wRate = RATE_18M;
551 else if (wRate > RATE_54M)
552 wRate = RATE_54M;
554 if(uFragIdx == (uMACfragNum-2)){
555 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
556 } else {
557 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
561 if(bNeedAck){
562 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
563 return (pDevice->uSIFS + uAckTime + uNextPktTime);
564 } else {
565 return (pDevice->uSIFS + uNextPktTime);
568 break;
570 case DATADUR_A_F1: //DATADUR_A_F1
571 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
572 if(bNeedAck){
573 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
574 return (pDevice->uSIFS + uAckTime);
575 } else {
576 return 0;
579 else { //First Frag or Mid Frag
580 if (byFBOption == AUTO_FB_0) {
581 if (wRate < RATE_18M)
582 wRate = RATE_18M;
583 else if (wRate > RATE_54M)
584 wRate = RATE_54M;
586 if(uFragIdx == (uMACfragNum-2)){
587 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
588 } else {
589 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
592 } else { // (byFBOption == AUTO_FB_1)
593 if (wRate < RATE_18M)
594 wRate = RATE_18M;
595 else if (wRate > RATE_54M)
596 wRate = RATE_54M;
598 if(uFragIdx == (uMACfragNum-2)){
599 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
600 } else {
601 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
604 if(bNeedAck){
605 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
606 return (pDevice->uSIFS + uAckTime + uNextPktTime);
607 } else {
608 return (pDevice->uSIFS + uNextPktTime);
611 break;
613 default:
614 break;
617 ASSERT(FALSE);
618 return 0;
622 //byFreqType: 0=>5GHZ 1=>2.4GHZ
623 static
624 UINT
625 s_uGetRTSCTSDuration (
626 IN PSDevice pDevice,
627 IN BYTE byDurType,
628 IN UINT cbFrameLength,
629 IN BYTE byPktType,
630 IN WORD wRate,
631 IN BOOL bNeedAck,
632 IN BYTE byFBOption
635 UINT uCTSTime = 0, uDurTime = 0;
638 switch (byDurType) {
640 case RTSDUR_BB: //RTSDuration_bb
641 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
642 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
643 break;
645 case RTSDUR_BA: //RTSDuration_ba
646 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
647 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
648 break;
650 case RTSDUR_AA: //RTSDuration_aa
651 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
652 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
653 break;
655 case CTSDUR_BA: //CTSDuration_ba
656 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
657 break;
659 case RTSDUR_BA_F0: //RTSDuration_ba_f0
660 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
661 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
662 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
663 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
664 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
666 break;
668 case RTSDUR_AA_F0: //RTSDuration_aa_f0
669 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
670 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
671 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
672 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
673 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
675 break;
677 case RTSDUR_BA_F1: //RTSDuration_ba_f1
678 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
679 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
680 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
681 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
682 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
684 break;
686 case RTSDUR_AA_F1: //RTSDuration_aa_f1
687 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
688 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
689 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
690 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
691 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
693 break;
695 case CTSDUR_BA_F0: //CTSDuration_ba_f0
696 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
697 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
698 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
699 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
701 break;
703 case CTSDUR_BA_F1: //CTSDuration_ba_f1
704 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
705 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
706 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
707 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
709 break;
711 default:
712 break;
715 return uDurTime;
721 static
722 UINT
723 s_uFillDataHead (
724 IN PSDevice pDevice,
725 IN BYTE byPktType,
726 IN PVOID pTxDataHead,
727 IN UINT cbFrameLength,
728 IN UINT uDMAIdx,
729 IN BOOL bNeedAck,
730 IN UINT uFragIdx,
731 IN UINT cbLastFragmentSize,
732 IN UINT uMACfragNum,
733 IN BYTE byFBOption,
734 IN WORD wCurrentRate
737 WORD wLen = 0x0000;
739 if (pTxDataHead == NULL) {
740 return 0;
743 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
744 if (byFBOption == AUTO_FB_NONE) {
745 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
746 //Get SignalField,ServiceField,Length
747 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
748 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
750 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
751 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
752 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
754 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
755 //Get Duration and TimeStamp
756 pBuf->wDuration_a = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
757 byPktType, wCurrentRate, bNeedAck, uFragIdx,
758 cbLastFragmentSize, uMACfragNum,
759 byFBOption)); //1: 2.4GHz
760 pBuf->wDuration_b = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
761 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
762 bNeedAck, uFragIdx, cbLastFragmentSize,
763 uMACfragNum, byFBOption)); //1: 2.4
765 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
766 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
768 return (pBuf->wDuration_a);
769 } else {
770 // Auto Fallback
771 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
772 //Get SignalField,ServiceField,Length
773 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
774 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
776 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
777 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
778 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
780 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
781 //Get Duration and TimeStamp
782 pBuf->wDuration_a = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
783 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
784 pBuf->wDuration_b = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
785 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
786 pBuf->wDuration_a_f0 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
787 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
788 pBuf->wDuration_a_f1 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
789 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
791 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
792 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
794 return (pBuf->wDuration_a);
795 } //if (byFBOption == AUTO_FB_NONE)
797 else if (byPktType == PK_TYPE_11A) {
798 if ((byFBOption != AUTO_FB_NONE)) {
799 // Auto Fallback
800 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
801 //Get SignalField,ServiceField,Length
802 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
803 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
805 pBuf->wTransmitLength = cpu_to_le16(wLen);
806 //Get Duration and TimeStampOff
808 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
809 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
810 pBuf->wDuration_f0 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
811 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
812 pBuf->wDuration_f1 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
813 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
814 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
815 return (pBuf->wDuration);
816 } else {
817 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
818 //Get SignalField,ServiceField,Length
819 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
820 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
822 pBuf->wTransmitLength = cpu_to_le16(wLen);
823 //Get Duration and TimeStampOff
825 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
826 wCurrentRate, bNeedAck, uFragIdx,
827 cbLastFragmentSize, uMACfragNum,
828 byFBOption));
830 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
831 return (pBuf->wDuration);
834 else {
835 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
836 //Get SignalField,ServiceField,Length
837 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
838 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
840 pBuf->wTransmitLength = cpu_to_le16(wLen);
841 //Get Duration and TimeStampOff
842 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
843 wCurrentRate, bNeedAck, uFragIdx,
844 cbLastFragmentSize, uMACfragNum,
845 byFBOption));
846 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
847 return (pBuf->wDuration);
849 return 0;
853 static
854 VOID
855 s_vFillRTSHead (
856 IN PSDevice pDevice,
857 IN BYTE byPktType,
858 IN PVOID pvRTS,
859 IN UINT cbFrameLength,
860 IN BOOL bNeedAck,
861 IN BOOL bDisCRC,
862 IN PSEthernetHeader psEthHeader,
863 IN WORD wCurrentRate,
864 IN BYTE byFBOption
867 UINT uRTSFrameLen = 20;
868 WORD wLen = 0x0000;
870 if (pvRTS == NULL)
871 return;
873 if (bDisCRC) {
874 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
875 // in this case we need to decrease its length by 4.
876 uRTSFrameLen -= 4;
879 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
880 // Otherwise, we need to modified codes for them.
881 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
882 if (byFBOption == AUTO_FB_NONE) {
883 PSRTS_g pBuf = (PSRTS_g)pvRTS;
884 //Get SignalField,ServiceField,Length
885 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
886 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
888 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
889 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
890 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
892 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
893 //Get Duration
894 pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
895 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
896 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
898 pBuf->Data.wDurationID = pBuf->wDuration_aa;
899 //Get RTS Frame body
900 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
901 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
902 (pDevice->eOPMode == OP_MODE_AP)) {
903 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
905 else {
906 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
908 if (pDevice->eOPMode == OP_MODE_AP) {
909 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
911 else {
912 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
915 else {
916 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
917 //Get SignalField,ServiceField,Length
918 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
919 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
921 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
922 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
923 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
925 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
927 //Get Duration
928 pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
929 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
930 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
931 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
932 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
933 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
934 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
935 pBuf->Data.wDurationID = pBuf->wDuration_aa;
936 //Get RTS Frame body
937 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
939 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
940 (pDevice->eOPMode == OP_MODE_AP)) {
941 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
943 else {
944 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
947 if (pDevice->eOPMode == OP_MODE_AP) {
948 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
950 else {
951 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
954 } // if (byFBOption == AUTO_FB_NONE)
956 else if (byPktType == PK_TYPE_11A) {
957 if (byFBOption == AUTO_FB_NONE) {
958 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
959 //Get SignalField,ServiceField,Length
960 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
961 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
963 pBuf->wTransmitLength = cpu_to_le16(wLen);
964 //Get Duration
965 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
966 pBuf->Data.wDurationID = pBuf->wDuration;
967 //Get RTS Frame body
968 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
970 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
971 (pDevice->eOPMode == OP_MODE_AP)) {
972 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
974 else {
975 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
978 if (pDevice->eOPMode == OP_MODE_AP) {
979 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
981 else {
982 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
986 else {
987 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
988 //Get SignalField,ServiceField,Length
989 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
990 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
992 pBuf->wTransmitLength = cpu_to_le16(wLen);
993 //Get Duration
994 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
995 pBuf->wRTSDuration_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
996 pBuf->wRTSDuration_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
997 pBuf->Data.wDurationID = pBuf->wDuration;
998 //Get RTS Frame body
999 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1001 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1002 (pDevice->eOPMode == OP_MODE_AP)) {
1003 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1005 else {
1006 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1008 if (pDevice->eOPMode == OP_MODE_AP) {
1009 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1011 else {
1012 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1016 else if (byPktType == PK_TYPE_11B) {
1017 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1018 //Get SignalField,ServiceField,Length
1019 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1020 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1022 pBuf->wTransmitLength = cpu_to_le16(wLen);
1023 //Get Duration
1024 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1025 pBuf->Data.wDurationID = pBuf->wDuration;
1026 //Get RTS Frame body
1027 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1030 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1031 (pDevice->eOPMode == OP_MODE_AP)) {
1032 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1034 else {
1035 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1038 if (pDevice->eOPMode == OP_MODE_AP) {
1039 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1041 else {
1042 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1047 static
1048 VOID
1049 s_vFillCTSHead (
1050 IN PSDevice pDevice,
1051 IN UINT uDMAIdx,
1052 IN BYTE byPktType,
1053 IN PVOID pvCTS,
1054 IN UINT cbFrameLength,
1055 IN BOOL bNeedAck,
1056 IN BOOL bDisCRC,
1057 IN WORD wCurrentRate,
1058 IN BYTE byFBOption
1061 UINT uCTSFrameLen = 14;
1062 WORD wLen = 0x0000;
1064 if (pvCTS == NULL) {
1065 return;
1068 if (bDisCRC) {
1069 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1070 // in this case we need to decrease its length by 4.
1071 uCTSFrameLen -= 4;
1074 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1075 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1076 // Auto Fall back
1077 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1078 //Get SignalField,ServiceField,Length
1079 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1080 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1084 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1086 pBuf->wDuration_ba = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1087 pBuf->wDuration_ba += pDevice->wCTSDuration;
1088 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1089 //Get CTSDuration_ba_f0
1090 pBuf->wCTSDuration_ba_f0 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
1091 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1092 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1093 //Get CTSDuration_ba_f1
1094 pBuf->wCTSDuration_ba_f1 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
1095 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1096 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1097 //Get CTS Frame body
1098 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1099 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1100 pBuf->Data.wReserved = 0x0000;
1101 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1103 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1104 PSCTS pBuf = (PSCTS)pvCTS;
1105 //Get SignalField,ServiceField,Length
1106 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1107 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1109 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1110 //Get CTSDuration_ba
1111 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1112 pBuf->wDuration_ba += pDevice->wCTSDuration;
1113 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1115 //Get CTS Frame body
1116 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1117 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1118 pBuf->Data.wReserved = 0x0000;
1119 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1131 * Description:
1132 * Generate FIFO control for MAC & Baseband controller
1134 * Parameters:
1135 * In:
1136 * pDevice - Pointer to adpater
1137 * pTxDataHead - Transmit Data Buffer
1138 * pTxBufHead - pTxBufHead
1139 * pvRrvTime - pvRrvTime
1140 * pvRTS - RTS Buffer
1141 * pCTS - CTS Buffer
1142 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1143 * bNeedACK - If need ACK
1144 * uDescIdx - Desc Index
1145 * Out:
1146 * none
1148 * Return Value: none
1151 // UINT cbFrameSize,//Hdr+Payload+FCS
1152 static
1153 VOID
1154 s_vGenerateTxParameter (
1155 IN PSDevice pDevice,
1156 IN BYTE byPktType,
1157 IN PVOID pTxBufHead,
1158 IN PVOID pvRrvTime,
1159 IN PVOID pvRTS,
1160 IN PVOID pvCTS,
1161 IN UINT cbFrameSize,
1162 IN BOOL bNeedACK,
1163 IN UINT uDMAIdx,
1164 IN PSEthernetHeader psEthHeader,
1165 IN WORD wCurrentRate
1168 UINT cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1169 WORD wFifoCtl;
1170 BOOL bDisCRC = FALSE;
1171 BYTE byFBOption = AUTO_FB_NONE;
1172 // WORD wCurrentRate = pDevice->wCurrentRate;
1174 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1175 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1176 pFifoHead->wReserved = wCurrentRate;
1177 wFifoCtl = pFifoHead->wFIFOCtl;
1179 if (wFifoCtl & FIFOCTL_CRCDIS) {
1180 bDisCRC = TRUE;
1183 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1184 byFBOption = AUTO_FB_0;
1186 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1187 byFBOption = AUTO_FB_1;
1190 if (pDevice->bLongHeader)
1191 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1193 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1195 if (pvRTS != NULL) { //RTS_need
1196 //Fill RsvTime
1197 if (pvRrvTime) {
1198 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1199 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1200 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1201 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1202 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1203 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1205 //Fill RTS
1206 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1208 else {//RTS_needless, PCF mode
1210 //Fill RsvTime
1211 if (pvRrvTime) {
1212 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1213 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1214 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1215 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1219 //Fill CTS
1220 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1223 else if (byPktType == PK_TYPE_11A) {
1225 if (pvRTS != NULL) {//RTS_need, non PCF mode
1226 //Fill RsvTime
1227 if (pvRrvTime) {
1228 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1229 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1230 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1232 //Fill RTS
1233 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1235 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1236 //Fill RsvTime
1237 if (pvRrvTime) {
1238 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1239 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1243 else if (byPktType == PK_TYPE_11B) {
1245 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1246 //Fill RsvTime
1247 if (pvRrvTime) {
1248 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1249 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1250 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1252 //Fill RTS
1253 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1255 else { //RTS_needless, non PCF mode
1256 //Fill RsvTime
1257 if (pvRrvTime) {
1258 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1259 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1263 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1266 PBYTE pbyBuffer,//point to pTxBufHead
1267 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1268 UINT cbFragmentSize,//Hdr+payoad+FCS
1270 static
1271 VOID
1272 s_vFillFragParameter(
1273 IN PSDevice pDevice,
1274 IN PBYTE pbyBuffer,
1275 IN UINT uTxType,
1276 IN PVOID pvtdCurr,
1277 IN WORD wFragType,
1278 IN UINT cbReqCount
1281 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
1282 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
1284 if (uTxType == TYPE_SYNCDMA) {
1285 //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1286 PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
1288 //Set FIFOCtl & TimeStamp in TxSyncDesc
1289 ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
1290 ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
1291 //Set TSR1 & ReqCount in TxDescHead
1292 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
1293 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1294 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1296 else {
1297 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1300 else {
1301 //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1302 PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
1303 //Set TSR1 & ReqCount in TxDescHead
1304 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
1305 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1306 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1308 else {
1309 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1313 pTxBufHead->wFragCtl |= (WORD)wFragType;//0x0001; //0000 0000 0000 0001
1315 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
1318 static
1319 UINT
1320 s_cbFillTxBufHead (
1321 IN PSDevice pDevice,
1322 IN BYTE byPktType,
1323 IN PBYTE pbyTxBufferAddr,
1324 IN UINT cbFrameBodySize,
1325 IN UINT uDMAIdx,
1326 IN PSTxDesc pHeadTD,
1327 IN PSEthernetHeader psEthHeader,
1328 IN PBYTE pPacket,
1329 IN BOOL bNeedEncrypt,
1330 IN PSKeyItem pTransmitKey,
1331 IN UINT uNodeIndex,
1332 OUT PUINT puMACfragNum
1335 UINT cbMACHdLen;
1336 UINT cbFrameSize;
1337 UINT cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1338 UINT cbFragPayloadSize;
1339 UINT cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1340 UINT cbLastFragPayloadSize;
1341 UINT uFragIdx;
1342 PBYTE pbyPayloadHead;
1343 PBYTE pbyIVHead;
1344 PBYTE pbyMacHdr;
1345 WORD wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
1346 UINT uDuration;
1347 PBYTE pbyBuffer;
1348 // UINT uKeyEntryIdx = NUM_KEY_ENTRY+1;
1349 // BYTE byKeySel = 0xFF;
1350 UINT cbIVlen = 0;
1351 UINT cbICVlen = 0;
1352 UINT cbMIClen = 0;
1353 UINT cbFCSlen = 4;
1354 UINT cb802_1_H_len = 0;
1355 UINT uLength = 0;
1356 UINT uTmpLen = 0;
1357 // BYTE abyTmp[8];
1358 // DWORD dwCRC;
1359 UINT cbMICHDR = 0;
1360 DWORD dwMICKey0, dwMICKey1;
1361 DWORD dwMIC_Priority;
1362 PDWORD pdwMIC_L;
1363 PDWORD pdwMIC_R;
1364 DWORD dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
1365 BOOL bMIC2Frag = FALSE;
1366 UINT uMICFragLen = 0;
1367 UINT uMACfragNum = 1;
1368 UINT uPadding = 0;
1369 UINT cbReqCount = 0;
1371 BOOL bNeedACK;
1372 BOOL bRTS;
1373 BOOL bIsAdhoc;
1374 PBYTE pbyType;
1375 PSTxDesc ptdCurr;
1376 PSTxBufHead psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
1377 // UINT tmpDescIdx;
1378 UINT cbHeaderLength = 0;
1379 PVOID pvRrvTime;
1380 PSMICHDRHead pMICHDR;
1381 PVOID pvRTS;
1382 PVOID pvCTS;
1383 PVOID pvTxDataHd;
1384 WORD wTxBufSize; // FFinfo size
1385 UINT uTotalCopyLength = 0;
1386 BYTE byFBOption = AUTO_FB_NONE;
1387 BOOL bIsWEP256 = FALSE;
1388 PSMgmtObject pMgmt = pDevice->pMgmt;
1391 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1393 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
1394 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1395 (pDevice->eOPMode == OP_MODE_AP)) {
1397 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
1398 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
1399 bNeedACK = FALSE;
1401 else {
1402 bNeedACK = TRUE;
1404 bIsAdhoc = TRUE;
1406 else {
1407 // MSDUs in Infra mode always need ACK
1408 bNeedACK = TRUE;
1409 bIsAdhoc = FALSE;
1412 if (pDevice->bLongHeader)
1413 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1414 else
1415 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1418 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL)) {
1419 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1420 cbIVlen = 4;
1421 cbICVlen = 4;
1422 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
1423 bIsWEP256 = TRUE;
1426 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1427 cbIVlen = 8;//IV+ExtIV
1428 cbMIClen = 8;
1429 cbICVlen = 4;
1431 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1432 cbIVlen = 8;//RSN Header
1433 cbICVlen = 8;//MIC
1434 cbMICHDR = sizeof(SMICHDRHead);
1436 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1437 //MAC Header should be padding 0 to DW alignment.
1438 uPadding = 4 - (cbMACHdLen%4);
1439 uPadding %= 4;
1444 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1446 if ((bNeedACK == FALSE) ||
1447 (cbFrameSize < pDevice->wRTSThreshold) ||
1448 ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
1450 bRTS = FALSE;
1452 else {
1453 bRTS = TRUE;
1454 psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1457 // Use for AUTO FALL BACK
1459 if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1460 byFBOption = AUTO_FB_0;
1462 else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1463 byFBOption = AUTO_FB_1;
1466 //////////////////////////////////////////////////////
1467 //Set RrvTime/RTS/CTS Buffer
1468 wTxBufSize = sizeof(STxBufHead);
1469 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1471 if (byFBOption == AUTO_FB_NONE) {
1472 if (bRTS == TRUE) {//RTS_need
1473 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1474 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1475 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1476 pvCTS = NULL;
1477 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1478 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1480 else { //RTS_needless
1481 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1482 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1483 pvRTS = NULL;
1484 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1485 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1486 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1488 } else {
1489 // Auto Fall Back
1490 if (bRTS == TRUE) {//RTS_need
1491 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1492 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1493 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1494 pvCTS = NULL;
1495 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1496 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1498 else { //RTS_needless
1499 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1500 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1501 pvRTS = NULL;
1502 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1503 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1504 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1506 } // Auto Fall Back
1508 else {//802.11a/b packet
1510 if (byFBOption == AUTO_FB_NONE) {
1511 if (bRTS == TRUE) {
1512 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1513 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1514 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1515 pvCTS = NULL;
1516 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1517 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1519 else { //RTS_needless, need MICHDR
1520 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1521 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1522 pvRTS = NULL;
1523 pvCTS = NULL;
1524 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1525 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1527 } else {
1528 // Auto Fall Back
1529 if (bRTS == TRUE) {//RTS_need
1530 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1531 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1532 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1533 pvCTS = NULL;
1534 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1535 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1537 else { //RTS_needless
1538 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1539 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1540 pvRTS = NULL;
1541 pvCTS = NULL;
1542 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1543 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1545 } // Auto Fall Back
1547 memset((PVOID)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1549 //////////////////////////////////////////////////////////////////
1550 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1551 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
1552 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1553 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1555 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1556 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1557 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1559 else {
1560 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1561 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1563 // DO Software Michael
1564 MIC_vInit(dwMICKey0, dwMICKey1);
1565 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1566 dwMIC_Priority = 0;
1567 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1571 ///////////////////////////////////////////////////////////////////
1573 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1574 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1575 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1577 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == TRUE) && (bIsWEP256 == FALSE)) {
1578 // Fragmentation
1579 // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
1580 cbFragmentSize = pDevice->wFragmentationThreshold;
1581 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
1582 //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
1583 uMACfragNum = (WORD) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
1584 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
1585 if (cbLastFragPayloadSize == 0) {
1586 cbLastFragPayloadSize = cbFragPayloadSize;
1587 } else {
1588 uMACfragNum++;
1590 //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
1591 cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
1593 for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx ++) {
1594 if (uFragIdx == 0) {
1595 //=========================
1596 // Start Fragmentation
1597 //=========================
1598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start Fragmentation...\n");
1599 wFragType = FRAGCTL_STAFRAG;
1602 //Fill FIFO,RrvTime,RTS,and CTS
1603 s_vGenerateTxParameter(pDevice, byPktType, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1604 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1605 //Fill DataHead
1606 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1607 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1608 // Generate TX MAC Header
1609 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1610 wFragType, uDMAIdx, uFragIdx);
1612 if (bNeedEncrypt == TRUE) {
1613 //Fill TXKEY
1614 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1615 pbyMacHdr, (WORD)cbFragPayloadSize, (PBYTE)pMICHDR);
1616 //Fill IV(ExtIV,RSNHDR)
1617 if (pDevice->bEnableHostWEP) {
1618 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1619 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1624 // 802.1H
1625 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
1626 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1627 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1628 memcpy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1630 else {
1631 memcpy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1633 pbyType = (PBYTE) (pbyPayloadHead + 6);
1634 memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1635 cb802_1_H_len = 8;
1638 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1639 //---------------------------
1640 // S/W or H/W Encryption
1641 //---------------------------
1642 //Fill MICHDR
1643 //if (pDevice->bAES) {
1644 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1646 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (PVOID)psTxBufHd, byKeySel,
1647 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1651 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
1652 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1654 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1655 //copy TxBufferHeader + MacHeader to desc
1656 memcpy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1658 // Copy the Packet into a tx Buffer
1659 memcpy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
1662 uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
1664 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1665 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start MIC: %d\n", cbFragPayloadSize);
1666 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
1670 //---------------------------
1671 // S/W Encryption
1672 //---------------------------
1673 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1674 if (bNeedEncrypt) {
1675 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (WORD)cbFragPayloadSize);
1676 cbReqCount += cbICVlen;
1680 ptdCurr = (PSTxDesc)pHeadTD;
1681 //--------------------
1682 //1.Set TSR1 & ReqCount in TxDescHead
1683 //2.Set FragCtl in TxBufferHead
1684 //3.Set Frame Control
1685 //4.Set Sequence Control
1686 //5.Get S/W generate FCS
1687 //--------------------
1688 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1690 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1691 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1692 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1693 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1694 pDevice->iTDUsed[uDMAIdx]++;
1695 pHeadTD = ptdCurr->next;
1697 else if (uFragIdx == (uMACfragNum-1)) {
1698 //=========================
1699 // Last Fragmentation
1700 //=========================
1701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last Fragmentation...\n");
1702 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1704 wFragType = FRAGCTL_ENDFRAG;
1706 //Fill FIFO,RrvTime,RTS,and CTS
1707 s_vGenerateTxParameter(pDevice, byPktType, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1708 cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1709 //Fill DataHead
1710 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
1711 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1713 // Generate TX MAC Header
1714 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1715 wFragType, uDMAIdx, uFragIdx);
1717 if (bNeedEncrypt == TRUE) {
1718 //Fill TXKEY
1719 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1720 pbyMacHdr, (WORD)cbLastFragPayloadSize, (PBYTE)pMICHDR);
1722 if (pDevice->bEnableHostWEP) {
1723 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1724 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1730 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
1731 //---------------------------
1732 // S/W or H/W Encryption
1733 //---------------------------
1737 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1738 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1740 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1742 //copy TxBufferHeader + MacHeader to desc
1743 memcpy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1745 // Copy the Packet into a tx Buffer
1746 if (bMIC2Frag == FALSE) {
1748 memcpy((pbyBuffer + uLength),
1749 (pPacket + 14 + uTotalCopyLength),
1750 (cbLastFragPayloadSize - cbMIClen)
1752 //TODO check uTmpLen !
1753 uTmpLen = cbLastFragPayloadSize - cbMIClen;
1756 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
1758 uMICFragLen, cbLastFragPayloadSize, uTmpLen);
1760 if (bMIC2Frag == FALSE) {
1761 if (uTmpLen != 0)
1762 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1763 pdwMIC_L = (PDWORD)(pbyBuffer + uLength + uTmpLen);
1764 pdwMIC_R = (PDWORD)(pbyBuffer + uLength + uTmpLen + 4);
1765 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1766 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1767 } else {
1768 if (uMICFragLen >= 4) {
1769 memcpy((pbyBuffer + uLength), ((PBYTE)&dwSafeMIC_R + (uMICFragLen - 4)),
1770 (cbMIClen - uMICFragLen));
1771 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen >= 4: %X, %d\n",
1772 *(PBYTE)((PBYTE)&dwSafeMIC_R + (uMICFragLen - 4)),
1773 (cbMIClen - uMICFragLen));
1775 } else {
1776 memcpy((pbyBuffer + uLength), ((PBYTE)&dwSafeMIC_L + uMICFragLen),
1777 (4 - uMICFragLen));
1778 memcpy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
1779 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen < 4: %X, %d\n",
1780 *(PBYTE)((PBYTE)&dwSafeMIC_R + uMICFragLen - 4),
1781 (cbMIClen - uMICFragLen));
1784 for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii - 8 - 24)));
1787 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1790 MIC_vUnInit();
1791 } else {
1792 ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
1796 //---------------------------
1797 // S/W Encryption
1798 //---------------------------
1799 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1800 if (bNeedEncrypt) {
1801 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (WORD)cbLastFragPayloadSize);
1802 cbReqCount += cbICVlen;
1806 ptdCurr = (PSTxDesc)pHeadTD;
1808 //--------------------
1809 //1.Set TSR1 & ReqCount in TxDescHead
1810 //2.Set FragCtl in TxBufferHead
1811 //3.Set Frame Control
1812 //4.Set Sequence Control
1813 //5.Get S/W generate FCS
1814 //--------------------
1817 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1819 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1820 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1821 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1822 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1823 pDevice->iTDUsed[uDMAIdx]++;
1824 pHeadTD = ptdCurr->next;
1827 else {
1828 //=========================
1829 // Middle Fragmentation
1830 //=========================
1831 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle Fragmentation...\n");
1832 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1834 wFragType = FRAGCTL_MIDFRAG;
1836 //Fill FIFO,RrvTime,RTS,and CTS
1837 s_vGenerateTxParameter(pDevice, byPktType, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1838 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1839 //Fill DataHead
1840 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1841 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1843 // Generate TX MAC Header
1844 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1845 wFragType, uDMAIdx, uFragIdx);
1848 if (bNeedEncrypt == TRUE) {
1849 //Fill TXKEY
1850 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1851 pbyMacHdr, (WORD)cbFragPayloadSize, (PBYTE)pMICHDR);
1853 if (pDevice->bEnableHostWEP) {
1854 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1855 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1859 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1860 //---------------------------
1861 // S/W or H/W Encryption
1862 //---------------------------
1863 //Fill MICHDR
1864 //if (pDevice->bAES) {
1865 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1867 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (PVOID)psTxBufHd, byKeySel,
1868 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1871 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1872 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1875 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1877 //copy TxBufferHeader + MacHeader to desc
1878 memcpy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1880 // Copy the Packet into a tx Buffer
1881 memcpy((pbyBuffer + uLength),
1882 (pPacket + 14 + uTotalCopyLength),
1883 cbFragPayloadSize
1885 uTmpLen = cbFragPayloadSize;
1887 uTotalCopyLength += uTmpLen;
1889 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1891 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1893 if (uTmpLen < cbFragPayloadSize) {
1894 bMIC2Frag = TRUE;
1895 uMICFragLen = cbFragPayloadSize - uTmpLen;
1896 ASSERT(uMICFragLen < cbMIClen);
1898 pdwMIC_L = (PDWORD)(pbyBuffer + uLength + uTmpLen);
1899 pdwMIC_R = (PDWORD)(pbyBuffer + uLength + uTmpLen + 4);
1900 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1901 dwSafeMIC_L = *pdwMIC_L;
1902 dwSafeMIC_R = *pdwMIC_R;
1904 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
1905 uMICFragLen, cbFragPayloadSize, uTmpLen);
1906 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MIC in Middle frag [%d]\n", uMICFragLen);
1908 for (ii = 0; ii < uMICFragLen; ii++) {
1909 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength + uTmpLen) + ii)));
1911 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1913 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1915 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle frag len: %d\n", uTmpLen);
1917 for (ii = 0; ii < uTmpLen; ii++) {
1918 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
1920 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1923 } else {
1924 ASSERT(uTmpLen == (cbFragPayloadSize));
1927 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1928 if (bNeedEncrypt) {
1929 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (WORD)cbFragPayloadSize);
1930 cbReqCount += cbICVlen;
1934 ptdCurr = (PSTxDesc)pHeadTD;
1936 //--------------------
1937 //1.Set TSR1 & ReqCount in TxDescHead
1938 //2.Set FragCtl in TxBufferHead
1939 //3.Set Frame Control
1940 //4.Set Sequence Control
1941 //5.Get S/W generate FCS
1942 //--------------------
1944 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1946 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1947 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1948 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1949 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1950 pDevice->iTDUsed[uDMAIdx]++;
1951 pHeadTD = ptdCurr->next;
1953 } // for (uMACfragNum)
1955 else {
1956 //=========================
1957 // No Fragmentation
1958 //=========================
1959 //DBG_PRTGRP03(("No Fragmentation...\n"));
1960 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1961 wFragType = FRAGCTL_NONFRAG;
1963 //Set FragCtl in TxBufferHead
1964 psTxBufHd->wFragCtl |= (WORD)wFragType;
1966 //Fill FIFO,RrvTime,RTS,and CTS
1967 s_vGenerateTxParameter(pDevice, byPktType, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1968 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1969 //Fill DataHead
1970 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1971 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1973 // Generate TX MAC Header
1974 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1975 wFragType, uDMAIdx, 0);
1977 if (bNeedEncrypt == TRUE) {
1978 //Fill TXKEY
1979 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1980 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
1982 if (pDevice->bEnableHostWEP) {
1983 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1984 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1988 // 802.1H
1989 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
1990 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1991 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1992 memcpy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1994 else {
1995 memcpy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1997 pbyType = (PBYTE) (pbyPayloadHead + 6);
1998 memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1999 cb802_1_H_len = 8;
2002 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
2003 //---------------------------
2004 // S/W or H/W Encryption
2005 //---------------------------
2006 //Fill MICHDR
2007 //if (pDevice->bAES) {
2008 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
2009 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFrameBodySize);
2012 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
2013 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
2015 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
2017 //copy TxBufferHeader + MacHeader to desc
2018 memcpy(pbyBuffer, (PVOID)psTxBufHd, uLength);
2020 // Copy the Packet into a tx Buffer
2021 memcpy((pbyBuffer + uLength),
2022 (pPacket + 14),
2023 cbFrameBodySize - cb802_1_H_len
2026 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)){
2028 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
2030 for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
2031 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
2033 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2036 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
2038 pdwMIC_L = (PDWORD)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
2039 pdwMIC_R = (PDWORD)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
2041 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2042 MIC_vUnInit();
2045 if (pDevice->bTxMICFail == TRUE) {
2046 *pdwMIC_L = 0;
2047 *pdwMIC_R = 0;
2048 pDevice->bTxMICFail = FALSE;
2051 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2052 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
2053 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2055 for (ii = 0; ii < 8; ii++) {
2056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((PBYTE)(pdwMIC_L) + ii)));
2058 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2064 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)){
2065 if (bNeedEncrypt) {
2066 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
2067 (WORD)(cbFrameBodySize + cbMIClen));
2068 cbReqCount += cbICVlen;
2073 ptdCurr = (PSTxDesc)pHeadTD;
2075 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
2076 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
2077 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
2078 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
2079 //Set TSR1 & ReqCount in TxDescHead
2080 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
2081 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
2083 pDevice->iTDUsed[uDMAIdx]++;
2086 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
2087 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
2090 *puMACfragNum = uMACfragNum;
2091 //DBG_PRTGRP03(("s_cbFillTxBufHead END\n"));
2092 return cbHeaderLength;
2096 VOID
2097 vGenerateFIFOHeader (
2098 IN PSDevice pDevice,
2099 IN BYTE byPktType,
2100 IN PBYTE pbyTxBufferAddr,
2101 IN BOOL bNeedEncrypt,
2102 IN UINT cbPayloadSize,
2103 IN UINT uDMAIdx,
2104 IN PSTxDesc pHeadTD,
2105 IN PSEthernetHeader psEthHeader,
2106 IN PBYTE pPacket,
2107 IN PSKeyItem pTransmitKey,
2108 IN UINT uNodeIndex,
2109 OUT PUINT puMACfragNum,
2110 OUT PUINT pcbHeaderSize
2113 UINT wTxBufSize; // FFinfo size
2114 BOOL bNeedACK;
2115 BOOL bIsAdhoc;
2116 WORD cbMacHdLen;
2117 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2119 wTxBufSize = sizeof(STxBufHead);
2121 memset(pTxBufHead, 0, wTxBufSize);
2122 //Set FIFOCTL_NEEDACK
2124 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2125 (pDevice->eOPMode == OP_MODE_AP)) {
2126 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
2127 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
2128 bNeedACK = FALSE;
2129 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
2131 else {
2132 bNeedACK = TRUE;
2133 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2135 bIsAdhoc = TRUE;
2137 else {
2138 // MSDUs in Infra mode always need ACK
2139 bNeedACK = TRUE;
2140 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2141 bIsAdhoc = FALSE;
2145 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2146 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2148 //Set FIFOCTL_LHEAD
2149 if (pDevice->bLongHeader)
2150 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
2152 //Set FIFOCTL_GENINT
2154 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2157 //Set FIFOCTL_ISDMA0
2158 if (TYPE_TXDMA0 == uDMAIdx) {
2159 pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
2162 //Set FRAGCTL_MACHDCNT
2163 if (pDevice->bLongHeader) {
2164 cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
2165 } else {
2166 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2168 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2170 //Set packet type
2171 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2174 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2175 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2177 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2178 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2180 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2181 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2183 //Set FIFOCTL_GrpAckPolicy
2184 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2185 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2188 //Set Auto Fallback Ctl
2189 if (pDevice->wCurrentRate >= RATE_18M) {
2190 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
2191 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
2192 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
2193 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
2197 //Set FRAGCTL_WEPTYP
2198 pDevice->bAES = FALSE;
2200 //Set FRAGCTL_WEPTYP
2201 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
2202 if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
2203 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2204 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2206 else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
2207 if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
2208 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2210 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
2211 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2216 #ifdef PLICE_DEBUG
2217 //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2219 //if (pDevice->wCurrentRate <= 3)
2221 // RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
2223 //else
2225 RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
2226 #endif
2227 //if (pDevice->wCurrentRate == 3)
2228 //pDevice->byCurPwr = 46;
2229 pTxBufHead->byTxPower = pDevice->byCurPwr;
2235 if(pDevice->bEnableHostWEP)
2236 pTxBufHead->wFragCtl &= ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
2238 *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
2239 uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
2240 pTransmitKey, uNodeIndex, puMACfragNum);
2242 return;
2250 * Description:
2251 * Translate 802.3 to 802.11 header
2253 * Parameters:
2254 * In:
2255 * pDevice - Pointer to adpater
2256 * dwTxBufferAddr - Transmit Buffer
2257 * pPacket - Packet from upper layer
2258 * cbPacketSize - Transmit Data Length
2259 * Out:
2260 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
2261 * pcbAppendPayload - size of append payload for 802.1H translation
2263 * Return Value: none
2267 VOID
2268 vGenerateMACHeader (
2269 IN PSDevice pDevice,
2270 IN PBYTE pbyBufferAddr,
2271 IN WORD wDuration,
2272 IN PSEthernetHeader psEthHeader,
2273 IN BOOL bNeedEncrypt,
2274 IN WORD wFragType,
2275 IN UINT uDMAIdx,
2276 IN UINT uFragIdx
2279 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
2281 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
2283 if (uDMAIdx == TYPE_ATIMDMA) {
2284 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
2285 } else {
2286 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
2289 if (pDevice->eOPMode == OP_MODE_AP) {
2290 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2291 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2292 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2293 pMACHeader->wFrameCtl |= FC_FROMDS;
2295 else {
2296 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2297 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2298 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2299 memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2301 else {
2302 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2303 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2304 memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2305 pMACHeader->wFrameCtl |= FC_TODS;
2309 if (bNeedEncrypt)
2310 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
2312 pMACHeader->wDurationID = cpu_to_le16(wDuration);
2314 if (pDevice->bLongHeader) {
2315 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
2316 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
2317 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
2319 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2321 //Set FragNumber in Sequence Control
2322 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
2324 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
2325 pDevice->wSeqCounter++;
2326 if (pDevice->wSeqCounter > 0x0fff)
2327 pDevice->wSeqCounter = 0;
2330 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
2331 pMACHeader->wFrameCtl |= FC_MOREFRAG;
2340 CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2342 PSTxDesc pFrstTD;
2343 BYTE byPktType;
2344 PBYTE pbyTxBufferAddr;
2345 PVOID pvRTS;
2346 PSCTS pCTS;
2347 PVOID pvTxDataHd;
2348 UINT uDuration;
2349 UINT cbReqCount;
2350 PS802_11Header pMACHeader;
2351 UINT cbHeaderSize;
2352 UINT cbFrameBodySize;
2353 BOOL bNeedACK;
2354 BOOL bIsPSPOLL = FALSE;
2355 PSTxBufHead pTxBufHead;
2356 UINT cbFrameSize;
2357 UINT cbIVlen = 0;
2358 UINT cbICVlen = 0;
2359 UINT cbMIClen = 0;
2360 UINT cbFCSlen = 4;
2361 UINT uPadding = 0;
2362 WORD wTxBufSize;
2363 UINT cbMacHdLen;
2364 SEthernetHeader sEthHeader;
2365 PVOID pvRrvTime;
2366 PVOID pMICHDR;
2367 PSMgmtObject pMgmt = pDevice->pMgmt;
2368 WORD wCurrentRate = RATE_1M;
2371 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2372 return CMD_STATUS_RESOURCES;
2375 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2376 pbyTxBufferAddr = (PBYTE)pFrstTD->pTDInfo->buf;
2377 cbFrameBodySize = pPacket->cbPayloadLen;
2378 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2379 wTxBufSize = sizeof(STxBufHead);
2380 memset(pTxBufHead, 0, wTxBufSize);
2382 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2383 wCurrentRate = RATE_6M;
2384 byPktType = PK_TYPE_11A;
2385 } else {
2386 wCurrentRate = RATE_1M;
2387 byPktType = PK_TYPE_11B;
2390 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2391 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2392 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2393 // to set power here.
2394 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2396 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2397 } else {
2398 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2400 pTxBufHead->byTxPower = pDevice->byCurPwr;
2401 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2402 if (pDevice->byFOETuning) {
2403 if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2404 wCurrentRate = RATE_24M;
2405 byPktType = PK_TYPE_11GA;
2409 //Set packet type
2410 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2411 pTxBufHead->wFIFOCtl = 0;
2413 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2414 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2416 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2417 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2419 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2420 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2423 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2424 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2427 if (IS_MULTICAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0])) ||
2428 IS_BROADCAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0]))) {
2429 bNeedACK = FALSE;
2431 else {
2432 bNeedACK = TRUE;
2433 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2436 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2437 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2439 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2440 //Set Preamble type always long
2441 //pDevice->byPreambleType = PREAMBLE_LONG;
2442 // probe-response don't retry
2443 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2444 // bNeedACK = FALSE;
2445 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2449 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2451 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2452 bIsPSPOLL = TRUE;
2453 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2454 } else {
2455 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2458 //Set FRAGCTL_MACHDCNT
2459 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2461 // Notes:
2462 // Although spec says MMPDU can be fragmented; In most case,
2463 // no one will send a MMPDU under fragmentation. With RTS may occur.
2464 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2466 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2467 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2468 cbIVlen = 4;
2469 cbICVlen = 4;
2470 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2472 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2473 cbIVlen = 8;//IV+ExtIV
2474 cbMIClen = 8;
2475 cbICVlen = 4;
2476 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2477 //We need to get seed here for filling TxKey entry.
2478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2481 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2482 cbIVlen = 8;//RSN Header
2483 cbICVlen = 8;//MIC
2484 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2485 pDevice->bAES = TRUE;
2487 //MAC Header should be padding 0 to DW alignment.
2488 uPadding = 4 - (cbMacHdLen%4);
2489 uPadding %= 4;
2492 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2494 //Set FIFOCTL_GrpAckPolicy
2495 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2496 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2498 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2500 //Set RrvTime/RTS/CTS Buffer
2501 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2503 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2504 pMICHDR = NULL;
2505 pvRTS = NULL;
2506 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2507 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2508 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2510 else { // 802.11a/b packet
2511 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2512 pMICHDR = NULL;
2513 pvRTS = NULL;
2514 pCTS = NULL;
2515 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2516 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2519 memset((PVOID)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
2521 memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
2522 memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
2523 //=========================
2524 // No Fragmentation
2525 //=========================
2526 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2529 //Fill FIFO,RrvTime,RTS,and CTS
2530 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2531 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2533 //Fill DataHead
2534 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2535 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2537 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2539 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2541 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2542 PBYTE pbyIVHead;
2543 PBYTE pbyPayloadHead;
2544 PBYTE pbyBSSID;
2545 PSKeyItem pTransmitKey = NULL;
2547 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2548 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2550 //Fill TXKEY
2551 //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet.
2552 //s_vFillTxKey(pDevice, (PBYTE)pTxBufHead->adwTxKey, NULL);
2554 //Fill IV(ExtIV,RSNHDR)
2555 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
2556 //---------------------------
2557 // S/W or H/W Encryption
2558 //---------------------------
2559 //Fill MICHDR
2560 //if (pDevice->bAES) {
2561 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, (PBYTE)pMACHeader, (WORD)cbFrameBodySize);
2563 do {
2564 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2565 (pDevice->bLinkPass == TRUE)) {
2566 pbyBSSID = pDevice->abyBSSID;
2567 // get pairwise key
2568 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2569 // get group key
2570 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2572 break;
2574 } else {
2575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2576 break;
2579 // get group key
2580 pbyBSSID = pDevice->abyBroadcastAddr;
2581 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2582 pTransmitKey = NULL;
2583 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2584 } else {
2585 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2587 } while(FALSE);
2588 //Fill TXKEY
2589 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2590 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2592 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2593 memcpy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2594 cbFrameBodySize);
2596 else {
2597 // Copy the Packet into a tx Buffer
2598 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2601 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2602 pDevice->wSeqCounter++ ;
2603 if (pDevice->wSeqCounter > 0x0fff)
2604 pDevice->wSeqCounter = 0;
2606 if (bIsPSPOLL) {
2607 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2608 // of FIFO control header.
2609 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2610 // in the same place of other packet's Duration-field).
2611 // And it will cause Cisco-AP to issue Disassociation-packet
2612 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2613 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2614 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2615 } else {
2616 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2621 // first TD is the only TD
2622 //Set TSR1 & ReqCount in TxDescHead
2623 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
2624 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
2625 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
2626 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2627 pFrstTD->pTDInfo->byFlags = 0;
2629 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2630 // Disable PS
2631 MACbPSWakeup(pDevice->PortOffset);
2633 pDevice->bPWBitOn = FALSE;
2635 wmb();
2636 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2637 wmb();
2639 pDevice->iTDUsed[TYPE_TXDMA0]++;
2641 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
2642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
2645 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
2646 #ifdef PLICE_DEBUG
2647 //printk("SCAN:CurrentRate is %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
2648 #endif
2650 #ifdef TxInSleep
2651 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2652 #endif
2654 // Poll Transmit the adapter
2655 MACvTransmit0(pDevice->PortOffset);
2657 return CMD_STATUS_PENDING;
2662 CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2664 BYTE byPktType;
2665 PBYTE pbyBuffer = (PBYTE)pDevice->tx_beacon_bufs;
2666 UINT cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2667 UINT cbHeaderSize = 0;
2668 WORD wTxBufSize = sizeof(STxShortBufHead);
2669 PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
2670 PSTxDataHead_ab pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
2671 PS802_11Header pMACHeader;
2672 WORD wCurrentRate;
2673 WORD wLen = 0x0000;
2676 memset(pTxBufHead, 0, wTxBufSize);
2678 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2679 wCurrentRate = RATE_6M;
2680 byPktType = PK_TYPE_11A;
2681 } else {
2682 wCurrentRate = RATE_2M;
2683 byPktType = PK_TYPE_11B;
2686 //Set Preamble type always long
2687 pDevice->byPreambleType = PREAMBLE_LONG;
2689 //Set FIFOCTL_GENINT
2691 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2694 //Set packet type & Get Duration
2695 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2696 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktType,
2697 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2699 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2700 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2701 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktType,
2702 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2705 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktType,
2706 (PWORD)&(wLen), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2708 pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
2709 //Get TimeStampOff
2710 pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
2711 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2713 //Generate Beacon Header
2714 pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
2715 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2717 pMACHeader->wDurationID = 0;
2718 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2719 pDevice->wSeqCounter++ ;
2720 if (pDevice->wSeqCounter > 0x0fff)
2721 pDevice->wSeqCounter = 0;
2723 // Set Beacon buffer length
2724 pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
2726 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
2728 MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
2729 // Set auto Transmit on
2730 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2731 // Poll Transmit the adapter
2732 MACvTransmitBCN(pDevice->PortOffset);
2734 return CMD_STATUS_PENDING;
2739 UINT
2740 cbGetFragCount (
2741 IN PSDevice pDevice,
2742 IN PSKeyItem pTransmitKey,
2743 IN UINT cbFrameBodySize,
2744 IN PSEthernetHeader psEthHeader
2747 UINT cbMACHdLen;
2748 UINT cbFrameSize;
2749 UINT cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
2750 UINT cbFragPayloadSize;
2751 UINT cbLastFragPayloadSize;
2752 UINT cbIVlen = 0;
2753 UINT cbICVlen = 0;
2754 UINT cbMIClen = 0;
2755 UINT cbFCSlen = 4;
2756 UINT uMACfragNum = 1;
2757 BOOL bNeedACK;
2761 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2762 (pDevice->eOPMode == OP_MODE_AP)) {
2763 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
2764 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
2765 bNeedACK = FALSE;
2767 else {
2768 bNeedACK = TRUE;
2771 else {
2772 // MSDUs in Infra mode always need ACK
2773 bNeedACK = TRUE;
2776 if (pDevice->bLongHeader)
2777 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
2778 else
2779 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
2782 if (pDevice->bEncryptionEnable == TRUE) {
2784 if (pTransmitKey == NULL) {
2785 if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
2786 (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
2787 cbIVlen = 4;
2788 cbICVlen = 4;
2789 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2790 cbIVlen = 8;//IV+ExtIV
2791 cbMIClen = 8;
2792 cbICVlen = 4;
2793 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2794 cbIVlen = 8;//RSN Header
2795 cbICVlen = 8;//MIC
2797 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
2798 cbIVlen = 4;
2799 cbICVlen = 4;
2800 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2801 cbIVlen = 8;//IV+ExtIV
2802 cbMIClen = 8;
2803 cbICVlen = 4;
2804 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
2805 cbIVlen = 8;//RSN Header
2806 cbICVlen = 8;//MIC
2810 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
2812 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == TRUE)) {
2813 // Fragmentation
2814 cbFragmentSize = pDevice->wFragmentationThreshold;
2815 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
2816 uMACfragNum = (WORD) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
2817 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
2818 if (cbLastFragPayloadSize == 0) {
2819 cbLastFragPayloadSize = cbFragPayloadSize;
2820 } else {
2821 uMACfragNum++;
2824 return uMACfragNum;
2828 VOID
2829 vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, PBYTE pbMPDU, UINT cbMPDULen) {
2831 PSTxDesc pFrstTD;
2832 BYTE byPktType;
2833 PBYTE pbyTxBufferAddr;
2834 PVOID pvRTS;
2835 PVOID pvCTS;
2836 PVOID pvTxDataHd;
2837 UINT uDuration;
2838 UINT cbReqCount;
2839 PS802_11Header pMACHeader;
2840 UINT cbHeaderSize;
2841 UINT cbFrameBodySize;
2842 BOOL bNeedACK;
2843 BOOL bIsPSPOLL = FALSE;
2844 PSTxBufHead pTxBufHead;
2845 UINT cbFrameSize;
2846 UINT cbIVlen = 0;
2847 UINT cbICVlen = 0;
2848 UINT cbMIClen = 0;
2849 UINT cbFCSlen = 4;
2850 UINT uPadding = 0;
2851 UINT cbMICHDR = 0;
2852 UINT uLength = 0;
2853 DWORD dwMICKey0, dwMICKey1;
2854 DWORD dwMIC_Priority;
2855 PDWORD pdwMIC_L;
2856 PDWORD pdwMIC_R;
2857 WORD wTxBufSize;
2858 UINT cbMacHdLen;
2859 SEthernetHeader sEthHeader;
2860 PVOID pvRrvTime;
2861 PVOID pMICHDR;
2862 PSMgmtObject pMgmt = pDevice->pMgmt;
2863 WORD wCurrentRate = RATE_1M;
2864 PUWLAN_80211HDR p80211Header;
2865 UINT uNodeIndex = 0;
2866 BOOL bNodeExist = FALSE;
2867 SKeyItem STempKey;
2868 PSKeyItem pTransmitKey = NULL;
2869 PBYTE pbyIVHead;
2870 PBYTE pbyPayloadHead;
2871 PBYTE pbyMacHdr;
2873 UINT cbExtSuppRate = 0;
2874 // PWLAN_IE pItem;
2877 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2879 if(cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
2880 cbFrameBodySize = 0;
2882 else {
2883 cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
2885 p80211Header = (PUWLAN_80211HDR)pbMPDU;
2888 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2889 pbyTxBufferAddr = (PBYTE)pFrstTD->pTDInfo->buf;
2890 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2891 wTxBufSize = sizeof(STxBufHead);
2892 memset(pTxBufHead, 0, wTxBufSize);
2894 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2895 wCurrentRate = RATE_6M;
2896 byPktType = PK_TYPE_11A;
2897 } else {
2898 wCurrentRate = RATE_1M;
2899 byPktType = PK_TYPE_11B;
2902 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2903 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2904 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2905 // to set power here.
2906 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2907 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2908 } else {
2909 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2911 pTxBufHead->byTxPower = pDevice->byCurPwr;
2913 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2914 if (pDevice->byFOETuning) {
2915 if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2916 wCurrentRate = RATE_24M;
2917 byPktType = PK_TYPE_11GA;
2921 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2923 //Set packet type
2924 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2925 pTxBufHead->wFIFOCtl = 0;
2927 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2928 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2930 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2931 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2933 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2934 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2937 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2938 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2941 if (IS_MULTICAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0])) ||
2942 IS_BROADCAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0]))) {
2943 bNeedACK = FALSE;
2944 if (pDevice->bEnableHostWEP) {
2945 uNodeIndex = 0;
2946 bNodeExist = TRUE;
2949 else {
2950 if (pDevice->bEnableHostWEP) {
2951 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2952 bNodeExist = TRUE;
2954 bNeedACK = TRUE;
2955 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2958 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2959 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2961 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2962 //Set Preamble type always long
2963 //pDevice->byPreambleType = PREAMBLE_LONG;
2965 // probe-response don't retry
2966 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2967 // bNeedACK = FALSE;
2968 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2972 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2974 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2975 bIsPSPOLL = TRUE;
2976 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2977 } else {
2978 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2981 // hostapd deamon ext support rate patch
2982 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2984 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2985 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2988 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2989 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2992 if (cbExtSuppRate >0) {
2993 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2998 //Set FRAGCTL_MACHDCNT
2999 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
3001 // Notes:
3002 // Although spec says MMPDU can be fragmented; In most case,
3003 // no one will send a MMPDU under fragmentation. With RTS may occur.
3004 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
3007 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3008 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
3009 cbIVlen = 4;
3010 cbICVlen = 4;
3011 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
3013 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
3014 cbIVlen = 8;//IV+ExtIV
3015 cbMIClen = 8;
3016 cbICVlen = 4;
3017 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
3018 //We need to get seed here for filling TxKey entry.
3019 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
3020 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
3022 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
3023 cbIVlen = 8;//RSN Header
3024 cbICVlen = 8;//MIC
3025 cbMICHDR = sizeof(SMICHDRHead);
3026 pTxBufHead->wFragCtl |= FRAGCTL_AES;
3027 pDevice->bAES = TRUE;
3029 //MAC Header should be padding 0 to DW alignment.
3030 uPadding = 4 - (cbMacHdLen%4);
3031 uPadding %= 4;
3034 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
3036 //Set FIFOCTL_GrpAckPolicy
3037 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
3038 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
3040 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
3043 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
3045 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
3046 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
3047 pvRTS = NULL;
3048 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
3049 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
3050 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
3053 else {//802.11a/b packet
3055 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
3056 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
3057 pvRTS = NULL;
3058 pvCTS = NULL;
3059 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
3060 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
3064 memset((PVOID)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
3065 memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
3066 memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
3067 //=========================
3068 // No Fragmentation
3069 //=========================
3070 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
3073 //Fill FIFO,RrvTime,RTS,and CTS
3074 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
3075 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
3077 //Fill DataHead
3078 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
3079 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
3081 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
3083 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
3085 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
3086 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
3087 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
3089 // Copy the Packet into a tx Buffer
3090 memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
3092 // version set to 0, patch for hostapd deamon
3093 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
3094 memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
3096 // replace support rate, patch for hostapd deamon( only support 11M)
3097 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
3098 if (cbExtSuppRate != 0) {
3099 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
3100 memcpy((pbyPayloadHead + cbFrameBodySize),
3101 pMgmt->abyCurrSuppRates,
3102 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
3104 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
3105 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
3106 pMgmt->abyCurrExtSuppRates,
3107 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3112 // Set wep
3113 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3115 if (pDevice->bEnableHostWEP) {
3116 pTransmitKey = &STempKey;
3117 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3118 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3119 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3120 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3121 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3122 memcpy(pTransmitKey->abyKey,
3123 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3124 pTransmitKey->uKeyLength
3128 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
3130 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
3131 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
3133 // DO Software Michael
3134 MIC_vInit(dwMICKey0, dwMICKey1);
3135 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
3136 dwMIC_Priority = 0;
3137 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
3138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
3140 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
3142 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
3144 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
3145 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
3147 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
3148 MIC_vUnInit();
3150 if (pDevice->bTxMICFail == TRUE) {
3151 *pdwMIC_L = 0;
3152 *pdwMIC_R = 0;
3153 pDevice->bTxMICFail = FALSE;
3156 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
3157 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
3158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
3163 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
3164 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
3166 if (pDevice->bEnableHostWEP) {
3167 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
3168 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
3171 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
3172 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
3176 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
3177 pDevice->wSeqCounter++ ;
3178 if (pDevice->wSeqCounter > 0x0fff)
3179 pDevice->wSeqCounter = 0;
3182 if (bIsPSPOLL) {
3183 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
3184 // of FIFO control header.
3185 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
3186 // in the same place of other packet's Duration-field).
3187 // And it will cause Cisco-AP to issue Disassociation-packet
3188 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
3189 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
3190 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
3191 } else {
3192 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
3197 // first TD is the only TD
3198 //Set TSR1 & ReqCount in TxDescHead
3199 pFrstTD->pTDInfo->skb = skb;
3200 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
3201 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
3202 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
3203 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
3204 pFrstTD->pTDInfo->byFlags = 0;
3205 pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
3207 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
3208 // Disable PS
3209 MACbPSWakeup(pDevice->PortOffset);
3211 pDevice->bPWBitOn = FALSE;
3213 wmb();
3214 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
3215 wmb();
3217 pDevice->iTDUsed[TYPE_TXDMA0]++;
3219 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
3220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
3223 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
3225 // Poll Transmit the adapter
3226 MACvTransmit0(pDevice->PortOffset);
3228 return;