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 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, u8 *pbyBuf,
111 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
112 struct vnt_mic_hdr *mic_hdr);
114 static void s_vSWencryption(struct vnt_private *pDevice,
115 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
117 static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
118 u32 cbFrameLength, u16 wRate, int bNeedAck);
120 static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
121 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
123 static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
124 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
125 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
127 static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
128 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
129 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
131 static u16 s_uGetDataDuration(struct vnt_private *pDevice,
132 u8 byPktType, int bNeedAck);
134 static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
135 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
136 int bNeedAck, u8 byFBOption);
138 static void *s_vGetFreeContext(struct vnt_private *pDevice)
140 struct vnt_usb_send_context *pContext = NULL;
141 struct vnt_usb_send_context *pReturnContext = NULL;
144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
146 for (ii = 0; ii < pDevice->cbTD; ii++) {
147 if (!pDevice->apTD[ii])
149 pContext = pDevice->apTD[ii];
150 if (pContext->bBoolInUse == false) {
151 pContext->bBoolInUse = true;
152 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
153 pReturnContext = pContext;
157 if ( ii == pDevice->cbTD ) {
158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
160 return (void *) pReturnContext;
163 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
164 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
166 PSStatCounter pStatistic = &pDevice->scStatistic;
168 if (is_broadcast_ether_addr(pbyDestAddr))
169 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
170 else if (is_multicast_ether_addr(pbyDestAddr))
171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
175 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
176 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
177 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
182 static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
183 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
184 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
186 u32 *pdwIV = (u32 *)pbyIVHead;
187 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
188 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
192 if (pTransmitKey == NULL)
195 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
196 *pdwIV = pDevice->dwIVCounter;
197 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
199 switch (pTransmitKey->byCipherSuite) {
201 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
202 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
203 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
204 pTransmitKey->uKeyLength);
206 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
207 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
208 pTransmitKey->uKeyLength);
209 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
210 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
211 memcpy(pbyBuf+11, pTransmitKey->abyKey,
212 pTransmitKey->uKeyLength);
215 memcpy(pDevice->abyPRNG, pbyBuf, 16);
217 /* Append IV after Mac Header */
218 *pdwIV &= WEP_IV_MASK;
219 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
220 *pdwIV = cpu_to_le32(*pdwIV);
222 pDevice->dwIVCounter++;
223 if (pDevice->dwIVCounter > WEP_IV_MASK)
224 pDevice->dwIVCounter = 0;
228 pTransmitKey->wTSC15_0++;
229 if (pTransmitKey->wTSC15_0 == 0)
230 pTransmitKey->dwTSC47_16++;
232 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
233 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
235 memcpy(pbyBuf, pDevice->abyPRNG, 16);
238 memcpy(pdwIV, pDevice->abyPRNG, 3);
240 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
242 /* Append IV&ExtIV after Mac Header */
243 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
246 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
250 pTransmitKey->wTSC15_0++;
251 if (pTransmitKey->wTSC15_0 == 0)
252 pTransmitKey->dwTSC47_16++;
254 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
258 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
261 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
263 /* Append IV&ExtIV after Mac Header */
264 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
271 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
272 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
274 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
275 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
278 if (pDevice->bLongHeader)
279 mic_hdr->hlen = cpu_to_be16(28);
281 mic_hdr->hlen = cpu_to_be16(22);
283 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
284 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
287 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
288 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
290 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
292 if (pDevice->bLongHeader)
293 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
297 static void s_vSWencryption(struct vnt_private *pDevice,
298 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
301 u32 dwICV = 0xffffffff;
304 if (pTransmitKey == NULL)
307 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
308 //=======================================================================
309 // Append ICV after payload
310 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
311 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
312 // finally, we must invert dwCRC to get the correct answer
313 *pdwICV = cpu_to_le32(~dwICV);
315 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
316 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
317 //=======================================================================
318 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
319 //=======================================================================
320 //Append ICV after payload
321 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
322 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
323 // finally, we must invert dwCRC to get the correct answer
324 *pdwICV = cpu_to_le32(~dwICV);
326 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
327 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
328 //=======================================================================
332 static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
334 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
338 /*byPktType : PK_TYPE_11A 0
343 static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
344 u32 cbFrameLength, u16 wRate, int bNeedAck)
346 u32 uDataTime, uAckTime;
348 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
349 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
350 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
351 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
352 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
356 return (uDataTime + pDevice->uSIFS + uAckTime);
363 static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
364 u32 frame_length, u16 rate, int need_ack)
366 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
367 frame_length, rate, need_ack));
370 //byFreqType: 0=>5GHZ 1=>2.4GHZ
371 static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
372 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
374 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
376 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
378 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
379 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
380 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
381 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
383 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
384 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
385 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
386 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
388 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
389 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
390 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
392 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
393 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
394 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
395 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
400 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
401 return cpu_to_le16((u16)uRrvTime);
404 //byFreqType 0: 5GHz, 1:2.4Ghz
405 static u16 s_uGetDataDuration(struct vnt_private *pDevice,
406 u8 byPktType, int bNeedAck)
411 if (byPktType == PK_TYPE_11B)
412 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
413 byPktType, 14, pDevice->byTopCCKBasicRate);
415 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
416 byPktType, 14, pDevice->byTopOFDMBasicRate);
417 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
423 //byFreqType: 0=>5GHZ 1=>2.4GHZ
424 static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
425 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
428 u32 uCTSTime = 0, uDurTime = 0;
432 case RTSDUR_BB: //RTSDuration_bb
433 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
434 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
437 case RTSDUR_BA: //RTSDuration_ba
438 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
439 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
442 case RTSDUR_AA: //RTSDuration_aa
443 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
444 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
447 case CTSDUR_BA: //CTSDuration_ba
448 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
451 case RTSDUR_BA_F0: //RTSDuration_ba_f0
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
453 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
454 byPktType, cbFrameLength, wRate, bNeedAck);
457 case RTSDUR_AA_F0: //RTSDuration_aa_f0
458 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
459 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
460 byPktType, cbFrameLength, wRate, bNeedAck);
463 case RTSDUR_BA_F1: //RTSDuration_ba_f1
464 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
465 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
466 byPktType, cbFrameLength, wRate, bNeedAck);
469 case RTSDUR_AA_F1: //RTSDuration_aa_f1
470 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
471 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
472 byPktType, cbFrameLength, wRate, bNeedAck);
475 case CTSDUR_BA_F0: //CTSDuration_ba_f0
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
477 byPktType, cbFrameLength, wRate, bNeedAck);
480 case CTSDUR_BA_F1: //CTSDuration_ba_f1
481 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
482 byPktType, cbFrameLength, wRate, bNeedAck);
489 return cpu_to_le16((u16)uDurTime);
492 static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
493 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
495 /* Get SignalField,ServiceField,Length */
496 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
497 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
498 PK_TYPE_11B, &buf->b);
500 /* Get Duration and TimeStamp */
501 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
502 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
504 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
505 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
506 priv->byTopCCKBasicRate);
508 return buf->wDuration_a;
511 static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
512 u16 rate, struct vnt_tx_datahead_g_fb *buf,
513 u32 frame_len, int need_ack)
515 /* Get SignalField,ServiceField,Length */
516 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
518 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
519 PK_TYPE_11B, &buf->b);
521 /* Get Duration and TimeStamp */
522 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
523 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
525 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
526 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
528 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
529 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
530 priv->byTopCCKBasicRate);
532 return buf->wDuration_a;
535 static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
536 u16 rate, struct vnt_tx_datahead_a_fb *buf,
537 u32 frame_len, int need_ack)
539 /* Get SignalField,ServiceField,Length */
540 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
541 /* Get Duration and TimeStampOff */
542 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
544 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
545 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
547 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
549 return buf->wDuration;
552 static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
553 u16 rate, struct vnt_tx_datahead_ab *buf,
554 u32 frame_len, int need_ack)
556 /* Get SignalField,ServiceField,Length */
557 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
558 /* Get Duration and TimeStampOff */
559 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
561 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
563 return buf->wDuration;
566 static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
567 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
570 rts->duration = duration;
571 rts->frame_control = TYPE_CTL_RTS;
573 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
574 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
576 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
578 if (priv->eOPMode == OP_MODE_AP)
579 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
581 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
586 static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
587 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
588 u8 pkt_type, u32 frame_len, int need_ack,
589 u16 current_rate, u8 fb_option)
591 u16 rts_frame_len = 20;
593 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
594 PK_TYPE_11B, &buf->b);
595 BBvCalculateParameter(priv, rts_frame_len,
596 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
598 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
599 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
600 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
601 pkt_type, current_rate, need_ack, fb_option);
602 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
603 pkt_type, current_rate, need_ack, fb_option);
605 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
607 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
608 &buf->data_head, frame_len, need_ack);
611 static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
612 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
613 u8 pkt_type, u32 frame_len, int need_ack,
614 u16 current_rate, u8 fb_option)
616 u16 rts_frame_len = 20;
618 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
619 PK_TYPE_11B, &buf->b);
620 BBvCalculateParameter(priv, rts_frame_len,
621 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
624 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
625 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
626 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
627 pkt_type, current_rate, need_ack, fb_option);
628 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
629 pkt_type, current_rate, need_ack, fb_option);
632 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
633 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
634 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
635 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
636 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
637 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
638 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
639 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
641 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
643 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
644 &buf->data_head, frame_len, need_ack);
647 static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
648 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
649 u8 pkt_type, u32 frame_len, int need_ack,
650 u16 current_rate, u8 fb_option)
652 u16 rts_frame_len = 20;
654 BBvCalculateParameter(priv, rts_frame_len,
655 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
657 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
658 pkt_type, current_rate, need_ack, fb_option);
660 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
662 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
663 &buf->data_head, frame_len, need_ack);
666 static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
667 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
668 u8 pkt_type, u32 frame_len, int need_ack,
669 u16 current_rate, u8 fb_option)
671 u16 rts_frame_len = 20;
673 BBvCalculateParameter(priv, rts_frame_len,
674 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
676 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
677 pkt_type, current_rate, need_ack, fb_option);
679 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
680 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
682 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
683 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
685 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
687 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
688 &buf->data_head, frame_len, need_ack);
691 static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
692 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
693 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
699 /* Note: So far RTSHead doesn't appear in ATIM
700 * & Beacom DMA, so we don't need to take them
702 * Otherwise, we need to modified codes for them.
707 if (byFBOption == AUTO_FB_NONE)
708 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
709 psEthHeader, byPktType, cbFrameLength,
710 bNeedAck, wCurrentRate, byFBOption);
712 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
713 psEthHeader, byPktType, cbFrameLength,
714 bNeedAck, wCurrentRate, byFBOption);
718 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
719 psEthHeader, byPktType, cbFrameLength,
720 bNeedAck, wCurrentRate, byFBOption);
724 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
725 psEthHeader, byPktType, cbFrameLength,
726 bNeedAck, wCurrentRate, byFBOption);
732 static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
733 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
734 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
736 u32 uCTSFrameLen = 14;
741 if (byFBOption != AUTO_FB_NONE) {
743 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
744 /* Get SignalField,ServiceField,Length */
745 BBvCalculateParameter(pDevice, uCTSFrameLen,
746 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
747 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
748 cbFrameLength, byPktType,
749 wCurrentRate, bNeedAck, byFBOption);
750 /* Get CTSDuration_ba_f0 */
751 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
752 CTSDUR_BA_F0, cbFrameLength, byPktType,
753 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
754 /* Get CTSDuration_ba_f1 */
755 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
756 CTSDUR_BA_F1, cbFrameLength, byPktType,
757 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
758 /* Get CTS Frame body */
759 pBuf->data.duration = pBuf->wDuration_ba;
760 pBuf->data.frame_control = TYPE_CTL_CTS;
761 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
763 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
764 &pBuf->data_head, cbFrameLength, bNeedAck);
766 struct vnt_cts *pBuf = &head->cts_g;
767 /* Get SignalField,ServiceField,Length */
768 BBvCalculateParameter(pDevice, uCTSFrameLen,
769 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
770 /* Get CTSDuration_ba */
771 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
772 CTSDUR_BA, cbFrameLength, byPktType,
773 wCurrentRate, bNeedAck, byFBOption);
774 /*Get CTS Frame body*/
775 pBuf->data.duration = pBuf->wDuration_ba;
776 pBuf->data.frame_control = TYPE_CTL_CTS;
777 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
779 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
780 &pBuf->data_head, cbFrameLength, bNeedAck);
789 * Generate FIFO control for MAC & Baseband controller
793 * pDevice - Pointer to adpater
794 * pTxDataHead - Transmit Data Buffer
795 * pTxBufHead - pTxBufHead
796 * pvRrvTime - pvRrvTime
799 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
800 * bNeedACK - If need ACK
801 * uDMAIdx - DMA Index
809 static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
810 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
811 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
812 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
814 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
815 union vnt_tx_data_head *head = NULL;
816 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
818 u8 byFBOption = AUTO_FB_NONE;
820 pFifoHead->wReserved = wCurrentRate;
821 wFifoCtl = pFifoHead->wFIFOCtl;
823 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
824 byFBOption = AUTO_FB_0;
825 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
826 byFBOption = AUTO_FB_1;
831 if (pDevice->bLongHeader)
832 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
834 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
836 struct vnt_rrv_time_rts *pBuf =
837 &tx_buffer->tx_head.tx_rts.rts;
839 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
840 byPktType, cbFrameSize, wCurrentRate);
841 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
842 byPktType, cbFrameSize, wCurrentRate);
843 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
844 byPktType, cbFrameSize, wCurrentRate);
846 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
847 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
848 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
849 PK_TYPE_11B, cbFrameSize,
850 pDevice->byTopCCKBasicRate, bNeedACK);
853 *mic_hdr = &tx_buffer->
854 tx_head.tx_rts.tx.mic.hdr;
855 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
857 head = &tx_buffer->tx_head.tx_rts.tx.head;
861 return s_vFillRTSHead(pDevice, byPktType, head,
862 cbFrameSize, bNeedACK, psEthHeader,
863 wCurrentRate, byFBOption);
866 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
869 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
870 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
871 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
872 PK_TYPE_11B, cbFrameSize,
873 pDevice->byTopCCKBasicRate, bNeedACK);
875 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
876 byPktType, cbFrameSize, wCurrentRate);
879 *mic_hdr = &tx_buffer->
880 tx_head.tx_cts.tx.mic.hdr;
881 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
883 head = &tx_buffer->tx_head.tx_cts.tx.head;
887 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
888 head, cbFrameSize, bNeedACK, wCurrentRate,
891 } else if (byPktType == PK_TYPE_11A) {
893 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
894 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
896 head = &tx_buffer->tx_head.tx_ab.tx.head;
900 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
903 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
904 byPktType, cbFrameSize, wCurrentRate);
906 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
907 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
910 return s_vFillRTSHead(pDevice, byPktType, head,
911 cbFrameSize, bNeedACK, psEthHeader,
912 wCurrentRate, byFBOption);
914 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
917 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
918 PK_TYPE_11A, cbFrameSize,
919 wCurrentRate, bNeedACK);
921 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
922 wCurrentRate, &head->data_head_a_fb,
923 cbFrameSize, bNeedACK);
925 } else if (byPktType == PK_TYPE_11B) {
927 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
928 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
930 head = &tx_buffer->tx_head.tx_ab.tx.head;
934 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
937 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
938 byPktType, cbFrameSize, wCurrentRate);
940 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
941 PK_TYPE_11B, cbFrameSize, wCurrentRate,
945 return s_vFillRTSHead(pDevice, byPktType, head,
947 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
949 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
952 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
953 PK_TYPE_11B, cbFrameSize,
954 wCurrentRate, bNeedACK);
956 return vnt_rxtx_datahead_ab(pDevice, byPktType,
957 wCurrentRate, &head->data_head_ab,
958 cbFrameSize, bNeedACK);
965 u8 * pbyBuffer,//point to pTxBufHead
966 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
967 unsigned int cbFragmentSize,//Hdr+payoad+FCS
970 static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
971 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
972 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
973 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
974 u32 *pcbHeaderLen, u32 *pcbTotalLen)
976 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
977 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
978 u32 cbFrameSize, cbFrameBodySize;
980 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
981 u32 cbFCSlen = 4, cbMICHDR = 0;
984 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
985 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
986 u8 abySNAP_Bridgetunnel[ETH_ALEN]
987 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
989 u32 cbHeaderLength = 0, uPadding = 0;
990 struct vnt_mic_hdr *pMICHDR;
991 u8 byFBOption = AUTO_FB_NONE, byFragType;
993 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
994 u32 *pdwMIC_L, *pdwMIC_R;
995 int bSoftWEP = false;
999 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
1000 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1001 bSoftWEP = true; /* WEP 256 */
1005 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
1006 if (pDevice->dwDiagRefCount == 0) {
1015 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
1018 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
1020 if (pDevice->dwDiagRefCount != 0) {
1022 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1023 } else { //if (pDevice->dwDiagRefCount != 0) {
1024 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1025 (pDevice->eOPMode == OP_MODE_AP)) {
1026 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
1028 pTxBufHead->wFIFOCtl =
1029 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1032 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1036 // MSDUs in Infra mode always need ACK
1038 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1040 } //if (pDevice->dwDiagRefCount != 0) {
1042 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1045 if (pDevice->bLongHeader)
1046 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1048 //Set FRAGCTL_MACHDCNT
1049 if (pDevice->bLongHeader) {
1050 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1052 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1054 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
1056 //Set FIFOCTL_GrpAckPolicy
1057 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1058 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1061 /* Set Auto Fallback Ctl */
1062 if (wCurrentRate >= RATE_18M) {
1063 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1064 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1066 pDevice->tx_rate_fb0 =
1067 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1068 pDevice->tx_rate_fb1 =
1069 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1071 byFBOption = AUTO_FB_0;
1072 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1073 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1074 pDevice->tx_rate_fb0 =
1075 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1076 pDevice->tx_rate_fb1 =
1077 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1079 byFBOption = AUTO_FB_1;
1083 if (bSoftWEP != true) {
1084 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1085 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1086 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1088 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1090 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1092 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1093 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1098 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1099 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1103 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1104 cbIVlen = 8;//IV+ExtIV
1108 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1109 cbIVlen = 8;//RSN Header
1111 cbMICHDR = sizeof(struct vnt_mic_hdr);
1113 if (bSoftWEP == false) {
1114 //MAC Header should be padding 0 to DW alignment.
1115 uPadding = 4 - (cbMACHdLen%4);
1120 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1122 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1126 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1129 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
1130 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1132 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1133 if (byFBOption == AUTO_FB_NONE) {
1134 if (bRTS == true) {//RTS_need
1135 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1136 cbMICHDR + sizeof(struct vnt_rts_g);
1138 else { //RTS_needless
1139 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1140 cbMICHDR + sizeof(struct vnt_cts);
1144 if (bRTS == true) {//RTS_need
1145 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1146 cbMICHDR + sizeof(struct vnt_rts_g_fb);
1148 else if (bRTS == false) { //RTS_needless
1149 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1150 cbMICHDR + sizeof(struct vnt_cts_fb);
1154 else {//802.11a/b packet
1155 if (byFBOption == AUTO_FB_NONE) {
1156 if (bRTS == true) {//RTS_need
1157 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1158 cbMICHDR + sizeof(struct vnt_rts_ab);
1160 else if (bRTS == false) { //RTS_needless, no MICHDR
1161 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1162 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
1166 if (bRTS == true) {//RTS_need
1167 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1168 cbMICHDR + sizeof(struct vnt_rts_a_fb);
1170 else if (bRTS == false) { //RTS_needless
1171 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1172 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
1177 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1178 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1179 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1181 //=========================
1183 //=========================
1184 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1185 byFragType = FRAGCTL_NONFRAG;
1186 //uDMAIdx = TYPE_AC0DMA;
1187 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1189 /* Fill FIFO, RrvTime, RTS and CTS */
1190 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1191 tx_buffer, &pMICHDR, cbMICHDR,
1192 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
1194 // Generate TX MAC Header
1195 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
1196 byFragType, uDMAIdx, 0);
1198 if (bNeedEncryption == true) {
1200 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1201 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
1203 if (pDevice->bEnableHostWEP) {
1204 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1205 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1210 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
1211 if (pDevice->dwDiagRefCount == 0) {
1212 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1213 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
1214 memcpy((u8 *) (pbyPayloadHead),
1215 abySNAP_Bridgetunnel, 6);
1217 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1219 pbyType = (u8 *) (pbyPayloadHead + 6);
1220 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1222 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
1228 if (pPacket != NULL) {
1229 // Copy the Packet into a tx Buffer
1230 memcpy((pbyPayloadHead + cb802_1_H_len),
1231 (pPacket + ETH_HLEN),
1232 uSkbPacketLen - ETH_HLEN
1236 // while bRelayPacketSend psEthHeader is point to header+payload
1237 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
1240 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1242 ///////////////////////////////////////////////////////////////////
1244 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1245 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1246 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1248 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1249 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1250 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1253 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1254 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
1256 // DO Software Michael
1257 MIC_vInit(dwMICKey0, dwMICKey1);
1258 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
1260 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
1261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1262 dwMICKey0, dwMICKey1);
1264 ///////////////////////////////////////////////////////////////////
1266 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1267 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1268 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
1270 //DBG_PRN_GRP12(("\n\n\n"));
1272 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1274 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1275 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
1277 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1280 if (pDevice->bTxMICFail == true) {
1283 pDevice->bTxMICFail = false;
1285 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1286 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1287 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1290 if (bSoftWEP == true) {
1292 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
1294 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1295 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1296 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
1297 cbFrameSize -= cbICVlen;
1300 cbFrameSize -= cbFCSlen;
1302 *pcbHeaderLen = cbHeaderLength;
1303 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1305 //Set FragCtl in TxBufferHead
1306 pTxBufHead->wFragCtl |= (u16)byFragType;
1315 * Translate 802.3 to 802.11 header
1319 * pDevice - Pointer to adapter
1320 * dwTxBufferAddr - Transmit Buffer
1321 * pPacket - Packet from upper layer
1322 * cbPacketSize - Transmit Data Length
1324 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1325 * pcbAppendPayload - size of append payload for 802.1H translation
1327 * Return Value: none
1331 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
1332 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
1333 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
1335 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
1337 pMACHeader->frame_control = TYPE_802_11_DATA;
1339 if (pDevice->eOPMode == OP_MODE_AP) {
1340 memcpy(&(pMACHeader->addr1[0]),
1341 &(psEthHeader->h_dest[0]),
1343 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1344 memcpy(&(pMACHeader->addr3[0]),
1345 &(psEthHeader->h_source[0]),
1347 pMACHeader->frame_control |= FC_FROMDS;
1349 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1350 memcpy(&(pMACHeader->addr1[0]),
1351 &(psEthHeader->h_dest[0]),
1353 memcpy(&(pMACHeader->addr2[0]),
1354 &(psEthHeader->h_source[0]),
1356 memcpy(&(pMACHeader->addr3[0]),
1357 &(pDevice->abyBSSID[0]),
1360 memcpy(&(pMACHeader->addr3[0]),
1361 &(psEthHeader->h_dest[0]),
1363 memcpy(&(pMACHeader->addr2[0]),
1364 &(psEthHeader->h_source[0]),
1366 memcpy(&(pMACHeader->addr1[0]),
1367 &(pDevice->abyBSSID[0]),
1369 pMACHeader->frame_control |= FC_TODS;
1374 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
1376 pMACHeader->duration_id = cpu_to_le16(wDuration);
1378 if (pDevice->bLongHeader) {
1379 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1380 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
1381 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
1383 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1385 //Set FragNumber in Sequence Control
1386 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
1388 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1389 pDevice->wSeqCounter++;
1390 if (pDevice->wSeqCounter > 0x0fff)
1391 pDevice->wSeqCounter = 0;
1394 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1395 pMACHeader->frame_control |= FC_MOREFRAG;
1402 * Request instructs a MAC to transmit a 802.11 management packet through
1403 * the adapter onto the medium.
1407 * hDeviceContext - Pointer to the adapter
1408 * pPacket - A pointer to a descriptor for the packet to transmit
1412 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1416 CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1417 struct vnt_tx_mgmt *pPacket)
1419 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1420 struct vnt_tx_buffer *pTX_Buffer;
1421 struct vnt_usb_send_context *pContext;
1422 struct vnt_tx_fifo_head *pTxBufHead;
1423 struct ieee80211_hdr *pMACHeader;
1424 struct ethhdr sEthHeader;
1425 u8 byPktType, *pbyTxBufferAddr;
1426 struct vnt_mic_hdr *pMICHDR = NULL;
1427 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
1428 int bNeedACK, bIsPSPOLL = false;
1429 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1433 u16 wCurrentRate = RATE_1M;
1435 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
1437 if (NULL == pContext) {
1438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1439 return CMD_STATUS_RESOURCES;
1442 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
1443 cbFrameBodySize = pPacket->cbPayloadLen;
1444 pTxBufHead = &pTX_Buffer->fifo_head;
1445 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1446 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1448 if (pDevice->byBBType == BB_TYPE_11A) {
1449 wCurrentRate = RATE_6M;
1450 byPktType = PK_TYPE_11A;
1452 wCurrentRate = RATE_1M;
1453 byPktType = PK_TYPE_11B;
1456 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1457 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1458 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1459 // to set power here.
1460 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1461 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1463 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1465 pDevice->wCurrentRate = wCurrentRate;
1468 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1469 pTxBufHead->wFIFOCtl = 0;
1471 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1472 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1474 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1475 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1477 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1478 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1481 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1482 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1484 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
1489 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1492 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1493 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1495 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1496 //Set Preamble type always long
1497 //pDevice->byPreambleType = PREAMBLE_LONG;
1498 // probe-response don't retry
1499 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1500 // bNeedACK = false;
1501 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1505 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1507 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
1509 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1511 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1514 //Set FRAGCTL_MACHDCNT
1515 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
1518 // Although spec says MMPDU can be fragmented; In most case,
1519 // no one will send a MMPDU under fragmentation. With RTS may occur.
1520 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
1522 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1523 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1526 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1528 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1529 cbIVlen = 8;//IV+ExtIV
1532 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1533 //We need to get seed here for filling TxKey entry.
1534 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1535 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1537 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1538 cbIVlen = 8;//RSN Header
1540 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1541 pDevice->bAES = true;
1543 //MAC Header should be padding 0 to DW alignment.
1544 uPadding = 4 - (cbMacHdLen%4);
1548 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1550 //Set FIFOCTL_GrpAckPolicy
1551 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1552 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1554 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1556 //Set RrvTime/RTS/CTS Buffer
1557 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1558 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1559 sizeof(struct vnt_cts);
1561 else { // 802.11a/b packet
1562 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1563 sizeof(struct vnt_tx_datahead_ab);
1566 memcpy(&(sEthHeader.h_dest[0]),
1567 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1569 memcpy(&(sEthHeader.h_source[0]),
1570 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1572 //=========================
1574 //=========================
1575 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
1577 /* Fill FIFO,RrvTime,RTS,and CTS */
1578 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1579 pTX_Buffer, &pMICHDR, 0,
1580 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
1582 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
1584 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1586 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1588 u8 * pbyPayloadHead;
1590 PSKeyItem pTransmitKey = NULL;
1592 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1593 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
1595 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
1596 (pDevice->bLinkPass == true)) {
1597 pbyBSSID = pDevice->abyBSSID;
1599 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1601 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1602 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1606 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1611 pbyBSSID = pDevice->abyBroadcastAddr;
1612 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1613 pTransmitKey = NULL;
1614 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1616 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1620 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1621 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
1623 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
1624 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
1628 // Copy the Packet into a tx Buffer
1629 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1632 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1633 pDevice->wSeqCounter++ ;
1634 if (pDevice->wSeqCounter > 0x0fff)
1635 pDevice->wSeqCounter = 0;
1638 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1639 // of FIFO control header.
1640 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1641 // in the same place of other packet's Duration-field).
1642 // And it will cause Cisco-AP to issue Disassociation-packet
1643 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1644 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1645 tx_cts.tx.head.cts_g.data_head;
1646 data_head->wDuration_a =
1647 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1648 data_head->wDuration_b =
1649 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1651 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1652 tx_ab.tx.head.data_head_ab;
1653 data_head->wDuration =
1654 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1658 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
1659 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
1660 pTX_Buffer->byType = 0x00;
1662 pContext->pPacket = NULL;
1663 pContext->Type = CONTEXT_MGMT_PACKET;
1664 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
1666 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1667 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1668 &pMACHeader->addr1[0], (u16)cbFrameSize,
1669 pTxBufHead->wFIFOCtl);
1672 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1673 &pMACHeader->addr3[0], (u16)cbFrameSize,
1674 pTxBufHead->wFIFOCtl);
1677 PIPEnsSendBulkOut(pDevice,pContext);
1678 return CMD_STATUS_PENDING;
1681 CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1682 struct vnt_tx_mgmt *pPacket)
1684 struct vnt_beacon_buffer *pTX_Buffer;
1685 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1686 u32 cbHeaderSize = 0;
1687 u16 wTxBufSize = sizeof(STxShortBufHead);
1688 PSTxShortBufHead pTxBufHead;
1689 struct ieee80211_hdr *pMACHeader;
1690 struct vnt_tx_datahead_ab *pTxDataHead;
1692 u32 cbFrameBodySize;
1694 u8 *pbyTxBufferAddr;
1695 struct vnt_usb_send_context *pContext;
1698 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
1699 if (NULL == pContext) {
1700 status = CMD_STATUS_RESOURCES;
1701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1705 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
1706 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
1708 cbFrameBodySize = pPacket->cbPayloadLen;
1710 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1711 wTxBufSize = sizeof(STxShortBufHead);
1713 if (pDevice->byBBType == BB_TYPE_11A) {
1714 wCurrentRate = RATE_6M;
1715 pTxDataHead = (struct vnt_tx_datahead_ab *)
1716 (pbyTxBufferAddr + wTxBufSize);
1717 //Get SignalField,ServiceField,Length
1718 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1720 //Get Duration and TimeStampOff
1721 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
1722 PK_TYPE_11A, false);
1723 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
1724 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
1726 wCurrentRate = RATE_1M;
1727 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1728 pTxDataHead = (struct vnt_tx_datahead_ab *)
1729 (pbyTxBufferAddr + wTxBufSize);
1730 //Get SignalField,ServiceField,Length
1731 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1733 //Get Duration and TimeStampOff
1734 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
1735 PK_TYPE_11B, false);
1736 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
1737 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
1740 //Generate Beacon Header
1741 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
1742 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1744 pMACHeader->duration_id = 0;
1745 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1746 pDevice->wSeqCounter++ ;
1747 if (pDevice->wSeqCounter > 0x0fff)
1748 pDevice->wSeqCounter = 0;
1750 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1752 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
1753 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
1754 pTX_Buffer->byType = 0x01;
1756 pContext->pPacket = NULL;
1757 pContext->Type = CONTEXT_MGMT_PACKET;
1758 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
1760 PIPEnsSendBulkOut(pDevice,pContext);
1761 return CMD_STATUS_PENDING;
1765 void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1767 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1768 struct vnt_tx_buffer *pTX_Buffer;
1769 struct vnt_tx_fifo_head *pTxBufHead;
1771 u8 *pbyTxBufferAddr;
1772 u32 uDuration, cbReqCount;
1773 struct ieee80211_hdr *pMACHeader;
1774 u32 cbHeaderSize, cbFrameBodySize;
1775 int bNeedACK, bIsPSPOLL = false;
1777 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1779 u32 cbMICHDR = 0, uLength = 0;
1780 u32 dwMICKey0, dwMICKey1;
1782 u32 *pdwMIC_L, *pdwMIC_R;
1785 struct ethhdr sEthHeader;
1786 struct vnt_mic_hdr *pMICHDR;
1787 u32 wCurrentRate = RATE_1M;
1788 PUWLAN_80211HDR p80211Header;
1790 int bNodeExist = false;
1792 PSKeyItem pTransmitKey = NULL;
1793 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1794 u32 cbExtSuppRate = 0;
1795 struct vnt_usb_send_context *pContext;
1799 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1800 cbFrameBodySize = 0;
1803 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1805 p80211Header = (PUWLAN_80211HDR)skb->data;
1807 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
1809 if (NULL == pContext) {
1810 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1811 dev_kfree_skb_irq(skb);
1815 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
1816 pTxBufHead = &pTX_Buffer->fifo_head;
1817 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1818 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1820 if (pDevice->byBBType == BB_TYPE_11A) {
1821 wCurrentRate = RATE_6M;
1822 byPktType = PK_TYPE_11A;
1824 wCurrentRate = RATE_1M;
1825 byPktType = PK_TYPE_11B;
1828 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1829 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1830 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1831 // to set power here.
1832 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1833 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1835 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1838 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1841 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1842 pTxBufHead->wFIFOCtl = 0;
1844 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1845 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1847 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1848 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1850 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1851 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1854 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1855 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1857 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
1859 if (pDevice->bEnableHostWEP) {
1865 if (pDevice->bEnableHostWEP) {
1866 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
1870 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1873 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1874 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1876 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1877 //Set Preamble type always long
1878 //pDevice->byPreambleType = PREAMBLE_LONG;
1880 // probe-response don't retry
1881 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1882 // bNeedACK = false;
1883 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1887 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1889 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
1891 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1893 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1896 // hostapd daemon ext support rate patch
1897 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1899 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1900 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1903 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1904 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1907 if (cbExtSuppRate >0) {
1908 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1912 //Set FRAGCTL_MACHDCNT
1913 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
1916 // Although spec says MMPDU can be fragmented; In most case,
1917 // no one will send a MMPDU under fragmentation. With RTS may occur.
1918 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
1920 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1921 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1924 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1926 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1927 cbIVlen = 8;//IV+ExtIV
1930 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1931 //We need to get seed here for filling TxKey entry.
1932 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1933 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1935 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1936 cbIVlen = 8;//RSN Header
1938 cbMICHDR = sizeof(struct vnt_mic_hdr);
1939 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1940 pDevice->bAES = true;
1942 //MAC Header should be padding 0 to DW alignment.
1943 uPadding = 4 - (cbMacHdLen%4);
1947 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1949 //Set FIFOCTL_GrpAckPolicy
1950 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1951 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1953 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1955 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1956 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
1957 sizeof(struct vnt_cts);
1960 else {//802.11a/b packet
1961 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
1962 sizeof(struct vnt_tx_datahead_ab);
1964 memcpy(&(sEthHeader.h_dest[0]),
1965 &(p80211Header->sA3.abyAddr1[0]),
1967 memcpy(&(sEthHeader.h_source[0]),
1968 &(p80211Header->sA3.abyAddr2[0]),
1970 //=========================
1972 //=========================
1973 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
1975 /* Fill FIFO,RrvTime,RTS,and CTS */
1976 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1977 pTX_Buffer, &pMICHDR, cbMICHDR,
1978 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
1980 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
1982 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1984 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1985 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1986 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
1988 // Copy the Packet into a tx Buffer
1989 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1991 // version set to 0, patch for hostapd deamon
1992 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
1993 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1995 // replace support rate, patch for hostapd daemon( only support 11M)
1996 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1997 if (cbExtSuppRate != 0) {
1998 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1999 memcpy((pbyPayloadHead + cbFrameBodySize),
2000 pMgmt->abyCurrSuppRates,
2001 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2003 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2004 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2005 pMgmt->abyCurrExtSuppRates,
2006 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2012 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2014 if (pDevice->bEnableHostWEP) {
2015 pTransmitKey = &STempKey;
2016 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2017 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2018 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2019 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2020 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2021 memcpy(pTransmitKey->abyKey,
2022 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2023 pTransmitKey->uKeyLength
2027 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2029 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2030 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
2032 // DO Software Michael
2033 MIC_vInit(dwMICKey0, dwMICKey1);
2034 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
2036 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
2037 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2038 " %X, %X\n", dwMICKey0, dwMICKey1);
2040 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2042 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2044 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2045 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2047 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2050 if (pDevice->bTxMICFail == true) {
2053 pDevice->bTxMICFail = false;
2056 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2057 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2058 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2059 *pdwMIC_L, *pdwMIC_R);
2063 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2064 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
2066 if (pDevice->bEnableHostWEP) {
2067 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2068 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2071 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
2072 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
2076 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
2077 pDevice->wSeqCounter++ ;
2078 if (pDevice->wSeqCounter > 0x0fff)
2079 pDevice->wSeqCounter = 0;
2082 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2083 // of FIFO control header.
2084 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2085 // in the same place of other packet's Duration-field).
2086 // And it will cause Cisco-AP to issue Disassociation-packet
2087 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2088 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2089 tx_cts.tx.head.cts_g.data_head;
2090 data_head->wDuration_a =
2091 cpu_to_le16(p80211Header->sA2.wDurationID);
2092 data_head->wDuration_b =
2093 cpu_to_le16(p80211Header->sA2.wDurationID);
2095 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2096 tx_ab.tx.head.data_head_ab;
2097 data_head->wDuration =
2098 cpu_to_le16(p80211Header->sA2.wDurationID);
2102 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
2103 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2104 pTX_Buffer->byType = 0x00;
2106 pContext->pPacket = skb;
2107 pContext->Type = CONTEXT_MGMT_PACKET;
2108 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
2110 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2111 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2112 &pMACHeader->addr1[0], (u16)cbFrameSize,
2113 pTxBufHead->wFIFOCtl);
2116 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2117 &pMACHeader->addr3[0], (u16)cbFrameSize,
2118 pTxBufHead->wFIFOCtl);
2120 PIPEnsSendBulkOut(pDevice,pContext);
2125 //TYPE_AC0DMA data tx
2128 * Tx packet via AC0DMA(DMA1)
2132 * pDevice - Pointer to the adapter
2133 * skb - Pointer to tx skb packet
2137 * Return Value: NULL
2140 int nsDMA_tx_packet(struct vnt_private *pDevice,
2141 u32 uDMAIdx, struct sk_buff *skb)
2143 struct net_device_stats *pStats = &pDevice->stats;
2144 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2145 struct vnt_tx_buffer *pTX_Buffer;
2146 u32 BytesToWrite = 0, uHeaderLen = 0;
2148 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2151 int bNeedEncryption = false;
2152 PSKeyItem pTransmitKey = NULL;
2155 int bTKIP_UseGTK = false;
2156 int bNeedDeAuth = false;
2158 int bNodeExist = false;
2159 struct vnt_usb_send_context *pContext;
2160 bool fConvertedPacket;
2162 u16 wKeepRate = pDevice->wCurrentRate;
2163 int bTxeapol_key = false;
2165 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2167 if (pDevice->uAssocCount == 0) {
2168 dev_kfree_skb_irq(skb);
2172 if (is_multicast_ether_addr((u8 *)(skb->data))) {
2175 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2177 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2178 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2180 pMgmt->abyPSTxMap[0] |= byMask[0];
2183 // multicast/broadcast data rate
2185 if (pDevice->byBBType != BB_TYPE_11A)
2186 pDevice->wCurrentRate = RATE_2M;
2188 pDevice->wCurrentRate = RATE_24M;
2189 // long preamble type
2190 pDevice->byPreambleType = PREAMBLE_SHORT;
2194 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
2196 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2198 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2200 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2202 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2203 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2205 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2209 // AP rate decided from node
2210 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2211 // tx preamble decided from node
2213 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2214 pDevice->byPreambleType = pDevice->byShortPreamble;
2217 pDevice->byPreambleType = PREAMBLE_LONG;
2223 if (bNodeExist == false) {
2224 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2225 dev_kfree_skb_irq(skb);
2230 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
2232 if (pContext == NULL) {
2233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2234 dev_kfree_skb_irq(skb);
2235 return STATUS_RESOURCES;
2238 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
2240 //mike add:station mode check eapol-key challenge--->
2242 u8 Protocol_Version; //802.1x Authentication
2243 u8 Packet_Type; //802.1x Authentication
2247 Protocol_Version = skb->data[ETH_HLEN];
2248 Packet_Type = skb->data[ETH_HLEN+1];
2249 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2250 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2251 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
2252 /* 802.1x OR eapol-key challenge frame transfer */
2253 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2254 (Packet_Type == 3)) {
2255 bTxeapol_key = true;
2256 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2257 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2258 if(Descriptor_type==254) {
2259 pDevice->fWPA_Authened = true;
2263 pDevice->fWPA_Authened = true;
2264 PRINT_K("WPA2(re-keying) ");
2266 PRINT_K("Authentication completed!!\n");
2268 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
2269 (Key_info & BIT8) && (Key_info & BIT9)) {
2270 pDevice->fWPA_Authened = true;
2271 PRINT_K("WPA2 Authentication completed!!\n");
2276 //mike add:station mode check eapol-key challenge<---
2278 if (pDevice->bEncryptionEnable == true) {
2279 bNeedEncryption = true;
2282 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2283 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2284 pbyBSSID = pDevice->abyBSSID;
2286 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2288 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2289 bTKIP_UseGTK = true;
2290 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2294 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2297 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2298 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2299 pbyBSSID = pDevice->sTxEthHeader.h_dest;
2300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2301 for (ii = 0; ii< 6; ii++)
2302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2306 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2310 pbyBSSID = pDevice->abyBroadcastAddr;
2311 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2312 pTransmitKey = NULL;
2313 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2314 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2317 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2319 bTKIP_UseGTK = true;
2320 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2325 if (pDevice->bEnableHostWEP) {
2326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2327 if (pDevice->bEncryptionEnable == true) {
2328 pTransmitKey = &STempKey;
2329 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2330 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2331 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2332 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2333 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2334 memcpy(pTransmitKey->abyKey,
2335 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2336 pTransmitKey->uKeyLength
2341 byPktType = (u8)pDevice->byPacketType;
2343 if (pDevice->bFixRate) {
2344 if (pDevice->byBBType == BB_TYPE_11B) {
2345 if (pDevice->uConnectionRate >= RATE_11M) {
2346 pDevice->wCurrentRate = RATE_11M;
2348 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2351 if ((pDevice->byBBType == BB_TYPE_11A) &&
2352 (pDevice->uConnectionRate <= RATE_6M)) {
2353 pDevice->wCurrentRate = RATE_6M;
2355 if (pDevice->uConnectionRate >= RATE_54M)
2356 pDevice->wCurrentRate = RATE_54M;
2358 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2363 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2364 // Adhoc Tx rate decided from node DB
2365 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
2366 // Multicast use highest data rate
2367 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2369 pDevice->byPreambleType = pDevice->byShortPreamble;
2372 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
2373 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2374 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2375 pDevice->byPreambleType = pDevice->byShortPreamble;
2379 pDevice->byPreambleType = PREAMBLE_LONG;
2381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2384 if (pDevice->byBBType != BB_TYPE_11A)
2385 pDevice->wCurrentRate = RATE_2M;
2387 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2388 // abyCurrExtSuppRates[]
2389 pDevice->byPreambleType = PREAMBLE_SHORT;
2390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2394 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2395 // Infra STA rate decided from AP Node, index = 0
2396 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2400 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
2401 if (pDevice->byBBType != BB_TYPE_11A) {
2402 pDevice->wCurrentRate = RATE_1M;
2403 pDevice->byACKRate = RATE_1M;
2404 pDevice->byTopCCKBasicRate = RATE_1M;
2405 pDevice->byTopOFDMBasicRate = RATE_6M;
2407 pDevice->wCurrentRate = RATE_6M;
2408 pDevice->byACKRate = RATE_6M;
2409 pDevice->byTopCCKBasicRate = RATE_1M;
2410 pDevice->byTopOFDMBasicRate = RATE_6M;
2414 DBG_PRT(MSG_LEVEL_DEBUG,
2415 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2416 pDevice->wCurrentRate);
2418 if (wKeepRate != pDevice->wCurrentRate) {
2419 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
2422 if (pDevice->wCurrentRate <= RATE_11M) {
2423 byPktType = PK_TYPE_11B;
2426 if (bNeedEncryption == true) {
2427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2428 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
2429 bNeedEncryption = false;
2430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
2431 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2432 if (pTransmitKey == NULL) {
2433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2436 if (bTKIP_UseGTK == true) {
2437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2440 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2441 pTransmitKey->dwKeyIndex);
2442 bNeedEncryption = true;
2447 if (pDevice->bEnableHostWEP) {
2448 if ((uNodeIndex != 0) &&
2449 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2451 pTransmitKey->dwKeyIndex);
2452 bNeedEncryption = true;
2458 if (pTransmitKey == NULL) {
2459 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2460 pContext->bBoolInUse = false;
2461 dev_kfree_skb_irq(skb);
2462 pStats->tx_dropped++;
2463 return STATUS_FAILURE;
2468 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2470 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
2471 pTX_Buffer, bNeedEncryption,
2472 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
2473 (u8 *)skb->data, pTransmitKey, uNodeIndex,
2474 pDevice->wCurrentRate,
2475 &uHeaderLen, &BytesToWrite
2478 if (fConvertedPacket == false) {
2479 pContext->bBoolInUse = false;
2480 dev_kfree_skb_irq(skb);
2481 return STATUS_FAILURE;
2484 if ( pDevice->bEnablePSMode == true ) {
2485 if ( !pDevice->bPSModeTxBurst ) {
2486 bScheduleCommand((void *) pDevice,
2487 WLAN_CMD_MAC_DISPOWERSAVING,
2489 pDevice->bPSModeTxBurst = true;
2493 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2494 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
2496 pContext->pPacket = skb;
2497 pContext->Type = CONTEXT_DATA_PACKET;
2498 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
2500 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2501 &pContext->sEthHeader.h_dest[0],
2502 (u16)(BytesToWrite-uHeaderLen),
2503 pTX_Buffer->fifo_head.wFIFOCtl);
2505 status = PIPEnsSendBulkOut(pDevice,pContext);
2507 if (bNeedDeAuth == true) {
2508 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
2510 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
2513 if(status!=STATUS_PENDING) {
2514 pContext->bBoolInUse = false;
2515 dev_kfree_skb_irq(skb);
2516 return STATUS_FAILURE;
2525 * Relay packet send (AC1DMA) from rx dpc.
2529 * pDevice - Pointer to the adapter
2530 * pPacket - Pointer to rx packet
2531 * cbPacketSize - rx ethernet frame size
2535 * Return Value: Return true if packet is copy to dma1; otherwise false
2538 int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2541 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2542 struct vnt_tx_buffer *pTX_Buffer;
2543 u32 BytesToWrite = 0, uHeaderLen = 0;
2544 u8 byPktType = PK_TYPE_11B;
2545 int bNeedEncryption = false;
2547 PSKeyItem pTransmitKey = NULL;
2549 struct vnt_usb_send_context *pContext;
2551 int fConvertedPacket;
2553 u16 wKeepRate = pDevice->wCurrentRate;
2555 pContext = (struct vnt_usb_send_context *)s_vGetFreeContext(pDevice);
2557 if (NULL == pContext) {
2561 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
2563 if (pDevice->bEncryptionEnable == true) {
2564 bNeedEncryption = true;
2566 pbyBSSID = pDevice->abyBroadcastAddr;
2567 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2568 pTransmitKey = NULL;
2569 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2571 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2575 if (pDevice->bEnableHostWEP) {
2576 if (uNodeIndex < MAX_NODE_NUM + 1) {
2577 pTransmitKey = &STempKey;
2578 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2579 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2580 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2581 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2582 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2583 memcpy(pTransmitKey->abyKey,
2584 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2585 pTransmitKey->uKeyLength
2590 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
2591 pContext->bBoolInUse = false;
2595 byPktTyp = (u8)pDevice->byPacketType;
2597 if (pDevice->bFixRate) {
2598 if (pDevice->byBBType == BB_TYPE_11B) {
2599 if (pDevice->uConnectionRate >= RATE_11M) {
2600 pDevice->wCurrentRate = RATE_11M;
2602 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2605 if ((pDevice->byBBType == BB_TYPE_11A) &&
2606 (pDevice->uConnectionRate <= RATE_6M)) {
2607 pDevice->wCurrentRate = RATE_6M;
2609 if (pDevice->uConnectionRate >= RATE_54M)
2610 pDevice->wCurrentRate = RATE_54M;
2612 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2617 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2620 if (wKeepRate != pDevice->wCurrentRate) {
2621 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
2624 if (pDevice->wCurrentRate <= RATE_11M)
2625 byPktType = PK_TYPE_11B;
2627 BytesToWrite = uDataLen + ETH_FCS_LEN;
2629 // Convert the packet to an usb frame and copy into our buffer
2630 // and send the irp.
2632 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2634 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
2635 pTX_Buffer, bNeedEncryption,
2636 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2637 pbySkbData, pTransmitKey, uNodeIndex,
2638 pDevice->wCurrentRate,
2639 &uHeaderLen, &BytesToWrite
2642 if (fConvertedPacket == false) {
2643 pContext->bBoolInUse = false;
2647 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2648 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
2650 pContext->pPacket = NULL;
2651 pContext->Type = CONTEXT_DATA_PACKET;
2652 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
2654 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2655 &pContext->sEthHeader.h_dest[0],
2656 (u16)(BytesToWrite - uHeaderLen),
2657 pTX_Buffer->fifo_head.wFIFOCtl);
2659 status = PIPEnsSendBulkOut(pDevice,pContext);