Merge branch 'bugfixes' into nfs-for-next
[linux-2.6/kvm.git] / drivers / staging / vt6656 / rxtx.c
blob94ddf8bab62be9aa05bdb90dbe8c52da29f7574e
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 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
34 * s_uGetRTSCTSDuration- get rtx/cts requried duration
35 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
38 * s_vFillFragParameter- Set fragement ctl parameter.
39 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
45 * Revision History:
49 #include "device.h"
50 #include "rxtx.h"
51 #include "tether.h"
52 #include "card.h"
53 #include "bssdb.h"
54 #include "mac.h"
55 #include "baseband.h"
56 #include "michael.h"
57 #include "tkip.h"
58 #include "tcrc.h"
59 #include "wctl.h"
60 #include "hostap.h"
61 #include "rf.h"
62 #include "datarate.h"
63 #include "usbpipe.h"
65 #ifdef WPA_SM_Transtatus
66 #include "iocmd.h"
67 #endif
69 /*--------------------- Static Definitions -------------------------*/
71 /*--------------------- Static Classes ----------------------------*/
73 /*--------------------- Static Variables --------------------------*/
74 //static int msglevel =MSG_LEVEL_DEBUG;
75 static int msglevel =MSG_LEVEL_INFO;
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 --------------------------*/
115 static
116 VOID
117 s_vSaveTxPktInfo(
118 IN PSDevice pDevice,
119 IN BYTE byPktNum,
120 IN PBYTE pbyDestAddr,
121 IN WORD wPktLength,
122 IN WORD wFIFOCtl
125 static
126 PVOID
127 s_vGetFreeContext(
128 PSDevice pDevice
132 static
133 VOID
134 s_vGenerateTxParameter(
135 IN PSDevice pDevice,
136 IN BYTE byPktType,
137 IN WORD wCurrentRate,
138 IN PVOID pTxBufHead,
139 IN PVOID pvRrvTime,
140 IN PVOID pvRTS,
141 IN PVOID pvCTS,
142 IN UINT cbFrameSize,
143 IN BOOL bNeedACK,
144 IN UINT uDMAIdx,
145 IN PSEthernetHeader psEthHeader
149 static
150 UINT
151 s_uFillDataHead (
152 IN PSDevice pDevice,
153 IN BYTE byPktType,
154 IN WORD wCurrentRate,
155 IN PVOID pTxDataHead,
156 IN UINT cbFrameLength,
157 IN UINT uDMAIdx,
158 IN BOOL bNeedAck,
159 IN UINT uFragIdx,
160 IN UINT cbLastFragmentSize,
161 IN UINT uMACfragNum,
162 IN BYTE byFBOption
168 static
169 VOID
170 s_vGenerateMACHeader (
171 IN PSDevice pDevice,
172 IN PBYTE pbyBufferAddr,
173 IN WORD wDuration,
174 IN PSEthernetHeader psEthHeader,
175 IN BOOL bNeedEncrypt,
176 IN WORD wFragType,
177 IN UINT uDMAIdx,
178 IN UINT uFragIdx
181 static
182 VOID
183 s_vFillTxKey(
184 IN PSDevice pDevice,
185 IN PBYTE pbyBuf,
186 IN PBYTE pbyIVHead,
187 IN PSKeyItem pTransmitKey,
188 IN PBYTE pbyHdrBuf,
189 IN WORD wPayloadLen,
190 OUT PBYTE pMICHDR
193 static
194 VOID
195 s_vSWencryption (
196 IN PSDevice pDevice,
197 IN PSKeyItem pTransmitKey,
198 IN PBYTE pbyPayloadHead,
199 IN WORD wPayloadSize
202 static
203 UINT
204 s_uGetTxRsvTime (
205 IN PSDevice pDevice,
206 IN BYTE byPktType,
207 IN UINT cbFrameLength,
208 IN WORD wRate,
209 IN BOOL bNeedAck
213 static
214 UINT
215 s_uGetRTSCTSRsvTime (
216 IN PSDevice pDevice,
217 IN BYTE byRTSRsvType,
218 IN BYTE byPktType,
219 IN UINT cbFrameLength,
220 IN WORD wCurrentRate
223 static
224 VOID
225 s_vFillCTSHead (
226 IN PSDevice pDevice,
227 IN UINT uDMAIdx,
228 IN BYTE byPktType,
229 IN PVOID pvCTS,
230 IN UINT cbFrameLength,
231 IN BOOL bNeedAck,
232 IN BOOL bDisCRC,
233 IN WORD wCurrentRate,
234 IN BYTE byFBOption
237 static
238 VOID
239 s_vFillRTSHead(
240 IN PSDevice pDevice,
241 IN BYTE byPktType,
242 IN PVOID pvRTS,
243 IN UINT cbFrameLength,
244 IN BOOL bNeedAck,
245 IN BOOL bDisCRC,
246 IN PSEthernetHeader psEthHeader,
247 IN WORD wCurrentRate,
248 IN BYTE byFBOption
251 static
252 UINT
253 s_uGetDataDuration (
254 IN PSDevice pDevice,
255 IN BYTE byDurType,
256 IN UINT cbFrameLength,
257 IN BYTE byPktType,
258 IN WORD wRate,
259 IN BOOL bNeedAck,
260 IN UINT uFragIdx,
261 IN UINT cbLastFragmentSize,
262 IN UINT uMACfragNum,
263 IN BYTE byFBOption
267 static
268 UINT
269 s_uGetRTSCTSDuration (
270 IN PSDevice pDevice,
271 IN BYTE byDurType,
272 IN UINT cbFrameLength,
273 IN BYTE byPktType,
274 IN WORD wRate,
275 IN BOOL bNeedAck,
276 IN BYTE byFBOption
280 /*--------------------- Export Variables --------------------------*/
282 static
283 PVOID
284 s_vGetFreeContext(
285 PSDevice pDevice
288 PUSB_SEND_CONTEXT pContext = NULL;
289 PUSB_SEND_CONTEXT pReturnContext = NULL;
290 UINT ii;
292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
294 for (ii = 0; ii < pDevice->cbTD; ii++) {
295 pContext = pDevice->apTD[ii];
296 if (pContext->bBoolInUse == FALSE) {
297 pContext->bBoolInUse = TRUE;
298 pReturnContext = pContext;
299 break;
302 if ( ii == pDevice->cbTD ) {
303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
305 return ((PVOID) pReturnContext);
309 static
310 VOID
311 s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLength, WORD wFIFOCtl)
313 PSStatCounter pStatistic=&(pDevice->scStatistic);
316 if (IS_BROADCAST_ADDRESS(pbyDestAddr))
317 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
318 else if (IS_MULTICAST_ADDRESS(pbyDestAddr))
319 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
320 else
321 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
323 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
324 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
325 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr, pbyDestAddr, U_ETHER_ADDR_LEN);
331 static
332 VOID
333 s_vFillTxKey (
334 IN PSDevice pDevice,
335 IN PBYTE pbyBuf,
336 IN PBYTE pbyIVHead,
337 IN PSKeyItem pTransmitKey,
338 IN PBYTE pbyHdrBuf,
339 IN WORD wPayloadLen,
340 OUT PBYTE pMICHDR
343 PDWORD pdwIV = (PDWORD) pbyIVHead;
344 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
345 WORD wValue;
346 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
347 DWORD dwRevIVCounter;
351 //Fill TXKEY
352 if (pTransmitKey == NULL)
353 return;
355 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
356 *pdwIV = pDevice->dwIVCounter;
357 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
359 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
360 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
361 memcpy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
362 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
363 } else {
364 memcpy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
365 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
366 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
367 memcpy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
368 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
370 memcpy(pDevice->abyPRNG, pbyBuf, 16);
372 // Append IV after Mac Header
373 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
374 *pdwIV |= (pDevice->byKeyIndex << 30);
375 *pdwIV = cpu_to_le32(*pdwIV);
376 pDevice->dwIVCounter++;
377 if (pDevice->dwIVCounter > WEP_IV_MASK) {
378 pDevice->dwIVCounter = 0;
380 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
381 pTransmitKey->wTSC15_0++;
382 if (pTransmitKey->wTSC15_0 == 0) {
383 pTransmitKey->dwTSC47_16++;
385 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
386 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
387 memcpy(pbyBuf, pDevice->abyPRNG, 16);
388 // Make IV
389 memcpy(pdwIV, pDevice->abyPRNG, 3);
391 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
392 // Append IV&ExtIV after Mac Header
393 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
396 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
397 pTransmitKey->wTSC15_0++;
398 if (pTransmitKey->wTSC15_0 == 0) {
399 pTransmitKey->dwTSC47_16++;
401 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
403 // Make IV
404 *pdwIV = 0;
405 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
406 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
407 //Append IV&ExtIV after Mac Header
408 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
410 //Fill MICHDR0
411 *pMICHDR = 0x59;
412 *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
413 memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
414 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
415 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
416 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
417 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
418 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
419 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
420 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
421 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
423 //Fill MICHDR1
424 *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
425 if (pDevice->bLongHeader) {
426 *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
427 } else {
428 *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
430 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
431 memcpy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
432 memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
433 memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
435 //Fill MICHDR2
436 memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
437 wValue = pMACHeader->wSeqCtl;
438 wValue &= 0x000F;
439 wValue = cpu_to_le16(wValue);
440 memcpy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
441 if (pDevice->bLongHeader) {
442 memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
448 static
449 VOID
450 s_vSWencryption (
451 IN PSDevice pDevice,
452 IN PSKeyItem pTransmitKey,
453 IN PBYTE pbyPayloadHead,
454 IN WORD wPayloadSize
457 UINT cbICVlen = 4;
458 DWORD dwICV = 0xFFFFFFFFL;
459 PDWORD pdwICV;
461 if (pTransmitKey == NULL)
462 return;
464 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
465 //=======================================================================
466 // Append ICV after payload
467 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
468 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
469 // finally, we must invert dwCRC to get the correct answer
470 *pdwICV = cpu_to_le32(~dwICV);
471 // RC4 encryption
472 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
473 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
474 //=======================================================================
475 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
476 //=======================================================================
477 //Append ICV after payload
478 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
479 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
480 // finally, we must invert dwCRC to get the correct answer
481 *pdwICV = cpu_to_le32(~dwICV);
482 // RC4 encryption
483 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
484 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
485 //=======================================================================
492 /*byPktType : PK_TYPE_11A 0
493 PK_TYPE_11B 1
494 PK_TYPE_11GB 2
495 PK_TYPE_11GA 3
497 static
498 UINT
499 s_uGetTxRsvTime (
500 IN PSDevice pDevice,
501 IN BYTE byPktType,
502 IN UINT cbFrameLength,
503 IN WORD wRate,
504 IN BOOL bNeedAck
507 UINT uDataTime, uAckTime;
509 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
510 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
511 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopCCKBasicRate);
512 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
513 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopOFDMBasicRate);
516 if (bNeedAck) {
517 return (uDataTime + pDevice->uSIFS + uAckTime);
519 else {
520 return uDataTime;
524 //byFreqType: 0=>5GHZ 1=>2.4GHZ
525 static
526 UINT
527 s_uGetRTSCTSRsvTime (
528 IN PSDevice pDevice,
529 IN BYTE byRTSRsvType,
530 IN BYTE byPktType,
531 IN UINT cbFrameLength,
532 IN WORD wCurrentRate
535 UINT uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
537 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
540 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
541 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
542 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
543 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
545 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
546 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
547 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
548 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
550 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
551 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
552 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
554 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
555 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
556 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
557 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
558 return uRrvTime;
561 //RTSRrvTime
562 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
563 return uRrvTime;
566 //byFreqType 0: 5GHz, 1:2.4Ghz
567 static
568 UINT
569 s_uGetDataDuration (
570 IN PSDevice pDevice,
571 IN BYTE byDurType,
572 IN UINT cbFrameLength,
573 IN BYTE byPktType,
574 IN WORD wRate,
575 IN BOOL bNeedAck,
576 IN UINT uFragIdx,
577 IN UINT cbLastFragmentSize,
578 IN UINT uMACfragNum,
579 IN BYTE byFBOption
582 BOOL bLastFrag = 0;
583 UINT uAckTime =0, uNextPktTime = 0;
586 if (uFragIdx == (uMACfragNum-1)) {
587 bLastFrag = 1;
590 switch (byDurType) {
592 case DATADUR_B: //DATADUR_B
593 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
594 if (bNeedAck) {
595 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
596 return (pDevice->uSIFS + uAckTime);
597 } else {
598 return 0;
601 else {//First Frag or Mid Frag
602 if (uFragIdx == (uMACfragNum-2)) {
603 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
604 } else {
605 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
607 if (bNeedAck) {
608 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
609 return (pDevice->uSIFS + uAckTime + uNextPktTime);
610 } else {
611 return (pDevice->uSIFS + uNextPktTime);
614 break;
617 case DATADUR_A: //DATADUR_A
618 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
619 if(bNeedAck){
620 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
621 return (pDevice->uSIFS + uAckTime);
622 } else {
623 return 0;
626 else {//First Frag or Mid Frag
627 if(uFragIdx == (uMACfragNum-2)){
628 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
629 } else {
630 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
632 if(bNeedAck){
633 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
634 return (pDevice->uSIFS + uAckTime + uNextPktTime);
635 } else {
636 return (pDevice->uSIFS + uNextPktTime);
639 break;
641 case DATADUR_A_F0: //DATADUR_A_F0
642 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
643 if(bNeedAck){
644 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
645 return (pDevice->uSIFS + uAckTime);
646 } else {
647 return 0;
650 else { //First Frag or Mid Frag
651 if (byFBOption == AUTO_FB_0) {
652 if (wRate < RATE_18M)
653 wRate = RATE_18M;
654 else if (wRate > RATE_54M)
655 wRate = RATE_54M;
657 if(uFragIdx == (uMACfragNum-2)){
658 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
659 } else {
660 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
662 } else { // (byFBOption == AUTO_FB_1)
663 if (wRate < RATE_18M)
664 wRate = RATE_18M;
665 else if (wRate > RATE_54M)
666 wRate = RATE_54M;
668 if(uFragIdx == (uMACfragNum-2)){
669 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
670 } else {
671 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
675 if(bNeedAck){
676 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
677 return (pDevice->uSIFS + uAckTime + uNextPktTime);
678 } else {
679 return (pDevice->uSIFS + uNextPktTime);
682 break;
684 case DATADUR_A_F1: //DATADUR_A_F1
685 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
686 if(bNeedAck){
687 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
688 return (pDevice->uSIFS + uAckTime);
689 } else {
690 return 0;
693 else { //First Frag or Mid Frag
694 if (byFBOption == AUTO_FB_0) {
695 if (wRate < RATE_18M)
696 wRate = RATE_18M;
697 else if (wRate > RATE_54M)
698 wRate = RATE_54M;
700 if(uFragIdx == (uMACfragNum-2)){
701 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
702 } else {
703 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
706 } else { // (byFBOption == AUTO_FB_1)
707 if (wRate < RATE_18M)
708 wRate = RATE_18M;
709 else if (wRate > RATE_54M)
710 wRate = RATE_54M;
712 if(uFragIdx == (uMACfragNum-2)){
713 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
714 } else {
715 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
718 if(bNeedAck){
719 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
720 return (pDevice->uSIFS + uAckTime + uNextPktTime);
721 } else {
722 return (pDevice->uSIFS + uNextPktTime);
725 break;
727 default:
728 break;
731 ASSERT(FALSE);
732 return 0;
736 //byFreqType: 0=>5GHZ 1=>2.4GHZ
737 static
738 UINT
739 s_uGetRTSCTSDuration (
740 IN PSDevice pDevice,
741 IN BYTE byDurType,
742 IN UINT cbFrameLength,
743 IN BYTE byPktType,
744 IN WORD wRate,
745 IN BOOL bNeedAck,
746 IN BYTE byFBOption
749 UINT uCTSTime = 0, uDurTime = 0;
752 switch (byDurType) {
754 case RTSDUR_BB: //RTSDuration_bb
755 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
756 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
757 break;
759 case RTSDUR_BA: //RTSDuration_ba
760 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
761 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
762 break;
764 case RTSDUR_AA: //RTSDuration_aa
765 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
766 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
767 break;
769 case CTSDUR_BA: //CTSDuration_ba
770 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
771 break;
773 case RTSDUR_BA_F0: //RTSDuration_ba_f0
774 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
775 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
776 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
777 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
778 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
780 break;
782 case RTSDUR_AA_F0: //RTSDuration_aa_f0
783 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
784 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
785 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
786 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
787 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
789 break;
791 case RTSDUR_BA_F1: //RTSDuration_ba_f1
792 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
793 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
794 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
795 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
796 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
798 break;
800 case RTSDUR_AA_F1: //RTSDuration_aa_f1
801 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
802 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
803 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
804 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
805 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
807 break;
809 case CTSDUR_BA_F0: //CTSDuration_ba_f0
810 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
811 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
812 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
813 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
815 break;
817 case CTSDUR_BA_F1: //CTSDuration_ba_f1
818 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
819 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
820 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
821 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
823 break;
825 default:
826 break;
829 return uDurTime;
836 static
837 UINT
838 s_uFillDataHead (
839 IN PSDevice pDevice,
840 IN BYTE byPktType,
841 IN WORD wCurrentRate,
842 IN PVOID pTxDataHead,
843 IN UINT cbFrameLength,
844 IN UINT uDMAIdx,
845 IN BOOL bNeedAck,
846 IN UINT uFragIdx,
847 IN UINT cbLastFragmentSize,
848 IN UINT uMACfragNum,
849 IN BYTE byFBOption
853 if (pTxDataHead == NULL) {
854 return 0;
857 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
858 if((uDMAIdx==TYPE_ATIMDMA)||(uDMAIdx==TYPE_BEACONDMA)) {
859 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
860 //Get SignalField,ServiceField,Length
861 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
862 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
864 //Get Duration and TimeStampOff
865 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
866 wCurrentRate, bNeedAck, uFragIdx,
867 cbLastFragmentSize, uMACfragNum,
868 byFBOption); //1: 2.4GHz
869 if(uDMAIdx!=TYPE_ATIMDMA) {
870 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
872 return (pBuf->wDuration);
874 else { // DATA & MANAGE Frame
875 if (byFBOption == AUTO_FB_NONE) {
876 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
877 //Get SignalField,ServiceField,Length
878 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
879 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
881 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
882 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
884 //Get Duration and TimeStamp
885 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
886 byPktType, wCurrentRate, bNeedAck, uFragIdx,
887 cbLastFragmentSize, uMACfragNum,
888 byFBOption); //1: 2.4GHz
889 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
890 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
891 bNeedAck, uFragIdx, cbLastFragmentSize,
892 uMACfragNum, byFBOption); //1: 2.4GHz
894 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
895 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
896 return (pBuf->wDuration_a);
897 } else {
898 // Auto Fallback
899 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
900 //Get SignalField,ServiceField,Length
901 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
902 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
904 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
905 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
907 //Get Duration and TimeStamp
908 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
909 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
910 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
911 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
912 pBuf->wDuration_a_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
913 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
914 pBuf->wDuration_a_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
915 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
916 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
917 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
918 return (pBuf->wDuration_a);
919 } //if (byFBOption == AUTO_FB_NONE)
922 else if (byPktType == PK_TYPE_11A) {
923 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
924 // Auto Fallback
925 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
926 //Get SignalField,ServiceField,Length
927 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
928 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
930 //Get Duration and TimeStampOff
931 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
932 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
933 pBuf->wDuration_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
934 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
935 pBuf->wDuration_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
936 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
937 if(uDMAIdx!=TYPE_ATIMDMA) {
938 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
940 return (pBuf->wDuration);
941 } else {
942 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
943 //Get SignalField,ServiceField,Length
944 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
945 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
947 //Get Duration and TimeStampOff
948 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
949 wCurrentRate, bNeedAck, uFragIdx,
950 cbLastFragmentSize, uMACfragNum,
951 byFBOption);
953 if(uDMAIdx!=TYPE_ATIMDMA) {
954 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
956 return (pBuf->wDuration);
959 else if (byPktType == PK_TYPE_11B) {
960 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
961 //Get SignalField,ServiceField,Length
962 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
963 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
965 //Get Duration and TimeStampOff
966 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
967 wCurrentRate, bNeedAck, uFragIdx,
968 cbLastFragmentSize, uMACfragNum,
969 byFBOption);
970 if (uDMAIdx != TYPE_ATIMDMA) {
971 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
973 return (pBuf->wDuration);
975 return 0;
981 static
982 VOID
983 s_vFillRTSHead (
984 IN PSDevice pDevice,
985 IN BYTE byPktType,
986 IN PVOID pvRTS,
987 IN UINT cbFrameLength,
988 IN BOOL bNeedAck,
989 IN BOOL bDisCRC,
990 IN PSEthernetHeader psEthHeader,
991 IN WORD wCurrentRate,
992 IN BYTE byFBOption
995 UINT uRTSFrameLen = 20;
996 WORD wLen = 0x0000;
998 if (pvRTS == NULL)
999 return;
1001 if (bDisCRC) {
1002 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
1003 // in this case we need to decrease its length by 4.
1004 uRTSFrameLen -= 4;
1007 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
1008 // Otherwise, we need to modified codes for them.
1009 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1010 if (byFBOption == AUTO_FB_NONE) {
1011 PSRTS_g pBuf = (PSRTS_g)pvRTS;
1012 //Get SignalField,ServiceField,Length
1013 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1014 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1016 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1017 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1018 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1020 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1021 //Get Duration
1022 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
1023 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
1024 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
1026 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1027 //Get RTS Frame body
1028 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1029 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1030 (pDevice->eOPMode == OP_MODE_AP)) {
1031 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1033 else {
1034 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1036 if (pDevice->eOPMode == OP_MODE_AP) {
1037 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1039 else {
1040 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1043 else {
1044 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
1045 //Get SignalField,ServiceField,Length
1046 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1047 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1049 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1050 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1051 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1053 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1054 //Get Duration
1055 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
1056 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
1057 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
1058 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
1059 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
1060 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
1061 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
1062 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1063 //Get RTS Frame body
1064 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1066 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1067 (pDevice->eOPMode == OP_MODE_AP)) {
1068 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1070 else {
1071 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1074 if (pDevice->eOPMode == OP_MODE_AP) {
1075 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1077 else {
1078 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1081 } // if (byFBOption == AUTO_FB_NONE)
1083 else if (byPktType == PK_TYPE_11A) {
1084 if (byFBOption == AUTO_FB_NONE) {
1085 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1086 //Get SignalField,ServiceField,Length
1087 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1088 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1090 pBuf->wTransmitLength = cpu_to_le16(wLen);
1091 //Get Duration
1092 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1093 pBuf->Data.wDurationID = pBuf->wDuration;
1094 //Get RTS Frame body
1095 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1097 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1098 (pDevice->eOPMode == OP_MODE_AP)) {
1099 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1101 else {
1102 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1105 if (pDevice->eOPMode == OP_MODE_AP) {
1106 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1108 else {
1109 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1113 else {
1114 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
1115 //Get SignalField,ServiceField,Length
1116 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1117 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1119 pBuf->wTransmitLength = cpu_to_le16(wLen);
1120 //Get Duration
1121 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1122 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
1123 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:
1124 pBuf->Data.wDurationID = pBuf->wDuration;
1125 //Get RTS Frame body
1126 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1128 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1129 (pDevice->eOPMode == OP_MODE_AP)) {
1130 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1132 else {
1133 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1135 if (pDevice->eOPMode == OP_MODE_AP) {
1136 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1138 else {
1139 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1143 else if (byPktType == PK_TYPE_11B) {
1144 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1145 //Get SignalField,ServiceField,Length
1146 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1147 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1149 pBuf->wTransmitLength = cpu_to_le16(wLen);
1150 //Get Duration
1151 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1152 pBuf->Data.wDurationID = pBuf->wDuration;
1153 //Get RTS Frame body
1154 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1157 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1158 (pDevice->eOPMode == OP_MODE_AP)) {
1159 memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1161 else {
1162 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1165 if (pDevice->eOPMode == OP_MODE_AP) {
1166 memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1168 else {
1169 memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1174 static
1175 VOID
1176 s_vFillCTSHead (
1177 IN PSDevice pDevice,
1178 IN UINT uDMAIdx,
1179 IN BYTE byPktType,
1180 IN PVOID pvCTS,
1181 IN UINT cbFrameLength,
1182 IN BOOL bNeedAck,
1183 IN BOOL bDisCRC,
1184 IN WORD wCurrentRate,
1185 IN BYTE byFBOption
1188 UINT uCTSFrameLen = 14;
1189 WORD wLen = 0x0000;
1191 if (pvCTS == NULL) {
1192 return;
1195 if (bDisCRC) {
1196 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1197 // in this case we need to decrease its length by 4.
1198 uCTSFrameLen -= 4;
1201 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1202 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1203 // Auto Fall back
1204 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1205 //Get SignalField,ServiceField,Length
1206 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1207 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1209 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1210 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
1211 pBuf->wDuration_ba += pDevice->wCTSDuration;
1212 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1213 //Get CTSDuration_ba_f0
1214 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
1215 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1216 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1217 //Get CTSDuration_ba_f1
1218 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
1219 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1220 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1221 //Get CTS Frame body
1222 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1223 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1224 pBuf->Data.wReserved = 0x0000;
1225 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1226 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1227 PSCTS pBuf = (PSCTS)pvCTS;
1228 //Get SignalField,ServiceField,Length
1229 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1230 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1232 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1233 //Get CTSDuration_ba
1234 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
1235 pBuf->wDuration_ba += pDevice->wCTSDuration;
1236 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1238 //Get CTS Frame body
1239 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1240 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1241 pBuf->Data.wReserved = 0x0000;
1242 memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1254 * Description:
1255 * Generate FIFO control for MAC & Baseband controller
1257 * Parameters:
1258 * In:
1259 * pDevice - Pointer to adpater
1260 * pTxDataHead - Transmit Data Buffer
1261 * pTxBufHead - pTxBufHead
1262 * pvRrvTime - pvRrvTime
1263 * pvRTS - RTS Buffer
1264 * pCTS - CTS Buffer
1265 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1266 * bNeedACK - If need ACK
1267 * uDMAIdx - DMA Index
1268 * Out:
1269 * none
1271 * Return Value: none
1274 // UINT cbFrameSize,//Hdr+Payload+FCS
1275 static
1276 VOID
1277 s_vGenerateTxParameter (
1278 IN PSDevice pDevice,
1279 IN BYTE byPktType,
1280 IN WORD wCurrentRate,
1281 IN PVOID pTxBufHead,
1282 IN PVOID pvRrvTime,
1283 IN PVOID pvRTS,
1284 IN PVOID pvCTS,
1285 IN UINT cbFrameSize,
1286 IN BOOL bNeedACK,
1287 IN UINT uDMAIdx,
1288 IN PSEthernetHeader psEthHeader
1291 UINT cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1292 WORD wFifoCtl;
1293 BOOL bDisCRC = FALSE;
1294 BYTE byFBOption = AUTO_FB_NONE;
1295 // WORD wCurrentRate = pDevice->wCurrentRate;
1297 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1298 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1299 pFifoHead->wReserved = wCurrentRate;
1300 wFifoCtl = pFifoHead->wFIFOCtl;
1302 if (wFifoCtl & FIFOCTL_CRCDIS) {
1303 bDisCRC = TRUE;
1306 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1307 byFBOption = AUTO_FB_0;
1309 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1310 byFBOption = AUTO_FB_1;
1313 if (pDevice->bLongHeader)
1314 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1316 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1318 if (pvRTS != NULL) { //RTS_need
1319 //Fill RsvTime
1320 if (pvRrvTime) {
1321 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1322 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1323 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1324 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1325 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1326 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1328 //Fill RTS
1329 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1331 else {//RTS_needless, PCF mode
1333 //Fill RsvTime
1334 if (pvRrvTime) {
1335 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1336 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1337 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1338 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1340 //Fill CTS
1341 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1344 else if (byPktType == PK_TYPE_11A) {
1346 if (pvRTS != NULL) {//RTS_need, non PCF mode
1347 //Fill RsvTime
1348 if (pvRrvTime) {
1349 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1350 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1351 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1353 //Fill RTS
1354 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1356 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1357 //Fill RsvTime
1358 if (pvRrvTime) {
1359 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1360 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1364 else if (byPktType == PK_TYPE_11B) {
1366 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1367 //Fill RsvTime
1368 if (pvRrvTime) {
1369 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1370 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1371 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1373 //Fill RTS
1374 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1376 else { //RTS_needless, non PCF mode
1377 //Fill RsvTime
1378 if (pvRrvTime) {
1379 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1380 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1384 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1387 PBYTE pbyBuffer,//point to pTxBufHead
1388 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1389 UINT cbFragmentSize,//Hdr+payoad+FCS
1393 BOOL
1394 s_bPacketToWirelessUsb(
1395 IN PSDevice pDevice,
1396 IN BYTE byPktType,
1397 IN PBYTE usbPacketBuf,
1398 IN BOOL bNeedEncryption,
1399 IN UINT uSkbPacketLen,
1400 IN UINT uDMAIdx,
1401 IN PSEthernetHeader psEthHeader,
1402 IN PBYTE pPacket,
1403 IN PSKeyItem pTransmitKey,
1404 IN UINT uNodeIndex,
1405 IN WORD wCurrentRate,
1406 OUT UINT *pcbHeaderLen,
1407 OUT UINT *pcbTotalLen
1410 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1411 UINT cbFrameSize,cbFrameBodySize;
1412 PTX_BUFFER pTxBufHead;
1413 UINT cb802_1_H_len;
1414 UINT cbIVlen=0,cbICVlen=0,cbMIClen=0,cbMACHdLen=0,cbFCSlen=4;
1415 UINT cbMICHDR = 0;
1416 BOOL bNeedACK,bRTS;
1417 PBYTE pbyType,pbyMacHdr,pbyIVHead,pbyPayloadHead,pbyTxBufferAddr;
1418 BYTE abySNAP_RFC1042[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1419 BYTE abySNAP_Bridgetunnel[6] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1420 UINT uDuration;
1421 UINT cbHeaderLength= 0,uPadding = 0;
1422 PVOID pvRrvTime;
1423 PSMICHDRHead pMICHDR;
1424 PVOID pvRTS;
1425 PVOID pvCTS;
1426 PVOID pvTxDataHd;
1427 BYTE byFBOption = AUTO_FB_NONE,byFragType;
1428 WORD wTxBufSize;
1429 DWORD dwMICKey0,dwMICKey1,dwMIC_Priority,dwCRC;
1430 PDWORD pdwMIC_L,pdwMIC_R;
1431 BOOL bSoftWEP = FALSE;
1436 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1437 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1438 if (((PSKeyTable) (pTransmitKey->pvKeyTable))->bSoftWEP == TRUE) {
1439 // WEP 256
1440 bSoftWEP = TRUE;
1444 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
1445 memset(pTxBufHead, 0, sizeof(TX_BUFFER));
1447 // Get pkt type
1448 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
1449 if (pDevice->dwDiagRefCount == 0) {
1450 cb802_1_H_len = 8;
1451 } else {
1452 cb802_1_H_len = 2;
1454 } else {
1455 cb802_1_H_len = 0;
1458 cbFrameBodySize = uSkbPacketLen - U_HEADER_LEN + cb802_1_H_len;
1460 //Set packet type
1461 pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8);
1463 if (pDevice->dwDiagRefCount != 0) {
1464 bNeedACK = FALSE;
1465 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1466 } else { //if (pDevice->dwDiagRefCount != 0) {
1467 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1468 (pDevice->eOPMode == OP_MODE_AP)) {
1469 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
1470 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
1471 bNeedACK = FALSE;
1472 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1474 else {
1475 bNeedACK = TRUE;
1476 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1479 else {
1480 // MSDUs in Infra mode always need ACK
1481 bNeedACK = TRUE;
1482 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1484 } //if (pDevice->dwDiagRefCount != 0) {
1486 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1488 //Set FIFOCTL_LHEAD
1489 if (pDevice->bLongHeader)
1490 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1492 if (pDevice->bSoftwareGenCrcErr) {
1493 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1496 //Set FRAGCTL_MACHDCNT
1497 if (pDevice->bLongHeader) {
1498 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1499 } else {
1500 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1502 pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10);
1504 //Set FIFOCTL_GrpAckPolicy
1505 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
1506 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1509 //Set Auto Fallback Ctl
1510 if (wCurrentRate >= RATE_18M) {
1511 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1512 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1513 byFBOption = AUTO_FB_0;
1514 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1515 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1516 byFBOption = AUTO_FB_1;
1520 if (bSoftWEP != TRUE) {
1521 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1522 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1523 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1525 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1526 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1527 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1529 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1530 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1536 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1537 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1538 cbIVlen = 4;
1539 cbICVlen = 4;
1541 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1542 cbIVlen = 8;//IV+ExtIV
1543 cbMIClen = 8;
1544 cbICVlen = 4;
1546 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1547 cbIVlen = 8;//RSN Header
1548 cbICVlen = 8;//MIC
1549 cbMICHDR = sizeof(SMICHDRHead);
1551 if (bSoftWEP == FALSE) {
1552 //MAC Header should be padding 0 to DW alignment.
1553 uPadding = 4 - (cbMACHdLen%4);
1554 uPadding %= 4;
1558 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1560 if ( (bNeedACK == FALSE) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1561 bRTS = FALSE;
1562 } else {
1563 bRTS = TRUE;
1564 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1567 pbyTxBufferAddr = (PBYTE) &(pTxBufHead->adwTxKey[0]);
1568 wTxBufSize = sizeof(STxBufHead);
1569 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1570 if (byFBOption == AUTO_FB_NONE) {
1571 if (bRTS == TRUE) {//RTS_need
1572 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1573 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1574 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1575 pvCTS = NULL;
1576 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1577 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1579 else { //RTS_needless
1580 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1581 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1582 pvRTS = NULL;
1583 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1584 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1585 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1587 } else {
1588 // Auto Fall Back
1589 if (bRTS == TRUE) {//RTS_need
1590 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1591 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1592 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1593 pvCTS = NULL;
1594 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1595 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1597 else if (bRTS == FALSE) { //RTS_needless
1598 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1599 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1600 pvRTS = NULL;
1601 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1602 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1603 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1605 } // Auto Fall Back
1607 else {//802.11a/b packet
1608 if (byFBOption == AUTO_FB_NONE) {
1609 if (bRTS == TRUE) {//RTS_need
1610 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1611 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1612 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1613 pvCTS = NULL;
1614 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1615 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1617 else if (bRTS == FALSE) { //RTS_needless, no MICHDR
1618 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1619 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1620 pvRTS = NULL;
1621 pvCTS = NULL;
1622 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1623 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1625 } else {
1626 // Auto Fall Back
1627 if (bRTS == TRUE) {//RTS_need
1628 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1629 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1630 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1631 pvCTS = NULL;
1632 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1633 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1635 else if (bRTS == FALSE) { //RTS_needless
1636 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1637 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1638 pvRTS = NULL;
1639 pvCTS = NULL;
1640 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1641 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1643 } // Auto Fall Back
1646 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1647 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1648 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1651 //=========================
1652 // No Fragmentation
1653 //=========================
1654 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1655 byFragType = FRAGCTL_NONFRAG;
1656 //uDMAIdx = TYPE_AC0DMA;
1657 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1660 //Fill FIFO,RrvTime,RTS,and CTS
1661 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, (PVOID)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
1662 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1663 //Fill DataHead
1664 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1665 0, 0, 1/*uMACfragNum*/, byFBOption);
1666 // Generate TX MAC Header
1667 s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption,
1668 byFragType, uDMAIdx, 0);
1670 if (bNeedEncryption == TRUE) {
1671 //Fill TXKEY
1672 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1673 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
1675 if (pDevice->bEnableHostWEP) {
1676 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1677 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1681 // 802.1H
1682 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
1683 if (pDevice->dwDiagRefCount == 0) {
1684 if ( (psEthHeader->wType == TYPE_PKT_IPX) ||
1685 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1686 memcpy((PBYTE) (pbyPayloadHead), &abySNAP_Bridgetunnel[0], 6);
1687 } else {
1688 memcpy((PBYTE) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1690 pbyType = (PBYTE) (pbyPayloadHead + 6);
1691 memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1692 } else {
1693 memcpy((PBYTE) (pbyPayloadHead), &(psEthHeader->wType), sizeof(WORD));
1700 if (pPacket != NULL) {
1701 // Copy the Packet into a tx Buffer
1702 memcpy((pbyPayloadHead + cb802_1_H_len),
1703 (pPacket + U_HEADER_LEN),
1704 uSkbPacketLen - U_HEADER_LEN
1707 } else {
1708 // while bRelayPacketSend psEthHeader is point to header+payload
1709 memcpy((pbyPayloadHead + cb802_1_H_len), ((PBYTE)psEthHeader)+U_HEADER_LEN, uSkbPacketLen - U_HEADER_LEN);
1712 ASSERT(uLength == cbNdisBodySize);
1714 if ((bNeedEncryption == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1716 ///////////////////////////////////////////////////////////////////
1718 if (pDevice->sMgmtObj.eAuthenMode == WMAC_AUTH_WPANONE) {
1719 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1720 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1722 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1723 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1724 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1726 else {
1727 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1728 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1730 // DO Software Michael
1731 MIC_vInit(dwMICKey0, dwMICKey1);
1732 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1733 dwMIC_Priority = 0;
1734 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1735 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1737 ///////////////////////////////////////////////////////////////////
1739 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1740 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1741 // DBG_PRN_GRP12(("%02x ", *((PBYTE)((pbyPayloadHead + cb802_1_H_len) + ii))));
1743 //DBG_PRN_GRP12(("\n\n\n"));
1745 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1747 pdwMIC_L = (PDWORD)(pbyPayloadHead + cbFrameBodySize);
1748 pdwMIC_R = (PDWORD)(pbyPayloadHead + cbFrameBodySize + 4);
1750 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1751 MIC_vUnInit();
1753 if (pDevice->bTxMICFail == TRUE) {
1754 *pdwMIC_L = 0;
1755 *pdwMIC_R = 0;
1756 pDevice->bTxMICFail = FALSE;
1758 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1759 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1760 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1764 if (bSoftWEP == TRUE) {
1766 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen));
1768 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == TRUE)) ||
1769 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == TRUE)) ||
1770 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == TRUE)) ) {
1771 cbFrameSize -= cbICVlen;
1774 if (pDevice->bSoftwareGenCrcErr == TRUE) {
1775 UINT cbLen;
1776 PDWORD pdwCRC;
1778 dwCRC = 0xFFFFFFFFL;
1779 cbLen = cbFrameSize - cbFCSlen;
1780 // calculate CRC, and wrtie CRC value to end of TD
1781 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
1782 pdwCRC = (PDWORD)(pbyMacHdr + cbLen);
1783 // finally, we must invert dwCRC to get the correct answer
1784 *pdwCRC = ~dwCRC;
1785 // Force Error
1786 *pdwCRC -= 1;
1787 } else {
1788 cbFrameSize -= cbFCSlen;
1791 *pcbHeaderLen = cbHeaderLength;
1792 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1795 //Set FragCtl in TxBufferHead
1796 pTxBufHead->wFragCtl |= (WORD)byFragType;
1799 return TRUE;
1806 * Description:
1807 * Translate 802.3 to 802.11 header
1809 * Parameters:
1810 * In:
1811 * pDevice - Pointer to adpater
1812 * dwTxBufferAddr - Transmit Buffer
1813 * pPacket - Packet from upper layer
1814 * cbPacketSize - Transmit Data Length
1815 * Out:
1816 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1817 * pcbAppendPayload - size of append payload for 802.1H translation
1819 * Return Value: none
1823 VOID
1824 s_vGenerateMACHeader (
1825 IN PSDevice pDevice,
1826 IN PBYTE pbyBufferAddr,
1827 IN WORD wDuration,
1828 IN PSEthernetHeader psEthHeader,
1829 IN BOOL bNeedEncrypt,
1830 IN WORD wFragType,
1831 IN UINT uDMAIdx,
1832 IN UINT uFragIdx
1835 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
1837 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
1839 if (uDMAIdx == TYPE_ATIMDMA) {
1840 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
1841 } else {
1842 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
1845 if (pDevice->eOPMode == OP_MODE_AP) {
1846 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1847 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1848 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1849 pMACHeader->wFrameCtl |= FC_FROMDS;
1851 else {
1852 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1853 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1854 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1855 memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1857 else {
1858 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1859 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1860 memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1861 pMACHeader->wFrameCtl |= FC_TODS;
1865 if (bNeedEncrypt)
1866 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
1868 pMACHeader->wDurationID = cpu_to_le16(wDuration);
1870 if (pDevice->bLongHeader) {
1871 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1872 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
1873 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
1875 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1877 //Set FragNumber in Sequence Control
1878 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
1880 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1881 pDevice->wSeqCounter++;
1882 if (pDevice->wSeqCounter > 0x0fff)
1883 pDevice->wSeqCounter = 0;
1886 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1887 pMACHeader->wFrameCtl |= FC_MOREFRAG;
1895 * Description:
1896 * Request instructs a MAC to transmit a 802.11 management packet through
1897 * the adapter onto the medium.
1899 * Parameters:
1900 * In:
1901 * hDeviceContext - Pointer to the adapter
1902 * pPacket - A pointer to a descriptor for the packet to transmit
1903 * Out:
1904 * none
1906 * Return Value: CMD_STATUS_PENDING if MAC Tx resource avaliable; otherwise FALSE
1910 CMD_STATUS csMgmt_xmit(
1911 IN PSDevice pDevice,
1912 IN PSTxMgmtPacket pPacket
1915 BYTE byPktType;
1916 PBYTE pbyTxBufferAddr;
1917 PVOID pvRTS;
1918 PSCTS pCTS;
1919 PVOID pvTxDataHd;
1920 UINT uDuration;
1921 UINT cbReqCount;
1922 PS802_11Header pMACHeader;
1923 UINT cbHeaderSize;
1924 UINT cbFrameBodySize;
1925 BOOL bNeedACK;
1926 BOOL bIsPSPOLL = FALSE;
1927 PSTxBufHead pTxBufHead;
1928 UINT cbFrameSize;
1929 UINT cbIVlen = 0;
1930 UINT cbICVlen = 0;
1931 UINT cbMIClen = 0;
1932 UINT cbFCSlen = 4;
1933 UINT uPadding = 0;
1934 WORD wTxBufSize;
1935 UINT cbMacHdLen;
1936 SEthernetHeader sEthHeader;
1937 PVOID pvRrvTime;
1938 PVOID pMICHDR;
1939 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1940 WORD wCurrentRate = RATE_1M;
1941 PTX_BUFFER pTX_Buffer;
1942 PUSB_SEND_CONTEXT pContext;
1946 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1948 if (NULL == pContext) {
1949 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1950 return CMD_STATUS_RESOURCES;
1953 pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
1954 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->adwTxKey[0]);
1955 cbFrameBodySize = pPacket->cbPayloadLen;
1956 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1957 wTxBufSize = sizeof(STxBufHead);
1958 memset(pTxBufHead, 0, wTxBufSize);
1960 if (pDevice->byBBType == BB_TYPE_11A) {
1961 wCurrentRate = RATE_6M;
1962 byPktType = PK_TYPE_11A;
1963 } else {
1964 wCurrentRate = RATE_1M;
1965 byPktType = PK_TYPE_11B;
1968 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1969 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1970 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1971 // to set power here.
1972 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1973 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1974 } else {
1975 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1977 pDevice->wCurrentRate = wCurrentRate;
1980 //Set packet type
1981 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1982 pTxBufHead->wFIFOCtl = 0;
1984 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1985 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1987 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1988 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1990 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1991 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1994 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1995 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1998 if (IS_MULTICAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0])) ||
1999 IS_BROADCAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0]))) {
2000 bNeedACK = FALSE;
2002 else {
2003 bNeedACK = TRUE;
2004 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2007 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2008 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2010 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2011 //Set Preamble type always long
2012 //pDevice->byPreambleType = PREAMBLE_LONG;
2013 // probe-response don't retry
2014 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2015 // bNeedACK = FALSE;
2016 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2020 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2022 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2023 bIsPSPOLL = TRUE;
2024 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2025 } else {
2026 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2029 //Set FRAGCTL_MACHDCNT
2030 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2032 // Notes:
2033 // Although spec says MMPDU can be fragmented; In most case,
2034 // no one will send a MMPDU under fragmentation. With RTS may occur.
2035 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2037 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2038 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2039 cbIVlen = 4;
2040 cbICVlen = 4;
2041 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2043 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2044 cbIVlen = 8;//IV+ExtIV
2045 cbMIClen = 8;
2046 cbICVlen = 4;
2047 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2048 //We need to get seed here for filling TxKey entry.
2049 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2050 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2052 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2053 cbIVlen = 8;//RSN Header
2054 cbICVlen = 8;//MIC
2055 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2056 pDevice->bAES = TRUE;
2058 //MAC Header should be padding 0 to DW alignment.
2059 uPadding = 4 - (cbMacHdLen%4);
2060 uPadding %= 4;
2063 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2065 //Set FIFOCTL_GrpAckPolicy
2066 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2067 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2069 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2071 //Set RrvTime/RTS/CTS Buffer
2072 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2074 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2075 pMICHDR = NULL;
2076 pvRTS = NULL;
2077 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2078 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2079 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2081 else { // 802.11a/b packet
2082 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2083 pMICHDR = NULL;
2084 pvRTS = NULL;
2085 pCTS = NULL;
2086 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2087 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2090 memset((PVOID)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
2092 memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
2093 memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
2094 //=========================
2095 // No Fragmentation
2096 //=========================
2097 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2100 //Fill FIFO,RrvTime,RTS,and CTS
2101 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2102 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2104 //Fill DataHead
2105 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2106 0, 0, 1, AUTO_FB_NONE);
2108 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2110 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2112 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2113 PBYTE pbyIVHead;
2114 PBYTE pbyPayloadHead;
2115 PBYTE pbyBSSID;
2116 PSKeyItem pTransmitKey = NULL;
2118 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2119 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2120 do {
2121 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2122 (pDevice->bLinkPass == TRUE)) {
2123 pbyBSSID = pDevice->abyBSSID;
2124 // get pairwise key
2125 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2126 // get group key
2127 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2128 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2129 break;
2131 } else {
2132 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2133 break;
2136 // get group key
2137 pbyBSSID = pDevice->abyBroadcastAddr;
2138 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2139 pTransmitKey = NULL;
2140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2141 } else {
2142 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2144 } while(FALSE);
2145 //Fill TXKEY
2146 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2147 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2149 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2150 memcpy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2151 cbFrameBodySize);
2153 else {
2154 // Copy the Packet into a tx Buffer
2155 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2158 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2159 pDevice->wSeqCounter++ ;
2160 if (pDevice->wSeqCounter > 0x0fff)
2161 pDevice->wSeqCounter = 0;
2163 if (bIsPSPOLL) {
2164 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2165 // of FIFO control header.
2166 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2167 // in the same place of other packet's Duration-field).
2168 // And it will cause Cisco-AP to issue Disassociation-packet
2169 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2170 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2171 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2172 } else {
2173 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2178 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2179 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2180 pTX_Buffer->byType = 0x00;
2182 pContext->pPacket = NULL;
2183 pContext->Type = CONTEXT_MGMT_PACKET;
2184 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2186 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2187 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2189 else {
2190 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2193 PIPEnsSendBulkOut(pDevice,pContext);
2194 return CMD_STATUS_PENDING;
2198 CMD_STATUS
2199 csBeacon_xmit(
2200 IN PSDevice pDevice,
2201 IN PSTxMgmtPacket pPacket
2205 UINT cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2206 UINT cbHeaderSize = 0;
2207 WORD wTxBufSize = sizeof(STxShortBufHead);
2208 PSTxShortBufHead pTxBufHead;
2209 PS802_11Header pMACHeader;
2210 PSTxDataHead_ab pTxDataHead;
2211 WORD wCurrentRate;
2212 UINT cbFrameBodySize;
2213 UINT cbReqCount;
2214 PBEACON_BUFFER pTX_Buffer;
2215 PBYTE pbyTxBufferAddr;
2216 PUSB_SEND_CONTEXT pContext;
2217 CMD_STATUS status;
2220 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2221 if (NULL == pContext) {
2222 status = CMD_STATUS_RESOURCES;
2223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
2224 return status ;
2226 pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
2227 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->wFIFOCtl);
2229 cbFrameBodySize = pPacket->cbPayloadLen;
2231 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
2232 wTxBufSize = sizeof(STxShortBufHead);
2233 memset(pTxBufHead, 0, wTxBufSize);
2235 if (pDevice->byBBType == BB_TYPE_11A) {
2236 wCurrentRate = RATE_6M;
2237 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2238 //Get SignalField,ServiceField,Length
2239 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
2240 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2242 //Get Duration and TimeStampOff
2243 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
2244 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2245 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2246 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2247 } else {
2248 wCurrentRate = RATE_1M;
2249 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2250 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2251 //Get SignalField,ServiceField,Length
2252 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
2253 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2255 //Get Duration and TimeStampOff
2256 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
2257 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2258 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2259 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2262 //Generate Beacon Header
2263 pMACHeader = (PS802_11Header)(pbyTxBufferAddr + cbHeaderSize);
2264 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2266 pMACHeader->wDurationID = 0;
2267 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2268 pDevice->wSeqCounter++ ;
2269 if (pDevice->wSeqCounter > 0x0fff)
2270 pDevice->wSeqCounter = 0;
2272 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
2274 pTX_Buffer->wTxByteCount = (WORD)cbReqCount;
2275 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2276 pTX_Buffer->byType = 0x01;
2278 pContext->pPacket = NULL;
2279 pContext->Type = CONTEXT_MGMT_PACKET;
2280 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2282 PIPEnsSendBulkOut(pDevice,pContext);
2283 return CMD_STATUS_PENDING;
2291 VOID
2292 vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2294 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2295 BYTE byPktType;
2296 PBYTE pbyTxBufferAddr;
2297 PVOID pvRTS;
2298 PVOID pvCTS;
2299 PVOID pvTxDataHd;
2300 UINT uDuration;
2301 UINT cbReqCount;
2302 PS802_11Header pMACHeader;
2303 UINT cbHeaderSize;
2304 UINT cbFrameBodySize;
2305 BOOL bNeedACK;
2306 BOOL bIsPSPOLL = FALSE;
2307 PSTxBufHead pTxBufHead;
2308 UINT cbFrameSize;
2309 UINT cbIVlen = 0;
2310 UINT cbICVlen = 0;
2311 UINT cbMIClen = 0;
2312 UINT cbFCSlen = 4;
2313 UINT uPadding = 0;
2314 UINT cbMICHDR = 0;
2315 UINT uLength = 0;
2316 DWORD dwMICKey0, dwMICKey1;
2317 DWORD dwMIC_Priority;
2318 PDWORD pdwMIC_L;
2319 PDWORD pdwMIC_R;
2320 WORD wTxBufSize;
2321 UINT cbMacHdLen;
2322 SEthernetHeader sEthHeader;
2323 PVOID pvRrvTime;
2324 PVOID pMICHDR;
2325 WORD wCurrentRate = RATE_1M;
2326 PUWLAN_80211HDR p80211Header;
2327 UINT uNodeIndex = 0;
2328 BOOL bNodeExist = FALSE;
2329 SKeyItem STempKey;
2330 PSKeyItem pTransmitKey = NULL;
2331 PBYTE pbyIVHead;
2332 PBYTE pbyPayloadHead;
2333 PBYTE pbyMacHdr;
2334 UINT cbExtSuppRate = 0;
2335 PTX_BUFFER pTX_Buffer;
2336 PUSB_SEND_CONTEXT pContext;
2337 // PWLAN_IE pItem;
2340 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2342 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
2343 cbFrameBodySize = 0;
2345 else {
2346 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
2348 p80211Header = (PUWLAN_80211HDR)skb->data;
2350 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2352 if (NULL == pContext) {
2353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
2354 dev_kfree_skb_irq(skb);
2355 return ;
2358 pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
2359 pbyTxBufferAddr = (PBYTE)(&pTX_Buffer->adwTxKey[0]);
2360 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2361 wTxBufSize = sizeof(STxBufHead);
2362 memset(pTxBufHead, 0, wTxBufSize);
2364 if (pDevice->byBBType == BB_TYPE_11A) {
2365 wCurrentRate = RATE_6M;
2366 byPktType = PK_TYPE_11A;
2367 } else {
2368 wCurrentRate = RATE_1M;
2369 byPktType = PK_TYPE_11B;
2372 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2373 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2374 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2375 // to set power here.
2376 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2377 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2378 } else {
2379 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2384 //Set packet type
2385 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2386 pTxBufHead->wFIFOCtl = 0;
2388 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2389 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2391 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2392 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2394 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2395 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2398 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2399 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2402 if (IS_MULTICAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0])) ||
2403 IS_BROADCAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0]))) {
2404 bNeedACK = FALSE;
2405 if (pDevice->bEnableHostWEP) {
2406 uNodeIndex = 0;
2407 bNodeExist = TRUE;
2410 else {
2411 if (pDevice->bEnableHostWEP) {
2412 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2413 bNodeExist = TRUE;
2415 bNeedACK = TRUE;
2416 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2419 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2420 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2422 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2423 //Set Preamble type always long
2424 //pDevice->byPreambleType = PREAMBLE_LONG;
2426 // probe-response don't retry
2427 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2428 // bNeedACK = FALSE;
2429 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2433 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2435 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2436 bIsPSPOLL = TRUE;
2437 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2438 } else {
2439 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2442 // hostapd deamon ext support rate patch
2443 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2445 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2446 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2449 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2450 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2453 if (cbExtSuppRate >0) {
2454 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2459 //Set FRAGCTL_MACHDCNT
2460 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
2462 // Notes:
2463 // Although spec says MMPDU can be fragmented; In most case,
2464 // no one will send a MMPDU under fragmentation. With RTS may occur.
2465 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2468 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2469 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2470 cbIVlen = 4;
2471 cbICVlen = 4;
2472 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2474 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2475 cbIVlen = 8;//IV+ExtIV
2476 cbMIClen = 8;
2477 cbICVlen = 4;
2478 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2479 //We need to get seed here for filling TxKey entry.
2480 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2481 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2483 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2484 cbIVlen = 8;//RSN Header
2485 cbICVlen = 8;//MIC
2486 cbMICHDR = sizeof(SMICHDRHead);
2487 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2488 pDevice->bAES = TRUE;
2490 //MAC Header should be padding 0 to DW alignment.
2491 uPadding = 4 - (cbMacHdLen%4);
2492 uPadding %= 4;
2495 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2497 //Set FIFOCTL_GrpAckPolicy
2498 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2499 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2501 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2504 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2506 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2507 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2508 pvRTS = NULL;
2509 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
2510 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
2511 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
2514 else {//802.11a/b packet
2516 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2517 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2518 pvRTS = NULL;
2519 pvCTS = NULL;
2520 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2521 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2523 memset((PVOID)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
2524 memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
2525 memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
2526 //=========================
2527 // No Fragmentation
2528 //=========================
2529 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2532 //Fill FIFO,RrvTime,RTS,and CTS
2533 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2534 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2536 //Fill DataHead
2537 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2538 0, 0, 1, AUTO_FB_NONE);
2540 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2542 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2544 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
2545 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2546 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
2548 // Copy the Packet into a tx Buffer
2549 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2551 // version set to 0, patch for hostapd deamon
2552 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
2553 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2555 // replace support rate, patch for hostapd deamon( only support 11M)
2556 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2557 if (cbExtSuppRate != 0) {
2558 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2559 memcpy((pbyPayloadHead + cbFrameBodySize),
2560 pMgmt->abyCurrSuppRates,
2561 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2563 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2564 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2565 pMgmt->abyCurrExtSuppRates,
2566 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2571 // Set wep
2572 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2574 if (pDevice->bEnableHostWEP) {
2575 pTransmitKey = &STempKey;
2576 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2577 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2578 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2579 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2580 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2581 memcpy(pTransmitKey->abyKey,
2582 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2583 pTransmitKey->uKeyLength
2587 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2589 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
2590 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
2592 // DO Software Michael
2593 MIC_vInit(dwMICKey0, dwMICKey1);
2594 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
2595 dwMIC_Priority = 0;
2596 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
2597 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
2599 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2601 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2603 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2604 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2606 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2607 MIC_vUnInit();
2609 if (pDevice->bTxMICFail == TRUE) {
2610 *pdwMIC_L = 0;
2611 *pdwMIC_R = 0;
2612 pDevice->bTxMICFail = FALSE;
2615 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2616 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2621 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2622 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
2624 if (pDevice->bEnableHostWEP) {
2625 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2626 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2629 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
2630 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
2634 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2635 pDevice->wSeqCounter++ ;
2636 if (pDevice->wSeqCounter > 0x0fff)
2637 pDevice->wSeqCounter = 0;
2640 if (bIsPSPOLL) {
2641 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2642 // of FIFO control header.
2643 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2644 // in the same place of other packet's Duration-field).
2645 // And it will cause Cisco-AP to issue Disassociation-packet
2646 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2647 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2648 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2649 } else {
2650 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2654 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2655 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2656 pTX_Buffer->byType = 0x00;
2658 pContext->pPacket = skb;
2659 pContext->Type = CONTEXT_MGMT_PACKET;
2660 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2662 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2663 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2665 else {
2666 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2668 PIPEnsSendBulkOut(pDevice,pContext);
2669 return ;
2676 //TYPE_AC0DMA data tx
2678 * Description:
2679 * Tx packet via AC0DMA(DMA1)
2681 * Parameters:
2682 * In:
2683 * pDevice - Pointer to the adapter
2684 * skb - Pointer to tx skb packet
2685 * Out:
2686 * void
2688 * Return Value: NULL
2693 NTSTATUS
2694 nsDMA_tx_packet(
2695 IN PSDevice pDevice,
2696 IN UINT uDMAIdx,
2697 IN struct sk_buff *skb
2700 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2701 UINT BytesToWrite =0,uHeaderLen = 0;
2702 UINT uNodeIndex = 0;
2703 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2704 WORD wAID;
2705 BYTE byPktType;
2706 BOOL bNeedEncryption = FALSE;
2707 PSKeyItem pTransmitKey = NULL;
2708 SKeyItem STempKey;
2709 UINT ii;
2710 BOOL bTKIP_UseGTK = FALSE;
2711 BOOL bNeedDeAuth = FALSE;
2712 PBYTE pbyBSSID;
2713 BOOL bNodeExist = FALSE;
2714 PUSB_SEND_CONTEXT pContext;
2715 BOOL fConvertedPacket;
2716 PTX_BUFFER pTX_Buffer;
2717 UINT status;
2718 WORD wKeepRate = pDevice->wCurrentRate;
2719 struct net_device_stats* pStats = &pDevice->stats;
2720 //#ifdef WPA_SM_Transtatus
2721 // extern SWPAResult wpa_Result;
2722 //#endif
2723 BOOL bTxeapol_key = FALSE;
2726 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2728 if (pDevice->uAssocCount == 0) {
2729 dev_kfree_skb_irq(skb);
2730 return 0;
2733 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2734 uNodeIndex = 0;
2735 bNodeExist = TRUE;
2736 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2738 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2739 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2740 // set tx map
2741 pMgmt->abyPSTxMap[0] |= byMask[0];
2742 return 0;
2744 // muticast/broadcast data rate
2746 if (pDevice->byBBType != BB_TYPE_11A)
2747 pDevice->wCurrentRate = RATE_2M;
2748 else
2749 pDevice->wCurrentRate = RATE_24M;
2750 // long preamble type
2751 pDevice->byPreambleType = PREAMBLE_SHORT;
2753 }else {
2755 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data), &uNodeIndex)) {
2757 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2759 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2761 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2762 // set tx map
2763 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2764 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2765 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2766 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2768 return 0;
2770 // AP rate decided from node
2771 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2772 // tx preamble decided from node
2774 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2775 pDevice->byPreambleType = pDevice->byShortPreamble;
2777 }else {
2778 pDevice->byPreambleType = PREAMBLE_LONG;
2780 bNodeExist = TRUE;
2784 if (bNodeExist == FALSE) {
2785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2786 dev_kfree_skb_irq(skb);
2787 return 0;
2791 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2793 if (pContext == NULL) {
2794 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2795 dev_kfree_skb_irq(skb);
2796 return STATUS_RESOURCES;
2799 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2801 //mike add:station mode check eapol-key challenge--->
2803 BYTE Protocol_Version; //802.1x Authentication
2804 BYTE Packet_Type; //802.1x Authentication
2805 BYTE Descriptor_type;
2806 WORD Key_info;
2808 Protocol_Version = skb->data[U_HEADER_LEN];
2809 Packet_Type = skb->data[U_HEADER_LEN+1];
2810 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2811 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2812 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2813 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2814 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2815 bTxeapol_key = TRUE;
2816 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2817 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2818 if(Descriptor_type==254) {
2819 pDevice->fWPA_Authened = TRUE;
2820 PRINT_K("WPA ");
2822 else {
2823 pDevice->fWPA_Authened = TRUE;
2824 PRINT_K("WPA2(re-keying) ");
2826 PRINT_K("Authentication completed!!\n");
2828 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairse-key challenge
2829 (Key_info & BIT8) && (Key_info & BIT9)) {
2830 pDevice->fWPA_Authened = TRUE;
2831 PRINT_K("WPA2 Authentication completed!!\n");
2836 //mike add:station mode check eapol-key challenge<---
2838 if (pDevice->bEncryptionEnable == TRUE) {
2839 bNeedEncryption = TRUE;
2840 // get Transmit key
2841 do {
2842 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2843 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2844 pbyBSSID = pDevice->abyBSSID;
2845 // get pairwise key
2846 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2847 // get group key
2848 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2849 bTKIP_UseGTK = TRUE;
2850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2851 break;
2853 } else {
2854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2855 break;
2857 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2859 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2860 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2861 for (ii = 0; ii< 6; ii++)
2862 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2863 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2865 // get pairwise key
2866 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2867 break;
2869 // get group key
2870 pbyBSSID = pDevice->abyBroadcastAddr;
2871 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2872 pTransmitKey = NULL;
2873 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2876 else
2877 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2878 } else {
2879 bTKIP_UseGTK = TRUE;
2880 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2882 } while(FALSE);
2885 if (pDevice->bEnableHostWEP) {
2886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2887 if (pDevice->bEncryptionEnable == TRUE) {
2888 pTransmitKey = &STempKey;
2889 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2890 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2891 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2892 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2893 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2894 memcpy(pTransmitKey->abyKey,
2895 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2896 pTransmitKey->uKeyLength
2901 byPktType = (BYTE)pDevice->byPacketType;
2903 if (pDevice->bFixRate) {
2904 if (pDevice->byBBType == BB_TYPE_11B) {
2905 if (pDevice->uConnectionRate >= RATE_11M) {
2906 pDevice->wCurrentRate = RATE_11M;
2907 } else {
2908 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2910 } else {
2911 if ((pDevice->byBBType == BB_TYPE_11A) &&
2912 (pDevice->uConnectionRate <= RATE_6M)) {
2913 pDevice->wCurrentRate = RATE_6M;
2914 } else {
2915 if (pDevice->uConnectionRate >= RATE_54M)
2916 pDevice->wCurrentRate = RATE_54M;
2917 else
2918 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2922 else {
2923 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2924 // Adhoc Tx rate decided from node DB
2925 if (IS_MULTICAST_ADDRESS(&(pDevice->sTxEthHeader.abyDstAddr[0]))) {
2926 // Multicast use highest data rate
2927 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2928 // preamble type
2929 pDevice->byPreambleType = pDevice->byShortPreamble;
2931 else {
2932 if(BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.abyDstAddr[0]), &uNodeIndex)) {
2933 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2934 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2935 pDevice->byPreambleType = pDevice->byShortPreamble;
2938 else {
2939 pDevice->byPreambleType = PREAMBLE_LONG;
2941 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2943 else {
2944 if (pDevice->byBBType != BB_TYPE_11A)
2945 pDevice->wCurrentRate = RATE_2M;
2946 else
2947 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2948 // abyCurrExtSuppRates[]
2949 pDevice->byPreambleType = PREAMBLE_SHORT;
2950 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2954 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2955 // Infra STA rate decided from AP Node, index = 0
2956 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2960 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2961 if (pDevice->byBBType != BB_TYPE_11A) {
2962 pDevice->wCurrentRate = RATE_1M;
2963 pDevice->byACKRate = RATE_1M;
2964 pDevice->byTopCCKBasicRate = RATE_1M;
2965 pDevice->byTopOFDMBasicRate = RATE_6M;
2966 } else {
2967 pDevice->wCurrentRate = RATE_6M;
2968 pDevice->byACKRate = RATE_6M;
2969 pDevice->byTopCCKBasicRate = RATE_1M;
2970 pDevice->byTopOFDMBasicRate = RATE_6M;
2974 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma_tx: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2976 if (wKeepRate != pDevice->wCurrentRate) {
2977 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SETPOWER, NULL);
2980 if (pDevice->wCurrentRate <= RATE_11M) {
2981 byPktType = PK_TYPE_11B;
2984 if (bNeedEncryption == TRUE) {
2985 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2986 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2987 bNeedEncryption = FALSE;
2988 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2989 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2990 if (pTransmitKey == NULL) {
2991 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2993 else {
2994 if (bTKIP_UseGTK == TRUE) {
2995 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2997 else {
2998 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2999 bNeedEncryption = TRUE;
3004 if (pDevice->byCntMeasure == 2) {
3005 bNeedDeAuth = TRUE;
3006 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
3009 if (pDevice->bEnableHostWEP) {
3010 if ((uNodeIndex != 0) &&
3011 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
3012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3013 bNeedEncryption = TRUE;
3017 else {
3019 #if 0
3020 if((pDevice->fWPA_Authened == FALSE) &&
3021 ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)||(pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK))){
3022 dev_kfree_skb_irq(skb);
3023 pStats->tx_dropped++;
3024 return STATUS_FAILURE;
3026 else if (pTransmitKey == NULL) {
3027 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
3028 dev_kfree_skb_irq(skb);
3029 pStats->tx_dropped++;
3030 return STATUS_FAILURE;
3032 #else
3033 if (pTransmitKey == NULL) {
3034 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
3035 dev_kfree_skb_irq(skb);
3036 pStats->tx_dropped++;
3037 return STATUS_FAILURE;
3039 #endif
3044 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3045 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3046 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
3047 (PBYTE)skb->data, pTransmitKey, uNodeIndex,
3048 pDevice->wCurrentRate,
3049 &uHeaderLen, &BytesToWrite
3052 if (fConvertedPacket == FALSE) {
3053 pContext->bBoolInUse = FALSE;
3054 dev_kfree_skb_irq(skb);
3055 return STATUS_FAILURE;
3058 if ( pDevice->bEnablePSMode == TRUE ) {
3059 if ( !pDevice->bPSModeTxBurst ) {
3060 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_MAC_DISPOWERSAVING, NULL);
3061 pDevice->bPSModeTxBurst = TRUE;
3065 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3066 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3067 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3069 pContext->pPacket = skb;
3070 pContext->Type = CONTEXT_DATA_PACKET;
3071 pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
3073 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3075 status = PIPEnsSendBulkOut(pDevice,pContext);
3077 if (bNeedDeAuth == TRUE) {
3078 WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE;
3080 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&wReason);
3083 if(status!=STATUS_PENDING) {
3084 pContext->bBoolInUse = FALSE;
3085 dev_kfree_skb_irq(skb);
3086 return STATUS_FAILURE;
3088 else
3089 return 0;
3096 * Description:
3097 * Relay packet send (AC1DMA) from rx dpc.
3099 * Parameters:
3100 * In:
3101 * pDevice - Pointer to the adapter
3102 * pPacket - Pointer to rx packet
3103 * cbPacketSize - rx ethernet frame size
3104 * Out:
3105 * TURE, FALSE
3107 * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE
3111 BOOL
3112 bRelayPacketSend (
3113 IN PSDevice pDevice,
3114 IN PBYTE pbySkbData,
3115 IN UINT uDataLen,
3116 IN UINT uNodeIndex
3119 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
3120 UINT BytesToWrite =0,uHeaderLen = 0;
3121 BYTE byPktType = PK_TYPE_11B;
3122 BOOL bNeedEncryption = FALSE;
3123 SKeyItem STempKey;
3124 PSKeyItem pTransmitKey = NULL;
3125 PBYTE pbyBSSID;
3126 PUSB_SEND_CONTEXT pContext;
3127 BYTE byPktTyp;
3128 BOOL fConvertedPacket;
3129 PTX_BUFFER pTX_Buffer;
3130 UINT status;
3131 WORD wKeepRate = pDevice->wCurrentRate;
3135 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
3137 if (NULL == pContext) {
3138 return FALSE;
3141 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, U_HEADER_LEN);
3143 if (pDevice->bEncryptionEnable == TRUE) {
3144 bNeedEncryption = TRUE;
3145 // get group key
3146 pbyBSSID = pDevice->abyBroadcastAddr;
3147 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
3148 pTransmitKey = NULL;
3149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
3150 } else {
3151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
3155 if (pDevice->bEnableHostWEP) {
3156 if (uNodeIndex >= 0) {
3157 pTransmitKey = &STempKey;
3158 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3159 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3160 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3161 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3162 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3163 memcpy(pTransmitKey->abyKey,
3164 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3165 pTransmitKey->uKeyLength
3170 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
3171 pContext->bBoolInUse = FALSE;
3172 return FALSE;
3175 byPktTyp = (BYTE)pDevice->byPacketType;
3177 if (pDevice->bFixRate) {
3178 if (pDevice->byBBType == BB_TYPE_11B) {
3179 if (pDevice->uConnectionRate >= RATE_11M) {
3180 pDevice->wCurrentRate = RATE_11M;
3181 } else {
3182 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3184 } else {
3185 if ((pDevice->byBBType == BB_TYPE_11A) &&
3186 (pDevice->uConnectionRate <= RATE_6M)) {
3187 pDevice->wCurrentRate = RATE_6M;
3188 } else {
3189 if (pDevice->uConnectionRate >= RATE_54M)
3190 pDevice->wCurrentRate = RATE_54M;
3191 else
3192 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3196 else {
3197 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
3201 if (wKeepRate != pDevice->wCurrentRate) {
3202 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SETPOWER, NULL);
3205 if (pDevice->wCurrentRate <= RATE_11M)
3206 byPktType = PK_TYPE_11B;
3208 BytesToWrite = uDataLen + U_CRC_LEN;
3209 // Convert the packet to an usb frame and copy into our buffer
3210 // and send the irp.
3212 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3213 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3214 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
3215 pbySkbData, pTransmitKey, uNodeIndex,
3216 pDevice->wCurrentRate,
3217 &uHeaderLen, &BytesToWrite
3220 if (fConvertedPacket == FALSE) {
3221 pContext->bBoolInUse = FALSE;
3222 return FALSE;
3225 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3226 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3227 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3229 pContext->pPacket = NULL;
3230 pContext->Type = CONTEXT_DATA_PACKET;
3231 pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
3233 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3235 status = PIPEnsSendBulkOut(pDevice,pContext);
3237 return TRUE;