staging: vt6656: rxtx.c merge pvRTS and pvCTS/pCTS void pointers
[deliverable/linux.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,
128 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
09bd0f35 129 u16 wCurrentRate, u8 byFBOption);
d56131de
MP
130
131static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
fedbfe7e 132 void *pvRTS, 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,
fedbfe7e 720 void *pvRTS, u32 cbFrameLength, int bNeedAck,
ceb8c5da 721 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
92b96797 722{
13fe62ae 723 union vnt_tx_data_head *head = pvRTS;
92b96797 724
13fe62ae
MP
725 if (!head)
726 return;
92b96797 727
9d5829bf
MP
728 /* Note: So far RTSHead doesn't appear in ATIM
729 * & Beacom DMA, so we don't need to take them
730 * into account.
731 * Otherwise, we need to modified codes for them.
732 */
0bddd303
MP
733 switch (byPktType) {
734 case PK_TYPE_11GB:
735 case PK_TYPE_11GA:
9d5829bf
MP
736 if (byFBOption == AUTO_FB_NONE)
737 vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
5e67ee49
MP
738 psEthHeader, byPktType, cbFrameLength,
739 bNeedAck, wCurrentRate, byFBOption);
9d5829bf
MP
740 else
741 vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
ec91713a
MP
742 psEthHeader, byPktType, cbFrameLength,
743 bNeedAck, wCurrentRate, byFBOption);
0bddd303
MP
744 break;
745 case PK_TYPE_11A:
2b83ebd0 746 if (byFBOption) {
9d5829bf 747 vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
9d2578c1
MP
748 psEthHeader, byPktType, cbFrameLength,
749 bNeedAck, wCurrentRate, byFBOption);
2b83ebd0
MP
750 break;
751 }
0bddd303 752 case PK_TYPE_11B:
9d5829bf 753 vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
1712633d
MP
754 psEthHeader, byPktType, cbFrameLength,
755 bNeedAck, wCurrentRate, byFBOption);
9d5829bf 756 }
92b96797
FB
757}
758
d56131de
MP
759static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
760 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
09bd0f35 761 u16 wCurrentRate, u8 byFBOption)
92b96797 762{
27df3ebf 763 union vnt_tx_data_head *head = pvCTS;
d56131de 764 u32 uCTSFrameLen = 14;
92b96797 765
27df3ebf
MP
766 if (!head)
767 return;
92b96797 768
c921cc8c
MP
769 if (byFBOption != AUTO_FB_NONE) {
770 /* Auto Fall back */
27df3ebf 771 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
aed387c7
MP
772 /* Get SignalField,ServiceField,Length */
773 BBvCalculateParameter(pDevice, uCTSFrameLen,
774 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe
MP
775 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
776 cbFrameLength, byPktType,
777 wCurrentRate, bNeedAck, byFBOption);
778 /* Get CTSDuration_ba_f0 */
779 pBuf->wCTSDuration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
780 CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate,
781 bNeedAck, byFBOption);
782 /* Get CTSDuration_ba_f1 */
783 pBuf->wCTSDuration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
784 CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate,
785 bNeedAck, byFBOption);
14840cdd
MP
786 /* Get CTS Frame body */
787 pBuf->data.duration = pBuf->wDuration_ba;
788 pBuf->data.frame_control = TYPE_CTL_CTS;
789 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
c921cc8c 790 } else {
27df3ebf 791 struct vnt_cts *pBuf = &head->cts_g;
aed387c7
MP
792 /* Get SignalField,ServiceField,Length */
793 BBvCalculateParameter(pDevice, uCTSFrameLen,
794 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe
MP
795 /* Get CTSDuration_ba */
796 pBuf->wDuration_ba = s_uGetRTSCTSDuration(pDevice,
797 CTSDUR_BA, cbFrameLength, byPktType,
798 wCurrentRate, bNeedAck, byFBOption);
14840cdd
MP
799 /*Get CTS Frame body*/
800 pBuf->data.duration = pBuf->wDuration_ba;
801 pBuf->data.frame_control = TYPE_CTL_CTS;
802 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
92b96797 803 }
92b96797
FB
804}
805
92b96797
FB
806/*+
807 *
808 * Description:
809 * Generate FIFO control for MAC & Baseband controller
810 *
811 * Parameters:
812 * In:
813 * pDevice - Pointer to adpater
814 * pTxDataHead - Transmit Data Buffer
815 * pTxBufHead - pTxBufHead
816 * pvRrvTime - pvRrvTime
817 * pvRTS - RTS Buffer
818 * pCTS - CTS Buffer
819 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
820 * bNeedACK - If need ACK
821 * uDMAIdx - DMA Index
822 * Out:
823 * none
824 *
825 * Return Value: none
826 *
827-*/
cc856e61 828
d56131de
MP
829static void s_vGenerateTxParameter(struct vnt_private *pDevice,
830 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
351c7dc3 831 void *rts_cts, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
f46142b0 832 struct ethhdr *psEthHeader, bool need_rts)
92b96797 833{
d56131de
MP
834 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
835 u16 wFifoCtl;
d56131de 836 u8 byFBOption = AUTO_FB_NONE;
92b96797
FB
837
838 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
839 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
840 pFifoHead->wReserved = wCurrentRate;
841 wFifoCtl = pFifoHead->wFIFOCtl;
842
92b96797
FB
843 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
844 byFBOption = AUTO_FB_0;
845 }
846 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
847 byFBOption = AUTO_FB_1;
848 }
849
2dc22d5a
MP
850 if (!pvRrvTime)
851 return;
852
92b96797
FB
853 if (pDevice->bLongHeader)
854 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
855
856 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
f46142b0 857 if (need_rts) {
92b96797 858 //Fill RsvTime
6398a59b
MP
859 struct vnt_rrv_time_rts *pBuf =
860 (struct vnt_rrv_time_rts *)pvRrvTime;
cfabe4b4
MP
861 pBuf->wRTSTxRrvTime_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
862 byPktType, cbFrameSize, wCurrentRate);
863 pBuf->wRTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
864 byPktType, cbFrameSize, wCurrentRate);
865 pBuf->wRTSTxRrvTime_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
866 byPktType, cbFrameSize, wCurrentRate);
9c3806d5
MP
867 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice,
868 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
869 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
870 PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate,
871 bNeedACK);
351c7dc3
MP
872 /* Fill RTS */
873 s_vFillRTSHead(pDevice, byPktType, rts_cts, cbFrameSize,
874 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
92b96797
FB
875 }
876 else {//RTS_needless, PCF mode
92b96797 877 //Fill RsvTime
4f990057
MP
878 struct vnt_rrv_time_cts *pBuf =
879 (struct vnt_rrv_time_cts *)pvRrvTime;
9c3806d5
MP
880 pBuf->wTxRrvTime_a = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
881 cbFrameSize, wCurrentRate, bNeedACK);
882 pBuf->wTxRrvTime_b = vnt_rxtx_rsvtime_le16(pDevice,
883 PK_TYPE_11B, cbFrameSize,
884 pDevice->byTopCCKBasicRate, bNeedACK);
cfabe4b4
MP
885 pBuf->wCTSTxRrvTime_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
886 byPktType, cbFrameSize, wCurrentRate);
351c7dc3
MP
887 /* Fill CTS */
888 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, rts_cts,
889 cbFrameSize, bNeedACK, wCurrentRate, byFBOption);
92b96797
FB
890 }
891 }
892 else if (byPktType == PK_TYPE_11A) {
f46142b0 893 if (need_rts) {
92b96797 894 //Fill RsvTime
976467d3
MP
895 struct vnt_rrv_time_ab *pBuf =
896 (struct vnt_rrv_time_ab *)pvRrvTime;
cfabe4b4
MP
897 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 2,
898 byPktType, cbFrameSize, wCurrentRate);
9c3806d5
MP
899 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, byPktType,
900 cbFrameSize, wCurrentRate, bNeedACK);
351c7dc3
MP
901 /* Fill RTS */
902 s_vFillRTSHead(pDevice, byPktType, rts_cts, cbFrameSize,
903 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
f46142b0 904 } else {
92b96797 905 //Fill RsvTime
976467d3
MP
906 struct vnt_rrv_time_ab *pBuf =
907 (struct vnt_rrv_time_ab *)pvRrvTime;
9c3806d5
MP
908 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A,
909 cbFrameSize, wCurrentRate, bNeedACK);
92b96797
FB
910 }
911 }
912 else if (byPktType == PK_TYPE_11B) {
f46142b0 913 if (need_rts) {
92b96797 914 //Fill RsvTime
976467d3
MP
915 struct vnt_rrv_time_ab *pBuf =
916 (struct vnt_rrv_time_ab *)pvRrvTime;
cfabe4b4
MP
917 pBuf->wRTSTxRrvTime = s_uGetRTSCTSRsvTime(pDevice, 0,
918 byPktType, cbFrameSize, wCurrentRate);
9c3806d5
MP
919 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
920 cbFrameSize, wCurrentRate, bNeedACK);
351c7dc3
MP
921 /* Fill RTS */
922 s_vFillRTSHead(pDevice, byPktType, rts_cts, cbFrameSize,
923 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
92b96797
FB
924 }
925 else { //RTS_needless, non PCF mode
926 //Fill RsvTime
976467d3
MP
927 struct vnt_rrv_time_ab *pBuf =
928 (struct vnt_rrv_time_ab *)pvRrvTime;
9c3806d5
MP
929 pBuf->wTxRrvTime = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11B,
930 cbFrameSize, wCurrentRate, bNeedACK);
92b96797
FB
931 }
932 }
933 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
934}
935/*
b902fbfe 936 u8 * pbyBuffer,//point to pTxBufHead
3eaca0d2 937 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
cc856e61 938 unsigned int cbFragmentSize,//Hdr+payoad+FCS
92b96797
FB
939*/
940
d56131de 941static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
d0a2b8fa
MP
942 struct vnt_tx_buffer *pTxBufHead, int bNeedEncryption,
943 u32 uSkbPacketLen, u32 uDMAIdx, struct ethhdr *psEthHeader,
944 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
945 u32 *pcbHeaderLen, u32 *pcbTotalLen)
92b96797 946{
d56131de
MP
947 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
948 u32 cbFrameSize, cbFrameBodySize;
d56131de
MP
949 u32 cb802_1_H_len;
950 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
951 u32 cbFCSlen = 4, cbMICHDR = 0;
f46142b0
MP
952 int bNeedACK;
953 bool bRTS = false;
d56131de
MP
954 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
955 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
956 u8 abySNAP_Bridgetunnel[ETH_ALEN]
957 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
958 u32 uDuration;
959 u32 cbHeaderLength = 0, uPadding = 0;
960 void *pvRrvTime;
5a5d6a80 961 struct vnt_mic_hdr *pMICHDR;
351c7dc3 962 void *rts_cts = NULL;
d56131de
MP
963 void *pvTxDataHd;
964 u8 byFBOption = AUTO_FB_NONE, byFragType;
965 u16 wTxBufSize;
4235f72f 966 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
d56131de 967 u32 *pdwMIC_L, *pdwMIC_R;
e269fc2d 968 int bSoftWEP = false;
d56131de 969
351c7dc3 970 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
92b96797 971
e2efba76 972 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
4e9b5e2b
AM
973 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
974 bSoftWEP = true; /* WEP 256 */
e2efba76 975 }
92b96797 976
92b96797 977 // Get pkt type
ceb8c5da 978 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
92b96797
FB
979 if (pDevice->dwDiagRefCount == 0) {
980 cb802_1_H_len = 8;
981 } else {
982 cb802_1_H_len = 2;
983 }
984 } else {
985 cb802_1_H_len = 0;
986 }
987
21ec51f3 988 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
92b96797
FB
989
990 //Set packet type
3eaca0d2 991 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
92b96797
FB
992
993 if (pDevice->dwDiagRefCount != 0) {
e269fc2d 994 bNeedACK = false;
92b96797
FB
995 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
996 } else { //if (pDevice->dwDiagRefCount != 0) {
22040bbf
AM
997 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
998 (pDevice->eOPMode == OP_MODE_AP)) {
ceb8c5da 999 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
e269fc2d 1000 bNeedACK = false;
22040bbf
AM
1001 pTxBufHead->wFIFOCtl =
1002 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1003 } else {
4e9b5e2b 1004 bNeedACK = true;
22040bbf
AM
1005 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1006 }
92b96797
FB
1007 }
1008 else {
1009 // MSDUs in Infra mode always need ACK
4e9b5e2b 1010 bNeedACK = true;
92b96797
FB
1011 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1012 }
1013 } //if (pDevice->dwDiagRefCount != 0) {
1014
1015 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1016
1017 //Set FIFOCTL_LHEAD
1018 if (pDevice->bLongHeader)
1019 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1020
92b96797
FB
1021 //Set FRAGCTL_MACHDCNT
1022 if (pDevice->bLongHeader) {
1023 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1024 } else {
1025 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1026 }
3eaca0d2 1027 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
92b96797
FB
1028
1029 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1030 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1031 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1032 }
1033
1034 //Set Auto Fallback Ctl
1035 if (wCurrentRate >= RATE_18M) {
1036 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1037 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1038 byFBOption = AUTO_FB_0;
1039 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1040 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1041 byFBOption = AUTO_FB_1;
1042 }
1043 }
1044
4e9b5e2b 1045 if (bSoftWEP != true) {
92b96797
FB
1046 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1047 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1048 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1049 }
1050 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1051 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1052 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1053 }
1054 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1055 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1056 }
1057 }
1058 }
1059
92b96797
FB
1060 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1061 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1062 cbIVlen = 4;
1063 cbICVlen = 4;
1064 }
1065 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1066 cbIVlen = 8;//IV+ExtIV
1067 cbMIClen = 8;
1068 cbICVlen = 4;
1069 }
1070 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1071 cbIVlen = 8;//RSN Header
1072 cbICVlen = 8;//MIC
5a5d6a80 1073 cbMICHDR = sizeof(struct vnt_mic_hdr);
92b96797 1074 }
e269fc2d 1075 if (bSoftWEP == false) {
92b96797
FB
1076 //MAC Header should be padding 0 to DW alignment.
1077 uPadding = 4 - (cbMACHdLen%4);
1078 uPadding %= 4;
1079 }
1080 }
1081
1082 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1083
e269fc2d
AM
1084 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1085 bRTS = false;
92b96797 1086 } else {
4e9b5e2b 1087 bRTS = true;
92b96797
FB
1088 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1089 }
1090
b902fbfe 1091 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
92b96797
FB
1092 wTxBufSize = sizeof(STxBufHead);
1093 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1094 if (byFBOption == AUTO_FB_NONE) {
4e9b5e2b 1095 if (bRTS == true) {//RTS_need
6398a59b
MP
1096 pvRrvTime = (struct vnt_rrv_time_rts *)
1097 (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 1098 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
6398a59b 1099 sizeof(struct vnt_rrv_time_rts));
351c7dc3 1100 rts_cts = (struct vnt_rts_g *) (pbyTxBufferAddr + wTxBufSize +
6398a59b 1101 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
7e60a3de
MP
1102 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
1103 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1104 cbMICHDR + sizeof(struct vnt_rts_g));
6398a59b 1105 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
c521cb58 1106 cbMICHDR + sizeof(struct vnt_rts_g) +
7e60a3de 1107 sizeof(struct vnt_tx_datahead_g);
92b96797
FB
1108 }
1109 else { //RTS_needless
4f990057
MP
1110 pvRrvTime = (struct vnt_rrv_time_cts *)
1111 (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 1112 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1113 sizeof(struct vnt_rrv_time_cts));
351c7dc3 1114 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1115 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
7e60a3de
MP
1116 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr +
1117 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1118 cbMICHDR + sizeof(struct vnt_cts));
4f990057
MP
1119 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1120 cbMICHDR + sizeof(struct vnt_cts) +
7e60a3de 1121 sizeof(struct vnt_tx_datahead_g);
92b96797
FB
1122 }
1123 } else {
1124 // Auto Fall Back
4e9b5e2b 1125 if (bRTS == true) {//RTS_need
6398a59b
MP
1126 pvRrvTime = (struct vnt_rrv_time_rts *)(pbyTxBufferAddr +
1127 wTxBufSize);
5a5d6a80 1128 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
6398a59b 1129 sizeof(struct vnt_rrv_time_rts));
351c7dc3 1130 rts_cts = (struct vnt_rts_g_fb *)(pbyTxBufferAddr + wTxBufSize +
6398a59b 1131 sizeof(struct vnt_rrv_time_rts) + cbMICHDR);
7c05c545
MP
1132 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
1133 wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1134 cbMICHDR + sizeof(struct vnt_rts_g_fb));
6398a59b
MP
1135 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
1136 cbMICHDR + sizeof(struct vnt_rts_g_fb) +
7c05c545 1137 sizeof(struct vnt_tx_datahead_g_fb);
92b96797 1138 }
e269fc2d 1139 else if (bRTS == false) { //RTS_needless
4f990057
MP
1140 pvRrvTime = (struct vnt_rrv_time_cts *)
1141 (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 1142 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1143 sizeof(struct vnt_rrv_time_cts));
351c7dc3 1144 rts_cts = (struct vnt_cts_fb *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1145 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
7c05c545 1146 pvTxDataHd = (struct vnt_tx_datahead_g_fb *) (pbyTxBufferAddr +
4f990057
MP
1147 wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
1148 cbMICHDR + sizeof(struct vnt_cts_fb));
1149 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
f0c5ba28 1150 cbMICHDR + sizeof(struct vnt_cts_fb) +
7c05c545 1151 sizeof(struct vnt_tx_datahead_g_fb);
92b96797
FB
1152 }
1153 } // Auto Fall Back
1154 }
1155 else {//802.11a/b packet
1156 if (byFBOption == AUTO_FB_NONE) {
4e9b5e2b 1157 if (bRTS == true) {//RTS_need
976467d3
MP
1158 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr +
1159 wTxBufSize);
5a5d6a80 1160 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
976467d3 1161 sizeof(struct vnt_rrv_time_ab));
351c7dc3 1162 rts_cts = (struct vnt_rts_ab *) (pbyTxBufferAddr + wTxBufSize +
976467d3 1163 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
558becf1
MP
1164 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1165 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
c521cb58 1166 sizeof(struct vnt_rts_ab));
976467d3
MP
1167 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1168 cbMICHDR + sizeof(struct vnt_rts_ab) +
558becf1 1169 sizeof(struct vnt_tx_datahead_ab);
92b96797 1170 }
e269fc2d 1171 else if (bRTS == false) { //RTS_needless, no MICHDR
976467d3
MP
1172 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1173 wTxBufSize);
5a5d6a80 1174 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
976467d3 1175 sizeof(struct vnt_rrv_time_ab));
558becf1
MP
1176 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
1177 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
976467d3 1178 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
558becf1 1179 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1180 }
1181 } else {
1182 // Auto Fall Back
4e9b5e2b 1183 if (bRTS == true) {//RTS_need
976467d3
MP
1184 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1185 wTxBufSize);
5a5d6a80 1186 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
976467d3 1187 sizeof(struct vnt_rrv_time_ab));
351c7dc3 1188 rts_cts = (struct vnt_rts_a_fb *)(pbyTxBufferAddr + wTxBufSize +
976467d3 1189 sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
1da4ee20
MP
1190 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1191 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
c521cb58 1192 sizeof(struct vnt_rts_a_fb));
976467d3
MP
1193 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1194 cbMICHDR + sizeof(struct vnt_rts_a_fb) +
1da4ee20 1195 sizeof(struct vnt_tx_datahead_a_fb);
92b96797 1196 }
e269fc2d 1197 else if (bRTS == false) { //RTS_needless
976467d3
MP
1198 pvRrvTime = (struct vnt_rrv_time_ab *)(pbyTxBufferAddr +
1199 wTxBufSize);
5a5d6a80 1200 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize +
976467d3 1201 sizeof(struct vnt_rrv_time_ab));
1da4ee20
MP
1202 pvTxDataHd = (struct vnt_tx_datahead_a_fb *)(pbyTxBufferAddr +
1203 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
976467d3 1204 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1da4ee20 1205 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
92b96797
FB
1206 }
1207 } // Auto Fall Back
1208 }
1209
b902fbfe
AM
1210 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1211 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1212 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
92b96797 1213
92b96797
FB
1214 //=========================
1215 // No Fragmentation
1216 //=========================
1217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1218 byFragType = FRAGCTL_NONFRAG;
1219 //uDMAIdx = TYPE_AC0DMA;
1220 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1221
92b96797 1222 //Fill FIFO,RrvTime,RTS,and CTS
8611a29a 1223 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
351c7dc3 1224 (void *)pbyTxBufferAddr, pvRrvTime, rts_cts,
f46142b0 1225 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, bRTS);
92b96797
FB
1226 //Fill DataHead
1227 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
ab01fedc 1228 byFBOption);
92b96797 1229 // Generate TX MAC Header
3eaca0d2 1230 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
92b96797
FB
1231 byFragType, uDMAIdx, 0);
1232
4e9b5e2b 1233 if (bNeedEncryption == true) {
92b96797 1234 //Fill TXKEY
b902fbfe 1235 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
ec37d8b6 1236 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
92b96797
FB
1237
1238 if (pDevice->bEnableHostWEP) {
1239 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1240 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1241 }
1242 }
1243
1244 // 802.1H
ceb8c5da 1245 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
203e4615 1246 if (pDevice->dwDiagRefCount == 0) {
ceb8c5da
AM
1247 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
1248 (psEthHeader->h_proto == cpu_to_le16(0xF380))) {
b902fbfe 1249 memcpy((u8 *) (pbyPayloadHead),
203e4615 1250 abySNAP_Bridgetunnel, 6);
92b96797 1251 } else {
b902fbfe 1252 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
92b96797 1253 }
b902fbfe 1254 pbyType = (u8 *) (pbyPayloadHead + 6);
ceb8c5da 1255 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
92b96797 1256 } else {
ceb8c5da 1257 memcpy((u8 *) (pbyPayloadHead), &(psEthHeader->h_proto), sizeof(u16));
92b96797
FB
1258
1259 }
1260
1261 }
1262
92b96797
FB
1263 if (pPacket != NULL) {
1264 // Copy the Packet into a tx Buffer
3e362598 1265 memcpy((pbyPayloadHead + cb802_1_H_len),
21ec51f3
CC
1266 (pPacket + ETH_HLEN),
1267 uSkbPacketLen - ETH_HLEN
92b96797
FB
1268 );
1269
1270 } else {
1271 // while bRelayPacketSend psEthHeader is point to header+payload
b902fbfe 1272 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
92b96797
FB
1273 }
1274
4e9b5e2b 1275 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
92b96797
FB
1276
1277 ///////////////////////////////////////////////////////////////////
1278
14c5ef57
MP
1279 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1280 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1281 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1282 }
92b96797 1283 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
52a7e64b
AM
1284 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1285 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
92b96797
FB
1286 }
1287 else {
52a7e64b
AM
1288 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1289 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
92b96797
FB
1290 }
1291 // DO Software Michael
1292 MIC_vInit(dwMICKey0, dwMICKey1);
ceb8c5da 1293 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
92b96797 1294 dwMIC_Priority = 0;
b902fbfe 1295 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
b4dc03af
MP
1296 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1297 dwMICKey0, dwMICKey1);
92b96797
FB
1298
1299 ///////////////////////////////////////////////////////////////////
1300
1301 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1302 //for (ii = 0; ii < cbFrameBodySize; ii++) {
b902fbfe 1303 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
92b96797
FB
1304 //}
1305 //DBG_PRN_GRP12(("\n\n\n"));
1306
1307 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1308
52a7e64b
AM
1309 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1310 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
92b96797
FB
1311
1312 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1313 MIC_vUnInit();
1314
4e9b5e2b 1315 if (pDevice->bTxMICFail == true) {
92b96797
FB
1316 *pdwMIC_L = 0;
1317 *pdwMIC_R = 0;
e269fc2d 1318 pDevice->bTxMICFail = false;
92b96797
FB
1319 }
1320 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1321 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1322 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1323 }
1324
4e9b5e2b 1325 if (bSoftWEP == true) {
92b96797 1326
3eaca0d2 1327 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
92b96797 1328
4e9b5e2b
AM
1329 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1330 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1331 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
92b96797
FB
1332 cbFrameSize -= cbICVlen;
1333 }
1334
92b96797 1335 cbFrameSize -= cbFCSlen;
92b96797
FB
1336
1337 *pcbHeaderLen = cbHeaderLength;
1338 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1339
92b96797 1340 //Set FragCtl in TxBufferHead
3eaca0d2 1341 pTxBufHead->wFragCtl |= (u16)byFragType;
92b96797 1342
4e9b5e2b 1343 return true;
92b96797
FB
1344
1345}
1346
92b96797
FB
1347/*+
1348 *
1349 * Description:
1350 * Translate 802.3 to 802.11 header
1351 *
1352 * Parameters:
1353 * In:
a0a1f61a 1354 * pDevice - Pointer to adapter
92b96797
FB
1355 * dwTxBufferAddr - Transmit Buffer
1356 * pPacket - Packet from upper layer
1357 * cbPacketSize - Transmit Data Length
1358 * Out:
1359 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1360 * pcbAppendPayload - size of append payload for 802.1H translation
1361 *
1362 * Return Value: none
1363 *
1364-*/
1365
d56131de 1366static void s_vGenerateMACHeader(struct vnt_private *pDevice,
ceb8c5da 1367 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
d56131de 1368 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
92b96797 1369{
1cac4a4b 1370 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
92b96797 1371
c921cc8c 1372 pMACHeader->frame_control = TYPE_802_11_DATA;
92b96797
FB
1373
1374 if (pDevice->eOPMode == OP_MODE_AP) {
1cac4a4b 1375 memcpy(&(pMACHeader->addr1[0]),
ceb8c5da 1376 &(psEthHeader->h_dest[0]),
9a0e756c 1377 ETH_ALEN);
1cac4a4b
AM
1378 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1379 memcpy(&(pMACHeader->addr3[0]),
ceb8c5da 1380 &(psEthHeader->h_source[0]),
9a0e756c 1381 ETH_ALEN);
1cac4a4b 1382 pMACHeader->frame_control |= FC_FROMDS;
9a0e756c
AM
1383 } else {
1384 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1cac4a4b 1385 memcpy(&(pMACHeader->addr1[0]),
ceb8c5da 1386 &(psEthHeader->h_dest[0]),
9a0e756c 1387 ETH_ALEN);
1cac4a4b 1388 memcpy(&(pMACHeader->addr2[0]),
ceb8c5da 1389 &(psEthHeader->h_source[0]),
9a0e756c 1390 ETH_ALEN);
1cac4a4b 1391 memcpy(&(pMACHeader->addr3[0]),
9a0e756c
AM
1392 &(pDevice->abyBSSID[0]),
1393 ETH_ALEN);
1394 } else {
1cac4a4b 1395 memcpy(&(pMACHeader->addr3[0]),
ceb8c5da 1396 &(psEthHeader->h_dest[0]),
9a0e756c 1397 ETH_ALEN);
1cac4a4b 1398 memcpy(&(pMACHeader->addr2[0]),
ceb8c5da 1399 &(psEthHeader->h_source[0]),
9a0e756c 1400 ETH_ALEN);
1cac4a4b 1401 memcpy(&(pMACHeader->addr1[0]),
9a0e756c
AM
1402 &(pDevice->abyBSSID[0]),
1403 ETH_ALEN);
1cac4a4b 1404 pMACHeader->frame_control |= FC_TODS;
92b96797
FB
1405 }
1406 }
1407
1408 if (bNeedEncrypt)
1cac4a4b 1409 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
92b96797 1410
1cac4a4b 1411 pMACHeader->duration_id = cpu_to_le16(wDuration);
92b96797
FB
1412
1413 if (pDevice->bLongHeader) {
1414 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1cac4a4b 1415 pMACHeader->frame_control |= (FC_TODS | FC_FROMDS);
3e362598 1416 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
92b96797 1417 }
1cac4a4b 1418 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1419
1420 //Set FragNumber in Sequence Control
1cac4a4b 1421 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
92b96797
FB
1422
1423 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1424 pDevice->wSeqCounter++;
1425 if (pDevice->wSeqCounter > 0x0fff)
1426 pDevice->wSeqCounter = 0;
1427 }
1428
1429 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1cac4a4b 1430 pMACHeader->frame_control |= FC_MOREFRAG;
92b96797
FB
1431 }
1432}
1433
92b96797
FB
1434/*+
1435 *
1436 * Description:
1437 * Request instructs a MAC to transmit a 802.11 management packet through
1438 * the adapter onto the medium.
1439 *
1440 * Parameters:
1441 * In:
1442 * hDeviceContext - Pointer to the adapter
1443 * pPacket - A pointer to a descriptor for the packet to transmit
1444 * Out:
1445 * none
1446 *
e269fc2d 1447 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
92b96797
FB
1448 *
1449-*/
1450
d56131de
MP
1451CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1452 struct vnt_tx_mgmt *pPacket)
92b96797 1453{
d56131de 1454 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 1455 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
1456 PSTxBufHead pTxBufHead;
1457 PUSB_SEND_CONTEXT pContext;
1cac4a4b 1458 struct ieee80211_hdr *pMACHeader;
ceb8c5da 1459 struct ethhdr sEthHeader;
d56131de 1460 u8 byPktType, *pbyTxBufferAddr;
351c7dc3
MP
1461 void *rts_cts = NULL;
1462 void *pvTxDataHd, *pvRrvTime, *pMICHDR;
d56131de 1463 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
e269fc2d 1464 int bNeedACK, bIsPSPOLL = false;
d56131de
MP
1465 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1466 u32 uPadding = 0;
1467 u16 wTxBufSize;
1468 u32 cbMacHdLen;
1469 u16 wCurrentRate = RATE_1M;
92b96797 1470
92b96797
FB
1471 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1472
1473 if (NULL == pContext) {
1474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1475 return CMD_STATUS_RESOURCES;
1476 }
1477
f39c0d8e 1478 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
b902fbfe 1479 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->adwTxKey[0]);
92b96797
FB
1480 cbFrameBodySize = pPacket->cbPayloadLen;
1481 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1482 wTxBufSize = sizeof(STxBufHead);
92b96797
FB
1483
1484 if (pDevice->byBBType == BB_TYPE_11A) {
1485 wCurrentRate = RATE_6M;
1486 byPktType = PK_TYPE_11A;
1487 } else {
1488 wCurrentRate = RATE_1M;
1489 byPktType = PK_TYPE_11B;
1490 }
1491
1492 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1493 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1494 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1495 // to set power here.
1496 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1497 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1498 } else {
1499 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1500 }
1501 pDevice->wCurrentRate = wCurrentRate;
1502
92b96797
FB
1503 //Set packet type
1504 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1505 pTxBufHead->wFIFOCtl = 0;
1506 }
1507 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1508 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1509 }
1510 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1511 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1512 }
1513 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1514 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1515 }
1516
1517 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1518 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1519
22040bbf 1520 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
e269fc2d 1521 bNeedACK = false;
92b96797
FB
1522 }
1523 else {
4e9b5e2b 1524 bNeedACK = true;
92b96797
FB
1525 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1526 };
1527
1528 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1529 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1530
1531 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1532 //Set Preamble type always long
1533 //pDevice->byPreambleType = PREAMBLE_LONG;
1534 // probe-response don't retry
1535 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
e269fc2d 1536 // bNeedACK = false;
92b96797
FB
1537 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1538 //}
1539 }
1540
1541 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1542
1543 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
4e9b5e2b 1544 bIsPSPOLL = true;
92b96797
FB
1545 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1546 } else {
1547 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1548 }
1549
1550 //Set FRAGCTL_MACHDCNT
3eaca0d2 1551 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
92b96797
FB
1552
1553 // Notes:
1554 // Although spec says MMPDU can be fragmented; In most case,
1555 // no one will send a MMPDU under fragmentation. With RTS may occur.
e269fc2d 1556 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
92b96797
FB
1557
1558 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1559 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1560 cbIVlen = 4;
1561 cbICVlen = 4;
1562 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1563 }
1564 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1565 cbIVlen = 8;//IV+ExtIV
1566 cbMIClen = 8;
1567 cbICVlen = 4;
1568 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1569 //We need to get seed here for filling TxKey entry.
1570 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1571 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1572 }
1573 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1574 cbIVlen = 8;//RSN Header
1575 cbICVlen = 8;//MIC
1576 pTxBufHead->wFragCtl |= FRAGCTL_AES;
4e9b5e2b 1577 pDevice->bAES = true;
92b96797
FB
1578 }
1579 //MAC Header should be padding 0 to DW alignment.
1580 uPadding = 4 - (cbMacHdLen%4);
1581 uPadding %= 4;
1582 }
1583
1584 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1585
1586 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1587 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1588 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1589 }
1590 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1591
1592 //Set RrvTime/RTS/CTS Buffer
1593 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1594
4f990057 1595 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
92b96797 1596 pMICHDR = NULL;
351c7dc3 1597 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
4f990057 1598 sizeof(struct vnt_rrv_time_cts));
7e60a3de 1599 pvTxDataHd = (struct vnt_tx_datahead_g *)(pbyTxBufferAddr + wTxBufSize +
4f990057
MP
1600 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
1601 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
7e60a3de 1602 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
92b96797
FB
1603 }
1604 else { // 802.11a/b packet
976467d3 1605 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
92b96797 1606 pMICHDR = NULL;
558becf1
MP
1607 pvTxDataHd = (struct vnt_tx_datahead_ab *) (pbyTxBufferAddr +
1608 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
976467d3 1609 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
558becf1 1610 sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1611 }
1612
ceb8c5da 1613 memcpy(&(sEthHeader.h_dest[0]),
9a0e756c
AM
1614 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1615 ETH_ALEN);
ceb8c5da 1616 memcpy(&(sEthHeader.h_source[0]),
9a0e756c
AM
1617 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1618 ETH_ALEN);
92b96797
FB
1619 //=========================
1620 // No Fragmentation
1621 //=========================
3eaca0d2 1622 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
92b96797 1623
351c7dc3
MP
1624 /* Fill FIFO,RrvTime,RTS,and CTS */
1625 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1626 pbyTxBufferAddr, pvRrvTime, rts_cts,
f46142b0 1627 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
92b96797
FB
1628
1629 //Fill DataHead
1630 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
ab01fedc 1631 AUTO_FB_NONE);
92b96797 1632
1cac4a4b 1633 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
92b96797
FB
1634
1635 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1636
1637 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
b902fbfe
AM
1638 u8 * pbyIVHead;
1639 u8 * pbyPayloadHead;
1640 u8 * pbyBSSID;
92b96797
FB
1641 PSKeyItem pTransmitKey = NULL;
1642
b902fbfe
AM
1643 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1644 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
92b96797
FB
1645 do {
1646 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
4e9b5e2b 1647 (pDevice->bLinkPass == true)) {
92b96797
FB
1648 pbyBSSID = pDevice->abyBSSID;
1649 // get pairwise key
e269fc2d 1650 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
92b96797 1651 // get group key
4e9b5e2b 1652 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
92b96797
FB
1653 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1654 break;
1655 }
1656 } else {
1657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1658 break;
1659 }
1660 }
1661 // get group key
1662 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 1663 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
1664 pTransmitKey = NULL;
1665 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
1666 } else {
1667 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1668 }
e269fc2d 1669 } while(false);
92b96797 1670 //Fill TXKEY
b902fbfe 1671 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
3eaca0d2 1672 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
92b96797 1673
3e362598 1674 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
b902fbfe 1675 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
92b96797
FB
1676 cbFrameBodySize);
1677 }
1678 else {
1679 // Copy the Packet into a tx Buffer
3e362598 1680 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
92b96797
FB
1681 }
1682
1cac4a4b 1683 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1684 pDevice->wSeqCounter++ ;
1685 if (pDevice->wSeqCounter > 0x0fff)
1686 pDevice->wSeqCounter = 0;
1687
1688 if (bIsPSPOLL) {
1689 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
a0a1f61a 1690 // of FIFO control header.
92b96797
FB
1691 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1692 // in the same place of other packet's Duration-field).
1693 // And it will cause Cisco-AP to issue Disassociation-packet
7e60a3de
MP
1694 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1695 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
1696 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1697 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
1698 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1699 } else {
558becf1
MP
1700 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
1701 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1702 }
92b96797
FB
1703 }
1704
3eaca0d2 1705 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
b902fbfe 1706 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
1707 pTX_Buffer->byType = 0x00;
1708
1709 pContext->pPacket = NULL;
1710 pContext->Type = CONTEXT_MGMT_PACKET;
3eaca0d2 1711 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
92b96797 1712
1cac4a4b
AM
1713 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
1714 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
1715 }
1716 else {
1cac4a4b 1717 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
1718 }
1719
1720 PIPEnsSendBulkOut(pDevice,pContext);
1721 return CMD_STATUS_PENDING;
1722}
1723
d56131de
MP
1724CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1725 struct vnt_tx_mgmt *pPacket)
92b96797 1726{
01f865ba 1727 struct vnt_beacon_buffer *pTX_Buffer;
d56131de
MP
1728 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1729 u32 cbHeaderSize = 0;
1730 u16 wTxBufSize = sizeof(STxShortBufHead);
1731 PSTxShortBufHead pTxBufHead;
1cac4a4b 1732 struct ieee80211_hdr *pMACHeader;
558becf1 1733 struct vnt_tx_datahead_ab *pTxDataHead;
d56131de
MP
1734 u16 wCurrentRate;
1735 u32 cbFrameBodySize;
1736 u32 cbReqCount;
d56131de
MP
1737 u8 *pbyTxBufferAddr;
1738 PUSB_SEND_CONTEXT pContext;
1739 CMD_STATUS status;
92b96797 1740
92b96797
FB
1741 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1742 if (NULL == pContext) {
1743 status = CMD_STATUS_RESOURCES;
1744 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1745 return status ;
1746 }
01f865ba
MP
1747
1748 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->Data[0];
b902fbfe 1749 pbyTxBufferAddr = (u8 *)&(pTX_Buffer->wFIFOCtl);
92b96797
FB
1750
1751 cbFrameBodySize = pPacket->cbPayloadLen;
1752
1753 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
1754 wTxBufSize = sizeof(STxShortBufHead);
92b96797
FB
1755
1756 if (pDevice->byBBType == BB_TYPE_11A) {
1757 wCurrentRate = RATE_6M;
558becf1
MP
1758 pTxDataHead = (struct vnt_tx_datahead_ab *)
1759 (pbyTxBufferAddr + wTxBufSize);
92b96797 1760 //Get SignalField,ServiceField,Length
aed387c7
MP
1761 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
1762 &pTxDataHead->ab);
92b96797 1763 //Get Duration and TimeStampOff
d5005955 1764 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
6b5ad9d2 1765 PK_TYPE_11A, false);
f115e76a 1766 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
558becf1 1767 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1768 } else {
1769 wCurrentRate = RATE_1M;
1770 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
558becf1
MP
1771 pTxDataHead = (struct vnt_tx_datahead_ab *)
1772 (pbyTxBufferAddr + wTxBufSize);
92b96797 1773 //Get SignalField,ServiceField,Length
aed387c7
MP
1774 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
1775 &pTxDataHead->ab);
92b96797 1776 //Get Duration and TimeStampOff
d5005955 1777 pTxDataHead->wDuration = s_uGetDataDuration(pDevice,
6b5ad9d2 1778 PK_TYPE_11B, false);
f115e76a 1779 pTxDataHead->wTimeStampOff = vnt_time_stamp_off(pDevice, wCurrentRate);
558becf1 1780 cbHeaderSize = wTxBufSize + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1781 }
1782
1783 //Generate Beacon Header
1cac4a4b 1784 pMACHeader = (struct ieee80211_hdr *)(pbyTxBufferAddr + cbHeaderSize);
3e362598 1785 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
92b96797 1786
1cac4a4b
AM
1787 pMACHeader->duration_id = 0;
1788 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1789 pDevice->wSeqCounter++ ;
1790 if (pDevice->wSeqCounter > 0x0fff)
1791 pDevice->wSeqCounter = 0;
1792
1793 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1794
3eaca0d2 1795 pTX_Buffer->wTxByteCount = (u16)cbReqCount;
b902fbfe 1796 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
1797 pTX_Buffer->byType = 0x01;
1798
1799 pContext->pPacket = NULL;
1800 pContext->Type = CONTEXT_MGMT_PACKET;
3eaca0d2 1801 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
92b96797
FB
1802
1803 PIPEnsSendBulkOut(pDevice,pContext);
1804 return CMD_STATUS_PENDING;
1805
1806}
1807
d56131de
MP
1808void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
1809{
1810 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 1811 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
1812 u8 byPktType;
1813 u8 *pbyTxBufferAddr;
351c7dc3
MP
1814 void *rts_cts = NULL;
1815 void *pvTxDataHd;
d56131de 1816 u32 uDuration, cbReqCount;
1cac4a4b 1817 struct ieee80211_hdr *pMACHeader;
d56131de 1818 u32 cbHeaderSize, cbFrameBodySize;
e269fc2d 1819 int bNeedACK, bIsPSPOLL = false;
d56131de
MP
1820 PSTxBufHead pTxBufHead;
1821 u32 cbFrameSize;
1822 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1823 u32 uPadding = 0;
1824 u32 cbMICHDR = 0, uLength = 0;
1825 u32 dwMICKey0, dwMICKey1;
1826 u32 dwMIC_Priority;
1827 u32 *pdwMIC_L, *pdwMIC_R;
1828 u16 wTxBufSize;
1829 u32 cbMacHdLen;
ceb8c5da 1830 struct ethhdr sEthHeader;
d56131de
MP
1831 void *pvRrvTime, *pMICHDR;
1832 u32 wCurrentRate = RATE_1M;
1833 PUWLAN_80211HDR p80211Header;
1834 u32 uNodeIndex = 0;
e269fc2d 1835 int bNodeExist = false;
d56131de
MP
1836 SKeyItem STempKey;
1837 PSKeyItem pTransmitKey = NULL;
1838 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
1839 u32 cbExtSuppRate = 0;
d56131de 1840 PUSB_SEND_CONTEXT pContext;
92b96797 1841
351c7dc3 1842 pvRrvTime = pMICHDR = pvTxDataHd = NULL;
92b96797
FB
1843
1844 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
1845 cbFrameBodySize = 0;
1846 }
1847 else {
1848 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
1849 }
1850 p80211Header = (PUWLAN_80211HDR)skb->data;
1851
1852 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1853
1854 if (NULL == pContext) {
1855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
1856 dev_kfree_skb_irq(skb);
1857 return ;
1858 }
1859
f39c0d8e 1860 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
b902fbfe 1861 pbyTxBufferAddr = (u8 *)(&pTX_Buffer->adwTxKey[0]);
92b96797
FB
1862 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1863 wTxBufSize = sizeof(STxBufHead);
92b96797
FB
1864
1865 if (pDevice->byBBType == BB_TYPE_11A) {
1866 wCurrentRate = RATE_6M;
1867 byPktType = PK_TYPE_11A;
1868 } else {
1869 wCurrentRate = RATE_1M;
1870 byPktType = PK_TYPE_11B;
1871 }
1872
1873 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
1874 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
1875 // And cmd timer will wait data pkt TX finish before scanning so it's OK
1876 // to set power here.
1877 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
1878 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
1879 } else {
1880 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
1881 }
1882
1883 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
1884
1885 //Set packet type
1886 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1887 pTxBufHead->wFIFOCtl = 0;
1888 }
1889 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1890 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1891 }
1892 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1893 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1894 }
1895 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1896 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1897 }
1898
1899 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1900 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1901
22040bbf 1902 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
e269fc2d 1903 bNeedACK = false;
92b96797
FB
1904 if (pDevice->bEnableHostWEP) {
1905 uNodeIndex = 0;
4e9b5e2b 1906 bNodeExist = true;
9fc86028 1907 }
92b96797
FB
1908 }
1909 else {
1910 if (pDevice->bEnableHostWEP) {
b902fbfe 1911 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
4e9b5e2b 1912 bNodeExist = true;
9fc86028 1913 }
4e9b5e2b 1914 bNeedACK = true;
92b96797
FB
1915 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1916 };
1917
1918 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1919 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1920
1921 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1922 //Set Preamble type always long
1923 //pDevice->byPreambleType = PREAMBLE_LONG;
1924
1925 // probe-response don't retry
1926 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
e269fc2d 1927 // bNeedACK = false;
92b96797
FB
1928 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1929 //}
1930 }
1931
1932 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1933
1934 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
4e9b5e2b 1935 bIsPSPOLL = true;
92b96797
FB
1936 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1937 } else {
1938 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1939 }
1940
a0a1f61a 1941 // hostapd daemon ext support rate patch
92b96797
FB
1942 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
1943
1944 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
1945 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
1946 }
1947
1948 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
1949 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
1950 }
1951
1952 if (cbExtSuppRate >0) {
1953 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
1954 }
1955 }
1956
92b96797 1957 //Set FRAGCTL_MACHDCNT
3eaca0d2 1958 pTxBufHead->wFragCtl |= cpu_to_le16((u16)cbMacHdLen << 10);
92b96797
FB
1959
1960 // Notes:
1961 // Although spec says MMPDU can be fragmented; In most case,
1962 // no one will send a MMPDU under fragmentation. With RTS may occur.
e269fc2d 1963 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
92b96797 1964
92b96797
FB
1965 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
1966 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1967 cbIVlen = 4;
1968 cbICVlen = 4;
1969 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1970 }
1971 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1972 cbIVlen = 8;//IV+ExtIV
1973 cbMIClen = 8;
1974 cbICVlen = 4;
1975 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1976 //We need to get seed here for filling TxKey entry.
1977 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1978 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1979 }
1980 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1981 cbIVlen = 8;//RSN Header
1982 cbICVlen = 8;//MIC
5a5d6a80 1983 cbMICHDR = sizeof(struct vnt_mic_hdr);
92b96797 1984 pTxBufHead->wFragCtl |= FRAGCTL_AES;
4e9b5e2b 1985 pDevice->bAES = true;
92b96797
FB
1986 }
1987 //MAC Header should be padding 0 to DW alignment.
1988 uPadding = 4 - (cbMacHdLen%4);
1989 uPadding %= 4;
1990 }
1991
1992 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
1993
1994 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1995 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1996 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1997 }
1998 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1999
92b96797 2000 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
4f990057 2001 pvRrvTime = (struct vnt_rrv_time_cts *) (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 2002 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
4f990057 2003 sizeof(struct vnt_rrv_time_cts));
351c7dc3 2004 rts_cts = (struct vnt_cts *) (pbyTxBufferAddr + wTxBufSize +
4f990057 2005 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
7e60a3de
MP
2006 pvTxDataHd = (struct vnt_tx_datahead_g *) (pbyTxBufferAddr +
2007 wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
4f990057
MP
2008 sizeof(struct vnt_cts));
2009 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) + cbMICHDR +
7e60a3de 2010 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
92b96797
FB
2011
2012 }
2013 else {//802.11a/b packet
2014
976467d3 2015 pvRrvTime = (struct vnt_rrv_time_ab *) (pbyTxBufferAddr + wTxBufSize);
5a5d6a80 2016 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr + wTxBufSize +
976467d3 2017 sizeof(struct vnt_rrv_time_ab));
558becf1
MP
2018 pvTxDataHd = (struct vnt_tx_datahead_ab *)(pbyTxBufferAddr +
2019 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
976467d3 2020 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR +
558becf1 2021 sizeof(struct vnt_tx_datahead_ab);
92b96797 2022 }
ceb8c5da 2023 memcpy(&(sEthHeader.h_dest[0]),
9a0e756c
AM
2024 &(p80211Header->sA3.abyAddr1[0]),
2025 ETH_ALEN);
ceb8c5da 2026 memcpy(&(sEthHeader.h_source[0]),
9a0e756c
AM
2027 &(p80211Header->sA3.abyAddr2[0]),
2028 ETH_ALEN);
92b96797
FB
2029 //=========================
2030 // No Fragmentation
2031 //=========================
3eaca0d2 2032 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
92b96797 2033
351c7dc3
MP
2034 /* Fill FIFO,RrvTime,RTS,and CTS */
2035 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
2036 pbyTxBufferAddr, pvRrvTime, rts_cts,
f46142b0 2037 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, false);
92b96797
FB
2038
2039 //Fill DataHead
2040 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
ab01fedc 2041 AUTO_FB_NONE);
92b96797 2042
1cac4a4b 2043 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
92b96797
FB
2044
2045 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2046
b902fbfe
AM
2047 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderSize);
2048 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2049 pbyIVHead = (u8 *)(pbyMacHdr + cbMacHdLen + uPadding);
92b96797
FB
2050
2051 // Copy the Packet into a tx Buffer
2052 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2053
2054 // version set to 0, patch for hostapd deamon
1cac4a4b 2055 pMACHeader->frame_control &= cpu_to_le16(0xfffc);
92b96797
FB
2056 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2057
a0a1f61a 2058 // replace support rate, patch for hostapd daemon( only support 11M)
92b96797
FB
2059 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2060 if (cbExtSuppRate != 0) {
2061 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2062 memcpy((pbyPayloadHead + cbFrameBodySize),
2063 pMgmt->abyCurrSuppRates,
2064 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2065 );
2066 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2067 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2068 pMgmt->abyCurrExtSuppRates,
2069 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2070 );
2071 }
2072 }
2073
2074 // Set wep
2075 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2076
2077 if (pDevice->bEnableHostWEP) {
2078 pTransmitKey = &STempKey;
2079 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2080 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2081 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2082 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2083 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2084 memcpy(pTransmitKey->abyKey,
2085 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2086 pTransmitKey->uKeyLength
2087 );
2088 }
2089
2090 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2091
52a7e64b
AM
2092 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2093 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
92b96797
FB
2094
2095 // DO Software Michael
2096 MIC_vInit(dwMICKey0, dwMICKey1);
ceb8c5da 2097 MIC_vAppend((u8 *)&(sEthHeader.h_dest[0]), 12);
92b96797 2098 dwMIC_Priority = 0;
b902fbfe 2099 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
b4dc03af
MP
2100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY:"\
2101 " %X, %X\n", dwMICKey0, dwMICKey1);
92b96797
FB
2102
2103 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2104
2105 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2106
52a7e64b
AM
2107 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2108 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
92b96797
FB
2109
2110 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2111 MIC_vUnInit();
2112
4e9b5e2b 2113 if (pDevice->bTxMICFail == true) {
92b96797
FB
2114 *pdwMIC_L = 0;
2115 *pdwMIC_R = 0;
e269fc2d 2116 pDevice->bTxMICFail = false;
92b96797
FB
2117 }
2118
2119 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
b4dc03af
MP
2121 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%x, %x\n",
2122 *pdwMIC_L, *pdwMIC_R);
92b96797
FB
2123
2124 }
2125
b902fbfe 2126 s_vFillTxKey(pDevice, (u8 *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
ec37d8b6 2127 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
92b96797
FB
2128
2129 if (pDevice->bEnableHostWEP) {
2130 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2131 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2132 }
2133
2134 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
3eaca0d2 2135 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (u16)(cbFrameBodySize + cbMIClen));
92b96797
FB
2136 }
2137 }
2138
1cac4a4b 2139 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
2140 pDevice->wSeqCounter++ ;
2141 if (pDevice->wSeqCounter > 0x0fff)
2142 pDevice->wSeqCounter = 0;
2143
92b96797
FB
2144 if (bIsPSPOLL) {
2145 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2146 // of FIFO control header.
2147 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2148 // in the same place of other packet's Duration-field).
2149 // And it will cause Cisco-AP to issue Disassociation-packet
7e60a3de
MP
2150 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2151 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_a =
2152 cpu_to_le16(p80211Header->sA2.wDurationID);
2153 ((struct vnt_tx_datahead_g *)pvTxDataHd)->wDuration_b =
2154 cpu_to_le16(p80211Header->sA2.wDurationID);
2155 } else {
558becf1
MP
2156 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->wDuration =
2157 cpu_to_le16(p80211Header->sA2.wDurationID);
2158 }
92b96797
FB
2159 }
2160
3eaca0d2 2161 pTX_Buffer->wTxByteCount = cpu_to_le16((u16)(cbReqCount));
b902fbfe 2162 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
2163 pTX_Buffer->byType = 0x00;
2164
2165 pContext->pPacket = skb;
2166 pContext->Type = CONTEXT_MGMT_PACKET;
3eaca0d2 2167 pContext->uBufLen = (u16)cbReqCount + 4; //USB header
92b96797 2168
1cac4a4b
AM
2169 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
2170 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr1[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
2171 }
2172 else {
1cac4a4b 2173 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->addr3[0]), (u16)cbFrameSize, pTX_Buffer->wFIFOCtl);
92b96797
FB
2174 }
2175 PIPEnsSendBulkOut(pDevice,pContext);
2176 return ;
2177
2178}
2179
92b96797
FB
2180//TYPE_AC0DMA data tx
2181/*
2182 * Description:
2183 * Tx packet via AC0DMA(DMA1)
2184 *
2185 * Parameters:
2186 * In:
2187 * pDevice - Pointer to the adapter
2188 * skb - Pointer to tx skb packet
2189 * Out:
2190 * void
2191 *
2192 * Return Value: NULL
2193 */
2194
d56131de
MP
2195int nsDMA_tx_packet(struct vnt_private *pDevice,
2196 u32 uDMAIdx, struct sk_buff *skb)
92b96797 2197{
d56131de
MP
2198 struct net_device_stats *pStats = &pDevice->stats;
2199 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 2200 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
2201 u32 BytesToWrite = 0, uHeaderLen = 0;
2202 u32 uNodeIndex = 0;
2203 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2204 u16 wAID;
2205 u8 byPktType;
e269fc2d 2206 int bNeedEncryption = false;
d56131de
MP
2207 PSKeyItem pTransmitKey = NULL;
2208 SKeyItem STempKey;
2209 int ii;
e269fc2d
AM
2210 int bTKIP_UseGTK = false;
2211 int bNeedDeAuth = false;
d56131de 2212 u8 *pbyBSSID;
e269fc2d 2213 int bNodeExist = false;
d56131de 2214 PUSB_SEND_CONTEXT pContext;
dfdcc425 2215 bool fConvertedPacket;
d56131de
MP
2216 u32 status;
2217 u16 wKeepRate = pDevice->wCurrentRate;
e269fc2d 2218 int bTxeapol_key = false;
92b96797 2219
92b96797
FB
2220 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2221
2222 if (pDevice->uAssocCount == 0) {
2223 dev_kfree_skb_irq(skb);
2224 return 0;
2225 }
2226
b902fbfe 2227 if (is_multicast_ether_addr((u8 *)(skb->data))) {
92b96797 2228 uNodeIndex = 0;
4e9b5e2b 2229 bNodeExist = true;
92b96797
FB
2230 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2231
2232 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2233 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2234 // set tx map
2235 pMgmt->abyPSTxMap[0] |= byMask[0];
2236 return 0;
2237 }
93184690 2238 // multicast/broadcast data rate
92b96797
FB
2239
2240 if (pDevice->byBBType != BB_TYPE_11A)
2241 pDevice->wCurrentRate = RATE_2M;
2242 else
2243 pDevice->wCurrentRate = RATE_24M;
2244 // long preamble type
2245 pDevice->byPreambleType = PREAMBLE_SHORT;
2246
2247 }else {
2248
b902fbfe 2249 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
92b96797
FB
2250
2251 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2252
2253 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2254
2255 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2256 // set tx map
2257 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2258 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2260 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2261
2262 return 0;
2263 }
2264 // AP rate decided from node
2265 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2266 // tx preamble decided from node
2267
2268 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2269 pDevice->byPreambleType = pDevice->byShortPreamble;
2270
2271 }else {
2272 pDevice->byPreambleType = PREAMBLE_LONG;
2273 }
4e9b5e2b 2274 bNodeExist = true;
92b96797
FB
2275 }
2276 }
2277
e269fc2d 2278 if (bNodeExist == false) {
92b96797
FB
2279 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2280 dev_kfree_skb_irq(skb);
2281 return 0;
2282 }
2283 }
2284
2285 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2286
2287 if (pContext == NULL) {
2288 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2289 dev_kfree_skb_irq(skb);
2290 return STATUS_RESOURCES;
2291 }
2292
ceb8c5da 2293 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)(skb->data), ETH_HLEN);
92b96797
FB
2294
2295//mike add:station mode check eapol-key challenge--->
2296{
b902fbfe
AM
2297 u8 Protocol_Version; //802.1x Authentication
2298 u8 Packet_Type; //802.1x Authentication
2299 u8 Descriptor_type;
3eaca0d2 2300 u16 Key_info;
92b96797 2301
21ec51f3
CC
2302 Protocol_Version = skb->data[ETH_HLEN];
2303 Packet_Type = skb->data[ETH_HLEN+1];
2304 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2305 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
ceb8c5da 2306 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
aa209eef
MP
2307 /* 802.1x OR eapol-key challenge frame transfer */
2308 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2309 (Packet_Type == 3)) {
4e9b5e2b 2310 bTxeapol_key = true;
92b96797
FB
2311 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2312 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2313 if(Descriptor_type==254) {
4e9b5e2b 2314 pDevice->fWPA_Authened = true;
92b96797
FB
2315 PRINT_K("WPA ");
2316 }
2317 else {
4e9b5e2b 2318 pDevice->fWPA_Authened = true;
92b96797
FB
2319 PRINT_K("WPA2(re-keying) ");
2320 }
2321 PRINT_K("Authentication completed!!\n");
2322 }
a0a1f61a 2323 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
92b96797 2324 (Key_info & BIT8) && (Key_info & BIT9)) {
4e9b5e2b 2325 pDevice->fWPA_Authened = true;
92b96797
FB
2326 PRINT_K("WPA2 Authentication completed!!\n");
2327 }
2328 }
2329 }
2330}
2331//mike add:station mode check eapol-key challenge<---
2332
4e9b5e2b
AM
2333 if (pDevice->bEncryptionEnable == true) {
2334 bNeedEncryption = true;
92b96797
FB
2335 // get Transmit key
2336 do {
2337 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2338 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2339 pbyBSSID = pDevice->abyBSSID;
2340 // get pairwise key
e269fc2d 2341 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
92b96797 2342 // get group key
4e9b5e2b
AM
2343 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2344 bTKIP_UseGTK = true;
92b96797
FB
2345 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2346 break;
2347 }
2348 } else {
2349 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2350 break;
2351 }
2352 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
ceb8c5da
AM
2353 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
2354 pbyBSSID = pDevice->sTxEthHeader.h_dest;
92b96797
FB
2355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2356 for (ii = 0; ii< 6; ii++)
2357 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2359
2360 // get pairwise key
4e9b5e2b 2361 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
92b96797
FB
2362 break;
2363 }
2364 // get group key
2365 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 2366 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
2367 pTransmitKey = NULL;
2368 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2369 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2370 }
2371 else
2372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2373 } else {
4e9b5e2b 2374 bTKIP_UseGTK = true;
92b96797
FB
2375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2376 }
e269fc2d 2377 } while(false);
92b96797
FB
2378 }
2379
2380 if (pDevice->bEnableHostWEP) {
2381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
4e9b5e2b 2382 if (pDevice->bEncryptionEnable == true) {
92b96797
FB
2383 pTransmitKey = &STempKey;
2384 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2385 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2386 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2387 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2388 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2389 memcpy(pTransmitKey->abyKey,
2390 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2391 pTransmitKey->uKeyLength
2392 );
2393 }
2394 }
2395
b902fbfe 2396 byPktType = (u8)pDevice->byPacketType;
92b96797
FB
2397
2398 if (pDevice->bFixRate) {
2399 if (pDevice->byBBType == BB_TYPE_11B) {
2400 if (pDevice->uConnectionRate >= RATE_11M) {
2401 pDevice->wCurrentRate = RATE_11M;
2402 } else {
3eaca0d2 2403 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2404 }
2405 } else {
2406 if ((pDevice->byBBType == BB_TYPE_11A) &&
2407 (pDevice->uConnectionRate <= RATE_6M)) {
2408 pDevice->wCurrentRate = RATE_6M;
2409 } else {
2410 if (pDevice->uConnectionRate >= RATE_54M)
2411 pDevice->wCurrentRate = RATE_54M;
2412 else
3eaca0d2 2413 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2414 }
2415 }
2416 }
2417 else {
2418 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2419 // Adhoc Tx rate decided from node DB
ceb8c5da 2420 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
92b96797
FB
2421 // Multicast use highest data rate
2422 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2423 // preamble type
2424 pDevice->byPreambleType = pDevice->byShortPreamble;
2425 }
2426 else {
ceb8c5da 2427 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
92b96797
FB
2428 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2429 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2430 pDevice->byPreambleType = pDevice->byShortPreamble;
2431
2432 }
2433 else {
2434 pDevice->byPreambleType = PREAMBLE_LONG;
2435 }
2436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2437 }
2438 else {
2439 if (pDevice->byBBType != BB_TYPE_11A)
2440 pDevice->wCurrentRate = RATE_2M;
2441 else
2442 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
2443 // abyCurrExtSuppRates[]
2444 pDevice->byPreambleType = PREAMBLE_SHORT;
2445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2446 }
2447 }
2448 }
2449 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2450 // Infra STA rate decided from AP Node, index = 0
2451 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2452 }
2453 }
2454
ceb8c5da 2455 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
aa209eef
MP
2456 if (pDevice->byBBType != BB_TYPE_11A) {
2457 pDevice->wCurrentRate = RATE_1M;
2458 pDevice->byACKRate = RATE_1M;
2459 pDevice->byTopCCKBasicRate = RATE_1M;
2460 pDevice->byTopOFDMBasicRate = RATE_6M;
2461 } else {
2462 pDevice->wCurrentRate = RATE_6M;
2463 pDevice->byACKRate = RATE_6M;
2464 pDevice->byTopCCKBasicRate = RATE_1M;
2465 pDevice->byTopOFDMBasicRate = RATE_6M;
2466 }
2467 }
92b96797 2468
0cbd8d98
AM
2469 DBG_PRT(MSG_LEVEL_DEBUG,
2470 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
2471 pDevice->wCurrentRate);
92b96797
FB
2472
2473 if (wKeepRate != pDevice->wCurrentRate) {
0cbd8d98 2474 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
92b96797
FB
2475 }
2476
2477 if (pDevice->wCurrentRate <= RATE_11M) {
2478 byPktType = PK_TYPE_11B;
2479 }
2480
4e9b5e2b 2481 if (bNeedEncryption == true) {
ceb8c5da
AM
2482 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
2483 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
e269fc2d 2484 bNeedEncryption = false;
ceb8c5da 2485 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
92b96797
FB
2486 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2487 if (pTransmitKey == NULL) {
2488 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2489 }
2490 else {
4e9b5e2b 2491 if (bTKIP_UseGTK == true) {
92b96797
FB
2492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2493 }
2494 else {
b4dc03af
MP
2495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2496 pTransmitKey->dwKeyIndex);
4e9b5e2b 2497 bNeedEncryption = true;
92b96797
FB
2498 }
2499 }
2500 }
2501
92b96797
FB
2502 if (pDevice->bEnableHostWEP) {
2503 if ((uNodeIndex != 0) &&
2504 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
b4dc03af
MP
2505 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
2506 pTransmitKey->dwKeyIndex);
4e9b5e2b 2507 bNeedEncryption = true;
92b96797
FB
2508 }
2509 }
2510 }
2511 else {
2512
92b96797
FB
2513 if (pTransmitKey == NULL) {
2514 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
e269fc2d 2515 pContext->bBoolInUse = false;
92b96797
FB
2516 dev_kfree_skb_irq(skb);
2517 pStats->tx_dropped++;
2518 return STATUS_FAILURE;
2519 }
92b96797
FB
2520 }
2521 }
2522
d0a2b8fa
MP
2523 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2524
92b96797 2525 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
d0a2b8fa 2526 pTX_Buffer, bNeedEncryption,
92b96797 2527 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
b902fbfe 2528 (u8 *)skb->data, pTransmitKey, uNodeIndex,
92b96797
FB
2529 pDevice->wCurrentRate,
2530 &uHeaderLen, &BytesToWrite
2531 );
2532
e269fc2d
AM
2533 if (fConvertedPacket == false) {
2534 pContext->bBoolInUse = false;
92b96797
FB
2535 dev_kfree_skb_irq(skb);
2536 return STATUS_FAILURE;
2537 }
2538
4e9b5e2b 2539 if ( pDevice->bEnablePSMode == true ) {
92b96797 2540 if ( !pDevice->bPSModeTxBurst ) {
0cbd8d98
AM
2541 bScheduleCommand((void *) pDevice,
2542 WLAN_CMD_MAC_DISPOWERSAVING,
2543 NULL);
4e9b5e2b 2544 pDevice->bPSModeTxBurst = true;
92b96797
FB
2545 }
2546 }
2547
b902fbfe 2548 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3eaca0d2 2549 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
92b96797
FB
2550
2551 pContext->pPacket = skb;
2552 pContext->Type = CONTEXT_DATA_PACKET;
3eaca0d2 2553 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
92b96797 2554
ceb8c5da 2555 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
92b96797
FB
2556
2557 status = PIPEnsSendBulkOut(pDevice,pContext);
2558
4e9b5e2b 2559 if (bNeedDeAuth == true) {
3eaca0d2 2560 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
92b96797 2561
b902fbfe 2562 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
92b96797
FB
2563 }
2564
2565 if(status!=STATUS_PENDING) {
e269fc2d 2566 pContext->bBoolInUse = false;
92b96797
FB
2567 dev_kfree_skb_irq(skb);
2568 return STATUS_FAILURE;
2569 }
2570 else
2571 return 0;
2572
2573}
2574
92b96797
FB
2575/*
2576 * Description:
2577 * Relay packet send (AC1DMA) from rx dpc.
2578 *
2579 * Parameters:
2580 * In:
2581 * pDevice - Pointer to the adapter
2582 * pPacket - Pointer to rx packet
2583 * cbPacketSize - rx ethernet frame size
2584 * Out:
e269fc2d 2585 * TURE, false
92b96797 2586 *
4e9b5e2b 2587 * Return Value: Return true if packet is copy to dma1; otherwise false
92b96797
FB
2588 */
2589
d56131de
MP
2590int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
2591 u32 uNodeIndex)
92b96797 2592{
d56131de 2593 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 2594 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
2595 u32 BytesToWrite = 0, uHeaderLen = 0;
2596 u8 byPktType = PK_TYPE_11B;
e269fc2d 2597 int bNeedEncryption = false;
d56131de
MP
2598 SKeyItem STempKey;
2599 PSKeyItem pTransmitKey = NULL;
2600 u8 *pbyBSSID;
2601 PUSB_SEND_CONTEXT pContext;
2602 u8 byPktTyp;
2603 int fConvertedPacket;
d56131de
MP
2604 u32 status;
2605 u16 wKeepRate = pDevice->wCurrentRate;
92b96797 2606
92b96797
FB
2607 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2608
2609 if (NULL == pContext) {
e269fc2d 2610 return false;
92b96797
FB
2611 }
2612
ceb8c5da 2613 memcpy(pDevice->sTxEthHeader.h_dest, (u8 *)pbySkbData, ETH_HLEN);
92b96797 2614
4e9b5e2b
AM
2615 if (pDevice->bEncryptionEnable == true) {
2616 bNeedEncryption = true;
92b96797
FB
2617 // get group key
2618 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 2619 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
2620 pTransmitKey = NULL;
2621 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2622 } else {
2623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2624 }
2625 }
2626
2627 if (pDevice->bEnableHostWEP) {
ee93e197 2628 if (uNodeIndex < MAX_NODE_NUM + 1) {
92b96797
FB
2629 pTransmitKey = &STempKey;
2630 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2631 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2632 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2633 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2634 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2635 memcpy(pTransmitKey->abyKey,
2636 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2637 pTransmitKey->uKeyLength
2638 );
2639 }
2640 }
2641
2642 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
e269fc2d
AM
2643 pContext->bBoolInUse = false;
2644 return false;
92b96797
FB
2645 }
2646
b902fbfe 2647 byPktTyp = (u8)pDevice->byPacketType;
92b96797
FB
2648
2649 if (pDevice->bFixRate) {
2650 if (pDevice->byBBType == BB_TYPE_11B) {
2651 if (pDevice->uConnectionRate >= RATE_11M) {
2652 pDevice->wCurrentRate = RATE_11M;
2653 } else {
3eaca0d2 2654 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2655 }
2656 } else {
2657 if ((pDevice->byBBType == BB_TYPE_11A) &&
2658 (pDevice->uConnectionRate <= RATE_6M)) {
2659 pDevice->wCurrentRate = RATE_6M;
2660 } else {
2661 if (pDevice->uConnectionRate >= RATE_54M)
2662 pDevice->wCurrentRate = RATE_54M;
2663 else
3eaca0d2 2664 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
2665 }
2666 }
2667 }
2668 else {
2669 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2670 }
2671
92b96797 2672 if (wKeepRate != pDevice->wCurrentRate) {
0cbd8d98 2673 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
92b96797
FB
2674 }
2675
2676 if (pDevice->wCurrentRate <= RATE_11M)
2677 byPktType = PK_TYPE_11B;
2678
abad19d0
AM
2679 BytesToWrite = uDataLen + ETH_FCS_LEN;
2680
92b96797
FB
2681 // Convert the packet to an usb frame and copy into our buffer
2682 // and send the irp.
2683
d0a2b8fa
MP
2684 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->Data[0];
2685
92b96797 2686 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
d0a2b8fa 2687 pTX_Buffer, bNeedEncryption,
92b96797
FB
2688 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
2689 pbySkbData, pTransmitKey, uNodeIndex,
2690 pDevice->wCurrentRate,
2691 &uHeaderLen, &BytesToWrite
2692 );
2693
e269fc2d
AM
2694 if (fConvertedPacket == false) {
2695 pContext->bBoolInUse = false;
2696 return false;
92b96797
FB
2697 }
2698
b902fbfe 2699 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3eaca0d2 2700 pTX_Buffer->wTxByteCount = (u16)BytesToWrite;
92b96797
FB
2701
2702 pContext->pPacket = NULL;
2703 pContext->Type = CONTEXT_DATA_PACKET;
3eaca0d2 2704 pContext->uBufLen = (u16)BytesToWrite + 4 ; //USB header
92b96797 2705
ceb8c5da 2706 s_vSaveTxPktInfo(pDevice, (u8) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.h_dest[0]), (u16) (BytesToWrite-uHeaderLen), pTX_Buffer->wFIFOCtl);
92b96797
FB
2707
2708 status = PIPEnsSendBulkOut(pDevice,pContext);
2709
4e9b5e2b 2710 return true;
92b96797
FB
2711}
2712
This page took 1.011951 seconds and 5 git commands to generate.