]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/vt6656/rxtx.c
staging: vt6656: rename MACvWriteBeaconInterval to vnt_mac_set_beacon_interval
[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 "wctl.h"
92b96797 58#include "rf.h"
92b96797 59#include "datarate.h"
92b96797 60#include "usbpipe.h"
92b96797 61#include "iocmd.h"
9d26d60f 62
4a499de2 63static int msglevel = MSG_LEVEL_INFO;
92b96797 64
3b138851 65static const u16 wTimeStampOff[2][MAX_RATE] = {
92b96797
FB
66 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
67 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
68 };
69
3b138851 70static const u16 wFB_Opt0[2][5] = {
92b96797
FB
71 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
72 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
73 };
3b138851 74static const u16 wFB_Opt1[2][5] = {
92b96797
FB
75 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
76 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
77 };
78
92b96797
FB
79#define RTSDUR_BB 0
80#define RTSDUR_BA 1
81#define RTSDUR_AA 2
82#define CTSDUR_BA 3
83#define RTSDUR_BA_F0 4
84#define RTSDUR_AA_F0 5
85#define RTSDUR_BA_F1 6
86#define RTSDUR_AA_F1 7
87#define CTSDUR_BA_F0 8
88#define CTSDUR_BA_F1 9
89#define DATADUR_B 10
90#define DATADUR_A 11
91#define DATADUR_A_F0 12
92#define DATADUR_A_F1 13
93
d56131de
MP
94static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
95 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
96
b89f3b94 97static struct vnt_usb_send_context *s_vGetFreeContext(struct vnt_private *);
d56131de 98
0a0f4b69 99static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
8e344c88 100 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
fa57560c 101 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
05cc617b 102 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts);
d56131de 103
d56131de 104static void s_vGenerateMACHeader(struct vnt_private *pDevice,
ceb8c5da 105 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
05cc617b 106 int bNeedEncrypt, u16 wFragType, u32 uFragIdx);
d56131de 107
3ba0938c
MP
108static void s_vFillTxKey(struct vnt_private *pDevice,
109 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
110 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
ec37d8b6 111 struct vnt_mic_hdr *mic_hdr);
d56131de
MP
112
113static void s_vSWencryption(struct vnt_private *pDevice,
114 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
115
116static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
117 u32 cbFrameLength, u16 wRate, int bNeedAck);
118
20338015 119static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
3b6cee7b 120 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate);
d56131de 121
05cc617b 122static u16 s_vFillCTSHead(struct vnt_private *pDevice,
5fb8e412
MP
123 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
124 int bNeedAck, u16 wCurrentRate, u8 byFBOption);
d56131de 125
0a0f4b69 126static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
5fb8e412 127 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
ceb8c5da 128 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption);
d56131de 129
5abe3d63 130static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
3ed210ef 131 u8 byPktType, int bNeedAck);
d56131de 132
7f591a11 133static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice,
d56131de
MP
134 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
135 int bNeedAck, u8 byFBOption);
92b96797 136
aceaf018 137static struct vnt_usb_send_context
b89f3b94 138 *s_vGetFreeContext(struct vnt_private *priv)
92b96797 139{
b89f3b94 140 struct vnt_usb_send_context *context = NULL;
d56131de 141 int ii;
92b96797 142
b89f3b94
MP
143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
144
145 for (ii = 0; ii < priv->cbTD; ii++) {
146 if (!priv->apTD[ii])
147 return NULL;
148
149 context = priv->apTD[ii];
30a05b39
MP
150 if (context->in_use == false) {
151 context->in_use = true;
152 memset(context->data, 0,
b89f3b94
MP
153 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
154 return context;
155 }
156 }
157
158 if (ii == priv->cbTD)
159 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
aceaf018 160
5c851383 161 return NULL;
92b96797
FB
162}
163
d56131de
MP
164static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
165 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
92b96797 166{
ae27b142 167 struct net_device_stats *stats = &pDevice->stats;
51934e7f
MP
168 struct vnt_tx_pkt_info *pkt_info = pDevice->pkt_info;
169
170 pkt_info[byPktNum].fifo_ctl = wFIFOCtl;
171 memcpy(pkt_info[byPktNum].dest_addr, pbyDestAddr, ETH_ALEN);
ae27b142
MP
172
173 stats->tx_bytes += wPktLength;
92b96797
FB
174}
175
3ba0938c
MP
176static void s_vFillTxKey(struct vnt_private *pDevice,
177 struct vnt_tx_fifo_head *fifo_head, u8 *pbyIVHead,
178 PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
179 struct vnt_mic_hdr *mic_hdr)
92b96797 180{
3ba0938c 181 u8 *pbyBuf = (u8 *)&fifo_head->adwTxKey[0];
fb453db9 182 __le32 *pdwIV = (__le32 *)pbyIVHead;
2fbb230c 183 __le32 *pdwExtIV = (__le32 *)((u8 *)pbyIVHead + 4);
1cac4a4b 184 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyHdrBuf;
fbfaccff 185 __le32 rev_iv_counter;
92b96797 186
95bfb1ae
MP
187 /* Fill TXKEY */
188 if (pTransmitKey == NULL)
ec37d8b6
MP
189 return;
190
fbfaccff 191 rev_iv_counter = cpu_to_le32(pDevice->dwIVCounter);
fb453db9 192 *pdwIV = cpu_to_le32(pDevice->dwIVCounter);
95bfb1ae
MP
193 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
194
f6804f33
MP
195 switch (pTransmitKey->byCipherSuite) {
196 case KEY_CTL_WEP:
95bfb1ae 197 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
fbfaccff 198 memcpy(pDevice->abyPRNG, (u8 *)&rev_iv_counter, 3);
95bfb1ae
MP
199 memcpy(pDevice->abyPRNG + 3, pTransmitKey->abyKey,
200 pTransmitKey->uKeyLength);
201 } else {
fbfaccff 202 memcpy(pbyBuf, (u8 *)&rev_iv_counter, 3);
95bfb1ae
MP
203 memcpy(pbyBuf + 3, pTransmitKey->abyKey,
204 pTransmitKey->uKeyLength);
205 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
fbfaccff 206 memcpy(pbyBuf+8, (u8 *)&rev_iv_counter, 3);
5cb5bff7 207 memcpy(pbyBuf+11, pTransmitKey->abyKey,
95bfb1ae
MP
208 pTransmitKey->uKeyLength);
209 }
210
211 memcpy(pDevice->abyPRNG, pbyBuf, 16);
212 }
213 /* Append IV after Mac Header */
fb453db9
MP
214 *pdwIV &= cpu_to_le32(WEP_IV_MASK);
215 *pdwIV |= cpu_to_le32((u32)pDevice->byKeyIndex << 30);
95bfb1ae
MP
216
217 pDevice->dwIVCounter++;
218 if (pDevice->dwIVCounter > WEP_IV_MASK)
219 pDevice->dwIVCounter = 0;
f6804f33
MP
220
221 break;
222 case KEY_CTL_TKIP:
95bfb1ae
MP
223 pTransmitKey->wTSC15_0++;
224 if (pTransmitKey->wTSC15_0 == 0)
225 pTransmitKey->dwTSC47_16++;
226
227 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
228 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16,
229 pDevice->abyPRNG);
230 memcpy(pbyBuf, pDevice->abyPRNG, 16);
231
232 /* Make IV */
233 memcpy(pdwIV, pDevice->abyPRNG, 3);
234
235 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
236 0xc0) | 0x20);
237 /* Append IV&ExtIV after Mac Header */
238 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
239
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
241 "vFillTxKey()---- pdwExtIV: %x\n", *pdwExtIV);
242
f6804f33
MP
243 break;
244 case KEY_CTL_CCMP:
95bfb1ae
MP
245 pTransmitKey->wTSC15_0++;
246 if (pTransmitKey->wTSC15_0 == 0)
247 pTransmitKey->dwTSC47_16++;
248
249 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
250
251 /* Make IV */
252 *pdwIV = 0;
253 *(pbyIVHead+3) = (u8)(((pDevice->byKeyIndex << 6) &
254 0xc0) | 0x20);
255
fb453db9 256 *pdwIV |= cpu_to_le32((u32)(pTransmitKey->wTSC15_0));
95bfb1ae
MP
257
258 /* Append IV&ExtIV after Mac Header */
259 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
260
261 if (!mic_hdr)
262 return;
263
264 /* MICHDR0 */
265 mic_hdr->id = 0x59;
266 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
267 memcpy(mic_hdr->mic_addr2, pMACHeader->addr2, ETH_ALEN);
268
269 mic_hdr->tsc_47_16 = cpu_to_be32(pTransmitKey->dwTSC47_16);
270 mic_hdr->tsc_15_0 = cpu_to_be16(pTransmitKey->wTSC15_0);
271
272 /* MICHDR1 */
078d0cfd 273 if (ieee80211_has_a4(pMACHeader->frame_control))
95bfb1ae
MP
274 mic_hdr->hlen = cpu_to_be16(28);
275 else
276 mic_hdr->hlen = cpu_to_be16(22);
277
278 memcpy(mic_hdr->addr1, pMACHeader->addr1, ETH_ALEN);
279 memcpy(mic_hdr->addr2, pMACHeader->addr2, ETH_ALEN);
280
281 /* MICHDR2 */
282 memcpy(mic_hdr->addr3, pMACHeader->addr3, ETH_ALEN);
5d4fe757
MP
283 mic_hdr->frame_control = cpu_to_le16(
284 le16_to_cpu(pMACHeader->frame_control) & 0xc78f);
285 mic_hdr->seq_ctrl = cpu_to_le16(
286 le16_to_cpu(pMACHeader->seq_ctrl) & 0xf);
ec37d8b6 287
078d0cfd 288 if (ieee80211_has_a4(pMACHeader->frame_control))
95bfb1ae
MP
289 memcpy(mic_hdr->addr4, pMACHeader->addr4, ETH_ALEN);
290 }
92b96797
FB
291}
292
d56131de
MP
293static void s_vSWencryption(struct vnt_private *pDevice,
294 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
92b96797 295{
d56131de
MP
296 u32 cbICVlen = 4;
297 u32 dwICV = 0xffffffff;
298 u32 *pdwICV;
92b96797
FB
299
300 if (pTransmitKey == NULL)
301 return;
302
303 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
304 //=======================================================================
305 // Append ICV after payload
929cb313 306 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
52a7e64b 307 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
92b96797
FB
308 // finally, we must invert dwCRC to get the correct answer
309 *pdwICV = cpu_to_le32(~dwICV);
310 // RC4 encryption
311 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
312 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
313 //=======================================================================
314 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
315 //=======================================================================
316 //Append ICV after payload
929cb313 317 dwICV = ether_crc_le(wPayloadSize, pbyPayloadHead);
52a7e64b 318 pdwICV = (u32 *)(pbyPayloadHead + wPayloadSize);
92b96797
FB
319 // finally, we must invert dwCRC to get the correct answer
320 *pdwICV = cpu_to_le32(~dwICV);
321 // RC4 encryption
322 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
323 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
324 //=======================================================================
325 }
326}
327
dab085b1 328static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
f115e76a
MP
329{
330 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
331 [rate % MAX_RATE]);
332}
333
92b96797
FB
334/*byPktType : PK_TYPE_11A 0
335 PK_TYPE_11B 1
336 PK_TYPE_11GB 2
337 PK_TYPE_11GA 3
338*/
3fd5620f
MP
339static u32 s_uGetTxRsvTime(struct vnt_private *priv, u8 pkt_type,
340 u32 frame_length, u16 rate, int need_ack)
92b96797 341{
3fd5620f 342 u32 data_time, ack_time;
92b96797 343
3fd5620f
MP
344 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
345 frame_length, rate);
92b96797 346
3fd5620f
MP
347 if (pkt_type == PK_TYPE_11B)
348 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
349 (u16)priv->byTopCCKBasicRate);
350 else
351 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type, 14,
352 (u16)priv->byTopOFDMBasicRate);
353
354 if (need_ack)
355 return data_time + priv->uSIFS + ack_time;
356
357 return data_time;
92b96797
FB
358}
359
2075f654 360static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
9c3806d5
MP
361 u32 frame_length, u16 rate, int need_ack)
362{
363 return cpu_to_le16((u16)s_uGetTxRsvTime(priv, pkt_type,
364 frame_length, rate, need_ack));
365}
366
92b96797 367//byFreqType: 0=>5GHZ 1=>2.4GHZ
20338015 368static __le16 s_uGetRTSCTSRsvTime(struct vnt_private *priv,
3b6cee7b 369 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
92b96797 370{
342e2e20 371 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
92b96797 372
342e2e20 373 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
92b96797 374
342e2e20 375 data_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
3b6cee7b 376 frame_length, current_rate);
342e2e20
MP
377
378 if (rsv_type == 0) {
379 rts_time = BBuGetFrameTime(priv->byPreambleType,
380 pkt_type, 20, priv->byTopCCKBasicRate);
381 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
382 pkt_type, 14, priv->byTopCCKBasicRate);
383 } else if (rsv_type == 1) {
384 rts_time = BBuGetFrameTime(priv->byPreambleType,
385 pkt_type, 20, priv->byTopCCKBasicRate);
386 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
387 14, priv->byTopCCKBasicRate);
388 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
389 14, priv->byTopOFDMBasicRate);
390 } else if (rsv_type == 2) {
391 rts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
392 20, priv->byTopOFDMBasicRate);
393 cts_time = ack_time = BBuGetFrameTime(priv->byPreambleType,
394 pkt_type, 14, priv->byTopOFDMBasicRate);
395 } else if (rsv_type == 3) {
396 cts_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
397 14, priv->byTopCCKBasicRate);
398 ack_time = BBuGetFrameTime(priv->byPreambleType, pkt_type,
399 14, priv->byTopOFDMBasicRate);
400
401 rrv_time = cts_time + ack_time + data_time + 2 * priv->uSIFS;
402
20338015 403 return cpu_to_le16((u16)rrv_time);
342e2e20
MP
404 }
405
406 rrv_time = rts_time + cts_time + ack_time + data_time + 3 * priv->uSIFS;
92b96797 407
342e2e20 408 return cpu_to_le16((u16)rrv_time);
92b96797
FB
409}
410
411//byFreqType 0: 5GHz, 1:2.4Ghz
5abe3d63 412static __le16 s_uGetDataDuration(struct vnt_private *pDevice,
6b5ad9d2 413 u8 byPktType, int bNeedAck)
92b96797 414{
0005cb00 415 u32 uAckTime = 0;
92b96797 416
b02ccd59 417 if (bNeedAck) {
6b5ad9d2 418 if (byPktType == PK_TYPE_11B)
b02ccd59
MP
419 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
420 byPktType, 14, pDevice->byTopCCKBasicRate);
421 else
422 uAckTime = BBuGetFrameTime(pDevice->byPreambleType,
423 byPktType, 14, pDevice->byTopOFDMBasicRate);
d5005955 424 return cpu_to_le16((u16)(pDevice->uSIFS + uAckTime));
b02ccd59 425 }
92b96797 426
92b96797
FB
427 return 0;
428}
429
92b96797 430//byFreqType: 0=>5GHZ 1=>2.4GHZ
7f591a11 431static __le16 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
d56131de
MP
432 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
433 u8 byFBOption)
92b96797 434{
d56131de 435 u32 uCTSTime = 0, uDurTime = 0;
92b96797 436
ecd80240
MP
437 switch (byDurType) {
438 case RTSDUR_BB:
439 case RTSDUR_BA:
440 case RTSDUR_BA_F0:
441 case RTSDUR_BA_F1:
442 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
443 14, pDevice->byTopCCKBasicRate);
444 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
445 s_uGetTxRsvTime(pDevice, byPktType,
446 cbFrameLength, wRate, bNeedAck);
447 break;
92b96797 448
ecd80240
MP
449 case RTSDUR_AA:
450 case RTSDUR_AA_F0:
451 case RTSDUR_AA_F1:
452 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType,
453 14, pDevice->byTopOFDMBasicRate);
454 uDurTime = uCTSTime + 2 * pDevice->uSIFS +
455 s_uGetTxRsvTime(pDevice, byPktType,
456 cbFrameLength, wRate, bNeedAck);
457 break;
92b96797 458
ecd80240
MP
459 case CTSDUR_BA:
460 case CTSDUR_BA_F0:
461 case CTSDUR_BA_F1:
462 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice,
f84cdf65 463 byPktType, cbFrameLength, wRate, bNeedAck);
ecd80240 464 break;
92b96797 465
ecd80240
MP
466 default:
467 break;
468 }
92b96797 469
e34f9dbe 470 return cpu_to_le16((u16)uDurTime);
92b96797
FB
471}
472
78363fd1
MP
473static u16 vnt_rxtx_datahead_g(struct vnt_private *priv, u8 pkt_type, u16 rate,
474 struct vnt_tx_datahead_g *buf, u32 frame_len, int need_ack)
475{
476 /* Get SignalField,ServiceField,Length */
477 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
478 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
479 PK_TYPE_11B, &buf->b);
480
481 /* Get Duration and TimeStamp */
4e01117c
MP
482 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
483 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
78363fd1 484
10bb39a0
MP
485 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
486 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
78363fd1
MP
487 priv->byTopCCKBasicRate);
488
c4cf6dfb 489 return le16_to_cpu(buf->duration_a);
78363fd1
MP
490}
491
5b852f53
MP
492static u16 vnt_rxtx_datahead_g_fb(struct vnt_private *priv, u8 pkt_type,
493 u16 rate, struct vnt_tx_datahead_g_fb *buf,
494 u32 frame_len, int need_ack)
495{
496 /* Get SignalField,ServiceField,Length */
497 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
498
499 BBvCalculateParameter(priv, frame_len, priv->byTopCCKBasicRate,
500 PK_TYPE_11B, &buf->b);
501
502 /* Get Duration and TimeStamp */
4e01117c
MP
503 buf->duration_a = s_uGetDataDuration(priv, pkt_type, need_ack);
504 buf->duration_b = s_uGetDataDuration(priv, PK_TYPE_11B, need_ack);
5b852f53 505
4e01117c
MP
506 buf->duration_a_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
507 buf->duration_a_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
5b852f53 508
10bb39a0
MP
509 buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate);
510 buf->time_stamp_off_b = vnt_time_stamp_off(priv,
5b852f53
MP
511 priv->byTopCCKBasicRate);
512
c4cf6dfb 513 return le16_to_cpu(buf->duration_a);
5b852f53
MP
514}
515
bd3f51f1
MP
516static u16 vnt_rxtx_datahead_a_fb(struct vnt_private *priv, u8 pkt_type,
517 u16 rate, struct vnt_tx_datahead_a_fb *buf,
518 u32 frame_len, int need_ack)
519{
520 /* Get SignalField,ServiceField,Length */
521 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->a);
522 /* Get Duration and TimeStampOff */
4e01117c 523 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
bd3f51f1 524
4e01117c
MP
525 buf->duration_f0 = s_uGetDataDuration(priv, pkt_type, need_ack);
526 buf->duration_f1 = s_uGetDataDuration(priv, pkt_type, need_ack);
bd3f51f1 527
10bb39a0 528 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
bd3f51f1 529
c4cf6dfb 530 return le16_to_cpu(buf->duration);
bd3f51f1
MP
531}
532
5634a5ab
MP
533static u16 vnt_rxtx_datahead_ab(struct vnt_private *priv, u8 pkt_type,
534 u16 rate, struct vnt_tx_datahead_ab *buf,
535 u32 frame_len, int need_ack)
536{
537 /* Get SignalField,ServiceField,Length */
538 BBvCalculateParameter(priv, frame_len, rate, pkt_type, &buf->ab);
539 /* Get Duration and TimeStampOff */
4e01117c 540 buf->duration = s_uGetDataDuration(priv, pkt_type, need_ack);
5634a5ab 541
10bb39a0 542 buf->time_stamp_off = vnt_time_stamp_off(priv, rate);
5634a5ab 543
c4cf6dfb 544 return le16_to_cpu(buf->duration);
5634a5ab
MP
545}
546
5e67ee49
MP
547static int vnt_fill_ieee80211_rts(struct vnt_private *priv,
548 struct ieee80211_rts *rts, struct ethhdr *eth_hdr,
10bb39a0 549 __le16 duration)
5e67ee49
MP
550{
551 rts->duration = duration;
f4554d3b
MP
552 rts->frame_control =
553 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
5e67ee49 554
a0ad2776
MP
555 if (priv->op_mode == NL80211_IFTYPE_ADHOC ||
556 priv->op_mode == NL80211_IFTYPE_AP)
5e67ee49
MP
557 memcpy(rts->ra, eth_hdr->h_dest, ETH_ALEN);
558 else
559 memcpy(rts->ra, priv->abyBSSID, ETH_ALEN);
560
a0ad2776 561 if (priv->op_mode == NL80211_IFTYPE_AP)
5e67ee49
MP
562 memcpy(rts->ta, priv->abyBSSID, ETH_ALEN);
563 else
564 memcpy(rts->ta, eth_hdr->h_source, ETH_ALEN);
565
566 return 0;
567}
568
0a0f4b69 569static u16 vnt_rxtx_rts_g_head(struct vnt_private *priv,
5e67ee49
MP
570 struct vnt_rts_g *buf, struct ethhdr *eth_hdr,
571 u8 pkt_type, u32 frame_len, int need_ack,
572 u16 current_rate, u8 fb_option)
573{
574 u16 rts_frame_len = 20;
575
576 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
577 PK_TYPE_11B, &buf->b);
578 BBvCalculateParameter(priv, rts_frame_len,
579 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
580
4e01117c 581 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
5e67ee49 582 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
4e01117c 583 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
5e67ee49 584 pkt_type, current_rate, need_ack, fb_option);
4e01117c 585 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
5e67ee49
MP
586 pkt_type, current_rate, need_ack, fb_option);
587
4e01117c 588 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
5e67ee49 589
78363fd1
MP
590 return vnt_rxtx_datahead_g(priv, pkt_type, current_rate,
591 &buf->data_head, frame_len, need_ack);
5e67ee49
MP
592}
593
0a0f4b69 594static u16 vnt_rxtx_rts_g_fb_head(struct vnt_private *priv,
ec91713a
MP
595 struct vnt_rts_g_fb *buf, struct ethhdr *eth_hdr,
596 u8 pkt_type, u32 frame_len, int need_ack,
597 u16 current_rate, u8 fb_option)
598{
599 u16 rts_frame_len = 20;
600
601 BBvCalculateParameter(priv, rts_frame_len, priv->byTopCCKBasicRate,
602 PK_TYPE_11B, &buf->b);
603 BBvCalculateParameter(priv, rts_frame_len,
604 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
605
606
4e01117c 607 buf->duration_bb = s_uGetRTSCTSDuration(priv, RTSDUR_BB, frame_len,
ec91713a 608 PK_TYPE_11B, priv->byTopCCKBasicRate, need_ack, fb_option);
4e01117c 609 buf->duration_aa = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
ec91713a 610 pkt_type, current_rate, need_ack, fb_option);
4e01117c 611 buf->duration_ba = s_uGetRTSCTSDuration(priv, RTSDUR_BA, frame_len,
ec91713a
MP
612 pkt_type, current_rate, need_ack, fb_option);
613
614
fadc3bdf 615 buf->rts_duration_ba_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F0,
f84cdf65 616 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
fadc3bdf 617 buf->rts_duration_aa_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
f84cdf65 618 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
fadc3bdf 619 buf->rts_duration_ba_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_BA_F1,
f84cdf65 620 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
fadc3bdf 621 buf->rts_duration_aa_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
f84cdf65 622 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
ec91713a 623
4e01117c 624 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration_aa);
ec91713a 625
5b852f53
MP
626 return vnt_rxtx_datahead_g_fb(priv, pkt_type, current_rate,
627 &buf->data_head, frame_len, need_ack);
ec91713a
MP
628}
629
0a0f4b69 630static u16 vnt_rxtx_rts_ab_head(struct vnt_private *priv,
1712633d
MP
631 struct vnt_rts_ab *buf, struct ethhdr *eth_hdr,
632 u8 pkt_type, u32 frame_len, int need_ack,
633 u16 current_rate, u8 fb_option)
634{
635 u16 rts_frame_len = 20;
636
637 BBvCalculateParameter(priv, rts_frame_len,
638 priv->byTopOFDMBasicRate, pkt_type, &buf->ab);
639
4e01117c 640 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
1712633d
MP
641 pkt_type, current_rate, need_ack, fb_option);
642
4e01117c 643 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
1712633d 644
5634a5ab
MP
645 return vnt_rxtx_datahead_ab(priv, pkt_type, current_rate,
646 &buf->data_head, frame_len, need_ack);
1712633d
MP
647}
648
0a0f4b69 649static u16 vnt_rxtx_rts_a_fb_head(struct vnt_private *priv,
9d2578c1
MP
650 struct vnt_rts_a_fb *buf, struct ethhdr *eth_hdr,
651 u8 pkt_type, u32 frame_len, int need_ack,
652 u16 current_rate, u8 fb_option)
653{
654 u16 rts_frame_len = 20;
655
656 BBvCalculateParameter(priv, rts_frame_len,
657 priv->byTopOFDMBasicRate, pkt_type, &buf->a);
658
4e01117c 659 buf->duration = s_uGetRTSCTSDuration(priv, RTSDUR_AA, frame_len,
9d2578c1
MP
660 pkt_type, current_rate, need_ack, fb_option);
661
fadc3bdf 662 buf->rts_duration_f0 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F0,
f84cdf65 663 frame_len, pkt_type, priv->tx_rate_fb0, need_ack, fb_option);
9d2578c1 664
fadc3bdf 665 buf->rts_duration_f1 = s_uGetRTSCTSDuration(priv, RTSDUR_AA_F1,
f84cdf65 666 frame_len, pkt_type, priv->tx_rate_fb1, need_ack, fb_option);
9d2578c1 667
4e01117c 668 vnt_fill_ieee80211_rts(priv, &buf->data, eth_hdr, buf->duration);
9d2578c1 669
bd3f51f1
MP
670 return vnt_rxtx_datahead_a_fb(priv, pkt_type, current_rate,
671 &buf->data_head, frame_len, need_ack);
9d2578c1
MP
672}
673
0a0f4b69 674static u16 s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
5fb8e412 675 union vnt_tx_data_head *head, u32 cbFrameLength, int bNeedAck,
ceb8c5da 676 struct ethhdr *psEthHeader, u16 wCurrentRate, u8 byFBOption)
92b96797 677{
92b96797 678
13fe62ae 679 if (!head)
0a0f4b69 680 return 0;
92b96797 681
9d5829bf
MP
682 /* Note: So far RTSHead doesn't appear in ATIM
683 * & Beacom DMA, so we don't need to take them
684 * into account.
685 * Otherwise, we need to modified codes for them.
686 */
0bddd303
MP
687 switch (byPktType) {
688 case PK_TYPE_11GB:
689 case PK_TYPE_11GA:
9d5829bf 690 if (byFBOption == AUTO_FB_NONE)
78363fd1 691 return vnt_rxtx_rts_g_head(pDevice, &head->rts_g,
5e67ee49
MP
692 psEthHeader, byPktType, cbFrameLength,
693 bNeedAck, wCurrentRate, byFBOption);
9d5829bf 694 else
5b852f53 695 return vnt_rxtx_rts_g_fb_head(pDevice, &head->rts_g_fb,
ec91713a
MP
696 psEthHeader, byPktType, cbFrameLength,
697 bNeedAck, wCurrentRate, byFBOption);
0bddd303
MP
698 break;
699 case PK_TYPE_11A:
2b83ebd0 700 if (byFBOption) {
bd3f51f1 701 return vnt_rxtx_rts_a_fb_head(pDevice, &head->rts_a_fb,
9d2578c1
MP
702 psEthHeader, byPktType, cbFrameLength,
703 bNeedAck, wCurrentRate, byFBOption);
2b83ebd0
MP
704 break;
705 }
0bddd303 706 case PK_TYPE_11B:
5634a5ab 707 return vnt_rxtx_rts_ab_head(pDevice, &head->rts_ab,
1712633d
MP
708 psEthHeader, byPktType, cbFrameLength,
709 bNeedAck, wCurrentRate, byFBOption);
9d5829bf 710 }
0a0f4b69
MP
711
712 return 0;
92b96797
FB
713}
714
05cc617b 715static u16 s_vFillCTSHead(struct vnt_private *pDevice,
5fb8e412
MP
716 u8 byPktType, union vnt_tx_data_head *head, u32 cbFrameLength,
717 int bNeedAck, u16 wCurrentRate, u8 byFBOption)
92b96797 718{
d56131de 719 u32 uCTSFrameLen = 14;
92b96797 720
27df3ebf 721 if (!head)
0a0f4b69 722 return 0;
92b96797 723
c921cc8c
MP
724 if (byFBOption != AUTO_FB_NONE) {
725 /* Auto Fall back */
27df3ebf 726 struct vnt_cts_fb *pBuf = &head->cts_g_fb;
aed387c7
MP
727 /* Get SignalField,ServiceField,Length */
728 BBvCalculateParameter(pDevice, uCTSFrameLen,
729 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
4e01117c 730 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice, CTSDUR_BA,
e34f9dbe
MP
731 cbFrameLength, byPktType,
732 wCurrentRate, bNeedAck, byFBOption);
733 /* Get CTSDuration_ba_f0 */
7fd5747f 734 pBuf->cts_duration_ba_f0 = s_uGetRTSCTSDuration(pDevice,
f84cdf65
MP
735 CTSDUR_BA_F0, cbFrameLength, byPktType,
736 pDevice->tx_rate_fb0, bNeedAck, byFBOption);
e34f9dbe 737 /* Get CTSDuration_ba_f1 */
7fd5747f 738 pBuf->cts_duration_ba_f1 = s_uGetRTSCTSDuration(pDevice,
f84cdf65
MP
739 CTSDUR_BA_F1, cbFrameLength, byPktType,
740 pDevice->tx_rate_fb1, bNeedAck, byFBOption);
14840cdd 741 /* Get CTS Frame body */
4e01117c 742 pBuf->data.duration = pBuf->duration_ba;
d9560ae5
MP
743 pBuf->data.frame_control =
744 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
745
14840cdd 746 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
5b852f53
MP
747
748 return vnt_rxtx_datahead_g_fb(pDevice, byPktType, wCurrentRate,
749 &pBuf->data_head, cbFrameLength, bNeedAck);
c921cc8c 750 } else {
27df3ebf 751 struct vnt_cts *pBuf = &head->cts_g;
aed387c7
MP
752 /* Get SignalField,ServiceField,Length */
753 BBvCalculateParameter(pDevice, uCTSFrameLen,
754 pDevice->byTopCCKBasicRate, PK_TYPE_11B, &pBuf->b);
e34f9dbe 755 /* Get CTSDuration_ba */
4e01117c 756 pBuf->duration_ba = s_uGetRTSCTSDuration(pDevice,
e34f9dbe
MP
757 CTSDUR_BA, cbFrameLength, byPktType,
758 wCurrentRate, bNeedAck, byFBOption);
14840cdd 759 /*Get CTS Frame body*/
4e01117c 760 pBuf->data.duration = pBuf->duration_ba;
d9560ae5
MP
761 pBuf->data.frame_control =
762 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
763
14840cdd 764 memcpy(pBuf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN);
78363fd1
MP
765
766 return vnt_rxtx_datahead_g(pDevice, byPktType, wCurrentRate,
767 &pBuf->data_head, cbFrameLength, bNeedAck);
92b96797 768 }
0a0f4b69
MP
769
770 return 0;
92b96797
FB
771}
772
92b96797
FB
773/*+
774 *
775 * Description:
776 * Generate FIFO control for MAC & Baseband controller
777 *
778 * Parameters:
779 * In:
780 * pDevice - Pointer to adpater
781 * pTxDataHead - Transmit Data Buffer
782 * pTxBufHead - pTxBufHead
783 * pvRrvTime - pvRrvTime
784 * pvRTS - RTS Buffer
785 * pCTS - CTS Buffer
786 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
787 * bNeedACK - If need ACK
92b96797
FB
788 * Out:
789 * none
790 *
791 * Return Value: none
792 *
793-*/
cc856e61 794
0a0f4b69 795static u16 s_vGenerateTxParameter(struct vnt_private *pDevice,
8e344c88 796 u8 byPktType, u16 wCurrentRate, struct vnt_tx_buffer *tx_buffer,
fa57560c 797 struct vnt_mic_hdr **mic_hdr, u32 need_mic, u32 cbFrameSize,
05cc617b 798 int bNeedACK, struct ethhdr *psEthHeader, bool need_rts)
92b96797 799{
8e344c88 800 struct vnt_tx_fifo_head *pFifoHead = &tx_buffer->fifo_head;
b9cc2fc0 801 union vnt_tx_data_head *head = NULL;
d56131de 802 u16 wFifoCtl;
d56131de 803 u8 byFBOption = AUTO_FB_NONE;
92b96797 804
03a9cf34 805 pFifoHead->current_rate = cpu_to_le16(wCurrentRate);
92928f13 806 wFifoCtl = pFifoHead->wFIFOCtl;
92b96797 807
92928f13
MP
808 if (wFifoCtl & FIFOCTL_AUTO_FB_0)
809 byFBOption = AUTO_FB_0;
810 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
811 byFBOption = AUTO_FB_1;
92b96797 812
92928f13
MP
813 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
814 if (need_rts) {
815 struct vnt_rrv_time_rts *pBuf =
816 &tx_buffer->tx_head.tx_rts.rts;
9e38a5c1 817
85417bf0 818 pBuf->rts_rrv_time_aa = s_uGetRTSCTSRsvTime(pDevice, 2,
92928f13 819 byPktType, cbFrameSize, wCurrentRate);
85417bf0 820 pBuf->rts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 1,
92928f13 821 byPktType, cbFrameSize, wCurrentRate);
85417bf0 822 pBuf->rts_rrv_time_bb = s_uGetRTSCTSRsvTime(pDevice, 0,
cfabe4b4 823 byPktType, cbFrameSize, wCurrentRate);
b9cc2fc0 824
5ff627ae 825 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 826 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
5ff627ae 827 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
828 PK_TYPE_11B, cbFrameSize,
829 pDevice->byTopCCKBasicRate, bNeedACK);
830
831 if (need_mic) {
832 *mic_hdr = &tx_buffer->
833 tx_head.tx_rts.tx.mic.hdr;
834 head = &tx_buffer->tx_head.tx_rts.tx.mic.head;
835 } else {
836 head = &tx_buffer->tx_head.tx_rts.tx.head;
837 }
f0e0d505 838
92928f13
MP
839 /* Fill RTS */
840 return s_vFillRTSHead(pDevice, byPktType, head,
841 cbFrameSize, bNeedACK, psEthHeader,
842 wCurrentRate, byFBOption);
f0e0d505 843
92928f13
MP
844 } else {
845 struct vnt_rrv_time_cts *pBuf = &tx_buffer->
846 tx_head.tx_cts.cts;
847
5ff627ae 848 pBuf->rrv_time_a = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 849 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
5ff627ae 850 pBuf->rrv_time_b = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
851 PK_TYPE_11B, cbFrameSize,
852 pDevice->byTopCCKBasicRate, bNeedACK);
853
372108e7 854 pBuf->cts_rrv_time_ba = s_uGetRTSCTSRsvTime(pDevice, 3,
92928f13
MP
855 byPktType, cbFrameSize, wCurrentRate);
856
857 if (need_mic) {
858 *mic_hdr = &tx_buffer->
859 tx_head.tx_cts.tx.mic.hdr;
860 head = &tx_buffer->tx_head.tx_cts.tx.mic.head;
861 } else {
862 head = &tx_buffer->tx_head.tx_cts.tx.head;
863 }
864
865 /* Fill CTS */
05cc617b 866 return s_vFillCTSHead(pDevice, byPktType,
92928f13
MP
867 head, cbFrameSize, bNeedACK, wCurrentRate,
868 byFBOption);
869 }
870 } else if (byPktType == PK_TYPE_11A) {
b9cc2fc0 871 if (need_mic) {
92928f13
MP
872 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
873 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
b9cc2fc0 874 } else {
92928f13 875 head = &tx_buffer->tx_head.tx_ab.tx.head;
b9cc2fc0 876 }
f0e0d505 877
92928f13
MP
878 if (need_rts) {
879 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
880 tx_head.tx_ab.ab;
9e38a5c1 881
85417bf0 882 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 2,
cfabe4b4 883 byPktType, cbFrameSize, wCurrentRate);
b9cc2fc0 884
5ff627ae 885 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13 886 byPktType, cbFrameSize, wCurrentRate, bNeedACK);
9e38a5c1 887
92928f13
MP
888 /* Fill RTS */
889 return s_vFillRTSHead(pDevice, byPktType, head,
890 cbFrameSize, bNeedACK, psEthHeader,
891 wCurrentRate, byFBOption);
892 } else {
893 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
894 tx_head.tx_ab.ab;
a90186e4 895
5ff627ae 896 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
897 PK_TYPE_11A, cbFrameSize,
898 wCurrentRate, bNeedACK);
c12dca09 899
92928f13
MP
900 return vnt_rxtx_datahead_a_fb(pDevice, byPktType,
901 wCurrentRate, &head->data_head_a_fb,
902 cbFrameSize, bNeedACK);
903 }
904 } else if (byPktType == PK_TYPE_11B) {
905 if (need_mic) {
906 *mic_hdr = &tx_buffer->tx_head.tx_ab.tx.mic.hdr;
907 head = &tx_buffer->tx_head.tx_ab.tx.mic.head;
908 } else {
909 head = &tx_buffer->tx_head.tx_ab.tx.head;
910 }
911
912 if (need_rts) {
913 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
914 tx_head.tx_ab.ab;
9e38a5c1 915
85417bf0 916 pBuf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0,
cfabe4b4 917 byPktType, cbFrameSize, wCurrentRate);
f0e0d505 918
5ff627ae 919 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
920 PK_TYPE_11B, cbFrameSize, wCurrentRate,
921 bNeedACK);
922
923 /* Fill RTS */
924 return s_vFillRTSHead(pDevice, byPktType, head,
925 cbFrameSize,
351c7dc3 926 bNeedACK, psEthHeader, wCurrentRate, byFBOption);
92928f13
MP
927 } else {
928 struct vnt_rrv_time_ab *pBuf = &tx_buffer->
929 tx_head.tx_ab.ab;
9e38a5c1 930
5ff627ae 931 pBuf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice,
92928f13
MP
932 PK_TYPE_11B, cbFrameSize,
933 wCurrentRate, bNeedACK);
c12dca09 934
92928f13
MP
935 return vnt_rxtx_datahead_ab(pDevice, byPktType,
936 wCurrentRate, &head->data_head_ab,
937 cbFrameSize, bNeedACK);
938 }
939 }
0a0f4b69
MP
940
941 return 0;
92b96797
FB
942}
943/*
b902fbfe 944 u8 * pbyBuffer,//point to pTxBufHead
3eaca0d2 945 u16 wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
cc856e61 946 unsigned int cbFragmentSize,//Hdr+payoad+FCS
92b96797
FB
947*/
948
d56131de 949static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
d66caada 950 struct vnt_tx_buffer *tx_buffer, int bNeedEncryption,
05cc617b 951 u32 uSkbPacketLen, struct ethhdr *psEthHeader,
d0a2b8fa
MP
952 u8 *pPacket, PSKeyItem pTransmitKey, u32 uNodeIndex, u16 wCurrentRate,
953 u32 *pcbHeaderLen, u32 *pcbTotalLen)
92b96797 954{
d66caada 955 struct vnt_tx_fifo_head *pTxBufHead = &tx_buffer->fifo_head;
d56131de 956 u32 cbFrameSize, cbFrameBodySize;
d56131de
MP
957 u32 cb802_1_H_len;
958 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
959 u32 cbFCSlen = 4, cbMICHDR = 0;
f46142b0
MP
960 int bNeedACK;
961 bool bRTS = false;
d56131de
MP
962 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
963 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
964 u8 abySNAP_Bridgetunnel[ETH_ALEN]
965 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
966 u32 uDuration;
967 u32 cbHeaderLength = 0, uPadding = 0;
5a5d6a80 968 struct vnt_mic_hdr *pMICHDR;
d56131de
MP
969 u8 byFBOption = AUTO_FB_NONE, byFragType;
970 u16 wTxBufSize;
4235f72f 971 u32 dwMICKey0, dwMICKey1, dwMIC_Priority;
d56131de 972 u32 *pdwMIC_L, *pdwMIC_R;
e269fc2d 973 int bSoftWEP = false;
9e38a5c1 974
c545e6a6 975 pMICHDR = NULL;
92b96797 976
e2efba76 977 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
4e9b5e2b
AM
978 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
979 bSoftWEP = true; /* WEP 256 */
e2efba76 980 }
92b96797 981
c47b0a34
MP
982 /* Get pkt type */
983 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN)
984 cb802_1_H_len = 8;
985 else
986 cb802_1_H_len = 0;
92b96797 987
21ec51f3 988 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
92b96797
FB
989
990 //Set packet type
3eaca0d2 991 pTxBufHead->wFIFOCtl |= (u16)(byPktType<<8);
92b96797 992
a0ad2776
MP
993 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC ||
994 pDevice->op_mode == NL80211_IFTYPE_AP) {
ceb8c5da 995 if (is_multicast_ether_addr(psEthHeader->h_dest)) {
e269fc2d 996 bNeedACK = false;
22040bbf
AM
997 pTxBufHead->wFIFOCtl =
998 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
999 } else {
4e9b5e2b 1000 bNeedACK = true;
22040bbf
AM
1001 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1002 }
c47b0a34
MP
1003 } else {
1004 /* MSDUs in Infra mode always need ACK */
1005 bNeedACK = true;
1006 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1007 }
92b96797 1008
5846251d 1009 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
92b96797 1010
92b96797 1011 //Set FRAGCTL_MACHDCNT
078d0cfd
MP
1012 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1013
3eaca0d2 1014 pTxBufHead->wFragCtl |= (u16)(cbMACHdLen << 10);
92b96797
FB
1015
1016 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1017 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1018 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1019 }
1020
f84cdf65
MP
1021 /* Set Auto Fallback Ctl */
1022 if (wCurrentRate >= RATE_18M) {
1023 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1024 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1025
1026 pDevice->tx_rate_fb0 =
1027 wFB_Opt0[FB_RATE0][wCurrentRate - RATE_18M];
1028 pDevice->tx_rate_fb1 =
1029 wFB_Opt0[FB_RATE1][wCurrentRate - RATE_18M];
1030
1031 byFBOption = AUTO_FB_0;
1032 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1033 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1034 pDevice->tx_rate_fb0 =
1035 wFB_Opt1[FB_RATE0][wCurrentRate - RATE_18M];
1036 pDevice->tx_rate_fb1 =
1037 wFB_Opt1[FB_RATE1][wCurrentRate - RATE_18M];
1038
1039 byFBOption = AUTO_FB_1;
1040 }
1041 }
92b96797 1042
4e9b5e2b 1043 if (bSoftWEP != true) {
92b96797
FB
1044 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1045 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1046 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1047 }
1048 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1049 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1050 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1051 }
1052 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
1053 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1054 }
1055 }
1056 }
1057
92b96797
FB
1058 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1059 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1060 cbIVlen = 4;
1061 cbICVlen = 4;
1062 }
1063 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1064 cbIVlen = 8;//IV+ExtIV
1065 cbMIClen = 8;
1066 cbICVlen = 4;
1067 }
1068 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1069 cbIVlen = 8;//RSN Header
1070 cbICVlen = 8;//MIC
5a5d6a80 1071 cbMICHDR = sizeof(struct vnt_mic_hdr);
92b96797 1072 }
e269fc2d 1073 if (bSoftWEP == false) {
92b96797
FB
1074 //MAC Header should be padding 0 to DW alignment.
1075 uPadding = 4 - (cbMACHdLen%4);
1076 uPadding %= 4;
1077 }
1078 }
1079
1080 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1081
e269fc2d
AM
1082 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1083 bRTS = false;
92b96797 1084 } else {
4e9b5e2b 1085 bRTS = true;
92b96797
FB
1086 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1087 }
1088
b902fbfe 1089 pbyTxBufferAddr = (u8 *) &(pTxBufHead->adwTxKey[0]);
d66caada
MP
1090 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
1091
92b96797
FB
1092 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1093 if (byFBOption == AUTO_FB_NONE) {
4e9b5e2b 1094 if (bRTS == true) {//RTS_need
6398a59b 1095 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
78363fd1 1096 cbMICHDR + sizeof(struct vnt_rts_g);
92b96797
FB
1097 }
1098 else { //RTS_needless
4f990057 1099 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
78363fd1 1100 cbMICHDR + sizeof(struct vnt_cts);
92b96797
FB
1101 }
1102 } else {
1103 // Auto Fall Back
4e9b5e2b 1104 if (bRTS == true) {//RTS_need
6398a59b 1105 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_rts) +
5b852f53 1106 cbMICHDR + sizeof(struct vnt_rts_g_fb);
92b96797 1107 }
e269fc2d 1108 else if (bRTS == false) { //RTS_needless
4f990057 1109 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
5b852f53 1110 cbMICHDR + sizeof(struct vnt_cts_fb);
92b96797
FB
1111 }
1112 } // Auto Fall Back
1113 }
1114 else {//802.11a/b packet
1115 if (byFBOption == AUTO_FB_NONE) {
4e9b5e2b 1116 if (bRTS == true) {//RTS_need
976467d3 1117 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
5634a5ab 1118 cbMICHDR + sizeof(struct vnt_rts_ab);
92b96797 1119 }
e269fc2d 1120 else if (bRTS == false) { //RTS_needless, no MICHDR
976467d3 1121 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
558becf1 1122 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1123 }
1124 } else {
1125 // Auto Fall Back
4e9b5e2b 1126 if (bRTS == true) {//RTS_need
976467d3 1127 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
bd3f51f1 1128 cbMICHDR + sizeof(struct vnt_rts_a_fb);
92b96797 1129 }
e269fc2d 1130 else if (bRTS == false) { //RTS_needless
976467d3 1131 cbHeaderLength = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
1da4ee20 1132 cbMICHDR + sizeof(struct vnt_tx_datahead_a_fb);
92b96797
FB
1133 }
1134 } // Auto Fall Back
1135 }
1136
b902fbfe
AM
1137 pbyMacHdr = (u8 *)(pbyTxBufferAddr + cbHeaderLength);
1138 pbyIVHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding);
1139 pbyPayloadHead = (u8 *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
92b96797 1140
92b96797
FB
1141 //=========================
1142 // No Fragmentation
1143 //=========================
1144 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1145 byFragType = FRAGCTL_NONFRAG;
92b96797
FB
1146 //pTxBufHead = (PSTxBufHead) &(pTxBufHead->adwTxKey[0]);
1147
78363fd1
MP
1148 /* Fill FIFO, RrvTime, RTS and CTS */
1149 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1150 tx_buffer, &pMICHDR, cbMICHDR,
05cc617b 1151 cbFrameSize, bNeedACK, psEthHeader, bRTS);
c12dca09 1152
92b96797 1153 // Generate TX MAC Header
3eaca0d2 1154 s_vGenerateMACHeader(pDevice, pbyMacHdr, (u16)uDuration, psEthHeader, bNeedEncryption,
05cc617b 1155 byFragType, 0);
92b96797 1156
4e9b5e2b 1157 if (bNeedEncryption == true) {
92b96797 1158 //Fill TXKEY
3ba0938c 1159 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
ec37d8b6 1160 pbyMacHdr, (u16)cbFrameBodySize, pMICHDR);
92b96797
FB
1161 }
1162
c47b0a34
MP
1163 /* 802.1H */
1164 if (ntohs(psEthHeader->h_proto) > ETH_DATA_LEN) {
ceb8c5da 1165 if ((psEthHeader->h_proto == cpu_to_be16(ETH_P_IPX)) ||
c47b0a34 1166 (psEthHeader->h_proto == cpu_to_le16(0xF380)))
b902fbfe 1167 memcpy((u8 *) (pbyPayloadHead),
c47b0a34
MP
1168 abySNAP_Bridgetunnel, 6);
1169 else
1170 memcpy((u8 *) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
92b96797 1171
c47b0a34 1172 pbyType = (u8 *) (pbyPayloadHead + 6);
92b96797 1173
c47b0a34
MP
1174 memcpy(pbyType, &(psEthHeader->h_proto), sizeof(u16));
1175 }
92b96797 1176
92b96797
FB
1177 if (pPacket != NULL) {
1178 // Copy the Packet into a tx Buffer
3e362598 1179 memcpy((pbyPayloadHead + cb802_1_H_len),
21ec51f3
CC
1180 (pPacket + ETH_HLEN),
1181 uSkbPacketLen - ETH_HLEN
92b96797
FB
1182 );
1183
1184 } else {
1185 // while bRelayPacketSend psEthHeader is point to header+payload
b902fbfe 1186 memcpy((pbyPayloadHead + cb802_1_H_len), ((u8 *)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
92b96797
FB
1187 }
1188
4e9b5e2b 1189 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
92b96797
FB
1190
1191 ///////////////////////////////////////////////////////////////////
1192
14c5ef57
MP
1193 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1194 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1195 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1196 }
92b96797 1197 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
52a7e64b
AM
1198 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1199 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
92b96797
FB
1200 }
1201 else {
52a7e64b
AM
1202 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1203 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
92b96797
FB
1204 }
1205 // DO Software Michael
1206 MIC_vInit(dwMICKey0, dwMICKey1);
ceb8c5da 1207 MIC_vAppend((u8 *)&(psEthHeader->h_dest[0]), 12);
92b96797 1208 dwMIC_Priority = 0;
b902fbfe 1209 MIC_vAppend((u8 *)&dwMIC_Priority, 4);
b4dc03af
MP
1210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %X, %X\n",
1211 dwMICKey0, dwMICKey1);
92b96797
FB
1212
1213 ///////////////////////////////////////////////////////////////////
1214
1215 //DBG_PRN_GRP12(("Length:%d, %d\n", cbFrameBodySize, uFromHDtoPLDLength));
1216 //for (ii = 0; ii < cbFrameBodySize; ii++) {
b902fbfe 1217 // DBG_PRN_GRP12(("%02x ", *((u8 *)((pbyPayloadHead + cb802_1_H_len) + ii))));
92b96797
FB
1218 //}
1219 //DBG_PRN_GRP12(("\n\n\n"));
1220
1221 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1222
52a7e64b
AM
1223 pdwMIC_L = (u32 *)(pbyPayloadHead + cbFrameBodySize);
1224 pdwMIC_R = (u32 *)(pbyPayloadHead + cbFrameBodySize + 4);
92b96797
FB
1225
1226 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1227 MIC_vUnInit();
1228
4e9b5e2b 1229 if (pDevice->bTxMICFail == true) {
92b96797
FB
1230 *pdwMIC_L = 0;
1231 *pdwMIC_R = 0;
e269fc2d 1232 pDevice->bTxMICFail = false;
92b96797
FB
1233 }
1234 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1235 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
1236 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1237 }
1238
4e9b5e2b 1239 if (bSoftWEP == true) {
92b96797 1240
3eaca0d2 1241 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (u16)(cbFrameBodySize + cbMIClen));
92b96797 1242
4e9b5e2b
AM
1243 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1244 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1245 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
92b96797
FB
1246 cbFrameSize -= cbICVlen;
1247 }
1248
92b96797 1249 cbFrameSize -= cbFCSlen;
92b96797
FB
1250
1251 *pcbHeaderLen = cbHeaderLength;
1252 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1253
92b96797 1254 //Set FragCtl in TxBufferHead
3eaca0d2 1255 pTxBufHead->wFragCtl |= (u16)byFragType;
92b96797 1256
4e9b5e2b 1257 return true;
92b96797
FB
1258
1259}
1260
92b96797
FB
1261/*+
1262 *
1263 * Description:
1264 * Translate 802.3 to 802.11 header
1265 *
1266 * Parameters:
1267 * In:
a0a1f61a 1268 * pDevice - Pointer to adapter
92b96797
FB
1269 * dwTxBufferAddr - Transmit Buffer
1270 * pPacket - Packet from upper layer
1271 * cbPacketSize - Transmit Data Length
1272 * Out:
1273 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
1274 * pcbAppendPayload - size of append payload for 802.1H translation
1275 *
1276 * Return Value: none
1277 *
1278-*/
1279
d56131de 1280static void s_vGenerateMACHeader(struct vnt_private *pDevice,
ceb8c5da 1281 u8 *pbyBufferAddr, u16 wDuration, struct ethhdr *psEthHeader,
05cc617b 1282 int bNeedEncrypt, u16 wFragType, u32 uFragIdx)
92b96797 1283{
1cac4a4b 1284 struct ieee80211_hdr *pMACHeader = (struct ieee80211_hdr *)pbyBufferAddr;
92b96797 1285
c921cc8c 1286 pMACHeader->frame_control = TYPE_802_11_DATA;
92b96797 1287
a0ad2776 1288 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
1cac4a4b 1289 memcpy(&(pMACHeader->addr1[0]),
ceb8c5da 1290 &(psEthHeader->h_dest[0]),
9a0e756c 1291 ETH_ALEN);
1cac4a4b
AM
1292 memcpy(&(pMACHeader->addr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1293 memcpy(&(pMACHeader->addr3[0]),
ceb8c5da 1294 &(psEthHeader->h_source[0]),
9a0e756c 1295 ETH_ALEN);
1cac4a4b 1296 pMACHeader->frame_control |= FC_FROMDS;
9a0e756c 1297 } else {
a0ad2776 1298 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1cac4a4b 1299 memcpy(&(pMACHeader->addr1[0]),
ceb8c5da 1300 &(psEthHeader->h_dest[0]),
9a0e756c 1301 ETH_ALEN);
1cac4a4b 1302 memcpy(&(pMACHeader->addr2[0]),
ceb8c5da 1303 &(psEthHeader->h_source[0]),
9a0e756c 1304 ETH_ALEN);
1cac4a4b 1305 memcpy(&(pMACHeader->addr3[0]),
9a0e756c
AM
1306 &(pDevice->abyBSSID[0]),
1307 ETH_ALEN);
1308 } else {
1cac4a4b 1309 memcpy(&(pMACHeader->addr3[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->addr1[0]),
9a0e756c
AM
1316 &(pDevice->abyBSSID[0]),
1317 ETH_ALEN);
1cac4a4b 1318 pMACHeader->frame_control |= FC_TODS;
92b96797
FB
1319 }
1320 }
1321
1322 if (bNeedEncrypt)
1cac4a4b 1323 pMACHeader->frame_control |= cpu_to_le16((u16)WLAN_SET_FC_ISWEP(1));
92b96797 1324
1cac4a4b 1325 pMACHeader->duration_id = cpu_to_le16(wDuration);
92b96797 1326
1cac4a4b 1327 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1328
1329 //Set FragNumber in Sequence Control
1cac4a4b 1330 pMACHeader->seq_ctrl |= cpu_to_le16((u16)uFragIdx);
92b96797
FB
1331
1332 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1333 pDevice->wSeqCounter++;
1334 if (pDevice->wSeqCounter > 0x0fff)
1335 pDevice->wSeqCounter = 0;
1336 }
1337
1338 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
1cac4a4b 1339 pMACHeader->frame_control |= FC_MOREFRAG;
92b96797
FB
1340 }
1341}
1342
92b96797
FB
1343/*+
1344 *
1345 * Description:
1346 * Request instructs a MAC to transmit a 802.11 management packet through
1347 * the adapter onto the medium.
1348 *
1349 * Parameters:
1350 * In:
1351 * hDeviceContext - Pointer to the adapter
1352 * pPacket - A pointer to a descriptor for the packet to transmit
1353 * Out:
1354 * none
1355 *
e269fc2d 1356 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
92b96797
FB
1357 *
1358-*/
1359
d56131de
MP
1360CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1361 struct vnt_tx_mgmt *pPacket)
92b96797 1362{
d56131de 1363 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 1364 struct vnt_tx_buffer *pTX_Buffer;
dcdf1d03 1365 struct vnt_usb_send_context *pContext;
d66caada 1366 struct vnt_tx_fifo_head *pTxBufHead;
1cac4a4b 1367 struct ieee80211_hdr *pMACHeader;
ceb8c5da 1368 struct ethhdr sEthHeader;
d56131de 1369 u8 byPktType, *pbyTxBufferAddr;
f0e0d505 1370 struct vnt_mic_hdr *pMICHDR = NULL;
d56131de 1371 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
e269fc2d 1372 int bNeedACK, bIsPSPOLL = false;
d56131de
MP
1373 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1374 u32 uPadding = 0;
1375 u16 wTxBufSize;
1376 u32 cbMacHdLen;
1377 u16 wCurrentRate = RATE_1M;
931cb9ff 1378 unsigned long flags;
92b96797 1379
931cb9ff
MP
1380 if (pDevice->byBBType == BB_TYPE_11A) {
1381 wCurrentRate = RATE_6M;
1382 byPktType = PK_TYPE_11A;
1383 } else {
1384 wCurrentRate = RATE_1M;
1385 byPktType = PK_TYPE_11B;
1386 }
92b96797 1387
931cb9ff 1388 if (pMgmt->eScanState != WMAC_NO_SCANNING)
4f5290ea 1389 vnt_rf_setpower(pDevice, wCurrentRate, pDevice->byCurrentCh);
931cb9ff 1390 else
4f5290ea 1391 vnt_rf_setpower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
931cb9ff
MP
1392
1393 pDevice->wCurrentRate = wCurrentRate;
1394
1395 spin_lock_irqsave(&pDevice->lock, flags);
1396
1397 pContext = s_vGetFreeContext(pDevice);
1398 if (!pContext) {
1399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1400 "ManagementSend TX...NO CONTEXT!\n");
1401 spin_unlock_irqrestore(&pDevice->lock, flags);
1402 return CMD_STATUS_RESOURCES;
1403 }
92b96797 1404
30a05b39 1405 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
92b96797 1406 cbFrameBodySize = pPacket->cbPayloadLen;
d66caada
MP
1407 pTxBufHead = &pTX_Buffer->fifo_head;
1408 pbyTxBufferAddr = (u8 *)&pTxBufHead->adwTxKey[0];
1409 wTxBufSize = sizeof(struct vnt_tx_fifo_head);
92b96797 1410
92b96797 1411
92b96797
FB
1412 //Set packet type
1413 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
1414 pTxBufHead->wFIFOCtl = 0;
1415 }
1416 else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
1417 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
1418 }
1419 else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
1420 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
1421 }
1422 else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
1423 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
1424 }
1425
1426 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
5846251d 1427 pTxBufHead->time_stamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
92b96797 1428
22040bbf 1429 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
e269fc2d 1430 bNeedACK = false;
92b96797
FB
1431 }
1432 else {
4e9b5e2b 1433 bNeedACK = true;
92b96797
FB
1434 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1435 };
1436
1437 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
1438 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
1439
1440 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
1441 //Set Preamble type always long
1442 //pDevice->byPreambleType = PREAMBLE_LONG;
1443 // probe-response don't retry
1444 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
e269fc2d 1445 // bNeedACK = false;
92b96797
FB
1446 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
1447 //}
1448 }
1449
1450 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
1451
1452 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
4e9b5e2b 1453 bIsPSPOLL = true;
92b96797
FB
1454 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
1455 } else {
1456 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
1457 }
1458
1459 //Set FRAGCTL_MACHDCNT
3eaca0d2 1460 pTxBufHead->wFragCtl |= cpu_to_le16((u16)(cbMacHdLen << 10));
92b96797
FB
1461
1462 // Notes:
1463 // Although spec says MMPDU can be fragmented; In most case,
1464 // no one will send a MMPDU under fragmentation. With RTS may occur.
92b96797
FB
1465
1466 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
1467 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
1468 cbIVlen = 4;
1469 cbICVlen = 4;
1470 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1471 }
1472 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
1473 cbIVlen = 8;//IV+ExtIV
1474 cbMIClen = 8;
1475 cbICVlen = 4;
1476 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1477 //We need to get seed here for filling TxKey entry.
1478 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
1479 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
1480 }
1481 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
1482 cbIVlen = 8;//RSN Header
1483 cbICVlen = 8;//MIC
1484 pTxBufHead->wFragCtl |= FRAGCTL_AES;
92b96797
FB
1485 }
1486 //MAC Header should be padding 0 to DW alignment.
1487 uPadding = 4 - (cbMacHdLen%4);
1488 uPadding %= 4;
1489 }
1490
1491 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
1492
1493 //Set FIFOCTL_GrpAckPolicy
4e9b5e2b 1494 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
92b96797
FB
1495 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1496 }
1497 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
1498
1499 //Set RrvTime/RTS/CTS Buffer
1500 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
4f990057 1501 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
78363fd1 1502 sizeof(struct vnt_cts);
92b96797
FB
1503 }
1504 else { // 802.11a/b packet
976467d3 1505 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
558becf1 1506 sizeof(struct vnt_tx_datahead_ab);
92b96797
FB
1507 }
1508
ceb8c5da 1509 memcpy(&(sEthHeader.h_dest[0]),
9a0e756c
AM
1510 &(pPacket->p80211Header->sA3.abyAddr1[0]),
1511 ETH_ALEN);
ceb8c5da 1512 memcpy(&(sEthHeader.h_source[0]),
9a0e756c
AM
1513 &(pPacket->p80211Header->sA3.abyAddr2[0]),
1514 ETH_ALEN);
92b96797
FB
1515 //=========================
1516 // No Fragmentation
1517 //=========================
3eaca0d2 1518 pTxBufHead->wFragCtl |= (u16)FRAGCTL_NONFRAG;
92b96797 1519
351c7dc3 1520 /* Fill FIFO,RrvTime,RTS,and CTS */
78363fd1 1521 uDuration = s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
fa57560c 1522 pTX_Buffer, &pMICHDR, 0,
05cc617b 1523 cbFrameSize, bNeedACK, &sEthHeader, false);
92b96797 1524
1cac4a4b 1525 pMACHeader = (struct ieee80211_hdr *) (pbyTxBufferAddr + cbHeaderSize);
92b96797
FB
1526
1527 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
1528
1529 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
b902fbfe
AM
1530 u8 * pbyIVHead;
1531 u8 * pbyPayloadHead;
1532 u8 * pbyBSSID;
92b96797
FB
1533 PSKeyItem pTransmitKey = NULL;
1534
b902fbfe
AM
1535 pbyIVHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
1536 pbyPayloadHead = (u8 *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
92b96797 1537 do {
a0ad2776
MP
1538 if (pDevice->op_mode == NL80211_IFTYPE_STATION &&
1539 pDevice->bLinkPass == true) {
92b96797
FB
1540 pbyBSSID = pDevice->abyBSSID;
1541 // get pairwise key
e269fc2d 1542 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
92b96797 1543 // get group key
4e9b5e2b 1544 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
92b96797
FB
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1546 break;
1547 }
1548 } else {
1549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
1550 break;
1551 }
1552 }
1553 // get group key
1554 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 1555 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797 1556 pTransmitKey = NULL;
a0ad2776 1557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->op_mode);
92b96797
FB
1558 } else {
1559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
1560 }
e269fc2d 1561 } while(false);
92b96797 1562 //Fill TXKEY
3ba0938c 1563 s_vFillTxKey(pDevice, pTxBufHead, pbyIVHead, pTransmitKey,
3eaca0d2 1564 (u8 *)pMACHeader, (u16)cbFrameBodySize, NULL);
92b96797 1565
3e362598 1566 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
b902fbfe 1567 memcpy(pbyPayloadHead, ((u8 *)(pPacket->p80211Header) + cbMacHdLen),
92b96797
FB
1568 cbFrameBodySize);
1569 }
1570 else {
1571 // Copy the Packet into a tx Buffer
3e362598 1572 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
92b96797
FB
1573 }
1574
1cac4a4b 1575 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
92b96797
FB
1576 pDevice->wSeqCounter++ ;
1577 if (pDevice->wSeqCounter > 0x0fff)
1578 pDevice->wSeqCounter = 0;
1579
1580 if (bIsPSPOLL) {
1581 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
a0a1f61a 1582 // of FIFO control header.
92b96797
FB
1583 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
1584 // in the same place of other packet's Duration-field).
1585 // And it will cause Cisco-AP to issue Disassociation-packet
7e60a3de 1586 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
78363fd1
MP
1587 struct vnt_tx_datahead_g *data_head = &pTX_Buffer->tx_head.
1588 tx_cts.tx.head.cts_g.data_head;
4e01117c 1589 data_head->duration_a =
7e60a3de 1590 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
4e01117c 1591 data_head->duration_b =
7e60a3de
MP
1592 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1593 } else {
c12dca09
MP
1594 struct vnt_tx_datahead_ab *data_head = &pTX_Buffer->tx_head.
1595 tx_ab.tx.head.data_head_ab;
4e01117c 1596 data_head->duration =
558becf1
MP
1597 cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
1598 }
92b96797
FB
1599 }
1600
ca347596 1601 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)(cbReqCount));
b902fbfe 1602 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
1603 pTX_Buffer->byType = 0x00;
1604
30a05b39
MP
1605 pContext->skb = NULL;
1606 pContext->type = CONTEXT_MGMT_PACKET;
1607 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
92b96797 1608
1cac4a4b 1609 if (WLAN_GET_FC_TODS(pMACHeader->frame_control) == 0) {
d66caada
MP
1610 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1611 &pMACHeader->addr1[0], (u16)cbFrameSize,
1612 pTxBufHead->wFIFOCtl);
92b96797
FB
1613 }
1614 else {
d66caada
MP
1615 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
1616 &pMACHeader->addr3[0], (u16)cbFrameSize,
1617 pTxBufHead->wFIFOCtl);
92b96797
FB
1618 }
1619
1620 PIPEnsSendBulkOut(pDevice,pContext);
931cb9ff
MP
1621
1622 spin_unlock_irqrestore(&pDevice->lock, flags);
1623
92b96797
FB
1624 return CMD_STATUS_PENDING;
1625}
1626
d56131de
MP
1627CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
1628 struct vnt_tx_mgmt *pPacket)
92b96797 1629{
01f865ba 1630 struct vnt_beacon_buffer *pTX_Buffer;
c7c57b24 1631 struct vnt_tx_short_buf_head *short_head;
d56131de
MP
1632 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
1633 u32 cbHeaderSize = 0;
1cac4a4b 1634 struct ieee80211_hdr *pMACHeader;
d56131de
MP
1635 u16 wCurrentRate;
1636 u32 cbFrameBodySize;
1637 u32 cbReqCount;
dcdf1d03 1638 struct vnt_usb_send_context *pContext;
d56131de 1639 CMD_STATUS status;
92b96797 1640
aceaf018 1641 pContext = s_vGetFreeContext(pDevice);
92b96797
FB
1642 if (NULL == pContext) {
1643 status = CMD_STATUS_RESOURCES;
1644 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1645 return status ;
1646 }
01f865ba 1647
30a05b39 1648 pTX_Buffer = (struct vnt_beacon_buffer *)&pContext->data[0];
c7c57b24 1649 short_head = &pTX_Buffer->short_head;
92b96797
FB
1650
1651 cbFrameBodySize = pPacket->cbPayloadLen;
1652
c7c57b24 1653 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
92b96797 1654
c7c57b24
MP
1655 if (pDevice->byBBType == BB_TYPE_11A) {
1656 wCurrentRate = RATE_6M;
1657
1658 /* Get SignalField,ServiceField,Length */
1659 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1660 PK_TYPE_11A, &short_head->ab);
1661
1662 /* Get Duration and TimeStampOff */
1663 short_head->duration = s_uGetDataDuration(pDevice,
1664 PK_TYPE_11A, false);
1665 short_head->time_stamp_off =
1666 vnt_time_stamp_off(pDevice, wCurrentRate);
1667 } else {
1668 wCurrentRate = RATE_1M;
1669 short_head->fifo_ctl |= FIFOCTL_11B;
1670
1671 /* Get SignalField,ServiceField,Length */
1672 BBvCalculateParameter(pDevice, cbFrameSize, wCurrentRate,
1673 PK_TYPE_11B, &short_head->ab);
1674
1675 /* Get Duration and TimeStampOff */
1676 short_head->duration = s_uGetDataDuration(pDevice,
6b5ad9d2 1677 PK_TYPE_11B, false);
c7c57b24
MP
1678 short_head->time_stamp_off =
1679 vnt_time_stamp_off(pDevice, wCurrentRate);
1680 }
1681
92b96797 1682
0b71fe36
MP
1683 /* Generate Beacon Header */
1684 pMACHeader = &pTX_Buffer->hdr;
92b96797 1685
0b71fe36
MP
1686 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
1687
1688 pMACHeader->duration_id = 0;
1689 pMACHeader->seq_ctrl = cpu_to_le16(pDevice->wSeqCounter << 4);
1690 pDevice->wSeqCounter++;
1691 if (pDevice->wSeqCounter > 0x0fff)
1692 pDevice->wSeqCounter = 0;
92b96797
FB
1693
1694 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
1695
fad8e4ae 1696 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)cbReqCount);
b902fbfe 1697 pTX_Buffer->byPKTNO = (u8) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
92b96797
FB
1698 pTX_Buffer->byType = 0x01;
1699
30a05b39
MP
1700 pContext->skb = NULL;
1701 pContext->type = CONTEXT_MGMT_PACKET;
1702 pContext->buf_len = (u16)cbReqCount + 4; /* USB header */
92b96797
FB
1703
1704 PIPEnsSendBulkOut(pDevice,pContext);
1705 return CMD_STATUS_PENDING;
1706
1707}
1708
92b96797
FB
1709//TYPE_AC0DMA data tx
1710/*
1711 * Description:
1712 * Tx packet via AC0DMA(DMA1)
1713 *
1714 * Parameters:
1715 * In:
1716 * pDevice - Pointer to the adapter
1717 * skb - Pointer to tx skb packet
1718 * Out:
1719 * void
1720 *
1721 * Return Value: NULL
1722 */
1723
05cc617b 1724int nsDMA_tx_packet(struct vnt_private *pDevice, struct sk_buff *skb)
92b96797 1725{
d56131de
MP
1726 struct net_device_stats *pStats = &pDevice->stats;
1727 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
f39c0d8e 1728 struct vnt_tx_buffer *pTX_Buffer;
d56131de
MP
1729 u32 BytesToWrite = 0, uHeaderLen = 0;
1730 u32 uNodeIndex = 0;
1731 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1732 u16 wAID;
1733 u8 byPktType;
e269fc2d 1734 int bNeedEncryption = false;
d56131de 1735 PSKeyItem pTransmitKey = NULL;
d56131de 1736 int ii;
e269fc2d
AM
1737 int bTKIP_UseGTK = false;
1738 int bNeedDeAuth = false;
d56131de 1739 u8 *pbyBSSID;
e269fc2d 1740 int bNodeExist = false;
dcdf1d03 1741 struct vnt_usb_send_context *pContext;
dfdcc425 1742 bool fConvertedPacket;
d56131de
MP
1743 u32 status;
1744 u16 wKeepRate = pDevice->wCurrentRate;
e269fc2d 1745 int bTxeapol_key = false;
92b96797 1746
92b96797
FB
1747 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1748
1749 if (pDevice->uAssocCount == 0) {
1750 dev_kfree_skb_irq(skb);
1751 return 0;
1752 }
1753
b902fbfe 1754 if (is_multicast_ether_addr((u8 *)(skb->data))) {
92b96797 1755 uNodeIndex = 0;
4e9b5e2b 1756 bNodeExist = true;
92b96797
FB
1757 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1758
1759 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1760 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1761 // set tx map
1762 pMgmt->abyPSTxMap[0] |= byMask[0];
1763 return 0;
1764 }
93184690 1765 // multicast/broadcast data rate
92b96797
FB
1766
1767 if (pDevice->byBBType != BB_TYPE_11A)
1768 pDevice->wCurrentRate = RATE_2M;
1769 else
1770 pDevice->wCurrentRate = RATE_24M;
1771 // long preamble type
1772 pDevice->byPreambleType = PREAMBLE_SHORT;
1773
1774 }else {
1775
b902fbfe 1776 if (BSSbIsSTAInNodeDB(pDevice, (u8 *)(skb->data), &uNodeIndex)) {
92b96797
FB
1777
1778 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1779
1780 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1781
1782 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1783 // set tx map
1784 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1785 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1787 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1788
1789 return 0;
1790 }
1791 // AP rate decided from node
1792 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1793 // tx preamble decided from node
1794
1795 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1796 pDevice->byPreambleType = pDevice->byShortPreamble;
1797
1798 }else {
1799 pDevice->byPreambleType = PREAMBLE_LONG;
1800 }
4e9b5e2b 1801 bNodeExist = true;
92b96797
FB
1802 }
1803 }
1804
e269fc2d 1805 if (bNodeExist == false) {
92b96797
FB
1806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
1807 dev_kfree_skb_irq(skb);
1808 return 0;
1809 }
1810 }
1811
838c2d6c 1812 memcpy(&pDevice->sTxEthHeader, skb->data, ETH_HLEN);
92b96797
FB
1813
1814//mike add:station mode check eapol-key challenge--->
1815{
b902fbfe
AM
1816 u8 Protocol_Version; //802.1x Authentication
1817 u8 Packet_Type; //802.1x Authentication
1818 u8 Descriptor_type;
3eaca0d2 1819 u16 Key_info;
92b96797 1820
21ec51f3
CC
1821 Protocol_Version = skb->data[ETH_HLEN];
1822 Packet_Type = skb->data[ETH_HLEN+1];
1823 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1824 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
ceb8c5da 1825 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
aa209eef
MP
1826 /* 802.1x OR eapol-key challenge frame transfer */
1827 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1828 (Packet_Type == 3)) {
4e9b5e2b 1829 bTxeapol_key = true;
92b96797
FB
1830 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
1831 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1832 if(Descriptor_type==254) {
4e9b5e2b 1833 pDevice->fWPA_Authened = true;
92b96797
FB
1834 PRINT_K("WPA ");
1835 }
1836 else {
4e9b5e2b 1837 pDevice->fWPA_Authened = true;
92b96797
FB
1838 PRINT_K("WPA2(re-keying) ");
1839 }
1840 PRINT_K("Authentication completed!!\n");
1841 }
a0a1f61a 1842 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
92b96797 1843 (Key_info & BIT8) && (Key_info & BIT9)) {
4e9b5e2b 1844 pDevice->fWPA_Authened = true;
92b96797
FB
1845 PRINT_K("WPA2 Authentication completed!!\n");
1846 }
1847 }
1848 }
1849}
1850//mike add:station mode check eapol-key challenge<---
1851
4e9b5e2b
AM
1852 if (pDevice->bEncryptionEnable == true) {
1853 bNeedEncryption = true;
92b96797
FB
1854 // get Transmit key
1855 do {
1856 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1857 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1858 pbyBSSID = pDevice->abyBSSID;
1859 // get pairwise key
e269fc2d 1860 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
92b96797 1861 // get group key
4e9b5e2b
AM
1862 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1863 bTKIP_UseGTK = true;
92b96797
FB
1864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1865 break;
1866 }
1867 } else {
1868 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
1869 break;
1870 }
1871 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
ceb8c5da
AM
1872 /* TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1 */
1873 pbyBSSID = pDevice->sTxEthHeader.h_dest;
92b96797
FB
1874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
1875 for (ii = 0; ii< 6; ii++)
1876 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
1877 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
1878
1879 // get pairwise key
4e9b5e2b 1880 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
92b96797
FB
1881 break;
1882 }
1883 // get group key
1884 pbyBSSID = pDevice->abyBroadcastAddr;
e269fc2d 1885 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
92b96797
FB
1886 pTransmitKey = NULL;
1887 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1889 }
1890 else
1891 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
1892 } else {
4e9b5e2b 1893 bTKIP_UseGTK = true;
92b96797
FB
1894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
1895 }
e269fc2d 1896 } while(false);
92b96797
FB
1897 }
1898
b902fbfe 1899 byPktType = (u8)pDevice->byPacketType;
92b96797
FB
1900
1901 if (pDevice->bFixRate) {
1902 if (pDevice->byBBType == BB_TYPE_11B) {
1903 if (pDevice->uConnectionRate >= RATE_11M) {
1904 pDevice->wCurrentRate = RATE_11M;
1905 } else {
3eaca0d2 1906 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
1907 }
1908 } else {
1909 if ((pDevice->byBBType == BB_TYPE_11A) &&
1910 (pDevice->uConnectionRate <= RATE_6M)) {
1911 pDevice->wCurrentRate = RATE_6M;
1912 } else {
1913 if (pDevice->uConnectionRate >= RATE_54M)
1914 pDevice->wCurrentRate = RATE_54M;
1915 else
3eaca0d2 1916 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
92b96797
FB
1917 }
1918 }
1919 }
1920 else {
a0ad2776 1921 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
92b96797 1922 // Adhoc Tx rate decided from node DB
ceb8c5da 1923 if (is_multicast_ether_addr(pDevice->sTxEthHeader.h_dest)) {
92b96797
FB
1924 // Multicast use highest data rate
1925 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1926 // preamble type
1927 pDevice->byPreambleType = pDevice->byShortPreamble;
1928 }
1929 else {
ceb8c5da 1930 if (BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.h_dest[0]), &uNodeIndex)) {
92b96797
FB
1931 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1932 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
1933 pDevice->byPreambleType = pDevice->byShortPreamble;
1934
1935 }
1936 else {
1937 pDevice->byPreambleType = PREAMBLE_LONG;
1938 }
1939 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
1940 }
1941 else {
1942 if (pDevice->byBBType != BB_TYPE_11A)
1943 pDevice->wCurrentRate = RATE_2M;
1944 else
1945 pDevice->wCurrentRate = RATE_24M; // refer to vMgrCreateOwnIBSS()'s
1946 // abyCurrExtSuppRates[]
1947 pDevice->byPreambleType = PREAMBLE_SHORT;
1948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
1949 }
1950 }
1951 }
a0ad2776 1952 if (pDevice->op_mode == NL80211_IFTYPE_STATION) {
92b96797
FB
1953 // Infra STA rate decided from AP Node, index = 0
1954 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
1955 }
1956 }
1957
ceb8c5da 1958 if (pDevice->sTxEthHeader.h_proto == cpu_to_be16(ETH_P_PAE)) {
aa209eef
MP
1959 if (pDevice->byBBType != BB_TYPE_11A) {
1960 pDevice->wCurrentRate = RATE_1M;
aa209eef
MP
1961 pDevice->byTopCCKBasicRate = RATE_1M;
1962 pDevice->byTopOFDMBasicRate = RATE_6M;
1963 } else {
1964 pDevice->wCurrentRate = RATE_6M;
aa209eef
MP
1965 pDevice->byTopCCKBasicRate = RATE_1M;
1966 pDevice->byTopOFDMBasicRate = RATE_6M;
1967 }
1968 }
92b96797 1969
0cbd8d98
AM
1970 DBG_PRT(MSG_LEVEL_DEBUG,
1971 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
1972 pDevice->wCurrentRate);
92b96797
FB
1973
1974 if (wKeepRate != pDevice->wCurrentRate) {
0cbd8d98 1975 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
92b96797
FB
1976 }
1977
1978 if (pDevice->wCurrentRate <= RATE_11M) {
1979 byPktType = PK_TYPE_11B;
1980 }
1981
4e9b5e2b 1982 if (bNeedEncryption == true) {
ceb8c5da
AM
1983 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.h_proto));
1984 if ((pDevice->sTxEthHeader.h_proto) == cpu_to_be16(ETH_P_PAE)) {
e269fc2d 1985 bNeedEncryption = false;
ceb8c5da 1986 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.h_proto));
92b96797
FB
1987 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1988 if (pTransmitKey == NULL) {
1989 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
1990 }
1991 else {
4e9b5e2b 1992 if (bTKIP_UseGTK == true) {
92b96797
FB
1993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
1994 }
1995 else {
b4dc03af
MP
1996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
1997 pTransmitKey->dwKeyIndex);
4e9b5e2b 1998 bNeedEncryption = true;
92b96797
FB
1999 }
2000 }
2001 }
92b96797
FB
2002 }
2003 else {
2004
92b96797
FB
2005 if (pTransmitKey == NULL) {
2006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2007 dev_kfree_skb_irq(skb);
2008 pStats->tx_dropped++;
2009 return STATUS_FAILURE;
2010 }
92b96797
FB
2011 }
2012 }
2013
b674ee14
MP
2014 pContext = s_vGetFreeContext(pDevice);
2015 if (!pContext) {
2016 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2017 dev_kfree_skb_irq(skb);
2018 return STATUS_RESOURCES;
2019 }
2020
30a05b39 2021 pTX_Buffer = (struct vnt_tx_buffer *)&pContext->data[0];
d0a2b8fa 2022
92b96797 2023 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
d0a2b8fa 2024 pTX_Buffer, bNeedEncryption,
05cc617b 2025 skb->len, &pDevice->sTxEthHeader,
b902fbfe 2026 (u8 *)skb->data, pTransmitKey, uNodeIndex,
92b96797
FB
2027 pDevice->wCurrentRate,
2028 &uHeaderLen, &BytesToWrite
2029 );
2030
30a05b39
MP
2031 if (fConvertedPacket == false) {
2032 pContext->in_use = false;
2033 dev_kfree_skb_irq(skb);
2034 return STATUS_FAILURE;
2035 }
92b96797 2036
4e9b5e2b 2037 if ( pDevice->bEnablePSMode == true ) {
92b96797 2038 if ( !pDevice->bPSModeTxBurst ) {
0cbd8d98
AM
2039 bScheduleCommand((void *) pDevice,
2040 WLAN_CMD_MAC_DISPOWERSAVING,
2041 NULL);
4e9b5e2b 2042 pDevice->bPSModeTxBurst = true;
92b96797
FB
2043 }
2044 }
2045
b902fbfe 2046 pTX_Buffer->byPKTNO = (u8) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
ca347596 2047 pTX_Buffer->tx_byte_count = cpu_to_le16((u16)BytesToWrite);
92b96797 2048
30a05b39
MP
2049 pContext->skb = skb;
2050 pContext->type = CONTEXT_DATA_PACKET;
2051 pContext->buf_len = (u16)BytesToWrite + 4 ; /* USB header */
92b96797 2052
d66caada 2053 s_vSaveTxPktInfo(pDevice, (u8)(pTX_Buffer->byPKTNO & 0x0F),
81aec60e 2054 &pDevice->sTxEthHeader.h_dest[0],
d66caada
MP
2055 (u16)(BytesToWrite-uHeaderLen),
2056 pTX_Buffer->fifo_head.wFIFOCtl);
92b96797
FB
2057
2058 status = PIPEnsSendBulkOut(pDevice,pContext);
2059
4e9b5e2b 2060 if (bNeedDeAuth == true) {
3eaca0d2 2061 u16 wReason = WLAN_MGMT_REASON_MIC_FAILURE;
92b96797 2062
b902fbfe 2063 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (u8 *) &wReason);
92b96797
FB
2064 }
2065
30a05b39
MP
2066 if (status != STATUS_PENDING) {
2067 pContext->in_use = false;
2068 dev_kfree_skb_irq(skb);
2069 return STATUS_FAILURE;
2070 }
92b96797 2071
30a05b39
MP
2072
2073 return 0;
92b96797 2074}