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 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Calculate fragment number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts required duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragment ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
66 /*--------------------- Static Definitions -------------------------*/
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
72 /*--------------------- Static Functions --------------------------*/
74 /*--------------------- Static Definitions -------------------------*/
75 #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
76 // packet size >= 256 -> direct send
78 static const unsigned short wTimeStampOff[2][MAX_RATE] = {
79 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
80 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
83 static const unsigned short wFB_Opt0[2][5] = {
84 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
85 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
87 static const unsigned short wFB_Opt1[2][5] = {
88 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
89 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
96 #define RTSDUR_BA_F0 4
97 #define RTSDUR_AA_F0 5
98 #define RTSDUR_BA_F1 6
99 #define RTSDUR_AA_F1 7
100 #define CTSDUR_BA_F0 8
101 #define CTSDUR_BA_F1 9
104 #define DATADUR_A_F0 12
105 #define DATADUR_A_F1 13
107 /*--------------------- Static Functions --------------------------*/
112 struct vnt_private *pDevice,
113 unsigned char *pbyBuf,
114 unsigned char *pbyIVHead,
115 PSKeyItem pTransmitKey,
116 unsigned char *pbyHdrBuf,
117 unsigned short wPayloadLen,
118 unsigned char *pMICHDR
124 struct vnt_private *pDevice,
125 unsigned char byPktType,
127 unsigned int cbFrameLength,
130 struct ieee80211_hdr *hdr,
131 unsigned short wCurrentRate,
132 unsigned char byFBOption
137 s_vGenerateTxParameter(
138 struct vnt_private *pDevice,
139 unsigned char byPktType,
144 unsigned int cbFrameSize,
146 unsigned int uDMAIdx,
148 unsigned short wCurrentRate
152 s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
153 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize,
154 unsigned int uDMAIdx, PSTxDesc pHeadTD,
155 PSEthernetHeader psEthHeader, unsigned char *pPacket,
156 bool bNeedEncrypt, PSKeyItem pTransmitKey,
157 unsigned int uNodeIndex, unsigned int *puMACfragNum);
162 struct vnt_private *pDevice,
163 unsigned char byPktType,
165 unsigned int cbFrameLength,
166 unsigned int uDMAIdx,
168 unsigned int uFragIdx,
169 unsigned int cbLastFragmentSize,
170 unsigned int uMACfragNum,
171 unsigned char byFBOption,
172 unsigned short wCurrentRate
175 /*--------------------- Export Variables --------------------------*/
180 struct vnt_private *pDevice,
181 unsigned char *pbyBuf,
182 unsigned char *pbyIVHead,
183 PSKeyItem pTransmitKey,
184 unsigned char *pbyHdrBuf,
185 unsigned short wPayloadLen,
186 unsigned char *pMICHDR
189 struct vnt_mic_hdr *mic_hdr = (struct vnt_mic_hdr *)pMICHDR;
190 unsigned long *pdwIV = (unsigned long *)pbyIVHead;
191 unsigned long *pdwExtIV = (unsigned long *)((unsigned char *)pbyIVHead+4);
192 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
193 unsigned long dwRevIVCounter;
194 unsigned char byKeyIndex = 0;
197 if (pTransmitKey == NULL)
200 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
201 *pdwIV = pDevice->dwIVCounter;
202 byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
204 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
205 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
206 memcpy(pDevice->abyPRNG, (unsigned char *)&(dwRevIVCounter), 3);
207 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
209 memcpy(pbyBuf, (unsigned char *)&(dwRevIVCounter), 3);
210 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
211 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
212 memcpy(pbyBuf+8, (unsigned char *)&(dwRevIVCounter), 3);
213 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
215 memcpy(pDevice->abyPRNG, pbyBuf, 16);
217 // Append IV after Mac Header
218 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
219 *pdwIV |= (unsigned long)byKeyIndex << 30;
220 *pdwIV = cpu_to_le32(*pdwIV);
221 pDevice->dwIVCounter++;
222 if (pDevice->dwIVCounter > WEP_IV_MASK)
223 pDevice->dwIVCounter = 0;
225 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
226 pTransmitKey->wTSC15_0++;
227 if (pTransmitKey->wTSC15_0 == 0)
228 pTransmitKey->dwTSC47_16++;
230 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
231 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
232 memcpy(pbyBuf, pDevice->abyPRNG, 16);
234 memcpy(pdwIV, pDevice->abyPRNG, 3);
236 *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
237 // Append IV&ExtIV after Mac Header
238 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
239 pr_debug("vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
241 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
242 pTransmitKey->wTSC15_0++;
243 if (pTransmitKey->wTSC15_0 == 0)
244 pTransmitKey->dwTSC47_16++;
246 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
250 *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
251 *pdwIV |= cpu_to_le16((unsigned short)(pTransmitKey->wTSC15_0));
252 //Append IV&ExtIV after Mac Header
253 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
257 mic_hdr->tx_priority = 0;
258 ether_addr_copy(mic_hdr->mic_addr2, pMACHeader->abyAddr2);
260 /* ccmp pn big endian order */
261 mic_hdr->ccmp_pn[0] = (u8)(pTransmitKey->dwTSC47_16 >> 24);
262 mic_hdr->ccmp_pn[1] = (u8)(pTransmitKey->dwTSC47_16 >> 16);
263 mic_hdr->ccmp_pn[2] = (u8)(pTransmitKey->dwTSC47_16 >> 8);
264 mic_hdr->ccmp_pn[3] = (u8)pTransmitKey->dwTSC47_16;
265 mic_hdr->ccmp_pn[4] = (u8)(pTransmitKey->wTSC15_0 >> 8);
266 mic_hdr->ccmp_pn[5] = (u8)pTransmitKey->wTSC15_0;
269 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
271 if (pDevice->bLongHeader)
272 mic_hdr->hlen = cpu_to_be16(28);
274 mic_hdr->hlen = cpu_to_be16(22);
276 ether_addr_copy(mic_hdr->addr1, pMACHeader->abyAddr1);
277 ether_addr_copy(mic_hdr->addr2, pMACHeader->abyAddr2);
280 ether_addr_copy(mic_hdr->addr3, pMACHeader->abyAddr3);
281 mic_hdr->frame_control =
282 cpu_to_le16(pMACHeader->wFrameCtl & 0xc78f);
283 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->wSeqCtl & 0xf);
285 if (pDevice->bLongHeader)
286 ether_addr_copy(mic_hdr->addr4, pMACHeader->abyAddr4);
293 struct vnt_private *pDevice,
294 PSKeyItem pTransmitKey,
295 unsigned char *pbyPayloadHead,
296 unsigned short wPayloadSize
299 unsigned int cbICVlen = 4;
300 unsigned long dwICV = 0xFFFFFFFFL;
301 unsigned long *pdwICV;
303 if (pTransmitKey == NULL)
306 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
307 //=======================================================================
308 // Append ICV after payload
309 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
310 pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
311 // finally, we must invert dwCRC to get the correct answer
312 *pdwICV = cpu_to_le32(~dwICV);
314 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
315 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
316 //=======================================================================
317 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
318 //=======================================================================
319 //Append ICV after payload
320 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
321 pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
322 // finally, we must invert dwCRC to get the correct answer
323 *pdwICV = cpu_to_le32(~dwICV);
325 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
326 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
327 //=======================================================================
331 static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
333 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
337 /*byPktType : PK_TYPE_11A 0
345 struct vnt_private *pDevice,
346 unsigned char byPktType,
347 unsigned int cbFrameLength,
348 unsigned short wRate,
352 unsigned int uDataTime, uAckTime;
354 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
355 if (byPktType == PK_TYPE_11B) //llb,CCK mode
356 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
357 else //11g 2.4G OFDM mode & 11a 5G OFDM mode
358 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
361 return uDataTime + pDevice->uSIFS + uAckTime;
366 static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
367 u32 frame_length, u16 rate, bool need_ack)
369 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
370 frame_length, rate, need_ack));
373 //byFreqType: 0=>5GHZ 1=>2.4GHZ
377 struct vnt_private *pDevice,
378 unsigned char byRTSRsvType,
379 unsigned char byPktType,
380 unsigned int cbFrameLength,
381 unsigned short wCurrentRate
384 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
386 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
388 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
389 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
390 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
391 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
392 } else if (byRTSRsvType == 1) { //RTSTxRrvTime_ba, only in 2.4GHZ
393 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
394 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
395 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);
399 } else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
400 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
401 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
402 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
403 return cpu_to_le16((u16)uRrvTime);
407 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
408 return cpu_to_le16((u16)uRrvTime);
411 //byFreqType 0: 5GHz, 1:2.4Ghz
415 struct vnt_private *pDevice,
416 unsigned char byDurType,
417 unsigned int cbFrameLength,
418 unsigned char byPktType,
419 unsigned short wRate,
421 unsigned int uFragIdx,
422 unsigned int cbLastFragmentSize,
423 unsigned int uMACfragNum,
424 unsigned char byFBOption
428 unsigned int uAckTime = 0, uNextPktTime = 0;
430 if (uFragIdx == (uMACfragNum-1))
434 case DATADUR_B: //DATADUR_B
435 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
437 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
438 return pDevice->uSIFS + uAckTime;
442 } else {//First Frag or Mid Frag
443 if (uFragIdx == (uMACfragNum-2))
444 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
446 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
449 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
450 return pDevice->uSIFS + uAckTime + uNextPktTime;
452 return pDevice->uSIFS + uNextPktTime;
457 case DATADUR_A: //DATADUR_A
458 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
460 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
461 return pDevice->uSIFS + uAckTime;
465 } else {//First Frag or Mid Frag
466 if (uFragIdx == (uMACfragNum-2))
467 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
469 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
472 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
473 return pDevice->uSIFS + uAckTime + uNextPktTime;
475 return pDevice->uSIFS + uNextPktTime;
480 case DATADUR_A_F0: //DATADUR_A_F0
481 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
483 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
484 return pDevice->uSIFS + uAckTime;
488 } else { //First Frag or Mid Frag
489 if (byFBOption == AUTO_FB_0) {
490 if (wRate < RATE_18M)
492 else if (wRate > RATE_54M)
495 if (uFragIdx == (uMACfragNum-2))
496 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
498 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
500 } else { // (byFBOption == AUTO_FB_1)
501 if (wRate < RATE_18M)
503 else if (wRate > RATE_54M)
506 if (uFragIdx == (uMACfragNum-2))
507 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
509 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
514 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
515 return pDevice->uSIFS + uAckTime + uNextPktTime;
517 return pDevice->uSIFS + uNextPktTime;
522 case DATADUR_A_F1: //DATADUR_A_F1
523 if (((uMACfragNum == 1)) || bLastFrag) {//Non Frag or Last Frag
525 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
526 return pDevice->uSIFS + uAckTime;
530 } else { //First Frag or Mid Frag
531 if (byFBOption == AUTO_FB_0) {
532 if (wRate < RATE_18M)
534 else if (wRate > RATE_54M)
537 if (uFragIdx == (uMACfragNum-2))
538 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
540 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
542 } else { // (byFBOption == AUTO_FB_1)
543 if (wRate < RATE_18M)
545 else if (wRate > RATE_54M)
548 if (uFragIdx == (uMACfragNum-2))
549 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
551 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
554 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
555 return pDevice->uSIFS + uAckTime + uNextPktTime;
557 return pDevice->uSIFS + uNextPktTime;
570 //byFreqType: 0=>5GHZ 1=>2.4GHZ
573 s_uGetRTSCTSDuration(
574 struct vnt_private *pDevice,
575 unsigned char byDurType,
576 unsigned int cbFrameLength,
577 unsigned char byPktType,
578 unsigned short wRate,
580 unsigned char byFBOption
583 unsigned int uCTSTime = 0, uDurTime = 0;
586 case RTSDUR_BB: //RTSDuration_bb
587 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
588 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
591 case RTSDUR_BA: //RTSDuration_ba
592 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
593 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
596 case RTSDUR_AA: //RTSDuration_aa
597 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
598 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
601 case CTSDUR_BA: //CTSDuration_ba
602 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
605 case RTSDUR_BA_F0: //RTSDuration_ba_f0
606 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
607 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
608 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
609 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
610 uDurTime = uCTSTime + 2 * pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
614 case RTSDUR_AA_F0: //RTSDuration_aa_f0
615 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
616 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
617 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
618 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
619 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
623 case RTSDUR_BA_F1: //RTSDuration_ba_f1
624 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
625 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
626 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
627 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
628 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
632 case RTSDUR_AA_F1: //RTSDuration_aa_f1
633 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
634 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
635 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
636 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
637 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
641 case CTSDUR_BA_F0: //CTSDuration_ba_f0
642 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
643 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
644 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
645 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
649 case CTSDUR_BA_F1: //CTSDuration_ba_f1
650 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
651 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
652 else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <= RATE_54M))
653 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
661 return cpu_to_le16((u16)uDurTime);
667 struct vnt_private *pDevice,
668 unsigned char byPktType,
670 unsigned int cbFrameLength,
671 unsigned int uDMAIdx,
673 unsigned int uFragIdx,
674 unsigned int cbLastFragmentSize,
675 unsigned int uMACfragNum,
676 unsigned char byFBOption,
677 unsigned short wCurrentRate
681 if (pTxDataHead == NULL)
685 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
686 if (byFBOption == AUTO_FB_NONE) {
687 struct vnt_tx_datahead_g *buf = pTxDataHead;
688 /* Get SignalField, ServiceField & Length */
689 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
692 vnt_get_phy_field(pDevice, cbFrameLength,
693 pDevice->byTopCCKBasicRate,
694 PK_TYPE_11B, &buf->b);
696 /* Get Duration and TimeStamp */
697 buf->duration_a = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
698 byPktType, wCurrentRate, bNeedAck, uFragIdx,
699 cbLastFragmentSize, uMACfragNum,
701 buf->duration_b = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
702 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
703 bNeedAck, uFragIdx, cbLastFragmentSize,
704 uMACfragNum, byFBOption));
706 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
707 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
709 return buf->duration_a;
712 struct vnt_tx_datahead_g_fb *buf = pTxDataHead;
713 /* Get SignalField, ServiceField & Length */
714 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
717 vnt_get_phy_field(pDevice, cbFrameLength,
718 pDevice->byTopCCKBasicRate,
719 PK_TYPE_11B, &buf->b);
720 /* Get Duration and TimeStamp */
721 buf->duration_a = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
722 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
723 buf->duration_b = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
724 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
725 buf->duration_a_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
726 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
727 buf->duration_a_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
728 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
730 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
731 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
733 return buf->duration_a;
734 } //if (byFBOption == AUTO_FB_NONE)
735 } else if (byPktType == PK_TYPE_11A) {
736 if ((byFBOption != AUTO_FB_NONE)) {
738 struct vnt_tx_datahead_a_fb *buf = pTxDataHead;
739 /* Get SignalField, ServiceField & Length */
740 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
743 /* Get Duration and TimeStampOff */
744 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
745 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
746 buf->duration_f0 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
747 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
748 buf->duration_f1 = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
749 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption));
750 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
751 return buf->duration;
753 struct vnt_tx_datahead_ab *buf = pTxDataHead;
754 /* Get SignalField, ServiceField & Length */
755 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
756 byPktType, &buf->ab);
758 /* Get Duration and TimeStampOff */
759 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
760 wCurrentRate, bNeedAck, uFragIdx,
761 cbLastFragmentSize, uMACfragNum,
764 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
765 return buf->duration;
768 struct vnt_tx_datahead_ab *buf = pTxDataHead;
769 /* Get SignalField, ServiceField & Length */
770 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
771 byPktType, &buf->ab);
772 /* Get Duration and TimeStampOff */
773 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
774 wCurrentRate, bNeedAck, uFragIdx,
775 cbLastFragmentSize, uMACfragNum,
777 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
778 return buf->duration;
786 struct vnt_private *pDevice,
787 unsigned char byPktType,
789 unsigned int cbFrameLength,
792 struct ieee80211_hdr *hdr,
793 unsigned short wCurrentRate,
794 unsigned char byFBOption
797 unsigned int uRTSFrameLen = 20;
803 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
804 // in this case we need to decrease its length by 4.
808 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
809 // Otherwise, we need to modify codes for them.
810 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
811 if (byFBOption == AUTO_FB_NONE) {
812 struct vnt_rts_g *buf = pvRTS;
813 /* Get SignalField, ServiceField & Length */
814 vnt_get_phy_field(pDevice, uRTSFrameLen,
815 pDevice->byTopCCKBasicRate,
816 PK_TYPE_11B, &buf->b);
818 vnt_get_phy_field(pDevice, uRTSFrameLen,
819 pDevice->byTopOFDMBasicRate,
823 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
824 cbFrameLength, PK_TYPE_11B,
825 pDevice->byTopCCKBasicRate,
826 bNeedAck, byFBOption);
828 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
829 cbFrameLength, byPktType,
830 wCurrentRate, bNeedAck,
833 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
834 cbFrameLength, byPktType,
835 wCurrentRate, bNeedAck,
838 buf->data.duration = buf->duration_aa;
839 /* Get RTS Frame body */
840 buf->data.frame_control =
841 cpu_to_le16(IEEE80211_FTYPE_CTL |
842 IEEE80211_STYPE_RTS);
844 ether_addr_copy(buf->data.ra, hdr->addr1);
845 ether_addr_copy(buf->data.ta, hdr->addr2);
847 struct vnt_rts_g_fb *buf = pvRTS;
848 /* Get SignalField, ServiceField & Length */
849 vnt_get_phy_field(pDevice, uRTSFrameLen,
850 pDevice->byTopCCKBasicRate,
851 PK_TYPE_11B, &buf->b);
853 vnt_get_phy_field(pDevice, uRTSFrameLen,
854 pDevice->byTopOFDMBasicRate,
858 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB,
859 cbFrameLength, PK_TYPE_11B,
860 pDevice->byTopCCKBasicRate,
861 bNeedAck, byFBOption);
863 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
864 cbFrameLength, byPktType,
865 wCurrentRate, bNeedAck,
868 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA,
869 cbFrameLength, byPktType,
870 wCurrentRate, bNeedAck,
872 buf->rts_duration_ba_f0 =
873 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0,
874 cbFrameLength, byPktType,
875 wCurrentRate, bNeedAck,
877 buf->rts_duration_aa_f0 =
878 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
879 cbFrameLength, byPktType,
880 wCurrentRate, bNeedAck,
882 buf->rts_duration_ba_f1 =
883 s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1,
884 cbFrameLength, byPktType,
885 wCurrentRate, bNeedAck,
887 buf->rts_duration_aa_f1 =
888 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
889 cbFrameLength, byPktType,
890 wCurrentRate, bNeedAck,
892 buf->data.duration = buf->duration_aa;
893 /* Get RTS Frame body */
894 buf->data.frame_control =
895 cpu_to_le16(IEEE80211_FTYPE_CTL |
896 IEEE80211_STYPE_RTS);
898 ether_addr_copy(buf->data.ra, hdr->addr1);
899 ether_addr_copy(buf->data.ta, hdr->addr2);
900 } // if (byFBOption == AUTO_FB_NONE)
901 } else if (byPktType == PK_TYPE_11A) {
902 if (byFBOption == AUTO_FB_NONE) {
903 struct vnt_rts_ab *buf = pvRTS;
904 /* Get SignalField, ServiceField & Length */
905 vnt_get_phy_field(pDevice, uRTSFrameLen,
906 pDevice->byTopOFDMBasicRate,
907 byPktType, &buf->ab);
910 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
911 cbFrameLength, byPktType,
912 wCurrentRate, bNeedAck,
914 buf->data.duration = buf->duration;
915 /* Get RTS Frame body */
916 buf->data.frame_control =
917 cpu_to_le16(IEEE80211_FTYPE_CTL |
918 IEEE80211_STYPE_RTS);
920 ether_addr_copy(buf->data.ra, hdr->addr1);
921 ether_addr_copy(buf->data.ta, hdr->addr2);
923 struct vnt_rts_a_fb *buf = pvRTS;
924 /* Get SignalField, ServiceField & Length */
925 vnt_get_phy_field(pDevice, uRTSFrameLen,
926 pDevice->byTopOFDMBasicRate,
930 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA,
931 cbFrameLength, byPktType,
932 wCurrentRate, bNeedAck,
934 buf->rts_duration_f0 =
935 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0,
936 cbFrameLength, byPktType,
937 wCurrentRate, bNeedAck,
939 buf->rts_duration_f1 =
940 s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1,
941 cbFrameLength, byPktType,
942 wCurrentRate, bNeedAck,
944 buf->data.duration = buf->duration;
945 /* Get RTS Frame body */
946 buf->data.frame_control =
947 cpu_to_le16(IEEE80211_FTYPE_CTL |
948 IEEE80211_STYPE_RTS);
950 ether_addr_copy(buf->data.ra, hdr->addr1);
951 ether_addr_copy(buf->data.ta, hdr->addr2);
953 } else if (byPktType == PK_TYPE_11B) {
954 struct vnt_rts_ab *buf = pvRTS;
955 /* Get SignalField, ServiceField & Length */
956 vnt_get_phy_field(pDevice, uRTSFrameLen,
957 pDevice->byTopCCKBasicRate,
958 PK_TYPE_11B, &buf->ab);
961 s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength,
962 byPktType, wCurrentRate, bNeedAck,
965 buf->data.duration = buf->duration;
966 /* Get RTS Frame body */
967 buf->data.frame_control =
968 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
970 ether_addr_copy(buf->data.ra, hdr->addr1);
971 ether_addr_copy(buf->data.ta, hdr->addr2);
978 struct vnt_private *pDevice,
979 unsigned int uDMAIdx,
980 unsigned char byPktType,
982 unsigned int cbFrameLength,
985 unsigned short wCurrentRate,
986 unsigned char byFBOption
989 unsigned int uCTSFrameLen = 14;
995 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
996 // in this case we need to decrease its length by 4.
1000 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1001 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1003 struct vnt_cts_fb *buf = pvCTS;
1004 /* Get SignalField, ServiceField & Length */
1005 vnt_get_phy_field(pDevice, uCTSFrameLen,
1006 pDevice->byTopCCKBasicRate,
1007 PK_TYPE_11B, &buf->b);
1010 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
1011 cbFrameLength, byPktType,
1012 wCurrentRate, bNeedAck,
1015 /* Get CTSDuration_ba_f0 */
1016 buf->cts_duration_ba_f0 =
1017 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0,
1018 cbFrameLength, byPktType,
1019 wCurrentRate, bNeedAck,
1022 /* Get CTSDuration_ba_f1 */
1023 buf->cts_duration_ba_f1 =
1024 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1,
1025 cbFrameLength, byPktType,
1026 wCurrentRate, bNeedAck,
1029 /* Get CTS Frame body */
1030 buf->data.duration = buf->duration_ba;
1032 buf->data.frame_control =
1033 cpu_to_le16(IEEE80211_FTYPE_CTL |
1034 IEEE80211_STYPE_CTS);
1036 buf->reserved2 = 0x0;
1038 ether_addr_copy(buf->data.ra,
1039 pDevice->abyCurrentNetAddr);
1040 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1041 struct vnt_cts *buf = pvCTS;
1042 /* Get SignalField, ServiceField & Length */
1043 vnt_get_phy_field(pDevice, uCTSFrameLen,
1044 pDevice->byTopCCKBasicRate,
1045 PK_TYPE_11B, &buf->b);
1047 /* Get CTSDuration_ba */
1049 s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
1050 cbFrameLength, byPktType,
1051 wCurrentRate, bNeedAck,
1054 /* Get CTS Frame body */
1055 buf->data.duration = buf->duration_ba;
1057 buf->data.frame_control =
1058 cpu_to_le16(IEEE80211_FTYPE_CTL |
1059 IEEE80211_STYPE_CTS);
1061 buf->reserved2 = 0x0;
1062 ether_addr_copy(buf->data.ra,
1063 pDevice->abyCurrentNetAddr);
1071 * Generate FIFO control for MAC & Baseband controller
1075 * pDevice - Pointer to adapter
1076 * pTxDataHead - Transmit Data Buffer
1077 * pTxBufHead - pTxBufHead
1078 * pvRrvTime - pvRrvTime
1079 * pvRTS - RTS Buffer
1081 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1082 * bNeedACK - If need ACK
1083 * uDescIdx - Desc Index
1087 * Return Value: none
1090 // unsigned int cbFrameSize,//Hdr+Payload+FCS
1093 s_vGenerateTxParameter(
1094 struct vnt_private *pDevice,
1095 unsigned char byPktType,
1100 unsigned int cbFrameSize,
1102 unsigned int uDMAIdx,
1104 unsigned short wCurrentRate
1107 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1108 unsigned short wFifoCtl;
1109 bool bDisCRC = false;
1110 unsigned char byFBOption = AUTO_FB_NONE;
1112 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1114 pFifoHead->wReserved = wCurrentRate;
1115 wFifoCtl = pFifoHead->wFIFOCtl;
1117 if (wFifoCtl & FIFOCTL_CRCDIS)
1120 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
1121 byFBOption = AUTO_FB_0;
1122 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
1123 byFBOption = AUTO_FB_1;
1125 if (pDevice->bLongHeader)
1126 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1131 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1132 if (pvRTS != NULL) { //RTS_need
1134 struct vnt_rrv_time_rts *buf = pvRrvTime;
1136 buf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
1137 buf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate);
1138 buf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
1139 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
1140 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
1142 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1143 } else {//RTS_needless, PCF mode
1144 struct vnt_rrv_time_cts *buf = pvRrvTime;
1146 buf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
1147 buf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK);
1148 buf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate);
1151 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1153 } else if (byPktType == PK_TYPE_11A) {
1154 if (pvRTS != NULL) {//RTS_need, non PCF mode
1155 struct vnt_rrv_time_ab *buf = pvRrvTime;
1157 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate);
1158 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK);
1161 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1162 } else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1163 struct vnt_rrv_time_ab *buf = pvRrvTime;
1165 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK);
1167 } else if (byPktType == PK_TYPE_11B) {
1168 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1169 struct vnt_rrv_time_ab *buf = pvRrvTime;
1171 buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
1172 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
1175 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1176 } else { //RTS_needless, non PCF mode
1177 struct vnt_rrv_time_ab *buf = pvRrvTime;
1179 buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK);
1185 s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1186 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize,
1187 unsigned int uDMAIdx, PSTxDesc pHeadTD,
1188 PSEthernetHeader psEthHeader, unsigned char *pPacket,
1189 bool bNeedEncrypt, PSKeyItem pTransmitKey,
1190 unsigned int is_pspoll, unsigned int *puMACfragNum)
1192 PDEVICE_TD_INFO td_info = pHeadTD->pTDInfo;
1193 struct sk_buff *skb = td_info->skb;
1194 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1195 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1196 struct vnt_tx_fifo_head *tx_buffer_head =
1197 (struct vnt_tx_fifo_head *)td_info->buf;
1198 u16 fifo_ctl = le16_to_cpu(tx_buffer_head->fifo_ctl);
1199 unsigned int cbFrameSize;
1201 unsigned char *pbyBuffer;
1202 unsigned int uLength = 0;
1203 unsigned int cbMICHDR = 0;
1204 unsigned int uMACfragNum = 1;
1205 unsigned int uPadding = 0;
1206 unsigned int cbReqCount = 0;
1207 bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK);
1208 bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS);
1210 unsigned int cbHeaderLength = 0;
1212 struct vnt_mic_hdr *pMICHDR;
1216 unsigned short wTxBufSize; // FFinfo size
1217 unsigned char byFBOption = AUTO_FB_NONE;
1219 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1221 cbFrameSize = skb->len + 4;
1223 if (info->control.hw_key) {
1224 switch (info->control.hw_key->cipher) {
1225 case WLAN_CIPHER_SUITE_CCMP:
1226 cbMICHDR = sizeof(struct vnt_mic_hdr);
1231 cbFrameSize += info->control.hw_key->icv_len;
1233 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1234 //MAC Header should be padding 0 to DW alignment.
1235 uPadding = 4 - (ieee80211_get_hdrlen_from_skb(skb) % 4);
1241 // Use for AUTO FALL BACK
1243 if (fifo_ctl & FIFOCTL_AUTO_FB_0)
1244 byFBOption = AUTO_FB_0;
1245 else if (fifo_ctl & FIFOCTL_AUTO_FB_1)
1246 byFBOption = AUTO_FB_1;
1248 //////////////////////////////////////////////////////
1249 //Set RrvTime/RTS/CTS Buffer
1250 wTxBufSize = sizeof(STxBufHead);
1251 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1253 if (byFBOption == AUTO_FB_NONE) {
1254 if (bRTS == true) {//RTS_need
1255 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1256 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1257 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1259 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1260 cbMICHDR + sizeof(struct vnt_rts_g));
1261 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1262 cbMICHDR + sizeof(struct vnt_rts_g) +
1263 sizeof(struct vnt_tx_datahead_g);
1264 } else { //RTS_needless
1265 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1266 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1268 pvCTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1269 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1270 sizeof(struct vnt_rrv_time_cts) + cbMICHDR + sizeof(struct vnt_cts));
1271 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1272 cbMICHDR + sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
1276 if (bRTS == true) {//RTS_need
1277 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1278 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts));
1279 pvRTS = (void *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
1281 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1282 cbMICHDR + sizeof(struct vnt_rts_g_fb));
1283 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1284 cbMICHDR + sizeof(struct vnt_rts_g_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1285 } else { //RTS_needless
1286 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1287 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts));
1289 pvCTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
1290 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1291 cbMICHDR + sizeof(struct vnt_cts_fb));
1292 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1293 cbMICHDR + sizeof(struct vnt_cts_fb) + sizeof(struct vnt_tx_datahead_g_fb);
1296 } else {//802.11a/b packet
1298 if (byFBOption == AUTO_FB_NONE) {
1300 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1301 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1302 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1304 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1305 sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_ab));
1306 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1307 cbMICHDR + sizeof(struct vnt_rts_ab) + sizeof(struct vnt_tx_datahead_ab);
1308 } else { //RTS_needless, need MICHDR
1309 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1310 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1313 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1314 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1315 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
1319 if (bRTS == true) {//RTS_need
1320 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1321 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1322 pvRTS = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1324 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1325 sizeof(struct vnt_rrv_time_ab) + cbMICHDR + sizeof(struct vnt_rts_a_fb));
1326 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1327 cbMICHDR + sizeof(struct vnt_rts_a_fb) + sizeof(struct vnt_tx_datahead_a_fb);
1328 } else { //RTS_needless
1329 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1330 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab));
1333 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1334 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1335 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
1340 td_info->mic_hdr = pMICHDR;
1342 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1344 /* Fill FIFO,RrvTime,RTS,and CTS */
1345 s_vGenerateTxParameter(pDevice, byPktType, tx_buffer_head, pvRrvTime, pvRTS, pvCTS,
1346 cbFrameSize, bNeedACK, uDMAIdx, hdr, pDevice->wCurrentRate);
1348 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1349 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1351 hdr->duration_id = uDuration;
1353 cbReqCount = cbHeaderLength + uPadding + cbFrameBodySize;
1354 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1355 uLength = cbHeaderLength + uPadding;
1357 /* Copy the Packet into a tx Buffer */
1358 memcpy((pbyBuffer + uLength), pPacket, cbFrameBodySize);
1360 ptdCurr = (PSTxDesc)pHeadTD;
1362 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1363 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1364 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1365 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1366 /* Set TSR1 & ReqCount in TxDescHead */
1367 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1368 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1370 *puMACfragNum = uMACfragNum;
1372 return cbHeaderLength;
1376 vGenerateFIFOHeader(struct vnt_private *pDevice, unsigned char byPktType,
1377 unsigned char *pbyTxBufferAddr, bool bNeedEncrypt,
1378 unsigned int cbPayloadSize, unsigned int uDMAIdx,
1379 PSTxDesc pHeadTD, PSEthernetHeader psEthHeader, unsigned char *pPacket,
1380 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum,
1381 unsigned int *pcbHeaderSize)
1383 unsigned int wTxBufSize; // FFinfo size
1386 unsigned short cbMacHdLen;
1387 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1389 wTxBufSize = sizeof(STxBufHead);
1391 memset(pTxBufHead, 0, wTxBufSize);
1392 //Set FIFOCTL_NEEDACK
1394 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) ||
1395 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
1396 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0]))) {
1398 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1401 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1405 // MSDUs in Infra mode always need ACK
1407 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1411 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1412 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
1415 if (pDevice->bLongHeader)
1416 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1418 //Set FIFOCTL_GENINT
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
1422 //Set FIFOCTL_ISDMA0
1423 if (TYPE_TXDMA0 == uDMAIdx)
1424 pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
1426 //Set FRAGCTL_MACHDCNT
1427 if (pDevice->bLongHeader)
1428 cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
1430 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1432 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
1435 if (byPktType == PK_TYPE_11A) //0000 0000 0000 0000
1437 else if (byPktType == PK_TYPE_11B) //0000 0001 0000 0000
1438 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1439 else if (byPktType == PK_TYPE_11GB) //0000 0010 0000 0000
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1441 else if (byPktType == PK_TYPE_11GA) //0000 0011 0000 0000
1442 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1444 //Set FIFOCTL_GrpAckPolicy
1445 if (pDevice->bGrpAckPolicy == true) //0000 0100 0000 0000
1446 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1448 //Set Auto Fallback Ctl
1449 if (pDevice->wCurrentRate >= RATE_18M) {
1450 if (pDevice->byAutoFBCtrl == AUTO_FB_0)
1451 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1452 else if (pDevice->byAutoFBCtrl == AUTO_FB_1)
1453 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1456 //Set FRAGCTL_WEPTYP
1457 pDevice->bAES = false;
1459 //Set FRAGCTL_WEPTYP
1460 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1461 if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
1462 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1463 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1464 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1465 if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
1466 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1467 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1468 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1473 RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
1475 pTxBufHead->byTxPower = pDevice->byCurPwr;
1477 *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
1478 uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
1479 pTransmitKey, uNodeIndex, puMACfragNum);
1485 * Translate 802.3 to 802.11 header
1489 * pDevice - Pointer to adapter
1490 * dwTxBufferAddr - Transmit Buffer
1491 * pPacket - Packet from upper layer
1492 * cbPacketSize - Transmit Data Length
1494 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1495 * pcbAppendPayload - size of append payload for 802.1H translation
1497 * Return Value: none
1503 struct vnt_private *pDevice,
1504 unsigned char *pbyBufferAddr,
1506 PSEthernetHeader psEthHeader,
1508 unsigned short wFragType,
1509 unsigned int uDMAIdx,
1510 unsigned int uFragIdx
1513 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
1515 memset(pMACHeader, 0, (sizeof(S802_11Header)));
1517 if (uDMAIdx == TYPE_ATIMDMA)
1518 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
1520 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
1522 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
1523 ether_addr_copy(&(pMACHeader->abyAddr1[0]),
1524 &(psEthHeader->abyDstAddr[0]));
1525 ether_addr_copy(&(pMACHeader->abyAddr2[0]),
1526 &(pDevice->abyBSSID[0]));
1527 ether_addr_copy(&(pMACHeader->abyAddr3[0]),
1528 &(psEthHeader->abySrcAddr[0]));
1529 pMACHeader->wFrameCtl |= FC_FROMDS;
1531 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1532 ether_addr_copy(&(pMACHeader->abyAddr1[0]),
1533 &(psEthHeader->abyDstAddr[0]));
1534 ether_addr_copy(&(pMACHeader->abyAddr2[0]),
1535 &(psEthHeader->abySrcAddr[0]));
1536 ether_addr_copy(&(pMACHeader->abyAddr3[0]),
1537 &(pDevice->abyBSSID[0]));
1539 ether_addr_copy(&(pMACHeader->abyAddr3[0]),
1540 &(psEthHeader->abyDstAddr[0]));
1541 ether_addr_copy(&(pMACHeader->abyAddr2[0]),
1542 &(psEthHeader->abySrcAddr[0]));
1543 ether_addr_copy(&(pMACHeader->abyAddr1[0]),
1544 &(pDevice->abyBSSID[0]));
1545 pMACHeader->wFrameCtl |= FC_TODS;
1550 pMACHeader->wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_ISWEP(1));
1552 pMACHeader->wDurationID = le16_to_cpu(wDuration);
1554 if (pDevice->bLongHeader) {
1555 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1557 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
1558 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
1560 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1562 //Set FragNumber in Sequence Control
1563 pMACHeader->wSeqCtl |= cpu_to_le16((unsigned short)uFragIdx);
1565 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1566 pDevice->wSeqCounter++;
1567 if (pDevice->wSeqCounter > 0x0fff)
1568 pDevice->wSeqCounter = 0;
1571 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) //StartFrag or MidFrag
1572 pMACHeader->wFrameCtl |= FC_MOREFRAG;
1575 CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, PSTxMgmtPacket pPacket)
1578 unsigned char byPktType;
1579 unsigned char *pbyTxBufferAddr;
1581 struct vnt_cts *pCTS;
1583 unsigned int uDuration;
1584 unsigned int cbReqCount;
1585 PS802_11Header pMACHeader;
1586 unsigned int cbHeaderSize;
1587 unsigned int cbFrameBodySize;
1589 bool bIsPSPOLL = false;
1590 PSTxBufHead pTxBufHead;
1591 unsigned int cbFrameSize;
1592 unsigned int cbIVlen = 0;
1593 unsigned int cbICVlen = 0;
1594 unsigned int cbMIClen = 0;
1595 unsigned int cbFCSlen = 4;
1596 unsigned int uPadding = 0;
1597 unsigned short wTxBufSize;
1598 unsigned int cbMacHdLen;
1599 SEthernetHeader sEthHeader;
1602 PSMgmtObject pMgmt = pDevice->pMgmt;
1603 unsigned short wCurrentRate = RATE_1M;
1605 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0)
1606 return CMD_STATUS_RESOURCES;
1608 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
1609 pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
1610 cbFrameBodySize = pPacket->cbPayloadLen;
1611 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1612 wTxBufSize = sizeof(STxBufHead);
1613 memset(pTxBufHead, 0, wTxBufSize);
1615 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1616 wCurrentRate = RATE_6M;
1617 byPktType = PK_TYPE_11A;
1619 wCurrentRate = RATE_1M;
1620 byPktType = PK_TYPE_11B;
1623 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1624 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1625 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1626 // to set power here.
1627 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING)
1628 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1630 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1632 pTxBufHead->byTxPower = pDevice->byCurPwr;
1633 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
1634 if (pDevice->byFOETuning) {
1635 if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
1636 wCurrentRate = RATE_24M;
1637 byPktType = PK_TYPE_11GA;
1642 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1643 pTxBufHead->wFIFOCtl = 0;
1644 } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1645 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1646 } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1647 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1648 } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1649 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1652 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1653 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1655 if (is_multicast_ether_addr(&(pPacket->p80211Header->sA3.abyAddr1[0])))
1659 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1662 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1663 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1664 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1667 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1669 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
1671 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1673 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1676 //Set FRAGCTL_MACHDCNT
1677 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
1680 // Although spec says MMPDU can be fragmented; In most cases,
1681 // no one will send a MMPDU under fragmentation. With RTS may occur.
1682 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
1684 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1685 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1688 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1689 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1690 cbIVlen = 8;//IV+ExtIV
1693 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1694 //We need to get seed here for filling TxKey entry.
1695 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1696 cbIVlen = 8;//RSN Header
1698 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1699 pDevice->bAES = true;
1701 //MAC Header should be padding 0 to DW alignment.
1702 uPadding = 4 - (cbMacHdLen%4);
1706 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1708 //Set FIFOCTL_GrpAckPolicy
1709 if (pDevice->bGrpAckPolicy == true) //0000 0100 0000 0000
1710 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1712 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1714 //Set RrvTime/RTS/CTS Buffer
1715 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1716 pvRrvTime = (void *) (pbyTxBufferAddr + wTxBufSize);
1719 pCTS = (struct vnt_cts *)(pbyTxBufferAddr + wTxBufSize +
1720 sizeof(struct vnt_rrv_time_cts));
1721 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1722 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1723 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1724 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
1725 } else { // 802.11a/b packet
1726 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
1730 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
1731 sizeof(struct vnt_rrv_time_ab));
1732 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1733 sizeof(struct vnt_tx_datahead_ab);
1736 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
1738 ether_addr_copy(&(sEthHeader.abyDstAddr[0]),
1739 &(pPacket->p80211Header->sA3.abyAddr1[0]));
1740 ether_addr_copy(&(sEthHeader.abySrcAddr[0]),
1741 &(pPacket->p80211Header->sA3.abyAddr2[0]));
1742 //=========================
1744 //=========================
1745 pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
1747 //Fill FIFO,RrvTime,RTS,and CTS
1748 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
1749 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
1752 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
1753 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
1755 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
1757 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1759 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1760 unsigned char *pbyIVHead;
1761 unsigned char *pbyPayloadHead;
1762 unsigned char *pbyBSSID;
1763 PSKeyItem pTransmitKey = NULL;
1765 pbyIVHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1766 pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
1769 //Kyle: Need fix: TKIP and AES did't encrypt Mnt Packet.
1770 //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
1772 //Fill IV(ExtIV,RSNHDR)
1773 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
1774 //---------------------------
1775 // S/W or H/W Encryption
1776 //---------------------------
1778 if ((pDevice->op_mode == NL80211_IFTYPE_STATION) &&
1779 (pDevice->bLinkPass == true)) {
1780 pbyBSSID = pDevice->abyBSSID;
1782 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1784 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1785 pr_debug("Get GTK\n");
1789 pr_debug("Get PTK\n");
1794 pbyBSSID = pDevice->abyBroadcastAddr;
1795 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1796 pTransmitKey = NULL;
1797 pr_debug("KEY is NULL. OP Mode[%d]\n",
1800 pr_debug("Get GTK\n");
1804 s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1805 (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize, NULL);
1807 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
1808 memcpy(pbyPayloadHead, ((unsigned char *)(pPacket->p80211Header) + cbMacHdLen),
1811 // Copy the Packet into a tx Buffer
1812 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1815 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1816 pDevice->wSeqCounter++;
1817 if (pDevice->wSeqCounter > 0x0fff)
1818 pDevice->wSeqCounter = 0;
1821 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1822 // of FIFO control header.
1823 // This will cause AID-field of PS-POLL packet to be incorrect (Because PS-POLL's AID field is
1824 // in the same place of other packet's Duration-field).
1825 // And it will cause Cisco-AP to issue Disassociation-packet
1826 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1827 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1828 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1830 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->duration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1834 // first TD is the only TD
1835 //Set TSR1 & ReqCount in TxDescHead
1836 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
1837 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
1838 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1839 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
1840 pFrstTD->pTDInfo->byFlags = 0;
1842 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1844 MACbPSWakeup(pDevice->PortOffset);
1846 pDevice->bPWBitOn = false;
1849 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1852 pDevice->iTDUsed[TYPE_TXDMA0]++;
1854 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1)
1855 pr_debug(" available td0 <= 1\n");
1857 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
1859 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
1861 // Poll Transmit the adapter
1862 MACvTransmit0(pDevice->PortOffset);
1864 return CMD_STATUS_PENDING;
1867 CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, PSTxMgmtPacket pPacket)
1869 unsigned char byPktType;
1870 unsigned char *pbyBuffer = (unsigned char *)pDevice->tx_beacon_bufs;
1871 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1872 unsigned int cbHeaderSize = 0;
1873 struct vnt_tx_short_buf_head *short_head =
1874 (struct vnt_tx_short_buf_head *)pbyBuffer;
1875 PS802_11Header pMACHeader;
1876 unsigned short wCurrentRate;
1878 memset(short_head, 0, sizeof(*short_head));
1880 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1881 wCurrentRate = RATE_6M;
1882 byPktType = PK_TYPE_11A;
1884 wCurrentRate = RATE_2M;
1885 byPktType = PK_TYPE_11B;
1888 //Set Preamble type always long
1889 pDevice->byPreambleType = PREAMBLE_LONG;
1891 /* Set FIFOCTL_GENINT */
1892 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
1894 /* Set packet type & Get Duration */
1895 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1896 short_head->duration =
1897 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A,
1898 cbFrameSize, byPktType, wCurrentRate, false,
1899 0, 0, 1, AUTO_FB_NONE));
1900 } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1901 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
1903 short_head->duration =
1904 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B,
1905 cbFrameSize, byPktType, wCurrentRate, false,
1906 0, 0, 1, AUTO_FB_NONE));
1909 vnt_get_phy_field(pDevice, cbFrameSize,
1910 wCurrentRate, byPktType, &short_head->ab);
1912 /* Get TimeStampOff */
1913 short_head->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
1914 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
1916 //Generate Beacon Header
1917 pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
1918 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1920 pMACHeader->wDurationID = 0;
1921 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1922 pDevice->wSeqCounter++;
1923 if (pDevice->wSeqCounter > 0x0fff)
1924 pDevice->wSeqCounter = 0;
1926 // Set Beacon buffer length
1927 pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
1929 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
1931 MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
1932 // Set auto Transmit on
1933 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1934 // Poll Transmit the adapter
1935 MACvTransmitBCN(pDevice->PortOffset);
1937 return CMD_STATUS_PENDING;
1942 struct vnt_private *pDevice,
1943 PSKeyItem pTransmitKey,
1944 unsigned int cbFrameBodySize,
1945 PSEthernetHeader psEthHeader
1948 unsigned int cbMACHdLen;
1949 unsigned int cbFrameSize;
1950 unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1951 unsigned int cbFragPayloadSize;
1952 unsigned int cbLastFragPayloadSize;
1953 unsigned int cbIVlen = 0;
1954 unsigned int cbICVlen = 0;
1955 unsigned int cbMIClen = 0;
1956 unsigned int cbFCSlen = 4;
1957 unsigned int uMACfragNum = 1;
1960 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) ||
1961 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
1962 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
1967 // MSDUs in Infra mode always need ACK
1971 if (pDevice->bLongHeader)
1972 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1974 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1976 if (pDevice->bEncryptionEnable == true) {
1977 if (pTransmitKey == NULL) {
1978 if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
1979 (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
1982 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1983 cbIVlen = 8;//IV+ExtIV
1986 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1987 cbIVlen = 8;//RSN Header
1990 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1993 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1994 cbIVlen = 8;//IV+ExtIV
1997 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1998 cbIVlen = 8;//RSN Header
2003 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
2005 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true)) {
2007 cbFragmentSize = pDevice->wFragmentationThreshold;
2008 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
2009 uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
2010 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
2011 if (cbLastFragPayloadSize == 0)
2012 cbLastFragPayloadSize = cbFragPayloadSize;
2019 void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb,
2020 unsigned char *pbMPDU, unsigned int cbMPDULen)
2023 unsigned char byPktType;
2024 unsigned char *pbyTxBufferAddr;
2028 unsigned int uDuration;
2029 unsigned int cbReqCount;
2030 PS802_11Header pMACHeader;
2031 unsigned int cbHeaderSize;
2032 unsigned int cbFrameBodySize;
2034 bool bIsPSPOLL = false;
2035 PSTxBufHead pTxBufHead;
2036 unsigned int cbFrameSize;
2037 unsigned int cbIVlen = 0;
2038 unsigned int cbICVlen = 0;
2039 unsigned int cbMIClen = 0;
2040 unsigned int cbFCSlen = 4;
2041 unsigned int uPadding = 0;
2042 unsigned int cbMICHDR = 0;
2043 unsigned int uLength = 0;
2044 u32 dwMICKey0, dwMICKey1;
2048 unsigned short wTxBufSize;
2049 unsigned int cbMacHdLen;
2050 SEthernetHeader sEthHeader;
2053 PSMgmtObject pMgmt = pDevice->pMgmt;
2054 unsigned short wCurrentRate = RATE_1M;
2055 PUWLAN_80211HDR p80211Header;
2056 unsigned int uNodeIndex = 0;
2057 bool bNodeExist = false;
2059 PSKeyItem pTransmitKey = NULL;
2060 unsigned char *pbyIVHead;
2061 unsigned char *pbyPayloadHead;
2062 unsigned char *pbyMacHdr;
2064 unsigned int cbExtSuppRate = 0;
2066 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2068 if (cbMPDULen <= WLAN_HDR_ADDR3_LEN)
2069 cbFrameBodySize = 0;
2071 cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
2073 p80211Header = (PUWLAN_80211HDR)pbMPDU;
2075 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2076 pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
2077 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2078 wTxBufSize = sizeof(STxBufHead);
2079 memset(pTxBufHead, 0, wTxBufSize);
2081 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2082 wCurrentRate = RATE_6M;
2083 byPktType = PK_TYPE_11A;
2085 wCurrentRate = RATE_1M;
2086 byPktType = PK_TYPE_11B;
2089 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2090 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2091 // And cmd timer will wait data pkt TX to finish before scanning so it's OK
2092 // to set power here.
2093 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING)
2094 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2096 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2098 pTxBufHead->byTxPower = pDevice->byCurPwr;
2100 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2101 if (pDevice->byFOETuning) {
2102 if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2103 wCurrentRate = RATE_24M;
2104 byPktType = PK_TYPE_11GA;
2108 pr_debug("vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x\n",
2109 p80211Header->sA3.wFrameCtl);
2112 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2113 pTxBufHead->wFIFOCtl = 0;
2114 } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2115 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2116 } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2117 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2118 } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2119 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2122 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2123 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2125 if (is_multicast_ether_addr(&(p80211Header->sA3.abyAddr1[0]))) {
2127 if (pDevice->bEnableHostWEP) {
2132 if (pDevice->bEnableHostWEP) {
2133 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (unsigned char *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2137 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2140 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2141 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
2142 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2145 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2147 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2149 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2151 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2154 // hostapd deamon ext support rate patch
2155 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2156 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2157 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2159 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2160 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2162 if (cbExtSuppRate > 0)
2163 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2166 //Set FRAGCTL_MACHDCNT
2167 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10);
2170 // Although spec says MMPDU can be fragmented; In most cases,
2171 // no one will send a MMPDU under fragmentation. With RTS may occur.
2172 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2174 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2175 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2178 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2179 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2180 cbIVlen = 8;//IV+ExtIV
2183 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2184 //We need to get seed here for filling TxKey entry.
2185 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2186 cbIVlen = 8;//RSN Header
2188 cbMICHDR = sizeof(struct vnt_mic_hdr);
2189 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2190 pDevice->bAES = true;
2192 //MAC Header should be padding 0 to DW alignment.
2193 uPadding = 4 - (cbMacHdLen%4);
2197 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2199 //Set FIFOCTL_GrpAckPolicy
2200 if (pDevice->bGrpAckPolicy == true) //0000 0100 0000 0000
2201 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2203 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2205 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2207 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
2208 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
2209 sizeof(struct vnt_rrv_time_cts));
2211 pvCTS = (struct vnt_cts *)(pbyTxBufferAddr + wTxBufSize +
2212 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
2213 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
2214 sizeof(struct vnt_rrv_time_cts) + cbMICHDR + sizeof(struct vnt_cts));
2215 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
2216 cbMICHDR + sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
2218 } else {//802.11a/b packet
2220 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
2221 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr +
2222 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
2225 pvTxDataHd = (void *)(pbyTxBufferAddr +
2226 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
2227 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
2228 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
2232 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
2233 ether_addr_copy(&(sEthHeader.abyDstAddr[0]),
2234 &(p80211Header->sA3.abyAddr1[0]));
2235 ether_addr_copy(&(sEthHeader.abySrcAddr[0]),
2236 &(p80211Header->sA3.abyAddr2[0]));
2237 //=========================
2239 //=========================
2240 pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
2242 //Fill FIFO,RrvTime,RTS,and CTS
2243 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2244 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2247 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2248 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2250 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2252 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2254 pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize);
2255 pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2256 pbyIVHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding);
2258 // Copy the Packet into a tx Buffer
2259 memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
2261 // version set to 0, patch for hostapd deamon
2262 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
2263 memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
2265 // replace support rate, patch for hostapd deamon(only support 11M)
2266 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2267 if (cbExtSuppRate != 0) {
2268 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2269 memcpy((pbyPayloadHead + cbFrameBodySize),
2270 pMgmt->abyCurrSuppRates,
2271 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2273 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2274 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2275 pMgmt->abyCurrExtSuppRates,
2276 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2282 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2283 if (pDevice->bEnableHostWEP) {
2284 pTransmitKey = &STempKey;
2285 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2286 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2287 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2288 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2289 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2290 memcpy(pTransmitKey->abyKey,
2291 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2292 pTransmitKey->uKeyLength
2296 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2297 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2298 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
2300 // DO Software Michael
2301 MIC_vInit(dwMICKey0, dwMICKey1);
2302 MIC_vAppend((unsigned char *)&(sEthHeader.abyDstAddr[0]), 12);
2304 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
2305 pr_debug("DMA0_tx_8021:MIC KEY: %X, %X\n",
2306 dwMICKey0, dwMICKey1);
2308 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2310 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2312 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2313 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2315 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2318 if (pDevice->bTxMICFail == true) {
2321 pDevice->bTxMICFail = false;
2324 pr_debug("uLength: %d, %d\n", uLength, cbFrameBodySize);
2325 pr_debug("cbReqCount:%d, %d, %d, %d\n",
2326 cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2327 pr_debug("MIC:%x, %x\n", *pdwMIC_L, *pdwMIC_R);
2331 s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2332 pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
2334 if (pDevice->bEnableHostWEP) {
2335 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2336 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2339 if ((pDevice->byLocalID <= REV_ID_VT3253_A1))
2340 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (unsigned short)(cbFrameBodySize + cbMIClen));
2343 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2344 pDevice->wSeqCounter++;
2345 if (pDevice->wSeqCounter > 0x0fff)
2346 pDevice->wSeqCounter = 0;
2349 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2350 // of FIFO control header.
2351 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2352 // in the same place of other packet's Duration-field).
2353 // And it will cause Cisco-AP to issue Disassociation-packet
2354 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2355 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2356 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2358 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->duration = cpu_to_le16(p80211Header->sA2.wDurationID);
2362 // first TD is the only TD
2363 //Set TSR1 & ReqCount in TxDescHead
2364 pFrstTD->pTDInfo->skb = skb;
2365 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
2366 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
2367 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
2368 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2369 pFrstTD->pTDInfo->byFlags = 0;
2370 pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
2372 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2374 MACbPSWakeup(pDevice->PortOffset);
2376 pDevice->bPWBitOn = false;
2379 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2382 pDevice->iTDUsed[TYPE_TXDMA0]++;
2384 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1)
2385 pr_debug(" available td0 <= 1\n");
2387 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
2389 // Poll Transmit the adapter
2390 MACvTransmit0(pDevice->PortOffset);
2393 static void vnt_fill_txkey(struct ieee80211_hdr *hdr, u8 *key_buffer,
2394 struct ieee80211_key_conf *tx_key,
2395 struct sk_buff *skb, u16 payload_len,
2396 struct vnt_mic_hdr *mic_hdr)
2398 struct ieee80211_key_seq seq;
2399 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
2401 /* strip header and icv len from payload */
2402 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
2403 payload_len -= tx_key->icv_len;
2405 switch (tx_key->cipher) {
2406 case WLAN_CIPHER_SUITE_WEP40:
2407 case WLAN_CIPHER_SUITE_WEP104:
2408 memcpy(key_buffer, iv, 3);
2409 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
2411 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
2412 memcpy(key_buffer + 8, iv, 3);
2413 memcpy(key_buffer + 11,
2414 tx_key->key, WLAN_KEY_LEN_WEP40);
2418 case WLAN_CIPHER_SUITE_TKIP:
2419 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
2422 case WLAN_CIPHER_SUITE_CCMP:
2428 mic_hdr->payload_len = cpu_to_be16(payload_len);
2429 ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
2431 ieee80211_get_key_tx_seq(tx_key, &seq);
2433 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
2435 if (ieee80211_has_a4(hdr->frame_control))
2436 mic_hdr->hlen = cpu_to_be16(28);
2438 mic_hdr->hlen = cpu_to_be16(22);
2440 ether_addr_copy(mic_hdr->addr1, hdr->addr1);
2441 ether_addr_copy(mic_hdr->addr2, hdr->addr2);
2442 ether_addr_copy(mic_hdr->addr3, hdr->addr3);
2444 mic_hdr->frame_control = cpu_to_le16(
2445 le16_to_cpu(hdr->frame_control) & 0xc78f);
2446 mic_hdr->seq_ctrl = cpu_to_le16(
2447 le16_to_cpu(hdr->seq_ctrl) & 0xf);
2449 if (ieee80211_has_a4(hdr->frame_control))
2450 ether_addr_copy(mic_hdr->addr4, hdr->addr4);
2452 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
2460 int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx,
2461 PSTxDesc head_td, struct sk_buff *skb)
2463 PDEVICE_TD_INFO td_info = head_td->pTDInfo;
2464 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2465 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
2466 struct ieee80211_rate *rate;
2467 struct ieee80211_key_conf *tx_key;
2468 struct ieee80211_hdr *hdr;
2469 struct vnt_tx_fifo_head *tx_buffer_head =
2470 (struct vnt_tx_fifo_head *)td_info->buf;
2472 u16 tx_body_size = skb->len, current_rate;
2474 bool is_pspoll = false;
2476 memset(tx_buffer_head, 0, sizeof(*tx_buffer_head));
2478 hdr = (struct ieee80211_hdr *)(skb->data);
2480 rate = ieee80211_get_tx_rate(priv->hw, info);
2482 current_rate = rate->hw_value;
2483 if (priv->wCurrentRate != current_rate &&
2484 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
2485 priv->wCurrentRate = current_rate;
2487 RFbSetPower(priv, priv->wCurrentRate,
2488 priv->hw->conf.chandef.chan->hw_value);
2491 if (current_rate > RATE_11M)
2492 pkt_type = (u8)priv->byPacketType;
2494 pkt_type = PK_TYPE_11B;
2496 /*Set fifo controls */
2497 if (pkt_type == PK_TYPE_11A)
2498 tx_buffer_head->fifo_ctl = 0;
2499 else if (pkt_type == PK_TYPE_11B)
2500 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
2501 else if (pkt_type == PK_TYPE_11GB)
2502 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
2503 else if (pkt_type == PK_TYPE_11GA)
2504 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
2506 /* generate interrupt */
2507 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
2509 if (!ieee80211_is_data(hdr->frame_control)) {
2510 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
2511 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_ISDMA0);
2512 tx_buffer_head->time_stamp =
2513 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2515 tx_buffer_head->time_stamp =
2516 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2519 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
2520 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
2522 if (ieee80211_has_retry(hdr->frame_control))
2523 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
2525 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
2526 priv->byPreambleType = PREAMBLE_SHORT;
2528 priv->byPreambleType = PREAMBLE_LONG;
2530 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
2531 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
2533 if (ieee80211_has_a4(hdr->frame_control)) {
2534 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
2535 priv->bLongHeader = true;
2538 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
2541 tx_buffer_head->frag_ctl =
2542 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
2544 if (info->control.hw_key) {
2545 tx_key = info->control.hw_key;
2547 switch (info->control.hw_key->cipher) {
2548 case WLAN_CIPHER_SUITE_WEP40:
2549 case WLAN_CIPHER_SUITE_WEP104:
2550 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
2552 case WLAN_CIPHER_SUITE_TKIP:
2553 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
2555 case WLAN_CIPHER_SUITE_CCMP:
2556 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
2562 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
2564 /* legacy rates TODO use ieee80211_tx_rate */
2565 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
2566 if (priv->byAutoFBCtrl == AUTO_FB_0)
2567 tx_buffer_head->fifo_ctl |=
2568 cpu_to_le16(FIFOCTL_AUTO_FB_0);
2569 else if (priv->byAutoFBCtrl == AUTO_FB_1)
2570 tx_buffer_head->fifo_ctl |=
2571 cpu_to_le16(FIFOCTL_AUTO_FB_1);
2575 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
2577 s_cbFillTxBufHead(priv, pkt_type, (u8 *)tx_buffer_head, skb->len,
2578 dma_idx, head_td, NULL, (u8 *)skb->data,
2579 false, NULL, is_pspoll, &frag);
2581 if (info->control.hw_key) {
2582 tx_key = info->control.hw_key;
2583 if (tx_key->keylen > 0)
2584 vnt_fill_txkey(hdr, tx_buffer_head->tx_key,
2585 tx_key, skb, tx_body_size, td_info->mic_hdr);
2591 static int vnt_beacon_xmit(struct vnt_private *priv,
2592 struct sk_buff *skb)
2594 struct vnt_tx_short_buf_head *short_head =
2595 (struct vnt_tx_short_buf_head *)priv->tx_beacon_bufs;
2596 struct ieee80211_mgmt *mgmt_hdr = (struct ieee80211_mgmt *)
2597 (priv->tx_beacon_bufs + sizeof(*short_head));
2598 struct ieee80211_tx_info *info;
2599 u32 frame_size = skb->len + 4;
2602 memset(priv->tx_beacon_bufs, 0, sizeof(*short_head));
2604 if (priv->byBBType == BB_TYPE_11A) {
2605 current_rate = RATE_6M;
2607 /* Get SignalField,ServiceField,Length */
2608 vnt_get_phy_field(priv, frame_size, current_rate,
2609 PK_TYPE_11A, &short_head->ab);
2611 /* Get Duration and TimeStampOff */
2612 short_head->duration =
2613 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
2614 frame_size, PK_TYPE_11A, current_rate,
2615 false, 0, 0, 1, AUTO_FB_NONE));
2617 short_head->time_stamp_off =
2618 vnt_time_stamp_off(priv, current_rate);
2620 current_rate = RATE_1M;
2621 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
2623 /* Get SignalField,ServiceField,Length */
2624 vnt_get_phy_field(priv, frame_size, current_rate,
2625 PK_TYPE_11B, &short_head->ab);
2627 /* Get Duration and TimeStampOff */
2628 short_head->duration =
2629 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
2630 frame_size, PK_TYPE_11B, current_rate,
2631 false, 0, 0, 1, AUTO_FB_NONE));
2633 short_head->time_stamp_off =
2634 vnt_time_stamp_off(priv, current_rate);
2637 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
2640 memcpy(mgmt_hdr, skb->data, skb->len);
2642 /* time stamp always 0 */
2643 mgmt_hdr->u.beacon.timestamp = 0;
2645 info = IEEE80211_SKB_CB(skb);
2646 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2647 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
2649 hdr->duration_id = 0;
2650 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
2653 priv->wSeqCounter++;
2654 if (priv->wSeqCounter > 0x0fff)
2655 priv->wSeqCounter = 0;
2657 priv->wBCNBufLen = sizeof(*short_head) + skb->len;
2659 MACvSetCurrBCNTxDescAddr(priv->PortOffset, priv->tx_beacon_dma);
2661 MACvSetCurrBCNLength(priv->PortOffset, priv->wBCNBufLen);
2662 /* Set auto Transmit on */
2663 MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2664 /* Poll Transmit the adapter */
2665 MACvTransmitBCN(priv->PortOffset);
2670 int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
2672 struct sk_buff *beacon;
2674 beacon = ieee80211_beacon_get(priv->hw, vif);
2678 if (vnt_beacon_xmit(priv, beacon)) {
2679 ieee80211_free_txskb(priv->hw, beacon);
2686 int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
2687 struct ieee80211_bss_conf *conf)
2691 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
2693 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2695 CARDvSetFirstNextTBTT(priv->PortOffset, conf->beacon_int);
2697 CARDbSetBeaconPeriod(priv, conf->beacon_int);
2699 ret = vnt_beacon_make(priv, vif);