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 static 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 static 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 static 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 struct vnt_usb_send_context
*s_vGetFreeContext(struct vnt_private
*);
101 static u16
s_vGenerateTxParameter(struct vnt_private
*pDevice
,
102 u8 byPktType
, u16 wCurrentRate
, struct vnt_tx_buffer
*tx_buffer
,
103 struct vnt_mic_hdr
**mic_hdr
, u32 need_mic
, u32 cbFrameSize
,
104 int bNeedACK
, u32 uDMAIdx
, struct ethhdr
*psEthHeader
, bool need_rts
);
106 static void s_vGenerateMACHeader(struct vnt_private
*pDevice
,
107 u8
*pbyBufferAddr
, u16 wDuration
, struct ethhdr
*psEthHeader
,
108 int bNeedEncrypt
, u16 wFragType
, u32 uDMAIdx
, u32 uFragIdx
);
110 static void s_vFillTxKey(struct vnt_private
*pDevice
,
111 struct vnt_tx_fifo_head
*fifo_head
, u8
*pbyIVHead
,
112 PSKeyItem pTransmitKey
, u8
*pbyHdrBuf
, u16 wPayloadLen
,
113 struct vnt_mic_hdr
*mic_hdr
);
115 static void s_vSWencryption(struct vnt_private
*pDevice
,
116 PSKeyItem pTransmitKey
, u8
*pbyPayloadHead
, u16 wPayloadSize
);
118 static unsigned int s_uGetTxRsvTime(struct vnt_private
*pDevice
, u8 byPktType
,
119 u32 cbFrameLength
, u16 wRate
, int bNeedAck
);
121 static u16
s_uGetRTSCTSRsvTime(struct vnt_private
*pDevice
, u8 byRTSRsvType
,
122 u8 byPktType
, u32 cbFrameLength
, u16 wCurrentRate
);
124 static u16
s_vFillCTSHead(struct vnt_private
*pDevice
, u32 uDMAIdx
,
125 u8 byPktType
, union vnt_tx_data_head
*head
, u32 cbFrameLength
,
126 int bNeedAck
, u16 wCurrentRate
, u8 byFBOption
);
128 static u16
s_vFillRTSHead(struct vnt_private
*pDevice
, u8 byPktType
,
129 union vnt_tx_data_head
*head
, u32 cbFrameLength
, int bNeedAck
,
130 struct ethhdr
*psEthHeader
, u16 wCurrentRate
, u8 byFBOption
);
132 static u16
s_uGetDataDuration(struct vnt_private
*pDevice
,
133 u8 byPktType
, int bNeedAck
);
135 static u16
s_uGetRTSCTSDuration(struct vnt_private
*pDevice
,
136 u8 byDurType
, u32 cbFrameLength
, u8 byPktType
, u16 wRate
,
137 int bNeedAck
, u8 byFBOption
);
139 static struct vnt_usb_send_context
140 *s_vGetFreeContext(struct vnt_private
*priv
)
142 struct vnt_usb_send_context
*context
= NULL
;
145 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"GetFreeContext()\n");
147 for (ii
= 0; ii
< priv
->cbTD
; ii
++) {
151 context
= priv
->apTD
[ii
];
152 if (context
->bBoolInUse
== false) {
153 context
->bBoolInUse
= true;
154 memset(context
->Data
, 0,
155 MAX_TOTAL_SIZE_WITH_ALL_HEADERS
);
160 if (ii
== priv
->cbTD
)
161 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Free Tx Context\n");
166 static void s_vSaveTxPktInfo(struct vnt_private
*pDevice
, u8 byPktNum
,
167 u8
*pbyDestAddr
, u16 wPktLength
, u16 wFIFOCtl
)
169 struct net_device_stats
*stats
= &pDevice
->stats
;
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
,
185 stats
->tx_bytes
+= wPktLength
;
188 static void s_vFillTxKey(struct vnt_private
*pDevice
,
189 struct vnt_tx_fifo_head
*fifo_head
, u8
*pbyIVHead
,
190 PSKeyItem pTransmitKey
, u8
*pbyHdrBuf
, u16 wPayloadLen
,
191 struct vnt_mic_hdr
*mic_hdr
)
193 u8
*pbyBuf
= (u8
*)&fifo_head
->adwTxKey
[0];
194 u32
*pdwIV
= (u32
*)pbyIVHead
;
195 u32
*pdwExtIV
= (u32
*)((u8
*)pbyIVHead
+ 4);
196 struct ieee80211_hdr
*pMACHeader
= (struct ieee80211_hdr
*)pbyHdrBuf
;
200 if (pTransmitKey
== NULL
)
203 dwRevIVCounter
= cpu_to_le32(pDevice
->dwIVCounter
);
204 *pdwIV
= pDevice
->dwIVCounter
;
205 pDevice
->byKeyIndex
= pTransmitKey
->dwKeyIndex
& 0xf;
207 switch (pTransmitKey
->byCipherSuite
) {
209 if (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
) {
210 memcpy(pDevice
->abyPRNG
, (u8
*)&dwRevIVCounter
, 3);
211 memcpy(pDevice
->abyPRNG
+ 3, pTransmitKey
->abyKey
,
212 pTransmitKey
->uKeyLength
);
214 memcpy(pbyBuf
, (u8
*)&dwRevIVCounter
, 3);
215 memcpy(pbyBuf
+ 3, pTransmitKey
->abyKey
,
216 pTransmitKey
->uKeyLength
);
217 if (pTransmitKey
->uKeyLength
== WLAN_WEP40_KEYLEN
) {
218 memcpy(pbyBuf
+8, (u8
*)&dwRevIVCounter
, 3);
219 memcpy(pbyBuf
+11, pTransmitKey
->abyKey
,
220 pTransmitKey
->uKeyLength
);
223 memcpy(pDevice
->abyPRNG
, pbyBuf
, 16);
225 /* Append IV after Mac Header */
226 *pdwIV
&= WEP_IV_MASK
;
227 *pdwIV
|= (u32
)pDevice
->byKeyIndex
<< 30;
228 *pdwIV
= cpu_to_le32(*pdwIV
);
230 pDevice
->dwIVCounter
++;
231 if (pDevice
->dwIVCounter
> WEP_IV_MASK
)
232 pDevice
->dwIVCounter
= 0;
236 pTransmitKey
->wTSC15_0
++;
237 if (pTransmitKey
->wTSC15_0
== 0)
238 pTransmitKey
->dwTSC47_16
++;
240 TKIPvMixKey(pTransmitKey
->abyKey
, pDevice
->abyCurrentNetAddr
,
241 pTransmitKey
->wTSC15_0
, pTransmitKey
->dwTSC47_16
,
243 memcpy(pbyBuf
, pDevice
->abyPRNG
, 16);
246 memcpy(pdwIV
, pDevice
->abyPRNG
, 3);
248 *(pbyIVHead
+3) = (u8
)(((pDevice
->byKeyIndex
<< 6) &
250 /* Append IV&ExtIV after Mac Header */
251 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
253 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
254 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV
);
258 pTransmitKey
->wTSC15_0
++;
259 if (pTransmitKey
->wTSC15_0
== 0)
260 pTransmitKey
->dwTSC47_16
++;
262 memcpy(pbyBuf
, pTransmitKey
->abyKey
, 16);
266 *(pbyIVHead
+3) = (u8
)(((pDevice
->byKeyIndex
<< 6) &
269 *pdwIV
|= cpu_to_le16((u16
)(pTransmitKey
->wTSC15_0
));
271 /* Append IV&ExtIV after Mac Header */
272 *pdwExtIV
= cpu_to_le32(pTransmitKey
->dwTSC47_16
);
279 mic_hdr
->payload_len
= cpu_to_be16(wPayloadLen
);
280 memcpy(mic_hdr
->mic_addr2
, pMACHeader
->addr2
, ETH_ALEN
);
282 mic_hdr
->tsc_47_16
= cpu_to_be32(pTransmitKey
->dwTSC47_16
);
283 mic_hdr
->tsc_15_0
= cpu_to_be16(pTransmitKey
->wTSC15_0
);
286 if (ieee80211_has_a4(pMACHeader
->frame_control
))
287 mic_hdr
->hlen
= cpu_to_be16(28);
289 mic_hdr
->hlen
= cpu_to_be16(22);
291 memcpy(mic_hdr
->addr1
, pMACHeader
->addr1
, ETH_ALEN
);
292 memcpy(mic_hdr
->addr2
, pMACHeader
->addr2
, ETH_ALEN
);
295 memcpy(mic_hdr
->addr3
, pMACHeader
->addr3
, ETH_ALEN
);
296 mic_hdr
->frame_control
= cpu_to_le16(pMACHeader
->frame_control
298 mic_hdr
->seq_ctrl
= cpu_to_le16(pMACHeader
->seq_ctrl
& 0xf);
300 if (ieee80211_has_a4(pMACHeader
->frame_control
))
301 memcpy(mic_hdr
->addr4
, pMACHeader
->addr4
, ETH_ALEN
);
305 static void s_vSWencryption(struct vnt_private
*pDevice
,
306 PSKeyItem pTransmitKey
, u8
*pbyPayloadHead
, u16 wPayloadSize
)
309 u32 dwICV
= 0xffffffff;
312 if (pTransmitKey
== NULL
)
315 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
316 //=======================================================================
317 // Append ICV after payload
318 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
319 pdwICV
= (u32
*)(pbyPayloadHead
+ wPayloadSize
);
320 // finally, we must invert dwCRC to get the correct answer
321 *pdwICV
= cpu_to_le32(~dwICV
);
323 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pTransmitKey
->uKeyLength
+ 3);
324 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
325 //=======================================================================
326 } else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
327 //=======================================================================
328 //Append ICV after payload
329 dwICV
= CRCdwGetCrc32Ex(pbyPayloadHead
, wPayloadSize
, dwICV
);//ICV(Payload)
330 pdwICV
= (u32
*)(pbyPayloadHead
+ wPayloadSize
);
331 // finally, we must invert dwCRC to get the correct answer
332 *pdwICV
= cpu_to_le32(~dwICV
);
334 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
335 rc4_encrypt(&pDevice
->SBox
, pbyPayloadHead
, pbyPayloadHead
, wPayloadSize
+cbICVlen
);
336 //=======================================================================
340 static u16
vnt_time_stamp_off(struct vnt_private
*priv
, u16 rate
)
342 return cpu_to_le16(wTimeStampOff
[priv
->byPreambleType
% 2]
346 /*byPktType : PK_TYPE_11A 0
351 static u32
s_uGetTxRsvTime(struct vnt_private
*pDevice
, u8 byPktType
,
352 u32 cbFrameLength
, u16 wRate
, int bNeedAck
)
354 u32 uDataTime
, uAckTime
;
356 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wRate
);
357 if (byPktType
== PK_TYPE_11B
) {//llb,CCK mode
358 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (u16
)pDevice
->byTopCCKBasicRate
);
359 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
360 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, (u16
)pDevice
->byTopOFDMBasicRate
);
364 return (uDataTime
+ pDevice
->uSIFS
+ uAckTime
);
371 static u16
vnt_rxtx_rsvtime_le16(struct vnt_private
*priv
, u8 pkt_type
,
372 u32 frame_length
, u16 rate
, int need_ack
)
374 return cpu_to_le16((u16
)s_uGetTxRsvTime(priv
, pkt_type
,
375 frame_length
, rate
, need_ack
));
378 //byFreqType: 0=>5GHZ 1=>2.4GHZ
379 static u16
s_uGetRTSCTSRsvTime(struct vnt_private
*pDevice
,
380 u8 byRTSRsvType
, u8 byPktType
, u32 cbFrameLength
, u16 wCurrentRate
)
382 u32 uRrvTime
, uRTSTime
, uCTSTime
, uAckTime
, uDataTime
;
384 uRrvTime
= uRTSTime
= uCTSTime
= uAckTime
= uDataTime
= 0;
386 uDataTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, cbFrameLength
, wCurrentRate
);
387 if (byRTSRsvType
== 0) { //RTSTxRrvTime_bb
388 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
389 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
391 else if (byRTSRsvType
== 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
392 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopCCKBasicRate
);
393 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
394 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
396 else if (byRTSRsvType
== 2) { //RTSTxRrvTime_aa
397 uRTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 20, pDevice
->byTopOFDMBasicRate
);
398 uCTSTime
= uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
400 else if (byRTSRsvType
== 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
401 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopCCKBasicRate
);
402 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
403 uRrvTime
= uCTSTime
+ uAckTime
+ uDataTime
+ 2*pDevice
->uSIFS
;
408 uRrvTime
= uRTSTime
+ uCTSTime
+ uAckTime
+ uDataTime
+ 3*pDevice
->uSIFS
;
409 return cpu_to_le16((u16
)uRrvTime
);
412 //byFreqType 0: 5GHz, 1:2.4Ghz
413 static u16
s_uGetDataDuration(struct vnt_private
*pDevice
,
414 u8 byPktType
, int bNeedAck
)
419 if (byPktType
== PK_TYPE_11B
)
420 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
,
421 byPktType
, 14, pDevice
->byTopCCKBasicRate
);
423 uAckTime
= BBuGetFrameTime(pDevice
->byPreambleType
,
424 byPktType
, 14, pDevice
->byTopOFDMBasicRate
);
425 return cpu_to_le16((u16
)(pDevice
->uSIFS
+ uAckTime
));
431 //byFreqType: 0=>5GHZ 1=>2.4GHZ
432 static u16
s_uGetRTSCTSDuration(struct vnt_private
*pDevice
, u8 byDurType
,
433 u32 cbFrameLength
, u8 byPktType
, u16 wRate
, int bNeedAck
,
436 u32 uCTSTime
= 0, uDurTime
= 0;
443 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
,
444 14, pDevice
->byTopCCKBasicRate
);
445 uDurTime
= uCTSTime
+ 2 * pDevice
->uSIFS
+
446 s_uGetTxRsvTime(pDevice
, byPktType
,
447 cbFrameLength
, wRate
, bNeedAck
);
453 uCTSTime
= BBuGetFrameTime(pDevice
->byPreambleType
, byPktType
,
454 14, pDevice
->byTopOFDMBasicRate
);
455 uDurTime
= uCTSTime
+ 2 * pDevice
->uSIFS
+
456 s_uGetTxRsvTime(pDevice
, byPktType
,
457 cbFrameLength
, wRate
, bNeedAck
);
463 uDurTime
= pDevice
->uSIFS
+ s_uGetTxRsvTime(pDevice
,
464 byPktType
, cbFrameLength
, wRate
, bNeedAck
);
471 return cpu_to_le16((u16
)uDurTime
);
474 static u16
vnt_rxtx_datahead_g(struct vnt_private
*priv
, u8 pkt_type
, u16 rate
,
475 struct vnt_tx_datahead_g
*buf
, u32 frame_len
, int need_ack
)
477 /* Get SignalField,ServiceField,Length */
478 BBvCalculateParameter(priv
, frame_len
, rate
, pkt_type
, &buf
->a
);
479 BBvCalculateParameter(priv
, frame_len
, priv
->byTopCCKBasicRate
,
480 PK_TYPE_11B
, &buf
->b
);
482 /* Get Duration and TimeStamp */
483 buf
->wDuration_a
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
484 buf
->wDuration_b
= s_uGetDataDuration(priv
, PK_TYPE_11B
, need_ack
);
486 buf
->wTimeStampOff_a
= vnt_time_stamp_off(priv
, rate
);
487 buf
->wTimeStampOff_b
= vnt_time_stamp_off(priv
,
488 priv
->byTopCCKBasicRate
);
490 return buf
->wDuration_a
;
493 static u16
vnt_rxtx_datahead_g_fb(struct vnt_private
*priv
, u8 pkt_type
,
494 u16 rate
, struct vnt_tx_datahead_g_fb
*buf
,
495 u32 frame_len
, int need_ack
)
497 /* Get SignalField,ServiceField,Length */
498 BBvCalculateParameter(priv
, frame_len
, rate
, pkt_type
, &buf
->a
);
500 BBvCalculateParameter(priv
, frame_len
, priv
->byTopCCKBasicRate
,
501 PK_TYPE_11B
, &buf
->b
);
503 /* Get Duration and TimeStamp */
504 buf
->wDuration_a
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
505 buf
->wDuration_b
= s_uGetDataDuration(priv
, PK_TYPE_11B
, need_ack
);
507 buf
->wDuration_a_f0
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
508 buf
->wDuration_a_f1
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
510 buf
->wTimeStampOff_a
= vnt_time_stamp_off(priv
, rate
);
511 buf
->wTimeStampOff_b
= vnt_time_stamp_off(priv
,
512 priv
->byTopCCKBasicRate
);
514 return buf
->wDuration_a
;
517 static u16
vnt_rxtx_datahead_a_fb(struct vnt_private
*priv
, u8 pkt_type
,
518 u16 rate
, struct vnt_tx_datahead_a_fb
*buf
,
519 u32 frame_len
, int need_ack
)
521 /* Get SignalField,ServiceField,Length */
522 BBvCalculateParameter(priv
, frame_len
, rate
, pkt_type
, &buf
->a
);
523 /* Get Duration and TimeStampOff */
524 buf
->wDuration
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
526 buf
->wDuration_f0
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
527 buf
->wDuration_f1
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
529 buf
->wTimeStampOff
= vnt_time_stamp_off(priv
, rate
);
531 return buf
->wDuration
;
534 static u16
vnt_rxtx_datahead_ab(struct vnt_private
*priv
, u8 pkt_type
,
535 u16 rate
, struct vnt_tx_datahead_ab
*buf
,
536 u32 frame_len
, int need_ack
)
538 /* Get SignalField,ServiceField,Length */
539 BBvCalculateParameter(priv
, frame_len
, rate
, pkt_type
, &buf
->ab
);
540 /* Get Duration and TimeStampOff */
541 buf
->wDuration
= s_uGetDataDuration(priv
, pkt_type
, need_ack
);
543 buf
->wTimeStampOff
= vnt_time_stamp_off(priv
, rate
);
545 return buf
->wDuration
;
548 static int vnt_fill_ieee80211_rts(struct vnt_private
*priv
,
549 struct ieee80211_rts
*rts
, struct ethhdr
*eth_hdr
,
552 rts
->duration
= duration
;
553 rts
->frame_control
= TYPE_CTL_RTS
;
555 if (priv
->eOPMode
== OP_MODE_ADHOC
|| priv
->eOPMode
== OP_MODE_AP
)
556 memcpy(rts
->ra
, eth_hdr
->h_dest
, ETH_ALEN
);
558 memcpy(rts
->ra
, priv
->abyBSSID
, ETH_ALEN
);
560 if (priv
->eOPMode
== OP_MODE_AP
)
561 memcpy(rts
->ta
, priv
->abyBSSID
, ETH_ALEN
);
563 memcpy(rts
->ta
, eth_hdr
->h_source
, ETH_ALEN
);
568 static u16
vnt_rxtx_rts_g_head(struct vnt_private
*priv
,
569 struct vnt_rts_g
*buf
, struct ethhdr
*eth_hdr
,
570 u8 pkt_type
, u32 frame_len
, int need_ack
,
571 u16 current_rate
, u8 fb_option
)
573 u16 rts_frame_len
= 20;
575 BBvCalculateParameter(priv
, rts_frame_len
, priv
->byTopCCKBasicRate
,
576 PK_TYPE_11B
, &buf
->b
);
577 BBvCalculateParameter(priv
, rts_frame_len
,
578 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->a
);
580 buf
->wDuration_bb
= s_uGetRTSCTSDuration(priv
, RTSDUR_BB
, frame_len
,
581 PK_TYPE_11B
, priv
->byTopCCKBasicRate
, need_ack
, fb_option
);
582 buf
->wDuration_aa
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
583 pkt_type
, current_rate
, need_ack
, fb_option
);
584 buf
->wDuration_ba
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA
, frame_len
,
585 pkt_type
, current_rate
, need_ack
, fb_option
);
587 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration_aa
);
589 return vnt_rxtx_datahead_g(priv
, pkt_type
, current_rate
,
590 &buf
->data_head
, frame_len
, need_ack
);
593 static u16
vnt_rxtx_rts_g_fb_head(struct vnt_private
*priv
,
594 struct vnt_rts_g_fb
*buf
, struct ethhdr
*eth_hdr
,
595 u8 pkt_type
, u32 frame_len
, int need_ack
,
596 u16 current_rate
, u8 fb_option
)
598 u16 rts_frame_len
= 20;
600 BBvCalculateParameter(priv
, rts_frame_len
, priv
->byTopCCKBasicRate
,
601 PK_TYPE_11B
, &buf
->b
);
602 BBvCalculateParameter(priv
, rts_frame_len
,
603 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->a
);
606 buf
->wDuration_bb
= s_uGetRTSCTSDuration(priv
, RTSDUR_BB
, frame_len
,
607 PK_TYPE_11B
, priv
->byTopCCKBasicRate
, need_ack
, fb_option
);
608 buf
->wDuration_aa
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
609 pkt_type
, current_rate
, need_ack
, fb_option
);
610 buf
->wDuration_ba
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA
, frame_len
,
611 pkt_type
, current_rate
, need_ack
, fb_option
);
614 buf
->wRTSDuration_ba_f0
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA_F0
,
615 frame_len
, pkt_type
, priv
->tx_rate_fb0
, need_ack
, fb_option
);
616 buf
->wRTSDuration_aa_f0
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F0
,
617 frame_len
, pkt_type
, priv
->tx_rate_fb0
, need_ack
, fb_option
);
618 buf
->wRTSDuration_ba_f1
= s_uGetRTSCTSDuration(priv
, RTSDUR_BA_F1
,
619 frame_len
, pkt_type
, priv
->tx_rate_fb1
, need_ack
, fb_option
);
620 buf
->wRTSDuration_aa_f1
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F1
,
621 frame_len
, pkt_type
, priv
->tx_rate_fb1
, need_ack
, fb_option
);
623 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration_aa
);
625 return vnt_rxtx_datahead_g_fb(priv
, pkt_type
, current_rate
,
626 &buf
->data_head
, frame_len
, need_ack
);
629 static u16
vnt_rxtx_rts_ab_head(struct vnt_private
*priv
,
630 struct vnt_rts_ab
*buf
, struct ethhdr
*eth_hdr
,
631 u8 pkt_type
, u32 frame_len
, int need_ack
,
632 u16 current_rate
, u8 fb_option
)
634 u16 rts_frame_len
= 20;
636 BBvCalculateParameter(priv
, rts_frame_len
,
637 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->ab
);
639 buf
->wDuration
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
640 pkt_type
, current_rate
, need_ack
, fb_option
);
642 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration
);
644 return vnt_rxtx_datahead_ab(priv
, pkt_type
, current_rate
,
645 &buf
->data_head
, frame_len
, need_ack
);
648 static u16
vnt_rxtx_rts_a_fb_head(struct vnt_private
*priv
,
649 struct vnt_rts_a_fb
*buf
, struct ethhdr
*eth_hdr
,
650 u8 pkt_type
, u32 frame_len
, int need_ack
,
651 u16 current_rate
, u8 fb_option
)
653 u16 rts_frame_len
= 20;
655 BBvCalculateParameter(priv
, rts_frame_len
,
656 priv
->byTopOFDMBasicRate
, pkt_type
, &buf
->a
);
658 buf
->wDuration
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA
, frame_len
,
659 pkt_type
, current_rate
, need_ack
, fb_option
);
661 buf
->wRTSDuration_f0
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F0
,
662 frame_len
, pkt_type
, priv
->tx_rate_fb0
, need_ack
, fb_option
);
664 buf
->wRTSDuration_f1
= s_uGetRTSCTSDuration(priv
, RTSDUR_AA_F1
,
665 frame_len
, pkt_type
, priv
->tx_rate_fb1
, need_ack
, fb_option
);
667 vnt_fill_ieee80211_rts(priv
, &buf
->data
, eth_hdr
, buf
->wDuration
);
669 return vnt_rxtx_datahead_a_fb(priv
, pkt_type
, current_rate
,
670 &buf
->data_head
, frame_len
, need_ack
);
673 static u16
s_vFillRTSHead(struct vnt_private
*pDevice
, u8 byPktType
,
674 union vnt_tx_data_head
*head
, u32 cbFrameLength
, int bNeedAck
,
675 struct ethhdr
*psEthHeader
, u16 wCurrentRate
, u8 byFBOption
)
681 /* Note: So far RTSHead doesn't appear in ATIM
682 * & Beacom DMA, so we don't need to take them
684 * Otherwise, we need to modified codes for them.
689 if (byFBOption
== AUTO_FB_NONE
)
690 return vnt_rxtx_rts_g_head(pDevice
, &head
->rts_g
,
691 psEthHeader
, byPktType
, cbFrameLength
,
692 bNeedAck
, wCurrentRate
, byFBOption
);
694 return vnt_rxtx_rts_g_fb_head(pDevice
, &head
->rts_g_fb
,
695 psEthHeader
, byPktType
, cbFrameLength
,
696 bNeedAck
, wCurrentRate
, byFBOption
);
700 return vnt_rxtx_rts_a_fb_head(pDevice
, &head
->rts_a_fb
,
701 psEthHeader
, byPktType
, cbFrameLength
,
702 bNeedAck
, wCurrentRate
, byFBOption
);
706 return vnt_rxtx_rts_ab_head(pDevice
, &head
->rts_ab
,
707 psEthHeader
, byPktType
, cbFrameLength
,
708 bNeedAck
, wCurrentRate
, byFBOption
);
714 static u16
s_vFillCTSHead(struct vnt_private
*pDevice
, u32 uDMAIdx
,
715 u8 byPktType
, union vnt_tx_data_head
*head
, u32 cbFrameLength
,
716 int bNeedAck
, u16 wCurrentRate
, u8 byFBOption
)
718 u32 uCTSFrameLen
= 14;
723 if (byFBOption
!= AUTO_FB_NONE
) {
725 struct vnt_cts_fb
*pBuf
= &head
->cts_g_fb
;
726 /* Get SignalField,ServiceField,Length */
727 BBvCalculateParameter(pDevice
, uCTSFrameLen
,
728 pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
, &pBuf
->b
);
729 pBuf
->wDuration_ba
= s_uGetRTSCTSDuration(pDevice
, CTSDUR_BA
,
730 cbFrameLength
, byPktType
,
731 wCurrentRate
, bNeedAck
, byFBOption
);
732 /* Get CTSDuration_ba_f0 */
733 pBuf
->wCTSDuration_ba_f0
= s_uGetRTSCTSDuration(pDevice
,
734 CTSDUR_BA_F0
, cbFrameLength
, byPktType
,
735 pDevice
->tx_rate_fb0
, bNeedAck
, byFBOption
);
736 /* Get CTSDuration_ba_f1 */
737 pBuf
->wCTSDuration_ba_f1
= s_uGetRTSCTSDuration(pDevice
,
738 CTSDUR_BA_F1
, cbFrameLength
, byPktType
,
739 pDevice
->tx_rate_fb1
, bNeedAck
, byFBOption
);
740 /* Get CTS Frame body */
741 pBuf
->data
.duration
= pBuf
->wDuration_ba
;
742 pBuf
->data
.frame_control
= TYPE_CTL_CTS
;
743 memcpy(pBuf
->data
.ra
, pDevice
->abyCurrentNetAddr
, ETH_ALEN
);
745 return vnt_rxtx_datahead_g_fb(pDevice
, byPktType
, wCurrentRate
,
746 &pBuf
->data_head
, cbFrameLength
, bNeedAck
);
748 struct vnt_cts
*pBuf
= &head
->cts_g
;
749 /* Get SignalField,ServiceField,Length */
750 BBvCalculateParameter(pDevice
, uCTSFrameLen
,
751 pDevice
->byTopCCKBasicRate
, PK_TYPE_11B
, &pBuf
->b
);
752 /* Get CTSDuration_ba */
753 pBuf
->wDuration_ba
= s_uGetRTSCTSDuration(pDevice
,
754 CTSDUR_BA
, cbFrameLength
, byPktType
,
755 wCurrentRate
, bNeedAck
, byFBOption
);
756 /*Get CTS Frame body*/
757 pBuf
->data
.duration
= pBuf
->wDuration_ba
;
758 pBuf
->data
.frame_control
= TYPE_CTL_CTS
;
759 memcpy(pBuf
->data
.ra
, pDevice
->abyCurrentNetAddr
, ETH_ALEN
);
761 return vnt_rxtx_datahead_g(pDevice
, byPktType
, wCurrentRate
,
762 &pBuf
->data_head
, cbFrameLength
, bNeedAck
);
771 * Generate FIFO control for MAC & Baseband controller
775 * pDevice - Pointer to adpater
776 * pTxDataHead - Transmit Data Buffer
777 * pTxBufHead - pTxBufHead
778 * pvRrvTime - pvRrvTime
781 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
782 * bNeedACK - If need ACK
783 * uDMAIdx - DMA Index
791 static u16
s_vGenerateTxParameter(struct vnt_private
*pDevice
,
792 u8 byPktType
, u16 wCurrentRate
, struct vnt_tx_buffer
*tx_buffer
,
793 struct vnt_mic_hdr
**mic_hdr
, u32 need_mic
, u32 cbFrameSize
,
794 int bNeedACK
, u32 uDMAIdx
, struct ethhdr
*psEthHeader
, bool need_rts
)
796 struct vnt_tx_fifo_head
*pFifoHead
= &tx_buffer
->fifo_head
;
797 union vnt_tx_data_head
*head
= NULL
;
799 u8 byFBOption
= AUTO_FB_NONE
;
801 pFifoHead
->wReserved
= wCurrentRate
;
802 wFifoCtl
= pFifoHead
->wFIFOCtl
;
804 if (wFifoCtl
& FIFOCTL_AUTO_FB_0
)
805 byFBOption
= AUTO_FB_0
;
806 else if (wFifoCtl
& FIFOCTL_AUTO_FB_1
)
807 byFBOption
= AUTO_FB_1
;
812 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
814 struct vnt_rrv_time_rts
*pBuf
=
815 &tx_buffer
->tx_head
.tx_rts
.rts
;
817 pBuf
->wRTSTxRrvTime_aa
= s_uGetRTSCTSRsvTime(pDevice
, 2,
818 byPktType
, cbFrameSize
, wCurrentRate
);
819 pBuf
->wRTSTxRrvTime_ba
= s_uGetRTSCTSRsvTime(pDevice
, 1,
820 byPktType
, cbFrameSize
, wCurrentRate
);
821 pBuf
->wRTSTxRrvTime_bb
= s_uGetRTSCTSRsvTime(pDevice
, 0,
822 byPktType
, cbFrameSize
, wCurrentRate
);
824 pBuf
->wTxRrvTime_a
= vnt_rxtx_rsvtime_le16(pDevice
,
825 byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
);
826 pBuf
->wTxRrvTime_b
= vnt_rxtx_rsvtime_le16(pDevice
,
827 PK_TYPE_11B
, cbFrameSize
,
828 pDevice
->byTopCCKBasicRate
, bNeedACK
);
831 *mic_hdr
= &tx_buffer
->
832 tx_head
.tx_rts
.tx
.mic
.hdr
;
833 head
= &tx_buffer
->tx_head
.tx_rts
.tx
.mic
.head
;
835 head
= &tx_buffer
->tx_head
.tx_rts
.tx
.head
;
839 return s_vFillRTSHead(pDevice
, byPktType
, head
,
840 cbFrameSize
, bNeedACK
, psEthHeader
,
841 wCurrentRate
, byFBOption
);
844 struct vnt_rrv_time_cts
*pBuf
= &tx_buffer
->
847 pBuf
->wTxRrvTime_a
= vnt_rxtx_rsvtime_le16(pDevice
,
848 byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
);
849 pBuf
->wTxRrvTime_b
= vnt_rxtx_rsvtime_le16(pDevice
,
850 PK_TYPE_11B
, cbFrameSize
,
851 pDevice
->byTopCCKBasicRate
, bNeedACK
);
853 pBuf
->wCTSTxRrvTime_ba
= s_uGetRTSCTSRsvTime(pDevice
, 3,
854 byPktType
, cbFrameSize
, wCurrentRate
);
857 *mic_hdr
= &tx_buffer
->
858 tx_head
.tx_cts
.tx
.mic
.hdr
;
859 head
= &tx_buffer
->tx_head
.tx_cts
.tx
.mic
.head
;
861 head
= &tx_buffer
->tx_head
.tx_cts
.tx
.head
;
865 return s_vFillCTSHead(pDevice
, uDMAIdx
, byPktType
,
866 head
, cbFrameSize
, bNeedACK
, wCurrentRate
,
869 } else if (byPktType
== PK_TYPE_11A
) {
871 *mic_hdr
= &tx_buffer
->tx_head
.tx_ab
.tx
.mic
.hdr
;
872 head
= &tx_buffer
->tx_head
.tx_ab
.tx
.mic
.head
;
874 head
= &tx_buffer
->tx_head
.tx_ab
.tx
.head
;
878 struct vnt_rrv_time_ab
*pBuf
= &tx_buffer
->
881 pBuf
->wRTSTxRrvTime
= s_uGetRTSCTSRsvTime(pDevice
, 2,
882 byPktType
, cbFrameSize
, wCurrentRate
);
884 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
,
885 byPktType
, cbFrameSize
, wCurrentRate
, bNeedACK
);
888 return s_vFillRTSHead(pDevice
, byPktType
, head
,
889 cbFrameSize
, bNeedACK
, psEthHeader
,
890 wCurrentRate
, byFBOption
);
892 struct vnt_rrv_time_ab
*pBuf
= &tx_buffer
->
895 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
,
896 PK_TYPE_11A
, cbFrameSize
,
897 wCurrentRate
, bNeedACK
);
899 return vnt_rxtx_datahead_a_fb(pDevice
, byPktType
,
900 wCurrentRate
, &head
->data_head_a_fb
,
901 cbFrameSize
, bNeedACK
);
903 } else if (byPktType
== PK_TYPE_11B
) {
905 *mic_hdr
= &tx_buffer
->tx_head
.tx_ab
.tx
.mic
.hdr
;
906 head
= &tx_buffer
->tx_head
.tx_ab
.tx
.mic
.head
;
908 head
= &tx_buffer
->tx_head
.tx_ab
.tx
.head
;
912 struct vnt_rrv_time_ab
*pBuf
= &tx_buffer
->
915 pBuf
->wRTSTxRrvTime
= s_uGetRTSCTSRsvTime(pDevice
, 0,
916 byPktType
, cbFrameSize
, wCurrentRate
);
918 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
,
919 PK_TYPE_11B
, cbFrameSize
, wCurrentRate
,
923 return s_vFillRTSHead(pDevice
, byPktType
, head
,
925 bNeedACK
, psEthHeader
, wCurrentRate
, byFBOption
);
927 struct vnt_rrv_time_ab
*pBuf
= &tx_buffer
->
930 pBuf
->wTxRrvTime
= vnt_rxtx_rsvtime_le16(pDevice
,
931 PK_TYPE_11B
, cbFrameSize
,
932 wCurrentRate
, bNeedACK
);
934 return vnt_rxtx_datahead_ab(pDevice
, byPktType
,
935 wCurrentRate
, &head
->data_head_ab
,
936 cbFrameSize
, bNeedACK
);
943 u8 * pbyBuffer,//point to pTxBufHead
944 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
945 unsigned int cbFragmentSize,//Hdr+payoad+FCS
948 static int s_bPacketToWirelessUsb(struct vnt_private
*pDevice
, u8 byPktType
,
949 struct vnt_tx_buffer
*tx_buffer
, int bNeedEncryption
,
950 u32 uSkbPacketLen
, u32 uDMAIdx
, struct ethhdr
*psEthHeader
,
951 u8
*pPacket
, PSKeyItem pTransmitKey
, u32 uNodeIndex
, u16 wCurrentRate
,
952 u32
*pcbHeaderLen
, u32
*pcbTotalLen
)
954 struct vnt_tx_fifo_head
*pTxBufHead
= &tx_buffer
->fifo_head
;
955 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
956 u32 cbFrameSize
, cbFrameBodySize
;
958 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbMACHdLen
= 0;
959 u32 cbFCSlen
= 4, cbMICHDR
= 0;
962 u8
*pbyType
, *pbyMacHdr
, *pbyIVHead
, *pbyPayloadHead
, *pbyTxBufferAddr
;
963 u8 abySNAP_RFC1042
[ETH_ALEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
964 u8 abySNAP_Bridgetunnel
[ETH_ALEN
]
965 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
967 u32 cbHeaderLength
= 0, uPadding
= 0;
968 struct vnt_mic_hdr
*pMICHDR
;
969 u8 byFBOption
= AUTO_FB_NONE
, byFragType
;
971 u32 dwMICKey0
, dwMICKey1
, dwMIC_Priority
;
972 u32
*pdwMIC_L
, *pdwMIC_R
;
973 int bSoftWEP
= false;
977 if (bNeedEncryption
&& pTransmitKey
->pvKeyTable
) {
978 if (((PSKeyTable
)pTransmitKey
->pvKeyTable
)->bSoftWEP
== true)
979 bSoftWEP
= true; /* WEP 256 */
983 if (ntohs(psEthHeader
->h_proto
) > ETH_DATA_LEN
)
988 cbFrameBodySize
= uSkbPacketLen
- ETH_HLEN
+ cb802_1_H_len
;
991 pTxBufHead
->wFIFOCtl
|= (u16
)(byPktType
<<8);
993 if ((pDevice
->eOPMode
== OP_MODE_ADHOC
) ||
994 (pDevice
->eOPMode
== OP_MODE_AP
)) {
995 if (is_multicast_ether_addr(psEthHeader
->h_dest
)) {
997 pTxBufHead
->wFIFOCtl
=
998 pTxBufHead
->wFIFOCtl
& (~FIFOCTL_NEEDACK
);
1001 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1004 /* MSDUs in Infra mode always need ACK */
1006 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1009 pTxBufHead
->wTimeStamp
= DEFAULT_MSDU_LIFETIME_RES_64us
;
1011 //Set FRAGCTL_MACHDCNT
1012 cbMACHdLen
= WLAN_HDR_ADDR3_LEN
;
1014 pTxBufHead
->wFragCtl
|= (u16
)(cbMACHdLen
<< 10);
1016 //Set FIFOCTL_GrpAckPolicy
1017 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1018 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1021 /* Set Auto Fallback Ctl */
1022 if (wCurrentRate
>= RATE_18M
) {
1023 if (pDevice
->byAutoFBCtrl
== AUTO_FB_0
) {
1024 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_0
;
1026 pDevice
->tx_rate_fb0
=
1027 wFB_Opt0
[FB_RATE0
][wCurrentRate
- RATE_18M
];
1028 pDevice
->tx_rate_fb1
=
1029 wFB_Opt0
[FB_RATE1
][wCurrentRate
- RATE_18M
];
1031 byFBOption
= AUTO_FB_0
;
1032 } else if (pDevice
->byAutoFBCtrl
== AUTO_FB_1
) {
1033 pTxBufHead
->wFIFOCtl
|= FIFOCTL_AUTO_FB_1
;
1034 pDevice
->tx_rate_fb0
=
1035 wFB_Opt1
[FB_RATE0
][wCurrentRate
- RATE_18M
];
1036 pDevice
->tx_rate_fb1
=
1037 wFB_Opt1
[FB_RATE1
][wCurrentRate
- RATE_18M
];
1039 byFBOption
= AUTO_FB_1
;
1043 if (bSoftWEP
!= true) {
1044 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) { //WEP enabled
1045 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) { //WEP40 or WEP104
1046 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1048 if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1049 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1050 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1052 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) { //CCMP
1053 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1058 if ((bNeedEncryption
) && (pTransmitKey
!= NULL
)) {
1059 if (pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) {
1063 else if (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
) {
1064 cbIVlen
= 8;//IV+ExtIV
1068 if (pTransmitKey
->byCipherSuite
== KEY_CTL_CCMP
) {
1069 cbIVlen
= 8;//RSN Header
1071 cbMICHDR
= sizeof(struct vnt_mic_hdr
);
1073 if (bSoftWEP
== false) {
1074 //MAC Header should be padding 0 to DW alignment.
1075 uPadding
= 4 - (cbMACHdLen
%4);
1080 cbFrameSize
= cbMACHdLen
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbICVlen
+ cbFCSlen
;
1082 if ( (bNeedACK
== false) ||(cbFrameSize
< pDevice
->wRTSThreshold
) ) {
1086 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_RTS
| FIFOCTL_LRETRY
);
1089 pbyTxBufferAddr
= (u8
*) &(pTxBufHead
->adwTxKey
[0]);
1090 wTxBufSize
= sizeof(struct vnt_tx_fifo_head
);
1092 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1093 if (byFBOption
== AUTO_FB_NONE
) {
1094 if (bRTS
== true) {//RTS_need
1095 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_rts
) +
1096 cbMICHDR
+ sizeof(struct vnt_rts_g
);
1098 else { //RTS_needless
1099 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1100 cbMICHDR
+ sizeof(struct vnt_cts
);
1104 if (bRTS
== true) {//RTS_need
1105 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_rts
) +
1106 cbMICHDR
+ sizeof(struct vnt_rts_g_fb
);
1108 else if (bRTS
== false) { //RTS_needless
1109 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1110 cbMICHDR
+ sizeof(struct vnt_cts_fb
);
1114 else {//802.11a/b packet
1115 if (byFBOption
== AUTO_FB_NONE
) {
1116 if (bRTS
== true) {//RTS_need
1117 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1118 cbMICHDR
+ sizeof(struct vnt_rts_ab
);
1120 else if (bRTS
== false) { //RTS_needless, no MICHDR
1121 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1122 cbMICHDR
+ sizeof(struct vnt_tx_datahead_ab
);
1126 if (bRTS
== true) {//RTS_need
1127 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1128 cbMICHDR
+ sizeof(struct vnt_rts_a_fb
);
1130 else if (bRTS
== false) { //RTS_needless
1131 cbHeaderLength
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1132 cbMICHDR
+ sizeof(struct vnt_tx_datahead_a_fb
);
1137 pbyMacHdr
= (u8
*)(pbyTxBufferAddr
+ cbHeaderLength
);
1138 pbyIVHead
= (u8
*)(pbyMacHdr
+ cbMACHdLen
+ uPadding
);
1139 pbyPayloadHead
= (u8
*)(pbyMacHdr
+ cbMACHdLen
+ uPadding
+ cbIVlen
);
1141 //=========================
1143 //=========================
1144 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"No Fragmentation...\n");
1145 byFragType
= FRAGCTL_NONFRAG
;
1146 //uDMAIdx = TYPE_AC0DMA;
1147 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1149 /* Fill FIFO, RrvTime, RTS and CTS */
1150 uDuration
= s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
1151 tx_buffer
, &pMICHDR
, cbMICHDR
,
1152 cbFrameSize
, bNeedACK
, uDMAIdx
, psEthHeader
, bRTS
);
1154 // Generate TX MAC Header
1155 s_vGenerateMACHeader(pDevice
, pbyMacHdr
, (u16
)uDuration
, psEthHeader
, bNeedEncryption
,
1156 byFragType
, uDMAIdx
, 0);
1158 if (bNeedEncryption
== true) {
1160 s_vFillTxKey(pDevice
, pTxBufHead
, pbyIVHead
, pTransmitKey
,
1161 pbyMacHdr
, (u16
)cbFrameBodySize
, pMICHDR
);
1163 if (pDevice
->bEnableHostWEP
) {
1164 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
1165 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
1170 if (ntohs(psEthHeader
->h_proto
) > ETH_DATA_LEN
) {
1171 if ((psEthHeader
->h_proto
== cpu_to_be16(ETH_P_IPX
)) ||
1172 (psEthHeader
->h_proto
== cpu_to_le16(0xF380)))
1173 memcpy((u8
*) (pbyPayloadHead
),
1174 abySNAP_Bridgetunnel
, 6);
1176 memcpy((u8
*) (pbyPayloadHead
), &abySNAP_RFC1042
[0], 6);
1178 pbyType
= (u8
*) (pbyPayloadHead
+ 6);
1180 memcpy(pbyType
, &(psEthHeader
->h_proto
), sizeof(u16
));
1183 if (pPacket
!= NULL
) {
1184 // Copy the Packet into a tx Buffer
1185 memcpy((pbyPayloadHead
+ cb802_1_H_len
),
1186 (pPacket
+ ETH_HLEN
),
1187 uSkbPacketLen
- ETH_HLEN
1191 // while bRelayPacketSend psEthHeader is point to header+payload
1192 memcpy((pbyPayloadHead
+ cb802_1_H_len
), ((u8
*)psEthHeader
) + ETH_HLEN
, uSkbPacketLen
- ETH_HLEN
);
1195 if ((bNeedEncryption
== true) && (pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1197 ///////////////////////////////////////////////////////////////////
1199 if (pDevice
->vnt_mgmt
.eAuthenMode
== WMAC_AUTH_WPANONE
) {
1200 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
1201 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
1203 else if ((pTransmitKey
->dwKeyIndex
& AUTHENTICATOR_KEY
) != 0) {
1204 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
1205 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
1208 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[24]);
1209 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[28]);
1211 // DO Software Michael
1212 MIC_vInit(dwMICKey0
, dwMICKey1
);
1213 MIC_vAppend((u8
*)&(psEthHeader
->h_dest
[0]), 12);
1215 MIC_vAppend((u8
*)&dwMIC_Priority
, 4);
1216 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC KEY: %X, %X\n",
1217 dwMICKey0
, dwMICKey1
);
1219 ///////////////////////////////////////////////////////////////////
1221 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1222 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1223 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
1225 //DBG_PRN_GRP12(("\n\n\n"));
1227 MIC_vAppend(pbyPayloadHead
, cbFrameBodySize
);
1229 pdwMIC_L
= (u32
*)(pbyPayloadHead
+ cbFrameBodySize
);
1230 pdwMIC_R
= (u32
*)(pbyPayloadHead
+ cbFrameBodySize
+ 4);
1232 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1235 if (pDevice
->bTxMICFail
== true) {
1238 pDevice
->bTxMICFail
= false;
1240 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1241 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1242 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1245 if (bSoftWEP
== true) {
1247 s_vSWencryption(pDevice
, pTransmitKey
, (pbyPayloadHead
), (u16
)(cbFrameBodySize
+ cbMIClen
));
1249 } else if ( ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) && (bNeedEncryption
== true)) ||
1250 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) && (bNeedEncryption
== true)) ||
1251 ((pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) && (bNeedEncryption
== true)) ) {
1252 cbFrameSize
-= cbICVlen
;
1255 cbFrameSize
-= cbFCSlen
;
1257 *pcbHeaderLen
= cbHeaderLength
;
1258 *pcbTotalLen
= cbHeaderLength
+ cbFrameSize
;
1260 //Set FragCtl in TxBufferHead
1261 pTxBufHead
->wFragCtl
|= (u16
)byFragType
;
1270 * Translate 802.3 to 802.11 header
1274 * pDevice - Pointer to adapter
1275 * dwTxBufferAddr - Transmit Buffer
1276 * pPacket - Packet from upper layer
1277 * cbPacketSize - Transmit Data Length
1279 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1280 * pcbAppendPayload - size of append payload for 802.1H translation
1282 * Return Value: none
1286 static void s_vGenerateMACHeader(struct vnt_private
*pDevice
,
1287 u8
*pbyBufferAddr
, u16 wDuration
, struct ethhdr
*psEthHeader
,
1288 int bNeedEncrypt
, u16 wFragType
, u32 uDMAIdx
, u32 uFragIdx
)
1290 struct ieee80211_hdr
*pMACHeader
= (struct ieee80211_hdr
*)pbyBufferAddr
;
1292 pMACHeader
->frame_control
= TYPE_802_11_DATA
;
1294 if (pDevice
->eOPMode
== OP_MODE_AP
) {
1295 memcpy(&(pMACHeader
->addr1
[0]),
1296 &(psEthHeader
->h_dest
[0]),
1298 memcpy(&(pMACHeader
->addr2
[0]), &(pDevice
->abyBSSID
[0]), ETH_ALEN
);
1299 memcpy(&(pMACHeader
->addr3
[0]),
1300 &(psEthHeader
->h_source
[0]),
1302 pMACHeader
->frame_control
|= FC_FROMDS
;
1304 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
1305 memcpy(&(pMACHeader
->addr1
[0]),
1306 &(psEthHeader
->h_dest
[0]),
1308 memcpy(&(pMACHeader
->addr2
[0]),
1309 &(psEthHeader
->h_source
[0]),
1311 memcpy(&(pMACHeader
->addr3
[0]),
1312 &(pDevice
->abyBSSID
[0]),
1315 memcpy(&(pMACHeader
->addr3
[0]),
1316 &(psEthHeader
->h_dest
[0]),
1318 memcpy(&(pMACHeader
->addr2
[0]),
1319 &(psEthHeader
->h_source
[0]),
1321 memcpy(&(pMACHeader
->addr1
[0]),
1322 &(pDevice
->abyBSSID
[0]),
1324 pMACHeader
->frame_control
|= FC_TODS
;
1329 pMACHeader
->frame_control
|= cpu_to_le16((u16
)WLAN_SET_FC_ISWEP(1));
1331 pMACHeader
->duration_id
= cpu_to_le16(wDuration
);
1333 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1335 //Set FragNumber in Sequence Control
1336 pMACHeader
->seq_ctrl
|= cpu_to_le16((u16
)uFragIdx
);
1338 if ((wFragType
== FRAGCTL_ENDFRAG
) || (wFragType
== FRAGCTL_NONFRAG
)) {
1339 pDevice
->wSeqCounter
++;
1340 if (pDevice
->wSeqCounter
> 0x0fff)
1341 pDevice
->wSeqCounter
= 0;
1344 if ((wFragType
== FRAGCTL_STAFRAG
) || (wFragType
== FRAGCTL_MIDFRAG
)) { //StartFrag or MidFrag
1345 pMACHeader
->frame_control
|= FC_MOREFRAG
;
1352 * Request instructs a MAC to transmit a 802.11 management packet through
1353 * the adapter onto the medium.
1357 * hDeviceContext - Pointer to the adapter
1358 * pPacket - A pointer to a descriptor for the packet to transmit
1362 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1366 CMD_STATUS
csMgmt_xmit(struct vnt_private
*pDevice
,
1367 struct vnt_tx_mgmt
*pPacket
)
1369 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1370 struct vnt_tx_buffer
*pTX_Buffer
;
1371 struct vnt_usb_send_context
*pContext
;
1372 struct vnt_tx_fifo_head
*pTxBufHead
;
1373 struct ieee80211_hdr
*pMACHeader
;
1374 struct ethhdr sEthHeader
;
1375 u8 byPktType
, *pbyTxBufferAddr
;
1376 struct vnt_mic_hdr
*pMICHDR
= NULL
;
1377 u32 uDuration
, cbReqCount
, cbHeaderSize
, cbFrameBodySize
, cbFrameSize
;
1378 int bNeedACK
, bIsPSPOLL
= false;
1379 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbFCSlen
= 4;
1383 u16 wCurrentRate
= RATE_1M
;
1385 pContext
= s_vGetFreeContext(pDevice
);
1387 if (NULL
== pContext
) {
1388 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
1389 return CMD_STATUS_RESOURCES
;
1392 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
1393 cbFrameBodySize
= pPacket
->cbPayloadLen
;
1394 pTxBufHead
= &pTX_Buffer
->fifo_head
;
1395 pbyTxBufferAddr
= (u8
*)&pTxBufHead
->adwTxKey
[0];
1396 wTxBufSize
= sizeof(struct vnt_tx_fifo_head
);
1398 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1399 wCurrentRate
= RATE_6M
;
1400 byPktType
= PK_TYPE_11A
;
1402 wCurrentRate
= RATE_1M
;
1403 byPktType
= PK_TYPE_11B
;
1406 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1407 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1408 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1409 // to set power here.
1410 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
1411 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
1413 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
1415 pDevice
->wCurrentRate
= wCurrentRate
;
1418 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
1419 pTxBufHead
->wFIFOCtl
= 0;
1421 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
1422 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1424 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
1425 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
1427 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
1428 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
1431 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
1432 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
1434 if (is_multicast_ether_addr(pPacket
->p80211Header
->sA3
.abyAddr1
)) {
1439 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1442 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
1443 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
1445 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
1446 //Set Preamble type always long
1447 //pDevice->byPreambleType = PREAMBLE_LONG;
1448 // probe-response don't retry
1449 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1450 // bNeedACK = false;
1451 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1455 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
1457 if ((pPacket
->p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
1459 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
1461 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
1464 //Set FRAGCTL_MACHDCNT
1465 pTxBufHead
->wFragCtl
|= cpu_to_le16((u16
)(cbMacHdLen
<< 10));
1468 // Although spec says MMPDU can be fragmented; In most case,
1469 // no one will send a MMPDU under fragmentation. With RTS may occur.
1471 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
1472 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
1475 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1477 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
1478 cbIVlen
= 8;//IV+ExtIV
1481 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1482 //We need to get seed here for filling TxKey entry.
1483 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1484 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1486 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
1487 cbIVlen
= 8;//RSN Header
1489 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1491 //MAC Header should be padding 0 to DW alignment.
1492 uPadding
= 4 - (cbMacHdLen
%4);
1496 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
;
1498 //Set FIFOCTL_GrpAckPolicy
1499 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1500 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1502 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1504 //Set RrvTime/RTS/CTS Buffer
1505 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1506 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) +
1507 sizeof(struct vnt_cts
);
1509 else { // 802.11a/b packet
1510 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) +
1511 sizeof(struct vnt_tx_datahead_ab
);
1514 memcpy(&(sEthHeader
.h_dest
[0]),
1515 &(pPacket
->p80211Header
->sA3
.abyAddr1
[0]),
1517 memcpy(&(sEthHeader
.h_source
[0]),
1518 &(pPacket
->p80211Header
->sA3
.abyAddr2
[0]),
1520 //=========================
1522 //=========================
1523 pTxBufHead
->wFragCtl
|= (u16
)FRAGCTL_NONFRAG
;
1525 /* Fill FIFO,RrvTime,RTS,and CTS */
1526 uDuration
= s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
1527 pTX_Buffer
, &pMICHDR
, 0,
1528 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
, false);
1530 pMACHeader
= (struct ieee80211_hdr
*) (pbyTxBufferAddr
+ cbHeaderSize
);
1532 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ cbFrameBodySize
;
1534 if (WLAN_GET_FC_ISWEP(pPacket
->p80211Header
->sA4
.wFrameCtl
) != 0) {
1536 u8
* pbyPayloadHead
;
1538 PSKeyItem pTransmitKey
= NULL
;
1540 pbyIVHead
= (u8
*)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
);
1541 pbyPayloadHead
= (u8
*)(pbyTxBufferAddr
+ cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
1543 if ((pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
1544 (pDevice
->bLinkPass
== true)) {
1545 pbyBSSID
= pDevice
->abyBSSID
;
1547 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
1549 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
1550 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
1554 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get PTK.\n");
1559 pbyBSSID
= pDevice
->abyBroadcastAddr
;
1560 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
1561 pTransmitKey
= NULL
;
1562 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"KEY is NULL. OP Mode[%d]\n", pDevice
->eOPMode
);
1564 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get GTK.\n");
1568 s_vFillTxKey(pDevice
, pTxBufHead
, pbyIVHead
, pTransmitKey
,
1569 (u8
*)pMACHeader
, (u16
)cbFrameBodySize
, NULL
);
1571 memcpy(pMACHeader
, pPacket
->p80211Header
, cbMacHdLen
);
1572 memcpy(pbyPayloadHead
, ((u8
*)(pPacket
->p80211Header
) + cbMacHdLen
),
1576 // Copy the Packet into a tx Buffer
1577 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
1580 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1581 pDevice
->wSeqCounter
++ ;
1582 if (pDevice
->wSeqCounter
> 0x0fff)
1583 pDevice
->wSeqCounter
= 0;
1586 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1587 // of FIFO control header.
1588 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1589 // in the same place of other packet's Duration-field).
1590 // And it will cause Cisco-AP to issue Disassociation-packet
1591 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
1592 struct vnt_tx_datahead_g
*data_head
= &pTX_Buffer
->tx_head
.
1593 tx_cts
.tx
.head
.cts_g
.data_head
;
1594 data_head
->wDuration_a
=
1595 cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1596 data_head
->wDuration_b
=
1597 cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1599 struct vnt_tx_datahead_ab
*data_head
= &pTX_Buffer
->tx_head
.
1600 tx_ab
.tx
.head
.data_head_ab
;
1601 data_head
->wDuration
=
1602 cpu_to_le16(pPacket
->p80211Header
->sA2
.wDurationID
);
1606 pTX_Buffer
->wTxByteCount
= cpu_to_le16((u16
)(cbReqCount
));
1607 pTX_Buffer
->byPKTNO
= (u8
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
1608 pTX_Buffer
->byType
= 0x00;
1610 pContext
->pPacket
= NULL
;
1611 pContext
->Type
= CONTEXT_MGMT_PACKET
;
1612 pContext
->uBufLen
= (u16
)cbReqCount
+ 4; //USB header
1614 if (WLAN_GET_FC_TODS(pMACHeader
->frame_control
) == 0) {
1615 s_vSaveTxPktInfo(pDevice
, (u8
)(pTX_Buffer
->byPKTNO
& 0x0F),
1616 &pMACHeader
->addr1
[0], (u16
)cbFrameSize
,
1617 pTxBufHead
->wFIFOCtl
);
1620 s_vSaveTxPktInfo(pDevice
, (u8
)(pTX_Buffer
->byPKTNO
& 0x0F),
1621 &pMACHeader
->addr3
[0], (u16
)cbFrameSize
,
1622 pTxBufHead
->wFIFOCtl
);
1625 PIPEnsSendBulkOut(pDevice
,pContext
);
1626 return CMD_STATUS_PENDING
;
1629 CMD_STATUS
csBeacon_xmit(struct vnt_private
*pDevice
,
1630 struct vnt_tx_mgmt
*pPacket
)
1632 struct vnt_beacon_buffer
*pTX_Buffer
;
1633 struct vnt_tx_short_buf_head
*short_head
;
1634 u32 cbFrameSize
= pPacket
->cbMPDULen
+ WLAN_FCS_LEN
;
1635 u32 cbHeaderSize
= 0;
1636 struct ieee80211_hdr
*pMACHeader
;
1638 u32 cbFrameBodySize
;
1640 struct vnt_usb_send_context
*pContext
;
1643 pContext
= s_vGetFreeContext(pDevice
);
1644 if (NULL
== pContext
) {
1645 status
= CMD_STATUS_RESOURCES
;
1646 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ManagementSend TX...NO CONTEXT!\n");
1650 pTX_Buffer
= (struct vnt_beacon_buffer
*)&pContext
->Data
[0];
1651 short_head
= &pTX_Buffer
->short_head
;
1653 cbFrameBodySize
= pPacket
->cbPayloadLen
;
1655 cbHeaderSize
= sizeof(struct vnt_tx_short_buf_head
);
1657 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1658 wCurrentRate
= RATE_6M
;
1660 /* Get SignalField,ServiceField,Length */
1661 BBvCalculateParameter(pDevice
, cbFrameSize
, wCurrentRate
,
1662 PK_TYPE_11A
, &short_head
->ab
);
1664 /* Get Duration and TimeStampOff */
1665 short_head
->duration
= s_uGetDataDuration(pDevice
,
1666 PK_TYPE_11A
, false);
1667 short_head
->time_stamp_off
=
1668 vnt_time_stamp_off(pDevice
, wCurrentRate
);
1670 wCurrentRate
= RATE_1M
;
1671 short_head
->fifo_ctl
|= FIFOCTL_11B
;
1673 /* Get SignalField,ServiceField,Length */
1674 BBvCalculateParameter(pDevice
, cbFrameSize
, wCurrentRate
,
1675 PK_TYPE_11B
, &short_head
->ab
);
1677 /* Get Duration and TimeStampOff */
1678 short_head
->duration
= s_uGetDataDuration(pDevice
,
1679 PK_TYPE_11B
, false);
1680 short_head
->time_stamp_off
=
1681 vnt_time_stamp_off(pDevice
, wCurrentRate
);
1685 /* Generate Beacon Header */
1686 pMACHeader
= &pTX_Buffer
->hdr
;
1688 memcpy(pMACHeader
, pPacket
->p80211Header
, pPacket
->cbMPDULen
);
1690 pMACHeader
->duration_id
= 0;
1691 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
1692 pDevice
->wSeqCounter
++;
1693 if (pDevice
->wSeqCounter
> 0x0fff)
1694 pDevice
->wSeqCounter
= 0;
1696 cbReqCount
= cbHeaderSize
+ WLAN_HDR_ADDR3_LEN
+ cbFrameBodySize
;
1698 pTX_Buffer
->wTxByteCount
= (u16
)cbReqCount
;
1699 pTX_Buffer
->byPKTNO
= (u8
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
1700 pTX_Buffer
->byType
= 0x01;
1702 pContext
->pPacket
= NULL
;
1703 pContext
->Type
= CONTEXT_MGMT_PACKET
;
1704 pContext
->uBufLen
= (u16
)cbReqCount
+ 4; //USB header
1706 PIPEnsSendBulkOut(pDevice
,pContext
);
1707 return CMD_STATUS_PENDING
;
1711 void vDMA0_tx_80211(struct vnt_private
*pDevice
, struct sk_buff
*skb
)
1713 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1714 struct vnt_tx_buffer
*pTX_Buffer
;
1715 struct vnt_tx_fifo_head
*pTxBufHead
;
1717 u8
*pbyTxBufferAddr
;
1718 u32 uDuration
, cbReqCount
;
1719 struct ieee80211_hdr
*pMACHeader
;
1720 u32 cbHeaderSize
, cbFrameBodySize
;
1721 int bNeedACK
, bIsPSPOLL
= false;
1723 u32 cbIVlen
= 0, cbICVlen
= 0, cbMIClen
= 0, cbFCSlen
= 4;
1725 u32 cbMICHDR
= 0, uLength
= 0;
1726 u32 dwMICKey0
, dwMICKey1
;
1728 u32
*pdwMIC_L
, *pdwMIC_R
;
1731 struct ethhdr sEthHeader
;
1732 struct vnt_mic_hdr
*pMICHDR
;
1733 u32 wCurrentRate
= RATE_1M
;
1734 PUWLAN_80211HDR p80211Header
;
1736 int bNodeExist
= false;
1738 PSKeyItem pTransmitKey
= NULL
;
1739 u8
*pbyIVHead
, *pbyPayloadHead
, *pbyMacHdr
;
1740 u32 cbExtSuppRate
= 0;
1741 struct vnt_usb_send_context
*pContext
;
1745 if(skb
->len
<= WLAN_HDR_ADDR3_LEN
) {
1746 cbFrameBodySize
= 0;
1749 cbFrameBodySize
= skb
->len
- WLAN_HDR_ADDR3_LEN
;
1751 p80211Header
= (PUWLAN_80211HDR
)skb
->data
;
1753 pContext
= s_vGetFreeContext(pDevice
);
1755 if (NULL
== pContext
) {
1756 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0 TX...NO CONTEXT!\n");
1757 dev_kfree_skb_irq(skb
);
1761 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
1762 pTxBufHead
= &pTX_Buffer
->fifo_head
;
1763 pbyTxBufferAddr
= (u8
*)&pTxBufHead
->adwTxKey
[0];
1764 wTxBufSize
= sizeof(struct vnt_tx_fifo_head
);
1766 if (pDevice
->byBBType
== BB_TYPE_11A
) {
1767 wCurrentRate
= RATE_6M
;
1768 byPktType
= PK_TYPE_11A
;
1770 wCurrentRate
= RATE_1M
;
1771 byPktType
= PK_TYPE_11B
;
1774 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1775 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1776 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1777 // to set power here.
1778 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
1779 RFbSetPower(pDevice
, wCurrentRate
, pDevice
->byCurrentCh
);
1781 RFbSetPower(pDevice
, wCurrentRate
, pMgmt
->uCurrChannel
);
1784 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header
->sA3
.wFrameCtl
);
1787 if (byPktType
== PK_TYPE_11A
) {//0000 0000 0000 0000
1788 pTxBufHead
->wFIFOCtl
= 0;
1790 else if (byPktType
== PK_TYPE_11B
) {//0000 0001 0000 0000
1791 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11B
;
1793 else if (byPktType
== PK_TYPE_11GB
) {//0000 0010 0000 0000
1794 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GB
;
1796 else if (byPktType
== PK_TYPE_11GA
) {//0000 0011 0000 0000
1797 pTxBufHead
->wFIFOCtl
|= FIFOCTL_11GA
;
1800 pTxBufHead
->wFIFOCtl
|= FIFOCTL_TMOEN
;
1801 pTxBufHead
->wTimeStamp
= cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us
);
1803 if (is_multicast_ether_addr(p80211Header
->sA3
.abyAddr1
)) {
1805 if (pDevice
->bEnableHostWEP
) {
1811 if (pDevice
->bEnableHostWEP
) {
1812 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(p80211Header
->sA3
.abyAddr1
), &uNodeIndex
))
1816 pTxBufHead
->wFIFOCtl
|= FIFOCTL_NEEDACK
;
1819 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) ||
1820 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ) {
1822 pTxBufHead
->wFIFOCtl
|= FIFOCTL_LRETRY
;
1823 //Set Preamble type always long
1824 //pDevice->byPreambleType = PREAMBLE_LONG;
1826 // probe-response don't retry
1827 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1828 // bNeedACK = false;
1829 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1833 pTxBufHead
->wFIFOCtl
|= (FIFOCTL_GENINT
| FIFOCTL_ISDMA0
);
1835 if ((p80211Header
->sA4
.wFrameCtl
& TYPE_SUBTYPE_MASK
) == TYPE_CTL_PSPOLL
) {
1837 cbMacHdLen
= WLAN_HDR_ADDR2_LEN
;
1839 cbMacHdLen
= WLAN_HDR_ADDR3_LEN
;
1842 // hostapd daemon ext support rate patch
1843 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
1845 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0) {
1846 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
;
1849 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0) {
1850 cbExtSuppRate
+= ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
;
1853 if (cbExtSuppRate
>0) {
1854 cbFrameBodySize
= WLAN_ASSOCRESP_OFF_SUPP_RATES
;
1858 //Set FRAGCTL_MACHDCNT
1859 pTxBufHead
->wFragCtl
|= cpu_to_le16((u16
)cbMacHdLen
<< 10);
1862 // Although spec says MMPDU can be fragmented; In most case,
1863 // no one will send a MMPDU under fragmentation. With RTS may occur.
1865 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
1866 if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption1Enabled
) {
1869 pTxBufHead
->wFragCtl
|= FRAGCTL_LEGACY
;
1871 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
) {
1872 cbIVlen
= 8;//IV+ExtIV
1875 pTxBufHead
->wFragCtl
|= FRAGCTL_TKIP
;
1876 //We need to get seed here for filling TxKey entry.
1877 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1878 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1880 else if (pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
) {
1881 cbIVlen
= 8;//RSN Header
1883 cbMICHDR
= sizeof(struct vnt_mic_hdr
);
1884 pTxBufHead
->wFragCtl
|= FRAGCTL_AES
;
1886 //MAC Header should be padding 0 to DW alignment.
1887 uPadding
= 4 - (cbMacHdLen
%4);
1891 cbFrameSize
= cbMacHdLen
+ cbFrameBodySize
+ cbIVlen
+ cbMIClen
+ cbICVlen
+ cbFCSlen
+ cbExtSuppRate
;
1893 //Set FIFOCTL_GrpAckPolicy
1894 if (pDevice
->bGrpAckPolicy
== true) {//0000 0100 0000 0000
1895 pTxBufHead
->wFIFOCtl
|= FIFOCTL_GRPACK
;
1897 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1899 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {//802.11g packet
1900 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_cts
) + cbMICHDR
+
1901 sizeof(struct vnt_cts
);
1904 else {//802.11a/b packet
1905 cbHeaderSize
= wTxBufSize
+ sizeof(struct vnt_rrv_time_ab
) + cbMICHDR
+
1906 sizeof(struct vnt_tx_datahead_ab
);
1908 memcpy(&(sEthHeader
.h_dest
[0]),
1909 &(p80211Header
->sA3
.abyAddr1
[0]),
1911 memcpy(&(sEthHeader
.h_source
[0]),
1912 &(p80211Header
->sA3
.abyAddr2
[0]),
1914 //=========================
1916 //=========================
1917 pTxBufHead
->wFragCtl
|= (u16
)FRAGCTL_NONFRAG
;
1919 /* Fill FIFO,RrvTime,RTS,and CTS */
1920 uDuration
= s_vGenerateTxParameter(pDevice
, byPktType
, wCurrentRate
,
1921 pTX_Buffer
, &pMICHDR
, cbMICHDR
,
1922 cbFrameSize
, bNeedACK
, TYPE_TXDMA0
, &sEthHeader
, false);
1924 pMACHeader
= (struct ieee80211_hdr
*) (pbyTxBufferAddr
+ cbHeaderSize
);
1926 cbReqCount
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
+ (cbFrameBodySize
+ cbMIClen
) + cbExtSuppRate
;
1928 pbyMacHdr
= (u8
*)(pbyTxBufferAddr
+ cbHeaderSize
);
1929 pbyPayloadHead
= (u8
*)(pbyMacHdr
+ cbMacHdLen
+ uPadding
+ cbIVlen
);
1930 pbyIVHead
= (u8
*)(pbyMacHdr
+ cbMacHdLen
+ uPadding
);
1932 // Copy the Packet into a tx Buffer
1933 memcpy(pbyMacHdr
, skb
->data
, cbMacHdLen
);
1935 // version set to 0, patch for hostapd deamon
1936 pMACHeader
->frame_control
&= cpu_to_le16(0xfffc);
1937 memcpy(pbyPayloadHead
, (skb
->data
+ cbMacHdLen
), cbFrameBodySize
);
1939 // replace support rate, patch for hostapd daemon( only support 11M)
1940 if (WLAN_GET_FC_FSTYPE(p80211Header
->sA4
.wFrameCtl
) == WLAN_FSTYPE_ASSOCRESP
) {
1941 if (cbExtSuppRate
!= 0) {
1942 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
!= 0)
1943 memcpy((pbyPayloadHead
+ cbFrameBodySize
),
1944 pMgmt
->abyCurrSuppRates
,
1945 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
1947 if (((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
!= 0)
1948 memcpy((pbyPayloadHead
+ cbFrameBodySize
) + ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
)->len
+ WLAN_IEHDR_LEN
,
1949 pMgmt
->abyCurrExtSuppRates
,
1950 ((PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
)->len
+ WLAN_IEHDR_LEN
1956 if (WLAN_GET_FC_ISWEP(p80211Header
->sA4
.wFrameCtl
) != 0) {
1958 if (pDevice
->bEnableHostWEP
) {
1959 pTransmitKey
= &STempKey
;
1960 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
1961 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
1962 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
1963 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
1964 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
1965 memcpy(pTransmitKey
->abyKey
,
1966 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
1967 pTransmitKey
->uKeyLength
1971 if ((pTransmitKey
!= NULL
) && (pTransmitKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
1973 dwMICKey0
= *(u32
*)(&pTransmitKey
->abyKey
[16]);
1974 dwMICKey1
= *(u32
*)(&pTransmitKey
->abyKey
[20]);
1976 // DO Software Michael
1977 MIC_vInit(dwMICKey0
, dwMICKey1
);
1978 MIC_vAppend((u8
*)&(sEthHeader
.h_dest
[0]), 12);
1980 MIC_vAppend((u8
*)&dwMIC_Priority
, 4);
1981 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"DMA0_tx_8021:MIC KEY:"\
1982 " %X, %X\n", dwMICKey0
, dwMICKey1
);
1984 uLength
= cbHeaderSize
+ cbMacHdLen
+ uPadding
+ cbIVlen
;
1986 MIC_vAppend((pbyTxBufferAddr
+ uLength
), cbFrameBodySize
);
1988 pdwMIC_L
= (u32
*)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
);
1989 pdwMIC_R
= (u32
*)(pbyTxBufferAddr
+ uLength
+ cbFrameBodySize
+ 4);
1991 MIC_vGetMIC(pdwMIC_L
, pdwMIC_R
);
1994 if (pDevice
->bTxMICFail
== true) {
1997 pDevice
->bTxMICFail
= false;
2000 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uLength: %d, %d\n", uLength
, cbFrameBodySize
);
2001 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"cbReqCount:%d, %d, %d, %d\n", cbReqCount
, cbHeaderSize
, uPadding
, cbIVlen
);
2002 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC:%x, %x\n",
2003 *pdwMIC_L
, *pdwMIC_R
);
2007 s_vFillTxKey(pDevice
, pTxBufHead
, pbyIVHead
, pTransmitKey
,
2008 pbyMacHdr
, (u16
)cbFrameBodySize
, pMICHDR
);
2010 if (pDevice
->bEnableHostWEP
) {
2011 pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
= pTransmitKey
->dwTSC47_16
;
2012 pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
= pTransmitKey
->wTSC15_0
;
2015 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
2016 s_vSWencryption(pDevice
, pTransmitKey
, pbyPayloadHead
, (u16
)(cbFrameBodySize
+ cbMIClen
));
2020 pMACHeader
->seq_ctrl
= cpu_to_le16(pDevice
->wSeqCounter
<< 4);
2021 pDevice
->wSeqCounter
++ ;
2022 if (pDevice
->wSeqCounter
> 0x0fff)
2023 pDevice
->wSeqCounter
= 0;
2026 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2027 // of FIFO control header.
2028 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2029 // in the same place of other packet's Duration-field).
2030 // And it will cause Cisco-AP to issue Disassociation-packet
2031 if (byPktType
== PK_TYPE_11GB
|| byPktType
== PK_TYPE_11GA
) {
2032 struct vnt_tx_datahead_g
*data_head
= &pTX_Buffer
->tx_head
.
2033 tx_cts
.tx
.head
.cts_g
.data_head
;
2034 data_head
->wDuration_a
=
2035 cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2036 data_head
->wDuration_b
=
2037 cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2039 struct vnt_tx_datahead_ab
*data_head
= &pTX_Buffer
->tx_head
.
2040 tx_ab
.tx
.head
.data_head_ab
;
2041 data_head
->wDuration
=
2042 cpu_to_le16(p80211Header
->sA2
.wDurationID
);
2046 pTX_Buffer
->wTxByteCount
= cpu_to_le16((u16
)(cbReqCount
));
2047 pTX_Buffer
->byPKTNO
= (u8
) (((wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2048 pTX_Buffer
->byType
= 0x00;
2050 pContext
->pPacket
= skb
;
2051 pContext
->Type
= CONTEXT_MGMT_PACKET
;
2052 pContext
->uBufLen
= (u16
)cbReqCount
+ 4; //USB header
2054 if (WLAN_GET_FC_TODS(pMACHeader
->frame_control
) == 0) {
2055 s_vSaveTxPktInfo(pDevice
, (u8
)(pTX_Buffer
->byPKTNO
& 0x0F),
2056 &pMACHeader
->addr1
[0], (u16
)cbFrameSize
,
2057 pTxBufHead
->wFIFOCtl
);
2060 s_vSaveTxPktInfo(pDevice
, (u8
)(pTX_Buffer
->byPKTNO
& 0x0F),
2061 &pMACHeader
->addr3
[0], (u16
)cbFrameSize
,
2062 pTxBufHead
->wFIFOCtl
);
2064 PIPEnsSendBulkOut(pDevice
,pContext
);
2069 //TYPE_AC0DMA data tx
2072 * Tx packet via AC0DMA(DMA1)
2076 * pDevice - Pointer to the adapter
2077 * skb - Pointer to tx skb packet
2081 * Return Value: NULL
2084 int nsDMA_tx_packet(struct vnt_private
*pDevice
,
2085 u32 uDMAIdx
, struct sk_buff
*skb
)
2087 struct net_device_stats
*pStats
= &pDevice
->stats
;
2088 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2089 struct vnt_tx_buffer
*pTX_Buffer
;
2090 u32 BytesToWrite
= 0, uHeaderLen
= 0;
2092 u8 byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2095 int bNeedEncryption
= false;
2096 PSKeyItem pTransmitKey
= NULL
;
2099 int bTKIP_UseGTK
= false;
2100 int bNeedDeAuth
= false;
2102 int bNodeExist
= false;
2103 struct vnt_usb_send_context
*pContext
;
2104 bool fConvertedPacket
;
2106 u16 wKeepRate
= pDevice
->wCurrentRate
;
2107 int bTxeapol_key
= false;
2109 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
2111 if (pDevice
->uAssocCount
== 0) {
2112 dev_kfree_skb_irq(skb
);
2116 if (is_multicast_ether_addr((u8
*)(skb
->data
))) {
2119 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
2121 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skb
);
2122 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
2124 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
2127 // multicast/broadcast data rate
2129 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2130 pDevice
->wCurrentRate
= RATE_2M
;
2132 pDevice
->wCurrentRate
= RATE_24M
;
2133 // long preamble type
2134 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2138 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(skb
->data
), &uNodeIndex
)) {
2140 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bPSEnable
) {
2142 skb_queue_tail(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
, skb
);
2144 pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
++;
2146 wAID
= pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
;
2147 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
2148 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set:pMgmt->abyPSTxMap[%d]= %d\n",
2149 (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
2153 // AP rate decided from node
2154 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2155 // tx preamble decided from node
2157 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2158 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2161 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2167 if (bNodeExist
== false) {
2168 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Unknown STA not found in node DB \n");
2169 dev_kfree_skb_irq(skb
);
2174 pContext
= s_vGetFreeContext(pDevice
);
2176 if (pContext
== NULL
) {
2177 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
" pContext == NULL\n");
2178 dev_kfree_skb_irq(skb
);
2179 return STATUS_RESOURCES
;
2182 memcpy(pDevice
->sTxEthHeader
.h_dest
, (u8
*)(skb
->data
), ETH_HLEN
);
2184 //mike add:station mode check eapol-key challenge--->
2186 u8 Protocol_Version
; //802.1x Authentication
2187 u8 Packet_Type
; //802.1x Authentication
2191 Protocol_Version
= skb
->data
[ETH_HLEN
];
2192 Packet_Type
= skb
->data
[ETH_HLEN
+1];
2193 Descriptor_type
= skb
->data
[ETH_HLEN
+1+1+2];
2194 Key_info
= (skb
->data
[ETH_HLEN
+1+1+2+1] << 8)|(skb
->data
[ETH_HLEN
+1+1+2+2]);
2195 if (pDevice
->sTxEthHeader
.h_proto
== cpu_to_be16(ETH_P_PAE
)) {
2196 /* 802.1x OR eapol-key challenge frame transfer */
2197 if (((Protocol_Version
== 1) || (Protocol_Version
== 2)) &&
2198 (Packet_Type
== 3)) {
2199 bTxeapol_key
= true;
2200 if(!(Key_info
& BIT3
) && //WPA or RSN group-key challenge
2201 (Key_info
& BIT8
) && (Key_info
& BIT9
)) { //send 2/2 key
2202 if(Descriptor_type
==254) {
2203 pDevice
->fWPA_Authened
= true;
2207 pDevice
->fWPA_Authened
= true;
2208 PRINT_K("WPA2(re-keying) ");
2210 PRINT_K("Authentication completed!!\n");
2212 else if((Key_info
& BIT3
) && (Descriptor_type
==2) && //RSN pairwise-key challenge
2213 (Key_info
& BIT8
) && (Key_info
& BIT9
)) {
2214 pDevice
->fWPA_Authened
= true;
2215 PRINT_K("WPA2 Authentication completed!!\n");
2220 //mike add:station mode check eapol-key challenge<---
2222 if (pDevice
->bEncryptionEnable
== true) {
2223 bNeedEncryption
= true;
2226 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
2227 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2228 pbyBSSID
= pDevice
->abyBSSID
;
2230 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
2232 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
2233 bTKIP_UseGTK
= true;
2234 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2238 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get PTK.\n");
2241 }else if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2242 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2243 pbyBSSID
= pDevice
->sTxEthHeader
.h_dest
;
2244 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS Serach Key: \n");
2245 for (ii
= 0; ii
< 6; ii
++)
2246 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"%x \n", *(pbyBSSID
+ii
));
2247 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"\n");
2250 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == true)
2254 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2255 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2256 pTransmitKey
= NULL
;
2257 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2258 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2261 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"NOT IBSS and KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2263 bTKIP_UseGTK
= true;
2264 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2269 if (pDevice
->bEnableHostWEP
) {
2270 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"acdma0: STA index %d\n", uNodeIndex
);
2271 if (pDevice
->bEncryptionEnable
== true) {
2272 pTransmitKey
= &STempKey
;
2273 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2274 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2275 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2276 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2277 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2278 memcpy(pTransmitKey
->abyKey
,
2279 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2280 pTransmitKey
->uKeyLength
2285 byPktType
= (u8
)pDevice
->byPacketType
;
2287 if (pDevice
->bFixRate
) {
2288 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2289 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2290 pDevice
->wCurrentRate
= RATE_11M
;
2292 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2295 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2296 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2297 pDevice
->wCurrentRate
= RATE_6M
;
2299 if (pDevice
->uConnectionRate
>= RATE_54M
)
2300 pDevice
->wCurrentRate
= RATE_54M
;
2302 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2307 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2308 // Adhoc Tx rate decided from node DB
2309 if (is_multicast_ether_addr(pDevice
->sTxEthHeader
.h_dest
)) {
2310 // Multicast use highest data rate
2311 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2313 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2316 if (BSSbIsSTAInNodeDB(pDevice
, &(pDevice
->sTxEthHeader
.h_dest
[0]), &uNodeIndex
)) {
2317 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2318 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2319 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2323 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex
, pDevice
->wCurrentRate
);
2328 if (pDevice
->byBBType
!= BB_TYPE_11A
)
2329 pDevice
->wCurrentRate
= RATE_2M
;
2331 pDevice
->wCurrentRate
= RATE_24M
; // refer to vMgrCreateOwnIBSS()'s
2332 // abyCurrExtSuppRates[]
2333 pDevice
->byPreambleType
= PREAMBLE_SHORT
;
2334 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Not Found Node use highest basic Rate.....\n");
2338 if (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) {
2339 // Infra STA rate decided from AP Node, index = 0
2340 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[0].wTxDataRate
;
2344 if (pDevice
->sTxEthHeader
.h_proto
== cpu_to_be16(ETH_P_PAE
)) {
2345 if (pDevice
->byBBType
!= BB_TYPE_11A
) {
2346 pDevice
->wCurrentRate
= RATE_1M
;
2347 pDevice
->byACKRate
= RATE_1M
;
2348 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2349 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2351 pDevice
->wCurrentRate
= RATE_6M
;
2352 pDevice
->byACKRate
= RATE_6M
;
2353 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2354 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2358 DBG_PRT(MSG_LEVEL_DEBUG
,
2359 KERN_INFO
"dma_tx: pDevice->wCurrentRate = %d\n",
2360 pDevice
->wCurrentRate
);
2362 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2363 bScheduleCommand((void *) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2366 if (pDevice
->wCurrentRate
<= RATE_11M
) {
2367 byPktType
= PK_TYPE_11B
;
2370 if (bNeedEncryption
== true) {
2371 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ntohs Pkt Type=%04x\n", ntohs(pDevice
->sTxEthHeader
.h_proto
));
2372 if ((pDevice
->sTxEthHeader
.h_proto
) == cpu_to_be16(ETH_P_PAE
)) {
2373 bNeedEncryption
= false;
2374 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pkt Type=%04x\n", (pDevice
->sTxEthHeader
.h_proto
));
2375 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2376 if (pTransmitKey
== NULL
) {
2377 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Don't Find TX KEY\n");
2380 if (bTKIP_UseGTK
== true) {
2381 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"error: KEY is GTK!!~~\n");
2384 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%X]\n",
2385 pTransmitKey
->dwKeyIndex
);
2386 bNeedEncryption
= true;
2391 if (pDevice
->bEnableHostWEP
) {
2392 if ((uNodeIndex
!= 0) &&
2393 (pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
& PAIRWISE_KEY
)) {
2394 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%X]\n",
2395 pTransmitKey
->dwKeyIndex
);
2396 bNeedEncryption
= true;
2402 if (pTransmitKey
== NULL
) {
2403 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return no tx key\n");
2404 pContext
->bBoolInUse
= false;
2405 dev_kfree_skb_irq(skb
);
2406 pStats
->tx_dropped
++;
2407 return STATUS_FAILURE
;
2412 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
2414 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
2415 pTX_Buffer
, bNeedEncryption
,
2416 skb
->len
, uDMAIdx
, &pDevice
->sTxEthHeader
,
2417 (u8
*)skb
->data
, pTransmitKey
, uNodeIndex
,
2418 pDevice
->wCurrentRate
,
2419 &uHeaderLen
, &BytesToWrite
2422 if (fConvertedPacket
== false) {
2423 pContext
->bBoolInUse
= false;
2424 dev_kfree_skb_irq(skb
);
2425 return STATUS_FAILURE
;
2428 if ( pDevice
->bEnablePSMode
== true ) {
2429 if ( !pDevice
->bPSModeTxBurst
) {
2430 bScheduleCommand((void *) pDevice
,
2431 WLAN_CMD_MAC_DISPOWERSAVING
,
2433 pDevice
->bPSModeTxBurst
= true;
2437 pTX_Buffer
->byPKTNO
= (u8
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2438 pTX_Buffer
->wTxByteCount
= (u16
)BytesToWrite
;
2440 pContext
->pPacket
= skb
;
2441 pContext
->Type
= CONTEXT_DATA_PACKET
;
2442 pContext
->uBufLen
= (u16
)BytesToWrite
+ 4 ; //USB header
2444 s_vSaveTxPktInfo(pDevice
, (u8
)(pTX_Buffer
->byPKTNO
& 0x0F),
2445 &pContext
->sEthHeader
.h_dest
[0],
2446 (u16
)(BytesToWrite
-uHeaderLen
),
2447 pTX_Buffer
->fifo_head
.wFIFOCtl
);
2449 status
= PIPEnsSendBulkOut(pDevice
,pContext
);
2451 if (bNeedDeAuth
== true) {
2452 u16 wReason
= WLAN_MGMT_REASON_MIC_FAILURE
;
2454 bScheduleCommand((void *) pDevice
, WLAN_CMD_DEAUTH
, (u8
*) &wReason
);
2457 if(status
!=STATUS_PENDING
) {
2458 pContext
->bBoolInUse
= false;
2459 dev_kfree_skb_irq(skb
);
2460 return STATUS_FAILURE
;
2469 * Relay packet send (AC1DMA) from rx dpc.
2473 * pDevice - Pointer to the adapter
2474 * pPacket - Pointer to rx packet
2475 * cbPacketSize - rx ethernet frame size
2479 * Return Value: Return true if packet is copy to dma1; otherwise false
2482 int bRelayPacketSend(struct vnt_private
*pDevice
, u8
*pbySkbData
, u32 uDataLen
,
2485 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
2486 struct vnt_tx_buffer
*pTX_Buffer
;
2487 u32 BytesToWrite
= 0, uHeaderLen
= 0;
2488 u8 byPktType
= PK_TYPE_11B
;
2489 int bNeedEncryption
= false;
2491 PSKeyItem pTransmitKey
= NULL
;
2493 struct vnt_usb_send_context
*pContext
;
2495 int fConvertedPacket
;
2497 u16 wKeepRate
= pDevice
->wCurrentRate
;
2499 pContext
= s_vGetFreeContext(pDevice
);
2501 if (NULL
== pContext
) {
2505 memcpy(pDevice
->sTxEthHeader
.h_dest
, (u8
*)pbySkbData
, ETH_HLEN
);
2507 if (pDevice
->bEncryptionEnable
== true) {
2508 bNeedEncryption
= true;
2510 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2511 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2512 pTransmitKey
= NULL
;
2513 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"KEY is NULL. [%d]\n", pMgmt
->eCurrMode
);
2515 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2519 if (pDevice
->bEnableHostWEP
) {
2520 if (uNodeIndex
< MAX_NODE_NUM
+ 1) {
2521 pTransmitKey
= &STempKey
;
2522 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2523 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2524 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2525 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2526 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2527 memcpy(pTransmitKey
->abyKey
,
2528 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2529 pTransmitKey
->uKeyLength
2534 if ( bNeedEncryption
&& (pTransmitKey
== NULL
) ) {
2535 pContext
->bBoolInUse
= false;
2539 byPktTyp
= (u8
)pDevice
->byPacketType
;
2541 if (pDevice
->bFixRate
) {
2542 if (pDevice
->byBBType
== BB_TYPE_11B
) {
2543 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2544 pDevice
->wCurrentRate
= RATE_11M
;
2546 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2549 if ((pDevice
->byBBType
== BB_TYPE_11A
) &&
2550 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2551 pDevice
->wCurrentRate
= RATE_6M
;
2553 if (pDevice
->uConnectionRate
>= RATE_54M
)
2554 pDevice
->wCurrentRate
= RATE_54M
;
2556 pDevice
->wCurrentRate
= (u16
)pDevice
->uConnectionRate
;
2561 pDevice
->wCurrentRate
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2564 if (wKeepRate
!= pDevice
->wCurrentRate
) {
2565 bScheduleCommand((void *) pDevice
, WLAN_CMD_SETPOWER
, NULL
);
2568 if (pDevice
->wCurrentRate
<= RATE_11M
)
2569 byPktType
= PK_TYPE_11B
;
2571 BytesToWrite
= uDataLen
+ ETH_FCS_LEN
;
2573 // Convert the packet to an usb frame and copy into our buffer
2574 // and send the irp.
2576 pTX_Buffer
= (struct vnt_tx_buffer
*)&pContext
->Data
[0];
2578 fConvertedPacket
= s_bPacketToWirelessUsb(pDevice
, byPktType
,
2579 pTX_Buffer
, bNeedEncryption
,
2580 uDataLen
, TYPE_AC0DMA
, &pDevice
->sTxEthHeader
,
2581 pbySkbData
, pTransmitKey
, uNodeIndex
,
2582 pDevice
->wCurrentRate
,
2583 &uHeaderLen
, &BytesToWrite
2586 if (fConvertedPacket
== false) {
2587 pContext
->bBoolInUse
= false;
2591 pTX_Buffer
->byPKTNO
= (u8
) (((pDevice
->wCurrentRate
<<4) &0x00F0) | ((pDevice
->wSeqCounter
- 1) & 0x000F));
2592 pTX_Buffer
->wTxByteCount
= (u16
)BytesToWrite
;
2594 pContext
->pPacket
= NULL
;
2595 pContext
->Type
= CONTEXT_DATA_PACKET
;
2596 pContext
->uBufLen
= (u16
)BytesToWrite
+ 4 ; //USB header
2598 s_vSaveTxPktInfo(pDevice
, (u8
)(pTX_Buffer
->byPKTNO
& 0x0F),
2599 &pContext
->sEthHeader
.h_dest
[0],
2600 (u16
)(BytesToWrite
- uHeaderLen
),
2601 pTX_Buffer
->fifo_head
.wFIFOCtl
);
2603 status
= PIPEnsSendBulkOut(pDevice
,pContext
);