PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / staging / vt6656 / rxtx.c
blob51fff896fcb51a2dcc2657d7fdf952e1fc167431
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
19 * File: rxtx.c
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
23 * Author: Lyndon Chen
25 * Date: May 20, 2003
27 * 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
45 * Revision History:
49 #include "device.h"
50 #include "rxtx.h"
51 #include "tether.h"
52 #include "card.h"
53 #include "bssdb.h"
54 #include "mac.h"
55 #include "michael.h"
56 #include "tkip.h"
57 #include "tcrc.h"
58 #include "wctl.h"
59 #include "hostap.h"
60 #include "rf.h"
61 #include "datarate.h"
62 #include "usbpipe.h"
63 #include "iocmd.h"
65 static int msglevel = MSG_LEVEL_INFO;
67 static const u16 wTimeStampOff[2][MAX_RATE] = {
68 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
69 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
72 static const u16 wFB_Opt0[2][5] = {
73 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
74 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
76 static const u16 wFB_Opt1[2][5] = {
77 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
78 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
81 #define RTSDUR_BB 0
82 #define RTSDUR_BA 1
83 #define RTSDUR_AA 2
84 #define CTSDUR_BA 3
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
91 #define DATADUR_B 10
92 #define DATADUR_A 11
93 #define DATADUR_A_F0 12
94 #define DATADUR_A_F1 13
96 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
99 static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
101 static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
103 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
104 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts);
106 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
107 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
108 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
110 static void s_vFillTxKey(struct vnt_private *pDevice,
111 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
112 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
113 struct vnt_mic_hdr *mic_hdr);
115 static void s_vSWencryption(struct vnt_private *pDevice,
116 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
118 static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
119 u32 cbFrameLength, u16 wRate, int bNeedAck);
121 static u16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
122 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate);
124 static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
125 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
126 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
128 static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
129 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
130 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
132 static u16 s_uGetDataDuration(struct vnt_private *pDevice,
133 u8 byPktType, int bNeedAck);
135 static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
136 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
137 int bNeedAck, u8 byFBOption);
139 static struct vnt_usb_send_context
140 *s_vGetFreeContext(struct vnt_private *priv)
142 struct vnt_usb_send_context *context = NULL;
143 int ii;
145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
147 for (ii = 0; ii < priv->cbTD; ii++) {
148 if (!priv->apTD[ii])
149 return NULL;
151 context = priv->apTD[ii];
152 if (context->bBoolInUse == false) {
153 context->bBoolInUse = true;
154 memset(context->Data, 0,
155 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
156 return context;
160 if (ii == priv->cbTD)
161 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
163 return NULL;
166 static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
167 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
169 struct net_device_stats *stats = &pDevice->stats;
170 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
172 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
173 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
175 stats->tx_bytes += wPktLength;
178 static void s_vFillTxKey(struct vnt_private *pDevice,
179 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
180 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
181 struct vnt_mic_hdr *mic_hdr)
183 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
184 u32 *pdwIV = (u32 *)pbyIVHead;
185 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
186 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
187 u32 dwRevIVCounter;
189 /* Fill TXKEY */
190 if (pTransmitKey == NULL)
191 return;
193 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
194 *pdwIV = pDevice->dwIVCounter;
195 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
197 switch (pTransmitKey->byCipherSuite) {
198 case KEY_CTL_WEP:
199 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
200 memcpy(pDevice->abyPRNG, (u8 *)&dwRevIVCounter, 3);
201 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
202 pTransmitKey->uKeyLength);
203 } else {
204 memcpy(pbyBuf, (u8 *)&dwRevIVCounter, 3);
205 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
206 pTransmitKey->uKeyLength);
207 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
208 memcpy(pbyBuf+8, (u8 *)&dwRevIVCounter, 3);
209 memcpy(pbyBuf+11, pTransmitKey->abyKey,
210 pTransmitKey->uKeyLength);
213 memcpy(pDevice->abyPRNG, pbyBuf, 16);
215 /* Append IV after Mac Header */
216 *pdwIV &= WEP_IV_MASK;
217 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
218 *pdwIV = cpu_to_le32(*pdwIV);
220 pDevice->dwIVCounter++;
221 if (pDevice->dwIVCounter > WEP_IV_MASK)
222 pDevice->dwIVCounter = 0;
224 break;
225 case 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,
232 pDevice->abyPRNG);
233 memcpy(pbyBuf, pDevice->abyPRNG, 16);
235 /* Make IV */
236 memcpy(pdwIV, pDevice->abyPRNG, 3);
238 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
239 0xc0) | 0x20);
240 /* Append IV&ExtIV after Mac Header */
241 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
243 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
244 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
246 break;
247 case KEY_CTL_CCMP:
248 pTransmitKey->wTSC15_0++;
249 if (pTransmitKey->wTSC15_0 == 0)
250 pTransmitKey->dwTSC47_16++;
252 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
254 /* Make IV */
255 *pdwIV = 0;
256 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
257 0xc0) | 0x20);
259 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
261 /* Append IV&ExtIV after Mac Header */
262 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
264 if (!mic_hdr)
265 return;
267 /* MICHDR0 */
268 mic_hdr->id = 0x59;
269 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
270 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
272 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
273 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
275 /* MICHDR1 */
276 if (ieee80211_has_a4(pMACHeader->frame_control))
277 mic_hdr->hlen = cpu_to_be16(28);
278 else
279 mic_hdr->hlen = cpu_to_be16(22);
281 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
282 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
284 /* MICHDR2 */
285 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
286 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
287 & 0xc78f);
288 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
290 if (ieee80211_has_a4(pMACHeader->frame_control))
291 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
295 static void s_vSWencryption(struct vnt_private *pDevice,
296 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
298 u32 cbICVlen = 4;
299 u32 dwICV = 0xffffffff;
300 u32 *pdwICV;
302 if (pTransmitKey == NULL)
303 return;
305 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
306 //=======================================================================
307 // Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
310 // finally, we must invert dwCRC to get the correct answer
311 *pdwICV = cpu_to_le32(~dwICV);
312 // RC4 encryption
313 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
317 //=======================================================================
318 //Append ICV after payload
319 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
320 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
321 // finally, we must invert dwCRC to get the correct answer
322 *pdwICV = cpu_to_le32(~dwICV);
323 // RC4 encryption
324 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
325 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
326 //=======================================================================
330 static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
332 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
333 [rate % MAX_RATE]);
336 /*byPktType : PK_TYPE_11A 0
337 PK_TYPE_11B 1
338 PK_TYPE_11GB 2
339 PK_TYPE_11GA 3
341 static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
342 u32 frame_length, u16 rate, int need_ack)
344 u32 data_time, ack_time;
346 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
347 frame_length, rate);
349 if (pkt_type == PK_TYPE_11B)
350 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
351 (u16)priv->byTopCCKBasicRate);
352 else
353 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
354 (u16)priv->byTopOFDMBasicRate);
356 if (need_ack)
357 return data_time + priv->uSIFS + ack_time;
359 return data_time;
362 static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
363 u32 frame_length, u16 rate, int need_ack)
365 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
366 frame_length, rate, need_ack));
369 //byFreqType: 0=>5GHZ 1=>2.4GHZ
370 static u16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
371 u8 rsv_type, u8 pkt_type, u32 frame_lenght, u16 current_rate)
373 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
375 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
377 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
378 frame_lenght, current_rate);
380 if (rsv_type == 0) {
381 rts_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 20, priv->byTopCCKBasicRate);
383 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
384 pkt_type, 14, priv->byTopCCKBasicRate);
385 } else if (rsv_type == 1) {
386 rts_time = BBuGetFrameTime(priv->byPreambleType,
387 pkt_type, 20, priv->byTopCCKBasicRate);
388 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopCCKBasicRate);
390 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
391 14, priv->byTopOFDMBasicRate);
392 } else if (rsv_type == 2) {
393 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
394 20, priv->byTopOFDMBasicRate);
395 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
396 pkt_type, 14, priv->byTopOFDMBasicRate);
397 } else if (rsv_type == 3) {
398 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopCCKBasicRate);
400 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
401 14, priv->byTopOFDMBasicRate);
403 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
405 return rrv_time;
408 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
410 return cpu_to_le16((u16)rrv_time);
413 //byFreqType 0: 5GHz, 1:2.4Ghz
414 static u16 s_uGetDataDuration(struct vnt_private *pDevice,
415 u8 byPktType, int bNeedAck)
417 u32 uAckTime = 0;
419 if (bNeedAck) {
420 if (byPktType == PK_TYPE_11B)
421 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
422 byPktType, 14, pDevice->byTopCCKBasicRate);
423 else
424 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
425 byPktType, 14, pDevice->byTopOFDMBasicRate);
426 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
429 return 0;
432 //byFreqType: 0=>5GHZ 1=>2.4GHZ
433 static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
434 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
435 u8 byFBOption)
437 u32 uCTSTime = 0, uDurTime = 0;
439 switch (byDurType) {
440 case RTSDUR_BB:
441 case RTSDUR_BA:
442 case RTSDUR_BA_F0:
443 case RTSDUR_BA_F1:
444 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
445 14, pDevice->byTopCCKBasicRate);
446 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
447 s_uGetTxRsvTime(pDevice, byPktType,
448 cbFrameLength, wRate, bNeedAck);
449 break;
451 case RTSDUR_AA:
452 case RTSDUR_AA_F0:
453 case RTSDUR_AA_F1:
454 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
455 14, pDevice->byTopOFDMBasicRate);
456 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
457 s_uGetTxRsvTime(pDevice, byPktType,
458 cbFrameLength, wRate, bNeedAck);
459 break;
461 case CTSDUR_BA:
462 case CTSDUR_BA_F0:
463 case CTSDUR_BA_F1:
464 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
465 byPktType, cbFrameLength, wRate, bNeedAck);
466 break;
468 default:
469 break;
472 return cpu_to_le16((u16)uDurTime);
475 static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
476 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
478 /* Get SignalField,ServiceField,Length */
479 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
480 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
481 PK_TYPE_11B, &buf->b);
483 /* Get Duration and TimeStamp */
484 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
485 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
487 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
488 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
489 priv->byTopCCKBasicRate);
491 return buf->wDuration_a;
494 static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
495 u16 rate, struct vnt_tx_datahead_g_fb *buf,
496 u32 frame_len, int need_ack)
498 /* Get SignalField,ServiceField,Length */
499 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
501 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
502 PK_TYPE_11B, &buf->b);
504 /* Get Duration and TimeStamp */
505 buf->wDuration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
506 buf->wDuration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
508 buf->wDuration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
509 buf->wDuration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
511 buf->wTimeStampOff_a = vnt_time_stamp_off(priv, rate);
512 buf->wTimeStampOff_b = vnt_time_stamp_off(priv,
513 priv->byTopCCKBasicRate);
515 return buf->wDuration_a;
518 static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
519 u16 rate, struct vnt_tx_datahead_a_fb *buf,
520 u32 frame_len, int need_ack)
522 /* Get SignalField,ServiceField,Length */
523 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
524 /* Get Duration and TimeStampOff */
525 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
527 buf->wDuration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
528 buf->wDuration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
530 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
532 return buf->wDuration;
535 static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
536 u16 rate, struct vnt_tx_datahead_ab *buf,
537 u32 frame_len, int need_ack)
539 /* Get SignalField,ServiceField,Length */
540 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
541 /* Get Duration and TimeStampOff */
542 buf->wDuration = s_uGetDataDuration(priv, pkt_type, need_ack);
544 buf->wTimeStampOff = vnt_time_stamp_off(priv, rate);
546 return buf->wDuration;
549 static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
550 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
551 u16 duration)
553 rts->duration = duration;
554 rts->frame_control = TYPE_CTL_RTS;
556 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
557 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
558 else
559 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
561 if (priv->eOPMode == OP_MODE_AP)
562 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
563 else
564 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
566 return 0;
569 static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
570 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
571 u8 pkt_type, u32 frame_len, int need_ack,
572 u16 current_rate, u8 fb_option)
574 u16 rts_frame_len = 20;
576 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
577 PK_TYPE_11B, &buf->b);
578 BBvCalculateParameter(priv, rts_frame_len,
579 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
581 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
582 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
583 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
584 pkt_type, current_rate, need_ack, fb_option);
585 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
586 pkt_type, current_rate, need_ack, fb_option);
588 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
590 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
591 &buf->data_head, frame_len, need_ack);
594 static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
595 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
596 u8 pkt_type, u32 frame_len, int need_ack,
597 u16 current_rate, u8 fb_option)
599 u16 rts_frame_len = 20;
601 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
602 PK_TYPE_11B, &buf->b);
603 BBvCalculateParameter(priv, rts_frame_len,
604 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
607 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
608 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
609 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
610 pkt_type, current_rate, need_ack, fb_option);
611 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
612 pkt_type, current_rate, need_ack, fb_option);
615 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
616 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
617 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
618 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
619 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
620 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
621 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
624 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
626 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
627 &buf->data_head, frame_len, need_ack);
630 static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
631 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
632 u8 pkt_type, u32 frame_len, int need_ack,
633 u16 current_rate, u8 fb_option)
635 u16 rts_frame_len = 20;
637 BBvCalculateParameter(priv, rts_frame_len,
638 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
640 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
641 pkt_type, current_rate, need_ack, fb_option);
643 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
645 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
646 &buf->data_head, frame_len, need_ack);
649 static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
650 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
651 u8 pkt_type, u32 frame_len, int need_ack,
652 u16 current_rate, u8 fb_option)
654 u16 rts_frame_len = 20;
656 BBvCalculateParameter(priv, rts_frame_len,
657 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
659 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
660 pkt_type, current_rate, need_ack, fb_option);
662 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
663 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
665 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
666 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
668 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
670 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
671 &buf->data_head, frame_len, need_ack);
674 static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
675 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
676 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
679 if (!head)
680 return 0;
682 /* Note: So far RTSHead doesn't appear in ATIM
683 * & Beacom DMA, so we don't need to take them
684 * into account.
685 * Otherwise, we need to modified codes for them.
687 switch (byPktType) {
688 case PK_TYPE_11GB:
689 case PK_TYPE_11GA:
690 if (byFBOption == AUTO_FB_NONE)
691 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
694 else
695 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
696 psEthHeader, byPktType, cbFrameLength,
697 bNeedAck, wCurrentRate, byFBOption);
698 break;
699 case PK_TYPE_11A:
700 if (byFBOption) {
701 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
702 psEthHeader, byPktType, cbFrameLength,
703 bNeedAck, wCurrentRate, byFBOption);
704 break;
706 case PK_TYPE_11B:
707 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
708 psEthHeader, byPktType, cbFrameLength,
709 bNeedAck, wCurrentRate, byFBOption);
712 return 0;
715 static u16 s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
716 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
717 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
719 u32 uCTSFrameLen = 14;
721 if (!head)
722 return 0;
724 if (byFBOption != AUTO_FB_NONE) {
725 /* Auto Fall back */
726 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
727 /* Get SignalField,ServiceField,Length */
728 BBvCalculateParameter(pDevice, uCTSFrameLen,
729 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
730 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck, byFBOption);
733 /* Get CTSDuration_ba_f0 */
734 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
735 CTSDUR_BA_F0, cbFrameLength, byPktType,
736 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
737 /* Get CTSDuration_ba_f1 */
738 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
739 CTSDUR_BA_F1, cbFrameLength, byPktType,
740 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
741 /* Get CTS Frame body */
742 pBuf->data.duration = pBuf->wDuration_ba;
743 pBuf->data.frame_control = TYPE_CTL_CTS;
744 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
746 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
747 &pBuf->data_head, cbFrameLength, bNeedAck);
748 } else {
749 struct vnt_cts *pBuf = &head->cts_g;
750 /* Get SignalField,ServiceField,Length */
751 BBvCalculateParameter(pDevice, uCTSFrameLen,
752 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
753 /* Get CTSDuration_ba */
754 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
755 CTSDUR_BA, cbFrameLength, byPktType,
756 wCurrentRate, bNeedAck, byFBOption);
757 /*Get CTS Frame body*/
758 pBuf->data.duration = pBuf->wDuration_ba;
759 pBuf->data.frame_control = TYPE_CTL_CTS;
760 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
762 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
763 &pBuf->data_head, cbFrameLength, bNeedAck);
766 return 0;
771 * Description:
772 * Generate FIFO control for MAC & Baseband controller
774 * Parameters:
775 * In:
776 * pDevice - Pointer to adpater
777 * pTxDataHead - Transmit Data Buffer
778 * pTxBufHead - pTxBufHead
779 * pvRrvTime - pvRrvTime
780 * pvRTS - RTS Buffer
781 * pCTS - CTS Buffer
782 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
783 * bNeedACK - If need ACK
784 * uDMAIdx - DMA Index
785 * Out:
786 * none
788 * Return Value: none
792 static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
793 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
794 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
795 int bNeedACK, u32 uDMAIdx, struct ethhdr *psEthHeader, bool need_rts)
797 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
798 union vnt_tx_data_head *head = NULL;
799 u16 wFifoCtl;
800 u8 byFBOption = AUTO_FB_NONE;
802 pFifoHead->wReserved = wCurrentRate;
803 wFifoCtl = pFifoHead->wFIFOCtl;
805 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
806 byFBOption = AUTO_FB_0;
807 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
808 byFBOption = AUTO_FB_1;
810 if (!pFifoHead)
811 return 0;
813 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
814 if (need_rts) {
815 struct vnt_rrv_time_rts *pBuf =
816 &tx_buffer->tx_head.tx_rts.rts;
818 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
819 byPktType, cbFrameSize, wCurrentRate);
820 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
821 byPktType, cbFrameSize, wCurrentRate);
822 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
823 byPktType, cbFrameSize, wCurrentRate);
825 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
826 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
827 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
828 PK_TYPE_11B, cbFrameSize,
829 pDevice->byTopCCKBasicRate, bNeedACK);
831 if (need_mic) {
832 *mic_hdr = &tx_buffer->
833 tx_head.tx_rts.tx.mic.hdr;
834 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
835 } else {
836 head = &tx_buffer->tx_head.tx_rts.tx.head;
839 /* Fill RTS */
840 return s_vFillRTSHead(pDevice, byPktType, head,
841 cbFrameSize, bNeedACK, psEthHeader,
842 wCurrentRate, byFBOption);
844 } else {
845 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
846 tx_head.tx_cts.cts;
848 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
849 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
850 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
851 PK_TYPE_11B, cbFrameSize,
852 pDevice->byTopCCKBasicRate, bNeedACK);
854 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
855 byPktType, cbFrameSize, wCurrentRate);
857 if (need_mic) {
858 *mic_hdr = &tx_buffer->
859 tx_head.tx_cts.tx.mic.hdr;
860 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
861 } else {
862 head = &tx_buffer->tx_head.tx_cts.tx.head;
865 /* Fill CTS */
866 return s_vFillCTSHead(pDevice, uDMAIdx, byPktType,
867 head, cbFrameSize, bNeedACK, wCurrentRate,
868 byFBOption);
870 } else if (byPktType == PK_TYPE_11A) {
871 if (need_mic) {
872 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
873 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
874 } else {
875 head = &tx_buffer->tx_head.tx_ab.tx.head;
878 if (need_rts) {
879 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
880 tx_head.tx_ab.ab;
882 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
883 byPktType, cbFrameSize, wCurrentRate);
885 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
886 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
888 /* Fill RTS */
889 return s_vFillRTSHead(pDevice, byPktType, head,
890 cbFrameSize, bNeedACK, psEthHeader,
891 wCurrentRate, byFBOption);
892 } else {
893 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
894 tx_head.tx_ab.ab;
896 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
897 PK_TYPE_11A, cbFrameSize,
898 wCurrentRate, bNeedACK);
900 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
901 wCurrentRate, &head->data_head_a_fb,
902 cbFrameSize, bNeedACK);
904 } else if (byPktType == PK_TYPE_11B) {
905 if (need_mic) {
906 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
907 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
908 } else {
909 head = &tx_buffer->tx_head.tx_ab.tx.head;
912 if (need_rts) {
913 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
914 tx_head.tx_ab.ab;
916 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
917 byPktType, cbFrameSize, wCurrentRate);
919 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
920 PK_TYPE_11B, cbFrameSize, wCurrentRate,
921 bNeedACK);
923 /* Fill RTS */
924 return s_vFillRTSHead(pDevice, byPktType, head,
925 cbFrameSize,
926 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
927 } else {
928 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
929 tx_head.tx_ab.ab;
931 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice,
932 PK_TYPE_11B, cbFrameSize,
933 wCurrentRate, bNeedACK);
935 return vnt_rxtx_datahead_ab(pDevice, byPktType,
936 wCurrentRate, &head->data_head_ab,
937 cbFrameSize, bNeedACK);
941 return 0;
944 u8 * pbyBuffer,//point to pTxBufHead
945 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
946 unsigned int cbFragmentSize,//Hdr+payoad+FCS
949 static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
950 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
951 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
952 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
953 u32 *pcbHeaderLen, u32 *pcbTotalLen)
955 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
956 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
957 u32 cbFrameSize, cbFrameBodySize;
958 u32 cb802_1_H_len;
959 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
960 u32 cbFCSlen = 4, cbMICHDR = 0;
961 int bNeedACK;
962 bool bRTS = false;
963 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
964 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
965 u8 abySNAP_Bridgetunnel[ETH_ALEN]
966 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
967 u32 uDuration;
968 u32 cbHeaderLength = 0, uPadding = 0;
969 struct vnt_mic_hdr *pMICHDR;
970 u8 byFBOption = AUTO_FB_NONE, byFragType;
971 u16 wTxBufSize;
972 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
973 u32 *pdwMIC_L, *pdwMIC_R;
974 int bSoftWEP = false;
976 pMICHDR = NULL;
978 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
979 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
980 bSoftWEP = true; /* WEP 256 */
983 /* Get pkt type */
984 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
985 cb802_1_H_len = 8;
986 else
987 cb802_1_H_len = 0;
989 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
991 //Set packet type
992 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
994 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
995 (pDevice->eOPMode == OP_MODE_AP)) {
996 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
997 bNeedACK = false;
998 pTxBufHead->wFIFOCtl =
999 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1000 } else {
1001 bNeedACK = true;
1002 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1004 } else {
1005 /* MSDUs in Infra mode always need ACK */
1006 bNeedACK = true;
1007 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1010 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1012 //Set FRAGCTL_MACHDCNT
1013 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1015 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
1017 //Set FIFOCTL_GrpAckPolicy
1018 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1019 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1022 /* Set Auto Fallback Ctl */
1023 if (wCurrentRate >= RATE_18M) {
1024 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1025 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1027 pDevice->tx_rate_fb0 =
1028 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1029 pDevice->tx_rate_fb1 =
1030 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1032 byFBOption = AUTO_FB_0;
1033 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1034 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1035 pDevice->tx_rate_fb0 =
1036 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1037 pDevice->tx_rate_fb1 =
1038 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1040 byFBOption = AUTO_FB_1;
1044 if (bSoftWEP != true) {
1045 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1046 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1047 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1049 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1050 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1051 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1053 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1054 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1059 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1060 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1061 cbIVlen = 4;
1062 cbICVlen = 4;
1064 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1065 cbIVlen = 8;//IV+ExtIV
1066 cbMIClen = 8;
1067 cbICVlen = 4;
1069 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1070 cbIVlen = 8;//RSN Header
1071 cbICVlen = 8;//MIC
1072 cbMICHDR = sizeof(struct vnt_mic_hdr);
1074 if (bSoftWEP == false) {
1075 //MAC Header should be padding 0 to DW alignment.
1076 uPadding = 4 - (cbMACHdLen%4);
1077 uPadding %= 4;
1081 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1083 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1084 bRTS = false;
1085 } else {
1086 bRTS = true;
1087 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1090 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
1091 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1093 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1094 if (byFBOption == AUTO_FB_NONE) {
1095 if (bRTS == true) {//RTS_need
1096 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1097 cbMICHDR + sizeof(struct vnt_rts_g);
1099 else { //RTS_needless
1100 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1101 cbMICHDR + sizeof(struct vnt_cts);
1103 } else {
1104 // Auto Fall Back
1105 if (bRTS == true) {//RTS_need
1106 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1107 cbMICHDR + sizeof(struct vnt_rts_g_fb);
1109 else if (bRTS == false) { //RTS_needless
1110 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1111 cbMICHDR + sizeof(struct vnt_cts_fb);
1113 } // Auto Fall Back
1115 else {//802.11a/b packet
1116 if (byFBOption == AUTO_FB_NONE) {
1117 if (bRTS == true) {//RTS_need
1118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1119 cbMICHDR + sizeof(struct vnt_rts_ab);
1121 else if (bRTS == false) { //RTS_needless, no MICHDR
1122 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1123 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
1125 } else {
1126 // Auto Fall Back
1127 if (bRTS == true) {//RTS_need
1128 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1129 cbMICHDR + sizeof(struct vnt_rts_a_fb);
1131 else if (bRTS == false) { //RTS_needless
1132 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1133 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
1135 } // Auto Fall Back
1138 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1139 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1140 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1142 //=========================
1143 // No Fragmentation
1144 //=========================
1145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1146 byFragType = FRAGCTL_NONFRAG;
1147 //uDMAIdx = TYPE_AC0DMA;
1148 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1150 /* Fill FIFO, RrvTime, RTS and CTS */
1151 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1152 tx_buffer, &pMICHDR, cbMICHDR,
1153 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
1155 // Generate TX MAC Header
1156 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
1157 byFragType, uDMAIdx, 0);
1159 if (bNeedEncryption == true) {
1160 //Fill TXKEY
1161 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
1162 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
1164 if (pDevice->bEnableHostWEP) {
1165 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1166 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1170 /* 802.1H */
1171 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
1172 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1173 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
1174 memcpy((u8 *) (pbyPayloadHead),
1175 abySNAP_Bridgetunnel, 6);
1176 else
1177 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1179 pbyType = (u8 *) (pbyPayloadHead + 6);
1181 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1184 if (pPacket != NULL) {
1185 // Copy the Packet into a tx Buffer
1186 memcpy((pbyPayloadHead + cb802_1_H_len),
1187 (pPacket + ETH_HLEN),
1188 uSkbPacketLen - ETH_HLEN
1191 } else {
1192 // while bRelayPacketSend psEthHeader is point to header+payload
1193 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
1196 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1198 ///////////////////////////////////////////////////////////////////
1200 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1201 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1202 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1204 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1205 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1206 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1208 else {
1209 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1210 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
1212 // DO Software Michael
1213 MIC_vInit(dwMICKey0, dwMICKey1);
1214 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
1215 dwMIC_Priority = 0;
1216 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
1217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1218 dwMICKey0, dwMICKey1);
1220 ///////////////////////////////////////////////////////////////////
1222 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1223 //for (ii = 0; ii < cbFrameBodySize; ii++) {
1224 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
1226 //DBG_PRN_GRP12(("\n\n\n"));
1228 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1230 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1231 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
1233 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1234 MIC_vUnInit();
1236 if (pDevice->bTxMICFail == true) {
1237 *pdwMIC_L = 0;
1238 *pdwMIC_R = 0;
1239 pDevice->bTxMICFail = false;
1241 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1242 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1243 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1246 if (bSoftWEP == true) {
1248 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
1250 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1251 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1252 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
1253 cbFrameSize -= cbICVlen;
1256 cbFrameSize -= cbFCSlen;
1258 *pcbHeaderLen = cbHeaderLength;
1259 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1261 //Set FragCtl in TxBufferHead
1262 pTxBufHead->wFragCtl |= (u16)byFragType;
1264 return true;
1270 * Description:
1271 * Translate 802.3 to 802.11 header
1273 * Parameters:
1274 * In:
1275 * pDevice - Pointer to adapter
1276 * dwTxBufferAddr - Transmit Buffer
1277 * pPacket - Packet from upper layer
1278 * cbPacketSize - Transmit Data Length
1279 * Out:
1280 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1281 * pcbAppendPayload - size of append payload for 802.1H translation
1283 * Return Value: none
1287 static void s_vGenerateMACHeader(struct vnt_private *pDevice,
1288 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
1289 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
1291 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
1293 pMACHeader->frame_control = TYPE_802_11_DATA;
1295 if (pDevice->eOPMode == OP_MODE_AP) {
1296 memcpy(&(pMACHeader->addr1[0]),
1297 &(psEthHeader->h_dest[0]),
1298 ETH_ALEN);
1299 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1300 memcpy(&(pMACHeader->addr3[0]),
1301 &(psEthHeader->h_source[0]),
1302 ETH_ALEN);
1303 pMACHeader->frame_control |= FC_FROMDS;
1304 } else {
1305 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1306 memcpy(&(pMACHeader->addr1[0]),
1307 &(psEthHeader->h_dest[0]),
1308 ETH_ALEN);
1309 memcpy(&(pMACHeader->addr2[0]),
1310 &(psEthHeader->h_source[0]),
1311 ETH_ALEN);
1312 memcpy(&(pMACHeader->addr3[0]),
1313 &(pDevice->abyBSSID[0]),
1314 ETH_ALEN);
1315 } else {
1316 memcpy(&(pMACHeader->addr3[0]),
1317 &(psEthHeader->h_dest[0]),
1318 ETH_ALEN);
1319 memcpy(&(pMACHeader->addr2[0]),
1320 &(psEthHeader->h_source[0]),
1321 ETH_ALEN);
1322 memcpy(&(pMACHeader->addr1[0]),
1323 &(pDevice->abyBSSID[0]),
1324 ETH_ALEN);
1325 pMACHeader->frame_control |= FC_TODS;
1329 if (bNeedEncrypt)
1330 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
1332 pMACHeader->duration_id = cpu_to_le16(wDuration);
1334 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1336 //Set FragNumber in Sequence Control
1337 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
1339 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1340 pDevice->wSeqCounter++;
1341 if (pDevice->wSeqCounter > 0x0fff)
1342 pDevice->wSeqCounter = 0;
1345 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1346 pMACHeader->frame_control |= FC_MOREFRAG;
1352 * Description:
1353 * Request instructs a MAC to transmit a 802.11 management packet through
1354 * the adapter onto the medium.
1356 * Parameters:
1357 * In:
1358 * hDeviceContext - Pointer to the adapter
1359 * pPacket - A pointer to a descriptor for the packet to transmit
1360 * Out:
1361 * none
1363 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1367 CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1368 struct vnt_tx_mgmt *pPacket)
1370 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1371 struct vnt_tx_buffer *pTX_Buffer;
1372 struct vnt_usb_send_context *pContext;
1373 struct vnt_tx_fifo_head *pTxBufHead;
1374 struct ieee80211_hdr *pMACHeader;
1375 struct ethhdr sEthHeader;
1376 u8 byPktType, *pbyTxBufferAddr;
1377 struct vnt_mic_hdr *pMICHDR = NULL;
1378 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
1379 int bNeedACK, bIsPSPOLL = false;
1380 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1381 u32 uPadding = 0;
1382 u16 wTxBufSize;
1383 u32 cbMacHdLen;
1384 u16 wCurrentRate = RATE_1M;
1386 pContext = s_vGetFreeContext(pDevice);
1388 if (NULL == pContext) {
1389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1390 return CMD_STATUS_RESOURCES;
1393 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
1394 cbFrameBodySize = pPacket->cbPayloadLen;
1395 pTxBufHead = &pTX_Buffer->fifo_head;
1396 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1397 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1399 if (pDevice->byBBType == BB_TYPE_11A) {
1400 wCurrentRate = RATE_6M;
1401 byPktType = PK_TYPE_11A;
1402 } else {
1403 wCurrentRate = RATE_1M;
1404 byPktType = PK_TYPE_11B;
1407 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1408 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1409 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1410 // to set power here.
1411 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1412 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1413 } else {
1414 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1416 pDevice->wCurrentRate = wCurrentRate;
1418 //Set packet type
1419 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1420 pTxBufHead->wFIFOCtl = 0;
1422 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1425 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1428 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1429 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1432 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1433 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1435 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
1436 bNeedACK = false;
1438 else {
1439 bNeedACK = true;
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1443 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1444 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1446 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1447 //Set Preamble type always long
1448 //pDevice->byPreambleType = PREAMBLE_LONG;
1449 // probe-response don't retry
1450 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1451 // bNeedACK = false;
1452 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1456 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1458 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
1459 bIsPSPOLL = true;
1460 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1461 } else {
1462 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1465 //Set FRAGCTL_MACHDCNT
1466 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
1468 // Notes:
1469 // Although spec says MMPDU can be fragmented; In most case,
1470 // no one will send a MMPDU under fragmentation. With RTS may occur.
1472 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1473 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1474 cbIVlen = 4;
1475 cbICVlen = 4;
1476 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1478 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1479 cbIVlen = 8;//IV+ExtIV
1480 cbMIClen = 8;
1481 cbICVlen = 4;
1482 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1483 //We need to get seed here for filling TxKey entry.
1484 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1485 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1487 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1488 cbIVlen = 8;//RSN Header
1489 cbICVlen = 8;//MIC
1490 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1492 //MAC Header should be padding 0 to DW alignment.
1493 uPadding = 4 - (cbMacHdLen%4);
1494 uPadding %= 4;
1497 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1499 //Set FIFOCTL_GrpAckPolicy
1500 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1501 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1503 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1505 //Set RrvTime/RTS/CTS Buffer
1506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1507 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1508 sizeof(struct vnt_cts);
1510 else { // 802.11a/b packet
1511 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1512 sizeof(struct vnt_tx_datahead_ab);
1515 memcpy(&(sEthHeader.h_dest[0]),
1516 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1517 ETH_ALEN);
1518 memcpy(&(sEthHeader.h_source[0]),
1519 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1520 ETH_ALEN);
1521 //=========================
1522 // No Fragmentation
1523 //=========================
1524 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
1526 /* Fill FIFO,RrvTime,RTS,and CTS */
1527 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1528 pTX_Buffer, &pMICHDR, 0,
1529 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
1531 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
1533 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1535 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1536 u8 * pbyIVHead;
1537 u8 * pbyPayloadHead;
1538 u8 * pbyBSSID;
1539 PSKeyItem pTransmitKey = NULL;
1541 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1542 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
1543 do {
1544 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
1545 (pDevice->bLinkPass == true)) {
1546 pbyBSSID = pDevice->abyBSSID;
1547 // get pairwise key
1548 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1549 // get group key
1550 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1552 break;
1554 } else {
1555 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1556 break;
1559 // get group key
1560 pbyBSSID = pDevice->abyBroadcastAddr;
1561 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1562 pTransmitKey = NULL;
1563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1564 } else {
1565 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1567 } while(false);
1568 //Fill TXKEY
1569 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
1570 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
1572 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
1573 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
1574 cbFrameBodySize);
1576 else {
1577 // Copy the Packet into a tx Buffer
1578 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1581 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1582 pDevice->wSeqCounter++ ;
1583 if (pDevice->wSeqCounter > 0x0fff)
1584 pDevice->wSeqCounter = 0;
1586 if (bIsPSPOLL) {
1587 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
1588 // of FIFO control header.
1589 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1590 // in the same place of other packet's Duration-field).
1591 // And it will cause Cisco-AP to issue Disassociation-packet
1592 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1593 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1594 tx_cts.tx.head.cts_g.data_head;
1595 data_head->wDuration_a =
1596 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1597 data_head->wDuration_b =
1598 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1599 } else {
1600 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1601 tx_ab.tx.head.data_head_ab;
1602 data_head->wDuration =
1603 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1607 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
1608 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
1609 pTX_Buffer->byType = 0x00;
1611 pContext->pPacket = NULL;
1612 pContext->Type = CONTEXT_MGMT_PACKET;
1613 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
1615 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1616 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1617 &pMACHeader->addr1[0], (u16)cbFrameSize,
1618 pTxBufHead->wFIFOCtl);
1620 else {
1621 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1622 &pMACHeader->addr3[0], (u16)cbFrameSize,
1623 pTxBufHead->wFIFOCtl);
1626 PIPEnsSendBulkOut(pDevice,pContext);
1627 return CMD_STATUS_PENDING;
1630 CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1631 struct vnt_tx_mgmt *pPacket)
1633 struct vnt_beacon_buffer *pTX_Buffer;
1634 struct vnt_tx_short_buf_head *short_head;
1635 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1636 u32 cbHeaderSize = 0;
1637 struct ieee80211_hdr *pMACHeader;
1638 u16 wCurrentRate;
1639 u32 cbFrameBodySize;
1640 u32 cbReqCount;
1641 struct vnt_usb_send_context *pContext;
1642 CMD_STATUS status;
1644 pContext = s_vGetFreeContext(pDevice);
1645 if (NULL == pContext) {
1646 status = CMD_STATUS_RESOURCES;
1647 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1648 return status ;
1651 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
1652 short_head = &pTX_Buffer->short_head;
1654 cbFrameBodySize = pPacket->cbPayloadLen;
1656 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
1658 if (pDevice->byBBType == BB_TYPE_11A) {
1659 wCurrentRate = RATE_6M;
1661 /* Get SignalField,ServiceField,Length */
1662 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1663 PK_TYPE_11A, &short_head->ab);
1665 /* Get Duration and TimeStampOff */
1666 short_head->duration = s_uGetDataDuration(pDevice,
1667 PK_TYPE_11A, false);
1668 short_head->time_stamp_off =
1669 vnt_time_stamp_off(pDevice, wCurrentRate);
1670 } else {
1671 wCurrentRate = RATE_1M;
1672 short_head->fifo_ctl |= FIFOCTL_11B;
1674 /* Get SignalField,ServiceField,Length */
1675 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1676 PK_TYPE_11B, &short_head->ab);
1678 /* Get Duration and TimeStampOff */
1679 short_head->duration = s_uGetDataDuration(pDevice,
1680 PK_TYPE_11B, false);
1681 short_head->time_stamp_off =
1682 vnt_time_stamp_off(pDevice, wCurrentRate);
1686 /* Generate Beacon Header */
1687 pMACHeader = &pTX_Buffer->hdr;
1689 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1691 pMACHeader->duration_id = 0;
1692 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1693 pDevice->wSeqCounter++;
1694 if (pDevice->wSeqCounter > 0x0fff)
1695 pDevice->wSeqCounter = 0;
1697 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1699 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
1700 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
1701 pTX_Buffer->byType = 0x01;
1703 pContext->pPacket = NULL;
1704 pContext->Type = CONTEXT_MGMT_PACKET;
1705 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
1707 PIPEnsSendBulkOut(pDevice,pContext);
1708 return CMD_STATUS_PENDING;
1712 void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1714 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1715 struct vnt_tx_buffer *pTX_Buffer;
1716 struct vnt_tx_fifo_head *pTxBufHead;
1717 u8 byPktType;
1718 u8 *pbyTxBufferAddr;
1719 u32 uDuration, cbReqCount;
1720 struct ieee80211_hdr *pMACHeader;
1721 u32 cbHeaderSize, cbFrameBodySize;
1722 int bNeedACK, bIsPSPOLL = false;
1723 u32 cbFrameSize;
1724 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1725 u32 uPadding = 0;
1726 u32 cbMICHDR = 0, uLength = 0;
1727 u32 dwMICKey0, dwMICKey1;
1728 u32 dwMIC_Priority;
1729 u32 *pdwMIC_L, *pdwMIC_R;
1730 u16 wTxBufSize;
1731 u32 cbMacHdLen;
1732 struct ethhdr sEthHeader;
1733 struct vnt_mic_hdr *pMICHDR;
1734 u32 wCurrentRate = RATE_1M;
1735 PUWLAN_80211HDR p80211Header;
1736 u32 uNodeIndex = 0;
1737 int bNodeExist = false;
1738 SKeyItem STempKey;
1739 PSKeyItem pTransmitKey = NULL;
1740 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1741 u32 cbExtSuppRate = 0;
1742 struct vnt_usb_send_context *pContext;
1744 pMICHDR = NULL;
1746 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1747 cbFrameBodySize = 0;
1749 else {
1750 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1752 p80211Header = (PUWLAN_80211HDR)skb->data;
1754 pContext = s_vGetFreeContext(pDevice);
1756 if (NULL == pContext) {
1757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1758 dev_kfree_skb_irq(skb);
1759 return ;
1762 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
1763 pTxBufHead = &pTX_Buffer->fifo_head;
1764 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1765 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1767 if (pDevice->byBBType == BB_TYPE_11A) {
1768 wCurrentRate = RATE_6M;
1769 byPktType = PK_TYPE_11A;
1770 } else {
1771 wCurrentRate = RATE_1M;
1772 byPktType = PK_TYPE_11B;
1775 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1776 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1777 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1778 // to set power here.
1779 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1780 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1781 } else {
1782 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1787 //Set packet type
1788 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1789 pTxBufHead->wFIFOCtl = 0;
1791 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1792 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1794 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1795 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1797 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1798 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1801 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1802 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1804 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
1805 bNeedACK = false;
1806 if (pDevice->bEnableHostWEP) {
1807 uNodeIndex = 0;
1808 bNodeExist = true;
1811 else {
1812 if (pDevice->bEnableHostWEP) {
1813 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
1814 bNodeExist = true;
1816 bNeedACK = true;
1817 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1820 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1821 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1823 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1824 //Set Preamble type always long
1825 //pDevice->byPreambleType = PREAMBLE_LONG;
1827 // probe-response don't retry
1828 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
1829 // bNeedACK = false;
1830 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1834 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1836 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
1837 bIsPSPOLL = true;
1838 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1839 } else {
1840 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1843 // hostapd daemon ext support rate patch
1844 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1846 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1847 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1850 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1851 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1854 if (cbExtSuppRate >0) {
1855 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1859 //Set FRAGCTL_MACHDCNT
1860 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
1862 // Notes:
1863 // Although spec says MMPDU can be fragmented; In most case,
1864 // no one will send a MMPDU under fragmentation. With RTS may occur.
1866 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1867 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1868 cbIVlen = 4;
1869 cbICVlen = 4;
1870 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1872 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1873 cbIVlen = 8;//IV+ExtIV
1874 cbMIClen = 8;
1875 cbICVlen = 4;
1876 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1877 //We need to get seed here for filling TxKey entry.
1878 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1879 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1881 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1882 cbIVlen = 8;//RSN Header
1883 cbICVlen = 8;//MIC
1884 cbMICHDR = sizeof(struct vnt_mic_hdr);
1885 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1887 //MAC Header should be padding 0 to DW alignment.
1888 uPadding = 4 - (cbMacHdLen%4);
1889 uPadding %= 4;
1892 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1894 //Set FIFOCTL_GrpAckPolicy
1895 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1896 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1898 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1900 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1901 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
1902 sizeof(struct vnt_cts);
1905 else {//802.11a/b packet
1906 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
1907 sizeof(struct vnt_tx_datahead_ab);
1909 memcpy(&(sEthHeader.h_dest[0]),
1910 &(p80211Header->sA3.abyAddr1[0]),
1911 ETH_ALEN);
1912 memcpy(&(sEthHeader.h_source[0]),
1913 &(p80211Header->sA3.abyAddr2[0]),
1914 ETH_ALEN);
1915 //=========================
1916 // No Fragmentation
1917 //=========================
1918 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
1920 /* Fill FIFO,RrvTime,RTS,and CTS */
1921 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1922 pTX_Buffer, &pMICHDR, cbMICHDR,
1923 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
1925 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
1927 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
1929 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
1930 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
1931 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
1933 // Copy the Packet into a tx Buffer
1934 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
1936 // version set to 0, patch for hostapd deamon
1937 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
1938 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
1940 // replace support rate, patch for hostapd daemon( only support 11M)
1941 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1942 if (cbExtSuppRate != 0) {
1943 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
1944 memcpy((pbyPayloadHead + cbFrameBodySize),
1945 pMgmt->abyCurrSuppRates,
1946 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
1948 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
1949 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
1950 pMgmt->abyCurrExtSuppRates,
1951 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
1956 // Set wep
1957 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1959 if (pDevice->bEnableHostWEP) {
1960 pTransmitKey = &STempKey;
1961 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1962 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1963 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1964 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1965 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1966 memcpy(pTransmitKey->abyKey,
1967 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1968 pTransmitKey->uKeyLength
1972 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1974 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1975 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1977 // DO Software Michael
1978 MIC_vInit(dwMICKey0, dwMICKey1);
1979 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
1980 dwMIC_Priority = 0;
1981 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
1982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
1983 " %X, %X\n", dwMICKey0, dwMICKey1);
1985 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
1987 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
1989 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
1990 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
1992 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1993 MIC_vUnInit();
1995 if (pDevice->bTxMICFail == true) {
1996 *pdwMIC_L = 0;
1997 *pdwMIC_R = 0;
1998 pDevice->bTxMICFail = false;
2001 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2002 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2003 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2004 *pdwMIC_L, *pdwMIC_R);
2008 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
2009 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
2011 if (pDevice->bEnableHostWEP) {
2012 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2013 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2016 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
2017 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
2021 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
2022 pDevice->wSeqCounter++ ;
2023 if (pDevice->wSeqCounter > 0x0fff)
2024 pDevice->wSeqCounter = 0;
2026 if (bIsPSPOLL) {
2027 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2028 // of FIFO control header.
2029 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2030 // in the same place of other packet's Duration-field).
2031 // And it will cause Cisco-AP to issue Disassociation-packet
2032 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2033 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
2034 tx_cts.tx.head.cts_g.data_head;
2035 data_head->wDuration_a =
2036 cpu_to_le16(p80211Header->sA2.wDurationID);
2037 data_head->wDuration_b =
2038 cpu_to_le16(p80211Header->sA2.wDurationID);
2039 } else {
2040 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
2041 tx_ab.tx.head.data_head_ab;
2042 data_head->wDuration =
2043 cpu_to_le16(p80211Header->sA2.wDurationID);
2047 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
2048 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2049 pTX_Buffer->byType = 0x00;
2051 pContext->pPacket = skb;
2052 pContext->Type = CONTEXT_MGMT_PACKET;
2053 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
2055 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2056 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2057 &pMACHeader->addr1[0], (u16)cbFrameSize,
2058 pTxBufHead->wFIFOCtl);
2060 else {
2061 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2062 &pMACHeader->addr3[0], (u16)cbFrameSize,
2063 pTxBufHead->wFIFOCtl);
2065 PIPEnsSendBulkOut(pDevice,pContext);
2066 return ;
2070 //TYPE_AC0DMA data tx
2072 * Description:
2073 * Tx packet via AC0DMA(DMA1)
2075 * Parameters:
2076 * In:
2077 * pDevice - Pointer to the adapter
2078 * skb - Pointer to tx skb packet
2079 * Out:
2080 * void
2082 * Return Value: NULL
2085 int nsDMA_tx_packet(struct vnt_private *pDevice,
2086 u32 uDMAIdx, struct sk_buff *skb)
2088 struct net_device_stats *pStats = &pDevice->stats;
2089 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2090 struct vnt_tx_buffer *pTX_Buffer;
2091 u32 BytesToWrite = 0, uHeaderLen = 0;
2092 u32 uNodeIndex = 0;
2093 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2094 u16 wAID;
2095 u8 byPktType;
2096 int bNeedEncryption = false;
2097 PSKeyItem pTransmitKey = NULL;
2098 SKeyItem STempKey;
2099 int ii;
2100 int bTKIP_UseGTK = false;
2101 int bNeedDeAuth = false;
2102 u8 *pbyBSSID;
2103 int bNodeExist = false;
2104 struct vnt_usb_send_context *pContext;
2105 bool fConvertedPacket;
2106 u32 status;
2107 u16 wKeepRate = pDevice->wCurrentRate;
2108 int bTxeapol_key = false;
2110 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2112 if (pDevice->uAssocCount == 0) {
2113 dev_kfree_skb_irq(skb);
2114 return 0;
2117 if (is_multicast_ether_addr((u8 *)(skb->data))) {
2118 uNodeIndex = 0;
2119 bNodeExist = true;
2120 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2122 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2123 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2124 // set tx map
2125 pMgmt->abyPSTxMap[0] |= byMask[0];
2126 return 0;
2128 // multicast/broadcast data rate
2130 if (pDevice->byBBType != BB_TYPE_11A)
2131 pDevice->wCurrentRate = RATE_2M;
2132 else
2133 pDevice->wCurrentRate = RATE_24M;
2134 // long preamble type
2135 pDevice->byPreambleType = PREAMBLE_SHORT;
2137 }else {
2139 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
2141 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2143 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2145 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2146 // set tx map
2147 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2148 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2150 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2152 return 0;
2154 // AP rate decided from node
2155 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2156 // tx preamble decided from node
2158 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2159 pDevice->byPreambleType = pDevice->byShortPreamble;
2161 }else {
2162 pDevice->byPreambleType = PREAMBLE_LONG;
2164 bNodeExist = true;
2168 if (bNodeExist == false) {
2169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2170 dev_kfree_skb_irq(skb);
2171 return 0;
2175 pContext = s_vGetFreeContext(pDevice);
2177 if (pContext == NULL) {
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2179 dev_kfree_skb_irq(skb);
2180 return STATUS_RESOURCES;
2183 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
2185 //mike add:station mode check eapol-key challenge--->
2187 u8 Protocol_Version; //802.1x Authentication
2188 u8 Packet_Type; //802.1x Authentication
2189 u8 Descriptor_type;
2190 u16 Key_info;
2192 Protocol_Version = skb->data[ETH_HLEN];
2193 Packet_Type = skb->data[ETH_HLEN+1];
2194 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2195 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2196 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
2197 /* 802.1x OR eapol-key challenge frame transfer */
2198 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2199 (Packet_Type == 3)) {
2200 bTxeapol_key = true;
2201 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2202 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2203 if(Descriptor_type==254) {
2204 pDevice->fWPA_Authened = true;
2205 PRINT_K("WPA ");
2207 else {
2208 pDevice->fWPA_Authened = true;
2209 PRINT_K("WPA2(re-keying) ");
2211 PRINT_K("Authentication completed!!\n");
2213 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
2214 (Key_info & BIT8) && (Key_info & BIT9)) {
2215 pDevice->fWPA_Authened = true;
2216 PRINT_K("WPA2 Authentication completed!!\n");
2221 //mike add:station mode check eapol-key challenge<---
2223 if (pDevice->bEncryptionEnable == true) {
2224 bNeedEncryption = true;
2225 // get Transmit key
2226 do {
2227 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2228 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2229 pbyBSSID = pDevice->abyBSSID;
2230 // get pairwise key
2231 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2232 // get group key
2233 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2234 bTKIP_UseGTK = true;
2235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2236 break;
2238 } else {
2239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2240 break;
2242 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2243 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2244 pbyBSSID = pDevice->sTxEthHeader.h_dest;
2245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2246 for (ii = 0; ii< 6; ii++)
2247 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2250 // get pairwise key
2251 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2252 break;
2254 // get group key
2255 pbyBSSID = pDevice->abyBroadcastAddr;
2256 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2257 pTransmitKey = NULL;
2258 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2261 else
2262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2263 } else {
2264 bTKIP_UseGTK = true;
2265 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2267 } while(false);
2270 if (pDevice->bEnableHostWEP) {
2271 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2272 if (pDevice->bEncryptionEnable == true) {
2273 pTransmitKey = &STempKey;
2274 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2275 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2276 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2277 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2278 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2279 memcpy(pTransmitKey->abyKey,
2280 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2281 pTransmitKey->uKeyLength
2286 byPktType = (u8)pDevice->byPacketType;
2288 if (pDevice->bFixRate) {
2289 if (pDevice->byBBType == BB_TYPE_11B) {
2290 if (pDevice->uConnectionRate >= RATE_11M) {
2291 pDevice->wCurrentRate = RATE_11M;
2292 } else {
2293 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2295 } else {
2296 if ((pDevice->byBBType == BB_TYPE_11A) &&
2297 (pDevice->uConnectionRate <= RATE_6M)) {
2298 pDevice->wCurrentRate = RATE_6M;
2299 } else {
2300 if (pDevice->uConnectionRate >= RATE_54M)
2301 pDevice->wCurrentRate = RATE_54M;
2302 else
2303 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2307 else {
2308 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2309 // Adhoc Tx rate decided from node DB
2310 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
2311 // Multicast use highest data rate
2312 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2313 // preamble type
2314 pDevice->byPreambleType = pDevice->byShortPreamble;
2316 else {
2317 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
2318 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2319 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2320 pDevice->byPreambleType = pDevice->byShortPreamble;
2323 else {
2324 pDevice->byPreambleType = PREAMBLE_LONG;
2326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2328 else {
2329 if (pDevice->byBBType != BB_TYPE_11A)
2330 pDevice->wCurrentRate = RATE_2M;
2331 else
2332 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2333 // abyCurrExtSuppRates[]
2334 pDevice->byPreambleType = PREAMBLE_SHORT;
2335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2339 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2340 // Infra STA rate decided from AP Node, index = 0
2341 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2345 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
2346 if (pDevice->byBBType != BB_TYPE_11A) {
2347 pDevice->wCurrentRate = RATE_1M;
2348 pDevice->byACKRate = RATE_1M;
2349 pDevice->byTopCCKBasicRate = RATE_1M;
2350 pDevice->byTopOFDMBasicRate = RATE_6M;
2351 } else {
2352 pDevice->wCurrentRate = RATE_6M;
2353 pDevice->byACKRate = RATE_6M;
2354 pDevice->byTopCCKBasicRate = RATE_1M;
2355 pDevice->byTopOFDMBasicRate = RATE_6M;
2359 DBG_PRT(MSG_LEVEL_DEBUG,
2360 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2361 pDevice->wCurrentRate);
2363 if (wKeepRate != pDevice->wCurrentRate) {
2364 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
2367 if (pDevice->wCurrentRate <= RATE_11M) {
2368 byPktType = PK_TYPE_11B;
2371 if (bNeedEncryption == true) {
2372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2373 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
2374 bNeedEncryption = false;
2375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
2376 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2377 if (pTransmitKey == NULL) {
2378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2380 else {
2381 if (bTKIP_UseGTK == true) {
2382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2384 else {
2385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2386 pTransmitKey->dwKeyIndex);
2387 bNeedEncryption = true;
2392 if (pDevice->bEnableHostWEP) {
2393 if ((uNodeIndex != 0) &&
2394 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2395 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2396 pTransmitKey->dwKeyIndex);
2397 bNeedEncryption = true;
2401 else {
2403 if (pTransmitKey == NULL) {
2404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2405 pContext->bBoolInUse = false;
2406 dev_kfree_skb_irq(skb);
2407 pStats->tx_dropped++;
2408 return STATUS_FAILURE;
2413 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2415 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
2416 pTX_Buffer, bNeedEncryption,
2417 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
2418 (u8 *)skb->data, pTransmitKey, uNodeIndex,
2419 pDevice->wCurrentRate,
2420 &uHeaderLen, &BytesToWrite
2423 if (fConvertedPacket == false) {
2424 pContext->bBoolInUse = false;
2425 dev_kfree_skb_irq(skb);
2426 return STATUS_FAILURE;
2429 if ( pDevice->bEnablePSMode == true ) {
2430 if ( !pDevice->bPSModeTxBurst ) {
2431 bScheduleCommand((void *) pDevice,
2432 WLAN_CMD_MAC_DISPOWERSAVING,
2433 NULL);
2434 pDevice->bPSModeTxBurst = true;
2438 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2439 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
2441 pContext->pPacket = skb;
2442 pContext->Type = CONTEXT_DATA_PACKET;
2443 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
2445 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2446 &pContext->sEthHeader.h_dest[0],
2447 (u16)(BytesToWrite-uHeaderLen),
2448 pTX_Buffer->fifo_head.wFIFOCtl);
2450 status = PIPEnsSendBulkOut(pDevice,pContext);
2452 if (bNeedDeAuth == true) {
2453 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
2455 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
2458 if(status!=STATUS_PENDING) {
2459 pContext->bBoolInUse = false;
2460 dev_kfree_skb_irq(skb);
2461 return STATUS_FAILURE;
2463 else
2464 return 0;
2469 * Description:
2470 * Relay packet send (AC1DMA) from rx dpc.
2472 * Parameters:
2473 * In:
2474 * pDevice - Pointer to the adapter
2475 * pPacket - Pointer to rx packet
2476 * cbPacketSize - rx ethernet frame size
2477 * Out:
2478 * TURE, false
2480 * Return Value: Return true if packet is copy to dma1; otherwise false
2483 int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2484 u32 uNodeIndex)
2486 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2487 struct vnt_tx_buffer *pTX_Buffer;
2488 u32 BytesToWrite = 0, uHeaderLen = 0;
2489 u8 byPktType = PK_TYPE_11B;
2490 int bNeedEncryption = false;
2491 SKeyItem STempKey;
2492 PSKeyItem pTransmitKey = NULL;
2493 u8 *pbyBSSID;
2494 struct vnt_usb_send_context *pContext;
2495 u8 byPktTyp;
2496 int fConvertedPacket;
2497 u32 status;
2498 u16 wKeepRate = pDevice->wCurrentRate;
2500 pContext = s_vGetFreeContext(pDevice);
2502 if (NULL == pContext) {
2503 return false;
2506 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
2508 if (pDevice->bEncryptionEnable == true) {
2509 bNeedEncryption = true;
2510 // get group key
2511 pbyBSSID = pDevice->abyBroadcastAddr;
2512 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2513 pTransmitKey = NULL;
2514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2515 } else {
2516 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2520 if (pDevice->bEnableHostWEP) {
2521 if (uNodeIndex < MAX_NODE_NUM + 1) {
2522 pTransmitKey = &STempKey;
2523 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2524 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2525 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2526 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2527 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2528 memcpy(pTransmitKey->abyKey,
2529 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2530 pTransmitKey->uKeyLength
2535 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
2536 pContext->bBoolInUse = false;
2537 return false;
2540 byPktTyp = (u8)pDevice->byPacketType;
2542 if (pDevice->bFixRate) {
2543 if (pDevice->byBBType == BB_TYPE_11B) {
2544 if (pDevice->uConnectionRate >= RATE_11M) {
2545 pDevice->wCurrentRate = RATE_11M;
2546 } else {
2547 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2549 } else {
2550 if ((pDevice->byBBType == BB_TYPE_11A) &&
2551 (pDevice->uConnectionRate <= RATE_6M)) {
2552 pDevice->wCurrentRate = RATE_6M;
2553 } else {
2554 if (pDevice->uConnectionRate >= RATE_54M)
2555 pDevice->wCurrentRate = RATE_54M;
2556 else
2557 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
2561 else {
2562 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2565 if (wKeepRate != pDevice->wCurrentRate) {
2566 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
2569 if (pDevice->wCurrentRate <= RATE_11M)
2570 byPktType = PK_TYPE_11B;
2572 BytesToWrite = uDataLen + ETH_FCS_LEN;
2574 // Convert the packet to an usb frame and copy into our buffer
2575 // and send the irp.
2577 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2579 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
2580 pTX_Buffer, bNeedEncryption,
2581 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2582 pbySkbData, pTransmitKey, uNodeIndex,
2583 pDevice->wCurrentRate,
2584 &uHeaderLen, &BytesToWrite
2587 if (fConvertedPacket == false) {
2588 pContext->bBoolInUse = false;
2589 return false;
2592 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2593 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
2595 pContext->pPacket = NULL;
2596 pContext->Type = CONTEXT_DATA_PACKET;
2597 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
2599 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
2600 &pContext->sEthHeader.h_dest[0],
2601 (u16)(BytesToWrite - uHeaderLen),
2602 pTX_Buffer->fifo_head.wFIFOCtl);
2604 status = PIPEnsSendBulkOut(pDevice,pContext);
2606 return true;