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