2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
21 * Purpose: handle WMAC/802.3/802.11 rx & tx 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
66 /*--------------------- Static Definitions -------------------------*/
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
71 static int msglevel
= MSG_LEVEL_INFO
;
73 /*--------------------- Static Functions --------------------------*/
75 /*--------------------- Static Definitions -------------------------*/
77 const WORD wTimeStampOff
[2][MAX_RATE
] = {
78 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
79 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
82 const WORD wFB_Opt0
[2][5] = {
83 {RATE_12M
, RATE_18M
, RATE_24M
, RATE_36M
, RATE_48M
}, // fallback_rate0
84 {RATE_12M
, RATE_12M
, RATE_18M
, RATE_24M
, RATE_36M
}, // fallback_rate1
86 const WORD wFB_Opt1
[2][5] = {
87 {RATE_12M
, RATE_18M
, RATE_24M
, RATE_24M
, RATE_36M
}, // fallback_rate0
88 {RATE_6M
, RATE_6M
, RATE_12M
, RATE_12M
, RATE_18M
}, // fallback_rate1
96 #define RTSDUR_BA_F0 4
97 #define RTSDUR_AA_F0 5
98 #define RTSDUR_BA_F1 6
99 #define RTSDUR_AA_F1 7
100 #define CTSDUR_BA_F0 8
101 #define CTSDUR_BA_F1 9
104 #define DATADUR_A_F0 12
105 #define DATADUR_A_F1 13
107 /*--------------------- Static Functions --------------------------*/
109 static void s_vSaveTxPktInfo(struct vnt_private
*pDevice
, u8 byPktNum
,
110 u8
*pbyDestAddr
, u16 wPktLength
, u16 wFIFOCtl
);
112 static void *s_vGetFreeContext(struct vnt_private
*pDevice
);
114 static void s_vGenerateTxParameter(struct vnt_private
*pDevice
,
115 u8 byPktType
, u16 wCurrentRate
, void *pTxBufHead
, void *pvRrvTime
,
116 void *pvRTS
, void *pvCTS
, u32 cbFrameSize
, int bNeedACK
, u32 uDMAIdx
,
117 PSEthernetHeader psEthHeader
);
119 static u32
s_uFillDataHead(struct vnt_private
*pDevice
,
120 u8 byPktType
, u16 wCurrentRate
, void *pTxDataHead
, u32 cbFrameLength
,
121 u32 uDMAIdx
, int bNeedAck
, u32 uFragIdx
, u32 cbLastFragmentSize
,
122 u32 uMACfragNum
, u8 byFBOption
);
125 static void s_vGenerateMACHeader(struct vnt_private
*pDevice
,
126 u8
*pbyBufferAddr
, u16 wDuration
, PSEthernetHeader psEthHeader
,
127 int bNeedEncrypt
, u16 wFragType
, u32 uDMAIdx
, u32 uFragIdx
);
129 static void s_vFillTxKey(struct vnt_private
*pDevice
, u8
*pbyBuf
,
130 u8
*pbyIVHead
, PSKeyItem pTransmitKey
, u8
*pbyHdrBuf
, u16 wPayloadLen
,
133 static void s_vSWencryption(struct vnt_private
*pDevice
,
134 PSKeyItem pTransmitKey
, u8
*pbyPayloadHead
, u16 wPayloadSize
);
136 static unsigned int s_uGetTxRsvTime(struct vnt_private
*pDevice
, u8 byPktType
,
137 u32 cbFrameLength
, u16 wRate
, int bNeedAck
);
139 static u32
s_uGetRTSCTSRsvTime(struct vnt_private
*pDevice
, u8 byRTSRsvType
,
140 u8 byPktType
, u32 cbFrameLength
, u16 wCurrentRate
);
142 static void s_vFillCTSHead(struct vnt_private
*pDevice
, u32 uDMAIdx
,
143 u8 byPktType
, void *pvCTS
, u32 cbFrameLength
, int bNeedAck
,
144 int bDisCRC
, u16 wCurrentRate
, u8 byFBOption
);
146 static void s_vFillRTSHead(struct vnt_private
*pDevice
, u8 byPktType
,
147 void *pvRTS
, u32 cbFrameLength
, int bNeedAck
, int bDisCRC
,
148 PSEthernetHeader psEthHeader
, u16 wCurrentRate
, u8 byFBOption
);
150 static u32
s_uGetDataDuration(struct vnt_private
*pDevice
, u8 byDurType
,
151 u32 cbFrameLength
, u8 byPktType
, u16 wRate
, int bNeedAck
,
152 u32 uFragIdx
, u32 cbLastFragmentSize
, u32 uMACfragNum
,
155 static unsigned int s_uGetRTSCTSDuration(struct vnt_private
*pDevice
,
156 u8 byDurType
, u32 cbFrameLength
, u8 byPktType
, u16 wRate
,
157 int bNeedAck
, u8 byFBOption
);
160 /*--------------------- Export Variables --------------------------*/
162 static void *s_vGetFreeContext(struct vnt_private
*pDevice
)
164 PUSB_SEND_CONTEXT pContext
= NULL
;
165 PUSB_SEND_CONTEXT pReturnContext
= NULL
;
168 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GetFreeContext()\n");
170 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
171 pContext
= pDevice
->apTD
[ii
];
172 if (pContext
->bBoolInUse
== false) {
173 pContext
->bBoolInUse
= true;
174 pReturnContext
= pContext
;
178 if ( ii
== pDevice
->cbTD
) {
179 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Free Tx Context\n");
181 return (void *) pReturnContext
;
185 static void s_vSaveTxPktInfo(struct vnt_private
*pDevice
, u8 byPktNum
,
186 u8
*pbyDestAddr
, u16 wPktLength
, u16 wFIFOCtl
)
188 PSStatCounter pStatistic
= &pDevice
->scStatistic
;
190 if (is_broadcast_ether_addr(pbyDestAddr
))
191 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_BROAD
;
192 else if (is_multicast_ether_addr(pbyDestAddr
))
193 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_MULTI
;
195 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_UNI
;
197 pStatistic
->abyTxPktInfo
[byPktNum
].wLength
= wPktLength
;
198 pStatistic
->abyTxPktInfo
[byPktNum
].wFIFOCtl
= wFIFOCtl
;
199 memcpy(pStatistic
->abyTxPktInfo
[byPktNum
].abyDestAddr
,
204 static void s_vFillTxKey(struct vnt_private
*pDevice
, u8
*pbyBuf
,
205 u8
*pbyIVHead
, PSKeyItem pTransmitKey
, u8
*pbyHdrBuf
,
206 u16 wPayloadLen
, u8
*pMICHDR
)
208 u32
*pdwIV
= (u32
*)pbyIVHead
;
209 u32
*pdwExtIV
= (u32
*)((u8
*)pbyIVHead
+ 4);
211 PS802_11Header pMACHeader
= (PS802_11Header
)pbyHdrBuf
;
216 if (pTransmitKey
== NULL
)
219 dwRevIVCounter
= cpu_to_le32(pDevice
->dwIVCounter
);
220 *pdwIV
= pDevice
->dwIVCounter
;
221 pDevice
->byKeyIndex
= pTransmitKey
->dwKeyIndex
& 0xf;
223 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
224 if (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
){
225 memcpy(pDevice
->abyPRNG
, (PBYTE
)&(dwRevIVCounter
), 3);
226 memcpy(pDevice
->abyPRNG
+3, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
228 memcpy(pbyBuf
, (PBYTE
)&(dwRevIVCounter
), 3);
229 memcpy(pbyBuf
+3, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
230 if(pTransmitKey
->uKeyLength
== WLAN_WEP40_KEYLEN
) {
231 memcpy(pbyBuf
+8, (PBYTE
)&(dwRevIVCounter
), 3);
232 memcpy(pbyBuf
+11, pTransmitKey
->abyKey
, pTransmitKey
->uKeyLength
);
234 memcpy(pDevice
->abyPRNG
, pbyBuf
, 16);
236 // Append IV after Mac Header
237 *pdwIV
&= WEP_IV_MASK
;//00000000 11111111 11111111 11111111
238 *pdwIV
|= (u32
)pDevice
->byKeyIndex
<< 30;
239 *pdwIV
= cpu_to_le32(*pdwIV
);
240 pDevice
->dwIVCounter
++;
241 if (pDevice
->dwIVCounter
> WEP_IV_MASK
) {
242 pDevice
->dwIVCounter
= 0;
244 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
245 pTransmitKey
->wTSC15_0
++;
246 if (pTransmitKey
->wTSC15_0
== 0) {
247 pTransmitKey
->dwTSC47_16
++;
249 TKIPvMixKey(pTransmitKey
->abyKey
, pDevice
->abyCurrentNetAddr
,
250 pTransmitKey
->wTSC15_0
, pTransmitKey
->dwTSC47_16
, pDevice
->abyPRNG
);
251 memcpy(pbyBuf
, pDevice
->abyPRNG
, 16);
253 memcpy(pdwIV
, pDevice
->abyPRNG
, 3);
255 *(pbyIVHead
+3) = (BYTE
)(((pDevice
->byKeyIndex
<< 6) & 0xc0) | 0x20); // 0x20 is ExtIV
256 // Append IV&ExtIV after Mac Header
257 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
258 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vFillTxKey()---- pdwExtIV: %x\n",
261 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
262 pTransmitKey
->wTSC15_0
++;
263 if (pTransmitKey
->wTSC15_0
== 0) {
264 pTransmitKey
->dwTSC47_16
++;
266 memcpy(pbyBuf
, pTransmitKey
->abyKey
, 16);
270 *(pbyIVHead
+3) = (BYTE
)(((pDevice
->byKeyIndex
<< 6) & 0xc0) | 0x20); // 0x20 is ExtIV
271 *pdwIV
|= cpu_to_le16((WORD
)(pTransmitKey
->wTSC15_0
));
272 //Append IV&ExtIV after Mac Header
273 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
277 *((PBYTE
)(pMICHDR
+1)) = 0; // TxPriority
278 memcpy(pMICHDR
+2, &(pMACHeader
->abyAddr2
[0]), 6);
279 *((PBYTE
)(pMICHDR
+8)) = HIBYTE(HIWORD(pTransmitKey
->dwTSC47_16
));
280 *((PBYTE
)(pMICHDR
+9)) = LOBYTE(HIWORD(pTransmitKey
->dwTSC47_16
));
281 *((PBYTE
)(pMICHDR
+10)) = HIBYTE(LOWORD(pTransmitKey
->dwTSC47_16
));
282 *((PBYTE
)(pMICHDR
+11)) = LOBYTE(LOWORD(pTransmitKey
->dwTSC47_16
));
283 *((PBYTE
)(pMICHDR
+12)) = HIBYTE(pTransmitKey
->wTSC15_0
);
284 *((PBYTE
)(pMICHDR
+13)) = LOBYTE(pTransmitKey
->wTSC15_0
);
285 *((PBYTE
)(pMICHDR
+14)) = HIBYTE(wPayloadLen
);
286 *((PBYTE
)(pMICHDR
+15)) = LOBYTE(wPayloadLen
);
289 *((PBYTE
)(pMICHDR
+16)) = 0; // HLEN[15:8]
290 if (pDevice
->bLongHeader
) {
291 *((PBYTE
)(pMICHDR
+17)) = 28; // HLEN[7:0]
293 *((PBYTE
)(pMICHDR
+17)) = 22; // HLEN[7:0]
295 wValue
= cpu_to_le16(pMACHeader
->wFrameCtl
& 0xC78F);
296 memcpy(pMICHDR
+18, (PBYTE
)&wValue
, 2); // MSKFRACTL
297 memcpy(pMICHDR
+20, &(pMACHeader
->abyAddr1
[0]), 6);
298 memcpy(pMICHDR
+26, &(pMACHeader
->abyAddr2
[0]), 6);
301 memcpy(pMICHDR
+32, &(pMACHeader
->abyAddr3
[0]), 6);
302 wValue
= pMACHeader
->wSeqCtl
;
304 wValue
= cpu_to_le16(wValue
);
305 memcpy(pMICHDR
+38, (PBYTE
)&wValue
, 2); // MSKSEQCTL
306 if (pDevice
->bLongHeader
) {
307 memcpy(pMICHDR
+40, &(pMACHeader
->abyAddr4
[0]), 6);
313 static void s_vSWencryption(struct vnt_private
*pDevice
,
314 PSKeyItem pTransmitKey
, u8
*pbyPayloadHead
, u16 wPayloadSize
)
317 u32 dwICV
= 0xffffffff;
320 if (pTransmitKey
== NULL
)
323 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
324 //=======================================================================
325 // Append ICV after payload
326 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
327 pdwICV
= (PDWORD
)(pbyPayloadHead
+ wPayloadSize
);
328 // finally, we must invert dwCRC to get the correct answer
329 *pdwICV
= cpu_to_le32(~dwICV
);
331 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pTransmitKey
->uKeyLength
+ 3);
332 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
333 //=======================================================================
334 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
335 //=======================================================================
336 //Append ICV after payload
337 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
338 pdwICV
= (PDWORD
)(pbyPayloadHead
+ wPayloadSize
);
339 // finally, we must invert dwCRC to get the correct answer
340 *pdwICV
= cpu_to_le32(~dwICV
);
342 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
343 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
344 //=======================================================================
351 /*byPktType : PK_TYPE_11A 0
356 static u32
s_uGetTxRsvTime(struct vnt_private
*pDevice
, u8 byPktType
,
357 u32 cbFrameLength
, u16 wRate
, int bNeedAck
)
359 u32 uDataTime
, uAckTime
;
361 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wRate
);
362 if (byPktType
== PK_TYPE_11B
) {//llb,CCK mode
363 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (WORD
)pDevice
->byTopCCKBasicRate
);
364 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
365 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (WORD
)pDevice
->byTopOFDMBasicRate
);
369 return (uDataTime
+ pDevice
->uSIFS
+ uAckTime
);
376 //byFreqType: 0=>5GHZ 1=>2.4GHZ
377 static u32
s_uGetRTSCTSRsvTime(struct vnt_private
*pDevice
,
378 u8 byRTSRsvType
, u8 byPktType
, u32 cbFrameLength
, u16 wCurrentRate
)
380 u32 uRrvTime
, uRTSTime
, uCTSTime
, uAckTime
, uDataTime
;
382 uRrvTime
= uRTSTime
= uCTSTime
= uAckTime
= uDataTime
= 0;
385 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wCurrentRate
);
386 if (byRTSRsvType
== 0) { //RTSTxRrvTime_bb
387 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
388 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
390 else if (byRTSRsvType
== 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
391 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
392 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
393 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
395 else if (byRTSRsvType
== 2) { //RTSTxRrvTime_aa
396 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopOFDMBasicRate
);
397 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
399 else if (byRTSRsvType
== 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
400 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
401 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
402 uRrvTime
= uCTSTime
+ uAckTime
+ uDataTime
+ 2*pDevice
->uSIFS
;
407 uRrvTime
= uRTSTime
+ uCTSTime
+ uAckTime
+ uDataTime
+ 3*pDevice
->uSIFS
;
411 //byFreqType 0: 5GHz, 1:2.4Ghz
412 static u32
s_uGetDataDuration(struct vnt_private
*pDevice
, u8 byDurType
,
413 u32 cbFrameLength
, u8 byPktType
, u16 wRate
, int bNeedAck
,
414 u32 uFragIdx
, u32 cbLastFragmentSize
, u32 uMACfragNum
,
418 u32 uAckTime
= 0, uNextPktTime
= 0;
420 if (uFragIdx
== (uMACfragNum
-1)) {
426 case DATADUR_B
: //DATADUR_B
427 if (((uMACfragNum
== 1)) || (bLastFrag
== 1)) {//Non Frag or Last Frag
429 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
430 return (pDevice
->uSIFS
+ uAckTime
);
435 else {//First Frag or Mid Frag
436 if (uFragIdx
== (uMACfragNum
-2)) {
437 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wRate
, bNeedAck
);
439 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
442 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
443 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
445 return (pDevice
->uSIFS
+ uNextPktTime
);
451 case DATADUR_A
: //DATADUR_A
452 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
454 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
455 return (pDevice
->uSIFS
+ uAckTime
);
460 else {//First Frag or Mid Frag
461 if(uFragIdx
== (uMACfragNum
-2)){
462 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wRate
, bNeedAck
);
464 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
467 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
468 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
470 return (pDevice
->uSIFS
+ uNextPktTime
);
475 case DATADUR_A_F0
: //DATADUR_A_F0
476 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
478 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
479 return (pDevice
->uSIFS
+ uAckTime
);
484 else { //First Frag or Mid Frag
485 if (byFBOption
== AUTO_FB_0
) {
486 if (wRate
< RATE_18M
)
488 else if (wRate
> RATE_54M
)
491 if(uFragIdx
== (uMACfragNum
-2)){
492 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
494 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
496 } else { // (byFBOption == AUTO_FB_1)
497 if (wRate
< RATE_18M
)
499 else if (wRate
> RATE_54M
)
502 if(uFragIdx
== (uMACfragNum
-2)){
503 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
505 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
510 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
511 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
513 return (pDevice
->uSIFS
+ uNextPktTime
);
518 case DATADUR_A_F1
: //DATADUR_A_F1
519 if (((uMACfragNum
==1)) || (bLastFrag
==1)) {//Non Frag or Last Frag
521 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
522 return (pDevice
->uSIFS
+ uAckTime
);
527 else { //First Frag or Mid Frag
528 if (byFBOption
== AUTO_FB_0
) {
529 if (wRate
< RATE_18M
)
531 else if (wRate
> RATE_54M
)
534 if(uFragIdx
== (uMACfragNum
-2)){
535 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
537 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
540 } else { // (byFBOption == AUTO_FB_1)
541 if (wRate
< RATE_18M
)
543 else if (wRate
> RATE_54M
)
546 if(uFragIdx
== (uMACfragNum
-2)){
547 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbLastFragmentSize
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
549 uNextPktTime
= s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
553 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
554 return (pDevice
->uSIFS
+ uAckTime
+ uNextPktTime
);
556 return (pDevice
->uSIFS
+ uNextPktTime
);
570 //byFreqType: 0=>5GHZ 1=>2.4GHZ
571 static u32
s_uGetRTSCTSDuration(struct vnt_private
*pDevice
, u8 byDurType
,
572 u32 cbFrameLength
, u8 byPktType
, u16 wRate
, int bNeedAck
,
575 u32 uCTSTime
= 0, uDurTime
= 0;
580 case RTSDUR_BB
: //RTSDuration_bb
581 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
582 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
585 case RTSDUR_BA
: //RTSDuration_ba
586 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
587 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
590 case RTSDUR_AA
: //RTSDuration_aa
591 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
592 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
595 case CTSDUR_BA
: //CTSDuration_ba
596 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
599 case RTSDUR_BA_F0
: //RTSDuration_ba_f0
600 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
601 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
602 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
603 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
604 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
608 case RTSDUR_AA_F0
: //RTSDuration_aa_f0
609 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
610 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
611 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
612 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
613 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
617 case RTSDUR_BA_F1
: //RTSDuration_ba_f1
618 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
619 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
620 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
621 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
622 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
626 case RTSDUR_AA_F1
: //RTSDuration_aa_f1
627 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
628 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
629 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
630 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
631 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
635 case CTSDUR_BA_F0
: //CTSDuration_ba_f0
636 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
637 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
638 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
639 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
643 case CTSDUR_BA_F1
: //CTSDuration_ba_f1
644 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
645 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
646 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
647 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
659 static u32
s_uFillDataHead(struct vnt_private
*pDevice
,
660 u8 byPktType
, u16 wCurrentRate
, void *pTxDataHead
, u32 cbFrameLength
,
661 u32 uDMAIdx
, int bNeedAck
, u32 uFragIdx
, u32 cbLastFragmentSize
,
662 u32 uMACfragNum
, u8 byFBOption
)
665 if (pTxDataHead
== NULL
) {
669 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
670 if ((uDMAIdx
== TYPE_ATIMDMA
) || (uDMAIdx
== TYPE_BEACONDMA
)) {
671 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
) pTxDataHead
;
672 //Get SignalField,ServiceField,Length
673 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
674 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
676 //Get Duration and TimeStampOff
677 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
678 wCurrentRate
, bNeedAck
, uFragIdx
,
679 cbLastFragmentSize
, uMACfragNum
,
680 byFBOption
); //1: 2.4GHz
681 if(uDMAIdx
!=TYPE_ATIMDMA
) {
682 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
684 return (pBuf
->wDuration
);
686 else { // DATA & MANAGE Frame
687 if (byFBOption
== AUTO_FB_NONE
) {
688 PSTxDataHead_g pBuf
= (PSTxDataHead_g
)pTxDataHead
;
689 //Get SignalField,ServiceField,Length
690 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
691 (PWORD
)&(pBuf
->wTransmitLength_a
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
693 BBvCalculateParameter(pDevice
, cbFrameLength
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
694 (PWORD
)&(pBuf
->wTransmitLength_b
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
696 //Get Duration and TimeStamp
697 pBuf
->wDuration_a
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
,
698 byPktType
, wCurrentRate
, bNeedAck
, uFragIdx
,
699 cbLastFragmentSize
, uMACfragNum
,
700 byFBOption
); //1: 2.4GHz
701 pBuf
->wDuration_b
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
,
702 PK_TYPE_11B
, pDevice
->byTopCCKBasicRate
,
703 bNeedAck
, uFragIdx
, cbLastFragmentSize
,
704 uMACfragNum
, byFBOption
); //1: 2.4GHz
706 pBuf
->wTimeStampOff_a
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
707 pBuf
->wTimeStampOff_b
= wTimeStampOff
[pDevice
->byPreambleType
%2][pDevice
->byTopCCKBasicRate
%MAX_RATE
];
708 return (pBuf
->wDuration_a
);
711 PSTxDataHead_g_FB pBuf
= (PSTxDataHead_g_FB
)pTxDataHead
;
712 //Get SignalField,ServiceField,Length
713 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
714 (PWORD
)&(pBuf
->wTransmitLength_a
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
716 BBvCalculateParameter(pDevice
, cbFrameLength
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
717 (PWORD
)&(pBuf
->wTransmitLength_b
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
719 //Get Duration and TimeStamp
720 pBuf
->wDuration_a
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
721 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
722 pBuf
->wDuration_b
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
, PK_TYPE_11B
,
723 pDevice
->byTopCCKBasicRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
724 pBuf
->wDuration_a_f0
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F0
, cbFrameLength
, byPktType
,
725 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
726 pBuf
->wDuration_a_f1
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F1
, cbFrameLength
, byPktType
,
727 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //1: 2.4GHz
728 pBuf
->wTimeStampOff_a
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
729 pBuf
->wTimeStampOff_b
= wTimeStampOff
[pDevice
->byPreambleType
%2][pDevice
->byTopCCKBasicRate
%MAX_RATE
];
730 return (pBuf
->wDuration_a
);
731 } //if (byFBOption == AUTO_FB_NONE)
734 else if (byPktType
== PK_TYPE_11A
) {
735 if ((byFBOption
!= AUTO_FB_NONE
) && (uDMAIdx
!= TYPE_ATIMDMA
) && (uDMAIdx
!= TYPE_BEACONDMA
)) {
737 PSTxDataHead_a_FB pBuf
= (PSTxDataHead_a_FB
)pTxDataHead
;
738 //Get SignalField,ServiceField,Length
739 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
740 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
742 //Get Duration and TimeStampOff
743 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
744 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //0: 5GHz
745 pBuf
->wDuration_f0
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F0
, cbFrameLength
, byPktType
,
746 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //0: 5GHz
747 pBuf
->wDuration_f1
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A_F1
, cbFrameLength
, byPktType
,
748 wCurrentRate
, bNeedAck
, uFragIdx
, cbLastFragmentSize
, uMACfragNum
, byFBOption
); //0: 5GHz
749 if(uDMAIdx
!=TYPE_ATIMDMA
) {
750 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
752 return (pBuf
->wDuration
);
754 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
755 //Get SignalField,ServiceField,Length
756 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
757 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
759 //Get Duration and TimeStampOff
760 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameLength
, byPktType
,
761 wCurrentRate
, bNeedAck
, uFragIdx
,
762 cbLastFragmentSize
, uMACfragNum
,
765 if(uDMAIdx
!=TYPE_ATIMDMA
) {
766 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
768 return (pBuf
->wDuration
);
771 else if (byPktType
== PK_TYPE_11B
) {
772 PSTxDataHead_ab pBuf
= (PSTxDataHead_ab
)pTxDataHead
;
773 //Get SignalField,ServiceField,Length
774 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
, byPktType
,
775 (PWORD
)&(pBuf
->wTransmitLength
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
777 //Get Duration and TimeStampOff
778 pBuf
->wDuration
= (WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameLength
, byPktType
,
779 wCurrentRate
, bNeedAck
, uFragIdx
,
780 cbLastFragmentSize
, uMACfragNum
,
782 if (uDMAIdx
!= TYPE_ATIMDMA
) {
783 pBuf
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
785 return (pBuf
->wDuration
);
790 static void s_vFillRTSHead(struct vnt_private
*pDevice
, u8 byPktType
,
791 void *pvRTS
, u32 cbFrameLength
, int bNeedAck
, int bDisCRC
,
792 PSEthernetHeader psEthHeader
, u16 wCurrentRate
, u8 byFBOption
)
794 u32 uRTSFrameLen
= 20;
801 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
802 // in this case we need to decrease its length by 4.
806 // Note: So far RTSHead doesn't appear in ATIM & Beacom DMA, so we don't need to take them into account.
807 // Otherwise, we need to modified codes for them.
808 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
809 if (byFBOption
== AUTO_FB_NONE
) {
810 PSRTS_g pBuf
= (PSRTS_g
)pvRTS
;
811 //Get SignalField,ServiceField,Length
812 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
813 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
815 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
816 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
817 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
819 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
821 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
822 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
823 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
825 pBuf
->Data
.wDurationID
= pBuf
->wDuration_aa
;
827 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
829 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
830 (pDevice
->eOPMode
== OP_MODE_AP
)) {
831 memcpy(&(pBuf
->Data
.abyRA
[0]),
832 &(psEthHeader
->abyDstAddr
[0]),
836 memcpy(&(pBuf
->Data
.abyRA
[0]),
837 &(pDevice
->abyBSSID
[0]),
840 if (pDevice
->eOPMode
== OP_MODE_AP
) {
841 memcpy(&(pBuf
->Data
.abyTA
[0]),
842 &(pDevice
->abyBSSID
[0]),
846 memcpy(&(pBuf
->Data
.abyTA
[0]),
847 &(psEthHeader
->abySrcAddr
[0]),
852 PSRTS_g_FB pBuf
= (PSRTS_g_FB
)pvRTS
;
853 //Get SignalField,ServiceField,Length
854 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
855 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
857 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
858 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
859 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_a
), (PBYTE
)&(pBuf
->bySignalField_a
)
861 pBuf
->wTransmitLength_a
= cpu_to_le16(wLen
);
863 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
864 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
865 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
866 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
867 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
868 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
869 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
870 pBuf
->Data
.wDurationID
= pBuf
->wDuration_aa
;
872 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
874 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
875 (pDevice
->eOPMode
== OP_MODE_AP
)) {
876 memcpy(&(pBuf
->Data
.abyRA
[0]),
877 &(psEthHeader
->abyDstAddr
[0]),
881 memcpy(&(pBuf
->Data
.abyRA
[0]),
882 &(pDevice
->abyBSSID
[0]),
886 if (pDevice
->eOPMode
== OP_MODE_AP
) {
887 memcpy(&(pBuf
->Data
.abyTA
[0]),
888 &(pDevice
->abyBSSID
[0]),
892 memcpy(&(pBuf
->Data
.abyTA
[0]),
893 &(psEthHeader
->abySrcAddr
[0]),
897 } // if (byFBOption == AUTO_FB_NONE)
899 else if (byPktType
== PK_TYPE_11A
) {
900 if (byFBOption
== AUTO_FB_NONE
) {
901 PSRTS_ab pBuf
= (PSRTS_ab
)pvRTS
;
902 //Get SignalField,ServiceField,Length
903 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
904 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
906 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
908 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
909 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
911 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
913 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
914 (pDevice
->eOPMode
== OP_MODE_AP
)) {
915 memcpy(&(pBuf
->Data
.abyRA
[0]),
916 &(psEthHeader
->abyDstAddr
[0]),
919 memcpy(&(pBuf
->Data
.abyRA
[0]),
920 &(pDevice
->abyBSSID
[0]),
924 if (pDevice
->eOPMode
== OP_MODE_AP
) {
925 memcpy(&(pBuf
->Data
.abyTA
[0]),
926 &(pDevice
->abyBSSID
[0]),
929 memcpy(&(pBuf
->Data
.abyTA
[0]),
930 &(psEthHeader
->abySrcAddr
[0]),
936 PSRTS_a_FB pBuf
= (PSRTS_a_FB
)pvRTS
;
937 //Get SignalField,ServiceField,Length
938 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopOFDMBasicRate
, byPktType
,
939 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
941 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
943 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_AA
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
944 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
945 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:
946 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
948 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
950 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
951 (pDevice
->eOPMode
== OP_MODE_AP
)) {
952 memcpy(&(pBuf
->Data
.abyRA
[0]),
953 &(psEthHeader
->abyDstAddr
[0]),
956 memcpy(&(pBuf
->Data
.abyRA
[0]),
957 &(pDevice
->abyBSSID
[0]),
960 if (pDevice
->eOPMode
== OP_MODE_AP
) {
961 memcpy(&(pBuf
->Data
.abyTA
[0]),
962 &(pDevice
->abyBSSID
[0]),
965 memcpy(&(pBuf
->Data
.abyTA
[0]),
966 &(psEthHeader
->abySrcAddr
[0]),
971 else if (byPktType
== PK_TYPE_11B
) {
972 PSRTS_ab pBuf
= (PSRTS_ab
)pvRTS
;
973 //Get SignalField,ServiceField,Length
974 BBvCalculateParameter(pDevice
, uRTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
975 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField
), (PBYTE
)&(pBuf
->bySignalField
)
977 pBuf
->wTransmitLength
= cpu_to_le16(wLen
);
979 pBuf
->wDuration
= cpu_to_le16((WORD
)s_uGetRTSCTSDuration(pDevice
, RTSDUR_BB
, cbFrameLength
, byPktType
, wCurrentRate
, bNeedAck
, byFBOption
)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
980 pBuf
->Data
.wDurationID
= pBuf
->wDuration
;
982 pBuf
->Data
.wFrameControl
= TYPE_CTL_RTS
;//0x00B4
984 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
985 (pDevice
->eOPMode
== OP_MODE_AP
)) {
986 memcpy(&(pBuf
->Data
.abyRA
[0]),
987 &(psEthHeader
->abyDstAddr
[0]),
991 memcpy(&(pBuf
->Data
.abyRA
[0]),
992 &(pDevice
->abyBSSID
[0]),
996 if (pDevice
->eOPMode
== OP_MODE_AP
) {
997 memcpy(&(pBuf
->Data
.abyTA
[0]),
998 &(pDevice
->abyBSSID
[0]),
1001 memcpy(&(pBuf
->Data
.abyTA
[0]),
1002 &(psEthHeader
->abySrcAddr
[0]),
1008 static void s_vFillCTSHead(struct vnt_private
*pDevice
, u32 uDMAIdx
,
1009 u8 byPktType
, void *pvCTS
, u32 cbFrameLength
, int bNeedAck
,
1010 int bDisCRC
, u16 wCurrentRate
, u8 byFBOption
)
1012 u32 uCTSFrameLen
= 14;
1015 if (pvCTS
== NULL
) {
1020 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1021 // in this case we need to decrease its length by 4.
1025 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1026 if (byFBOption
!= AUTO_FB_NONE
&& uDMAIdx
!= TYPE_ATIMDMA
&& uDMAIdx
!= TYPE_BEACONDMA
) {
1028 PSCTS_FB pBuf
= (PSCTS_FB
)pvCTS
;
1029 //Get SignalField,ServiceField,Length
1030 BBvCalculateParameter(pDevice
, uCTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1031 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1033 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1034 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
1035 pBuf
->wDuration_ba
+= pDevice
->wCTSDuration
;
1036 pBuf
->wDuration_ba
= cpu_to_le16(pBuf
->wDuration_ba
);
1037 //Get CTSDuration_ba_f0
1038 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
1039 pBuf
->wCTSDuration_ba_f0
+= pDevice
->wCTSDuration
;
1040 pBuf
->wCTSDuration_ba_f0
= cpu_to_le16(pBuf
->wCTSDuration_ba_f0
);
1041 //Get CTSDuration_ba_f1
1042 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
1043 pBuf
->wCTSDuration_ba_f1
+= pDevice
->wCTSDuration
;
1044 pBuf
->wCTSDuration_ba_f1
= cpu_to_le16(pBuf
->wCTSDuration_ba_f1
);
1045 //Get CTS Frame body
1046 pBuf
->Data
.wDurationID
= pBuf
->wDuration_ba
;
1047 pBuf
->Data
.wFrameControl
= TYPE_CTL_CTS
;//0x00C4
1048 pBuf
->Data
.wReserved
= 0x0000;
1049 memcpy(&(pBuf
->Data
.abyRA
[0]),
1050 &(pDevice
->abyCurrentNetAddr
[0]),
1052 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1053 PSCTS pBuf
= (PSCTS
)pvCTS
;
1054 //Get SignalField,ServiceField,Length
1055 BBvCalculateParameter(pDevice
, uCTSFrameLen
, pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
,
1056 (PWORD
)&(wLen
), (PBYTE
)&(pBuf
->byServiceField_b
), (PBYTE
)&(pBuf
->bySignalField_b
)
1058 pBuf
->wTransmitLength_b
= cpu_to_le16(wLen
);
1059 //Get CTSDuration_ba
1060 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
1061 pBuf
->wDuration_ba
+= pDevice
->wCTSDuration
;
1062 pBuf
->wDuration_ba
= cpu_to_le16(pBuf
->wDuration_ba
);
1064 //Get CTS Frame body
1065 pBuf
->Data
.wDurationID
= pBuf
->wDuration_ba
;
1066 pBuf
->Data
.wFrameControl
= TYPE_CTL_CTS
;//0x00C4
1067 pBuf
->Data
.wReserved
= 0x0000;
1068 memcpy(&(pBuf
->Data
.abyRA
[0]),
1069 &(pDevice
->abyCurrentNetAddr
[0]),
1078 * Generate FIFO control for MAC & Baseband controller
1082 * pDevice - Pointer to adpater
1083 * pTxDataHead - Transmit Data Buffer
1084 * pTxBufHead - pTxBufHead
1085 * pvRrvTime - pvRrvTime
1086 * pvRTS - RTS Buffer
1088 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1089 * bNeedACK - If need ACK
1090 * uDMAIdx - DMA Index
1094 * Return Value: none
1098 static void s_vGenerateTxParameter(struct vnt_private
*pDevice
,
1099 u8 byPktType
, u16 wCurrentRate
, void *pTxBufHead
, void *pvRrvTime
,
1100 void *pvRTS
, void *pvCTS
, u32 cbFrameSize
, int bNeedACK
, u32 uDMAIdx
,
1101 PSEthernetHeader psEthHeader
)
1103 u32 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
; /* 24 */
1105 int bDisCRC
= false;
1106 u8 byFBOption
= AUTO_FB_NONE
;
1108 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1109 PSTxBufHead pFifoHead
= (PSTxBufHead
)pTxBufHead
;
1110 pFifoHead
->wReserved
= wCurrentRate
;
1111 wFifoCtl
= pFifoHead
->wFIFOCtl
;
1113 if (wFifoCtl
& FIFOCTL_CRCDIS
) {
1117 if (wFifoCtl
& FIFOCTL_AUTO_FB_0
) {
1118 byFBOption
= AUTO_FB_0
;
1120 else if (wFifoCtl
& FIFOCTL_AUTO_FB_1
) {
1121 byFBOption
= AUTO_FB_1
;
1124 if (pDevice
->bLongHeader
)
1125 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1127 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1129 if (pvRTS
!= NULL
) { //RTS_need
1132 PSRrvTime_gRTS pBuf
= (PSRrvTime_gRTS
)pvRrvTime
;
1133 pBuf
->wRTSTxRrvTime_aa
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 2, byPktType
, cbFrameSize
, wCurrentRate
));//2:RTSTxRrvTime_aa, 1:2.4GHz
1134 pBuf
->wRTSTxRrvTime_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 1, byPktType
, cbFrameSize
, wCurrentRate
));//1:RTSTxRrvTime_ba, 1:2.4GHz
1135 pBuf
->wRTSTxRrvTime_bb
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 0, byPktType
, cbFrameSize
, wCurrentRate
));//0:RTSTxRrvTime_bb, 1:2.4GHz
1136 pBuf
->wTxRrvTime_a
= cpu_to_le16((WORD
) s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//2.4G OFDM
1137 pBuf
->wTxRrvTime_b
= cpu_to_le16((WORD
) s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
, bNeedACK
));//1:CCK
1140 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1142 else {//RTS_needless, PCF mode
1146 PSRrvTime_gCTS pBuf
= (PSRrvTime_gCTS
)pvRrvTime
;
1147 pBuf
->wTxRrvTime_a
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//2.4G OFDM
1148 pBuf
->wTxRrvTime_b
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
, bNeedACK
));//1:CCK
1149 pBuf
->wCTSTxRrvTime_ba
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 3, byPktType
, cbFrameSize
, wCurrentRate
));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1152 s_vFillCTSHead(pDevice
, uDMAIdx
, byPktType
, pvCTS
, cbFrameSize
, bNeedACK
, bDisCRC
, wCurrentRate
, byFBOption
);
1155 else if (byPktType
== PK_TYPE_11A
) {
1157 if (pvRTS
!= NULL
) {//RTS_need, non PCF mode
1160 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1161 pBuf
->wRTSTxRrvTime
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 2, byPktType
, cbFrameSize
, wCurrentRate
));//2:RTSTxRrvTime_aa, 0:5GHz
1162 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
));//0:OFDM
1165 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1167 else if (pvRTS
== NULL
) {//RTS_needless, non PCF mode
1170 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1171 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11A
, cbFrameSize
, wCurrentRate
, bNeedACK
)); //0:OFDM
1175 else if (byPktType
== PK_TYPE_11B
) {
1177 if ((pvRTS
!= NULL
)) {//RTS_need, non PCF mode
1180 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1181 pBuf
->wRTSTxRrvTime
= cpu_to_le16((WORD
)s_uGetRTSCTSRsvTime(pDevice
, 0, byPktType
, cbFrameSize
, wCurrentRate
));//0:RTSTxRrvTime_bb, 1:2.4GHz
1182 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, wCurrentRate
, bNeedACK
));//1:CCK
1185 s_vFillRTSHead(pDevice
, byPktType
, pvRTS
, cbFrameSize
, bNeedACK
, bDisCRC
, psEthHeader
, wCurrentRate
, byFBOption
);
1187 else { //RTS_needless, non PCF mode
1190 PSRrvTime_ab pBuf
= (PSRrvTime_ab
)pvRrvTime
;
1191 pBuf
->wTxRrvTime
= cpu_to_le16((WORD
)s_uGetTxRsvTime(pDevice
, PK_TYPE_11B
, cbFrameSize
, wCurrentRate
, bNeedACK
)); //1:CCK
1195 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1198 PBYTE pbyBuffer,//point to pTxBufHead
1199 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1200 unsigned int cbFragmentSize,//Hdr+payoad+FCS
1203 static int s_bPacketToWirelessUsb(struct vnt_private
*pDevice
, u8 byPktType
,
1204 u8
*usbPacketBuf
, int bNeedEncryption
, u32 uSkbPacketLen
, u32 uDMAIdx
,
1205 PSEthernetHeader psEthHeader
, u8
*pPacket
, PSKeyItem pTransmitKey
,
1206 u32 uNodeIndex
, u16 wCurrentRate
, u32
*pcbHeaderLen
, u32
*pcbTotalLen
)
1208 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1209 u32 cbFrameSize
, cbFrameBodySize
;
1210 PTX_BUFFER pTxBufHead
;
1212 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbMACHdLen
= 0;
1213 u32 cbFCSlen
= 4, cbMICHDR
= 0;
1215 u8
*pbyType
, *pbyMacHdr
, *pbyIVHead
, *pbyPayloadHead
, *pbyTxBufferAddr
;
1216 u8 abySNAP_RFC1042
[ETH_ALEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1217 u8 abySNAP_Bridgetunnel
[ETH_ALEN
]
1218 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1220 u32 cbHeaderLength
= 0, uPadding
= 0;
1222 PSMICHDRHead pMICHDR
;
1226 u8 byFBOption
= AUTO_FB_NONE
, byFragType
;
1228 u32 dwMICKey0
, dwMICKey1
, dwMIC_Priority
, dwCRC
;
1229 u32
*pdwMIC_L
, *pdwMIC_R
;
1230 int bSoftWEP
= false;
1232 pvRrvTime
= pMICHDR
= pvRTS
= pvCTS
= pvTxDataHd
= NULL
;
1234 if (bNeedEncryption
&& pTransmitKey
->pvKeyTable
) {
1235 if (((PSKeyTable
)pTransmitKey
->pvKeyTable
)->bSoftWEP
== true)
1236 bSoftWEP
= true; /* WEP 256 */
1239 pTxBufHead
= (PTX_BUFFER
) usbPacketBuf
;
1240 memset(pTxBufHead
, 0, sizeof(TX_BUFFER
));
1243 if (ntohs(psEthHeader
->wType
) > ETH_DATA_LEN
) {
1244 if (pDevice
->dwDiagRefCount
== 0) {
1253 cbFrameBodySize
= uSkbPacketLen
- ETH_HLEN
+ cb802_1_H_len
;
1256 pTxBufHead
->wFIFOCtl
|= (WORD
)(byPktType
<<8);
1258 if (pDevice
->dwDiagRefCount
!= 0) {
1260 pTxBufHead
->wFIFOCtl
= pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1261 } else { //if (pDevice->dwDiagRefCount != 0) {
1262 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1263 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1264 if (is_multicast_ether_addr(psEthHeader
->abyDstAddr
)) {
1266 pTxBufHead
->wFIFOCtl
=
1267 pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1270 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1274 // MSDUs in Infra mode always need ACK
1276 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1278 } //if (pDevice->dwDiagRefCount != 0) {
1280 pTxBufHead
->wTimeStamp
= DEFAULT_MSDU_LIFETIME_RES_64us
;
1283 if (pDevice
->bLongHeader
)
1284 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LHEAD
;
1286 if (pDevice
->bSoftwareGenCrcErr
) {
1287 pTxBufHead
->wFIFOCtl
|= FIFOCTL_CRCDIS
; // set tx descriptors to NO hardware CRC
1290 //Set FRAGCTL_MACHDCNT
1291 if (pDevice
->bLongHeader
) {
1292 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1294 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
;
1296 pTxBufHead
->wFragCtl
|= (WORD
)(cbMACHdLen
<< 10);
1298 //Set FIFOCTL_GrpAckPolicy
1299 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1300 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1303 //Set Auto Fallback Ctl
1304 if (wCurrentRate
>= RATE_18M
) {
1305 if (pDevice
->byAutoFBCtrl
== AUTO_FB_0
) {
1306 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_0
;
1307 byFBOption
= AUTO_FB_0
;
1308 } else if (pDevice
->byAutoFBCtrl
== AUTO_FB_1
) {
1309 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_1
;
1310 byFBOption
= AUTO_FB_1
;
1314 if (bSoftWEP
!= true) {
1315 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) { //WEP enabled
1316 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) { //WEP40 or WEP104
1317 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1319 if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1320 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1321 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1323 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) { //CCMP
1324 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1330 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) {
1331 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
1335 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1336 cbIVlen
= 8;//IV+ExtIV
1340 if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
1341 cbIVlen
= 8;//RSN Header
1343 cbMICHDR
= sizeof(SMICHDRHead
);
1345 if (bSoftWEP
== false) {
1346 //MAC Header should be padding 0 to DW alignment.
1347 uPadding
= 4 - (cbMACHdLen
%4);
1352 cbFrameSize
= cbMACHdLen
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbICVlen
+ cbFCSlen
;
1354 if ( (bNeedACK
== false) ||(cbFrameSize
< pDevice
->wRTSThreshold
) ) {
1358 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_RTS
| FIFOCTL_LRETRY
);
1361 pbyTxBufferAddr
= (PBYTE
) &(pTxBufHead
->adwTxKey
[0]);
1362 wTxBufSize
= sizeof(STxBufHead
);
1363 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1364 if (byFBOption
== AUTO_FB_NONE
) {
1365 if (bRTS
== true) {//RTS_need
1366 pvRrvTime
= (PSRrvTime_gRTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1367 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
));
1368 pvRTS
= (PSRTS_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
);
1370 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g
));
1371 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g
) + sizeof(STxDataHead_g
);
1373 else { //RTS_needless
1374 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1375 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1377 pvCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
1378 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
));
1379 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
) + sizeof(STxDataHead_g
);
1383 if (bRTS
== true) {//RTS_need
1384 pvRrvTime
= (PSRrvTime_gRTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1385 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
));
1386 pvRTS
= (PSRTS_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
);
1388 pvTxDataHd
= (PSTxDataHead_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g_FB
));
1389 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gRTS
) + cbMICHDR
+ sizeof(SRTS_g_FB
) + sizeof(STxDataHead_g_FB
);
1391 else if (bRTS
== false) { //RTS_needless
1392 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1393 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1395 pvCTS
= (PSCTS_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
1396 pvTxDataHd
= (PSTxDataHead_g_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS_FB
));
1397 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS_FB
) + sizeof(STxDataHead_g_FB
);
1401 else {//802.11a/b packet
1402 if (byFBOption
== AUTO_FB_NONE
) {
1403 if (bRTS
== true) {//RTS_need
1404 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1405 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1406 pvRTS
= (PSRTS_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1408 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_ab
));
1409 cbHeaderLength
= wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_ab
) + sizeof(STxDataHead_ab
);
1411 else if (bRTS
== false) { //RTS_needless, no MICHDR
1412 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1413 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1416 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1417 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_ab
);
1421 if (bRTS
== true) {//RTS_need
1422 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1423 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1424 pvRTS
= (PSRTS_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1426 pvTxDataHd
= (PSTxDataHead_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_a_FB
));
1427 cbHeaderLength
= wTxBufSize
+ sizeof(PSRrvTime_ab
) + cbMICHDR
+ sizeof(SRTS_a_FB
) + sizeof(STxDataHead_a_FB
);
1429 else if (bRTS
== false) { //RTS_needless
1430 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1431 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1434 pvTxDataHd
= (PSTxDataHead_a_FB
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
1435 cbHeaderLength
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_a_FB
);
1440 pbyMacHdr
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderLength
);
1441 pbyIVHead
= (PBYTE
)(pbyMacHdr
+ cbMACHdLen
+ uPadding
);
1442 pbyPayloadHead
= (PBYTE
)(pbyMacHdr
+ cbMACHdLen
+ uPadding
+ cbIVlen
);
1445 //=========================
1447 //=========================
1448 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Fragmentation...\n");
1449 byFragType
= FRAGCTL_NONFRAG
;
1450 //uDMAIdx = TYPE_AC0DMA;
1451 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1454 //Fill FIFO,RrvTime,RTS,and CTS
1455 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
1456 (void *)pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pvCTS
,
1457 cbFrameSize
, bNeedACK
, uDMAIdx
, psEthHeader
);
1459 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, uDMAIdx
, bNeedACK
,
1460 0, 0, 1/*uMACfragNum*/, byFBOption
);
1461 // Generate TX MAC Header
1462 s_vGenerateMACHeader(pDevice
, pbyMacHdr
, (WORD
)uDuration
, psEthHeader
, bNeedEncryption
,
1463 byFragType
, uDMAIdx
, 0);
1465 if (bNeedEncryption
== true) {
1467 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1468 pbyMacHdr
, (WORD
)cbFrameBodySize
, (PBYTE
)pMICHDR
);
1470 if (pDevice
->bEnableHostWEP
) {
1471 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1472 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1477 if (ntohs(psEthHeader
->wType
) > ETH_DATA_LEN
) {
1478 if (pDevice
->dwDiagRefCount
== 0) {
1479 if ((psEthHeader
->wType
== cpu_to_be16(ETH_P_IPX
)) ||
1480 (psEthHeader
->wType
== cpu_to_le16(0xF380))) {
1481 memcpy((PBYTE
) (pbyPayloadHead
),
1482 abySNAP_Bridgetunnel
, 6);
1484 memcpy((PBYTE
) (pbyPayloadHead
), &abySNAP_RFC1042
[0], 6);
1486 pbyType
= (PBYTE
) (pbyPayloadHead
+ 6);
1487 memcpy(pbyType
, &(psEthHeader
->wType
), sizeof(WORD
));
1489 memcpy((PBYTE
) (pbyPayloadHead
), &(psEthHeader
->wType
), sizeof(WORD
));
1496 if (pPacket
!= NULL
) {
1497 // Copy the Packet into a tx Buffer
1498 memcpy((pbyPayloadHead
+ cb802_1_H_len
),
1499 (pPacket
+ ETH_HLEN
),
1500 uSkbPacketLen
- ETH_HLEN
1504 // while bRelayPacketSend psEthHeader is point to header+payload
1505 memcpy((pbyPayloadHead
+ cb802_1_H_len
), ((PBYTE
)psEthHeader
) + ETH_HLEN
, uSkbPacketLen
- ETH_HLEN
);
1508 ASSERT(uLength
== cbNdisBodySize
);
1510 if ((bNeedEncryption
== true) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1512 ///////////////////////////////////////////////////////////////////
1514 if (pDevice
->vnt_mgmt
.eAuthenMode
== WMAC_AUTH_WPANONE
) {
1515 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
1516 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
1518 else if ((pTransmitKey
->dwKeyIndex
& AUTHENTICATOR_KEY
) != 0) {
1519 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
1520 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
1523 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[24]);
1524 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[28]);
1526 // DO Software Michael
1527 MIC_vInit(dwMICKey0
, dwMICKey1
);
1528 MIC_vAppend((PBYTE
)&(psEthHeader
->abyDstAddr
[0]), 12);
1530 MIC_vAppend((PBYTE
)&dwMIC_Priority
, 4);
1531 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC KEY: %X, %X\n",
1532 dwMICKey0
, dwMICKey1
);
1534 ///////////////////////////////////////////////////////////////////
1536 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1537 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1538 // DBG_PRN_GRP12(("%02x ", *((PBYTE)((pbyPayloadHead + cb802_1_H_len) + ii))));
1540 //DBG_PRN_GRP12(("\n\n\n"));
1542 MIC_vAppend(pbyPayloadHead
, cbFrameBodySize
);
1544 pdwMIC_L
= (PDWORD
)(pbyPayloadHead
+ cbFrameBodySize
);
1545 pdwMIC_R
= (PDWORD
)(pbyPayloadHead
+ cbFrameBodySize
+ 4);
1547 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1550 if (pDevice
->bTxMICFail
== true) {
1553 pDevice
->bTxMICFail
= false;
1555 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1556 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1557 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1561 if (bSoftWEP
== true) {
1563 s_vSWencryption(pDevice
, pTransmitKey
, (pbyPayloadHead
), (WORD
)(cbFrameBodySize
+ cbMIClen
));
1565 } else if ( ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) && (bNeedEncryption
== true)) ||
1566 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) && (bNeedEncryption
== true)) ||
1567 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) && (bNeedEncryption
== true)) ) {
1568 cbFrameSize
-= cbICVlen
;
1571 if (pDevice
->bSoftwareGenCrcErr
== true) {
1575 dwCRC
= 0xFFFFFFFFL
;
1576 cbLen
= cbFrameSize
- cbFCSlen
;
1577 // calculate CRC, and wrtie CRC value to end of TD
1578 dwCRC
= CRCdwGetCrc32Ex(pbyMacHdr
, cbLen
, dwCRC
);
1579 pdwCRC
= (PDWORD
)(pbyMacHdr
+ cbLen
);
1580 // finally, we must invert dwCRC to get the correct answer
1585 cbFrameSize
-= cbFCSlen
;
1588 *pcbHeaderLen
= cbHeaderLength
;
1589 *pcbTotalLen
= cbHeaderLength
+ cbFrameSize
;
1592 //Set FragCtl in TxBufferHead
1593 pTxBufHead
->wFragCtl
|= (WORD
)byFragType
;
1604 * Translate 802.3 to 802.11 header
1608 * pDevice - Pointer to adapter
1609 * dwTxBufferAddr - Transmit Buffer
1610 * pPacket - Packet from upper layer
1611 * cbPacketSize - Transmit Data Length
1613 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1614 * pcbAppendPayload - size of append payload for 802.1H translation
1616 * Return Value: none
1620 static void s_vGenerateMACHeader(struct vnt_private
*pDevice
,
1621 u8
*pbyBufferAddr
, u16 wDuration
, PSEthernetHeader psEthHeader
,
1622 int bNeedEncrypt
, u16 wFragType
, u32 uDMAIdx
, u32 uFragIdx
)
1624 PS802_11Header pMACHeader
= (PS802_11Header
)pbyBufferAddr
;
1626 memset(pMACHeader
, 0, (sizeof(S802_11Header
))); //- sizeof(pMACHeader->dwIV)));
1628 if (uDMAIdx
== TYPE_ATIMDMA
) {
1629 pMACHeader
->wFrameCtl
= TYPE_802_11_ATIM
;
1631 pMACHeader
->wFrameCtl
= TYPE_802_11_DATA
;
1634 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1635 memcpy(&(pMACHeader
->abyAddr1
[0]),
1636 &(psEthHeader
->abyDstAddr
[0]),
1638 memcpy(&(pMACHeader
->abyAddr2
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1639 memcpy(&(pMACHeader
->abyAddr3
[0]),
1640 &(psEthHeader
->abySrcAddr
[0]),
1642 pMACHeader
->wFrameCtl
|= FC_FROMDS
;
1644 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
1645 memcpy(&(pMACHeader
->abyAddr1
[0]),
1646 &(psEthHeader
->abyDstAddr
[0]),
1648 memcpy(&(pMACHeader
->abyAddr2
[0]),
1649 &(psEthHeader
->abySrcAddr
[0]),
1651 memcpy(&(pMACHeader
->abyAddr3
[0]),
1652 &(pDevice
->abyBSSID
[0]),
1655 memcpy(&(pMACHeader
->abyAddr3
[0]),
1656 &(psEthHeader
->abyDstAddr
[0]),
1658 memcpy(&(pMACHeader
->abyAddr2
[0]),
1659 &(psEthHeader
->abySrcAddr
[0]),
1661 memcpy(&(pMACHeader
->abyAddr1
[0]),
1662 &(pDevice
->abyBSSID
[0]),
1664 pMACHeader
->wFrameCtl
|= FC_TODS
;
1669 pMACHeader
->wFrameCtl
|= cpu_to_le16((WORD
)WLAN_SET_FC_ISWEP(1));
1671 pMACHeader
->wDurationID
= cpu_to_le16(wDuration
);
1673 if (pDevice
->bLongHeader
) {
1674 PWLAN_80211HDR_A4 pMACA4Header
= (PWLAN_80211HDR_A4
) pbyBufferAddr
;
1675 pMACHeader
->wFrameCtl
|= (FC_TODS
| FC_FROMDS
);
1676 memcpy(pMACA4Header
->abyAddr4
, pDevice
->abyBSSID
, WLAN_ADDR_LEN
);
1678 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1680 //Set FragNumber in Sequence Control
1681 pMACHeader
->wSeqCtl
|= cpu_to_le16((WORD
)uFragIdx
);
1683 if ((wFragType
== FRAGCTL_ENDFRAG
) || (wFragType
== FRAGCTL_NONFRAG
)) {
1684 pDevice
->wSeqCounter
++;
1685 if (pDevice
->wSeqCounter
> 0x0fff)
1686 pDevice
->wSeqCounter
= 0;
1689 if ((wFragType
== FRAGCTL_STAFRAG
) || (wFragType
== FRAGCTL_MIDFRAG
)) { //StartFrag or MidFrag
1690 pMACHeader
->wFrameCtl
|= FC_MOREFRAG
;
1699 * Request instructs a MAC to transmit a 802.11 management packet through
1700 * the adapter onto the medium.
1704 * hDeviceContext - Pointer to the adapter
1705 * pPacket - A pointer to a descriptor for the packet to transmit
1709 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1713 CMD_STATUS
csMgmt_xmit(struct vnt_private
*pDevice
,
1714 struct vnt_tx_mgmt
*pPacket
)
1716 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1717 PTX_BUFFER pTX_Buffer
;
1718 PSTxBufHead pTxBufHead
;
1719 PUSB_SEND_CONTEXT pContext
;
1720 PS802_11Header pMACHeader
;
1722 SEthernetHeader sEthHeader
;
1723 u8 byPktType
, *pbyTxBufferAddr
;
1724 void *pvRTS
, *pvTxDataHd
, *pvRrvTime
, *pMICHDR
;
1725 u32 uDuration
, cbReqCount
, cbHeaderSize
, cbFrameBodySize
, cbFrameSize
;
1726 int bNeedACK
, bIsPSPOLL
= false;
1727 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbFCSlen
= 4;
1731 u16 wCurrentRate
= RATE_1M
;
1735 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
1737 if (NULL
== pContext
) {
1738 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
1739 return CMD_STATUS_RESOURCES
;
1742 pTX_Buffer
= (PTX_BUFFER
) (&pContext
->Data
[0]);
1743 pbyTxBufferAddr
= (PBYTE
)&(pTX_Buffer
->adwTxKey
[0]);
1744 cbFrameBodySize
= pPacket
->cbPayloadLen
;
1745 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
1746 wTxBufSize
= sizeof(STxBufHead
);
1747 memset(pTxBufHead
, 0, wTxBufSize
);
1749 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1750 wCurrentRate
= RATE_6M
;
1751 byPktType
= PK_TYPE_11A
;
1753 wCurrentRate
= RATE_1M
;
1754 byPktType
= PK_TYPE_11B
;
1757 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1758 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1759 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1760 // to set power here.
1761 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
1762 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
1764 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
1766 pDevice
->wCurrentRate
= wCurrentRate
;
1770 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
1771 pTxBufHead
->wFIFOCtl
= 0;
1773 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
1774 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1776 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
1777 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
1779 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
1780 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
1783 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
1784 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
1786 if (is_multicast_ether_addr(pPacket
->p80211Header
->sA3
.abyAddr1
)) {
1791 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1794 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
1795 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
1797 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
1798 //Set Preamble type always long
1799 //pDevice->byPreambleType = PREAMBLE_LONG;
1800 // probe-response don't retry
1801 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1802 // bNeedACK = false;
1803 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1807 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
1809 if ((pPacket
->p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
1811 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
1813 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
1816 //Set FRAGCTL_MACHDCNT
1817 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)(cbMacHdLen
<< 10));
1820 // Although spec says MMPDU can be fragmented; In most case,
1821 // no one will send a MMPDU under fragmentation. With RTS may occur.
1822 pDevice
->bAES
= false; //Set FRAGCTL_WEPTYP
1824 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
1825 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
1828 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1830 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
1831 cbIVlen
= 8;//IV+ExtIV
1834 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1835 //We need to get seed here for filling TxKey entry.
1836 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1837 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1839 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
1840 cbIVlen
= 8;//RSN Header
1842 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1843 pDevice
->bAES
= true;
1845 //MAC Header should be padding 0 to DW alignment.
1846 uPadding
= 4 - (cbMacHdLen
%4);
1850 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
;
1852 //Set FIFOCTL_GrpAckPolicy
1853 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1854 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1856 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1858 //Set RrvTime/RTS/CTS Buffer
1859 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1861 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
1864 pCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
1865 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + sizeof(SCTS
));
1866 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + sizeof(SCTS
) + sizeof(STxDataHead_g
);
1868 else { // 802.11a/b packet
1869 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
1873 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
1874 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_ab
) + sizeof(STxDataHead_ab
);
1877 memset((void *)(pbyTxBufferAddr
+ wTxBufSize
), 0,
1878 (cbHeaderSize
- wTxBufSize
));
1880 memcpy(&(sEthHeader
.abyDstAddr
[0]),
1881 &(pPacket
->p80211Header
->sA3
.abyAddr1
[0]),
1883 memcpy(&(sEthHeader
.abySrcAddr
[0]),
1884 &(pPacket
->p80211Header
->sA3
.abyAddr2
[0]),
1886 //=========================
1888 //=========================
1889 pTxBufHead
->wFragCtl
|= (WORD
)FRAGCTL_NONFRAG
;
1892 //Fill FIFO,RrvTime,RTS,and CTS
1893 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
, pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pCTS
,
1894 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
);
1897 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
1898 0, 0, 1, AUTO_FB_NONE
);
1900 pMACHeader
= (PS802_11Header
) (pbyTxBufferAddr
+ cbHeaderSize
);
1902 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ cbFrameBodySize
;
1904 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
1906 PBYTE pbyPayloadHead
;
1908 PSKeyItem pTransmitKey
= NULL
;
1910 pbyIVHead
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
);
1911 pbyPayloadHead
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
1913 if ((pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
1914 (pDevice
->bLinkPass
== true)) {
1915 pbyBSSID
= pDevice
->abyBSSID
;
1917 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
1919 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
1920 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
1924 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get PTK.\n");
1929 pbyBSSID
= pDevice
->abyBroadcastAddr
;
1930 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
1931 pTransmitKey
= NULL
;
1932 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KEY is NULL. OP Mode[%d]\n", pDevice
->eOPMode
);
1934 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
1938 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1939 (PBYTE
)pMACHeader
, (WORD
)cbFrameBodySize
, NULL
);
1941 memcpy(pMACHeader
, pPacket
->p80211Header
, cbMacHdLen
);
1942 memcpy(pbyPayloadHead
, ((PBYTE
)(pPacket
->p80211Header
) + cbMacHdLen
),
1946 // Copy the Packet into a tx Buffer
1947 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
1950 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1951 pDevice
->wSeqCounter
++ ;
1952 if (pDevice
->wSeqCounter
> 0x0fff)
1953 pDevice
->wSeqCounter
= 0;
1956 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1957 // of FIFO control header.
1958 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1959 // in the same place of other packet's Duration-field).
1960 // And it will cause Cisco-AP to issue Disassociation-packet
1961 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1962 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_a
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1963 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_b
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1965 ((PSTxDataHead_ab
)pvTxDataHd
)->wDuration
= cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1970 pTX_Buffer
->wTxByteCount
= cpu_to_le16((WORD
)(cbReqCount
));
1971 pTX_Buffer
->byPKTNO
= (BYTE
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
1972 pTX_Buffer
->byType
= 0x00;
1974 pContext
->pPacket
= NULL
;
1975 pContext
->Type
= CONTEXT_MGMT_PACKET
;
1976 pContext
->uBufLen
= (WORD
)cbReqCount
+ 4; //USB header
1978 if (WLAN_GET_FC_TODS(pMACHeader
->wFrameCtl
) == 0) {
1979 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr1
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
1982 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr3
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
1985 PIPEnsSendBulkOut(pDevice
,pContext
);
1986 return CMD_STATUS_PENDING
;
1990 CMD_STATUS
csBeacon_xmit(struct vnt_private
*pDevice
,
1991 struct vnt_tx_mgmt
*pPacket
)
1993 u32 cbFrameSize
= pPacket
->cbMPDULen
+ WLAN_FCS_LEN
;
1994 u32 cbHeaderSize
= 0;
1995 u16 wTxBufSize
= sizeof(STxShortBufHead
);
1996 PSTxShortBufHead pTxBufHead
;
1997 PS802_11Header pMACHeader
;
1998 PSTxDataHead_ab pTxDataHead
;
2000 u32 cbFrameBodySize
;
2002 PBEACON_BUFFER pTX_Buffer
;
2003 u8
*pbyTxBufferAddr
;
2004 PUSB_SEND_CONTEXT pContext
;
2008 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2009 if (NULL
== pContext
) {
2010 status
= CMD_STATUS_RESOURCES
;
2011 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
2014 pTX_Buffer
= (PBEACON_BUFFER
) (&pContext
->Data
[0]);
2015 pbyTxBufferAddr
= (PBYTE
)&(pTX_Buffer
->wFIFOCtl
);
2017 cbFrameBodySize
= pPacket
->cbPayloadLen
;
2019 pTxBufHead
= (PSTxShortBufHead
) pbyTxBufferAddr
;
2020 wTxBufSize
= sizeof(STxShortBufHead
);
2021 memset(pTxBufHead
, 0, wTxBufSize
);
2023 if (pDevice
->byBBType
== BB_TYPE_11A
) {
2024 wCurrentRate
= RATE_6M
;
2025 pTxDataHead
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2026 //Get SignalField,ServiceField,Length
2027 BBvCalculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, PK_TYPE_11A
,
2028 (PWORD
)&(pTxDataHead
->wTransmitLength
), (PBYTE
)&(pTxDataHead
->byServiceField
), (PBYTE
)&(pTxDataHead
->bySignalField
)
2030 //Get Duration and TimeStampOff
2031 pTxDataHead
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_A
, cbFrameSize
, PK_TYPE_11A
,
2032 wCurrentRate
, false, 0, 0, 1, AUTO_FB_NONE
));
2033 pTxDataHead
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
2034 cbHeaderSize
= wTxBufSize
+ sizeof(STxDataHead_ab
);
2036 wCurrentRate
= RATE_1M
;
2037 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2038 pTxDataHead
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2039 //Get SignalField,ServiceField,Length
2040 BBvCalculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, PK_TYPE_11B
,
2041 (PWORD
)&(pTxDataHead
->wTransmitLength
), (PBYTE
)&(pTxDataHead
->byServiceField
), (PBYTE
)&(pTxDataHead
->bySignalField
)
2043 //Get Duration and TimeStampOff
2044 pTxDataHead
->wDuration
= cpu_to_le16((WORD
)s_uGetDataDuration(pDevice
, DATADUR_B
, cbFrameSize
, PK_TYPE_11B
,
2045 wCurrentRate
, false, 0, 0, 1, AUTO_FB_NONE
));
2046 pTxDataHead
->wTimeStampOff
= wTimeStampOff
[pDevice
->byPreambleType
%2][wCurrentRate
%MAX_RATE
];
2047 cbHeaderSize
= wTxBufSize
+ sizeof(STxDataHead_ab
);
2050 //Generate Beacon Header
2051 pMACHeader
= (PS802_11Header
)(pbyTxBufferAddr
+ cbHeaderSize
);
2052 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
2054 pMACHeader
->wDurationID
= 0;
2055 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2056 pDevice
->wSeqCounter
++ ;
2057 if (pDevice
->wSeqCounter
> 0x0fff)
2058 pDevice
->wSeqCounter
= 0;
2060 cbReqCount
= cbHeaderSize
+ WLAN_HDR_ADDR3_LEN
+ cbFrameBodySize
;
2062 pTX_Buffer
->wTxByteCount
= (WORD
)cbReqCount
;
2063 pTX_Buffer
->byPKTNO
= (BYTE
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2064 pTX_Buffer
->byType
= 0x01;
2066 pContext
->pPacket
= NULL
;
2067 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2068 pContext
->uBufLen
= (WORD
)cbReqCount
+ 4; //USB header
2070 PIPEnsSendBulkOut(pDevice
,pContext
);
2071 return CMD_STATUS_PENDING
;
2076 void vDMA0_tx_80211(struct vnt_private
*pDevice
, struct sk_buff
*skb
)
2078 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2080 u8
*pbyTxBufferAddr
;
2081 void *pvRTS
, *pvCTS
, *pvTxDataHd
;
2082 u32 uDuration
, cbReqCount
;
2083 PS802_11Header pMACHeader
;
2084 u32 cbHeaderSize
, cbFrameBodySize
;
2085 int bNeedACK
, bIsPSPOLL
= false;
2086 PSTxBufHead pTxBufHead
;
2088 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbFCSlen
= 4;
2090 u32 cbMICHDR
= 0, uLength
= 0;
2091 u32 dwMICKey0
, dwMICKey1
;
2093 u32
*pdwMIC_L
, *pdwMIC_R
;
2096 SEthernetHeader sEthHeader
;
2097 void *pvRrvTime
, *pMICHDR
;
2098 u32 wCurrentRate
= RATE_1M
;
2099 PUWLAN_80211HDR p80211Header
;
2101 int bNodeExist
= false;
2103 PSKeyItem pTransmitKey
= NULL
;
2104 u8
*pbyIVHead
, *pbyPayloadHead
, *pbyMacHdr
;
2105 u32 cbExtSuppRate
= 0;
2106 PTX_BUFFER pTX_Buffer
;
2107 PUSB_SEND_CONTEXT pContext
;
2110 pvRrvTime
= pMICHDR
= pvRTS
= pvCTS
= pvTxDataHd
= NULL
;
2112 if(skb
->len
<= WLAN_HDR_ADDR3_LEN
) {
2113 cbFrameBodySize
= 0;
2116 cbFrameBodySize
= skb
->len
- WLAN_HDR_ADDR3_LEN
;
2118 p80211Header
= (PUWLAN_80211HDR
)skb
->data
;
2120 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2122 if (NULL
== pContext
) {
2123 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0 TX...NO CONTEXT!\n");
2124 dev_kfree_skb_irq(skb
);
2128 pTX_Buffer
= (PTX_BUFFER
)(&pContext
->Data
[0]);
2129 pbyTxBufferAddr
= (PBYTE
)(&pTX_Buffer
->adwTxKey
[0]);
2130 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
2131 wTxBufSize
= sizeof(STxBufHead
);
2132 memset(pTxBufHead
, 0, wTxBufSize
);
2134 if (pDevice
->byBBType
== BB_TYPE_11A
) {
2135 wCurrentRate
= RATE_6M
;
2136 byPktType
= PK_TYPE_11A
;
2138 wCurrentRate
= RATE_1M
;
2139 byPktType
= PK_TYPE_11B
;
2142 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2143 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2144 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2145 // to set power here.
2146 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
2147 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
2149 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
2152 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header
->sA3
.wFrameCtl
);
2155 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
2156 pTxBufHead
->wFIFOCtl
= 0;
2158 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
2159 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
2161 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
2162 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
2164 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
2165 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
2168 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
2169 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
2171 if (is_multicast_ether_addr(p80211Header
->sA3
.abyAddr1
)) {
2173 if (pDevice
->bEnableHostWEP
) {
2179 if (pDevice
->bEnableHostWEP
) {
2180 if (BSSbIsSTAInNodeDB(pDevice
, (PBYTE
)(p80211Header
->sA3
.abyAddr1
), &uNodeIndex
))
2184 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
2187 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
2188 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
2190 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
2191 //Set Preamble type always long
2192 //pDevice->byPreambleType = PREAMBLE_LONG;
2194 // probe-response don't retry
2195 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2196 // bNeedACK = false;
2197 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2201 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
2203 if ((p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
2205 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
2207 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
2210 // hostapd daemon ext support rate patch
2211 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
2213 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0) {
2214 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
;
2217 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0) {
2218 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
;
2221 if (cbExtSuppRate
>0) {
2222 cbFrameBodySize
= WLAN_ASSOCRESP_OFF_SUPP_RATES
;
2227 //Set FRAGCTL_MACHDCNT
2228 pTxBufHead
->wFragCtl
|= cpu_to_le16((WORD
)cbMacHdLen
<< 10);
2231 // Although spec says MMPDU can be fragmented; In most case,
2232 // no one will send a MMPDU under fragmentation. With RTS may occur.
2233 pDevice
->bAES
= false; //Set FRAGCTL_WEPTYP
2236 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
2237 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
2240 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
2242 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
2243 cbIVlen
= 8;//IV+ExtIV
2246 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
2247 //We need to get seed here for filling TxKey entry.
2248 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2249 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2251 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
2252 cbIVlen
= 8;//RSN Header
2254 cbMICHDR
= sizeof(SMICHDRHead
);
2255 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
2256 pDevice
->bAES
= true;
2258 //MAC Header should be padding 0 to DW alignment.
2259 uPadding
= 4 - (cbMacHdLen
%4);
2263 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
+ cbExtSuppRate
;
2265 //Set FIFOCTL_GrpAckPolicy
2266 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
2267 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
2269 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2272 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
2274 pvRrvTime
= (PSRrvTime_gCTS
) (pbyTxBufferAddr
+ wTxBufSize
);
2275 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
));
2277 pvCTS
= (PSCTS
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
);
2278 pvTxDataHd
= (PSTxDataHead_g
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
));
2279 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_gCTS
) + cbMICHDR
+ sizeof(SCTS
) + sizeof(STxDataHead_g
);
2282 else {//802.11a/b packet
2284 pvRrvTime
= (PSRrvTime_ab
) (pbyTxBufferAddr
+ wTxBufSize
);
2285 pMICHDR
= (PSMICHDRHead
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
));
2288 pvTxDataHd
= (PSTxDataHead_ab
) (pbyTxBufferAddr
+ wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
);
2289 cbHeaderSize
= wTxBufSize
+ sizeof(SRrvTime_ab
) + cbMICHDR
+ sizeof(STxDataHead_ab
);
2291 memset((void *)(pbyTxBufferAddr
+ wTxBufSize
), 0,
2292 (cbHeaderSize
- wTxBufSize
));
2293 memcpy(&(sEthHeader
.abyDstAddr
[0]),
2294 &(p80211Header
->sA3
.abyAddr1
[0]),
2296 memcpy(&(sEthHeader
.abySrcAddr
[0]),
2297 &(p80211Header
->sA3
.abyAddr2
[0]),
2299 //=========================
2301 //=========================
2302 pTxBufHead
->wFragCtl
|= (WORD
)FRAGCTL_NONFRAG
;
2305 //Fill FIFO,RrvTime,RTS,and CTS
2306 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
, pbyTxBufferAddr
, pvRrvTime
, pvRTS
, pvCTS
,
2307 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
);
2310 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
2311 0, 0, 1, AUTO_FB_NONE
);
2313 pMACHeader
= (PS802_11Header
) (pbyTxBufferAddr
+ cbHeaderSize
);
2315 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbExtSuppRate
;
2317 pbyMacHdr
= (PBYTE
)(pbyTxBufferAddr
+ cbHeaderSize
);
2318 pbyPayloadHead
= (PBYTE
)(pbyMacHdr
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
2319 pbyIVHead
= (PBYTE
)(pbyMacHdr
+ cbMacHdLen
+ uPadding
);
2321 // Copy the Packet into a tx Buffer
2322 memcpy(pbyMacHdr
, skb
->data
, cbMacHdLen
);
2324 // version set to 0, patch for hostapd deamon
2325 pMACHeader
->wFrameCtl
&= cpu_to_le16(0xfffc);
2326 memcpy(pbyPayloadHead
, (skb
->data
+ cbMacHdLen
), cbFrameBodySize
);
2328 // replace support rate, patch for hostapd daemon( only support 11M)
2329 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
2330 if (cbExtSuppRate
!= 0) {
2331 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0)
2332 memcpy((pbyPayloadHead
+ cbFrameBodySize
),
2333 pMgmt
->abyCurrSuppRates
,
2334 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
2336 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0)
2337 memcpy((pbyPayloadHead
+ cbFrameBodySize
) + ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
,
2338 pMgmt
->abyCurrExtSuppRates
,
2339 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
2345 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
2347 if (pDevice
->bEnableHostWEP
) {
2348 pTransmitKey
= &STempKey
;
2349 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2350 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2351 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2352 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2353 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2354 memcpy(pTransmitKey
->abyKey
,
2355 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2356 pTransmitKey
->uKeyLength
2360 if ((pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
2362 dwMICKey0
= *(PDWORD
)(&pTransmitKey
->abyKey
[16]);
2363 dwMICKey1
= *(PDWORD
)(&pTransmitKey
->abyKey
[20]);
2365 // DO Software Michael
2366 MIC_vInit(dwMICKey0
, dwMICKey1
);
2367 MIC_vAppend((PBYTE
)&(sEthHeader
.abyDstAddr
[0]), 12);
2369 MIC_vAppend((PBYTE
)&dwMIC_Priority
, 4);
2370 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0_tx_8021:MIC KEY:"\
2371 " %X, %X\n", dwMICKey0
, dwMICKey1
);
2373 uLength
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
;
2375 MIC_vAppend((pbyTxBufferAddr
+ uLength
), cbFrameBodySize
);
2377 pdwMIC_L
= (PDWORD
)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
);
2378 pdwMIC_R
= (PDWORD
)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
+ 4);
2380 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
2383 if (pDevice
->bTxMICFail
== true) {
2386 pDevice
->bTxMICFail
= false;
2389 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uLength: %d, %d\n", uLength
, cbFrameBodySize
);
2390 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"cbReqCount:%d, %d, %d, %d\n", cbReqCount
, cbHeaderSize
, uPadding
, cbIVlen
);
2391 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC:%x, %x\n",
2392 *pdwMIC_L
, *pdwMIC_R
);
2396 s_vFillTxKey(pDevice
, (PBYTE
)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
2397 pbyMacHdr
, (WORD
)cbFrameBodySize
, (PBYTE
)pMICHDR
);
2399 if (pDevice
->bEnableHostWEP
) {
2400 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
2401 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
2404 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
2405 s_vSWencryption(pDevice
, pTransmitKey
, pbyPayloadHead
, (WORD
)(cbFrameBodySize
+ cbMIClen
));
2409 pMACHeader
->wSeqCtl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2410 pDevice
->wSeqCounter
++ ;
2411 if (pDevice
->wSeqCounter
> 0x0fff)
2412 pDevice
->wSeqCounter
= 0;
2416 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2417 // of FIFO control header.
2418 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2419 // in the same place of other packet's Duration-field).
2420 // And it will cause Cisco-AP to issue Disassociation-packet
2421 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
2422 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_a
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2423 ((PSTxDataHead_g
)pvTxDataHd
)->wDuration_b
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2425 ((PSTxDataHead_ab
)pvTxDataHd
)->wDuration
= cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2429 pTX_Buffer
->wTxByteCount
= cpu_to_le16((WORD
)(cbReqCount
));
2430 pTX_Buffer
->byPKTNO
= (BYTE
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2431 pTX_Buffer
->byType
= 0x00;
2433 pContext
->pPacket
= skb
;
2434 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2435 pContext
->uBufLen
= (WORD
)cbReqCount
+ 4; //USB header
2437 if (WLAN_GET_FC_TODS(pMACHeader
->wFrameCtl
) == 0) {
2438 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr1
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
2441 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->abyAddr3
[0]),(WORD
)cbFrameSize
,pTX_Buffer
->wFIFOCtl
);
2443 PIPEnsSendBulkOut(pDevice
,pContext
);
2451 //TYPE_AC0DMA data tx
2454 * Tx packet via AC0DMA(DMA1)
2458 * pDevice - Pointer to the adapter
2459 * skb - Pointer to tx skb packet
2463 * Return Value: NULL
2466 int nsDMA_tx_packet(struct vnt_private
*pDevice
,
2467 u32 uDMAIdx
, struct sk_buff
*skb
)
2469 struct net_device_stats
*pStats
= &pDevice
->stats
;
2470 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2471 u32 BytesToWrite
= 0, uHeaderLen
= 0;
2473 u8 byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2476 int bNeedEncryption
= false;
2477 PSKeyItem pTransmitKey
= NULL
;
2480 int bTKIP_UseGTK
= false;
2481 int bNeedDeAuth
= false;
2483 int bNodeExist
= false;
2484 PUSB_SEND_CONTEXT pContext
;
2485 bool fConvertedPacket
;
2486 PTX_BUFFER pTX_Buffer
;
2488 u16 wKeepRate
= pDevice
->wCurrentRate
;
2489 int bTxeapol_key
= false;
2492 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
2494 if (pDevice
->uAssocCount
== 0) {
2495 dev_kfree_skb_irq(skb
);
2499 if (is_multicast_ether_addr((PBYTE
)(skb
->data
))) {
2502 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
2504 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skb
);
2505 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
2507 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
2510 // multicast/broadcast data rate
2512 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2513 pDevice
->wCurrentRate
= RATE_2M
;
2515 pDevice
->wCurrentRate
= RATE_24M
;
2516 // long preamble type
2517 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2521 if (BSSbIsSTAInNodeDB(pDevice
, (PBYTE
)(skb
->data
), &uNodeIndex
)) {
2523 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bPSEnable
) {
2525 skb_queue_tail(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
, skb
);
2527 pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
++;
2529 wAID
= pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
;
2530 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
2531 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set:pMgmt->abyPSTxMap[%d]= %d\n",
2532 (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
2536 // AP rate decided from node
2537 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2538 // tx preamble decided from node
2540 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2541 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2544 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2550 if (bNodeExist
== false) {
2551 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Unknown STA not found in node DB \n");
2552 dev_kfree_skb_irq(skb
);
2557 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2559 if (pContext
== NULL
) {
2560 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
" pContext == NULL\n");
2561 dev_kfree_skb_irq(skb
);
2562 return STATUS_RESOURCES
;
2565 memcpy(pDevice
->sTxEthHeader
.abyDstAddr
, (PBYTE
)(skb
->data
), ETH_HLEN
);
2567 //mike add:station mode check eapol-key challenge--->
2569 BYTE Protocol_Version
; //802.1x Authentication
2570 BYTE Packet_Type
; //802.1x Authentication
2571 BYTE Descriptor_type
;
2574 Protocol_Version
= skb
->data
[ETH_HLEN
];
2575 Packet_Type
= skb
->data
[ETH_HLEN
+1];
2576 Descriptor_type
= skb
->data
[ETH_HLEN
+1+1+2];
2577 Key_info
= (skb
->data
[ETH_HLEN
+1+1+2+1] << 8)|(skb
->data
[ETH_HLEN
+1+1+2+2]);
2578 if (pDevice
->sTxEthHeader
.wType
== cpu_to_be16(ETH_P_PAE
)) {
2579 /* 802.1x OR eapol-key challenge frame transfer */
2580 if (((Protocol_Version
== 1) || (Protocol_Version
== 2)) &&
2581 (Packet_Type
== 3)) {
2582 bTxeapol_key
= true;
2583 if(!(Key_info
& BIT3
) && //WPA or RSN group-key challenge
2584 (Key_info
& BIT8
) && (Key_info
& BIT9
)) { //send 2/2 key
2585 if(Descriptor_type
==254) {
2586 pDevice
->fWPA_Authened
= true;
2590 pDevice
->fWPA_Authened
= true;
2591 PRINT_K("WPA2(re-keying) ");
2593 PRINT_K("Authentication completed!!\n");
2595 else if((Key_info
& BIT3
) && (Descriptor_type
==2) && //RSN pairwise-key challenge
2596 (Key_info
& BIT8
) && (Key_info
& BIT9
)) {
2597 pDevice
->fWPA_Authened
= true;
2598 PRINT_K("WPA2 Authentication completed!!\n");
2603 //mike add:station mode check eapol-key challenge<---
2605 if (pDevice
->bEncryptionEnable
== true) {
2606 bNeedEncryption
= true;
2609 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
2610 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2611 pbyBSSID
= pDevice
->abyBSSID
;
2613 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
2615 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
2616 bTKIP_UseGTK
= true;
2617 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2621 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get PTK.\n");
2624 }else if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2626 pbyBSSID
= pDevice
->sTxEthHeader
.abyDstAddr
; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2627 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS Serach Key: \n");
2628 for (ii
= 0; ii
< 6; ii
++)
2629 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"%x \n", *(pbyBSSID
+ii
));
2630 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"\n");
2633 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == true)
2637 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2638 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2639 pTransmitKey
= NULL
;
2640 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2641 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2644 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"NOT IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2646 bTKIP_UseGTK
= true;
2647 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2652 if (pDevice
->bEnableHostWEP
) {
2653 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"acdma0: STA index %d\n", uNodeIndex
);
2654 if (pDevice
->bEncryptionEnable
== true) {
2655 pTransmitKey
= &STempKey
;
2656 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2657 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2658 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2659 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2660 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2661 memcpy(pTransmitKey
->abyKey
,
2662 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2663 pTransmitKey
->uKeyLength
2668 byPktType
= (BYTE
)pDevice
->byPacketType
;
2670 if (pDevice
->bFixRate
) {
2671 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2672 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2673 pDevice
->wCurrentRate
= RATE_11M
;
2675 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
2678 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2679 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2680 pDevice
->wCurrentRate
= RATE_6M
;
2682 if (pDevice
->uConnectionRate
>= RATE_54M
)
2683 pDevice
->wCurrentRate
= RATE_54M
;
2685 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
2690 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2691 // Adhoc Tx rate decided from node DB
2692 if (is_multicast_ether_addr(pDevice
->sTxEthHeader
.abyDstAddr
)) {
2693 // Multicast use highest data rate
2694 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2696 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2699 if(BSSbIsSTAInNodeDB(pDevice
, &(pDevice
->sTxEthHeader
.abyDstAddr
[0]), &uNodeIndex
)) {
2700 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2701 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2702 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2706 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2708 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex
, pDevice
->wCurrentRate
);
2711 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2712 pDevice
->wCurrentRate
= RATE_2M
;
2714 pDevice
->wCurrentRate
= RATE_24M
; // refer to vMgrCreateOwnIBSS()'s
2715 // abyCurrExtSuppRates[]
2716 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2717 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Not Found Node use highest basic Rate.....\n");
2721 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
2722 // Infra STA rate decided from AP Node, index = 0
2723 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2727 if (pDevice
->sTxEthHeader
.wType
== cpu_to_be16(ETH_P_PAE
)) {
2728 if (pDevice
->byBBType
!= BB_TYPE_11A
) {
2729 pDevice
->wCurrentRate
= RATE_1M
;
2730 pDevice
->byACKRate
= RATE_1M
;
2731 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2732 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2734 pDevice
->wCurrentRate
= RATE_6M
;
2735 pDevice
->byACKRate
= RATE_6M
;
2736 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2737 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2741 DBG_PRT(MSG_LEVEL_DEBUG
,
2742 KERN_INFO
"dma_tx: pDevice->wCurrentRate = %d\n",
2743 pDevice
->wCurrentRate
);
2745 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2746 bScheduleCommand((void *) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2749 if (pDevice
->wCurrentRate
<= RATE_11M
) {
2750 byPktType
= PK_TYPE_11B
;
2753 if (bNeedEncryption
== true) {
2754 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ntohs Pkt Type=%04x\n", ntohs(pDevice
->sTxEthHeader
.wType
));
2755 if ((pDevice
->sTxEthHeader
.wType
) == cpu_to_be16(ETH_P_PAE
)) {
2756 bNeedEncryption
= false;
2757 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pkt Type=%04x\n", (pDevice
->sTxEthHeader
.wType
));
2758 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2759 if (pTransmitKey
== NULL
) {
2760 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Don't Find TX KEY\n");
2763 if (bTKIP_UseGTK
== true) {
2764 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"error: KEY is GTK!!~~\n");
2767 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%X]\n",
2768 pTransmitKey
->dwKeyIndex
);
2769 bNeedEncryption
= true;
2774 if (pDevice
->bEnableHostWEP
) {
2775 if ((uNodeIndex
!= 0) &&
2776 (pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
& PAIRWISE_KEY
)) {
2777 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%X]\n",
2778 pTransmitKey
->dwKeyIndex
);
2779 bNeedEncryption
= true;
2785 if (pTransmitKey
== NULL
) {
2786 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return no tx key\n");
2787 pContext
->bBoolInUse
= false;
2788 dev_kfree_skb_irq(skb
);
2789 pStats
->tx_dropped
++;
2790 return STATUS_FAILURE
;
2795 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
2796 (PBYTE
)(&pContext
->Data
[0]), bNeedEncryption
,
2797 skb
->len
, uDMAIdx
, &pDevice
->sTxEthHeader
,
2798 (PBYTE
)skb
->data
, pTransmitKey
, uNodeIndex
,
2799 pDevice
->wCurrentRate
,
2800 &uHeaderLen
, &BytesToWrite
2803 if (fConvertedPacket
== false) {
2804 pContext
->bBoolInUse
= false;
2805 dev_kfree_skb_irq(skb
);
2806 return STATUS_FAILURE
;
2809 if ( pDevice
->bEnablePSMode
== true ) {
2810 if ( !pDevice
->bPSModeTxBurst
) {
2811 bScheduleCommand((void *) pDevice
,
2812 WLAN_CMD_MAC_DISPOWERSAVING
,
2814 pDevice
->bPSModeTxBurst
= true;
2818 pTX_Buffer
= (PTX_BUFFER
)&(pContext
->Data
[0]);
2819 pTX_Buffer
->byPKTNO
= (BYTE
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2820 pTX_Buffer
->wTxByteCount
= (WORD
)BytesToWrite
;
2822 pContext
->pPacket
= skb
;
2823 pContext
->Type
= CONTEXT_DATA_PACKET
;
2824 pContext
->uBufLen
= (WORD
)BytesToWrite
+ 4 ; //USB header
2826 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pContext
->sEthHeader
.abyDstAddr
[0]),(WORD
) (BytesToWrite
-uHeaderLen
),pTX_Buffer
->wFIFOCtl
);
2828 status
= PIPEnsSendBulkOut(pDevice
,pContext
);
2830 if (bNeedDeAuth
== true) {
2831 WORD wReason
= WLAN_MGMT_REASON_MIC_FAILURE
;
2833 bScheduleCommand((void *) pDevice
, WLAN_CMD_DEAUTH
, (PBYTE
) &wReason
);
2836 if(status
!=STATUS_PENDING
) {
2837 pContext
->bBoolInUse
= false;
2838 dev_kfree_skb_irq(skb
);
2839 return STATUS_FAILURE
;
2850 * Relay packet send (AC1DMA) from rx dpc.
2854 * pDevice - Pointer to the adapter
2855 * pPacket - Pointer to rx packet
2856 * cbPacketSize - rx ethernet frame size
2860 * Return Value: Return true if packet is copy to dma1; otherwise false
2863 int bRelayPacketSend(struct vnt_private
*pDevice
, u8
*pbySkbData
, u32 uDataLen
,
2866 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2867 u32 BytesToWrite
= 0, uHeaderLen
= 0;
2868 u8 byPktType
= PK_TYPE_11B
;
2869 int bNeedEncryption
= false;
2871 PSKeyItem pTransmitKey
= NULL
;
2873 PUSB_SEND_CONTEXT pContext
;
2875 int fConvertedPacket
;
2876 PTX_BUFFER pTX_Buffer
;
2878 u16 wKeepRate
= pDevice
->wCurrentRate
;
2882 pContext
= (PUSB_SEND_CONTEXT
)s_vGetFreeContext(pDevice
);
2884 if (NULL
== pContext
) {
2888 memcpy(pDevice
->sTxEthHeader
.abyDstAddr
, (PBYTE
)pbySkbData
, ETH_HLEN
);
2890 if (pDevice
->bEncryptionEnable
== true) {
2891 bNeedEncryption
= true;
2893 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2894 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2895 pTransmitKey
= NULL
;
2896 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2898 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2902 if (pDevice
->bEnableHostWEP
) {
2903 if (uNodeIndex
< MAX_NODE_NUM
+ 1) {
2904 pTransmitKey
= &STempKey
;
2905 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2906 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2907 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2908 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2909 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2910 memcpy(pTransmitKey
->abyKey
,
2911 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2912 pTransmitKey
->uKeyLength
2917 if ( bNeedEncryption
&& (pTransmitKey
== NULL
) ) {
2918 pContext
->bBoolInUse
= false;
2922 byPktTyp
= (BYTE
)pDevice
->byPacketType
;
2924 if (pDevice
->bFixRate
) {
2925 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2926 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2927 pDevice
->wCurrentRate
= RATE_11M
;
2929 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
2932 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2933 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2934 pDevice
->wCurrentRate
= RATE_6M
;
2936 if (pDevice
->uConnectionRate
>= RATE_54M
)
2937 pDevice
->wCurrentRate
= RATE_54M
;
2939 pDevice
->wCurrentRate
= (WORD
)pDevice
->uConnectionRate
;
2944 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2947 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2948 bScheduleCommand((void *) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2951 if (pDevice
->wCurrentRate
<= RATE_11M
)
2952 byPktType
= PK_TYPE_11B
;
2954 BytesToWrite
= uDataLen
+ ETH_FCS_LEN
;
2956 // Convert the packet to an usb frame and copy into our buffer
2957 // and send the irp.
2959 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
2960 (PBYTE
)(&pContext
->Data
[0]), bNeedEncryption
,
2961 uDataLen
, TYPE_AC0DMA
, &pDevice
->sTxEthHeader
,
2962 pbySkbData
, pTransmitKey
, uNodeIndex
,
2963 pDevice
->wCurrentRate
,
2964 &uHeaderLen
, &BytesToWrite
2967 if (fConvertedPacket
== false) {
2968 pContext
->bBoolInUse
= false;
2972 pTX_Buffer
= (PTX_BUFFER
)&(pContext
->Data
[0]);
2973 pTX_Buffer
->byPKTNO
= (BYTE
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2974 pTX_Buffer
->wTxByteCount
= (WORD
)BytesToWrite
;
2976 pContext
->pPacket
= NULL
;
2977 pContext
->Type
= CONTEXT_DATA_PACKET
;
2978 pContext
->uBufLen
= (WORD
)BytesToWrite
+ 4 ; //USB header
2980 s_vSaveTxPktInfo(pDevice
, (BYTE
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pContext
->sEthHeader
.abyDstAddr
[0]),(WORD
) (BytesToWrite
-uHeaderLen
),pTX_Buffer
->wFIFOCtl
);
2982 status
= PIPEnsSendBulkOut(pDevice
,pContext
);