usb: otg: mv_otg: Add dependence
[zen-stable.git] / drivers / staging / vt6656 / rxtx.c
blob9b64b102f55cccea62a74c258829446b235ace2b
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * File: rxtx.c
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
23 * Author: Lyndon Chen
25 * Date: May 20, 2003
27 * Functions:
28 * s_vGenerateTxParameter - Generate tx dma required parameter.
29 * s_vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * csBeacon_xmit - beacon tx function
31 * csMgmt_xmit - management tx function
32 * s_uGetDataDuration - get tx data required duration
33 * s_uFillDataHead- fulfill tx data duration header
34 * s_uGetRTSCTSDuration- get rtx/cts required duration
35 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
38 * s_vFillFragParameter- Set fragment ctl parameter.
39 * s_vFillRTSHead- fulfill RTS ctl header
40 * s_vFillTxKey- fulfill tx encrypt key
41 * s_vSWencryption- Software encrypt header
42 * vDMA0_tx_80211- tx 802.11 frame via dma0
43 * vGenerateFIFOHeader- Generate tx FIFO ctl header
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"
64 #include "iocmd.h"
66 /*--------------------- Static Definitions -------------------------*/
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
71 static int msglevel = MSG_LEVEL_INFO;
73 /*--------------------- Static Functions --------------------------*/
75 /*--------------------- Static Definitions -------------------------*/
76 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
77 // packet size >= 256 -> direct send
79 const WORD wTimeStampOff[2][MAX_RATE] = {
80 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
81 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
84 const WORD wFB_Opt0[2][5] = {
85 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
86 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
88 const WORD wFB_Opt1[2][5] = {
89 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
90 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
94 #define RTSDUR_BB 0
95 #define RTSDUR_BA 1
96 #define RTSDUR_AA 2
97 #define CTSDUR_BA 3
98 #define RTSDUR_BA_F0 4
99 #define RTSDUR_AA_F0 5
100 #define RTSDUR_BA_F1 6
101 #define RTSDUR_AA_F1 7
102 #define CTSDUR_BA_F0 8
103 #define CTSDUR_BA_F1 9
104 #define DATADUR_B 10
105 #define DATADUR_A 11
106 #define DATADUR_A_F0 12
107 #define DATADUR_A_F1 13
109 /*--------------------- Static Functions --------------------------*/
111 static
112 void
113 s_vSaveTxPktInfo(
114 PSDevice pDevice,
115 BYTE byPktNum,
116 PBYTE pbyDestAddr,
117 WORD wPktLength,
118 WORD wFIFOCtl
121 static
122 void *
123 s_vGetFreeContext(
124 PSDevice pDevice
128 static
129 void
130 s_vGenerateTxParameter(
131 PSDevice pDevice,
132 BYTE byPktType,
133 WORD wCurrentRate,
134 void *pTxBufHead,
135 void *pvRrvTime,
136 void *pvRTS,
137 void *pvCTS,
138 unsigned int cbFrameSize,
139 BOOL bNeedACK,
140 unsigned int uDMAIdx,
141 PSEthernetHeader psEthHeader
145 static unsigned int s_uFillDataHead(
146 PSDevice pDevice,
147 BYTE byPktType,
148 WORD wCurrentRate,
149 void *pTxDataHead,
150 unsigned int cbFrameLength,
151 unsigned int uDMAIdx,
152 BOOL bNeedAck,
153 unsigned int uFragIdx,
154 unsigned int cbLastFragmentSize,
155 unsigned int uMACfragNum,
156 BYTE byFBOption
162 static
163 void
164 s_vGenerateMACHeader (
165 PSDevice pDevice,
166 PBYTE pbyBufferAddr,
167 WORD wDuration,
168 PSEthernetHeader psEthHeader,
169 BOOL bNeedEncrypt,
170 WORD wFragType,
171 unsigned int uDMAIdx,
172 unsigned int uFragIdx
175 static
176 void
177 s_vFillTxKey(
178 PSDevice pDevice,
179 PBYTE pbyBuf,
180 PBYTE pbyIVHead,
181 PSKeyItem pTransmitKey,
182 PBYTE pbyHdrBuf,
183 WORD wPayloadLen,
184 PBYTE pMICHDR
187 static
188 void
189 s_vSWencryption (
190 PSDevice pDevice,
191 PSKeyItem pTransmitKey,
192 PBYTE pbyPayloadHead,
193 WORD wPayloadSize
196 static unsigned int s_uGetTxRsvTime(
197 PSDevice pDevice,
198 BYTE byPktType,
199 unsigned int cbFrameLength,
200 WORD wRate,
201 BOOL bNeedAck
205 static unsigned int s_uGetRTSCTSRsvTime(
206 PSDevice pDevice,
207 BYTE byRTSRsvType,
208 BYTE byPktType,
209 unsigned int cbFrameLength,
210 WORD wCurrentRate
213 static
214 void
215 s_vFillCTSHead (
216 PSDevice pDevice,
217 unsigned int uDMAIdx,
218 BYTE byPktType,
219 void *pvCTS,
220 unsigned int cbFrameLength,
221 BOOL bNeedAck,
222 BOOL bDisCRC,
223 WORD wCurrentRate,
224 BYTE byFBOption
227 static
228 void
229 s_vFillRTSHead(
230 PSDevice pDevice,
231 BYTE byPktType,
232 void *pvRTS,
233 unsigned int cbFrameLength,
234 BOOL bNeedAck,
235 BOOL bDisCRC,
236 PSEthernetHeader psEthHeader,
237 WORD wCurrentRate,
238 BYTE byFBOption
241 static unsigned int s_uGetDataDuration(
242 PSDevice pDevice,
243 BYTE byDurType,
244 unsigned int cbFrameLength,
245 BYTE byPktType,
246 WORD wRate,
247 BOOL bNeedAck,
248 unsigned int uFragIdx,
249 unsigned int cbLastFragmentSize,
250 unsigned int uMACfragNum,
251 BYTE byFBOption
255 static
256 unsigned int
257 s_uGetRTSCTSDuration (
258 PSDevice pDevice,
259 BYTE byDurType,
260 unsigned int cbFrameLength,
261 BYTE byPktType,
262 WORD wRate,
263 BOOL bNeedAck,
264 BYTE byFBOption
268 /*--------------------- Export Variables --------------------------*/
270 static
271 void *
272 s_vGetFreeContext(
273 PSDevice pDevice
276 PUSB_SEND_CONTEXT pContext = NULL;
277 PUSB_SEND_CONTEXT pReturnContext = NULL;
278 unsigned int ii;
280 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
282 for (ii = 0; ii < pDevice->cbTD; ii++) {
283 pContext = pDevice->apTD[ii];
284 if (pContext->bBoolInUse == FALSE) {
285 pContext->bBoolInUse = TRUE;
286 pReturnContext = pContext;
287 break;
290 if ( ii == pDevice->cbTD ) {
291 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
293 return (void *) pReturnContext;
297 static
298 void
299 s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLength, WORD wFIFOCtl)
301 PSStatCounter pStatistic=&(pDevice->scStatistic);
303 if (is_broadcast_ether_addr(pbyDestAddr))
304 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
305 else if (is_multicast_ether_addr(pbyDestAddr))
306 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
307 else
308 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
310 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
311 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
312 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
313 pbyDestAddr,
314 ETH_ALEN);
317 static
318 void
319 s_vFillTxKey (
320 PSDevice pDevice,
321 PBYTE pbyBuf,
322 PBYTE pbyIVHead,
323 PSKeyItem pTransmitKey,
324 PBYTE pbyHdrBuf,
325 WORD wPayloadLen,
326 PBYTE pMICHDR
329 PDWORD pdwIV = (PDWORD) pbyIVHead;
330 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
331 WORD wValue;
332 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
333 DWORD dwRevIVCounter;
337 //Fill TXKEY
338 if (pTransmitKey == NULL)
339 return;
341 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
342 *pdwIV = pDevice->dwIVCounter;
343 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
345 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
346 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
347 memcpy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
348 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
349 } else {
350 memcpy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
351 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
352 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
353 memcpy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
354 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
356 memcpy(pDevice->abyPRNG, pbyBuf, 16);
358 // Append IV after Mac Header
359 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
360 *pdwIV |= (pDevice->byKeyIndex << 30);
361 *pdwIV = cpu_to_le32(*pdwIV);
362 pDevice->dwIVCounter++;
363 if (pDevice->dwIVCounter > WEP_IV_MASK) {
364 pDevice->dwIVCounter = 0;
366 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
367 pTransmitKey->wTSC15_0++;
368 if (pTransmitKey->wTSC15_0 == 0) {
369 pTransmitKey->dwTSC47_16++;
371 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
372 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
373 memcpy(pbyBuf, pDevice->abyPRNG, 16);
374 // Make IV
375 memcpy(pdwIV, pDevice->abyPRNG, 3);
377 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
378 // Append IV&ExtIV after Mac Header
379 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
382 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
383 pTransmitKey->wTSC15_0++;
384 if (pTransmitKey->wTSC15_0 == 0) {
385 pTransmitKey->dwTSC47_16++;
387 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
389 // Make IV
390 *pdwIV = 0;
391 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
392 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
393 //Append IV&ExtIV after Mac Header
394 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
396 //Fill MICHDR0
397 *pMICHDR = 0x59;
398 *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
399 memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
400 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
401 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
402 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
403 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
404 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
405 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
406 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
407 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
409 //Fill MICHDR1
410 *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
411 if (pDevice->bLongHeader) {
412 *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
413 } else {
414 *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
416 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
417 memcpy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
418 memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
419 memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
421 //Fill MICHDR2
422 memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
423 wValue = pMACHeader->wSeqCtl;
424 wValue &= 0x000F;
425 wValue = cpu_to_le16(wValue);
426 memcpy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
427 if (pDevice->bLongHeader) {
428 memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
434 static
435 void
436 s_vSWencryption (
437 PSDevice pDevice,
438 PSKeyItem pTransmitKey,
439 PBYTE pbyPayloadHead,
440 WORD wPayloadSize
443 unsigned int cbICVlen = 4;
444 DWORD dwICV = 0xFFFFFFFFL;
445 PDWORD pdwICV;
447 if (pTransmitKey == NULL)
448 return;
450 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
451 //=======================================================================
452 // Append ICV after payload
453 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
454 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
455 // finally, we must invert dwCRC to get the correct answer
456 *pdwICV = cpu_to_le32(~dwICV);
457 // RC4 encryption
458 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
459 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
460 //=======================================================================
461 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
462 //=======================================================================
463 //Append ICV after payload
464 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
465 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
466 // finally, we must invert dwCRC to get the correct answer
467 *pdwICV = cpu_to_le32(~dwICV);
468 // RC4 encryption
469 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
470 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
471 //=======================================================================
478 /*byPktType : PK_TYPE_11A 0
479 PK_TYPE_11B 1
480 PK_TYPE_11GB 2
481 PK_TYPE_11GA 3
483 static
484 unsigned int
485 s_uGetTxRsvTime (
486 PSDevice pDevice,
487 BYTE byPktType,
488 unsigned int cbFrameLength,
489 WORD wRate,
490 BOOL bNeedAck
493 unsigned int uDataTime, uAckTime;
495 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
496 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
497 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopCCKBasicRate);
498 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
499 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopOFDMBasicRate);
502 if (bNeedAck) {
503 return (uDataTime + pDevice->uSIFS + uAckTime);
505 else {
506 return uDataTime;
510 //byFreqType: 0=>5GHZ 1=>2.4GHZ
511 static
512 unsigned int
513 s_uGetRTSCTSRsvTime (
514 PSDevice pDevice,
515 BYTE byRTSRsvType,
516 BYTE byPktType,
517 unsigned int cbFrameLength,
518 WORD wCurrentRate
521 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
523 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
526 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
527 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
528 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
529 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
531 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
532 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
533 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
534 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
536 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
537 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
538 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
540 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
541 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
542 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
543 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
544 return uRrvTime;
547 //RTSRrvTime
548 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
549 return uRrvTime;
552 //byFreqType 0: 5GHz, 1:2.4Ghz
553 static
554 unsigned int
555 s_uGetDataDuration (
556 PSDevice pDevice,
557 BYTE byDurType,
558 unsigned int cbFrameLength,
559 BYTE byPktType,
560 WORD wRate,
561 BOOL bNeedAck,
562 unsigned int uFragIdx,
563 unsigned int cbLastFragmentSize,
564 unsigned int uMACfragNum,
565 BYTE byFBOption
568 BOOL bLastFrag = 0;
569 unsigned int uAckTime = 0, uNextPktTime = 0;
571 if (uFragIdx == (uMACfragNum-1)) {
572 bLastFrag = 1;
575 switch (byDurType) {
577 case DATADUR_B: //DATADUR_B
578 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
579 if (bNeedAck) {
580 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
581 return (pDevice->uSIFS + uAckTime);
582 } else {
583 return 0;
586 else {//First Frag or Mid Frag
587 if (uFragIdx == (uMACfragNum-2)) {
588 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
589 } else {
590 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
592 if (bNeedAck) {
593 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
594 return (pDevice->uSIFS + uAckTime + uNextPktTime);
595 } else {
596 return (pDevice->uSIFS + uNextPktTime);
599 break;
602 case DATADUR_A: //DATADUR_A
603 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
604 if(bNeedAck){
605 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
606 return (pDevice->uSIFS + uAckTime);
607 } else {
608 return 0;
611 else {//First Frag or Mid Frag
612 if(uFragIdx == (uMACfragNum-2)){
613 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
614 } else {
615 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
617 if(bNeedAck){
618 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
619 return (pDevice->uSIFS + uAckTime + uNextPktTime);
620 } else {
621 return (pDevice->uSIFS + uNextPktTime);
624 break;
626 case DATADUR_A_F0: //DATADUR_A_F0
627 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
628 if(bNeedAck){
629 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
630 return (pDevice->uSIFS + uAckTime);
631 } else {
632 return 0;
635 else { //First Frag or Mid Frag
636 if (byFBOption == AUTO_FB_0) {
637 if (wRate < RATE_18M)
638 wRate = RATE_18M;
639 else if (wRate > RATE_54M)
640 wRate = RATE_54M;
642 if(uFragIdx == (uMACfragNum-2)){
643 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
644 } else {
645 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
647 } else { // (byFBOption == AUTO_FB_1)
648 if (wRate < RATE_18M)
649 wRate = RATE_18M;
650 else if (wRate > RATE_54M)
651 wRate = RATE_54M;
653 if(uFragIdx == (uMACfragNum-2)){
654 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
655 } else {
656 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
660 if(bNeedAck){
661 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
662 return (pDevice->uSIFS + uAckTime + uNextPktTime);
663 } else {
664 return (pDevice->uSIFS + uNextPktTime);
667 break;
669 case DATADUR_A_F1: //DATADUR_A_F1
670 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
671 if(bNeedAck){
672 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
673 return (pDevice->uSIFS + uAckTime);
674 } else {
675 return 0;
678 else { //First Frag or Mid Frag
679 if (byFBOption == AUTO_FB_0) {
680 if (wRate < RATE_18M)
681 wRate = RATE_18M;
682 else if (wRate > RATE_54M)
683 wRate = RATE_54M;
685 if(uFragIdx == (uMACfragNum-2)){
686 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
687 } else {
688 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
691 } else { // (byFBOption == AUTO_FB_1)
692 if (wRate < RATE_18M)
693 wRate = RATE_18M;
694 else if (wRate > RATE_54M)
695 wRate = RATE_54M;
697 if(uFragIdx == (uMACfragNum-2)){
698 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
699 } else {
700 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
703 if(bNeedAck){
704 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
705 return (pDevice->uSIFS + uAckTime + uNextPktTime);
706 } else {
707 return (pDevice->uSIFS + uNextPktTime);
710 break;
712 default:
713 break;
716 ASSERT(FALSE);
717 return 0;
721 //byFreqType: 0=>5GHZ 1=>2.4GHZ
722 static
723 unsigned int
724 s_uGetRTSCTSDuration (
725 PSDevice pDevice,
726 BYTE byDurType,
727 unsigned int cbFrameLength,
728 BYTE byPktType,
729 WORD wRate,
730 BOOL bNeedAck,
731 BYTE byFBOption
734 unsigned int uCTSTime = 0, uDurTime = 0;
737 switch (byDurType) {
739 case RTSDUR_BB: //RTSDuration_bb
740 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
741 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
742 break;
744 case RTSDUR_BA: //RTSDuration_ba
745 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
746 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
747 break;
749 case RTSDUR_AA: //RTSDuration_aa
750 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
751 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
752 break;
754 case CTSDUR_BA: //CTSDuration_ba
755 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
756 break;
758 case RTSDUR_BA_F0: //RTSDuration_ba_f0
759 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
760 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
761 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
762 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
763 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
765 break;
767 case RTSDUR_AA_F0: //RTSDuration_aa_f0
768 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
769 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
770 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
771 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
772 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
774 break;
776 case RTSDUR_BA_F1: //RTSDuration_ba_f1
777 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
778 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
779 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
780 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
781 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
783 break;
785 case RTSDUR_AA_F1: //RTSDuration_aa_f1
786 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
787 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
788 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
789 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
790 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
792 break;
794 case CTSDUR_BA_F0: //CTSDuration_ba_f0
795 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
796 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
797 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
798 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
800 break;
802 case CTSDUR_BA_F1: //CTSDuration_ba_f1
803 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
804 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
805 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
806 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
808 break;
810 default:
811 break;
814 return uDurTime;
821 static
822 unsigned int
823 s_uFillDataHead (
824 PSDevice pDevice,
825 BYTE byPktType,
826 WORD wCurrentRate,
827 void *pTxDataHead,
828 unsigned int cbFrameLength,
829 unsigned int uDMAIdx,
830 BOOL bNeedAck,
831 unsigned int uFragIdx,
832 unsigned int cbLastFragmentSize,
833 unsigned int uMACfragNum,
834 BYTE byFBOption
838 if (pTxDataHead == NULL) {
839 return 0;
842 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
843 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
844 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
845 //Get SignalField,ServiceField,Length
846 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
847 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
849 //Get Duration and TimeStampOff
850 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
851 wCurrentRate, bNeedAck, uFragIdx,
852 cbLastFragmentSize, uMACfragNum,
853 byFBOption); //1: 2.4GHz
854 if(uDMAIdx!=TYPE_ATIMDMA) {
855 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
857 return (pBuf->wDuration);
859 else { // DATA & MANAGE Frame
860 if (byFBOption == AUTO_FB_NONE) {
861 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
862 //Get SignalField,ServiceField,Length
863 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
864 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
866 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
867 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
869 //Get Duration and TimeStamp
870 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
871 byPktType, wCurrentRate, bNeedAck, uFragIdx,
872 cbLastFragmentSize, uMACfragNum,
873 byFBOption); //1: 2.4GHz
874 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
875 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
876 bNeedAck, uFragIdx, cbLastFragmentSize,
877 uMACfragNum, byFBOption); //1: 2.4GHz
879 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
880 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
881 return (pBuf->wDuration_a);
882 } else {
883 // Auto Fallback
884 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
885 //Get SignalField,ServiceField,Length
886 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
887 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
889 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
890 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
892 //Get Duration and TimeStamp
893 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
894 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
895 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
896 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
897 pBuf->wDuration_a_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
898 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
899 pBuf->wDuration_a_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
900 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //1: 2.4GHz
901 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
902 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
903 return (pBuf->wDuration_a);
904 } //if (byFBOption == AUTO_FB_NONE)
907 else if (byPktType == PK_TYPE_11A) {
908 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
909 // Auto Fallback
910 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
911 //Get SignalField,ServiceField,Length
912 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
913 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
915 //Get Duration and TimeStampOff
916 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
917 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
918 pBuf->wDuration_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
919 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
920 pBuf->wDuration_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
921 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption); //0: 5GHz
922 if(uDMAIdx!=TYPE_ATIMDMA) {
923 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
925 return (pBuf->wDuration);
926 } else {
927 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
928 //Get SignalField,ServiceField,Length
929 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
930 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
932 //Get Duration and TimeStampOff
933 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
934 wCurrentRate, bNeedAck, uFragIdx,
935 cbLastFragmentSize, uMACfragNum,
936 byFBOption);
938 if(uDMAIdx!=TYPE_ATIMDMA) {
939 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
941 return (pBuf->wDuration);
944 else if (byPktType == PK_TYPE_11B) {
945 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
946 //Get SignalField,ServiceField,Length
947 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
948 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
950 //Get Duration and TimeStampOff
951 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
952 wCurrentRate, bNeedAck, uFragIdx,
953 cbLastFragmentSize, uMACfragNum,
954 byFBOption);
955 if (uDMAIdx != TYPE_ATIMDMA) {
956 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
958 return (pBuf->wDuration);
960 return 0;
966 static
967 void
968 s_vFillRTSHead (
969 PSDevice pDevice,
970 BYTE byPktType,
971 void *pvRTS,
972 unsigned int cbFrameLength,
973 BOOL bNeedAck,
974 BOOL bDisCRC,
975 PSEthernetHeader psEthHeader,
976 WORD wCurrentRate,
977 BYTE byFBOption
980 unsigned int uRTSFrameLen = 20;
981 WORD wLen = 0x0000;
983 if (pvRTS == NULL)
984 return;
986 if (bDisCRC) {
987 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
988 // in this case we need to decrease its length by 4.
989 uRTSFrameLen -= 4;
992 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
993 // Otherwise, we need to modified codes for them.
994 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
995 if (byFBOption == AUTO_FB_NONE) {
996 PSRTS_g pBuf = (PSRTS_g)pvRTS;
997 //Get SignalField,ServiceField,Length
998 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
999 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1001 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1002 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1003 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1005 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1006 //Get Duration
1007 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
1008 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
1009 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
1011 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1012 //Get RTS Frame body
1013 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1015 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1016 (pDevice->eOPMode == OP_MODE_AP)) {
1017 memcpy(&(pBuf->Data.abyRA[0]),
1018 &(psEthHeader->abyDstAddr[0]),
1019 ETH_ALEN);
1021 else {
1022 memcpy(&(pBuf->Data.abyRA[0]),
1023 &(pDevice->abyBSSID[0]),
1024 ETH_ALEN);
1026 if (pDevice->eOPMode == OP_MODE_AP) {
1027 memcpy(&(pBuf->Data.abyTA[0]),
1028 &(pDevice->abyBSSID[0]),
1029 ETH_ALEN);
1031 else {
1032 memcpy(&(pBuf->Data.abyTA[0]),
1033 &(psEthHeader->abySrcAddr[0]),
1034 ETH_ALEN);
1037 else {
1038 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
1039 //Get SignalField,ServiceField,Length
1040 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1041 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1043 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1044 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1045 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1047 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1048 //Get Duration
1049 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
1050 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
1051 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
1052 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
1053 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
1054 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
1055 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
1056 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1057 //Get RTS Frame body
1058 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1060 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1061 (pDevice->eOPMode == OP_MODE_AP)) {
1062 memcpy(&(pBuf->Data.abyRA[0]),
1063 &(psEthHeader->abyDstAddr[0]),
1064 ETH_ALEN);
1066 else {
1067 memcpy(&(pBuf->Data.abyRA[0]),
1068 &(pDevice->abyBSSID[0]),
1069 ETH_ALEN);
1072 if (pDevice->eOPMode == OP_MODE_AP) {
1073 memcpy(&(pBuf->Data.abyTA[0]),
1074 &(pDevice->abyBSSID[0]),
1075 ETH_ALEN);
1077 else {
1078 memcpy(&(pBuf->Data.abyTA[0]),
1079 &(psEthHeader->abySrcAddr[0]),
1080 ETH_ALEN);
1083 } // if (byFBOption == AUTO_FB_NONE)
1085 else if (byPktType == PK_TYPE_11A) {
1086 if (byFBOption == AUTO_FB_NONE) {
1087 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1088 //Get SignalField,ServiceField,Length
1089 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1090 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1092 pBuf->wTransmitLength = cpu_to_le16(wLen);
1093 //Get Duration
1094 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1095 pBuf->Data.wDurationID = pBuf->wDuration;
1096 //Get RTS Frame body
1097 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1099 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1100 (pDevice->eOPMode == OP_MODE_AP)) {
1101 memcpy(&(pBuf->Data.abyRA[0]),
1102 &(psEthHeader->abyDstAddr[0]),
1103 ETH_ALEN);
1104 } else {
1105 memcpy(&(pBuf->Data.abyRA[0]),
1106 &(pDevice->abyBSSID[0]),
1107 ETH_ALEN);
1110 if (pDevice->eOPMode == OP_MODE_AP) {
1111 memcpy(&(pBuf->Data.abyTA[0]),
1112 &(pDevice->abyBSSID[0]),
1113 ETH_ALEN);
1114 } else {
1115 memcpy(&(pBuf->Data.abyTA[0]),
1116 &(psEthHeader->abySrcAddr[0]),
1117 ETH_ALEN);
1121 else {
1122 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
1123 //Get SignalField,ServiceField,Length
1124 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1125 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1127 pBuf->wTransmitLength = cpu_to_le16(wLen);
1128 //Get Duration
1129 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1130 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
1131 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:
1132 pBuf->Data.wDurationID = pBuf->wDuration;
1133 //Get RTS Frame body
1134 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1136 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1137 (pDevice->eOPMode == OP_MODE_AP)) {
1138 memcpy(&(pBuf->Data.abyRA[0]),
1139 &(psEthHeader->abyDstAddr[0]),
1140 ETH_ALEN);
1141 } else {
1142 memcpy(&(pBuf->Data.abyRA[0]),
1143 &(pDevice->abyBSSID[0]),
1144 ETH_ALEN);
1146 if (pDevice->eOPMode == OP_MODE_AP) {
1147 memcpy(&(pBuf->Data.abyTA[0]),
1148 &(pDevice->abyBSSID[0]),
1149 ETH_ALEN);
1150 } else {
1151 memcpy(&(pBuf->Data.abyTA[0]),
1152 &(psEthHeader->abySrcAddr[0]),
1153 ETH_ALEN);
1157 else if (byPktType == PK_TYPE_11B) {
1158 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1159 //Get SignalField,ServiceField,Length
1160 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1161 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1163 pBuf->wTransmitLength = cpu_to_le16(wLen);
1164 //Get Duration
1165 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1166 pBuf->Data.wDurationID = pBuf->wDuration;
1167 //Get RTS Frame body
1168 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1170 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1171 (pDevice->eOPMode == OP_MODE_AP)) {
1172 memcpy(&(pBuf->Data.abyRA[0]),
1173 &(psEthHeader->abyDstAddr[0]),
1174 ETH_ALEN);
1176 else {
1177 memcpy(&(pBuf->Data.abyRA[0]),
1178 &(pDevice->abyBSSID[0]),
1179 ETH_ALEN);
1182 if (pDevice->eOPMode == OP_MODE_AP) {
1183 memcpy(&(pBuf->Data.abyTA[0]),
1184 &(pDevice->abyBSSID[0]),
1185 ETH_ALEN);
1186 } else {
1187 memcpy(&(pBuf->Data.abyTA[0]),
1188 &(psEthHeader->abySrcAddr[0]),
1189 ETH_ALEN);
1194 static
1195 void
1196 s_vFillCTSHead (
1197 PSDevice pDevice,
1198 unsigned int uDMAIdx,
1199 BYTE byPktType,
1200 void *pvCTS,
1201 unsigned int cbFrameLength,
1202 BOOL bNeedAck,
1203 BOOL bDisCRC,
1204 WORD wCurrentRate,
1205 BYTE byFBOption
1208 unsigned int uCTSFrameLen = 14;
1209 WORD wLen = 0x0000;
1211 if (pvCTS == NULL) {
1212 return;
1215 if (bDisCRC) {
1216 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1217 // in this case we need to decrease its length by 4.
1218 uCTSFrameLen -= 4;
1221 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1222 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1223 // Auto Fall back
1224 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1225 //Get SignalField,ServiceField,Length
1226 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1227 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1229 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1230 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
1231 pBuf->wDuration_ba += pDevice->wCTSDuration;
1232 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1233 //Get CTSDuration_ba_f0
1234 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
1235 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1236 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1237 //Get CTSDuration_ba_f1
1238 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
1239 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1240 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1241 //Get CTS Frame body
1242 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1243 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1244 pBuf->Data.wReserved = 0x0000;
1245 memcpy(&(pBuf->Data.abyRA[0]),
1246 &(pDevice->abyCurrentNetAddr[0]),
1247 ETH_ALEN);
1248 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1249 PSCTS pBuf = (PSCTS)pvCTS;
1250 //Get SignalField,ServiceField,Length
1251 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1252 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1254 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1255 //Get CTSDuration_ba
1256 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
1257 pBuf->wDuration_ba += pDevice->wCTSDuration;
1258 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1260 //Get CTS Frame body
1261 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1262 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1263 pBuf->Data.wReserved = 0x0000;
1264 memcpy(&(pBuf->Data.abyRA[0]),
1265 &(pDevice->abyCurrentNetAddr[0]),
1266 ETH_ALEN);
1273 * Description:
1274 * Generate FIFO control for MAC & Baseband controller
1276 * Parameters:
1277 * In:
1278 * pDevice - Pointer to adpater
1279 * pTxDataHead - Transmit Data Buffer
1280 * pTxBufHead - pTxBufHead
1281 * pvRrvTime - pvRrvTime
1282 * pvRTS - RTS Buffer
1283 * pCTS - CTS Buffer
1284 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1285 * bNeedACK - If need ACK
1286 * uDMAIdx - DMA Index
1287 * Out:
1288 * none
1290 * Return Value: none
1294 static
1295 void
1296 s_vGenerateTxParameter (
1297 PSDevice pDevice,
1298 BYTE byPktType,
1299 WORD wCurrentRate,
1300 void *pTxBufHead,
1301 void *pvRrvTime,
1302 void *pvRTS,
1303 void *pvCTS,
1304 unsigned int cbFrameSize,
1305 BOOL bNeedACK,
1306 unsigned int uDMAIdx,
1307 PSEthernetHeader psEthHeader
1310 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
1311 WORD wFifoCtl;
1312 BOOL bDisCRC = FALSE;
1313 BYTE byFBOption = AUTO_FB_NONE;
1314 // WORD wCurrentRate = pDevice->wCurrentRate;
1316 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1317 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1318 pFifoHead->wReserved = wCurrentRate;
1319 wFifoCtl = pFifoHead->wFIFOCtl;
1321 if (wFifoCtl & FIFOCTL_CRCDIS) {
1322 bDisCRC = TRUE;
1325 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1326 byFBOption = AUTO_FB_0;
1328 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1329 byFBOption = AUTO_FB_1;
1332 if (pDevice->bLongHeader)
1333 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1335 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1337 if (pvRTS != NULL) { //RTS_need
1338 //Fill RsvTime
1339 if (pvRrvTime) {
1340 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1341 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1342 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1343 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1344 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1345 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1347 //Fill RTS
1348 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1350 else {//RTS_needless, PCF mode
1352 //Fill RsvTime
1353 if (pvRrvTime) {
1354 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1355 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1356 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1357 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1359 //Fill CTS
1360 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1363 else if (byPktType == PK_TYPE_11A) {
1365 if (pvRTS != NULL) {//RTS_need, non PCF mode
1366 //Fill RsvTime
1367 if (pvRrvTime) {
1368 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1369 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1370 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1372 //Fill RTS
1373 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1375 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1376 //Fill RsvTime
1377 if (pvRrvTime) {
1378 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1379 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1383 else if (byPktType == PK_TYPE_11B) {
1385 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1386 //Fill RsvTime
1387 if (pvRrvTime) {
1388 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1389 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1390 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1392 //Fill RTS
1393 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1395 else { //RTS_needless, non PCF mode
1396 //Fill RsvTime
1397 if (pvRrvTime) {
1398 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1399 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1403 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1406 PBYTE pbyBuffer,//point to pTxBufHead
1407 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1408 unsigned int cbFragmentSize,//Hdr+payoad+FCS
1412 BOOL
1413 s_bPacketToWirelessUsb(
1414 PSDevice pDevice,
1415 BYTE byPktType,
1416 PBYTE usbPacketBuf,
1417 BOOL bNeedEncryption,
1418 unsigned int uSkbPacketLen,
1419 unsigned int uDMAIdx,
1420 PSEthernetHeader psEthHeader,
1421 PBYTE pPacket,
1422 PSKeyItem pTransmitKey,
1423 unsigned int uNodeIndex,
1424 WORD wCurrentRate,
1425 unsigned int *pcbHeaderLen,
1426 unsigned int *pcbTotalLen
1429 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1430 unsigned int cbFrameSize, cbFrameBodySize;
1431 PTX_BUFFER pTxBufHead;
1432 unsigned int cb802_1_H_len;
1433 unsigned int cbIVlen = 0, cbICVlen = 0, cbMIClen = 0,
1434 cbMACHdLen = 0, cbFCSlen = 4;
1435 unsigned int cbMICHDR = 0;
1436 BOOL bNeedACK,bRTS;
1437 PBYTE pbyType,pbyMacHdr,pbyIVHead,pbyPayloadHead,pbyTxBufferAddr;
1438 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1439 BYTE abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1440 unsigned int uDuration;
1441 unsigned int cbHeaderLength = 0, uPadding = 0;
1442 void *pvRrvTime;
1443 PSMICHDRHead pMICHDR;
1444 void *pvRTS;
1445 void *pvCTS;
1446 void *pvTxDataHd;
1447 BYTE byFBOption = AUTO_FB_NONE,byFragType;
1448 WORD wTxBufSize;
1449 DWORD dwMICKey0,dwMICKey1,dwMIC_Priority,dwCRC;
1450 PDWORD pdwMIC_L,pdwMIC_R;
1451 BOOL bSoftWEP = FALSE;
1456 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1457 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1458 if (((PSKeyTable) (pTransmitKey->pvKeyTable))->bSoftWEP == TRUE) {
1459 // WEP 256
1460 bSoftWEP = TRUE;
1464 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
1465 memset(pTxBufHead, 0, sizeof(TX_BUFFER));
1467 // Get pkt type
1468 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1469 if (pDevice->dwDiagRefCount == 0) {
1470 cb802_1_H_len = 8;
1471 } else {
1472 cb802_1_H_len = 2;
1474 } else {
1475 cb802_1_H_len = 0;
1478 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
1480 //Set packet type
1481 pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8);
1483 if (pDevice->dwDiagRefCount != 0) {
1484 bNeedACK = FALSE;
1485 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1486 } else { //if (pDevice->dwDiagRefCount != 0) {
1487 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1488 (pDevice->eOPMode == OP_MODE_AP)) {
1489 if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) {
1490 bNeedACK = FALSE;
1491 pTxBufHead->wFIFOCtl =
1492 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1493 } else {
1494 bNeedACK = TRUE;
1495 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1498 else {
1499 // MSDUs in Infra mode always need ACK
1500 bNeedACK = TRUE;
1501 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1503 } //if (pDevice->dwDiagRefCount != 0) {
1505 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1507 //Set FIFOCTL_LHEAD
1508 if (pDevice->bLongHeader)
1509 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1511 if (pDevice->bSoftwareGenCrcErr) {
1512 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS; // set tx descriptors to NO hardware CRC
1515 //Set FRAGCTL_MACHDCNT
1516 if (pDevice->bLongHeader) {
1517 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1518 } else {
1519 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1521 pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10);
1523 //Set FIFOCTL_GrpAckPolicy
1524 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
1525 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1528 //Set Auto Fallback Ctl
1529 if (wCurrentRate >= RATE_18M) {
1530 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1531 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1532 byFBOption = AUTO_FB_0;
1533 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1534 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1535 byFBOption = AUTO_FB_1;
1539 if (bSoftWEP != TRUE) {
1540 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1541 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1542 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1544 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1546 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1548 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1549 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1555 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1556 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1557 cbIVlen = 4;
1558 cbICVlen = 4;
1560 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1561 cbIVlen = 8;//IV+ExtIV
1562 cbMIClen = 8;
1563 cbICVlen = 4;
1565 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1566 cbIVlen = 8;//RSN Header
1567 cbICVlen = 8;//MIC
1568 cbMICHDR = sizeof(SMICHDRHead);
1570 if (bSoftWEP == FALSE) {
1571 //MAC Header should be padding 0 to DW alignment.
1572 uPadding = 4 - (cbMACHdLen%4);
1573 uPadding %= 4;
1577 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1579 if ( (bNeedACK == FALSE) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1580 bRTS = FALSE;
1581 } else {
1582 bRTS = TRUE;
1583 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1586 pbyTxBufferAddr = (PBYTE) &(pTxBufHead->adwTxKey[0]);
1587 wTxBufSize = sizeof(STxBufHead);
1588 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1589 if (byFBOption == AUTO_FB_NONE) {
1590 if (bRTS == TRUE) {//RTS_need
1591 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1592 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1593 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1594 pvCTS = NULL;
1595 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1596 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1598 else { //RTS_needless
1599 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1600 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1601 pvRTS = NULL;
1602 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1603 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1604 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1606 } else {
1607 // Auto Fall Back
1608 if (bRTS == TRUE) {//RTS_need
1609 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1610 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1611 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1612 pvCTS = NULL;
1613 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1614 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1616 else if (bRTS == FALSE) { //RTS_needless
1617 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1618 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1619 pvRTS = NULL;
1620 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1621 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1622 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1624 } // Auto Fall Back
1626 else {//802.11a/b packet
1627 if (byFBOption == AUTO_FB_NONE) {
1628 if (bRTS == TRUE) {//RTS_need
1629 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1630 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1631 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1632 pvCTS = NULL;
1633 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1634 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1636 else if (bRTS == FALSE) { //RTS_needless, no MICHDR
1637 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1638 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1639 pvRTS = NULL;
1640 pvCTS = NULL;
1641 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1642 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1644 } else {
1645 // Auto Fall Back
1646 if (bRTS == TRUE) {//RTS_need
1647 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1648 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1649 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1650 pvCTS = NULL;
1651 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1652 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1654 else if (bRTS == FALSE) { //RTS_needless
1655 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1656 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1657 pvRTS = NULL;
1658 pvCTS = NULL;
1659 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1660 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1662 } // Auto Fall Back
1665 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1666 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1667 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1670 //=========================
1671 // No Fragmentation
1672 //=========================
1673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1674 byFragType = FRAGCTL_NONFRAG;
1675 //uDMAIdx = TYPE_AC0DMA;
1676 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1679 //Fill FIFO,RrvTime,RTS,and CTS
1680 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1681 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
1682 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1683 //Fill DataHead
1684 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1685 0, 0, 1/*uMACfragNum*/, byFBOption);
1686 // Generate TX MAC Header
1687 s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption,
1688 byFragType, uDMAIdx, 0);
1690 if (bNeedEncryption == TRUE) {
1691 //Fill TXKEY
1692 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1693 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
1695 if (pDevice->bEnableHostWEP) {
1696 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1697 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1701 // 802.1H
1702 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1703 if (pDevice->dwDiagRefCount == 0) {
1704 if ((psEthHeader->wType == cpu_to_le16(ETH_P_IPX)) ||
1705 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1706 memcpy((PBYTE) (pbyPayloadHead),
1707 abySNAP_Bridgetunnel, 6);
1708 } else {
1709 memcpy((PBYTE) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1711 pbyType = (PBYTE) (pbyPayloadHead + 6);
1712 memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1713 } else {
1714 memcpy((PBYTE) (pbyPayloadHead), &(psEthHeader->wType), sizeof(WORD));
1721 if (pPacket != NULL) {
1722 // Copy the Packet into a tx Buffer
1723 memcpy((pbyPayloadHead + cb802_1_H_len),
1724 (pPacket + ETH_HLEN),
1725 uSkbPacketLen - ETH_HLEN
1728 } else {
1729 // while bRelayPacketSend psEthHeader is point to header+payload
1730 memcpy((pbyPayloadHead + cb802_1_H_len), ((PBYTE)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
1733 ASSERT(uLength == cbNdisBodySize);
1735 if ((bNeedEncryption == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1737 ///////////////////////////////////////////////////////////////////
1739 if (pDevice->sMgmtObj.eAuthenMode == WMAC_AUTH_WPANONE) {
1740 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1741 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1743 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1744 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1745 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1747 else {
1748 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1749 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1751 // DO Software Michael
1752 MIC_vInit(dwMICKey0, dwMICKey1);
1753 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1754 dwMIC_Priority = 0;
1755 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1758 ///////////////////////////////////////////////////////////////////
1760 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1761 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1762 // DBG_PRN_GRP12(("%02x ", *((PBYTE)((pbyPayloadHead + cb802_1_H_len) + ii))));
1764 //DBG_PRN_GRP12(("\n\n\n"));
1766 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1768 pdwMIC_L = (PDWORD)(pbyPayloadHead + cbFrameBodySize);
1769 pdwMIC_R = (PDWORD)(pbyPayloadHead + cbFrameBodySize + 4);
1771 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1772 MIC_vUnInit();
1774 if (pDevice->bTxMICFail == TRUE) {
1775 *pdwMIC_L = 0;
1776 *pdwMIC_R = 0;
1777 pDevice->bTxMICFail = FALSE;
1779 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1780 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1781 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1785 if (bSoftWEP == TRUE) {
1787 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen));
1789 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == TRUE)) ||
1790 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == TRUE)) ||
1791 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == TRUE)) ) {
1792 cbFrameSize -= cbICVlen;
1795 if (pDevice->bSoftwareGenCrcErr == TRUE) {
1796 unsigned int cbLen;
1797 PDWORD pdwCRC;
1799 dwCRC = 0xFFFFFFFFL;
1800 cbLen = cbFrameSize - cbFCSlen;
1801 // calculate CRC, and wrtie CRC value to end of TD
1802 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
1803 pdwCRC = (PDWORD)(pbyMacHdr + cbLen);
1804 // finally, we must invert dwCRC to get the correct answer
1805 *pdwCRC = ~dwCRC;
1806 // Force Error
1807 *pdwCRC -= 1;
1808 } else {
1809 cbFrameSize -= cbFCSlen;
1812 *pcbHeaderLen = cbHeaderLength;
1813 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1816 //Set FragCtl in TxBufferHead
1817 pTxBufHead->wFragCtl |= (WORD)byFragType;
1820 return TRUE;
1827 * Description:
1828 * Translate 802.3 to 802.11 header
1830 * Parameters:
1831 * In:
1832 * pDevice - Pointer to adpater
1833 * dwTxBufferAddr - Transmit Buffer
1834 * pPacket - Packet from upper layer
1835 * cbPacketSize - Transmit Data Length
1836 * Out:
1837 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1838 * pcbAppendPayload - size of append payload for 802.1H translation
1840 * Return Value: none
1844 void
1845 s_vGenerateMACHeader (
1846 PSDevice pDevice,
1847 PBYTE pbyBufferAddr,
1848 WORD wDuration,
1849 PSEthernetHeader psEthHeader,
1850 BOOL bNeedEncrypt,
1851 WORD wFragType,
1852 unsigned int uDMAIdx,
1853 unsigned int uFragIdx
1856 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
1858 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
1860 if (uDMAIdx == TYPE_ATIMDMA) {
1861 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
1862 } else {
1863 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
1866 if (pDevice->eOPMode == OP_MODE_AP) {
1867 memcpy(&(pMACHeader->abyAddr1[0]),
1868 &(psEthHeader->abyDstAddr[0]),
1869 ETH_ALEN);
1870 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1871 memcpy(&(pMACHeader->abyAddr3[0]),
1872 &(psEthHeader->abySrcAddr[0]),
1873 ETH_ALEN);
1874 pMACHeader->wFrameCtl |= FC_FROMDS;
1875 } else {
1876 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1877 memcpy(&(pMACHeader->abyAddr1[0]),
1878 &(psEthHeader->abyDstAddr[0]),
1879 ETH_ALEN);
1880 memcpy(&(pMACHeader->abyAddr2[0]),
1881 &(psEthHeader->abySrcAddr[0]),
1882 ETH_ALEN);
1883 memcpy(&(pMACHeader->abyAddr3[0]),
1884 &(pDevice->abyBSSID[0]),
1885 ETH_ALEN);
1886 } else {
1887 memcpy(&(pMACHeader->abyAddr3[0]),
1888 &(psEthHeader->abyDstAddr[0]),
1889 ETH_ALEN);
1890 memcpy(&(pMACHeader->abyAddr2[0]),
1891 &(psEthHeader->abySrcAddr[0]),
1892 ETH_ALEN);
1893 memcpy(&(pMACHeader->abyAddr1[0]),
1894 &(pDevice->abyBSSID[0]),
1895 ETH_ALEN);
1896 pMACHeader->wFrameCtl |= FC_TODS;
1900 if (bNeedEncrypt)
1901 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
1903 pMACHeader->wDurationID = cpu_to_le16(wDuration);
1905 if (pDevice->bLongHeader) {
1906 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1907 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
1908 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
1910 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1912 //Set FragNumber in Sequence Control
1913 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
1915 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1916 pDevice->wSeqCounter++;
1917 if (pDevice->wSeqCounter > 0x0fff)
1918 pDevice->wSeqCounter = 0;
1921 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1922 pMACHeader->wFrameCtl |= FC_MOREFRAG;
1930 * Description:
1931 * Request instructs a MAC to transmit a 802.11 management packet through
1932 * the adapter onto the medium.
1934 * Parameters:
1935 * In:
1936 * hDeviceContext - Pointer to the adapter
1937 * pPacket - A pointer to a descriptor for the packet to transmit
1938 * Out:
1939 * none
1941 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise FALSE
1945 CMD_STATUS csMgmt_xmit(
1946 PSDevice pDevice,
1947 PSTxMgmtPacket pPacket
1950 BYTE byPktType;
1951 PBYTE pbyTxBufferAddr;
1952 void *pvRTS;
1953 PSCTS pCTS;
1954 void *pvTxDataHd;
1955 unsigned int uDuration;
1956 unsigned int cbReqCount;
1957 PS802_11Header pMACHeader;
1958 unsigned int cbHeaderSize;
1959 unsigned int cbFrameBodySize;
1960 BOOL bNeedACK;
1961 BOOL bIsPSPOLL = FALSE;
1962 PSTxBufHead pTxBufHead;
1963 unsigned int cbFrameSize;
1964 unsigned int cbIVlen = 0;
1965 unsigned int cbICVlen = 0;
1966 unsigned int cbMIClen = 0;
1967 unsigned int cbFCSlen = 4;
1968 unsigned int uPadding = 0;
1969 WORD wTxBufSize;
1970 unsigned int cbMacHdLen;
1971 SEthernetHeader sEthHeader;
1972 void *pvRrvTime;
1973 void *pMICHDR;
1974 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1975 WORD wCurrentRate = RATE_1M;
1976 PTX_BUFFER pTX_Buffer;
1977 PUSB_SEND_CONTEXT pContext;
1981 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1983 if (NULL == pContext) {
1984 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1985 return CMD_STATUS_RESOURCES;
1988 pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
1989 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->adwTxKey[0]);
1990 cbFrameBodySize = pPacket->cbPayloadLen;
1991 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1992 wTxBufSize = sizeof(STxBufHead);
1993 memset(pTxBufHead, 0, wTxBufSize);
1995 if (pDevice->byBBType == BB_TYPE_11A) {
1996 wCurrentRate = RATE_6M;
1997 byPktType = PK_TYPE_11A;
1998 } else {
1999 wCurrentRate = RATE_1M;
2000 byPktType = PK_TYPE_11B;
2003 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2004 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2005 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2006 // to set power here.
2007 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2008 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2009 } else {
2010 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2012 pDevice->wCurrentRate = wCurrentRate;
2015 //Set packet type
2016 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2017 pTxBufHead->wFIFOCtl = 0;
2019 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2020 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2022 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2023 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2025 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2026 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2029 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2030 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2032 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
2033 bNeedACK = FALSE;
2035 else {
2036 bNeedACK = TRUE;
2037 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2040 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2041 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2043 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2044 //Set Preamble type always long
2045 //pDevice->byPreambleType = PREAMBLE_LONG;
2046 // probe-response don't retry
2047 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2048 // bNeedACK = FALSE;
2049 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2053 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2055 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2056 bIsPSPOLL = TRUE;
2057 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2058 } else {
2059 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2062 //Set FRAGCTL_MACHDCNT
2063 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2065 // Notes:
2066 // Although spec says MMPDU can be fragmented; In most case,
2067 // no one will send a MMPDU under fragmentation. With RTS may occur.
2068 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2070 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2071 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2072 cbIVlen = 4;
2073 cbICVlen = 4;
2074 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2076 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2077 cbIVlen = 8;//IV+ExtIV
2078 cbMIClen = 8;
2079 cbICVlen = 4;
2080 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2081 //We need to get seed here for filling TxKey entry.
2082 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2083 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2085 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2086 cbIVlen = 8;//RSN Header
2087 cbICVlen = 8;//MIC
2088 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2089 pDevice->bAES = TRUE;
2091 //MAC Header should be padding 0 to DW alignment.
2092 uPadding = 4 - (cbMacHdLen%4);
2093 uPadding %= 4;
2096 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2098 //Set FIFOCTL_GrpAckPolicy
2099 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2100 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2102 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2104 //Set RrvTime/RTS/CTS Buffer
2105 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2107 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2108 pMICHDR = NULL;
2109 pvRTS = NULL;
2110 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2111 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2112 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2114 else { // 802.11a/b packet
2115 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2116 pMICHDR = NULL;
2117 pvRTS = NULL;
2118 pCTS = NULL;
2119 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2120 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2123 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
2124 (cbHeaderSize - wTxBufSize));
2126 memcpy(&(sEthHeader.abyDstAddr[0]),
2127 &(pPacket->p80211Header->sA3.abyAddr1[0]),
2128 ETH_ALEN);
2129 memcpy(&(sEthHeader.abySrcAddr[0]),
2130 &(pPacket->p80211Header->sA3.abyAddr2[0]),
2131 ETH_ALEN);
2132 //=========================
2133 // No Fragmentation
2134 //=========================
2135 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2138 //Fill FIFO,RrvTime,RTS,and CTS
2139 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2140 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2142 //Fill DataHead
2143 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2144 0, 0, 1, AUTO_FB_NONE);
2146 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2148 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2150 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2151 PBYTE pbyIVHead;
2152 PBYTE pbyPayloadHead;
2153 PBYTE pbyBSSID;
2154 PSKeyItem pTransmitKey = NULL;
2156 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2157 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2158 do {
2159 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2160 (pDevice->bLinkPass == TRUE)) {
2161 pbyBSSID = pDevice->abyBSSID;
2162 // get pairwise key
2163 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2164 // get group key
2165 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2166 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2167 break;
2169 } else {
2170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2171 break;
2174 // get group key
2175 pbyBSSID = pDevice->abyBroadcastAddr;
2176 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2177 pTransmitKey = NULL;
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2179 } else {
2180 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2182 } while(FALSE);
2183 //Fill TXKEY
2184 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2185 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2187 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2188 memcpy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2189 cbFrameBodySize);
2191 else {
2192 // Copy the Packet into a tx Buffer
2193 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2196 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2197 pDevice->wSeqCounter++ ;
2198 if (pDevice->wSeqCounter > 0x0fff)
2199 pDevice->wSeqCounter = 0;
2201 if (bIsPSPOLL) {
2202 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2203 // of FIFO control header.
2204 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2205 // in the same place of other packet's Duration-field).
2206 // And it will cause Cisco-AP to issue Disassociation-packet
2207 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2208 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2209 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2210 } else {
2211 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2216 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2217 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2218 pTX_Buffer->byType = 0x00;
2220 pContext->pPacket = NULL;
2221 pContext->Type = CONTEXT_MGMT_PACKET;
2222 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2224 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2225 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2227 else {
2228 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2231 PIPEnsSendBulkOut(pDevice,pContext);
2232 return CMD_STATUS_PENDING;
2236 CMD_STATUS
2237 csBeacon_xmit(
2238 PSDevice pDevice,
2239 PSTxMgmtPacket pPacket
2243 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2244 unsigned int cbHeaderSize = 0;
2245 WORD wTxBufSize = sizeof(STxShortBufHead);
2246 PSTxShortBufHead pTxBufHead;
2247 PS802_11Header pMACHeader;
2248 PSTxDataHead_ab pTxDataHead;
2249 WORD wCurrentRate;
2250 unsigned int cbFrameBodySize;
2251 unsigned int cbReqCount;
2252 PBEACON_BUFFER pTX_Buffer;
2253 PBYTE pbyTxBufferAddr;
2254 PUSB_SEND_CONTEXT pContext;
2255 CMD_STATUS status;
2258 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2259 if (NULL == pContext) {
2260 status = CMD_STATUS_RESOURCES;
2261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
2262 return status ;
2264 pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
2265 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->wFIFOCtl);
2267 cbFrameBodySize = pPacket->cbPayloadLen;
2269 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
2270 wTxBufSize = sizeof(STxShortBufHead);
2271 memset(pTxBufHead, 0, wTxBufSize);
2273 if (pDevice->byBBType == BB_TYPE_11A) {
2274 wCurrentRate = RATE_6M;
2275 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2276 //Get SignalField,ServiceField,Length
2277 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
2278 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2280 //Get Duration and TimeStampOff
2281 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
2282 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2283 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2284 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2285 } else {
2286 wCurrentRate = RATE_1M;
2287 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2288 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2289 //Get SignalField,ServiceField,Length
2290 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
2291 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2293 //Get Duration and TimeStampOff
2294 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
2295 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2296 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2297 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2300 //Generate Beacon Header
2301 pMACHeader = (PS802_11Header)(pbyTxBufferAddr + cbHeaderSize);
2302 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2304 pMACHeader->wDurationID = 0;
2305 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2306 pDevice->wSeqCounter++ ;
2307 if (pDevice->wSeqCounter > 0x0fff)
2308 pDevice->wSeqCounter = 0;
2310 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
2312 pTX_Buffer->wTxByteCount = (WORD)cbReqCount;
2313 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2314 pTX_Buffer->byType = 0x01;
2316 pContext->pPacket = NULL;
2317 pContext->Type = CONTEXT_MGMT_PACKET;
2318 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2320 PIPEnsSendBulkOut(pDevice,pContext);
2321 return CMD_STATUS_PENDING;
2329 void
2330 vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2332 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2333 BYTE byPktType;
2334 PBYTE pbyTxBufferAddr;
2335 void *pvRTS;
2336 void *pvCTS;
2337 void *pvTxDataHd;
2338 unsigned int uDuration;
2339 unsigned int cbReqCount;
2340 PS802_11Header pMACHeader;
2341 unsigned int cbHeaderSize;
2342 unsigned int cbFrameBodySize;
2343 BOOL bNeedACK;
2344 BOOL bIsPSPOLL = FALSE;
2345 PSTxBufHead pTxBufHead;
2346 unsigned int cbFrameSize;
2347 unsigned int cbIVlen = 0;
2348 unsigned int cbICVlen = 0;
2349 unsigned int cbMIClen = 0;
2350 unsigned int cbFCSlen = 4;
2351 unsigned int uPadding = 0;
2352 unsigned int cbMICHDR = 0;
2353 unsigned int uLength = 0;
2354 DWORD dwMICKey0, dwMICKey1;
2355 DWORD dwMIC_Priority;
2356 PDWORD pdwMIC_L;
2357 PDWORD pdwMIC_R;
2358 WORD wTxBufSize;
2359 unsigned int cbMacHdLen;
2360 SEthernetHeader sEthHeader;
2361 void *pvRrvTime;
2362 void *pMICHDR;
2363 WORD wCurrentRate = RATE_1M;
2364 PUWLAN_80211HDR p80211Header;
2365 unsigned int uNodeIndex = 0;
2366 BOOL bNodeExist = FALSE;
2367 SKeyItem STempKey;
2368 PSKeyItem pTransmitKey = NULL;
2369 PBYTE pbyIVHead;
2370 PBYTE pbyPayloadHead;
2371 PBYTE pbyMacHdr;
2372 unsigned int cbExtSuppRate = 0;
2373 PTX_BUFFER pTX_Buffer;
2374 PUSB_SEND_CONTEXT pContext;
2375 // PWLAN_IE pItem;
2378 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2380 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
2381 cbFrameBodySize = 0;
2383 else {
2384 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
2386 p80211Header = (PUWLAN_80211HDR)skb->data;
2388 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2390 if (NULL == pContext) {
2391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
2392 dev_kfree_skb_irq(skb);
2393 return ;
2396 pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
2397 pbyTxBufferAddr = (PBYTE)(&pTX_Buffer->adwTxKey[0]);
2398 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2399 wTxBufSize = sizeof(STxBufHead);
2400 memset(pTxBufHead, 0, wTxBufSize);
2402 if (pDevice->byBBType == BB_TYPE_11A) {
2403 wCurrentRate = RATE_6M;
2404 byPktType = PK_TYPE_11A;
2405 } else {
2406 wCurrentRate = RATE_1M;
2407 byPktType = PK_TYPE_11B;
2410 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2411 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2412 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2413 // to set power here.
2414 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2415 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2416 } else {
2417 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2422 //Set packet type
2423 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2424 pTxBufHead->wFIFOCtl = 0;
2426 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2427 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2429 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2430 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2432 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2433 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2436 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2437 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2439 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
2440 bNeedACK = FALSE;
2441 if (pDevice->bEnableHostWEP) {
2442 uNodeIndex = 0;
2443 bNodeExist = TRUE;
2446 else {
2447 if (pDevice->bEnableHostWEP) {
2448 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2449 bNodeExist = TRUE;
2451 bNeedACK = TRUE;
2452 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2455 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2456 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2458 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2459 //Set Preamble type always long
2460 //pDevice->byPreambleType = PREAMBLE_LONG;
2462 // probe-response don't retry
2463 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2464 // bNeedACK = FALSE;
2465 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2469 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2471 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2472 bIsPSPOLL = TRUE;
2473 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2474 } else {
2475 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2478 // hostapd deamon ext support rate patch
2479 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2481 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2482 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2485 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2486 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2489 if (cbExtSuppRate >0) {
2490 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2495 //Set FRAGCTL_MACHDCNT
2496 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
2498 // Notes:
2499 // Although spec says MMPDU can be fragmented; In most case,
2500 // no one will send a MMPDU under fragmentation. With RTS may occur.
2501 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2504 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2505 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2506 cbIVlen = 4;
2507 cbICVlen = 4;
2508 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2510 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2511 cbIVlen = 8;//IV+ExtIV
2512 cbMIClen = 8;
2513 cbICVlen = 4;
2514 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2515 //We need to get seed here for filling TxKey entry.
2516 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2517 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2519 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2520 cbIVlen = 8;//RSN Header
2521 cbICVlen = 8;//MIC
2522 cbMICHDR = sizeof(SMICHDRHead);
2523 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2524 pDevice->bAES = TRUE;
2526 //MAC Header should be padding 0 to DW alignment.
2527 uPadding = 4 - (cbMacHdLen%4);
2528 uPadding %= 4;
2531 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2533 //Set FIFOCTL_GrpAckPolicy
2534 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2535 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2537 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2540 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2542 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2543 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2544 pvRTS = NULL;
2545 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
2546 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
2547 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
2550 else {//802.11a/b packet
2552 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2553 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2554 pvRTS = NULL;
2555 pvCTS = NULL;
2556 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2557 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2559 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
2560 (cbHeaderSize - wTxBufSize));
2561 memcpy(&(sEthHeader.abyDstAddr[0]),
2562 &(p80211Header->sA3.abyAddr1[0]),
2563 ETH_ALEN);
2564 memcpy(&(sEthHeader.abySrcAddr[0]),
2565 &(p80211Header->sA3.abyAddr2[0]),
2566 ETH_ALEN);
2567 //=========================
2568 // No Fragmentation
2569 //=========================
2570 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2573 //Fill FIFO,RrvTime,RTS,and CTS
2574 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2575 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2577 //Fill DataHead
2578 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2579 0, 0, 1, AUTO_FB_NONE);
2581 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2583 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2585 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
2586 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2587 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
2589 // Copy the Packet into a tx Buffer
2590 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2592 // version set to 0, patch for hostapd deamon
2593 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
2594 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2596 // replace support rate, patch for hostapd deamon( only support 11M)
2597 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2598 if (cbExtSuppRate != 0) {
2599 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2600 memcpy((pbyPayloadHead + cbFrameBodySize),
2601 pMgmt->abyCurrSuppRates,
2602 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2604 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2605 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2606 pMgmt->abyCurrExtSuppRates,
2607 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2612 // Set wep
2613 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2615 if (pDevice->bEnableHostWEP) {
2616 pTransmitKey = &STempKey;
2617 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2618 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2619 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2620 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2621 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2622 memcpy(pTransmitKey->abyKey,
2623 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2624 pTransmitKey->uKeyLength
2628 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2630 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
2631 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
2633 // DO Software Michael
2634 MIC_vInit(dwMICKey0, dwMICKey1);
2635 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
2636 dwMIC_Priority = 0;
2637 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
2638 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
2640 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2642 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2644 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2645 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2647 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2648 MIC_vUnInit();
2650 if (pDevice->bTxMICFail == TRUE) {
2651 *pdwMIC_L = 0;
2652 *pdwMIC_R = 0;
2653 pDevice->bTxMICFail = FALSE;
2656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2658 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2662 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2663 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
2665 if (pDevice->bEnableHostWEP) {
2666 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2667 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2670 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
2671 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
2675 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2676 pDevice->wSeqCounter++ ;
2677 if (pDevice->wSeqCounter > 0x0fff)
2678 pDevice->wSeqCounter = 0;
2681 if (bIsPSPOLL) {
2682 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2683 // of FIFO control header.
2684 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2685 // in the same place of other packet's Duration-field).
2686 // And it will cause Cisco-AP to issue Disassociation-packet
2687 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2688 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2689 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2690 } else {
2691 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2695 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2696 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2697 pTX_Buffer->byType = 0x00;
2699 pContext->pPacket = skb;
2700 pContext->Type = CONTEXT_MGMT_PACKET;
2701 pContext->uBufLen = (WORD)cbReqCount + 4; //USB header
2703 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2704 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2706 else {
2707 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2709 PIPEnsSendBulkOut(pDevice,pContext);
2710 return ;
2717 //TYPE_AC0DMA data tx
2719 * Description:
2720 * Tx packet via AC0DMA(DMA1)
2722 * Parameters:
2723 * In:
2724 * pDevice - Pointer to the adapter
2725 * skb - Pointer to tx skb packet
2726 * Out:
2727 * void
2729 * Return Value: NULL
2732 int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2734 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2735 unsigned int BytesToWrite = 0, uHeaderLen = 0;
2736 unsigned int uNodeIndex = 0;
2737 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2738 WORD wAID;
2739 BYTE byPktType;
2740 BOOL bNeedEncryption = FALSE;
2741 PSKeyItem pTransmitKey = NULL;
2742 SKeyItem STempKey;
2743 unsigned int ii;
2744 BOOL bTKIP_UseGTK = FALSE;
2745 BOOL bNeedDeAuth = FALSE;
2746 PBYTE pbyBSSID;
2747 BOOL bNodeExist = FALSE;
2748 PUSB_SEND_CONTEXT pContext;
2749 BOOL fConvertedPacket;
2750 PTX_BUFFER pTX_Buffer;
2751 unsigned int status;
2752 WORD wKeepRate = pDevice->wCurrentRate;
2753 struct net_device_stats* pStats = &pDevice->stats;
2754 BOOL bTxeapol_key = FALSE;
2757 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2759 if (pDevice->uAssocCount == 0) {
2760 dev_kfree_skb_irq(skb);
2761 return 0;
2764 if (is_multicast_ether_addr((PBYTE)(skb->data))) {
2765 uNodeIndex = 0;
2766 bNodeExist = TRUE;
2767 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2769 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2770 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2771 // set tx map
2772 pMgmt->abyPSTxMap[0] |= byMask[0];
2773 return 0;
2775 // muticast/broadcast data rate
2777 if (pDevice->byBBType != BB_TYPE_11A)
2778 pDevice->wCurrentRate = RATE_2M;
2779 else
2780 pDevice->wCurrentRate = RATE_24M;
2781 // long preamble type
2782 pDevice->byPreambleType = PREAMBLE_SHORT;
2784 }else {
2786 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data), &uNodeIndex)) {
2788 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2790 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2792 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2793 // set tx map
2794 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2795 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2796 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2797 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2799 return 0;
2801 // AP rate decided from node
2802 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2803 // tx preamble decided from node
2805 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2806 pDevice->byPreambleType = pDevice->byShortPreamble;
2808 }else {
2809 pDevice->byPreambleType = PREAMBLE_LONG;
2811 bNodeExist = TRUE;
2815 if (bNodeExist == FALSE) {
2816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2817 dev_kfree_skb_irq(skb);
2818 return 0;
2822 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2824 if (pContext == NULL) {
2825 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2826 dev_kfree_skb_irq(skb);
2827 return STATUS_RESOURCES;
2830 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), ETH_HLEN);
2832 //mike add:station mode check eapol-key challenge--->
2834 BYTE Protocol_Version; //802.1x Authentication
2835 BYTE Packet_Type; //802.1x Authentication
2836 BYTE Descriptor_type;
2837 WORD Key_info;
2839 Protocol_Version = skb->data[ETH_HLEN];
2840 Packet_Type = skb->data[ETH_HLEN+1];
2841 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2842 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2843 if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) {
2844 /* 802.1x OR eapol-key challenge frame transfer */
2845 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2846 (Packet_Type == 3)) {
2847 bTxeapol_key = TRUE;
2848 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2849 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2850 if(Descriptor_type==254) {
2851 pDevice->fWPA_Authened = TRUE;
2852 PRINT_K("WPA ");
2854 else {
2855 pDevice->fWPA_Authened = TRUE;
2856 PRINT_K("WPA2(re-keying) ");
2858 PRINT_K("Authentication completed!!\n");
2860 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairse-key challenge
2861 (Key_info & BIT8) && (Key_info & BIT9)) {
2862 pDevice->fWPA_Authened = TRUE;
2863 PRINT_K("WPA2 Authentication completed!!\n");
2868 //mike add:station mode check eapol-key challenge<---
2870 if (pDevice->bEncryptionEnable == TRUE) {
2871 bNeedEncryption = TRUE;
2872 // get Transmit key
2873 do {
2874 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2875 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2876 pbyBSSID = pDevice->abyBSSID;
2877 // get pairwise key
2878 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2879 // get group key
2880 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2881 bTKIP_UseGTK = TRUE;
2882 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2883 break;
2885 } else {
2886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2887 break;
2889 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2891 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2892 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2893 for (ii = 0; ii< 6; ii++)
2894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2897 // get pairwise key
2898 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2899 break;
2901 // get group key
2902 pbyBSSID = pDevice->abyBroadcastAddr;
2903 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2904 pTransmitKey = NULL;
2905 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2906 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2908 else
2909 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2910 } else {
2911 bTKIP_UseGTK = TRUE;
2912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2914 } while(FALSE);
2917 if (pDevice->bEnableHostWEP) {
2918 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2919 if (pDevice->bEncryptionEnable == TRUE) {
2920 pTransmitKey = &STempKey;
2921 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2922 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2923 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2924 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2925 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2926 memcpy(pTransmitKey->abyKey,
2927 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2928 pTransmitKey->uKeyLength
2933 byPktType = (BYTE)pDevice->byPacketType;
2935 if (pDevice->bFixRate) {
2936 if (pDevice->byBBType == BB_TYPE_11B) {
2937 if (pDevice->uConnectionRate >= RATE_11M) {
2938 pDevice->wCurrentRate = RATE_11M;
2939 } else {
2940 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2942 } else {
2943 if ((pDevice->byBBType == BB_TYPE_11A) &&
2944 (pDevice->uConnectionRate <= RATE_6M)) {
2945 pDevice->wCurrentRate = RATE_6M;
2946 } else {
2947 if (pDevice->uConnectionRate >= RATE_54M)
2948 pDevice->wCurrentRate = RATE_54M;
2949 else
2950 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2954 else {
2955 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2956 // Adhoc Tx rate decided from node DB
2957 if (is_multicast_ether_addr(pDevice->sTxEthHeader.abyDstAddr)) {
2958 // Multicast use highest data rate
2959 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2960 // preamble type
2961 pDevice->byPreambleType = pDevice->byShortPreamble;
2963 else {
2964 if(BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.abyDstAddr[0]), &uNodeIndex)) {
2965 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2966 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2967 pDevice->byPreambleType = pDevice->byShortPreamble;
2970 else {
2971 pDevice->byPreambleType = PREAMBLE_LONG;
2973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2975 else {
2976 if (pDevice->byBBType != BB_TYPE_11A)
2977 pDevice->wCurrentRate = RATE_2M;
2978 else
2979 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2980 // abyCurrExtSuppRates[]
2981 pDevice->byPreambleType = PREAMBLE_SHORT;
2982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2986 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2987 // Infra STA rate decided from AP Node, index = 0
2988 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2992 if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) {
2993 if (pDevice->byBBType != BB_TYPE_11A) {
2994 pDevice->wCurrentRate = RATE_1M;
2995 pDevice->byACKRate = RATE_1M;
2996 pDevice->byTopCCKBasicRate = RATE_1M;
2997 pDevice->byTopOFDMBasicRate = RATE_6M;
2998 } else {
2999 pDevice->wCurrentRate = RATE_6M;
3000 pDevice->byACKRate = RATE_6M;
3001 pDevice->byTopCCKBasicRate = RATE_1M;
3002 pDevice->byTopOFDMBasicRate = RATE_6M;
3006 DBG_PRT(MSG_LEVEL_DEBUG,
3007 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
3008 pDevice->wCurrentRate);
3010 if (wKeepRate != pDevice->wCurrentRate) {
3011 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
3014 if (pDevice->wCurrentRate <= RATE_11M) {
3015 byPktType = PK_TYPE_11B;
3018 if (bNeedEncryption == TRUE) {
3019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
3020 if ((pDevice->sTxEthHeader.wType) == cpu_to_le16(ETH_P_PAE)) {
3021 bNeedEncryption = FALSE;
3022 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
3023 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
3024 if (pTransmitKey == NULL) {
3025 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
3027 else {
3028 if (bTKIP_UseGTK == TRUE) {
3029 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
3031 else {
3032 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3033 bNeedEncryption = TRUE;
3038 if (pDevice->byCntMeasure == 2) {
3039 bNeedDeAuth = TRUE;
3040 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
3043 if (pDevice->bEnableHostWEP) {
3044 if ((uNodeIndex != 0) &&
3045 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
3046 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3047 bNeedEncryption = TRUE;
3051 else {
3053 if (pTransmitKey == NULL) {
3054 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
3055 dev_kfree_skb_irq(skb);
3056 pStats->tx_dropped++;
3057 return STATUS_FAILURE;
3062 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3063 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3064 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
3065 (PBYTE)skb->data, pTransmitKey, uNodeIndex,
3066 pDevice->wCurrentRate,
3067 &uHeaderLen, &BytesToWrite
3070 if (fConvertedPacket == FALSE) {
3071 pContext->bBoolInUse = FALSE;
3072 dev_kfree_skb_irq(skb);
3073 return STATUS_FAILURE;
3076 if ( pDevice->bEnablePSMode == TRUE ) {
3077 if ( !pDevice->bPSModeTxBurst ) {
3078 bScheduleCommand((void *) pDevice,
3079 WLAN_CMD_MAC_DISPOWERSAVING,
3080 NULL);
3081 pDevice->bPSModeTxBurst = TRUE;
3085 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3086 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3087 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3089 pContext->pPacket = skb;
3090 pContext->Type = CONTEXT_DATA_PACKET;
3091 pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
3093 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3095 status = PIPEnsSendBulkOut(pDevice,pContext);
3097 if (bNeedDeAuth == TRUE) {
3098 WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE;
3100 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason);
3103 if(status!=STATUS_PENDING) {
3104 pContext->bBoolInUse = FALSE;
3105 dev_kfree_skb_irq(skb);
3106 return STATUS_FAILURE;
3108 else
3109 return 0;
3116 * Description:
3117 * Relay packet send (AC1DMA) from rx dpc.
3119 * Parameters:
3120 * In:
3121 * pDevice - Pointer to the adapter
3122 * pPacket - Pointer to rx packet
3123 * cbPacketSize - rx ethernet frame size
3124 * Out:
3125 * TURE, FALSE
3127 * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE
3131 BOOL
3132 bRelayPacketSend (
3133 PSDevice pDevice,
3134 PBYTE pbySkbData,
3135 unsigned int uDataLen,
3136 unsigned int uNodeIndex
3139 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
3140 unsigned int BytesToWrite = 0, uHeaderLen = 0;
3141 BYTE byPktType = PK_TYPE_11B;
3142 BOOL bNeedEncryption = FALSE;
3143 SKeyItem STempKey;
3144 PSKeyItem pTransmitKey = NULL;
3145 PBYTE pbyBSSID;
3146 PUSB_SEND_CONTEXT pContext;
3147 BYTE byPktTyp;
3148 BOOL fConvertedPacket;
3149 PTX_BUFFER pTX_Buffer;
3150 unsigned int status;
3151 WORD wKeepRate = pDevice->wCurrentRate;
3155 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
3157 if (NULL == pContext) {
3158 return FALSE;
3161 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN);
3163 if (pDevice->bEncryptionEnable == TRUE) {
3164 bNeedEncryption = TRUE;
3165 // get group key
3166 pbyBSSID = pDevice->abyBroadcastAddr;
3167 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
3168 pTransmitKey = NULL;
3169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
3170 } else {
3171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
3175 if (pDevice->bEnableHostWEP) {
3176 if (uNodeIndex < MAX_NODE_NUM + 1) {
3177 pTransmitKey = &STempKey;
3178 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3179 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3180 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3181 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3182 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3183 memcpy(pTransmitKey->abyKey,
3184 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3185 pTransmitKey->uKeyLength
3190 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
3191 pContext->bBoolInUse = FALSE;
3192 return FALSE;
3195 byPktTyp = (BYTE)pDevice->byPacketType;
3197 if (pDevice->bFixRate) {
3198 if (pDevice->byBBType == BB_TYPE_11B) {
3199 if (pDevice->uConnectionRate >= RATE_11M) {
3200 pDevice->wCurrentRate = RATE_11M;
3201 } else {
3202 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3204 } else {
3205 if ((pDevice->byBBType == BB_TYPE_11A) &&
3206 (pDevice->uConnectionRate <= RATE_6M)) {
3207 pDevice->wCurrentRate = RATE_6M;
3208 } else {
3209 if (pDevice->uConnectionRate >= RATE_54M)
3210 pDevice->wCurrentRate = RATE_54M;
3211 else
3212 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3216 else {
3217 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
3220 if (wKeepRate != pDevice->wCurrentRate) {
3221 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
3224 if (pDevice->wCurrentRate <= RATE_11M)
3225 byPktType = PK_TYPE_11B;
3227 BytesToWrite = uDataLen + ETH_FCS_LEN;
3229 // Convert the packet to an usb frame and copy into our buffer
3230 // and send the irp.
3232 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3233 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3234 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
3235 pbySkbData, pTransmitKey, uNodeIndex,
3236 pDevice->wCurrentRate,
3237 &uHeaderLen, &BytesToWrite
3240 if (fConvertedPacket == FALSE) {
3241 pContext->bBoolInUse = FALSE;
3242 return FALSE;
3245 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3246 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3247 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3249 pContext->pPacket = NULL;
3250 pContext->Type = CONTEXT_DATA_PACKET;
3251 pContext->uBufLen = (WORD)BytesToWrite + 4 ; //USB header
3253 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3255 status = PIPEnsSendBulkOut(pDevice,pContext);
3257 return TRUE;