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