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