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