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