]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/vt6656/rxtx.c
staging: vt6656: rxtx.c s_vFillRTSHead/s_vFillCTSHead move union vnt_tx_data_head...
[mirror_ubuntu-artful-kernel.git] / drivers / staging / vt6656 / rxtx.c
CommitLineData
92b96797
FB
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
f77f13e2 28 * s_vGenerateTxParameter - Generate tx dma required parameter.
92b96797
FB
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
f77f13e2 34 * s_uGetRTSCTSDuration- get rtx/cts required duration
92b96797
FB
35 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
36 * s_uGetTxRsvTime- get frame reserved time
37 * s_vFillCTSHead- fulfill CTS ctl header
f77f13e2 38 * s_vFillFragParameter- Set fragment ctl parameter.
92b96797
FB
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
44 *
45 * Revision History:
46 *
47 */
48
92b96797 49#include "device.h"
92b96797 50#include "rxtx.h"
92b96797 51#include "tether.h"
92b96797 52#include "card.h"
92b96797 53#include "bssdb.h"
92b96797 54#include "mac.h"
92b96797 55#include "michael.h"
92b96797 56#include "tkip.h"
92b96797 57#include "tcrc.h"
92b96797 58#include "wctl.h"
92b96797 59#include "hostap.h"
92b96797 60#include "rf.h"
92b96797 61#include "datarate.h"
92b96797 62#include "usbpipe.h"
92b96797 63#include "iocmd.h"
9d26d60f 64
4a499de2 65static int msglevel = MSG_LEVEL_INFO;
92b96797 66
3eaca0d2 67const u16 wTimeStampOff[2][MAX_RATE] = {
92b96797
FB
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
70 };
71
3eaca0d2 72const u16 wFB_Opt0[2][5] = {
92b96797
FB
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
75 };
3eaca0d2 76const u16 wFB_Opt1[2][5] = {
92b96797
FB
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
79 };
80
92b96797
FB
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
95
d56131de
MP
96static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
97 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
98
99static void *s_vGetFreeContext(struct vnt_private *pDevice);
100
101static void s_vGenerateTxParameter(struct vnt_private *pDevice,
102 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
351c7dc3 103 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
f46142b0 104 struct ethhdr *psEthHeader, bool need_rts);
d56131de
MP
105
106static u32 s_uFillDataHead(struct vnt_private *pDevice,
107 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
ab01fedc 108 u32 uDMAIdx, int bNeedAck, u8 byFBOption);
d56131de 109
d56131de 110static void s_vGenerateMACHeader(struct vnt_private *pDevice,
ceb8c5da 111 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
d56131de
MP
112 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
113
114static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
115 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
ec37d8b6 116 struct vnt_mic_hdr *mic_hdr);
d56131de
MP
117
118static void s_vSWencryption(struct vnt_private *pDevice,
119 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
120
121static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
122 u32 cbFrameLength, u16 wRate, int bNeedAck);
123
cfabe4b4 124static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
d56131de
MP
125 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
126
127static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
5fb8e412
MP
128 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
129 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
d56131de
MP
130
131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
5fb8e412 132 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
ceb8c5da 133 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
d56131de 134
6b5ad9d2 135static u16 s_uGetDataDuration(struct vnt_private *pDevice,
3ed210ef 136 u8 byPktType, int bNeedAck);
d56131de 137
e34f9dbe 138static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
d56131de
MP
139 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
140 int bNeedAck, u8 byFBOption);
92b96797 141
d56131de 142static void *s_vGetFreeContext(struct vnt_private *pDevice)
92b96797 143{
d56131de
MP
144 PUSB_SEND_CONTEXT pContext = NULL;
145 PUSB_SEND_CONTEXT pReturnContext = NULL;
146 int ii;
92b96797
FB
147
148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
149
150 for (ii = 0; ii < pDevice->cbTD; ii++) {
151 pContext = pDevice->apTD[ii];
e269fc2d 152 if (pContext->bBoolInUse == false) {
4e9b5e2b 153 pContext->bBoolInUse = true;
c0de17e4 154 memset(pContext->Data, 0, MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
92b96797
FB
155 pReturnContext = pContext;
156 break;
157 }
158 }
159 if ( ii == pDevice->cbTD ) {
160 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
161 }
8611a29a 162 return (void *) pReturnContext;
92b96797
FB
163}
164
d56131de
MP
165static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
166 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
92b96797 167{
d56131de 168 PSStatCounter pStatistic = &pDevice->scStatistic;
92b96797 169
4b50fb40 170 if (is_broadcast_ether_addr(pbyDestAddr))
92b96797 171 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
4b50fb40 172 else if (is_multicast_ether_addr(pbyDestAddr))
92b96797
FB
173 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
174 else
175 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
176
177 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
178 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
9a0e756c
AM
179 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
180 pbyDestAddr,
181 ETH_ALEN);
92b96797
FB
182}
183
d56131de
MP
184static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
185 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
ec37d8b6 186 u16 wPayloadLen, struct vnt_mic_hdr *mic_hdr)
92b96797 187{
d56131de
MP
188 u32 *pdwIV = (u32 *)pbyIVHead;
189 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
1cac4a4b 190 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
d56131de 191 u32 dwRevIVCounter;
92b96797 192
92b96797
FB
193 //Fill TXKEY
194 if (pTransmitKey == NULL)
195 return;
196
197 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
198 *pdwIV = pDevice->dwIVCounter;
199 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
200
201 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
202 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
b902fbfe 203 memcpy(pDevice->abyPRNG, (u8 *)&(dwRevIVCounter), 3);
3e362598 204 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
92b96797 205 } else {
b902fbfe 206 memcpy(pbyBuf, (u8 *)&(dwRevIVCounter), 3);
3e362598 207 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
92b96797 208 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
b902fbfe 209 memcpy(pbyBuf+8, (u8 *)&(dwRevIVCounter), 3);
3e362598 210 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
92b96797 211 }
3e362598 212 memcpy(pDevice->abyPRNG, pbyBuf, 16);
92b96797
FB
213 }
214 // Append IV after Mac Header
215 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
d5bbef7c 216 *pdwIV |= (u32)pDevice->byKeyIndex << 30;
92b96797
FB
217 *pdwIV = cpu_to_le32(*pdwIV);
218 pDevice->dwIVCounter++;
219 if (pDevice->dwIVCounter > WEP_IV_MASK) {
220 pDevice->dwIVCounter = 0;
221 }
222 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0) {
225 pTransmitKey->dwTSC47_16++;
226 }
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
3e362598 229 memcpy(pbyBuf, pDevice->abyPRNG, 16);
92b96797 230 // Make IV
3e362598 231 memcpy(pdwIV, pDevice->abyPRNG, 3);
92b96797 232
b902fbfe 233 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
92b96797
FB
234 // Append IV&ExtIV after Mac Header
235 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
b4dc03af
MP
236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %x\n",
237 *pdwExtIV);
92b96797
FB
238
239 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
240 pTransmitKey->wTSC15_0++;
241 if (pTransmitKey->wTSC15_0 == 0) {
242 pTransmitKey->dwTSC47_16++;
243 }
3e362598 244 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
92b96797
FB
245
246 // Make IV
247 *pdwIV = 0;
b902fbfe 248 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
3eaca0d2 249 *pdwIV |= cpu_to_le16((u16)(pTransmitKey->wTSC15_0));
92b96797
FB
250 //Append IV&ExtIV after Mac Header
251 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
252
ec37d8b6
MP
253 if (!mic_hdr)
254 return;
255
256 /* MICHDR0 */
257 mic_hdr->id = 0x59;
258 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
259 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
260
261 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
262 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
263
264 /* MICHDR1 */
265 if (pDevice->bLongHeader)
266 mic_hdr->hlen = cpu_to_be16(28);
267 else
268 mic_hdr->hlen = cpu_to_be16(22);
269
270 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
271 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
272
273 /* MICHDR2 */
274 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
275 mic_hdr->frame_control = cpu_to_le16(pMACHeader->frame_control
276 & 0xc78f);
277 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->seq_ctrl & 0xf);
278
279 if (pDevice->bLongHeader)
280 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
92b96797
FB
281 }
282}
283
d56131de
MP
284static void s_vSWencryption(struct vnt_private *pDevice,
285 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
92b96797 286{
d56131de
MP
287 u32 cbICVlen = 4;
288 u32 dwICV = 0xffffffff;
289 u32 *pdwICV;
92b96797
FB
290
291 if (pTransmitKey == NULL)
292 return;
293
294 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
295 //=======================================================================
296 // Append ICV after payload
297 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
52a7e64b 298 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
92b96797
FB
299 // finally, we must invert dwCRC to get the correct answer
300 *pdwICV = cpu_to_le32(~dwICV);
301 // RC4 encryption
302 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
303 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
304 //=======================================================================
305 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
306 //=======================================================================
307 //Append ICV after payload
308 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
52a7e64b 309 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
92b96797
FB
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, TKIP_KEY_LEN);
314 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
315 //=======================================================================
316 }
317}
318
f115e76a
MP
319static u16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
320{
321 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
322 [rate % MAX_RATE]);
323}
324
92b96797
FB
325/*byPktType : PK_TYPE_11A 0
326 PK_TYPE_11B 1
327 PK_TYPE_11GB 2
328 PK_TYPE_11GA 3
329*/
d56131de
MP
330static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
331 u32 cbFrameLength, u16 wRate, int bNeedAck)
92b96797 332{
d56131de 333 u32 uDataTime, uAckTime;
92b96797
FB
334
335 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
336 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
3eaca0d2 337 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopCCKBasicRate);
92b96797 338 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
3eaca0d2 339 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (u16)pDevice->byTopOFDMBasicRate);
92b96797
FB
340 }
341
342 if (bNeedAck) {
343 return (uDataTime + pDevice->uSIFS + uAckTime);
344 }
345 else {
346 return uDataTime;
347 }
348}
349
9c3806d5
MP
350static u16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
351 u32 frame_length, u16 rate, int need_ack)
352{
353 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
354 frame_length, rate, need_ack));
355}
356
92b96797 357//byFreqType: 0=>5GHZ 1=>2.4GHZ
cfabe4b4 358static u16 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
d56131de 359 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
92b96797 360{
d56131de 361 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
92b96797
FB
362
363 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
364
92b96797
FB
365 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
366 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
367 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
368 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
369 }
370 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
371 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
372 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
373 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
374 }
375 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
376 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
377 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
378 }
379 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
380 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
381 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
382 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
383 return uRrvTime;
384 }
385
386 //RTSRrvTime
387 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
cfabe4b4 388 return cpu_to_le16((u16)uRrvTime);
92b96797
FB
389}
390
391//byFreqType 0: 5GHz, 1:2.4Ghz
6b5ad9d2
MP
392static u16 s_uGetDataDuration(struct vnt_private *pDevice,
393 u8 byPktType, int bNeedAck)
92b96797 394{
0005cb00 395 u32 uAckTime = 0;
92b96797 396
b02ccd59 397 if (bNeedAck) {
6b5ad9d2 398 if (byPktType == PK_TYPE_11B)
b02ccd59
MP
399 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
400 byPktType, 14, pDevice->byTopCCKBasicRate);
401 else
402 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
403 byPktType, 14, pDevice->byTopOFDMBasicRate);
d5005955 404 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
b02ccd59 405 }
92b96797 406
92b96797
FB
407 return 0;
408}
409
92b96797 410//byFreqType: 0=>5GHZ 1=>2.4GHZ
e34f9dbe 411static u16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
d56131de
MP
412 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
413 u8 byFBOption)
92b96797 414{
d56131de 415 u32 uCTSTime = 0, uDurTime = 0;
92b96797 416
92b96797
FB
417 switch (byDurType) {
418
419 case RTSDUR_BB: //RTSDuration_bb
420 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
421 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
422 break;
423
424 case RTSDUR_BA: //RTSDuration_ba
425 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
426 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
427 break;
428
429 case RTSDUR_AA: //RTSDuration_aa
430 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
431 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
432 break;
433
434 case CTSDUR_BA: //CTSDuration_ba
435 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
436 break;
437
438 case RTSDUR_BA_F0: //RTSDuration_ba_f0
439 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
440 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
441 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
442 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
443 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
444 }
445 break;
446
447 case RTSDUR_AA_F0: //RTSDuration_aa_f0
448 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
449 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
450 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
451 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
452 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
453 }
454 break;
455
456 case RTSDUR_BA_F1: //RTSDuration_ba_f1
457 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
458 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
459 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
460 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
461 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
462 }
463 break;
464
465 case RTSDUR_AA_F1: //RTSDuration_aa_f1
466 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
467 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
468 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
469 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
470 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
471 }
472 break;
473
474 case CTSDUR_BA_F0: //CTSDuration_ba_f0
475 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
476 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
477 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
478 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
479 }
480 break;
481
482 case CTSDUR_BA_F1: //CTSDuration_ba_f1
483 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
484 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
485 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
486 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
487 }
488 break;
489
490 default:
491 break;
492 }
493
e34f9dbe 494 return cpu_to_le16((u16)uDurTime);
92b96797
FB
495}
496
d56131de
MP
497static u32 s_uFillDataHead(struct vnt_private *pDevice,
498 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
ab01fedc 499 u32 uDMAIdx, int bNeedAck, u8 byFBOption)
92b96797
FB
500{
501
502 if (pTxDataHead == NULL) {
503 return 0;
504 }
505
506 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
92b96797 507 if (byFBOption == AUTO_FB_NONE) {
7e60a3de
MP
508 struct vnt_tx_datahead_g *pBuf =
509 (struct vnt_tx_datahead_g *)pTxDataHead;
92b96797 510 //Get SignalField,ServiceField,Length
aed387c7
MP
511 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
512 byPktType, &pBuf->a);
513 BBvCalculateParameter(pDevice, cbFrameLength,
514 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
92b96797 515 //Get Duration and TimeStamp
6b5ad9d2 516 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
3ed210ef 517 byPktType, bNeedAck);
6b5ad9d2 518 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
3ed210ef 519 PK_TYPE_11B, bNeedAck);
92b96797 520
f115e76a
MP
521 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
522 wCurrentRate);
523 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
524 pDevice->byTopCCKBasicRate);
92b96797
FB
525 return (pBuf->wDuration_a);
526 } else {
527 // Auto Fallback
7c05c545
MP
528 struct vnt_tx_datahead_g_fb *pBuf =
529 (struct vnt_tx_datahead_g_fb *)pTxDataHead;
92b96797 530 //Get SignalField,ServiceField,Length
aed387c7
MP
531 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
532 byPktType, &pBuf->a);
533 BBvCalculateParameter(pDevice, cbFrameLength,
534 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
92b96797 535 //Get Duration and TimeStamp
6b5ad9d2 536 pBuf->wDuration_a = s_uGetDataDuration(pDevice,
3ed210ef 537 byPktType, bNeedAck);
6b5ad9d2 538 pBuf->wDuration_b = s_uGetDataDuration(pDevice,
3ed210ef 539 PK_TYPE_11B, bNeedAck);
d5005955 540 pBuf->wDuration_a_f0 = s_uGetDataDuration(pDevice,
6b5ad9d2 541 byPktType, bNeedAck);
d5005955 542 pBuf->wDuration_a_f1 = s_uGetDataDuration(pDevice,
6b5ad9d2 543 byPktType, bNeedAck);
f115e76a
MP
544 pBuf->wTimeStampOff_a = vnt_time_stamp_off(pDevice,
545 wCurrentRate);
546 pBuf->wTimeStampOff_b = vnt_time_stamp_off(pDevice,
547 pDevice->byTopCCKBasicRate);
92b96797
FB
548 return (pBuf->wDuration_a);
549 } //if (byFBOption == AUTO_FB_NONE)
92b96797
FB
550 }
551 else if (byPktType == PK_TYPE_11A) {
c921cc8c 552 if (byFBOption != AUTO_FB_NONE) {
1da4ee20
MP
553 struct vnt_tx_datahead_a_fb *pBuf =
554 (struct vnt_tx_datahead_a_fb *)pTxDataHead;
92b96797 555 //Get SignalField,ServiceField,Length
aed387c7
MP
556 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
557 byPktType, &pBuf->a);
92b96797 558 //Get Duration and TimeStampOff
6b5ad9d2 559 pBuf->wDuration = s_uGetDataDuration(pDevice,
3ed210ef 560 byPktType, bNeedAck);
d5005955 561 pBuf->wDuration_f0 = s_uGetDataDuration(pDevice,
6b5ad9d2 562 byPktType, bNeedAck);
d5005955 563 pBuf->wDuration_f1 = s_uGetDataDuration(pDevice,
6b5ad9d2 564 byPktType, bNeedAck);
f115e76a
MP
565 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
566 wCurrentRate);
92b96797
FB
567 return (pBuf->wDuration);
568 } else {
558becf1
MP
569 struct vnt_tx_datahead_ab *pBuf =
570 (struct vnt_tx_datahead_ab *)pTxDataHead;
92b96797 571 //Get SignalField,ServiceField,Length
aed387c7
MP
572 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
573 byPktType, &pBuf->ab);
92b96797 574 //Get Duration and TimeStampOff
6b5ad9d2 575 pBuf->wDuration = s_uGetDataDuration(pDevice,
3ed210ef 576 byPktType, bNeedAck);
f115e76a
MP
577 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
578 wCurrentRate);
92b96797
FB
579 return (pBuf->wDuration);
580 }
581 }
582 else if (byPktType == PK_TYPE_11B) {
558becf1
MP
583 struct vnt_tx_datahead_ab *pBuf =
584 (struct vnt_tx_datahead_ab *)pTxDataHead;
92b96797 585 //Get SignalField,ServiceField,Length
aed387c7
MP
586 BBvCalculateParameter(pDevice, cbFrameLength, wCurrentRate,
587 byPktType, &pBuf->ab);
92b96797 588 //Get Duration and TimeStampOff
6b5ad9d2 589 pBuf->wDuration = s_uGetDataDuration(pDevice,
3ed210ef 590 byPktType, bNeedAck);
f115e76a
MP
591 pBuf->wTimeStampOff = vnt_time_stamp_off(pDevice,
592 wCurrentRate);
92b96797
FB
593 return (pBuf->wDuration);
594 }
595 return 0;
596}
597
5e67ee49
MP
598static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
599 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
600 u16 duration)
601{
602 rts->duration = duration;
603 rts->frame_control = TYPE_CTL_RTS;
604
605 if (priv->eOPMode == OP_MODE_ADHOC || priv->eOPMode == OP_MODE_AP)
606 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
607 else
608 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
609
610 if (priv->eOPMode == OP_MODE_AP)
611 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
612 else
613 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
614
615 return 0;
616}
617
618static int vnt_rxtx_rts_g_head(struct vnt_private *priv,
619 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
620 u8 pkt_type, u32 frame_len, int need_ack,
621 u16 current_rate, u8 fb_option)
622{
623 u16 rts_frame_len = 20;
624
625 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
626 PK_TYPE_11B, &buf->b);
627 BBvCalculateParameter(priv, rts_frame_len,
628 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
629
630 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
631 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
632 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
633 pkt_type, current_rate, need_ack, fb_option);
634 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
635 pkt_type, current_rate, need_ack, fb_option);
636
637 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
638
639 return 0;
640}
641
ec91713a
MP
642static int vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
643 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
644 u8 pkt_type, u32 frame_len, int need_ack,
645 u16 current_rate, u8 fb_option)
646{
647 u16 rts_frame_len = 20;
648
649 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
650 PK_TYPE_11B, &buf->b);
651 BBvCalculateParameter(priv, rts_frame_len,
652 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
653
654
655 buf->wDuration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
656 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
657 buf->wDuration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
658 pkt_type, current_rate, need_ack, fb_option);
659 buf->wDuration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
660 pkt_type, current_rate, need_ack, fb_option);
661
662
663 buf->wRTSDuration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
664 frame_len, pkt_type, current_rate, need_ack, fb_option);
665 buf->wRTSDuration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
666 frame_len, pkt_type, current_rate, need_ack, fb_option);
667 buf->wRTSDuration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
668 frame_len, pkt_type, current_rate, need_ack, fb_option);
669 buf->wRTSDuration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
670 frame_len, pkt_type, current_rate, need_ack, fb_option);
671
672 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration_aa);
673
674 return 0;
675}
676
1712633d
MP
677static int vnt_rxtx_rts_ab_head(struct vnt_private *priv,
678 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
679 u8 pkt_type, u32 frame_len, int need_ack,
680 u16 current_rate, u8 fb_option)
681{
682 u16 rts_frame_len = 20;
683
684 BBvCalculateParameter(priv, rts_frame_len,
685 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
686
687 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
688 pkt_type, current_rate, need_ack, fb_option);
689
690 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
691
692 return 0;
693}
694
9d2578c1
MP
695static int vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
696 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
697 u8 pkt_type, u32 frame_len, int need_ack,
698 u16 current_rate, u8 fb_option)
699{
700 u16 rts_frame_len = 20;
701
702 BBvCalculateParameter(priv, rts_frame_len,
703 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
704
705 buf->wDuration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
706 pkt_type, current_rate, need_ack, fb_option);
707
708 buf->wRTSDuration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
709 frame_len, pkt_type, current_rate, need_ack, fb_option);
710
711 buf->wRTSDuration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
712 frame_len, pkt_type, current_rate, need_ack, fb_option);
713
714 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->wDuration);
715
716 return 0;
717}
718
d56131de 719static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
5fb8e412 720 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
ceb8c5da 721 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
92b96797 722{
92b96797 723
13fe62ae
MP
724 if (!head)
725 return;
92b96797 726
9d5829bf
MP
727 /* Note: So far RTSHead doesn't appear in ATIM
728 * & Beacom DMA, so we don't need to take them
729 * into account.
730 * Otherwise, we need to modified codes for them.
731 */
0bddd303
MP
732 switch (byPktType) {
733 case PK_TYPE_11GB:
734 case PK_TYPE_11GA:
9d5829bf
MP
735 if (byFBOption == AUTO_FB_NONE)
736 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
5e67ee49
MP
737 psEthHeader, byPktType, cbFrameLength,
738 bNeedAck, wCurrentRate, byFBOption);
9d5829bf
MP
739 else
740 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
ec91713a
MP
741 psEthHeader, byPktType, cbFrameLength,
742 bNeedAck, wCurrentRate, byFBOption);
0bddd303
MP
743 break;
744 case PK_TYPE_11A:
2b83ebd0 745 if (byFBOption) {
9d5829bf 746 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
9d2578c1
MP
747 psEthHeader, byPktType, cbFrameLength,
748 bNeedAck, wCurrentRate, byFBOption);
2b83ebd0
MP
749 break;
750 }
0bddd303 751 case PK_TYPE_11B:
9d5829bf 752 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
1712633d
MP
753 psEthHeader, byPktType, cbFrameLength,
754 bNeedAck, wCurrentRate, byFBOption);
9d5829bf 755 }
92b96797
FB
756}
757
d56131de 758static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
5fb8e412
MP
759 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
760 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
92b96797 761{
d56131de 762 u32 uCTSFrameLen = 14;
92b96797 763
27df3ebf
MP
764 if (!head)
765 return;
92b96797 766
c921cc8c
MP
767 if (byFBOption != AUTO_FB_NONE) {
768 /* Auto Fall back */
27df3ebf 769 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
aed387c7
MP
770 /* Get SignalField,ServiceField,Length */
771 BBvCalculateParameter(pDevice, uCTSFrameLen,
772 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe
MP
773 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
774 cbFrameLength, byPktType,
775 wCurrentRate, bNeedAck, byFBOption);
776 /* Get CTSDuration_ba_f0 */
777 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
778 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
779 bNeedAck, byFBOption);
780 /* Get CTSDuration_ba_f1 */
781 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
782 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
783 bNeedAck, byFBOption);
14840cdd
MP
784 /* Get CTS Frame body */
785 pBuf->data.duration = pBuf->wDuration_ba;
786 pBuf->data.frame_control = TYPE_CTL_CTS;
787 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
c921cc8c 788 } else {
27df3ebf 789 struct vnt_cts *pBuf = &head->cts_g;
aed387c7
MP
790 /* Get SignalField,ServiceField,Length */
791 BBvCalculateParameter(pDevice, uCTSFrameLen,
792 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe
MP
793 /* Get CTSDuration_ba */
794 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
795 CTSDUR_BA, cbFrameLength, byPktType,
796 wCurrentRate, bNeedAck, byFBOption);
14840cdd
MP
797 /*Get CTS Frame body*/
798 pBuf->data.duration = pBuf->wDuration_ba;
799 pBuf->data.frame_control = TYPE_CTL_CTS;
800 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
92b96797 801 }
92b96797
FB
802}
803
92b96797
FB
804/*+
805 *
806 * Description:
807 * Generate FIFO control for MAC & Baseband controller
808 *
809 * Parameters:
810 * In:
811 * pDevice - Pointer to adpater
812 * pTxDataHead - Transmit Data Buffer
813 * pTxBufHead - pTxBufHead
814 * pvRrvTime - pvRrvTime
815 * pvRTS - RTS Buffer
816 * pCTS - CTS Buffer
817 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
818 * bNeedACK - If need ACK
819 * uDMAIdx - DMA Index
820 * Out:
821 * none
822 *
823 * Return Value: none
824 *
825-*/
cc856e61 826
d56131de
MP
827static void s_vGenerateTxParameter(struct vnt_private *pDevice,
828 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
351c7dc3 829 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
f46142b0 830 struct ethhdr *psEthHeader, bool need_rts)
92b96797 831{
5fb8e412 832 union vnt_tx_data_head *head = rts_cts;
d56131de
MP
833 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
834 u16 wFifoCtl;
d56131de 835 u8 byFBOption = AUTO_FB_NONE;
92b96797
FB
836
837 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
838 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
839 pFifoHead->wReserved = wCurrentRate;
840 wFifoCtl = pFifoHead->wFIFOCtl;
841
92b96797
FB
842 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
843 byFBOption = AUTO_FB_0;
844 }
845 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
846 byFBOption = AUTO_FB_1;
847 }
848
2dc22d5a
MP
849 if (!pvRrvTime)
850 return;
851
92b96797
FB
852 if (pDevice->bLongHeader)
853 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
854
855 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
f46142b0 856 if (need_rts) {
92b96797 857 //Fill RsvTime
6398a59b
MP
858 struct vnt_rrv_time_rts *pBuf =
859 (struct vnt_rrv_time_rts *)pvRrvTime;
cfabe4b4
MP
860 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
861 byPktType, cbFrameSize, wCurrentRate);
862 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
863 byPktType, cbFrameSize, wCurrentRate);
864 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
865 byPktType, cbFrameSize, wCurrentRate);
9c3806d5
MP
866 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
867 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
868 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
869 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
870 bNeedACK);
351c7dc3 871 /* Fill RTS */
5fb8e412 872 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
351c7dc3 873 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
92b96797
FB
874 }
875 else {//RTS_needless, PCF mode
92b96797 876 //Fill RsvTime
4f990057
MP
877 struct vnt_rrv_time_cts *pBuf =
878 (struct vnt_rrv_time_cts *)pvRrvTime;
9c3806d5
MP
879 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
880 cbFrameSize, wCurrentRate, bNeedACK);
881 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
882 PK_TYPE_11B, cbFrameSize,
883 pDevice->byTopCCKBasicRate, bNeedACK);
cfabe4b4
MP
884 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
885 byPktType, cbFrameSize, wCurrentRate);
351c7dc3 886 /* Fill CTS */
5fb8e412 887 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, head,
351c7dc3 888 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
92b96797
FB
889 }
890 }
891 else if (byPktType == PK_TYPE_11A) {
f46142b0 892 if (need_rts) {
92b96797 893 //Fill RsvTime
976467d3
MP
894 struct vnt_rrv_time_ab *pBuf =
895 (struct vnt_rrv_time_ab *)pvRrvTime;
cfabe4b4
MP
896 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
897 byPktType, cbFrameSize, wCurrentRate);
9c3806d5
MP
898 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
899 cbFrameSize, wCurrentRate, bNeedACK);
351c7dc3 900 /* Fill RTS */
5fb8e412 901 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
351c7dc3 902 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
f46142b0 903 } else {
92b96797 904 //Fill RsvTime
976467d3
MP
905 struct vnt_rrv_time_ab *pBuf =
906 (struct vnt_rrv_time_ab *)pvRrvTime;
9c3806d5
MP
907 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
908 cbFrameSize, wCurrentRate, bNeedACK);
92b96797
FB
909 }
910 }
911 else if (byPktType == PK_TYPE_11B) {
f46142b0 912 if (need_rts) {
92b96797 913 //Fill RsvTime
976467d3
MP
914 struct vnt_rrv_time_ab *pBuf =
915 (struct vnt_rrv_time_ab *)pvRrvTime;
cfabe4b4
MP
916 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
917 byPktType, cbFrameSize, wCurrentRate);
9c3806d5
MP
918 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
919 cbFrameSize, wCurrentRate, bNeedACK);
351c7dc3 920 /* Fill RTS */
5fb8e412 921 s_vFillRTSHead(pDevice, byPktType, head, cbFrameSize,
351c7dc3 922 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
92b96797
FB
923 }
924 else { //RTS_needless, non PCF mode
925 //Fill RsvTime
976467d3
MP
926 struct vnt_rrv_time_ab *pBuf =
927 (struct vnt_rrv_time_ab *)pvRrvTime;
9c3806d5
MP
928 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
929 cbFrameSize, wCurrentRate, bNeedACK);
92b96797
FB
930 }
931 }
932 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
933}
934/*
b902fbfe 935 u8 * pbyBuffer,//point to pTxBufHead
3eaca0d2 936 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
cc856e61 937 unsigned int cbFragmentSize,//Hdr+payoad+FCS
92b96797
FB
938*/
939
d56131de 940static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
d0a2b8fa
MP
941 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
942 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
943 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
944 u32 *pcbHeaderLen, u32 *pcbTotalLen)
92b96797 945{
d56131de
MP
946 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
947 u32 cbFrameSize, cbFrameBodySize;
d56131de
MP
948 u32 cb802_1_H_len;
949 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
950 u32 cbFCSlen = 4, cbMICHDR = 0;
f46142b0
MP
951 int bNeedACK;
952 bool bRTS = false;
d56131de
MP
953 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
954 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
955 u8 abySNAP_Bridgetunnel[ETH_ALEN]
956 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
957 u32 uDuration;
958 u32 cbHeaderLength = 0, uPadding = 0;
959 void *pvRrvTime;
5a5d6a80 960 struct vnt_mic_hdr *pMICHDR;
351c7dc3 961 void *rts_cts = NULL;
d56131de
MP
962 void *pvTxDataHd;
963 u8 byFBOption = AUTO_FB_NONE, byFragType;
964 u16 wTxBufSize;
4235f72f 965 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
d56131de 966 u32 *pdwMIC_L, *pdwMIC_R;
e269fc2d 967 int bSoftWEP = false;
d56131de 968
351c7dc3 969 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
92b96797 970
e2efba76 971 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
4e9b5e2b
AM
972 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
973 bSoftWEP = true; /* WEP 256 */
e2efba76 974 }
92b96797 975
92b96797 976 // Get pkt type
ceb8c5da 977 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
92b96797
FB
978 if (pDevice->dwDiagRefCount == 0) {
979 cb802_1_H_len = 8;
980 } else {
981 cb802_1_H_len = 2;
982 }
983 } else {
984 cb802_1_H_len = 0;
985 }
986
21ec51f3 987 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
92b96797
FB
988
989 //Set packet type
3eaca0d2 990 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
92b96797
FB
991
992 if (pDevice->dwDiagRefCount != 0) {
e269fc2d 993 bNeedACK = false;
92b96797
FB
994 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
995 } else { //if (pDevice->dwDiagRefCount != 0) {
22040bbf
AM
996 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
997 (pDevice->eOPMode == OP_MODE_AP)) {
ceb8c5da 998 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
e269fc2d 999 bNeedACK = false;
22040bbf
AM
1000 pTxBufHead->wFIFOCtl =
1001 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1002 } else {
4e9b5e2b 1003 bNeedACK = true;
22040bbf
AM
1004 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1005 }
92b96797
FB
1006 }
1007 else {
1008 // MSDUs in Infra mode always need ACK
4e9b5e2b 1009 bNeedACK = true;
92b96797
FB
1010 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1011 }
1012 } //if (pDevice->dwDiagRefCount != 0) {
1013
1014 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1015
1016 //Set FIFOCTL_LHEAD
1017 if (pDevice->bLongHeader)
1018 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1019
92b96797
FB
1020 //Set FRAGCTL_MACHDCNT
1021 if (pDevice->bLongHeader) {
1022 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1023 } else {
1024 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1025 }
3eaca0d2 1026 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
92b96797
FB
1027
1028 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1029 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1030 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1031 }
1032
1033 //Set Auto Fallback Ctl
1034 if (wCurrentRate >= RATE_18M) {
1035 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1036 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1037 byFBOption = AUTO_FB_0;
1038 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1039 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1040 byFBOption = AUTO_FB_1;
1041 }
1042 }
1043
4e9b5e2b 1044 if (bSoftWEP != true) {
92b96797
FB
1045 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1046 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1047 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1048 }
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;
1052 }
1053 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1054 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1055 }
1056 }
1057 }
1058
92b96797
FB
1059 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1060 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1061 cbIVlen = 4;
1062 cbICVlen = 4;
1063 }
1064 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1065 cbIVlen = 8;//IV+ExtIV
1066 cbMIClen = 8;
1067 cbICVlen = 4;
1068 }
1069 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1070 cbIVlen = 8;//RSN Header
1071 cbICVlen = 8;//MIC
5a5d6a80 1072 cbMICHDR = sizeof(struct vnt_mic_hdr);
92b96797 1073 }
e269fc2d 1074 if (bSoftWEP == false) {
92b96797
FB
1075 //MAC Header should be padding 0 to DW alignment.
1076 uPadding = 4 - (cbMACHdLen%4);
1077 uPadding %= 4;
1078 }
1079 }
1080
1081 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1082
e269fc2d
AM
1083 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1084 bRTS = false;
92b96797 1085 } else {
4e9b5e2b 1086 bRTS = true;
92b96797
FB
1087 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1088 }
1089
b902fbfe 1090 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
92b96797
FB
1091 wTxBufSize = sizeof(STxBufHead);
1092 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1093 if (byFBOption == AUTO_FB_NONE) {
4e9b5e2b 1094 if (bRTS == true) {//RTS_need
6398a59b
MP
1095 pvRrvTime = (struct vnt_rrv_time_rts *)
1096 (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 1097 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
6398a59b 1098 sizeof(struct vnt_rrv_time_rts));
351c7dc3 1099 rts_cts = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
6398a59b 1100 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
7e60a3de
MP
1101 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1102 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1103 cbMICHDR + sizeof(struct vnt_rts_g));
6398a59b 1104 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
c521cb58 1105 cbMICHDR + sizeof(struct vnt_rts_g) +
7e60a3de 1106 sizeof(struct vnt_tx_datahead_g);
92b96797
FB
1107 }
1108 else { //RTS_needless
4f990057
MP
1109 pvRrvTime = (struct vnt_rrv_time_cts *)
1110 (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 1111 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1112 sizeof(struct vnt_rrv_time_cts));
351c7dc3 1113 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1114 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
7e60a3de
MP
1115 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1116 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1117 cbMICHDR + sizeof(struct vnt_cts));
4f990057
MP
1118 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1119 cbMICHDR + sizeof(struct vnt_cts) +
7e60a3de 1120 sizeof(struct vnt_tx_datahead_g);
92b96797
FB
1121 }
1122 } else {
1123 // Auto Fall Back
4e9b5e2b 1124 if (bRTS == true) {//RTS_need
6398a59b
MP
1125 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1126 wTxBufSize);
5a5d6a80 1127 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
6398a59b 1128 sizeof(struct vnt_rrv_time_rts));
351c7dc3 1129 rts_cts = (struct vnt_rts_g_fb *)(pbyTxBufferAddr + wTxBufSize +
6398a59b 1130 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
7c05c545
MP
1131 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1132 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1133 cbMICHDR + sizeof(struct vnt_rts_g_fb));
6398a59b
MP
1134 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1135 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
7c05c545 1136 sizeof(struct vnt_tx_datahead_g_fb);
92b96797 1137 }
e269fc2d 1138 else if (bRTS == false) { //RTS_needless
4f990057
MP
1139 pvRrvTime = (struct vnt_rrv_time_cts *)
1140 (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 1141 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1142 sizeof(struct vnt_rrv_time_cts));
351c7dc3 1143 rts_cts = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1144 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
7c05c545 1145 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
4f990057
MP
1146 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1147 cbMICHDR + sizeof(struct vnt_cts_fb));
1148 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
f0c5ba28 1149 cbMICHDR + sizeof(struct vnt_cts_fb) +
7c05c545 1150 sizeof(struct vnt_tx_datahead_g_fb);
92b96797
FB
1151 }
1152 } // Auto Fall Back
1153 }
1154 else {//802.11a/b packet
1155 if (byFBOption == AUTO_FB_NONE) {
4e9b5e2b 1156 if (bRTS == true) {//RTS_need
976467d3
MP
1157 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1158 wTxBufSize);
5a5d6a80 1159 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
976467d3 1160 sizeof(struct vnt_rrv_time_ab));
351c7dc3 1161 rts_cts = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
976467d3 1162 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
558becf1
MP
1163 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1164 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
c521cb58 1165 sizeof(struct vnt_rts_ab));
976467d3
MP
1166 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1167 cbMICHDR + sizeof(struct vnt_rts_ab) +
558becf1 1168 sizeof(struct vnt_tx_datahead_ab);
92b96797 1169 }
e269fc2d 1170 else if (bRTS == false) { //RTS_needless, no MICHDR
976467d3
MP
1171 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1172 wTxBufSize);
5a5d6a80 1173 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
976467d3 1174 sizeof(struct vnt_rrv_time_ab));
558becf1
MP
1175 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1176 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
976467d3 1177 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
558becf1 1178 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1179 }
1180 } else {
1181 // Auto Fall Back
4e9b5e2b 1182 if (bRTS == true) {//RTS_need
976467d3
MP
1183 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1184 wTxBufSize);
5a5d6a80 1185 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
976467d3 1186 sizeof(struct vnt_rrv_time_ab));
351c7dc3 1187 rts_cts = (struct vnt_rts_a_fb *)(pbyTxBufferAddr + wTxBufSize +
976467d3 1188 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1da4ee20
MP
1189 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1190 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
c521cb58 1191 sizeof(struct vnt_rts_a_fb));
976467d3
MP
1192 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1193 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
1da4ee20 1194 sizeof(struct vnt_tx_datahead_a_fb);
92b96797 1195 }
e269fc2d 1196 else if (bRTS == false) { //RTS_needless
976467d3
MP
1197 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1198 wTxBufSize);
5a5d6a80 1199 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
976467d3 1200 sizeof(struct vnt_rrv_time_ab));
1da4ee20
MP
1201 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1202 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
976467d3 1203 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1da4ee20 1204 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
92b96797
FB
1205 }
1206 } // Auto Fall Back
1207 }
1208
b902fbfe
AM
1209 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1210 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1211 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
92b96797 1212
92b96797
FB
1213 //=========================
1214 // No Fragmentation
1215 //=========================
1216 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1217 byFragType = FRAGCTL_NONFRAG;
1218 //uDMAIdx = TYPE_AC0DMA;
1219 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1220
92b96797 1221 //Fill FIFO,RrvTime,RTS,and CTS
8611a29a 1222 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
351c7dc3 1223 (void *)pbyTxBufferAddr, pvRrvTime, rts_cts,
f46142b0 1224 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
92b96797
FB
1225 //Fill DataHead
1226 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
ab01fedc 1227 byFBOption);
92b96797 1228 // Generate TX MAC Header
3eaca0d2 1229 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
92b96797
FB
1230 byFragType, uDMAIdx, 0);
1231
4e9b5e2b 1232 if (bNeedEncryption == true) {
92b96797 1233 //Fill TXKEY
b902fbfe 1234 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
ec37d8b6 1235 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
92b96797
FB
1236
1237 if (pDevice->bEnableHostWEP) {
1238 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1239 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1240 }
1241 }
1242
1243 // 802.1H
ceb8c5da 1244 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
203e4615 1245 if (pDevice->dwDiagRefCount == 0) {
ceb8c5da
AM
1246 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1247 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
b902fbfe 1248 memcpy((u8 *) (pbyPayloadHead),
203e4615 1249 abySNAP_Bridgetunnel, 6);
92b96797 1250 } else {
b902fbfe 1251 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
92b96797 1252 }
b902fbfe 1253 pbyType = (u8 *) (pbyPayloadHead + 6);
ceb8c5da 1254 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
92b96797 1255 } else {
ceb8c5da 1256 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
92b96797
FB
1257
1258 }
1259
1260 }
1261
92b96797
FB
1262 if (pPacket != NULL) {
1263 // Copy the Packet into a tx Buffer
3e362598 1264 memcpy((pbyPayloadHead + cb802_1_H_len),
21ec51f3
CC
1265 (pPacket + ETH_HLEN),
1266 uSkbPacketLen - ETH_HLEN
92b96797
FB
1267 );
1268
1269 } else {
1270 // while bRelayPacketSend psEthHeader is point to header+payload
b902fbfe 1271 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
92b96797
FB
1272 }
1273
4e9b5e2b 1274 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
92b96797
FB
1275
1276 ///////////////////////////////////////////////////////////////////
1277
14c5ef57
MP
1278 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1279 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1280 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1281 }
92b96797 1282 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
52a7e64b
AM
1283 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1284 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
92b96797
FB
1285 }
1286 else {
52a7e64b
AM
1287 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1288 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
92b96797
FB
1289 }
1290 // DO Software Michael
1291 MIC_vInit(dwMICKey0, dwMICKey1);
ceb8c5da 1292 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
92b96797 1293 dwMIC_Priority = 0;
b902fbfe 1294 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
b4dc03af
MP
1295 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1296 dwMICKey0, dwMICKey1);
92b96797
FB
1297
1298 ///////////////////////////////////////////////////////////////////
1299
1300 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1301 //for (ii = 0; ii < cbFrameBodySize; ii++) {
b902fbfe 1302 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
92b96797
FB
1303 //}
1304 //DBG_PRN_GRP12(("\n\n\n"));
1305
1306 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1307
52a7e64b
AM
1308 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1309 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
92b96797
FB
1310
1311 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1312 MIC_vUnInit();
1313
4e9b5e2b 1314 if (pDevice->bTxMICFail == true) {
92b96797
FB
1315 *pdwMIC_L = 0;
1316 *pdwMIC_R = 0;
e269fc2d 1317 pDevice->bTxMICFail = false;
92b96797
FB
1318 }
1319 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1320 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1321 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1322 }
1323
4e9b5e2b 1324 if (bSoftWEP == true) {
92b96797 1325
3eaca0d2 1326 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
92b96797 1327
4e9b5e2b
AM
1328 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1329 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1330 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
92b96797
FB
1331 cbFrameSize -= cbICVlen;
1332 }
1333
92b96797 1334 cbFrameSize -= cbFCSlen;
92b96797
FB
1335
1336 *pcbHeaderLen = cbHeaderLength;
1337 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1338
92b96797 1339 //Set FragCtl in TxBufferHead
3eaca0d2 1340 pTxBufHead->wFragCtl |= (u16)byFragType;
92b96797 1341
4e9b5e2b 1342 return true;
92b96797
FB
1343
1344}
1345
92b96797
FB
1346/*+
1347 *
1348 * Description:
1349 * Translate 802.3 to 802.11 header
1350 *
1351 * Parameters:
1352 * In:
a0a1f61a 1353 * pDevice - Pointer to adapter
92b96797
FB
1354 * dwTxBufferAddr - Transmit Buffer
1355 * pPacket - Packet from upper layer
1356 * cbPacketSize - Transmit Data Length
1357 * Out:
1358 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1359 * pcbAppendPayload - size of append payload for 802.1H translation
1360 *
1361 * Return Value: none
1362 *
1363-*/
1364
d56131de 1365static void s_vGenerateMACHeader(struct vnt_private *pDevice,
ceb8c5da 1366 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
d56131de 1367 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
92b96797 1368{
1cac4a4b 1369 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
92b96797 1370
c921cc8c 1371 pMACHeader->frame_control = TYPE_802_11_DATA;
92b96797
FB
1372
1373 if (pDevice->eOPMode == OP_MODE_AP) {
1cac4a4b 1374 memcpy(&(pMACHeader->addr1[0]),
ceb8c5da 1375 &(psEthHeader->h_dest[0]),
9a0e756c 1376 ETH_ALEN);
1cac4a4b
AM
1377 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1378 memcpy(&(pMACHeader->addr3[0]),
ceb8c5da 1379 &(psEthHeader->h_source[0]),
9a0e756c 1380 ETH_ALEN);
1cac4a4b 1381 pMACHeader->frame_control |= FC_FROMDS;
9a0e756c
AM
1382 } else {
1383 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1cac4a4b 1384 memcpy(&(pMACHeader->addr1[0]),
ceb8c5da 1385 &(psEthHeader->h_dest[0]),
9a0e756c 1386 ETH_ALEN);
1cac4a4b 1387 memcpy(&(pMACHeader->addr2[0]),
ceb8c5da 1388 &(psEthHeader->h_source[0]),
9a0e756c 1389 ETH_ALEN);
1cac4a4b 1390 memcpy(&(pMACHeader->addr3[0]),
9a0e756c
AM
1391 &(pDevice->abyBSSID[0]),
1392 ETH_ALEN);
1393 } else {
1cac4a4b 1394 memcpy(&(pMACHeader->addr3[0]),
ceb8c5da 1395 &(psEthHeader->h_dest[0]),
9a0e756c 1396 ETH_ALEN);
1cac4a4b 1397 memcpy(&(pMACHeader->addr2[0]),
ceb8c5da 1398 &(psEthHeader->h_source[0]),
9a0e756c 1399 ETH_ALEN);
1cac4a4b 1400 memcpy(&(pMACHeader->addr1[0]),
9a0e756c
AM
1401 &(pDevice->abyBSSID[0]),
1402 ETH_ALEN);
1cac4a4b 1403 pMACHeader->frame_control |= FC_TODS;
92b96797
FB
1404 }
1405 }
1406
1407 if (bNeedEncrypt)
1cac4a4b 1408 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
92b96797 1409
1cac4a4b 1410 pMACHeader->duration_id = cpu_to_le16(wDuration);
92b96797
FB
1411
1412 if (pDevice->bLongHeader) {
1413 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1cac4a4b 1414 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
3e362598 1415 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
92b96797 1416 }
1cac4a4b 1417 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1418
1419 //Set FragNumber in Sequence Control
1cac4a4b 1420 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
92b96797
FB
1421
1422 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1423 pDevice->wSeqCounter++;
1424 if (pDevice->wSeqCounter > 0x0fff)
1425 pDevice->wSeqCounter = 0;
1426 }
1427
1428 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1cac4a4b 1429 pMACHeader->frame_control |= FC_MOREFRAG;
92b96797
FB
1430 }
1431}
1432
92b96797
FB
1433/*+
1434 *
1435 * Description:
1436 * Request instructs a MAC to transmit a 802.11 management packet through
1437 * the adapter onto the medium.
1438 *
1439 * Parameters:
1440 * In:
1441 * hDeviceContext - Pointer to the adapter
1442 * pPacket - A pointer to a descriptor for the packet to transmit
1443 * Out:
1444 * none
1445 *
e269fc2d 1446 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
92b96797
FB
1447 *
1448-*/
1449
d56131de
MP
1450CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1451 struct vnt_tx_mgmt *pPacket)
92b96797 1452{
d56131de 1453 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 1454 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
1455 PSTxBufHead pTxBufHead;
1456 PUSB_SEND_CONTEXT pContext;
1cac4a4b 1457 struct ieee80211_hdr *pMACHeader;
ceb8c5da 1458 struct ethhdr sEthHeader;
d56131de 1459 u8 byPktType, *pbyTxBufferAddr;
351c7dc3
MP
1460 void *rts_cts = NULL;
1461 void *pvTxDataHd, *pvRrvTime, *pMICHDR;
d56131de 1462 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
e269fc2d 1463 int bNeedACK, bIsPSPOLL = false;
d56131de
MP
1464 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1465 u32 uPadding = 0;
1466 u16 wTxBufSize;
1467 u32 cbMacHdLen;
1468 u16 wCurrentRate = RATE_1M;
92b96797 1469
92b96797
FB
1470 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1471
1472 if (NULL == pContext) {
1473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1474 return CMD_STATUS_RESOURCES;
1475 }
1476
f39c0d8e 1477 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
b902fbfe 1478 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
92b96797
FB
1479 cbFrameBodySize = pPacket->cbPayloadLen;
1480 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1481 wTxBufSize = sizeof(STxBufHead);
92b96797
FB
1482
1483 if (pDevice->byBBType == BB_TYPE_11A) {
1484 wCurrentRate = RATE_6M;
1485 byPktType = PK_TYPE_11A;
1486 } else {
1487 wCurrentRate = RATE_1M;
1488 byPktType = PK_TYPE_11B;
1489 }
1490
1491 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1492 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1493 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1494 // to set power here.
1495 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1496 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1497 } else {
1498 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1499 }
1500 pDevice->wCurrentRate = wCurrentRate;
1501
92b96797
FB
1502 //Set packet type
1503 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1504 pTxBufHead->wFIFOCtl = 0;
1505 }
1506 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1507 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1508 }
1509 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1510 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1511 }
1512 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1513 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1514 }
1515
1516 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1517 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1518
22040bbf 1519 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
e269fc2d 1520 bNeedACK = false;
92b96797
FB
1521 }
1522 else {
4e9b5e2b 1523 bNeedACK = true;
92b96797
FB
1524 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1525 };
1526
1527 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1528 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1529
1530 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1531 //Set Preamble type always long
1532 //pDevice->byPreambleType = PREAMBLE_LONG;
1533 // probe-response don't retry
1534 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
e269fc2d 1535 // bNeedACK = false;
92b96797
FB
1536 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1537 //}
1538 }
1539
1540 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1541
1542 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
4e9b5e2b 1543 bIsPSPOLL = true;
92b96797
FB
1544 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1545 } else {
1546 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1547 }
1548
1549 //Set FRAGCTL_MACHDCNT
3eaca0d2 1550 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
92b96797
FB
1551
1552 // Notes:
1553 // Although spec says MMPDU can be fragmented; In most case,
1554 // no one will send a MMPDU under fragmentation. With RTS may occur.
e269fc2d 1555 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
92b96797
FB
1556
1557 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1558 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1559 cbIVlen = 4;
1560 cbICVlen = 4;
1561 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1562 }
1563 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1564 cbIVlen = 8;//IV+ExtIV
1565 cbMIClen = 8;
1566 cbICVlen = 4;
1567 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1568 //We need to get seed here for filling TxKey entry.
1569 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1570 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1571 }
1572 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1573 cbIVlen = 8;//RSN Header
1574 cbICVlen = 8;//MIC
1575 pTxBufHead->wFragCtl |= FRAGCTL_AES;
4e9b5e2b 1576 pDevice->bAES = true;
92b96797
FB
1577 }
1578 //MAC Header should be padding 0 to DW alignment.
1579 uPadding = 4 - (cbMacHdLen%4);
1580 uPadding %= 4;
1581 }
1582
1583 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1584
1585 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1586 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1587 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1588 }
1589 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1590
1591 //Set RrvTime/RTS/CTS Buffer
1592 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1593
4f990057 1594 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
92b96797 1595 pMICHDR = NULL;
351c7dc3 1596 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1597 sizeof(struct vnt_rrv_time_cts));
7e60a3de 1598 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
4f990057
MP
1599 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1600 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
7e60a3de 1601 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
92b96797
FB
1602 }
1603 else { // 802.11a/b packet
976467d3 1604 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
92b96797 1605 pMICHDR = NULL;
558becf1
MP
1606 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1607 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
976467d3 1608 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
558becf1 1609 sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1610 }
1611
ceb8c5da 1612 memcpy(&(sEthHeader.h_dest[0]),
9a0e756c
AM
1613 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1614 ETH_ALEN);
ceb8c5da 1615 memcpy(&(sEthHeader.h_source[0]),
9a0e756c
AM
1616 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1617 ETH_ALEN);
92b96797
FB
1618 //=========================
1619 // No Fragmentation
1620 //=========================
3eaca0d2 1621 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
92b96797 1622
351c7dc3
MP
1623 /* Fill FIFO,RrvTime,RTS,and CTS */
1624 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1625 pbyTxBufferAddr, pvRrvTime, rts_cts,
f46142b0 1626 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
92b96797
FB
1627
1628 //Fill DataHead
1629 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
ab01fedc 1630 AUTO_FB_NONE);
92b96797 1631
1cac4a4b 1632 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
92b96797
FB
1633
1634 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1635
1636 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
b902fbfe
AM
1637 u8 * pbyIVHead;
1638 u8 * pbyPayloadHead;
1639 u8 * pbyBSSID;
92b96797
FB
1640 PSKeyItem pTransmitKey = NULL;
1641
b902fbfe
AM
1642 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1643 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
92b96797
FB
1644 do {
1645 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
4e9b5e2b 1646 (pDevice->bLinkPass == true)) {
92b96797
FB
1647 pbyBSSID = pDevice->abyBSSID;
1648 // get pairwise key
e269fc2d 1649 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
92b96797 1650 // get group key
4e9b5e2b 1651 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
92b96797
FB
1652 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1653 break;
1654 }
1655 } else {
1656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1657 break;
1658 }
1659 }
1660 // get group key
1661 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 1662 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
1663 pTransmitKey = NULL;
1664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1665 } else {
1666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1667 }
e269fc2d 1668 } while(false);
92b96797 1669 //Fill TXKEY
b902fbfe 1670 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
3eaca0d2 1671 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
92b96797 1672
3e362598 1673 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
b902fbfe 1674 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
92b96797
FB
1675 cbFrameBodySize);
1676 }
1677 else {
1678 // Copy the Packet into a tx Buffer
3e362598 1679 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
92b96797
FB
1680 }
1681
1cac4a4b 1682 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1683 pDevice->wSeqCounter++ ;
1684 if (pDevice->wSeqCounter > 0x0fff)
1685 pDevice->wSeqCounter = 0;
1686
1687 if (bIsPSPOLL) {
1688 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
a0a1f61a 1689 // of FIFO control header.
92b96797
FB
1690 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1691 // in the same place of other packet's Duration-field).
1692 // And it will cause Cisco-AP to issue Disassociation-packet
7e60a3de
MP
1693 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1694 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1695 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1696 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1697 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1698 } else {
558becf1
MP
1699 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1700 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1701 }
92b96797
FB
1702 }
1703
3eaca0d2 1704 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
b902fbfe 1705 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
1706 pTX_Buffer->byType = 0x00;
1707
1708 pContext->pPacket = NULL;
1709 pContext->Type = CONTEXT_MGMT_PACKET;
3eaca0d2 1710 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
92b96797 1711
1cac4a4b
AM
1712 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1713 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
1714 }
1715 else {
1cac4a4b 1716 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
1717 }
1718
1719 PIPEnsSendBulkOut(pDevice,pContext);
1720 return CMD_STATUS_PENDING;
1721}
1722
d56131de
MP
1723CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1724 struct vnt_tx_mgmt *pPacket)
92b96797 1725{
01f865ba 1726 struct vnt_beacon_buffer *pTX_Buffer;
d56131de
MP
1727 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1728 u32 cbHeaderSize = 0;
1729 u16 wTxBufSize = sizeof(STxShortBufHead);
1730 PSTxShortBufHead pTxBufHead;
1cac4a4b 1731 struct ieee80211_hdr *pMACHeader;
558becf1 1732 struct vnt_tx_datahead_ab *pTxDataHead;
d56131de
MP
1733 u16 wCurrentRate;
1734 u32 cbFrameBodySize;
1735 u32 cbReqCount;
d56131de
MP
1736 u8 *pbyTxBufferAddr;
1737 PUSB_SEND_CONTEXT pContext;
1738 CMD_STATUS status;
92b96797 1739
92b96797
FB
1740 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1741 if (NULL == pContext) {
1742 status = CMD_STATUS_RESOURCES;
1743 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1744 return status ;
1745 }
01f865ba
MP
1746
1747 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
b902fbfe 1748 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
92b96797
FB
1749
1750 cbFrameBodySize = pPacket->cbPayloadLen;
1751
1752 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1753 wTxBufSize = sizeof(STxShortBufHead);
92b96797
FB
1754
1755 if (pDevice->byBBType == BB_TYPE_11A) {
1756 wCurrentRate = RATE_6M;
558becf1
MP
1757 pTxDataHead = (struct vnt_tx_datahead_ab *)
1758 (pbyTxBufferAddr + wTxBufSize);
92b96797 1759 //Get SignalField,ServiceField,Length
aed387c7
MP
1760 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1761 &pTxDataHead->ab);
92b96797 1762 //Get Duration and TimeStampOff
d5005955 1763 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
6b5ad9d2 1764 PK_TYPE_11A, false);
f115e76a 1765 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
558becf1 1766 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1767 } else {
1768 wCurrentRate = RATE_1M;
1769 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
558becf1
MP
1770 pTxDataHead = (struct vnt_tx_datahead_ab *)
1771 (pbyTxBufferAddr + wTxBufSize);
92b96797 1772 //Get SignalField,ServiceField,Length
aed387c7
MP
1773 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1774 &pTxDataHead->ab);
92b96797 1775 //Get Duration and TimeStampOff
d5005955 1776 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
6b5ad9d2 1777 PK_TYPE_11B, false);
f115e76a 1778 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
558becf1 1779 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1780 }
1781
1782 //Generate Beacon Header
1cac4a4b 1783 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
3e362598 1784 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
92b96797 1785
1cac4a4b
AM
1786 pMACHeader->duration_id = 0;
1787 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1788 pDevice->wSeqCounter++ ;
1789 if (pDevice->wSeqCounter > 0x0fff)
1790 pDevice->wSeqCounter = 0;
1791
1792 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1793
3eaca0d2 1794 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
b902fbfe 1795 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
1796 pTX_Buffer->byType = 0x01;
1797
1798 pContext->pPacket = NULL;
1799 pContext->Type = CONTEXT_MGMT_PACKET;
3eaca0d2 1800 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
92b96797
FB
1801
1802 PIPEnsSendBulkOut(pDevice,pContext);
1803 return CMD_STATUS_PENDING;
1804
1805}
1806
d56131de
MP
1807void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1808{
1809 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 1810 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
1811 u8 byPktType;
1812 u8 *pbyTxBufferAddr;
351c7dc3
MP
1813 void *rts_cts = NULL;
1814 void *pvTxDataHd;
d56131de 1815 u32 uDuration, cbReqCount;
1cac4a4b 1816 struct ieee80211_hdr *pMACHeader;
d56131de 1817 u32 cbHeaderSize, cbFrameBodySize;
e269fc2d 1818 int bNeedACK, bIsPSPOLL = false;
d56131de
MP
1819 PSTxBufHead pTxBufHead;
1820 u32 cbFrameSize;
1821 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1822 u32 uPadding = 0;
1823 u32 cbMICHDR = 0, uLength = 0;
1824 u32 dwMICKey0, dwMICKey1;
1825 u32 dwMIC_Priority;
1826 u32 *pdwMIC_L, *pdwMIC_R;
1827 u16 wTxBufSize;
1828 u32 cbMacHdLen;
ceb8c5da 1829 struct ethhdr sEthHeader;
d56131de
MP
1830 void *pvRrvTime, *pMICHDR;
1831 u32 wCurrentRate = RATE_1M;
1832 PUWLAN_80211HDR p80211Header;
1833 u32 uNodeIndex = 0;
e269fc2d 1834 int bNodeExist = false;
d56131de
MP
1835 SKeyItem STempKey;
1836 PSKeyItem pTransmitKey = NULL;
1837 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1838 u32 cbExtSuppRate = 0;
d56131de 1839 PUSB_SEND_CONTEXT pContext;
92b96797 1840
351c7dc3 1841 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
92b96797
FB
1842
1843 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1844 cbFrameBodySize = 0;
1845 }
1846 else {
1847 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1848 }
1849 p80211Header = (PUWLAN_80211HDR)skb->data;
1850
1851 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1852
1853 if (NULL == pContext) {
1854 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1855 dev_kfree_skb_irq(skb);
1856 return ;
1857 }
1858
f39c0d8e 1859 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
b902fbfe 1860 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
92b96797
FB
1861 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1862 wTxBufSize = sizeof(STxBufHead);
92b96797
FB
1863
1864 if (pDevice->byBBType == BB_TYPE_11A) {
1865 wCurrentRate = RATE_6M;
1866 byPktType = PK_TYPE_11A;
1867 } else {
1868 wCurrentRate = RATE_1M;
1869 byPktType = PK_TYPE_11B;
1870 }
1871
1872 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1873 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1874 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1875 // to set power here.
1876 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1877 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1878 } else {
1879 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1880 }
1881
1882 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1883
1884 //Set packet type
1885 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1886 pTxBufHead->wFIFOCtl = 0;
1887 }
1888 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1889 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1890 }
1891 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1892 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1893 }
1894 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1895 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1896 }
1897
1898 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1899 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1900
22040bbf 1901 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
e269fc2d 1902 bNeedACK = false;
92b96797
FB
1903 if (pDevice->bEnableHostWEP) {
1904 uNodeIndex = 0;
4e9b5e2b 1905 bNodeExist = true;
9fc86028 1906 }
92b96797
FB
1907 }
1908 else {
1909 if (pDevice->bEnableHostWEP) {
b902fbfe 1910 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
4e9b5e2b 1911 bNodeExist = true;
9fc86028 1912 }
4e9b5e2b 1913 bNeedACK = true;
92b96797
FB
1914 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1915 };
1916
1917 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1918 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1919
1920 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1921 //Set Preamble type always long
1922 //pDevice->byPreambleType = PREAMBLE_LONG;
1923
1924 // probe-response don't retry
1925 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
e269fc2d 1926 // bNeedACK = false;
92b96797
FB
1927 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1928 //}
1929 }
1930
1931 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1932
1933 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
4e9b5e2b 1934 bIsPSPOLL = true;
92b96797
FB
1935 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1936 } else {
1937 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1938 }
1939
a0a1f61a 1940 // hostapd daemon ext support rate patch
92b96797
FB
1941 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1942
1943 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1944 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1945 }
1946
1947 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1948 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1949 }
1950
1951 if (cbExtSuppRate >0) {
1952 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1953 }
1954 }
1955
92b96797 1956 //Set FRAGCTL_MACHDCNT
3eaca0d2 1957 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
92b96797
FB
1958
1959 // Notes:
1960 // Although spec says MMPDU can be fragmented; In most case,
1961 // no one will send a MMPDU under fragmentation. With RTS may occur.
e269fc2d 1962 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
92b96797 1963
92b96797
FB
1964 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1965 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1966 cbIVlen = 4;
1967 cbICVlen = 4;
1968 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1969 }
1970 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1971 cbIVlen = 8;//IV+ExtIV
1972 cbMIClen = 8;
1973 cbICVlen = 4;
1974 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1975 //We need to get seed here for filling TxKey entry.
1976 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1977 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1978 }
1979 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1980 cbIVlen = 8;//RSN Header
1981 cbICVlen = 8;//MIC
5a5d6a80 1982 cbMICHDR = sizeof(struct vnt_mic_hdr);
92b96797 1983 pTxBufHead->wFragCtl |= FRAGCTL_AES;
4e9b5e2b 1984 pDevice->bAES = true;
92b96797
FB
1985 }
1986 //MAC Header should be padding 0 to DW alignment.
1987 uPadding = 4 - (cbMacHdLen%4);
1988 uPadding %= 4;
1989 }
1990
1991 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1992
1993 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1994 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1995 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1996 }
1997 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1998
92b96797 1999 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
4f990057 2000 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 2001 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
4f990057 2002 sizeof(struct vnt_rrv_time_cts));
351c7dc3 2003 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
4f990057 2004 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
7e60a3de
MP
2005 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2006 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
4f990057
MP
2007 sizeof(struct vnt_cts));
2008 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
7e60a3de 2009 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
92b96797
FB
2010
2011 }
2012 else {//802.11a/b packet
2013
976467d3 2014 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 2015 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
976467d3 2016 sizeof(struct vnt_rrv_time_ab));
558becf1
MP
2017 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2018 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
976467d3 2019 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
558becf1 2020 sizeof(struct vnt_tx_datahead_ab);
92b96797 2021 }
ceb8c5da 2022 memcpy(&(sEthHeader.h_dest[0]),
9a0e756c
AM
2023 &(p80211Header->sA3.abyAddr1[0]),
2024 ETH_ALEN);
ceb8c5da 2025 memcpy(&(sEthHeader.h_source[0]),
9a0e756c
AM
2026 &(p80211Header->sA3.abyAddr2[0]),
2027 ETH_ALEN);
92b96797
FB
2028 //=========================
2029 // No Fragmentation
2030 //=========================
3eaca0d2 2031 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
92b96797 2032
351c7dc3
MP
2033 /* Fill FIFO,RrvTime,RTS,and CTS */
2034 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
2035 pbyTxBufferAddr, pvRrvTime, rts_cts,
f46142b0 2036 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
92b96797
FB
2037
2038 //Fill DataHead
2039 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
ab01fedc 2040 AUTO_FB_NONE);
92b96797 2041
1cac4a4b 2042 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
92b96797
FB
2043
2044 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2045
b902fbfe
AM
2046 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2047 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2048 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
92b96797
FB
2049
2050 // Copy the Packet into a tx Buffer
2051 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2052
2053 // version set to 0, patch for hostapd deamon
1cac4a4b 2054 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
92b96797
FB
2055 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2056
a0a1f61a 2057 // replace support rate, patch for hostapd daemon( only support 11M)
92b96797
FB
2058 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2059 if (cbExtSuppRate != 0) {
2060 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2061 memcpy((pbyPayloadHead + cbFrameBodySize),
2062 pMgmt->abyCurrSuppRates,
2063 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2064 );
2065 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2066 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2067 pMgmt->abyCurrExtSuppRates,
2068 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2069 );
2070 }
2071 }
2072
2073 // Set wep
2074 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2075
2076 if (pDevice->bEnableHostWEP) {
2077 pTransmitKey = &STempKey;
2078 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2079 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2080 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2081 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2082 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2083 memcpy(pTransmitKey->abyKey,
2084 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2085 pTransmitKey->uKeyLength
2086 );
2087 }
2088
2089 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2090
52a7e64b
AM
2091 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2092 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
92b96797
FB
2093
2094 // DO Software Michael
2095 MIC_vInit(dwMICKey0, dwMICKey1);
ceb8c5da 2096 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
92b96797 2097 dwMIC_Priority = 0;
b902fbfe 2098 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
b4dc03af
MP
2099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2100 " %X, %X\n", dwMICKey0, dwMICKey1);
92b96797
FB
2101
2102 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2103
2104 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2105
52a7e64b
AM
2106 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2107 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
92b96797
FB
2108
2109 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2110 MIC_vUnInit();
2111
4e9b5e2b 2112 if (pDevice->bTxMICFail == true) {
92b96797
FB
2113 *pdwMIC_L = 0;
2114 *pdwMIC_R = 0;
e269fc2d 2115 pDevice->bTxMICFail = false;
92b96797
FB
2116 }
2117
2118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2119 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
b4dc03af
MP
2120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2121 *pdwMIC_L, *pdwMIC_R);
92b96797
FB
2122
2123 }
2124
b902fbfe 2125 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
ec37d8b6 2126 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
92b96797
FB
2127
2128 if (pDevice->bEnableHostWEP) {
2129 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2130 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2131 }
2132
2133 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
3eaca0d2 2134 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
92b96797
FB
2135 }
2136 }
2137
1cac4a4b 2138 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
2139 pDevice->wSeqCounter++ ;
2140 if (pDevice->wSeqCounter > 0x0fff)
2141 pDevice->wSeqCounter = 0;
2142
92b96797
FB
2143 if (bIsPSPOLL) {
2144 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2145 // of FIFO control header.
2146 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2147 // in the same place of other packet's Duration-field).
2148 // And it will cause Cisco-AP to issue Disassociation-packet
7e60a3de
MP
2149 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2150 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2151 cpu_to_le16(p80211Header->sA2.wDurationID);
2152 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2153 cpu_to_le16(p80211Header->sA2.wDurationID);
2154 } else {
558becf1
MP
2155 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2156 cpu_to_le16(p80211Header->sA2.wDurationID);
2157 }
92b96797
FB
2158 }
2159
3eaca0d2 2160 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
b902fbfe 2161 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
2162 pTX_Buffer->byType = 0x00;
2163
2164 pContext->pPacket = skb;
2165 pContext->Type = CONTEXT_MGMT_PACKET;
3eaca0d2 2166 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
92b96797 2167
1cac4a4b
AM
2168 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2169 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
2170 }
2171 else {
1cac4a4b 2172 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
2173 }
2174 PIPEnsSendBulkOut(pDevice,pContext);
2175 return ;
2176
2177}
2178
92b96797
FB
2179//TYPE_AC0DMA data tx
2180/*
2181 * Description:
2182 * Tx packet via AC0DMA(DMA1)
2183 *
2184 * Parameters:
2185 * In:
2186 * pDevice - Pointer to the adapter
2187 * skb - Pointer to tx skb packet
2188 * Out:
2189 * void
2190 *
2191 * Return Value: NULL
2192 */
2193
d56131de
MP
2194int nsDMA_tx_packet(struct vnt_private *pDevice,
2195 u32 uDMAIdx, struct sk_buff *skb)
92b96797 2196{
d56131de
MP
2197 struct net_device_stats *pStats = &pDevice->stats;
2198 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 2199 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
2200 u32 BytesToWrite = 0, uHeaderLen = 0;
2201 u32 uNodeIndex = 0;
2202 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2203 u16 wAID;
2204 u8 byPktType;
e269fc2d 2205 int bNeedEncryption = false;
d56131de
MP
2206 PSKeyItem pTransmitKey = NULL;
2207 SKeyItem STempKey;
2208 int ii;
e269fc2d
AM
2209 int bTKIP_UseGTK = false;
2210 int bNeedDeAuth = false;
d56131de 2211 u8 *pbyBSSID;
e269fc2d 2212 int bNodeExist = false;
d56131de 2213 PUSB_SEND_CONTEXT pContext;
dfdcc425 2214 bool fConvertedPacket;
d56131de
MP
2215 u32 status;
2216 u16 wKeepRate = pDevice->wCurrentRate;
e269fc2d 2217 int bTxeapol_key = false;
92b96797 2218
92b96797
FB
2219 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2220
2221 if (pDevice->uAssocCount == 0) {
2222 dev_kfree_skb_irq(skb);
2223 return 0;
2224 }
2225
b902fbfe 2226 if (is_multicast_ether_addr((u8 *)(skb->data))) {
92b96797 2227 uNodeIndex = 0;
4e9b5e2b 2228 bNodeExist = true;
92b96797
FB
2229 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2230
2231 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2232 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2233 // set tx map
2234 pMgmt->abyPSTxMap[0] |= byMask[0];
2235 return 0;
2236 }
93184690 2237 // multicast/broadcast data rate
92b96797
FB
2238
2239 if (pDevice->byBBType != BB_TYPE_11A)
2240 pDevice->wCurrentRate = RATE_2M;
2241 else
2242 pDevice->wCurrentRate = RATE_24M;
2243 // long preamble type
2244 pDevice->byPreambleType = PREAMBLE_SHORT;
2245
2246 }else {
2247
b902fbfe 2248 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
92b96797
FB
2249
2250 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2251
2252 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2253
2254 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2255 // set tx map
2256 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2257 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2259 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2260
2261 return 0;
2262 }
2263 // AP rate decided from node
2264 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2265 // tx preamble decided from node
2266
2267 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2268 pDevice->byPreambleType = pDevice->byShortPreamble;
2269
2270 }else {
2271 pDevice->byPreambleType = PREAMBLE_LONG;
2272 }
4e9b5e2b 2273 bNodeExist = true;
92b96797
FB
2274 }
2275 }
2276
e269fc2d 2277 if (bNodeExist == false) {
92b96797
FB
2278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2279 dev_kfree_skb_irq(skb);
2280 return 0;
2281 }
2282 }
2283
2284 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2285
2286 if (pContext == NULL) {
2287 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2288 dev_kfree_skb_irq(skb);
2289 return STATUS_RESOURCES;
2290 }
2291
ceb8c5da 2292 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
92b96797
FB
2293
2294//mike add:station mode check eapol-key challenge--->
2295{
b902fbfe
AM
2296 u8 Protocol_Version; //802.1x Authentication
2297 u8 Packet_Type; //802.1x Authentication
2298 u8 Descriptor_type;
3eaca0d2 2299 u16 Key_info;
92b96797 2300
21ec51f3
CC
2301 Protocol_Version = skb->data[ETH_HLEN];
2302 Packet_Type = skb->data[ETH_HLEN+1];
2303 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2304 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
ceb8c5da 2305 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
aa209eef
MP
2306 /* 802.1x OR eapol-key challenge frame transfer */
2307 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2308 (Packet_Type == 3)) {
4e9b5e2b 2309 bTxeapol_key = true;
92b96797
FB
2310 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2311 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2312 if(Descriptor_type==254) {
4e9b5e2b 2313 pDevice->fWPA_Authened = true;
92b96797
FB
2314 PRINT_K("WPA ");
2315 }
2316 else {
4e9b5e2b 2317 pDevice->fWPA_Authened = true;
92b96797
FB
2318 PRINT_K("WPA2(re-keying) ");
2319 }
2320 PRINT_K("Authentication completed!!\n");
2321 }
a0a1f61a 2322 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
92b96797 2323 (Key_info & BIT8) && (Key_info & BIT9)) {
4e9b5e2b 2324 pDevice->fWPA_Authened = true;
92b96797
FB
2325 PRINT_K("WPA2 Authentication completed!!\n");
2326 }
2327 }
2328 }
2329}
2330//mike add:station mode check eapol-key challenge<---
2331
4e9b5e2b
AM
2332 if (pDevice->bEncryptionEnable == true) {
2333 bNeedEncryption = true;
92b96797
FB
2334 // get Transmit key
2335 do {
2336 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2337 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2338 pbyBSSID = pDevice->abyBSSID;
2339 // get pairwise key
e269fc2d 2340 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
92b96797 2341 // get group key
4e9b5e2b
AM
2342 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2343 bTKIP_UseGTK = true;
92b96797
FB
2344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2345 break;
2346 }
2347 } else {
2348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2349 break;
2350 }
2351 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
ceb8c5da
AM
2352 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2353 pbyBSSID = pDevice->sTxEthHeader.h_dest;
92b96797
FB
2354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2355 for (ii = 0; ii< 6; ii++)
2356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2357 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2358
2359 // get pairwise key
4e9b5e2b 2360 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
92b96797
FB
2361 break;
2362 }
2363 // get group key
2364 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 2365 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
2366 pTransmitKey = NULL;
2367 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2368 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2369 }
2370 else
2371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2372 } else {
4e9b5e2b 2373 bTKIP_UseGTK = true;
92b96797
FB
2374 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2375 }
e269fc2d 2376 } while(false);
92b96797
FB
2377 }
2378
2379 if (pDevice->bEnableHostWEP) {
2380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
4e9b5e2b 2381 if (pDevice->bEncryptionEnable == true) {
92b96797
FB
2382 pTransmitKey = &STempKey;
2383 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2384 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2385 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2386 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2387 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2388 memcpy(pTransmitKey->abyKey,
2389 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2390 pTransmitKey->uKeyLength
2391 );
2392 }
2393 }
2394
b902fbfe 2395 byPktType = (u8)pDevice->byPacketType;
92b96797
FB
2396
2397 if (pDevice->bFixRate) {
2398 if (pDevice->byBBType == BB_TYPE_11B) {
2399 if (pDevice->uConnectionRate >= RATE_11M) {
2400 pDevice->wCurrentRate = RATE_11M;
2401 } else {
3eaca0d2 2402 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2403 }
2404 } else {
2405 if ((pDevice->byBBType == BB_TYPE_11A) &&
2406 (pDevice->uConnectionRate <= RATE_6M)) {
2407 pDevice->wCurrentRate = RATE_6M;
2408 } else {
2409 if (pDevice->uConnectionRate >= RATE_54M)
2410 pDevice->wCurrentRate = RATE_54M;
2411 else
3eaca0d2 2412 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2413 }
2414 }
2415 }
2416 else {
2417 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2418 // Adhoc Tx rate decided from node DB
ceb8c5da 2419 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
92b96797
FB
2420 // Multicast use highest data rate
2421 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2422 // preamble type
2423 pDevice->byPreambleType = pDevice->byShortPreamble;
2424 }
2425 else {
ceb8c5da 2426 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
92b96797
FB
2427 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2428 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2429 pDevice->byPreambleType = pDevice->byShortPreamble;
2430
2431 }
2432 else {
2433 pDevice->byPreambleType = PREAMBLE_LONG;
2434 }
2435 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2436 }
2437 else {
2438 if (pDevice->byBBType != BB_TYPE_11A)
2439 pDevice->wCurrentRate = RATE_2M;
2440 else
2441 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2442 // abyCurrExtSuppRates[]
2443 pDevice->byPreambleType = PREAMBLE_SHORT;
2444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2445 }
2446 }
2447 }
2448 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2449 // Infra STA rate decided from AP Node, index = 0
2450 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2451 }
2452 }
2453
ceb8c5da 2454 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
aa209eef
MP
2455 if (pDevice->byBBType != BB_TYPE_11A) {
2456 pDevice->wCurrentRate = RATE_1M;
2457 pDevice->byACKRate = RATE_1M;
2458 pDevice->byTopCCKBasicRate = RATE_1M;
2459 pDevice->byTopOFDMBasicRate = RATE_6M;
2460 } else {
2461 pDevice->wCurrentRate = RATE_6M;
2462 pDevice->byACKRate = RATE_6M;
2463 pDevice->byTopCCKBasicRate = RATE_1M;
2464 pDevice->byTopOFDMBasicRate = RATE_6M;
2465 }
2466 }
92b96797 2467
0cbd8d98
AM
2468 DBG_PRT(MSG_LEVEL_DEBUG,
2469 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2470 pDevice->wCurrentRate);
92b96797
FB
2471
2472 if (wKeepRate != pDevice->wCurrentRate) {
0cbd8d98 2473 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
92b96797
FB
2474 }
2475
2476 if (pDevice->wCurrentRate <= RATE_11M) {
2477 byPktType = PK_TYPE_11B;
2478 }
2479
4e9b5e2b 2480 if (bNeedEncryption == true) {
ceb8c5da
AM
2481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2482 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
e269fc2d 2483 bNeedEncryption = false;
ceb8c5da 2484 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
92b96797
FB
2485 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2486 if (pTransmitKey == NULL) {
2487 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2488 }
2489 else {
4e9b5e2b 2490 if (bTKIP_UseGTK == true) {
92b96797
FB
2491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2492 }
2493 else {
b4dc03af
MP
2494 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2495 pTransmitKey->dwKeyIndex);
4e9b5e2b 2496 bNeedEncryption = true;
92b96797
FB
2497 }
2498 }
2499 }
2500
92b96797
FB
2501 if (pDevice->bEnableHostWEP) {
2502 if ((uNodeIndex != 0) &&
2503 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
b4dc03af
MP
2504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2505 pTransmitKey->dwKeyIndex);
4e9b5e2b 2506 bNeedEncryption = true;
92b96797
FB
2507 }
2508 }
2509 }
2510 else {
2511
92b96797
FB
2512 if (pTransmitKey == NULL) {
2513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
e269fc2d 2514 pContext->bBoolInUse = false;
92b96797
FB
2515 dev_kfree_skb_irq(skb);
2516 pStats->tx_dropped++;
2517 return STATUS_FAILURE;
2518 }
92b96797
FB
2519 }
2520 }
2521
d0a2b8fa
MP
2522 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2523
92b96797 2524 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
d0a2b8fa 2525 pTX_Buffer, bNeedEncryption,
92b96797 2526 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
b902fbfe 2527 (u8 *)skb->data, pTransmitKey, uNodeIndex,
92b96797
FB
2528 pDevice->wCurrentRate,
2529 &uHeaderLen, &BytesToWrite
2530 );
2531
e269fc2d
AM
2532 if (fConvertedPacket == false) {
2533 pContext->bBoolInUse = false;
92b96797
FB
2534 dev_kfree_skb_irq(skb);
2535 return STATUS_FAILURE;
2536 }
2537
4e9b5e2b 2538 if ( pDevice->bEnablePSMode == true ) {
92b96797 2539 if ( !pDevice->bPSModeTxBurst ) {
0cbd8d98
AM
2540 bScheduleCommand((void *) pDevice,
2541 WLAN_CMD_MAC_DISPOWERSAVING,
2542 NULL);
4e9b5e2b 2543 pDevice->bPSModeTxBurst = true;
92b96797
FB
2544 }
2545 }
2546
b902fbfe 2547 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3eaca0d2 2548 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
92b96797
FB
2549
2550 pContext->pPacket = skb;
2551 pContext->Type = CONTEXT_DATA_PACKET;
3eaca0d2 2552 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
92b96797 2553
ceb8c5da 2554 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
92b96797
FB
2555
2556 status = PIPEnsSendBulkOut(pDevice,pContext);
2557
4e9b5e2b 2558 if (bNeedDeAuth == true) {
3eaca0d2 2559 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
92b96797 2560
b902fbfe 2561 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
92b96797
FB
2562 }
2563
2564 if(status!=STATUS_PENDING) {
e269fc2d 2565 pContext->bBoolInUse = false;
92b96797
FB
2566 dev_kfree_skb_irq(skb);
2567 return STATUS_FAILURE;
2568 }
2569 else
2570 return 0;
2571
2572}
2573
92b96797
FB
2574/*
2575 * Description:
2576 * Relay packet send (AC1DMA) from rx dpc.
2577 *
2578 * Parameters:
2579 * In:
2580 * pDevice - Pointer to the adapter
2581 * pPacket - Pointer to rx packet
2582 * cbPacketSize - rx ethernet frame size
2583 * Out:
e269fc2d 2584 * TURE, false
92b96797 2585 *
4e9b5e2b 2586 * Return Value: Return true if packet is copy to dma1; otherwise false
92b96797
FB
2587 */
2588
d56131de
MP
2589int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2590 u32 uNodeIndex)
92b96797 2591{
d56131de 2592 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 2593 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
2594 u32 BytesToWrite = 0, uHeaderLen = 0;
2595 u8 byPktType = PK_TYPE_11B;
e269fc2d 2596 int bNeedEncryption = false;
d56131de
MP
2597 SKeyItem STempKey;
2598 PSKeyItem pTransmitKey = NULL;
2599 u8 *pbyBSSID;
2600 PUSB_SEND_CONTEXT pContext;
2601 u8 byPktTyp;
2602 int fConvertedPacket;
d56131de
MP
2603 u32 status;
2604 u16 wKeepRate = pDevice->wCurrentRate;
92b96797 2605
92b96797
FB
2606 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2607
2608 if (NULL == pContext) {
e269fc2d 2609 return false;
92b96797
FB
2610 }
2611
ceb8c5da 2612 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
92b96797 2613
4e9b5e2b
AM
2614 if (pDevice->bEncryptionEnable == true) {
2615 bNeedEncryption = true;
92b96797
FB
2616 // get group key
2617 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 2618 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
2619 pTransmitKey = NULL;
2620 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2621 } else {
2622 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2623 }
2624 }
2625
2626 if (pDevice->bEnableHostWEP) {
ee93e197 2627 if (uNodeIndex < MAX_NODE_NUM + 1) {
92b96797
FB
2628 pTransmitKey = &STempKey;
2629 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2630 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2631 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2632 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2633 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2634 memcpy(pTransmitKey->abyKey,
2635 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2636 pTransmitKey->uKeyLength
2637 );
2638 }
2639 }
2640
2641 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
e269fc2d
AM
2642 pContext->bBoolInUse = false;
2643 return false;
92b96797
FB
2644 }
2645
b902fbfe 2646 byPktTyp = (u8)pDevice->byPacketType;
92b96797
FB
2647
2648 if (pDevice->bFixRate) {
2649 if (pDevice->byBBType == BB_TYPE_11B) {
2650 if (pDevice->uConnectionRate >= RATE_11M) {
2651 pDevice->wCurrentRate = RATE_11M;
2652 } else {
3eaca0d2 2653 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2654 }
2655 } else {
2656 if ((pDevice->byBBType == BB_TYPE_11A) &&
2657 (pDevice->uConnectionRate <= RATE_6M)) {
2658 pDevice->wCurrentRate = RATE_6M;
2659 } else {
2660 if (pDevice->uConnectionRate >= RATE_54M)
2661 pDevice->wCurrentRate = RATE_54M;
2662 else
3eaca0d2 2663 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2664 }
2665 }
2666 }
2667 else {
2668 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2669 }
2670
92b96797 2671 if (wKeepRate != pDevice->wCurrentRate) {
0cbd8d98 2672 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
92b96797
FB
2673 }
2674
2675 if (pDevice->wCurrentRate <= RATE_11M)
2676 byPktType = PK_TYPE_11B;
2677
abad19d0
AM
2678 BytesToWrite = uDataLen + ETH_FCS_LEN;
2679
92b96797
FB
2680 // Convert the packet to an usb frame and copy into our buffer
2681 // and send the irp.
2682
d0a2b8fa
MP
2683 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2684
92b96797 2685 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
d0a2b8fa 2686 pTX_Buffer, bNeedEncryption,
92b96797
FB
2687 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2688 pbySkbData, pTransmitKey, uNodeIndex,
2689 pDevice->wCurrentRate,
2690 &uHeaderLen, &BytesToWrite
2691 );
2692
e269fc2d
AM
2693 if (fConvertedPacket == false) {
2694 pContext->bBoolInUse = false;
2695 return false;
92b96797
FB
2696 }
2697
b902fbfe 2698 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3eaca0d2 2699 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
92b96797
FB
2700
2701 pContext->pPacket = NULL;
2702 pContext->Type = CONTEXT_DATA_PACKET;
3eaca0d2 2703 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
92b96797 2704
ceb8c5da 2705 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
92b96797
FB
2706
2707 status = PIPEnsSendBulkOut(pDevice,pContext);
2708
4e9b5e2b 2709 return true;
92b96797
FB
2710}
2711