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
65 static int msglevel
= MSG_LEVEL_INFO
;
67 const u16 wTimeStampOff
[2][MAX_RATE
] = {
68 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
72 const u16 wFB_Opt0
[2][5] = {
73 {RATE_12M
, RATE_18M
, RATE_24M
, RATE_36M
, RATE_48M
}, // fallback_rate0
74 {RATE_12M
, RATE_12M
, RATE_18M
, RATE_24M
, RATE_36M
}, // fallback_rate1
76 const u16 wFB_Opt1
[2][5] = {
77 {RATE_12M
, RATE_18M
, RATE_24M
, RATE_24M
, RATE_36M
}, // fallback_rate0
78 {RATE_6M
, RATE_6M
, RATE_12M
, RATE_12M
, RATE_18M
}, // fallback_rate1
85 #define RTSDUR_BA_F0 4
86 #define RTSDUR_AA_F0 5
87 #define RTSDUR_BA_F1 6
88 #define RTSDUR_AA_F1 7
89 #define CTSDUR_BA_F0 8
90 #define CTSDUR_BA_F1 9
93 #define DATADUR_A_F0 12
94 #define DATADUR_A_F1 13
96 static void s_vSaveTxPktInfo(struct vnt_private
*pDevice
, u8 byPktNum
,
97 u8
*pbyDestAddr
, u16 wPktLength
, u16 wFIFOCtl
);
99 static void *s_vGetFreeContext(struct vnt_private
*pDevice
);
101 static void s_vGenerateTxParameter(struct vnt_private
*pDevice
,
102 u8 byPktType
, u16 wCurrentRate
, void *pTxBufHead
, void *pvRrvTime
,
103 void *rts_cts
, u32 cbFrameSize
, int bNeedACK
, u32 uDMAIdx
,
104 struct ethhdr
*psEthHeader
, bool need_rts
);
106 static u32
s_uFillDataHead(struct vnt_private
*pDevice
,
107 u8 byPktType
, u16 wCurrentRate
, void *pTxDataHead
, u32 cbFrameLength
,
108 u32 uDMAIdx
, int bNeedAck
, u8 byFBOption
);
110 static void s_vGenerateMACHeader(struct vnt_private
*pDevice
,
111 u8
*pbyBufferAddr
, u16 wDuration
, struct ethhdr
*psEthHeader
,
112 int bNeedEncrypt
, u16 wFragType
, u32 uDMAIdx
, u32 uFragIdx
);
114 static void s_vFillTxKey(struct vnt_private
*pDevice
, u8
*pbyBuf
,
115 u8
*pbyIVHead
, PSKeyItem pTransmitKey
, u8
*pbyHdrBuf
, u16 wPayloadLen
,
116 struct vnt_mic_hdr
*mic_hdr
);
118 static void s_vSWencryption(struct vnt_private
*pDevice
,
119 PSKeyItem pTransmitKey
, u8
*pbyPayloadHead
, u16 wPayloadSize
);
121 static unsigned int s_uGetTxRsvTime(struct vnt_private
*pDevice
, u8 byPktType
,
122 u32 cbFrameLength
, u16 wRate
, int bNeedAck
);
124 static u16
s_uGetRTSCTSRsvTime(struct vnt_private
*pDevice
, u8 byRTSRsvType
,
125 u8 byPktType
, u32 cbFrameLength
, u16 wCurrentRate
);
127 static void s_vFillCTSHead(struct vnt_private
*pDevice
, u32 uDMAIdx
,
128 u8 byPktType
, union vnt_tx_data_head
*head
, u32 cbFrameLength
,
129 int bNeedAck
, u16 wCurrentRate
, u8 byFBOption
);
131 static void s_vFillRTSHead(struct vnt_private
*pDevice
, u8 byPktType
,
132 union vnt_tx_data_head
*head
, u32 cbFrameLength
, int bNeedAck
,
133 struct ethhdr
*psEthHeader
, u16 wCurrentRate
, u8 byFBOption
);
135 static u16
s_uGetDataDuration(struct vnt_private
*pDevice
,
136 u8 byPktType
, int bNeedAck
);
138 static u16
s_uGetRTSCTSDuration(struct vnt_private
*pDevice
,
139 u8 byDurType
, u32 cbFrameLength
, u8 byPktType
, u16 wRate
,
140 int bNeedAck
, u8 byFBOption
);
142 static void *s_vGetFreeContext(struct vnt_private
*pDevice
)
144 struct vnt_usb_send_context
*pContext
= NULL
;
145 struct vnt_usb_send_context
*pReturnContext
= NULL
;
148 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GetFreeContext()\n");
150 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
151 if (!pDevice
->apTD
[ii
])
153 pContext
= pDevice
->apTD
[ii
];
154 if (pContext
->bBoolInUse
== false) {
155 pContext
->bBoolInUse
= true;
156 memset(pContext
->Data
, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS
);
157 pReturnContext
= pContext
;
161 if ( ii
== pDevice
->cbTD
) {
162 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Free Tx Context\n");
164 return (void *) pReturnContext
;
167 static void s_vSaveTxPktInfo(struct vnt_private
*pDevice
, u8 byPktNum
,
168 u8
*pbyDestAddr
, u16 wPktLength
, u16 wFIFOCtl
)
170 PSStatCounter pStatistic
= &pDevice
->scStatistic
;
172 if (is_broadcast_ether_addr(pbyDestAddr
))
173 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_BROAD
;
174 else if (is_multicast_ether_addr(pbyDestAddr
))
175 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_MULTI
;
177 pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
= TX_PKT_UNI
;
179 pStatistic
->abyTxPktInfo
[byPktNum
].wLength
= wPktLength
;
180 pStatistic
->abyTxPktInfo
[byPktNum
].wFIFOCtl
= wFIFOCtl
;
181 memcpy(pStatistic
->abyTxPktInfo
[byPktNum
].abyDestAddr
,
186 static void s_vFillTxKey(struct vnt_private
*pDevice
, u8
*pbyBuf
,
187 u8
*pbyIVHead
, PSKeyItem pTransmitKey
, u8
*pbyHdrBuf
,
188 u16 wPayloadLen
, struct vnt_mic_hdr
*mic_hdr
)
190 u32
*pdwIV
= (u32
*)pbyIVHead
;
191 u32
*pdwExtIV
= (u32
*)((u8
*)pbyIVHead
+ 4);
192 struct ieee80211_hdr
*pMACHeader
= (struct ieee80211_hdr
*)pbyHdrBuf
;
196 if (pTransmitKey
== NULL
)
199 dwRevIVCounter
= cpu_to_le32(pDevice
->dwIVCounter
);
200 *pdwIV
= pDevice
->dwIVCounter
;
201 pDevice
->byKeyIndex
= pTransmitKey
->dwKeyIndex
& 0xf;
203 switch (pTransmitKey
->byCipherSuite
) {
205 if (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
) {
206 memcpy(pDevice
->abyPRNG
, (u8
*)&dwRevIVCounter
, 3);
207 memcpy(pDevice
->abyPRNG
+ 3, pTransmitKey
->abyKey
,
208 pTransmitKey
->uKeyLength
);
210 memcpy(pbyBuf
, (u8
*)&dwRevIVCounter
, 3);
211 memcpy(pbyBuf
+ 3, pTransmitKey
->abyKey
,
212 pTransmitKey
->uKeyLength
);
213 if (pTransmitKey
->uKeyLength
== WLAN_WEP40_KEYLEN
) {
214 memcpy(pbyBuf
+8, (u8
*)&dwRevIVCounter
, 3);
215 memcpy(pbyBuf
+11, pTransmitKey
->abyKey
,
216 pTransmitKey
->uKeyLength
);
219 memcpy(pDevice
->abyPRNG
, pbyBuf
, 16);
221 /* Append IV after Mac Header */
222 *pdwIV
&= WEP_IV_MASK
;
223 *pdwIV
|= (u32
)pDevice
->byKeyIndex
<< 30;
224 *pdwIV
= cpu_to_le32(*pdwIV
);
226 pDevice
->dwIVCounter
++;
227 if (pDevice
->dwIVCounter
> WEP_IV_MASK
)
228 pDevice
->dwIVCounter
= 0;
232 pTransmitKey
->wTSC15_0
++;
233 if (pTransmitKey
->wTSC15_0
== 0)
234 pTransmitKey
->dwTSC47_16
++;
236 TKIPvMixKey(pTransmitKey
->abyKey
, pDevice
->abyCurrentNetAddr
,
237 pTransmitKey
->wTSC15_0
, pTransmitKey
->dwTSC47_16
,
239 memcpy(pbyBuf
, pDevice
->abyPRNG
, 16);
242 memcpy(pdwIV
, pDevice
->abyPRNG
, 3);
244 *(pbyIVHead
+3) = (u8
)(((pDevice
->byKeyIndex
<< 6) &
246 /* Append IV&ExtIV after Mac Header */
247 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
249 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
250 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV
);
254 pTransmitKey
->wTSC15_0
++;
255 if (pTransmitKey
->wTSC15_0
== 0)
256 pTransmitKey
->dwTSC47_16
++;
258 memcpy(pbyBuf
, pTransmitKey
->abyKey
, 16);
262 *(pbyIVHead
+3) = (u8
)(((pDevice
->byKeyIndex
<< 6) &
265 *pdwIV
|= cpu_to_le16((u16
)(pTransmitKey
->wTSC15_0
));
267 /* Append IV&ExtIV after Mac Header */
268 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
275 mic_hdr
->payload_len
= cpu_to_be16(wPayloadLen
);
276 memcpy(mic_hdr
->mic_addr2
, pMACHeader
->addr2
, ETH_ALEN
);
278 mic_hdr
->tsc_47_16
= cpu_to_be32(pTransmitKey
->dwTSC47_16
);
279 mic_hdr
->tsc_15_0
= cpu_to_be16(pTransmitKey
->wTSC15_0
);
282 if (pDevice
->bLongHeader
)
283 mic_hdr
->hlen
= cpu_to_be16(28);
285 mic_hdr
->hlen
= cpu_to_be16(22);
287 memcpy(mic_hdr
->addr1
, pMACHeader
->addr1
, ETH_ALEN
);
288 memcpy(mic_hdr
->addr2
, pMACHeader
->addr2
, ETH_ALEN
);
291 memcpy(mic_hdr
->addr3
, pMACHeader
->addr3
, ETH_ALEN
);
292 mic_hdr
->frame_control
= cpu_to_le16(pMACHeader
->frame_control
294 mic_hdr
->seq_ctrl
= cpu_to_le16(pMACHeader
->seq_ctrl
& 0xf);
296 if (pDevice
->bLongHeader
)
297 memcpy(mic_hdr
->addr4
, pMACHeader
->addr4
, ETH_ALEN
);
301 static void s_vSWencryption(struct vnt_private
*pDevice
,
302 PSKeyItem pTransmitKey
, u8
*pbyPayloadHead
, u16 wPayloadSize
)
305 u32 dwICV
= 0xffffffff;
308 if (pTransmitKey
== NULL
)
311 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
312 //=======================================================================
313 // Append ICV after payload
314 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
315 pdwICV
= (u32
*)(pbyPayloadHead
+ wPayloadSize
);
316 // finally, we must invert dwCRC to get the correct answer
317 *pdwICV
= cpu_to_le32(~dwICV
);
319 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pTransmitKey
->uKeyLength
+ 3);
320 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
321 //=======================================================================
322 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
323 //=======================================================================
324 //Append ICV after payload
325 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
326 pdwICV
= (u32
*)(pbyPayloadHead
+ wPayloadSize
);
327 // finally, we must invert dwCRC to get the correct answer
328 *pdwICV
= cpu_to_le32(~dwICV
);
330 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
331 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
332 //=======================================================================
336 static u16
vnt_time_stamp_off(struct vnt_private
*priv
, u16 rate
)
338 return cpu_to_le16(wTimeStampOff
[priv
->byPreambleType
% 2]
342 /*byPktType : PK_TYPE_11A 0
347 static u32
s_uGetTxRsvTime(struct vnt_private
*pDevice
, u8 byPktType
,
348 u32 cbFrameLength
, u16 wRate
, int bNeedAck
)
350 u32 uDataTime
, uAckTime
;
352 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wRate
);
353 if (byPktType
== PK_TYPE_11B
) {//llb,CCK mode
354 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (u16
)pDevice
->byTopCCKBasicRate
);
355 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
356 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (u16
)pDevice
->byTopOFDMBasicRate
);
360 return (uDataTime
+ pDevice
->uSIFS
+ uAckTime
);
367 static u16
vnt_rxtx_rsvtime_le16(struct vnt_private
*priv
, u8 pkt_type
,
368 u32 frame_length
, u16 rate
, int need_ack
)
370 return cpu_to_le16((u16
)s_uGetTxRsvTime(priv
, pkt_type
,
371 frame_length
, rate
, need_ack
));
374 //byFreqType: 0=>5GHZ 1=>2.4GHZ
375 static u16
s_uGetRTSCTSRsvTime(struct vnt_private
*pDevice
,
376 u8 byRTSRsvType
, u8 byPktType
, u32 cbFrameLength
, u16 wCurrentRate
)
378 u32 uRrvTime
, uRTSTime
, uCTSTime
, uAckTime
, uDataTime
;
380 uRrvTime
= uRTSTime
= uCTSTime
= uAckTime
= uDataTime
= 0;
382 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wCurrentRate
);
383 if (byRTSRsvType
== 0) { //RTSTxRrvTime_bb
384 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
385 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
387 else if (byRTSRsvType
== 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
388 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
389 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
390 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
392 else if (byRTSRsvType
== 2) { //RTSTxRrvTime_aa
393 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopOFDMBasicRate
);
394 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
396 else if (byRTSRsvType
== 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
397 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
398 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
399 uRrvTime
= uCTSTime
+ uAckTime
+ uDataTime
+ 2*pDevice
->uSIFS
;
404 uRrvTime
= uRTSTime
+ uCTSTime
+ uAckTime
+ uDataTime
+ 3*pDevice
->uSIFS
;
405 return cpu_to_le16((u16
)uRrvTime
);
408 //byFreqType 0: 5GHz, 1:2.4Ghz
409 static u16
s_uGetDataDuration(struct vnt_private
*pDevice
,
410 u8 byPktType
, int bNeedAck
)
415 if (byPktType
== PK_TYPE_11B
)
416 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
,
417 byPktType
, 14, pDevice
->byTopCCKBasicRate
);
419 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
,
420 byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
421 return cpu_to_le16((u16
)(pDevice
->uSIFS
+ uAckTime
));
427 //byFreqType: 0=>5GHZ 1=>2.4GHZ
428 static u16
s_uGetRTSCTSDuration(struct vnt_private
*pDevice
, u8 byDurType
,
429 u32 cbFrameLength
, u8 byPktType
, u16 wRate
, int bNeedAck
,
432 u32 uCTSTime
= 0, uDurTime
= 0;
436 case RTSDUR_BB
: //RTSDuration_bb
437 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
438 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
441 case RTSDUR_BA
: //RTSDuration_ba
442 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
443 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
446 case RTSDUR_AA
: //RTSDuration_aa
447 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
448 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
451 case CTSDUR_BA
: //CTSDuration_ba
452 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wRate
, bNeedAck
);
455 case RTSDUR_BA_F0
: //RTSDuration_ba_f0
456 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
457 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
458 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
459 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
460 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
464 case RTSDUR_AA_F0
: //RTSDuration_aa_f0
465 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
466 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
467 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
468 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
469 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
473 case RTSDUR_BA_F1
: //RTSDuration_ba_f1
474 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
475 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
476 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
477 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
478 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
482 case RTSDUR_AA_F1
: //RTSDuration_aa_f1
483 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
484 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
485 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
486 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
487 uDurTime
= uCTSTime
+ 2*pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
491 case CTSDUR_BA_F0
: //CTSDuration_ba_f0
492 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
493 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
494 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
495 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE0
][wRate
-RATE_18M
], bNeedAck
);
499 case CTSDUR_BA_F1
: //CTSDuration_ba_f1
500 if ((byFBOption
== AUTO_FB_0
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
501 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt0
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
502 } else if ((byFBOption
== AUTO_FB_1
) && (wRate
>= RATE_18M
) && (wRate
<=RATE_54M
)) {
503 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
, byPktType
, cbFrameLength
, wFB_Opt1
[FB_RATE1
][wRate
-RATE_18M
], bNeedAck
);
511 return cpu_to_le16((u16
)uDurTime
);
514 static u32
s_uFillDataHead(struct vnt_private
*pDevice
,
515 u8 byPktType
, u16 wCurrentRate
, void *pTxDataHead
, u32 cbFrameLength
,
516 u32 uDMAIdx
, int bNeedAck
, u8 byFBOption
)
519 if (pTxDataHead
== NULL
) {
523 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
524 if (byFBOption
== AUTO_FB_NONE
) {
525 struct vnt_tx_datahead_g
*pBuf
=
526 (struct vnt_tx_datahead_g
*)pTxDataHead
;
527 //Get SignalField,ServiceField,Length
528 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
,
529 byPktType
, &pBuf
->a
);
530 BBvCalculateParameter(pDevice
, cbFrameLength
,
531 pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
, &pBuf
->b
);
532 //Get Duration and TimeStamp
533 pBuf
->wDuration_a
= s_uGetDataDuration(pDevice
,
534 byPktType
, bNeedAck
);
535 pBuf
->wDuration_b
= s_uGetDataDuration(pDevice
,
536 PK_TYPE_11B
, bNeedAck
);
538 pBuf
->wTimeStampOff_a
= vnt_time_stamp_off(pDevice
,
540 pBuf
->wTimeStampOff_b
= vnt_time_stamp_off(pDevice
,
541 pDevice
->byTopCCKBasicRate
);
542 return (pBuf
->wDuration_a
);
545 struct vnt_tx_datahead_g_fb
*pBuf
=
546 (struct vnt_tx_datahead_g_fb
*)pTxDataHead
;
547 //Get SignalField,ServiceField,Length
548 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
,
549 byPktType
, &pBuf
->a
);
550 BBvCalculateParameter(pDevice
, cbFrameLength
,
551 pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
, &pBuf
->b
);
552 //Get Duration and TimeStamp
553 pBuf
->wDuration_a
= s_uGetDataDuration(pDevice
,
554 byPktType
, bNeedAck
);
555 pBuf
->wDuration_b
= s_uGetDataDuration(pDevice
,
556 PK_TYPE_11B
, bNeedAck
);
557 pBuf
->wDuration_a_f0
= s_uGetDataDuration(pDevice
,
558 byPktType
, bNeedAck
);
559 pBuf
->wDuration_a_f1
= s_uGetDataDuration(pDevice
,
560 byPktType
, bNeedAck
);
561 pBuf
->wTimeStampOff_a
= vnt_time_stamp_off(pDevice
,
563 pBuf
->wTimeStampOff_b
= vnt_time_stamp_off(pDevice
,
564 pDevice
->byTopCCKBasicRate
);
565 return (pBuf
->wDuration_a
);
566 } //if (byFBOption == AUTO_FB_NONE)
568 else if (byPktType
== PK_TYPE_11A
) {
569 if (byFBOption
!= AUTO_FB_NONE
) {
570 struct vnt_tx_datahead_a_fb
*pBuf
=
571 (struct vnt_tx_datahead_a_fb
*)pTxDataHead
;
572 //Get SignalField,ServiceField,Length
573 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
,
574 byPktType
, &pBuf
->a
);
575 //Get Duration and TimeStampOff
576 pBuf
->wDuration
= s_uGetDataDuration(pDevice
,
577 byPktType
, bNeedAck
);
578 pBuf
->wDuration_f0
= s_uGetDataDuration(pDevice
,
579 byPktType
, bNeedAck
);
580 pBuf
->wDuration_f1
= s_uGetDataDuration(pDevice
,
581 byPktType
, bNeedAck
);
582 pBuf
->wTimeStampOff
= vnt_time_stamp_off(pDevice
,
584 return (pBuf
->wDuration
);
586 struct vnt_tx_datahead_ab
*pBuf
=
587 (struct vnt_tx_datahead_ab
*)pTxDataHead
;
588 //Get SignalField,ServiceField,Length
589 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
,
590 byPktType
, &pBuf
->ab
);
591 //Get Duration and TimeStampOff
592 pBuf
->wDuration
= s_uGetDataDuration(pDevice
,
593 byPktType
, bNeedAck
);
594 pBuf
->wTimeStampOff
= vnt_time_stamp_off(pDevice
,
596 return (pBuf
->wDuration
);
599 else if (byPktType
== PK_TYPE_11B
) {
600 struct vnt_tx_datahead_ab
*pBuf
=
601 (struct vnt_tx_datahead_ab
*)pTxDataHead
;
602 //Get SignalField,ServiceField,Length
603 BBvCalculateParameter(pDevice
, cbFrameLength
, wCurrentRate
,
604 byPktType
, &pBuf
->ab
);
605 //Get Duration and TimeStampOff
606 pBuf
->wDuration
= s_uGetDataDuration(pDevice
,
607 byPktType
, bNeedAck
);
608 pBuf
->wTimeStampOff
= vnt_time_stamp_off(pDevice
,
610 return (pBuf
->wDuration
);
615 static int vnt_fill_ieee80211_rts(struct vnt_private
*priv
,
616 struct ieee80211_rts
*rts
, struct ethhdr
*eth_hdr
,
619 rts
->duration
= duration
;
620 rts
->frame_control
= TYPE_CTL_RTS
;
622 if (priv
->eOPMode
== OP_MODE_ADHOC
|| priv
->eOPMode
== OP_MODE_AP
)
623 memcpy(rts
->ra
, eth_hdr
->h_dest
, ETH_ALEN
);
625 memcpy(rts
->ra
, priv
->abyBSSID
, ETH_ALEN
);
627 if (priv
->eOPMode
== OP_MODE_AP
)
628 memcpy(rts
->ta
, priv
->abyBSSID
, ETH_ALEN
);
630 memcpy(rts
->ta
, eth_hdr
->h_source
, ETH_ALEN
);
635 static int vnt_rxtx_rts_g_head(struct vnt_private
*priv
,
636 struct vnt_rts_g
*buf
, struct ethhdr
*eth_hdr
,
637 u8 pkt_type
, u32 frame_len
, int need_ack
,
638 u16 current_rate
, u8 fb_option
)
640 u16 rts_frame_len
= 20;
642 BBvCalculateParameter(priv
, rts_frame_len
, priv
->byTopCCKBasicRate
,
643 PK_TYPE_11B
, &buf
->b
);
644 BBvCalculateParameter(priv
, rts_frame_len
,
645 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->a
);
647 buf
->wDuration_bb
= s_uGetRTSCTSDuration(priv
, RTSDUR_BB
, frame_len
,
648 PK_TYPE_11B
, priv
->byTopCCKBasicRate
, need_ack
, fb_option
);
649 buf
->wDuration_aa
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
650 pkt_type
, current_rate
, need_ack
, fb_option
);
651 buf
->wDuration_ba
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA
, frame_len
,
652 pkt_type
, current_rate
, need_ack
, fb_option
);
654 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration_aa
);
659 static int vnt_rxtx_rts_g_fb_head(struct vnt_private
*priv
,
660 struct vnt_rts_g_fb
*buf
, struct ethhdr
*eth_hdr
,
661 u8 pkt_type
, u32 frame_len
, int need_ack
,
662 u16 current_rate
, u8 fb_option
)
664 u16 rts_frame_len
= 20;
666 BBvCalculateParameter(priv
, rts_frame_len
, priv
->byTopCCKBasicRate
,
667 PK_TYPE_11B
, &buf
->b
);
668 BBvCalculateParameter(priv
, rts_frame_len
,
669 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->a
);
672 buf
->wDuration_bb
= s_uGetRTSCTSDuration(priv
, RTSDUR_BB
, frame_len
,
673 PK_TYPE_11B
, priv
->byTopCCKBasicRate
, need_ack
, fb_option
);
674 buf
->wDuration_aa
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
675 pkt_type
, current_rate
, need_ack
, fb_option
);
676 buf
->wDuration_ba
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA
, frame_len
,
677 pkt_type
, current_rate
, need_ack
, fb_option
);
680 buf
->wRTSDuration_ba_f0
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA_F0
,
681 frame_len
, pkt_type
, current_rate
, need_ack
, fb_option
);
682 buf
->wRTSDuration_aa_f0
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F0
,
683 frame_len
, pkt_type
, current_rate
, need_ack
, fb_option
);
684 buf
->wRTSDuration_ba_f1
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA_F1
,
685 frame_len
, pkt_type
, current_rate
, need_ack
, fb_option
);
686 buf
->wRTSDuration_aa_f1
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F1
,
687 frame_len
, pkt_type
, current_rate
, need_ack
, fb_option
);
689 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration_aa
);
694 static int vnt_rxtx_rts_ab_head(struct vnt_private
*priv
,
695 struct vnt_rts_ab
*buf
, struct ethhdr
*eth_hdr
,
696 u8 pkt_type
, u32 frame_len
, int need_ack
,
697 u16 current_rate
, u8 fb_option
)
699 u16 rts_frame_len
= 20;
701 BBvCalculateParameter(priv
, rts_frame_len
,
702 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->ab
);
704 buf
->wDuration
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
705 pkt_type
, current_rate
, need_ack
, fb_option
);
707 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration
);
712 static int vnt_rxtx_rts_a_fb_head(struct vnt_private
*priv
,
713 struct vnt_rts_a_fb
*buf
, struct ethhdr
*eth_hdr
,
714 u8 pkt_type
, u32 frame_len
, int need_ack
,
715 u16 current_rate
, u8 fb_option
)
717 u16 rts_frame_len
= 20;
719 BBvCalculateParameter(priv
, rts_frame_len
,
720 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->a
);
722 buf
->wDuration
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
723 pkt_type
, current_rate
, need_ack
, fb_option
);
725 buf
->wRTSDuration_f0
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F0
,
726 frame_len
, pkt_type
, current_rate
, need_ack
, fb_option
);
728 buf
->wRTSDuration_f1
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F1
,
729 frame_len
, pkt_type
, current_rate
, need_ack
, fb_option
);
731 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration
);
736 static void s_vFillRTSHead(struct vnt_private
*pDevice
, u8 byPktType
,
737 union vnt_tx_data_head
*head
, u32 cbFrameLength
, int bNeedAck
,
738 struct ethhdr
*psEthHeader
, u16 wCurrentRate
, u8 byFBOption
)
744 /* Note: So far RTSHead doesn't appear in ATIM
745 * & Beacom DMA, so we don't need to take them
747 * Otherwise, we need to modified codes for them.
752 if (byFBOption
== AUTO_FB_NONE
)
753 vnt_rxtx_rts_g_head(pDevice
, &head
->rts_g
,
754 psEthHeader
, byPktType
, cbFrameLength
,
755 bNeedAck
, wCurrentRate
, byFBOption
);
757 vnt_rxtx_rts_g_fb_head(pDevice
, &head
->rts_g_fb
,
758 psEthHeader
, byPktType
, cbFrameLength
,
759 bNeedAck
, wCurrentRate
, byFBOption
);
763 vnt_rxtx_rts_a_fb_head(pDevice
, &head
->rts_a_fb
,
764 psEthHeader
, byPktType
, cbFrameLength
,
765 bNeedAck
, wCurrentRate
, byFBOption
);
769 vnt_rxtx_rts_ab_head(pDevice
, &head
->rts_ab
,
770 psEthHeader
, byPktType
, cbFrameLength
,
771 bNeedAck
, wCurrentRate
, byFBOption
);
775 static void s_vFillCTSHead(struct vnt_private
*pDevice
, u32 uDMAIdx
,
776 u8 byPktType
, union vnt_tx_data_head
*head
, u32 cbFrameLength
,
777 int bNeedAck
, u16 wCurrentRate
, u8 byFBOption
)
779 u32 uCTSFrameLen
= 14;
784 if (byFBOption
!= AUTO_FB_NONE
) {
786 struct vnt_cts_fb
*pBuf
= &head
->cts_g_fb
;
787 /* Get SignalField,ServiceField,Length */
788 BBvCalculateParameter(pDevice
, uCTSFrameLen
,
789 pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
, &pBuf
->b
);
790 pBuf
->wDuration_ba
= s_uGetRTSCTSDuration(pDevice
, CTSDUR_BA
,
791 cbFrameLength
, byPktType
,
792 wCurrentRate
, bNeedAck
, byFBOption
);
793 /* Get CTSDuration_ba_f0 */
794 pBuf
->wCTSDuration_ba_f0
= s_uGetRTSCTSDuration(pDevice
,
795 CTSDUR_BA_F0
, cbFrameLength
, byPktType
, wCurrentRate
,
796 bNeedAck
, byFBOption
);
797 /* Get CTSDuration_ba_f1 */
798 pBuf
->wCTSDuration_ba_f1
= s_uGetRTSCTSDuration(pDevice
,
799 CTSDUR_BA_F1
, cbFrameLength
, byPktType
, wCurrentRate
,
800 bNeedAck
, byFBOption
);
801 /* Get CTS Frame body */
802 pBuf
->data
.duration
= pBuf
->wDuration_ba
;
803 pBuf
->data
.frame_control
= TYPE_CTL_CTS
;
804 memcpy(pBuf
->data
.ra
, pDevice
->abyCurrentNetAddr
, ETH_ALEN
);
806 struct vnt_cts
*pBuf
= &head
->cts_g
;
807 /* Get SignalField,ServiceField,Length */
808 BBvCalculateParameter(pDevice
, uCTSFrameLen
,
809 pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
, &pBuf
->b
);
810 /* Get CTSDuration_ba */
811 pBuf
->wDuration_ba
= s_uGetRTSCTSDuration(pDevice
,
812 CTSDUR_BA
, cbFrameLength
, byPktType
,
813 wCurrentRate
, bNeedAck
, byFBOption
);
814 /*Get CTS Frame body*/
815 pBuf
->data
.duration
= pBuf
->wDuration_ba
;
816 pBuf
->data
.frame_control
= TYPE_CTL_CTS
;
817 memcpy(pBuf
->data
.ra
, pDevice
->abyCurrentNetAddr
, ETH_ALEN
);
824 * Generate FIFO control for MAC & Baseband controller
828 * pDevice - Pointer to adpater
829 * pTxDataHead - Transmit Data Buffer
830 * pTxBufHead - pTxBufHead
831 * pvRrvTime - pvRrvTime
834 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
835 * bNeedACK - If need ACK
836 * uDMAIdx - DMA Index
844 static void s_vGenerateTxParameter(struct vnt_private
*pDevice
,
845 u8 byPktType
, u16 wCurrentRate
, void *pTxBufHead
, void *pvRrvTime
,
846 void *rts_cts
, u32 cbFrameSize
, int bNeedACK
, u32 uDMAIdx
,
847 struct ethhdr
*psEthHeader
, bool need_rts
)
849 union vnt_tx_data_head
*head
= rts_cts
;
850 u32 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
; /* 24 */
852 u8 byFBOption
= AUTO_FB_NONE
;
854 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
855 PSTxBufHead pFifoHead
= (PSTxBufHead
)pTxBufHead
;
856 pFifoHead
->wReserved
= wCurrentRate
;
857 wFifoCtl
= pFifoHead
->wFIFOCtl
;
859 if (wFifoCtl
& FIFOCTL_AUTO_FB_0
) {
860 byFBOption
= AUTO_FB_0
;
862 else if (wFifoCtl
& FIFOCTL_AUTO_FB_1
) {
863 byFBOption
= AUTO_FB_1
;
869 if (pDevice
->bLongHeader
)
870 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
872 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
875 struct vnt_rrv_time_rts
*pBuf
=
876 (struct vnt_rrv_time_rts
*)pvRrvTime
;
877 pBuf
->wRTSTxRrvTime_aa
= s_uGetRTSCTSRsvTime(pDevice
, 2,
878 byPktType
, cbFrameSize
, wCurrentRate
);
879 pBuf
->wRTSTxRrvTime_ba
= s_uGetRTSCTSRsvTime(pDevice
, 1,
880 byPktType
, cbFrameSize
, wCurrentRate
);
881 pBuf
->wRTSTxRrvTime_bb
= s_uGetRTSCTSRsvTime(pDevice
, 0,
882 byPktType
, cbFrameSize
, wCurrentRate
);
883 pBuf
->wTxRrvTime_a
= vnt_rxtx_rsvtime_le16(pDevice
,
884 byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
);
885 pBuf
->wTxRrvTime_b
= vnt_rxtx_rsvtime_le16(pDevice
,
886 PK_TYPE_11B
, cbFrameSize
, pDevice
->byTopCCKBasicRate
,
889 s_vFillRTSHead(pDevice
, byPktType
, head
, cbFrameSize
,
890 bNeedACK
, psEthHeader
, wCurrentRate
, byFBOption
);
892 else {//RTS_needless, PCF mode
894 struct vnt_rrv_time_cts
*pBuf
=
895 (struct vnt_rrv_time_cts
*)pvRrvTime
;
896 pBuf
->wTxRrvTime_a
= vnt_rxtx_rsvtime_le16(pDevice
, byPktType
,
897 cbFrameSize
, wCurrentRate
, bNeedACK
);
898 pBuf
->wTxRrvTime_b
= vnt_rxtx_rsvtime_le16(pDevice
,
899 PK_TYPE_11B
, cbFrameSize
,
900 pDevice
->byTopCCKBasicRate
, bNeedACK
);
901 pBuf
->wCTSTxRrvTime_ba
= s_uGetRTSCTSRsvTime(pDevice
, 3,
902 byPktType
, cbFrameSize
, wCurrentRate
);
904 s_vFillCTSHead(pDevice
, uDMAIdx
, byPktType
, head
,
905 cbFrameSize
, bNeedACK
, wCurrentRate
, byFBOption
);
908 else if (byPktType
== PK_TYPE_11A
) {
911 struct vnt_rrv_time_ab
*pBuf
=
912 (struct vnt_rrv_time_ab
*)pvRrvTime
;
913 pBuf
->wRTSTxRrvTime
= s_uGetRTSCTSRsvTime(pDevice
, 2,
914 byPktType
, cbFrameSize
, wCurrentRate
);
915 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
, byPktType
,
916 cbFrameSize
, wCurrentRate
, bNeedACK
);
918 s_vFillRTSHead(pDevice
, byPktType
, head
, cbFrameSize
,
919 bNeedACK
, psEthHeader
, wCurrentRate
, byFBOption
);
922 struct vnt_rrv_time_ab
*pBuf
=
923 (struct vnt_rrv_time_ab
*)pvRrvTime
;
924 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
, PK_TYPE_11A
,
925 cbFrameSize
, wCurrentRate
, bNeedACK
);
928 else if (byPktType
== PK_TYPE_11B
) {
931 struct vnt_rrv_time_ab
*pBuf
=
932 (struct vnt_rrv_time_ab
*)pvRrvTime
;
933 pBuf
->wRTSTxRrvTime
= s_uGetRTSCTSRsvTime(pDevice
, 0,
934 byPktType
, cbFrameSize
, wCurrentRate
);
935 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
, PK_TYPE_11B
,
936 cbFrameSize
, wCurrentRate
, bNeedACK
);
938 s_vFillRTSHead(pDevice
, byPktType
, head
, cbFrameSize
,
939 bNeedACK
, psEthHeader
, wCurrentRate
, byFBOption
);
941 else { //RTS_needless, non PCF mode
943 struct vnt_rrv_time_ab
*pBuf
=
944 (struct vnt_rrv_time_ab
*)pvRrvTime
;
945 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
, PK_TYPE_11B
,
946 cbFrameSize
, wCurrentRate
, bNeedACK
);
949 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
952 u8 * pbyBuffer,//point to pTxBufHead
953 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
954 unsigned int cbFragmentSize,//Hdr+payoad+FCS
957 static int s_bPacketToWirelessUsb(struct vnt_private
*pDevice
, u8 byPktType
,
958 struct vnt_tx_buffer
*pTxBufHead
, int bNeedEncryption
,
959 u32 uSkbPacketLen
, u32 uDMAIdx
, struct ethhdr
*psEthHeader
,
960 u8
*pPacket
, PSKeyItem pTransmitKey
, u32 uNodeIndex
, u16 wCurrentRate
,
961 u32
*pcbHeaderLen
, u32
*pcbTotalLen
)
963 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
964 u32 cbFrameSize
, cbFrameBodySize
;
966 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbMACHdLen
= 0;
967 u32 cbFCSlen
= 4, cbMICHDR
= 0;
970 u8
*pbyType
, *pbyMacHdr
, *pbyIVHead
, *pbyPayloadHead
, *pbyTxBufferAddr
;
971 u8 abySNAP_RFC1042
[ETH_ALEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
972 u8 abySNAP_Bridgetunnel
[ETH_ALEN
]
973 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
975 u32 cbHeaderLength
= 0, uPadding
= 0;
977 struct vnt_mic_hdr
*pMICHDR
;
978 void *rts_cts
= NULL
;
980 u8 byFBOption
= AUTO_FB_NONE
, byFragType
;
982 u32 dwMICKey0
, dwMICKey1
, dwMIC_Priority
;
983 u32
*pdwMIC_L
, *pdwMIC_R
;
984 int bSoftWEP
= false;
986 pvRrvTime
= pMICHDR
= pvTxDataHd
= NULL
;
988 if (bNeedEncryption
&& pTransmitKey
->pvKeyTable
) {
989 if (((PSKeyTable
)pTransmitKey
->pvKeyTable
)->bSoftWEP
== true)
990 bSoftWEP
= true; /* WEP 256 */
994 if (ntohs(psEthHeader
->h_proto
) > ETH_DATA_LEN
) {
995 if (pDevice
->dwDiagRefCount
== 0) {
1004 cbFrameBodySize
= uSkbPacketLen
- ETH_HLEN
+ cb802_1_H_len
;
1007 pTxBufHead
->wFIFOCtl
|= (u16
)(byPktType
<<8);
1009 if (pDevice
->dwDiagRefCount
!= 0) {
1011 pTxBufHead
->wFIFOCtl
= pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1012 } else { //if (pDevice->dwDiagRefCount != 0) {
1013 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
1014 (pDevice
->eOPMode
== OP_MODE_AP
)) {
1015 if (is_multicast_ether_addr(psEthHeader
->h_dest
)) {
1017 pTxBufHead
->wFIFOCtl
=
1018 pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1021 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1025 // MSDUs in Infra mode always need ACK
1027 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1029 } //if (pDevice->dwDiagRefCount != 0) {
1031 pTxBufHead
->wTimeStamp
= DEFAULT_MSDU_LIFETIME_RES_64us
;
1034 if (pDevice
->bLongHeader
)
1035 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LHEAD
;
1037 //Set FRAGCTL_MACHDCNT
1038 if (pDevice
->bLongHeader
) {
1039 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
+ 6;
1041 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
;
1043 pTxBufHead
->wFragCtl
|= (u16
)(cbMACHdLen
<< 10);
1045 //Set FIFOCTL_GrpAckPolicy
1046 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1047 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1050 //Set Auto Fallback Ctl
1051 if (wCurrentRate
>= RATE_18M
) {
1052 if (pDevice
->byAutoFBCtrl
== AUTO_FB_0
) {
1053 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_0
;
1054 byFBOption
= AUTO_FB_0
;
1055 } else if (pDevice
->byAutoFBCtrl
== AUTO_FB_1
) {
1056 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_1
;
1057 byFBOption
= AUTO_FB_1
;
1061 if (bSoftWEP
!= true) {
1062 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) { //WEP enabled
1063 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) { //WEP40 or WEP104
1064 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1066 if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1067 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1068 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1070 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) { //CCMP
1071 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1076 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) {
1077 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
1081 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1082 cbIVlen
= 8;//IV+ExtIV
1086 if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
1087 cbIVlen
= 8;//RSN Header
1089 cbMICHDR
= sizeof(struct vnt_mic_hdr
);
1091 if (bSoftWEP
== false) {
1092 //MAC Header should be padding 0 to DW alignment.
1093 uPadding
= 4 - (cbMACHdLen
%4);
1098 cbFrameSize
= cbMACHdLen
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbICVlen
+ cbFCSlen
;
1100 if ( (bNeedACK
== false) ||(cbFrameSize
< pDevice
->wRTSThreshold
) ) {
1104 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_RTS
| FIFOCTL_LRETRY
);
1107 pbyTxBufferAddr
= (u8
*) &(pTxBufHead
->adwTxKey
[0]);
1108 wTxBufSize
= sizeof(STxBufHead
);
1109 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1110 if (byFBOption
== AUTO_FB_NONE
) {
1111 if (bRTS
== true) {//RTS_need
1112 pvRrvTime
= (struct vnt_rrv_time_rts
*)
1113 (pbyTxBufferAddr
+ wTxBufSize
);
1114 pMICHDR
= (struct vnt_mic_hdr
*)(pbyTxBufferAddr
+ wTxBufSize
+
1115 sizeof(struct vnt_rrv_time_rts
));
1116 rts_cts
= (struct vnt_rts_g
*) (pbyTxBufferAddr
+ wTxBufSize
+
1117 sizeof(struct vnt_rrv_time_rts
) + cbMICHDR
);
1118 pvTxDataHd
= (struct vnt_tx_datahead_g
*) (pbyTxBufferAddr
+
1119 wTxBufSize
+ sizeof(struct vnt_rrv_time_rts
) +
1120 cbMICHDR
+ sizeof(struct vnt_rts_g
));
1121 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_rts
) +
1122 cbMICHDR
+ sizeof(struct vnt_rts_g
) +
1123 sizeof(struct vnt_tx_datahead_g
);
1125 else { //RTS_needless
1126 pvRrvTime
= (struct vnt_rrv_time_cts
*)
1127 (pbyTxBufferAddr
+ wTxBufSize
);
1128 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
1129 sizeof(struct vnt_rrv_time_cts
));
1130 rts_cts
= (struct vnt_cts
*) (pbyTxBufferAddr
+ wTxBufSize
+
1131 sizeof(struct vnt_rrv_time_cts
) + cbMICHDR
);
1132 pvTxDataHd
= (struct vnt_tx_datahead_g
*)(pbyTxBufferAddr
+
1133 wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1134 cbMICHDR
+ sizeof(struct vnt_cts
));
1135 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1136 cbMICHDR
+ sizeof(struct vnt_cts
) +
1137 sizeof(struct vnt_tx_datahead_g
);
1141 if (bRTS
== true) {//RTS_need
1142 pvRrvTime
= (struct vnt_rrv_time_rts
*)(pbyTxBufferAddr
+
1144 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
1145 sizeof(struct vnt_rrv_time_rts
));
1146 rts_cts
= (struct vnt_rts_g_fb
*)(pbyTxBufferAddr
+ wTxBufSize
+
1147 sizeof(struct vnt_rrv_time_rts
) + cbMICHDR
);
1148 pvTxDataHd
= (struct vnt_tx_datahead_g_fb
*) (pbyTxBufferAddr
+
1149 wTxBufSize
+ sizeof(struct vnt_rrv_time_rts
) +
1150 cbMICHDR
+ sizeof(struct vnt_rts_g_fb
));
1151 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_rts
) +
1152 cbMICHDR
+ sizeof(struct vnt_rts_g_fb
) +
1153 sizeof(struct vnt_tx_datahead_g_fb
);
1155 else if (bRTS
== false) { //RTS_needless
1156 pvRrvTime
= (struct vnt_rrv_time_cts
*)
1157 (pbyTxBufferAddr
+ wTxBufSize
);
1158 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
1159 sizeof(struct vnt_rrv_time_cts
));
1160 rts_cts
= (struct vnt_cts_fb
*) (pbyTxBufferAddr
+ wTxBufSize
+
1161 sizeof(struct vnt_rrv_time_cts
) + cbMICHDR
);
1162 pvTxDataHd
= (struct vnt_tx_datahead_g_fb
*) (pbyTxBufferAddr
+
1163 wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1164 cbMICHDR
+ sizeof(struct vnt_cts_fb
));
1165 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1166 cbMICHDR
+ sizeof(struct vnt_cts_fb
) +
1167 sizeof(struct vnt_tx_datahead_g_fb
);
1171 else {//802.11a/b packet
1172 if (byFBOption
== AUTO_FB_NONE
) {
1173 if (bRTS
== true) {//RTS_need
1174 pvRrvTime
= (struct vnt_rrv_time_ab
*) (pbyTxBufferAddr
+
1176 pMICHDR
= (struct vnt_mic_hdr
*)(pbyTxBufferAddr
+ wTxBufSize
+
1177 sizeof(struct vnt_rrv_time_ab
));
1178 rts_cts
= (struct vnt_rts_ab
*) (pbyTxBufferAddr
+ wTxBufSize
+
1179 sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
);
1180 pvTxDataHd
= (struct vnt_tx_datahead_ab
*)(pbyTxBufferAddr
+
1181 wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
+
1182 sizeof(struct vnt_rts_ab
));
1183 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1184 cbMICHDR
+ sizeof(struct vnt_rts_ab
) +
1185 sizeof(struct vnt_tx_datahead_ab
);
1187 else if (bRTS
== false) { //RTS_needless, no MICHDR
1188 pvRrvTime
= (struct vnt_rrv_time_ab
*)(pbyTxBufferAddr
+
1190 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
1191 sizeof(struct vnt_rrv_time_ab
));
1192 pvTxDataHd
= (struct vnt_tx_datahead_ab
*)(pbyTxBufferAddr
+
1193 wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
);
1194 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1195 cbMICHDR
+ sizeof(struct vnt_tx_datahead_ab
);
1199 if (bRTS
== true) {//RTS_need
1200 pvRrvTime
= (struct vnt_rrv_time_ab
*)(pbyTxBufferAddr
+
1202 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
1203 sizeof(struct vnt_rrv_time_ab
));
1204 rts_cts
= (struct vnt_rts_a_fb
*)(pbyTxBufferAddr
+ wTxBufSize
+
1205 sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
);
1206 pvTxDataHd
= (struct vnt_tx_datahead_a_fb
*)(pbyTxBufferAddr
+
1207 wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
+
1208 sizeof(struct vnt_rts_a_fb
));
1209 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1210 cbMICHDR
+ sizeof(struct vnt_rts_a_fb
) +
1211 sizeof(struct vnt_tx_datahead_a_fb
);
1213 else if (bRTS
== false) { //RTS_needless
1214 pvRrvTime
= (struct vnt_rrv_time_ab
*)(pbyTxBufferAddr
+
1216 pMICHDR
= (struct vnt_mic_hdr
*)(pbyTxBufferAddr
+ wTxBufSize
+
1217 sizeof(struct vnt_rrv_time_ab
));
1218 pvTxDataHd
= (struct vnt_tx_datahead_a_fb
*)(pbyTxBufferAddr
+
1219 wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
);
1220 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1221 cbMICHDR
+ sizeof(struct vnt_tx_datahead_a_fb
);
1226 pbyMacHdr
= (u8
*)(pbyTxBufferAddr
+ cbHeaderLength
);
1227 pbyIVHead
= (u8
*)(pbyMacHdr
+ cbMACHdLen
+ uPadding
);
1228 pbyPayloadHead
= (u8
*)(pbyMacHdr
+ cbMACHdLen
+ uPadding
+ cbIVlen
);
1230 //=========================
1232 //=========================
1233 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Fragmentation...\n");
1234 byFragType
= FRAGCTL_NONFRAG
;
1235 //uDMAIdx = TYPE_AC0DMA;
1236 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1238 //Fill FIFO,RrvTime,RTS,and CTS
1239 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
1240 (void *)pbyTxBufferAddr
, pvRrvTime
, rts_cts
,
1241 cbFrameSize
, bNeedACK
, uDMAIdx
, psEthHeader
, bRTS
);
1243 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, uDMAIdx
, bNeedACK
,
1245 // Generate TX MAC Header
1246 s_vGenerateMACHeader(pDevice
, pbyMacHdr
, (u16
)uDuration
, psEthHeader
, bNeedEncryption
,
1247 byFragType
, uDMAIdx
, 0);
1249 if (bNeedEncryption
== true) {
1251 s_vFillTxKey(pDevice
, (u8
*)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1252 pbyMacHdr
, (u16
)cbFrameBodySize
, pMICHDR
);
1254 if (pDevice
->bEnableHostWEP
) {
1255 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1256 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1261 if (ntohs(psEthHeader
->h_proto
) > ETH_DATA_LEN
) {
1262 if (pDevice
->dwDiagRefCount
== 0) {
1263 if ((psEthHeader
->h_proto
== cpu_to_be16(ETH_P_IPX
)) ||
1264 (psEthHeader
->h_proto
== cpu_to_le16(0xF380))) {
1265 memcpy((u8
*) (pbyPayloadHead
),
1266 abySNAP_Bridgetunnel
, 6);
1268 memcpy((u8
*) (pbyPayloadHead
), &abySNAP_RFC1042
[0], 6);
1270 pbyType
= (u8
*) (pbyPayloadHead
+ 6);
1271 memcpy(pbyType
, &(psEthHeader
->h_proto
), sizeof(u16
));
1273 memcpy((u8
*) (pbyPayloadHead
), &(psEthHeader
->h_proto
), sizeof(u16
));
1279 if (pPacket
!= NULL
) {
1280 // Copy the Packet into a tx Buffer
1281 memcpy((pbyPayloadHead
+ cb802_1_H_len
),
1282 (pPacket
+ ETH_HLEN
),
1283 uSkbPacketLen
- ETH_HLEN
1287 // while bRelayPacketSend psEthHeader is point to header+payload
1288 memcpy((pbyPayloadHead
+ cb802_1_H_len
), ((u8
*)psEthHeader
) + ETH_HLEN
, uSkbPacketLen
- ETH_HLEN
);
1291 if ((bNeedEncryption
== true) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1293 ///////////////////////////////////////////////////////////////////
1295 if (pDevice
->vnt_mgmt
.eAuthenMode
== WMAC_AUTH_WPANONE
) {
1296 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
1297 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
1299 else if ((pTransmitKey
->dwKeyIndex
& AUTHENTICATOR_KEY
) != 0) {
1300 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
1301 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
1304 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[24]);
1305 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[28]);
1307 // DO Software Michael
1308 MIC_vInit(dwMICKey0
, dwMICKey1
);
1309 MIC_vAppend((u8
*)&(psEthHeader
->h_dest
[0]), 12);
1311 MIC_vAppend((u8
*)&dwMIC_Priority
, 4);
1312 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC KEY: %X, %X\n",
1313 dwMICKey0
, dwMICKey1
);
1315 ///////////////////////////////////////////////////////////////////
1317 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1318 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1319 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
1321 //DBG_PRN_GRP12(("\n\n\n"));
1323 MIC_vAppend(pbyPayloadHead
, cbFrameBodySize
);
1325 pdwMIC_L
= (u32
*)(pbyPayloadHead
+ cbFrameBodySize
);
1326 pdwMIC_R
= (u32
*)(pbyPayloadHead
+ cbFrameBodySize
+ 4);
1328 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1331 if (pDevice
->bTxMICFail
== true) {
1334 pDevice
->bTxMICFail
= false;
1336 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1337 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1338 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1341 if (bSoftWEP
== true) {
1343 s_vSWencryption(pDevice
, pTransmitKey
, (pbyPayloadHead
), (u16
)(cbFrameBodySize
+ cbMIClen
));
1345 } else if ( ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) && (bNeedEncryption
== true)) ||
1346 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) && (bNeedEncryption
== true)) ||
1347 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) && (bNeedEncryption
== true)) ) {
1348 cbFrameSize
-= cbICVlen
;
1351 cbFrameSize
-= cbFCSlen
;
1353 *pcbHeaderLen
= cbHeaderLength
;
1354 *pcbTotalLen
= cbHeaderLength
+ cbFrameSize
;
1356 //Set FragCtl in TxBufferHead
1357 pTxBufHead
->wFragCtl
|= (u16
)byFragType
;
1366 * Translate 802.3 to 802.11 header
1370 * pDevice - Pointer to adapter
1371 * dwTxBufferAddr - Transmit Buffer
1372 * pPacket - Packet from upper layer
1373 * cbPacketSize - Transmit Data Length
1375 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1376 * pcbAppendPayload - size of append payload for 802.1H translation
1378 * Return Value: none
1382 static void s_vGenerateMACHeader(struct vnt_private
*pDevice
,
1383 u8
*pbyBufferAddr
, u16 wDuration
, struct ethhdr
*psEthHeader
,
1384 int bNeedEncrypt
, u16 wFragType
, u32 uDMAIdx
, u32 uFragIdx
)
1386 struct ieee80211_hdr
*pMACHeader
= (struct ieee80211_hdr
*)pbyBufferAddr
;
1388 pMACHeader
->frame_control
= TYPE_802_11_DATA
;
1390 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1391 memcpy(&(pMACHeader
->addr1
[0]),
1392 &(psEthHeader
->h_dest
[0]),
1394 memcpy(&(pMACHeader
->addr2
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1395 memcpy(&(pMACHeader
->addr3
[0]),
1396 &(psEthHeader
->h_source
[0]),
1398 pMACHeader
->frame_control
|= FC_FROMDS
;
1400 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
1401 memcpy(&(pMACHeader
->addr1
[0]),
1402 &(psEthHeader
->h_dest
[0]),
1404 memcpy(&(pMACHeader
->addr2
[0]),
1405 &(psEthHeader
->h_source
[0]),
1407 memcpy(&(pMACHeader
->addr3
[0]),
1408 &(pDevice
->abyBSSID
[0]),
1411 memcpy(&(pMACHeader
->addr3
[0]),
1412 &(psEthHeader
->h_dest
[0]),
1414 memcpy(&(pMACHeader
->addr2
[0]),
1415 &(psEthHeader
->h_source
[0]),
1417 memcpy(&(pMACHeader
->addr1
[0]),
1418 &(pDevice
->abyBSSID
[0]),
1420 pMACHeader
->frame_control
|= FC_TODS
;
1425 pMACHeader
->frame_control
|= cpu_to_le16((u16
)WLAN_SET_FC_ISWEP(1));
1427 pMACHeader
->duration_id
= cpu_to_le16(wDuration
);
1429 if (pDevice
->bLongHeader
) {
1430 PWLAN_80211HDR_A4 pMACA4Header
= (PWLAN_80211HDR_A4
) pbyBufferAddr
;
1431 pMACHeader
->frame_control
|= (FC_TODS
| FC_FROMDS
);
1432 memcpy(pMACA4Header
->abyAddr4
, pDevice
->abyBSSID
, WLAN_ADDR_LEN
);
1434 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1436 //Set FragNumber in Sequence Control
1437 pMACHeader
->seq_ctrl
|= cpu_to_le16((u16
)uFragIdx
);
1439 if ((wFragType
== FRAGCTL_ENDFRAG
) || (wFragType
== FRAGCTL_NONFRAG
)) {
1440 pDevice
->wSeqCounter
++;
1441 if (pDevice
->wSeqCounter
> 0x0fff)
1442 pDevice
->wSeqCounter
= 0;
1445 if ((wFragType
== FRAGCTL_STAFRAG
) || (wFragType
== FRAGCTL_MIDFRAG
)) { //StartFrag or MidFrag
1446 pMACHeader
->frame_control
|= FC_MOREFRAG
;
1453 * Request instructs a MAC to transmit a 802.11 management packet through
1454 * the adapter onto the medium.
1458 * hDeviceContext - Pointer to the adapter
1459 * pPacket - A pointer to a descriptor for the packet to transmit
1463 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1467 CMD_STATUS
csMgmt_xmit(struct vnt_private
*pDevice
,
1468 struct vnt_tx_mgmt
*pPacket
)
1470 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1471 struct vnt_tx_buffer
*pTX_Buffer
;
1472 PSTxBufHead pTxBufHead
;
1473 struct vnt_usb_send_context
*pContext
;
1474 struct ieee80211_hdr
*pMACHeader
;
1475 struct ethhdr sEthHeader
;
1476 u8 byPktType
, *pbyTxBufferAddr
;
1477 void *rts_cts
= NULL
;
1478 void *pvTxDataHd
, *pvRrvTime
, *pMICHDR
;
1479 u32 uDuration
, cbReqCount
, cbHeaderSize
, cbFrameBodySize
, cbFrameSize
;
1480 int bNeedACK
, bIsPSPOLL
= false;
1481 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbFCSlen
= 4;
1485 u16 wCurrentRate
= RATE_1M
;
1487 pContext
= (struct vnt_usb_send_context
*)s_vGetFreeContext(pDevice
);
1489 if (NULL
== pContext
) {
1490 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
1491 return CMD_STATUS_RESOURCES
;
1494 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
1495 pbyTxBufferAddr
= (u8
*)&(pTX_Buffer
->adwTxKey
[0]);
1496 cbFrameBodySize
= pPacket
->cbPayloadLen
;
1497 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
1498 wTxBufSize
= sizeof(STxBufHead
);
1500 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1501 wCurrentRate
= RATE_6M
;
1502 byPktType
= PK_TYPE_11A
;
1504 wCurrentRate
= RATE_1M
;
1505 byPktType
= PK_TYPE_11B
;
1508 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1509 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1510 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1511 // to set power here.
1512 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
1513 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
1515 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
1517 pDevice
->wCurrentRate
= wCurrentRate
;
1520 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
1521 pTxBufHead
->wFIFOCtl
= 0;
1523 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
1524 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1526 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
1527 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
1529 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
1530 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
1533 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
1534 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
1536 if (is_multicast_ether_addr(pPacket
->p80211Header
->sA3
.abyAddr1
)) {
1541 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1544 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
1545 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
1547 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
1548 //Set Preamble type always long
1549 //pDevice->byPreambleType = PREAMBLE_LONG;
1550 // probe-response don't retry
1551 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1552 // bNeedACK = false;
1553 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1557 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
1559 if ((pPacket
->p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
1561 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
1563 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
1566 //Set FRAGCTL_MACHDCNT
1567 pTxBufHead
->wFragCtl
|= cpu_to_le16((u16
)(cbMacHdLen
<< 10));
1570 // Although spec says MMPDU can be fragmented; In most case,
1571 // no one will send a MMPDU under fragmentation. With RTS may occur.
1572 pDevice
->bAES
= false; //Set FRAGCTL_WEPTYP
1574 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
1575 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
1578 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1580 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
1581 cbIVlen
= 8;//IV+ExtIV
1584 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1585 //We need to get seed here for filling TxKey entry.
1586 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1587 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1589 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
1590 cbIVlen
= 8;//RSN Header
1592 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1593 pDevice
->bAES
= true;
1595 //MAC Header should be padding 0 to DW alignment.
1596 uPadding
= 4 - (cbMacHdLen
%4);
1600 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
;
1602 //Set FIFOCTL_GrpAckPolicy
1603 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1604 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1606 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1608 //Set RrvTime/RTS/CTS Buffer
1609 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1611 pvRrvTime
= (struct vnt_rrv_time_cts
*) (pbyTxBufferAddr
+ wTxBufSize
);
1613 rts_cts
= (struct vnt_cts
*) (pbyTxBufferAddr
+ wTxBufSize
+
1614 sizeof(struct vnt_rrv_time_cts
));
1615 pvTxDataHd
= (struct vnt_tx_datahead_g
*)(pbyTxBufferAddr
+ wTxBufSize
+
1616 sizeof(struct vnt_rrv_time_cts
) + sizeof(struct vnt_cts
));
1617 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1618 sizeof(struct vnt_cts
) + sizeof(struct vnt_tx_datahead_g
);
1620 else { // 802.11a/b packet
1621 pvRrvTime
= (struct vnt_rrv_time_ab
*) (pbyTxBufferAddr
+ wTxBufSize
);
1623 pvTxDataHd
= (struct vnt_tx_datahead_ab
*) (pbyTxBufferAddr
+
1624 wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
));
1625 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1626 sizeof(struct vnt_tx_datahead_ab
);
1629 memcpy(&(sEthHeader
.h_dest
[0]),
1630 &(pPacket
->p80211Header
->sA3
.abyAddr1
[0]),
1632 memcpy(&(sEthHeader
.h_source
[0]),
1633 &(pPacket
->p80211Header
->sA3
.abyAddr2
[0]),
1635 //=========================
1637 //=========================
1638 pTxBufHead
->wFragCtl
|= (u16
)FRAGCTL_NONFRAG
;
1640 /* Fill FIFO,RrvTime,RTS,and CTS */
1641 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
1642 pbyTxBufferAddr
, pvRrvTime
, rts_cts
,
1643 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
, false);
1646 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
1649 pMACHeader
= (struct ieee80211_hdr
*) (pbyTxBufferAddr
+ cbHeaderSize
);
1651 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ cbFrameBodySize
;
1653 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
1655 u8
* pbyPayloadHead
;
1657 PSKeyItem pTransmitKey
= NULL
;
1659 pbyIVHead
= (u8
*)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
);
1660 pbyPayloadHead
= (u8
*)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
1662 if ((pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
1663 (pDevice
->bLinkPass
== true)) {
1664 pbyBSSID
= pDevice
->abyBSSID
;
1666 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
1668 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
1669 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
1673 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get PTK.\n");
1678 pbyBSSID
= pDevice
->abyBroadcastAddr
;
1679 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
1680 pTransmitKey
= NULL
;
1681 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KEY is NULL. OP Mode[%d]\n", pDevice
->eOPMode
);
1683 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
1687 s_vFillTxKey(pDevice
, (u8
*)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
1688 (u8
*)pMACHeader
, (u16
)cbFrameBodySize
, NULL
);
1690 memcpy(pMACHeader
, pPacket
->p80211Header
, cbMacHdLen
);
1691 memcpy(pbyPayloadHead
, ((u8
*)(pPacket
->p80211Header
) + cbMacHdLen
),
1695 // Copy the Packet into a tx Buffer
1696 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
1699 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1700 pDevice
->wSeqCounter
++ ;
1701 if (pDevice
->wSeqCounter
> 0x0fff)
1702 pDevice
->wSeqCounter
= 0;
1705 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1706 // of FIFO control header.
1707 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1708 // in the same place of other packet's Duration-field).
1709 // And it will cause Cisco-AP to issue Disassociation-packet
1710 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1711 ((struct vnt_tx_datahead_g
*)pvTxDataHd
)->wDuration_a
=
1712 cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1713 ((struct vnt_tx_datahead_g
*)pvTxDataHd
)->wDuration_b
=
1714 cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1716 ((struct vnt_tx_datahead_ab
*)pvTxDataHd
)->wDuration
=
1717 cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1721 pTX_Buffer
->wTxByteCount
= cpu_to_le16((u16
)(cbReqCount
));
1722 pTX_Buffer
->byPKTNO
= (u8
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
1723 pTX_Buffer
->byType
= 0x00;
1725 pContext
->pPacket
= NULL
;
1726 pContext
->Type
= CONTEXT_MGMT_PACKET
;
1727 pContext
->uBufLen
= (u16
)cbReqCount
+ 4; //USB header
1729 if (WLAN_GET_FC_TODS(pMACHeader
->frame_control
) == 0) {
1730 s_vSaveTxPktInfo(pDevice
, (u8
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->addr1
[0]), (u16
)cbFrameSize
, pTX_Buffer
->wFIFOCtl
);
1733 s_vSaveTxPktInfo(pDevice
, (u8
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->addr3
[0]), (u16
)cbFrameSize
, pTX_Buffer
->wFIFOCtl
);
1736 PIPEnsSendBulkOut(pDevice
,pContext
);
1737 return CMD_STATUS_PENDING
;
1740 CMD_STATUS
csBeacon_xmit(struct vnt_private
*pDevice
,
1741 struct vnt_tx_mgmt
*pPacket
)
1743 struct vnt_beacon_buffer
*pTX_Buffer
;
1744 u32 cbFrameSize
= pPacket
->cbMPDULen
+ WLAN_FCS_LEN
;
1745 u32 cbHeaderSize
= 0;
1746 u16 wTxBufSize
= sizeof(STxShortBufHead
);
1747 PSTxShortBufHead pTxBufHead
;
1748 struct ieee80211_hdr
*pMACHeader
;
1749 struct vnt_tx_datahead_ab
*pTxDataHead
;
1751 u32 cbFrameBodySize
;
1753 u8
*pbyTxBufferAddr
;
1754 struct vnt_usb_send_context
*pContext
;
1757 pContext
= (struct vnt_usb_send_context
*)s_vGetFreeContext(pDevice
);
1758 if (NULL
== pContext
) {
1759 status
= CMD_STATUS_RESOURCES
;
1760 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
1764 pTX_Buffer
= (struct vnt_beacon_buffer
*)&pContext
->Data
[0];
1765 pbyTxBufferAddr
= (u8
*)&(pTX_Buffer
->wFIFOCtl
);
1767 cbFrameBodySize
= pPacket
->cbPayloadLen
;
1769 pTxBufHead
= (PSTxShortBufHead
) pbyTxBufferAddr
;
1770 wTxBufSize
= sizeof(STxShortBufHead
);
1772 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1773 wCurrentRate
= RATE_6M
;
1774 pTxDataHead
= (struct vnt_tx_datahead_ab
*)
1775 (pbyTxBufferAddr
+ wTxBufSize
);
1776 //Get SignalField,ServiceField,Length
1777 BBvCalculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, PK_TYPE_11A
,
1779 //Get Duration and TimeStampOff
1780 pTxDataHead
->wDuration
= s_uGetDataDuration(pDevice
,
1781 PK_TYPE_11A
, false);
1782 pTxDataHead
->wTimeStampOff
= vnt_time_stamp_off(pDevice
, wCurrentRate
);
1783 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_tx_datahead_ab
);
1785 wCurrentRate
= RATE_1M
;
1786 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1787 pTxDataHead
= (struct vnt_tx_datahead_ab
*)
1788 (pbyTxBufferAddr
+ wTxBufSize
);
1789 //Get SignalField,ServiceField,Length
1790 BBvCalculateParameter(pDevice
, cbFrameSize
, wCurrentRate
, PK_TYPE_11B
,
1792 //Get Duration and TimeStampOff
1793 pTxDataHead
->wDuration
= s_uGetDataDuration(pDevice
,
1794 PK_TYPE_11B
, false);
1795 pTxDataHead
->wTimeStampOff
= vnt_time_stamp_off(pDevice
, wCurrentRate
);
1796 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_tx_datahead_ab
);
1799 //Generate Beacon Header
1800 pMACHeader
= (struct ieee80211_hdr
*)(pbyTxBufferAddr
+ cbHeaderSize
);
1801 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
1803 pMACHeader
->duration_id
= 0;
1804 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1805 pDevice
->wSeqCounter
++ ;
1806 if (pDevice
->wSeqCounter
> 0x0fff)
1807 pDevice
->wSeqCounter
= 0;
1809 cbReqCount
= cbHeaderSize
+ WLAN_HDR_ADDR3_LEN
+ cbFrameBodySize
;
1811 pTX_Buffer
->wTxByteCount
= (u16
)cbReqCount
;
1812 pTX_Buffer
->byPKTNO
= (u8
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
1813 pTX_Buffer
->byType
= 0x01;
1815 pContext
->pPacket
= NULL
;
1816 pContext
->Type
= CONTEXT_MGMT_PACKET
;
1817 pContext
->uBufLen
= (u16
)cbReqCount
+ 4; //USB header
1819 PIPEnsSendBulkOut(pDevice
,pContext
);
1820 return CMD_STATUS_PENDING
;
1824 void vDMA0_tx_80211(struct vnt_private
*pDevice
, struct sk_buff
*skb
)
1826 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1827 struct vnt_tx_buffer
*pTX_Buffer
;
1829 u8
*pbyTxBufferAddr
;
1830 void *rts_cts
= NULL
;
1832 u32 uDuration
, cbReqCount
;
1833 struct ieee80211_hdr
*pMACHeader
;
1834 u32 cbHeaderSize
, cbFrameBodySize
;
1835 int bNeedACK
, bIsPSPOLL
= false;
1836 PSTxBufHead pTxBufHead
;
1838 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbFCSlen
= 4;
1840 u32 cbMICHDR
= 0, uLength
= 0;
1841 u32 dwMICKey0
, dwMICKey1
;
1843 u32
*pdwMIC_L
, *pdwMIC_R
;
1846 struct ethhdr sEthHeader
;
1847 void *pvRrvTime
, *pMICHDR
;
1848 u32 wCurrentRate
= RATE_1M
;
1849 PUWLAN_80211HDR p80211Header
;
1851 int bNodeExist
= false;
1853 PSKeyItem pTransmitKey
= NULL
;
1854 u8
*pbyIVHead
, *pbyPayloadHead
, *pbyMacHdr
;
1855 u32 cbExtSuppRate
= 0;
1856 struct vnt_usb_send_context
*pContext
;
1858 pvRrvTime
= pMICHDR
= pvTxDataHd
= NULL
;
1860 if(skb
->len
<= WLAN_HDR_ADDR3_LEN
) {
1861 cbFrameBodySize
= 0;
1864 cbFrameBodySize
= skb
->len
- WLAN_HDR_ADDR3_LEN
;
1866 p80211Header
= (PUWLAN_80211HDR
)skb
->data
;
1868 pContext
= (struct vnt_usb_send_context
*)s_vGetFreeContext(pDevice
);
1870 if (NULL
== pContext
) {
1871 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0 TX...NO CONTEXT!\n");
1872 dev_kfree_skb_irq(skb
);
1876 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
1877 pbyTxBufferAddr
= (u8
*)(&pTX_Buffer
->adwTxKey
[0]);
1878 pTxBufHead
= (PSTxBufHead
) pbyTxBufferAddr
;
1879 wTxBufSize
= sizeof(STxBufHead
);
1881 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1882 wCurrentRate
= RATE_6M
;
1883 byPktType
= PK_TYPE_11A
;
1885 wCurrentRate
= RATE_1M
;
1886 byPktType
= PK_TYPE_11B
;
1889 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1890 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1891 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1892 // to set power here.
1893 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
1894 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
1896 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
1899 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header
->sA3
.wFrameCtl
);
1902 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
1903 pTxBufHead
->wFIFOCtl
= 0;
1905 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
1906 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1908 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
1909 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
1911 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
1912 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
1915 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
1916 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
1918 if (is_multicast_ether_addr(p80211Header
->sA3
.abyAddr1
)) {
1920 if (pDevice
->bEnableHostWEP
) {
1926 if (pDevice
->bEnableHostWEP
) {
1927 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(p80211Header
->sA3
.abyAddr1
), &uNodeIndex
))
1931 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1934 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
1935 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
1937 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
1938 //Set Preamble type always long
1939 //pDevice->byPreambleType = PREAMBLE_LONG;
1941 // probe-response don't retry
1942 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1943 // bNeedACK = false;
1944 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1948 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
1950 if ((p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
1952 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
1954 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
1957 // hostapd daemon ext support rate patch
1958 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
1960 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0) {
1961 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
;
1964 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0) {
1965 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
;
1968 if (cbExtSuppRate
>0) {
1969 cbFrameBodySize
= WLAN_ASSOCRESP_OFF_SUPP_RATES
;
1973 //Set FRAGCTL_MACHDCNT
1974 pTxBufHead
->wFragCtl
|= cpu_to_le16((u16
)cbMacHdLen
<< 10);
1977 // Although spec says MMPDU can be fragmented; In most case,
1978 // no one will send a MMPDU under fragmentation. With RTS may occur.
1979 pDevice
->bAES
= false; //Set FRAGCTL_WEPTYP
1981 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
1982 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
1985 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1987 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
1988 cbIVlen
= 8;//IV+ExtIV
1991 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1992 //We need to get seed here for filling TxKey entry.
1993 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1994 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1996 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
1997 cbIVlen
= 8;//RSN Header
1999 cbMICHDR
= sizeof(struct vnt_mic_hdr
);
2000 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
2001 pDevice
->bAES
= true;
2003 //MAC Header should be padding 0 to DW alignment.
2004 uPadding
= 4 - (cbMacHdLen
%4);
2008 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
+ cbExtSuppRate
;
2010 //Set FIFOCTL_GrpAckPolicy
2011 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
2012 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
2014 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2016 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
2017 pvRrvTime
= (struct vnt_rrv_time_cts
*) (pbyTxBufferAddr
+ wTxBufSize
);
2018 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
2019 sizeof(struct vnt_rrv_time_cts
));
2020 rts_cts
= (struct vnt_cts
*) (pbyTxBufferAddr
+ wTxBufSize
+
2021 sizeof(struct vnt_rrv_time_cts
) + cbMICHDR
);
2022 pvTxDataHd
= (struct vnt_tx_datahead_g
*) (pbyTxBufferAddr
+
2023 wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) + cbMICHDR
+
2024 sizeof(struct vnt_cts
));
2025 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) + cbMICHDR
+
2026 sizeof(struct vnt_cts
) + sizeof(struct vnt_tx_datahead_g
);
2029 else {//802.11a/b packet
2031 pvRrvTime
= (struct vnt_rrv_time_ab
*) (pbyTxBufferAddr
+ wTxBufSize
);
2032 pMICHDR
= (struct vnt_mic_hdr
*) (pbyTxBufferAddr
+ wTxBufSize
+
2033 sizeof(struct vnt_rrv_time_ab
));
2034 pvTxDataHd
= (struct vnt_tx_datahead_ab
*)(pbyTxBufferAddr
+
2035 wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
);
2036 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
+
2037 sizeof(struct vnt_tx_datahead_ab
);
2039 memcpy(&(sEthHeader
.h_dest
[0]),
2040 &(p80211Header
->sA3
.abyAddr1
[0]),
2042 memcpy(&(sEthHeader
.h_source
[0]),
2043 &(p80211Header
->sA3
.abyAddr2
[0]),
2045 //=========================
2047 //=========================
2048 pTxBufHead
->wFragCtl
|= (u16
)FRAGCTL_NONFRAG
;
2050 /* Fill FIFO,RrvTime,RTS,and CTS */
2051 s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
2052 pbyTxBufferAddr
, pvRrvTime
, rts_cts
,
2053 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
, false);
2056 uDuration
= s_uFillDataHead(pDevice
, byPktType
, wCurrentRate
, pvTxDataHd
, cbFrameSize
, TYPE_TXDMA0
, bNeedACK
,
2059 pMACHeader
= (struct ieee80211_hdr
*) (pbyTxBufferAddr
+ cbHeaderSize
);
2061 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbExtSuppRate
;
2063 pbyMacHdr
= (u8
*)(pbyTxBufferAddr
+ cbHeaderSize
);
2064 pbyPayloadHead
= (u8
*)(pbyMacHdr
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
2065 pbyIVHead
= (u8
*)(pbyMacHdr
+ cbMacHdLen
+ uPadding
);
2067 // Copy the Packet into a tx Buffer
2068 memcpy(pbyMacHdr
, skb
->data
, cbMacHdLen
);
2070 // version set to 0, patch for hostapd deamon
2071 pMACHeader
->frame_control
&= cpu_to_le16(0xfffc);
2072 memcpy(pbyPayloadHead
, (skb
->data
+ cbMacHdLen
), cbFrameBodySize
);
2074 // replace support rate, patch for hostapd daemon( only support 11M)
2075 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
2076 if (cbExtSuppRate
!= 0) {
2077 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0)
2078 memcpy((pbyPayloadHead
+ cbFrameBodySize
),
2079 pMgmt
->abyCurrSuppRates
,
2080 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
2082 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0)
2083 memcpy((pbyPayloadHead
+ cbFrameBodySize
) + ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
,
2084 pMgmt
->abyCurrExtSuppRates
,
2085 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
2091 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
2093 if (pDevice
->bEnableHostWEP
) {
2094 pTransmitKey
= &STempKey
;
2095 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2096 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2097 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2098 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2099 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2100 memcpy(pTransmitKey
->abyKey
,
2101 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2102 pTransmitKey
->uKeyLength
2106 if ((pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
2108 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
2109 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
2111 // DO Software Michael
2112 MIC_vInit(dwMICKey0
, dwMICKey1
);
2113 MIC_vAppend((u8
*)&(sEthHeader
.h_dest
[0]), 12);
2115 MIC_vAppend((u8
*)&dwMIC_Priority
, 4);
2116 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0_tx_8021:MIC KEY:"\
2117 " %X, %X\n", dwMICKey0
, dwMICKey1
);
2119 uLength
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
;
2121 MIC_vAppend((pbyTxBufferAddr
+ uLength
), cbFrameBodySize
);
2123 pdwMIC_L
= (u32
*)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
);
2124 pdwMIC_R
= (u32
*)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
+ 4);
2126 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
2129 if (pDevice
->bTxMICFail
== true) {
2132 pDevice
->bTxMICFail
= false;
2135 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uLength: %d, %d\n", uLength
, cbFrameBodySize
);
2136 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"cbReqCount:%d, %d, %d, %d\n", cbReqCount
, cbHeaderSize
, uPadding
, cbIVlen
);
2137 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC:%x, %x\n",
2138 *pdwMIC_L
, *pdwMIC_R
);
2142 s_vFillTxKey(pDevice
, (u8
*)(pTxBufHead
->adwTxKey
), pbyIVHead
, pTransmitKey
,
2143 pbyMacHdr
, (u16
)cbFrameBodySize
, pMICHDR
);
2145 if (pDevice
->bEnableHostWEP
) {
2146 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
2147 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
2150 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
2151 s_vSWencryption(pDevice
, pTransmitKey
, pbyPayloadHead
, (u16
)(cbFrameBodySize
+ cbMIClen
));
2155 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2156 pDevice
->wSeqCounter
++ ;
2157 if (pDevice
->wSeqCounter
> 0x0fff)
2158 pDevice
->wSeqCounter
= 0;
2161 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2162 // of FIFO control header.
2163 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2164 // in the same place of other packet's Duration-field).
2165 // And it will cause Cisco-AP to issue Disassociation-packet
2166 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
2167 ((struct vnt_tx_datahead_g
*)pvTxDataHd
)->wDuration_a
=
2168 cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2169 ((struct vnt_tx_datahead_g
*)pvTxDataHd
)->wDuration_b
=
2170 cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2172 ((struct vnt_tx_datahead_ab
*)pvTxDataHd
)->wDuration
=
2173 cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2177 pTX_Buffer
->wTxByteCount
= cpu_to_le16((u16
)(cbReqCount
));
2178 pTX_Buffer
->byPKTNO
= (u8
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2179 pTX_Buffer
->byType
= 0x00;
2181 pContext
->pPacket
= skb
;
2182 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2183 pContext
->uBufLen
= (u16
)cbReqCount
+ 4; //USB header
2185 if (WLAN_GET_FC_TODS(pMACHeader
->frame_control
) == 0) {
2186 s_vSaveTxPktInfo(pDevice
, (u8
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->addr1
[0]), (u16
)cbFrameSize
, pTX_Buffer
->wFIFOCtl
);
2189 s_vSaveTxPktInfo(pDevice
, (u8
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pMACHeader
->addr3
[0]), (u16
)cbFrameSize
, pTX_Buffer
->wFIFOCtl
);
2191 PIPEnsSendBulkOut(pDevice
,pContext
);
2196 //TYPE_AC0DMA data tx
2199 * Tx packet via AC0DMA(DMA1)
2203 * pDevice - Pointer to the adapter
2204 * skb - Pointer to tx skb packet
2208 * Return Value: NULL
2211 int nsDMA_tx_packet(struct vnt_private
*pDevice
,
2212 u32 uDMAIdx
, struct sk_buff
*skb
)
2214 struct net_device_stats
*pStats
= &pDevice
->stats
;
2215 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2216 struct vnt_tx_buffer
*pTX_Buffer
;
2217 u32 BytesToWrite
= 0, uHeaderLen
= 0;
2219 u8 byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2222 int bNeedEncryption
= false;
2223 PSKeyItem pTransmitKey
= NULL
;
2226 int bTKIP_UseGTK
= false;
2227 int bNeedDeAuth
= false;
2229 int bNodeExist
= false;
2230 struct vnt_usb_send_context
*pContext
;
2231 bool fConvertedPacket
;
2233 u16 wKeepRate
= pDevice
->wCurrentRate
;
2234 int bTxeapol_key
= false;
2236 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
2238 if (pDevice
->uAssocCount
== 0) {
2239 dev_kfree_skb_irq(skb
);
2243 if (is_multicast_ether_addr((u8
*)(skb
->data
))) {
2246 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
2248 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skb
);
2249 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
2251 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
2254 // multicast/broadcast data rate
2256 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2257 pDevice
->wCurrentRate
= RATE_2M
;
2259 pDevice
->wCurrentRate
= RATE_24M
;
2260 // long preamble type
2261 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2265 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(skb
->data
), &uNodeIndex
)) {
2267 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bPSEnable
) {
2269 skb_queue_tail(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
, skb
);
2271 pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
++;
2273 wAID
= pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
;
2274 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
2275 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set:pMgmt->abyPSTxMap[%d]= %d\n",
2276 (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
2280 // AP rate decided from node
2281 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2282 // tx preamble decided from node
2284 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2285 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2288 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2294 if (bNodeExist
== false) {
2295 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Unknown STA not found in node DB \n");
2296 dev_kfree_skb_irq(skb
);
2301 pContext
= (struct vnt_usb_send_context
*)s_vGetFreeContext(pDevice
);
2303 if (pContext
== NULL
) {
2304 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
" pContext == NULL\n");
2305 dev_kfree_skb_irq(skb
);
2306 return STATUS_RESOURCES
;
2309 memcpy(pDevice
->sTxEthHeader
.h_dest
, (u8
*)(skb
->data
), ETH_HLEN
);
2311 //mike add:station mode check eapol-key challenge--->
2313 u8 Protocol_Version
; //802.1x Authentication
2314 u8 Packet_Type
; //802.1x Authentication
2318 Protocol_Version
= skb
->data
[ETH_HLEN
];
2319 Packet_Type
= skb
->data
[ETH_HLEN
+1];
2320 Descriptor_type
= skb
->data
[ETH_HLEN
+1+1+2];
2321 Key_info
= (skb
->data
[ETH_HLEN
+1+1+2+1] << 8)|(skb
->data
[ETH_HLEN
+1+1+2+2]);
2322 if (pDevice
->sTxEthHeader
.h_proto
== cpu_to_be16(ETH_P_PAE
)) {
2323 /* 802.1x OR eapol-key challenge frame transfer */
2324 if (((Protocol_Version
== 1) || (Protocol_Version
== 2)) &&
2325 (Packet_Type
== 3)) {
2326 bTxeapol_key
= true;
2327 if(!(Key_info
& BIT3
) && //WPA or RSN group-key challenge
2328 (Key_info
& BIT8
) && (Key_info
& BIT9
)) { //send 2/2 key
2329 if(Descriptor_type
==254) {
2330 pDevice
->fWPA_Authened
= true;
2334 pDevice
->fWPA_Authened
= true;
2335 PRINT_K("WPA2(re-keying) ");
2337 PRINT_K("Authentication completed!!\n");
2339 else if((Key_info
& BIT3
) && (Descriptor_type
==2) && //RSN pairwise-key challenge
2340 (Key_info
& BIT8
) && (Key_info
& BIT9
)) {
2341 pDevice
->fWPA_Authened
= true;
2342 PRINT_K("WPA2 Authentication completed!!\n");
2347 //mike add:station mode check eapol-key challenge<---
2349 if (pDevice
->bEncryptionEnable
== true) {
2350 bNeedEncryption
= true;
2353 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
2354 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2355 pbyBSSID
= pDevice
->abyBSSID
;
2357 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
2359 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
2360 bTKIP_UseGTK
= true;
2361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2365 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get PTK.\n");
2368 }else if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2369 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2370 pbyBSSID
= pDevice
->sTxEthHeader
.h_dest
;
2371 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS Serach Key: \n");
2372 for (ii
= 0; ii
< 6; ii
++)
2373 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"%x \n", *(pbyBSSID
+ii
));
2374 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"\n");
2377 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == true)
2381 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2382 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2383 pTransmitKey
= NULL
;
2384 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2385 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2388 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"NOT IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2390 bTKIP_UseGTK
= true;
2391 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2396 if (pDevice
->bEnableHostWEP
) {
2397 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"acdma0: STA index %d\n", uNodeIndex
);
2398 if (pDevice
->bEncryptionEnable
== true) {
2399 pTransmitKey
= &STempKey
;
2400 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2401 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2402 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2403 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2404 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2405 memcpy(pTransmitKey
->abyKey
,
2406 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2407 pTransmitKey
->uKeyLength
2412 byPktType
= (u8
)pDevice
->byPacketType
;
2414 if (pDevice
->bFixRate
) {
2415 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2416 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2417 pDevice
->wCurrentRate
= RATE_11M
;
2419 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2422 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2423 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2424 pDevice
->wCurrentRate
= RATE_6M
;
2426 if (pDevice
->uConnectionRate
>= RATE_54M
)
2427 pDevice
->wCurrentRate
= RATE_54M
;
2429 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2434 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2435 // Adhoc Tx rate decided from node DB
2436 if (is_multicast_ether_addr(pDevice
->sTxEthHeader
.h_dest
)) {
2437 // Multicast use highest data rate
2438 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2440 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2443 if (BSSbIsSTAInNodeDB(pDevice
, &(pDevice
->sTxEthHeader
.h_dest
[0]), &uNodeIndex
)) {
2444 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2445 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2446 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2450 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2452 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex
, pDevice
->wCurrentRate
);
2455 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2456 pDevice
->wCurrentRate
= RATE_2M
;
2458 pDevice
->wCurrentRate
= RATE_24M
; // refer to vMgrCreateOwnIBSS()'s
2459 // abyCurrExtSuppRates[]
2460 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2461 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Not Found Node use highest basic Rate.....\n");
2465 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
2466 // Infra STA rate decided from AP Node, index = 0
2467 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2471 if (pDevice
->sTxEthHeader
.h_proto
== cpu_to_be16(ETH_P_PAE
)) {
2472 if (pDevice
->byBBType
!= BB_TYPE_11A
) {
2473 pDevice
->wCurrentRate
= RATE_1M
;
2474 pDevice
->byACKRate
= RATE_1M
;
2475 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2476 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2478 pDevice
->wCurrentRate
= RATE_6M
;
2479 pDevice
->byACKRate
= RATE_6M
;
2480 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2481 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2485 DBG_PRT(MSG_LEVEL_DEBUG
,
2486 KERN_INFO
"dma_tx: pDevice->wCurrentRate = %d\n",
2487 pDevice
->wCurrentRate
);
2489 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2490 bScheduleCommand((void *) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2493 if (pDevice
->wCurrentRate
<= RATE_11M
) {
2494 byPktType
= PK_TYPE_11B
;
2497 if (bNeedEncryption
== true) {
2498 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ntohs Pkt Type=%04x\n", ntohs(pDevice
->sTxEthHeader
.h_proto
));
2499 if ((pDevice
->sTxEthHeader
.h_proto
) == cpu_to_be16(ETH_P_PAE
)) {
2500 bNeedEncryption
= false;
2501 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pkt Type=%04x\n", (pDevice
->sTxEthHeader
.h_proto
));
2502 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2503 if (pTransmitKey
== NULL
) {
2504 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Don't Find TX KEY\n");
2507 if (bTKIP_UseGTK
== true) {
2508 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"error: KEY is GTK!!~~\n");
2511 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%X]\n",
2512 pTransmitKey
->dwKeyIndex
);
2513 bNeedEncryption
= true;
2518 if (pDevice
->bEnableHostWEP
) {
2519 if ((uNodeIndex
!= 0) &&
2520 (pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
& PAIRWISE_KEY
)) {
2521 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%X]\n",
2522 pTransmitKey
->dwKeyIndex
);
2523 bNeedEncryption
= true;
2529 if (pTransmitKey
== NULL
) {
2530 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return no tx key\n");
2531 pContext
->bBoolInUse
= false;
2532 dev_kfree_skb_irq(skb
);
2533 pStats
->tx_dropped
++;
2534 return STATUS_FAILURE
;
2539 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
2541 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
2542 pTX_Buffer
, bNeedEncryption
,
2543 skb
->len
, uDMAIdx
, &pDevice
->sTxEthHeader
,
2544 (u8
*)skb
->data
, pTransmitKey
, uNodeIndex
,
2545 pDevice
->wCurrentRate
,
2546 &uHeaderLen
, &BytesToWrite
2549 if (fConvertedPacket
== false) {
2550 pContext
->bBoolInUse
= false;
2551 dev_kfree_skb_irq(skb
);
2552 return STATUS_FAILURE
;
2555 if ( pDevice
->bEnablePSMode
== true ) {
2556 if ( !pDevice
->bPSModeTxBurst
) {
2557 bScheduleCommand((void *) pDevice
,
2558 WLAN_CMD_MAC_DISPOWERSAVING
,
2560 pDevice
->bPSModeTxBurst
= true;
2564 pTX_Buffer
->byPKTNO
= (u8
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2565 pTX_Buffer
->wTxByteCount
= (u16
)BytesToWrite
;
2567 pContext
->pPacket
= skb
;
2568 pContext
->Type
= CONTEXT_DATA_PACKET
;
2569 pContext
->uBufLen
= (u16
)BytesToWrite
+ 4 ; //USB header
2571 s_vSaveTxPktInfo(pDevice
, (u8
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pContext
->sEthHeader
.h_dest
[0]), (u16
) (BytesToWrite
-uHeaderLen
), pTX_Buffer
->wFIFOCtl
);
2573 status
= PIPEnsSendBulkOut(pDevice
,pContext
);
2575 if (bNeedDeAuth
== true) {
2576 u16 wReason
= WLAN_MGMT_REASON_MIC_FAILURE
;
2578 bScheduleCommand((void *) pDevice
, WLAN_CMD_DEAUTH
, (u8
*) &wReason
);
2581 if(status
!=STATUS_PENDING
) {
2582 pContext
->bBoolInUse
= false;
2583 dev_kfree_skb_irq(skb
);
2584 return STATUS_FAILURE
;
2593 * Relay packet send (AC1DMA) from rx dpc.
2597 * pDevice - Pointer to the adapter
2598 * pPacket - Pointer to rx packet
2599 * cbPacketSize - rx ethernet frame size
2603 * Return Value: Return true if packet is copy to dma1; otherwise false
2606 int bRelayPacketSend(struct vnt_private
*pDevice
, u8
*pbySkbData
, u32 uDataLen
,
2609 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2610 struct vnt_tx_buffer
*pTX_Buffer
;
2611 u32 BytesToWrite
= 0, uHeaderLen
= 0;
2612 u8 byPktType
= PK_TYPE_11B
;
2613 int bNeedEncryption
= false;
2615 PSKeyItem pTransmitKey
= NULL
;
2617 struct vnt_usb_send_context
*pContext
;
2619 int fConvertedPacket
;
2621 u16 wKeepRate
= pDevice
->wCurrentRate
;
2623 pContext
= (struct vnt_usb_send_context
*)s_vGetFreeContext(pDevice
);
2625 if (NULL
== pContext
) {
2629 memcpy(pDevice
->sTxEthHeader
.h_dest
, (u8
*)pbySkbData
, ETH_HLEN
);
2631 if (pDevice
->bEncryptionEnable
== true) {
2632 bNeedEncryption
= true;
2634 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2635 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2636 pTransmitKey
= NULL
;
2637 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2639 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2643 if (pDevice
->bEnableHostWEP
) {
2644 if (uNodeIndex
< MAX_NODE_NUM
+ 1) {
2645 pTransmitKey
= &STempKey
;
2646 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2647 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2648 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2649 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2650 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2651 memcpy(pTransmitKey
->abyKey
,
2652 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2653 pTransmitKey
->uKeyLength
2658 if ( bNeedEncryption
&& (pTransmitKey
== NULL
) ) {
2659 pContext
->bBoolInUse
= false;
2663 byPktTyp
= (u8
)pDevice
->byPacketType
;
2665 if (pDevice
->bFixRate
) {
2666 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2667 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2668 pDevice
->wCurrentRate
= RATE_11M
;
2670 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2673 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2674 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2675 pDevice
->wCurrentRate
= RATE_6M
;
2677 if (pDevice
->uConnectionRate
>= RATE_54M
)
2678 pDevice
->wCurrentRate
= RATE_54M
;
2680 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2685 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2688 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2689 bScheduleCommand((void *) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2692 if (pDevice
->wCurrentRate
<= RATE_11M
)
2693 byPktType
= PK_TYPE_11B
;
2695 BytesToWrite
= uDataLen
+ ETH_FCS_LEN
;
2697 // Convert the packet to an usb frame and copy into our buffer
2698 // and send the irp.
2700 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
2702 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
2703 pTX_Buffer
, bNeedEncryption
,
2704 uDataLen
, TYPE_AC0DMA
, &pDevice
->sTxEthHeader
,
2705 pbySkbData
, pTransmitKey
, uNodeIndex
,
2706 pDevice
->wCurrentRate
,
2707 &uHeaderLen
, &BytesToWrite
2710 if (fConvertedPacket
== false) {
2711 pContext
->bBoolInUse
= false;
2715 pTX_Buffer
->byPKTNO
= (u8
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2716 pTX_Buffer
->wTxByteCount
= (u16
)BytesToWrite
;
2718 pContext
->pPacket
= NULL
;
2719 pContext
->Type
= CONTEXT_DATA_PACKET
;
2720 pContext
->uBufLen
= (u16
)BytesToWrite
+ 4 ; //USB header
2722 s_vSaveTxPktInfo(pDevice
, (u8
) (pTX_Buffer
->byPKTNO
& 0x0F), &(pContext
->sEthHeader
.h_dest
[0]), (u16
) (BytesToWrite
-uHeaderLen
), pTX_Buffer
->wFIFOCtl
);
2724 status
= PIPEnsSendBulkOut(pDevice
,pContext
);