1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 "baseband.h"
56#include "michael.h"
57#include "tkip.h"
58#include "tcrc.h"
59#include "wctl.h"
60#include "hostap.h"
61#include "rf.h"
62#include "datarate.h"
63#include "usbpipe.h"
64#include "iocmd.h"
65
66
67
68
69
70
71static int msglevel = MSG_LEVEL_INFO;
72
73
74
75
76#define CRITICAL_PACKET_LEN 256
77
78
79const WORD wTimeStampOff[2][MAX_RATE] = {
80 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23},
81 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23},
82 };
83
84const WORD wFB_Opt0[2][5] = {
85 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M},
86 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M},
87 };
88const WORD wFB_Opt1[2][5] = {
89 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M},
90 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M},
91 };
92
93
94#define RTSDUR_BB 0
95#define RTSDUR_BA 1
96#define RTSDUR_AA 2
97#define CTSDUR_BA 3
98#define RTSDUR_BA_F0 4
99#define RTSDUR_AA_F0 5
100#define RTSDUR_BA_F1 6
101#define RTSDUR_AA_F1 7
102#define CTSDUR_BA_F0 8
103#define CTSDUR_BA_F1 9
104#define DATADUR_B 10
105#define DATADUR_A 11
106#define DATADUR_A_F0 12
107#define DATADUR_A_F1 13
108
109
110
111static
112void
113s_vSaveTxPktInfo(
114 PSDevice pDevice,
115 BYTE byPktNum,
116 PBYTE pbyDestAddr,
117 WORD wPktLength,
118 WORD wFIFOCtl
119);
120
121static
122void *
123s_vGetFreeContext(
124 PSDevice pDevice
125 );
126
127
128static
129void
130s_vGenerateTxParameter(
131 PSDevice pDevice,
132 BYTE byPktType,
133 WORD wCurrentRate,
134 void *pTxBufHead,
135 void *pvRrvTime,
136 void *pvRTS,
137 void *pvCTS,
138 unsigned int cbFrameSize,
139 BOOL bNeedACK,
140 unsigned int uDMAIdx,
141 PSEthernetHeader psEthHeader
142 );
143
144
145static unsigned int s_uFillDataHead(
146 PSDevice pDevice,
147 BYTE byPktType,
148 WORD wCurrentRate,
149 void *pTxDataHead,
150 unsigned int cbFrameLength,
151 unsigned int uDMAIdx,
152 BOOL bNeedAck,
153 unsigned int uFragIdx,
154 unsigned int cbLastFragmentSize,
155 unsigned int uMACfragNum,
156 BYTE byFBOption
157 );
158
159
160
161
162static
163void
164s_vGenerateMACHeader (
165 PSDevice pDevice,
166 PBYTE pbyBufferAddr,
167 WORD wDuration,
168 PSEthernetHeader psEthHeader,
169 BOOL bNeedEncrypt,
170 WORD wFragType,
171 unsigned int uDMAIdx,
172 unsigned int uFragIdx
173 );
174
175static
176void
177s_vFillTxKey(
178 PSDevice pDevice,
179 PBYTE pbyBuf,
180 PBYTE pbyIVHead,
181 PSKeyItem pTransmitKey,
182 PBYTE pbyHdrBuf,
183 WORD wPayloadLen,
184 PBYTE pMICHDR
185 );
186
187static
188void
189s_vSWencryption (
190 PSDevice pDevice,
191 PSKeyItem pTransmitKey,
192 PBYTE pbyPayloadHead,
193 WORD wPayloadSize
194 );
195
196static unsigned int s_uGetTxRsvTime(
197 PSDevice pDevice,
198 BYTE byPktType,
199 unsigned int cbFrameLength,
200 WORD wRate,
201 BOOL bNeedAck
202 );
203
204
205static unsigned int s_uGetRTSCTSRsvTime(
206 PSDevice pDevice,
207 BYTE byRTSRsvType,
208 BYTE byPktType,
209 unsigned int cbFrameLength,
210 WORD wCurrentRate
211 );
212
213static
214void
215s_vFillCTSHead (
216 PSDevice pDevice,
217 unsigned int uDMAIdx,
218 BYTE byPktType,
219 void *pvCTS,
220 unsigned int cbFrameLength,
221 BOOL bNeedAck,
222 BOOL bDisCRC,
223 WORD wCurrentRate,
224 BYTE byFBOption
225 );
226
227static
228void
229s_vFillRTSHead(
230 PSDevice pDevice,
231 BYTE byPktType,
232 void *pvRTS,
233 unsigned int cbFrameLength,
234 BOOL bNeedAck,
235 BOOL bDisCRC,
236 PSEthernetHeader psEthHeader,
237 WORD wCurrentRate,
238 BYTE byFBOption
239 );
240
241static unsigned int s_uGetDataDuration(
242 PSDevice pDevice,
243 BYTE byDurType,
244 unsigned int cbFrameLength,
245 BYTE byPktType,
246 WORD wRate,
247 BOOL bNeedAck,
248 unsigned int uFragIdx,
249 unsigned int cbLastFragmentSize,
250 unsigned int uMACfragNum,
251 BYTE byFBOption
252 );
253
254
255static
256unsigned int
257s_uGetRTSCTSDuration (
258 PSDevice pDevice,
259 BYTE byDurType,
260 unsigned int cbFrameLength,
261 BYTE byPktType,
262 WORD wRate,
263 BOOL bNeedAck,
264 BYTE byFBOption
265 );
266
267
268
269
270static
271void *
272s_vGetFreeContext(
273 PSDevice pDevice
274 )
275{
276 PUSB_SEND_CONTEXT pContext = NULL;
277 PUSB_SEND_CONTEXT pReturnContext = NULL;
278 unsigned int ii;
279
280 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
281
282 for (ii = 0; ii < pDevice->cbTD; ii++) {
283 pContext = pDevice->apTD[ii];
284 if (pContext->bBoolInUse == FALSE) {
285 pContext->bBoolInUse = TRUE;
286 pReturnContext = pContext;
287 break;
288 }
289 }
290 if ( ii == pDevice->cbTD ) {
291 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Free Tx Context\n");
292 }
293 return (void *) pReturnContext;
294}
295
296
297static
298void
299s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLength, WORD wFIFOCtl)
300{
301 PSStatCounter pStatistic=&(pDevice->scStatistic);
302
303 if (is_broadcast_ether_addr(pbyDestAddr))
304 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
305 else if (is_multicast_ether_addr(pbyDestAddr))
306 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_MULTI;
307 else
308 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_UNI;
309
310 pStatistic->abyTxPktInfo[byPktNum].wLength = wPktLength;
311 pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl = wFIFOCtl;
312 memcpy(pStatistic->abyTxPktInfo[byPktNum].abyDestAddr,
313 pbyDestAddr,
314 ETH_ALEN);
315}
316
317static
318void
319s_vFillTxKey (
320 PSDevice pDevice,
321 PBYTE pbyBuf,
322 PBYTE pbyIVHead,
323 PSKeyItem pTransmitKey,
324 PBYTE pbyHdrBuf,
325 WORD wPayloadLen,
326 PBYTE pMICHDR
327 )
328{
329 PDWORD pdwIV = (PDWORD) pbyIVHead;
330 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
331 WORD wValue;
332 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
333 DWORD dwRevIVCounter;
334
335
336
337
338 if (pTransmitKey == NULL)
339 return;
340
341 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
342 *pdwIV = pDevice->dwIVCounter;
343 pDevice->byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
344
345 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
346 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
347 memcpy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
348 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
349 } else {
350 memcpy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
351 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
352 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
353 memcpy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
354 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
355 }
356 memcpy(pDevice->abyPRNG, pbyBuf, 16);
357 }
358
359 *pdwIV &= WEP_IV_MASK;
360 *pdwIV |= (pDevice->byKeyIndex << 30);
361 *pdwIV = cpu_to_le32(*pdwIV);
362 pDevice->dwIVCounter++;
363 if (pDevice->dwIVCounter > WEP_IV_MASK) {
364 pDevice->dwIVCounter = 0;
365 }
366 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
367 pTransmitKey->wTSC15_0++;
368 if (pTransmitKey->wTSC15_0 == 0) {
369 pTransmitKey->dwTSC47_16++;
370 }
371 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
372 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
373 memcpy(pbyBuf, pDevice->abyPRNG, 16);
374
375 memcpy(pdwIV, pDevice->abyPRNG, 3);
376
377 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20);
378
379 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
381
382 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
383 pTransmitKey->wTSC15_0++;
384 if (pTransmitKey->wTSC15_0 == 0) {
385 pTransmitKey->dwTSC47_16++;
386 }
387 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
388
389
390 *pdwIV = 0;
391 *(pbyIVHead+3) = (BYTE)(((pDevice->byKeyIndex << 6) & 0xc0) | 0x20);
392 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
393
394 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
395
396
397 *pMICHDR = 0x59;
398 *((PBYTE)(pMICHDR+1)) = 0;
399 memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
400 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
401 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
402 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
403 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
404 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
405 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
406 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
407 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
408
409
410 *((PBYTE)(pMICHDR+16)) = 0;
411 if (pDevice->bLongHeader) {
412 *((PBYTE)(pMICHDR+17)) = 28;
413 } else {
414 *((PBYTE)(pMICHDR+17)) = 22;
415 }
416 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
417 memcpy(pMICHDR+18, (PBYTE)&wValue, 2);
418 memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
419 memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
420
421
422 memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
423 wValue = pMACHeader->wSeqCtl;
424 wValue &= 0x000F;
425 wValue = cpu_to_le16(wValue);
426 memcpy(pMICHDR+38, (PBYTE)&wValue, 2);
427 if (pDevice->bLongHeader) {
428 memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
429 }
430 }
431}
432
433
434static
435void
436s_vSWencryption (
437 PSDevice pDevice,
438 PSKeyItem pTransmitKey,
439 PBYTE pbyPayloadHead,
440 WORD wPayloadSize
441 )
442{
443 unsigned int cbICVlen = 4;
444 DWORD dwICV = 0xFFFFFFFFL;
445 PDWORD pdwICV;
446
447 if (pTransmitKey == NULL)
448 return;
449
450 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
451
452
453 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);
454 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
455
456 *pdwICV = cpu_to_le32(~dwICV);
457
458 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
459 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
460
461 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
462
463
464 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);
465 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
466
467 *pdwICV = cpu_to_le32(~dwICV);
468
469 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
470 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
471
472 }
473}
474
475
476
477
478
479
480
481
482
483static
484unsigned int
485s_uGetTxRsvTime (
486 PSDevice pDevice,
487 BYTE byPktType,
488 unsigned int cbFrameLength,
489 WORD wRate,
490 BOOL bNeedAck
491 )
492{
493 unsigned int uDataTime, uAckTime;
494
495 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
496 if (byPktType == PK_TYPE_11B) {
497 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopCCKBasicRate);
498 } else {
499 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (WORD)pDevice->byTopOFDMBasicRate);
500 }
501
502 if (bNeedAck) {
503 return (uDataTime + pDevice->uSIFS + uAckTime);
504 }
505 else {
506 return uDataTime;
507 }
508}
509
510
511static
512unsigned int
513s_uGetRTSCTSRsvTime (
514 PSDevice pDevice,
515 BYTE byRTSRsvType,
516 BYTE byPktType,
517 unsigned int cbFrameLength,
518 WORD wCurrentRate
519 )
520{
521 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
522
523 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
524
525
526 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
527 if (byRTSRsvType == 0) {
528 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
529 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
530 }
531 else if (byRTSRsvType == 1){
532 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
533 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
534 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
535 }
536 else if (byRTSRsvType == 2) {
537 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
538 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
539 }
540 else if (byRTSRsvType == 3) {
541 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
542 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
543 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
544 return uRrvTime;
545 }
546
547
548 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
549 return uRrvTime;
550}
551
552
553static
554unsigned int
555s_uGetDataDuration (
556 PSDevice pDevice,
557 BYTE byDurType,
558 unsigned int cbFrameLength,
559 BYTE byPktType,
560 WORD wRate,
561 BOOL bNeedAck,
562 unsigned int uFragIdx,
563 unsigned int cbLastFragmentSize,
564 unsigned int uMACfragNum,
565 BYTE byFBOption
566 )
567{
568 BOOL bLastFrag = 0;
569 unsigned int uAckTime = 0, uNextPktTime = 0;
570
571 if (uFragIdx == (uMACfragNum-1)) {
572 bLastFrag = 1;
573 }
574
575 switch (byDurType) {
576
577 case DATADUR_B:
578 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {
579 if (bNeedAck) {
580 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
581 return (pDevice->uSIFS + uAckTime);
582 } else {
583 return 0;
584 }
585 }
586 else {
587 if (uFragIdx == (uMACfragNum-2)) {
588 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
589 } else {
590 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
591 }
592 if (bNeedAck) {
593 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
594 return (pDevice->uSIFS + uAckTime + uNextPktTime);
595 } else {
596 return (pDevice->uSIFS + uNextPktTime);
597 }
598 }
599 break;
600
601
602 case DATADUR_A:
603 if (((uMACfragNum==1)) || (bLastFrag==1)) {
604 if(bNeedAck){
605 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
606 return (pDevice->uSIFS + uAckTime);
607 } else {
608 return 0;
609 }
610 }
611 else {
612 if(uFragIdx == (uMACfragNum-2)){
613 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
614 } else {
615 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
616 }
617 if(bNeedAck){
618 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
619 return (pDevice->uSIFS + uAckTime + uNextPktTime);
620 } else {
621 return (pDevice->uSIFS + uNextPktTime);
622 }
623 }
624 break;
625
626 case DATADUR_A_F0:
627 if (((uMACfragNum==1)) || (bLastFrag==1)) {
628 if(bNeedAck){
629 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
630 return (pDevice->uSIFS + uAckTime);
631 } else {
632 return 0;
633 }
634 }
635 else {
636 if (byFBOption == AUTO_FB_0) {
637 if (wRate < RATE_18M)
638 wRate = RATE_18M;
639 else if (wRate > RATE_54M)
640 wRate = RATE_54M;
641
642 if(uFragIdx == (uMACfragNum-2)){
643 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
644 } else {
645 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
646 }
647 } else {
648 if (wRate < RATE_18M)
649 wRate = RATE_18M;
650 else if (wRate > RATE_54M)
651 wRate = RATE_54M;
652
653 if(uFragIdx == (uMACfragNum-2)){
654 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
655 } else {
656 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
657 }
658 }
659
660 if(bNeedAck){
661 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
662 return (pDevice->uSIFS + uAckTime + uNextPktTime);
663 } else {
664 return (pDevice->uSIFS + uNextPktTime);
665 }
666 }
667 break;
668
669 case DATADUR_A_F1:
670 if (((uMACfragNum==1)) || (bLastFrag==1)) {
671 if(bNeedAck){
672 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
673 return (pDevice->uSIFS + uAckTime);
674 } else {
675 return 0;
676 }
677 }
678 else {
679 if (byFBOption == AUTO_FB_0) {
680 if (wRate < RATE_18M)
681 wRate = RATE_18M;
682 else if (wRate > RATE_54M)
683 wRate = RATE_54M;
684
685 if(uFragIdx == (uMACfragNum-2)){
686 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
687 } else {
688 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
689 }
690
691 } else {
692 if (wRate < RATE_18M)
693 wRate = RATE_18M;
694 else if (wRate > RATE_54M)
695 wRate = RATE_54M;
696
697 if(uFragIdx == (uMACfragNum-2)){
698 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
699 } else {
700 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
701 }
702 }
703 if(bNeedAck){
704 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
705 return (pDevice->uSIFS + uAckTime + uNextPktTime);
706 } else {
707 return (pDevice->uSIFS + uNextPktTime);
708 }
709 }
710 break;
711
712 default:
713 break;
714 }
715
716 ASSERT(FALSE);
717 return 0;
718}
719
720
721
722static
723unsigned int
724s_uGetRTSCTSDuration (
725 PSDevice pDevice,
726 BYTE byDurType,
727 unsigned int cbFrameLength,
728 BYTE byPktType,
729 WORD wRate,
730 BOOL bNeedAck,
731 BYTE byFBOption
732 )
733{
734 unsigned int uCTSTime = 0, uDurTime = 0;
735
736
737 switch (byDurType) {
738
739 case RTSDUR_BB:
740 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
741 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
742 break;
743
744 case RTSDUR_BA:
745 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
746 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
747 break;
748
749 case RTSDUR_AA:
750 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
751 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
752 break;
753
754 case CTSDUR_BA:
755 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
756 break;
757
758 case RTSDUR_BA_F0:
759 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
760 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
761 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
762 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
763 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
764 }
765 break;
766
767 case RTSDUR_AA_F0:
768 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
769 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
770 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
771 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
772 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
773 }
774 break;
775
776 case RTSDUR_BA_F1:
777 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
778 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
779 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
780 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
781 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
782 }
783 break;
784
785 case RTSDUR_AA_F1:
786 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
787 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
788 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
789 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
790 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
791 }
792 break;
793
794 case CTSDUR_BA_F0:
795 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
796 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
797 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
798 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
799 }
800 break;
801
802 case CTSDUR_BA_F1:
803 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
804 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
805 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
806 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
807 }
808 break;
809
810 default:
811 break;
812 }
813
814 return uDurTime;
815
816}
817
818
819
820
821static
822unsigned int
823s_uFillDataHead (
824 PSDevice pDevice,
825 BYTE byPktType,
826 WORD wCurrentRate,
827 void *pTxDataHead,
828 unsigned int cbFrameLength,
829 unsigned int uDMAIdx,
830 BOOL bNeedAck,
831 unsigned int uFragIdx,
832 unsigned int cbLastFragmentSize,
833 unsigned int uMACfragNum,
834 BYTE byFBOption
835 )
836{
837
838 if (pTxDataHead == NULL) {
839 return 0;
840 }
841
842 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
843 if ((uDMAIdx == TYPE_ATIMDMA) || (uDMAIdx == TYPE_BEACONDMA)) {
844 PSTxDataHead_ab pBuf = (PSTxDataHead_ab) pTxDataHead;
845
846 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
847 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
848 );
849
850 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
851 wCurrentRate, bNeedAck, uFragIdx,
852 cbLastFragmentSize, uMACfragNum,
853 byFBOption);
854 if(uDMAIdx!=TYPE_ATIMDMA) {
855 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
856 }
857 return (pBuf->wDuration);
858 }
859 else {
860 if (byFBOption == AUTO_FB_NONE) {
861 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
862
863 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
864 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
865 );
866 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
867 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
868 );
869
870 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
871 byPktType, wCurrentRate, bNeedAck, uFragIdx,
872 cbLastFragmentSize, uMACfragNum,
873 byFBOption);
874 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
875 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
876 bNeedAck, uFragIdx, cbLastFragmentSize,
877 uMACfragNum, byFBOption);
878
879 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
880 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
881 return (pBuf->wDuration_a);
882 } else {
883
884 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
885
886 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
887 (PWORD)&(pBuf->wTransmitLength_a), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
888 );
889 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
890 (PWORD)&(pBuf->wTransmitLength_b), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
891 );
892
893 pBuf->wDuration_a = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
894 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
895 pBuf->wDuration_b = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
896 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
897 pBuf->wDuration_a_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
898 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
899 pBuf->wDuration_a_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
900 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
901 pBuf->wTimeStampOff_a = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
902 pBuf->wTimeStampOff_b = wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE];
903 return (pBuf->wDuration_a);
904 }
905 }
906 }
907 else if (byPktType == PK_TYPE_11A) {
908 if ((byFBOption != AUTO_FB_NONE) && (uDMAIdx != TYPE_ATIMDMA) && (uDMAIdx != TYPE_BEACONDMA)) {
909
910 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
911
912 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
913 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
914 );
915
916 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
917 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
918 pBuf->wDuration_f0 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
919 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
920 pBuf->wDuration_f1 = (WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
921 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption);
922 if(uDMAIdx!=TYPE_ATIMDMA) {
923 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
924 }
925 return (pBuf->wDuration);
926 } else {
927 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
928
929 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
930 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
931 );
932
933 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
934 wCurrentRate, bNeedAck, uFragIdx,
935 cbLastFragmentSize, uMACfragNum,
936 byFBOption);
937
938 if(uDMAIdx!=TYPE_ATIMDMA) {
939 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
940 }
941 return (pBuf->wDuration);
942 }
943 }
944 else if (byPktType == PK_TYPE_11B) {
945 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
946
947 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
948 (PWORD)&(pBuf->wTransmitLength), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
949 );
950
951 pBuf->wDuration = (WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
952 wCurrentRate, bNeedAck, uFragIdx,
953 cbLastFragmentSize, uMACfragNum,
954 byFBOption);
955 if (uDMAIdx != TYPE_ATIMDMA) {
956 pBuf->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
957 }
958 return (pBuf->wDuration);
959 }
960 return 0;
961}
962
963
964
965
966static
967void
968s_vFillRTSHead (
969 PSDevice pDevice,
970 BYTE byPktType,
971 void *pvRTS,
972 unsigned int cbFrameLength,
973 BOOL bNeedAck,
974 BOOL bDisCRC,
975 PSEthernetHeader psEthHeader,
976 WORD wCurrentRate,
977 BYTE byFBOption
978 )
979{
980 unsigned int uRTSFrameLen = 20;
981 WORD wLen = 0x0000;
982
983 if (pvRTS == NULL)
984 return;
985
986 if (bDisCRC) {
987
988
989 uRTSFrameLen -= 4;
990 }
991
992
993
994 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
995 if (byFBOption == AUTO_FB_NONE) {
996 PSRTS_g pBuf = (PSRTS_g)pvRTS;
997
998 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
999 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1000 );
1001 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1002 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1003 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1004 );
1005 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1006
1007 pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));
1008 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1009 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1010
1011 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1012
1013 pBuf->Data.wFrameControl = TYPE_CTL_RTS;
1014
1015 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1016 (pDevice->eOPMode == OP_MODE_AP)) {
1017 memcpy(&(pBuf->Data.abyRA[0]),
1018 &(psEthHeader->abyDstAddr[0]),
1019 ETH_ALEN);
1020 }
1021 else {
1022 memcpy(&(pBuf->Data.abyRA[0]),
1023 &(pDevice->abyBSSID[0]),
1024 ETH_ALEN);
1025 }
1026 if (pDevice->eOPMode == OP_MODE_AP) {
1027 memcpy(&(pBuf->Data.abyTA[0]),
1028 &(pDevice->abyBSSID[0]),
1029 ETH_ALEN);
1030 }
1031 else {
1032 memcpy(&(pBuf->Data.abyTA[0]),
1033 &(psEthHeader->abySrcAddr[0]),
1034 ETH_ALEN);
1035 }
1036 }
1037 else {
1038 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
1039
1040 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1041 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1042 );
1043 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1044 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1045 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
1046 );
1047 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
1048
1049 pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption));
1050 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1051 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1052 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1053 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1054 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1055 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1056 pBuf->Data.wDurationID = pBuf->wDuration_aa;
1057
1058 pBuf->Data.wFrameControl = TYPE_CTL_RTS;
1059
1060 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1061 (pDevice->eOPMode == OP_MODE_AP)) {
1062 memcpy(&(pBuf->Data.abyRA[0]),
1063 &(psEthHeader->abyDstAddr[0]),
1064 ETH_ALEN);
1065 }
1066 else {
1067 memcpy(&(pBuf->Data.abyRA[0]),
1068 &(pDevice->abyBSSID[0]),
1069 ETH_ALEN);
1070 }
1071
1072 if (pDevice->eOPMode == OP_MODE_AP) {
1073 memcpy(&(pBuf->Data.abyTA[0]),
1074 &(pDevice->abyBSSID[0]),
1075 ETH_ALEN);
1076 }
1077 else {
1078 memcpy(&(pBuf->Data.abyTA[0]),
1079 &(psEthHeader->abySrcAddr[0]),
1080 ETH_ALEN);
1081 }
1082
1083 }
1084 }
1085 else if (byPktType == PK_TYPE_11A) {
1086 if (byFBOption == AUTO_FB_NONE) {
1087 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1088
1089 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1090 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1091 );
1092 pBuf->wTransmitLength = cpu_to_le16(wLen);
1093
1094 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1095 pBuf->Data.wDurationID = pBuf->wDuration;
1096
1097 pBuf->Data.wFrameControl = TYPE_CTL_RTS;
1098
1099 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1100 (pDevice->eOPMode == OP_MODE_AP)) {
1101 memcpy(&(pBuf->Data.abyRA[0]),
1102 &(psEthHeader->abyDstAddr[0]),
1103 ETH_ALEN);
1104 } else {
1105 memcpy(&(pBuf->Data.abyRA[0]),
1106 &(pDevice->abyBSSID[0]),
1107 ETH_ALEN);
1108 }
1109
1110 if (pDevice->eOPMode == OP_MODE_AP) {
1111 memcpy(&(pBuf->Data.abyTA[0]),
1112 &(pDevice->abyBSSID[0]),
1113 ETH_ALEN);
1114 } else {
1115 memcpy(&(pBuf->Data.abyTA[0]),
1116 &(psEthHeader->abySrcAddr[0]),
1117 ETH_ALEN);
1118 }
1119
1120 }
1121 else {
1122 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
1123
1124 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
1125 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1126 );
1127 pBuf->wTransmitLength = cpu_to_le16(wLen);
1128
1129 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1130 pBuf->wRTSDuration_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1131 pBuf->wRTSDuration_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1132 pBuf->Data.wDurationID = pBuf->wDuration;
1133
1134 pBuf->Data.wFrameControl = TYPE_CTL_RTS;
1135
1136 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1137 (pDevice->eOPMode == OP_MODE_AP)) {
1138 memcpy(&(pBuf->Data.abyRA[0]),
1139 &(psEthHeader->abyDstAddr[0]),
1140 ETH_ALEN);
1141 } else {
1142 memcpy(&(pBuf->Data.abyRA[0]),
1143 &(pDevice->abyBSSID[0]),
1144 ETH_ALEN);
1145 }
1146 if (pDevice->eOPMode == OP_MODE_AP) {
1147 memcpy(&(pBuf->Data.abyTA[0]),
1148 &(pDevice->abyBSSID[0]),
1149 ETH_ALEN);
1150 } else {
1151 memcpy(&(pBuf->Data.abyTA[0]),
1152 &(psEthHeader->abySrcAddr[0]),
1153 ETH_ALEN);
1154 }
1155 }
1156 }
1157 else if (byPktType == PK_TYPE_11B) {
1158 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1159
1160 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1161 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1162 );
1163 pBuf->wTransmitLength = cpu_to_le16(wLen);
1164
1165 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1166 pBuf->Data.wDurationID = pBuf->wDuration;
1167
1168 pBuf->Data.wFrameControl = TYPE_CTL_RTS;
1169
1170 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1171 (pDevice->eOPMode == OP_MODE_AP)) {
1172 memcpy(&(pBuf->Data.abyRA[0]),
1173 &(psEthHeader->abyDstAddr[0]),
1174 ETH_ALEN);
1175 }
1176 else {
1177 memcpy(&(pBuf->Data.abyRA[0]),
1178 &(pDevice->abyBSSID[0]),
1179 ETH_ALEN);
1180 }
1181
1182 if (pDevice->eOPMode == OP_MODE_AP) {
1183 memcpy(&(pBuf->Data.abyTA[0]),
1184 &(pDevice->abyBSSID[0]),
1185 ETH_ALEN);
1186 } else {
1187 memcpy(&(pBuf->Data.abyTA[0]),
1188 &(psEthHeader->abySrcAddr[0]),
1189 ETH_ALEN);
1190 }
1191 }
1192}
1193
1194static
1195void
1196s_vFillCTSHead (
1197 PSDevice pDevice,
1198 unsigned int uDMAIdx,
1199 BYTE byPktType,
1200 void *pvCTS,
1201 unsigned int cbFrameLength,
1202 BOOL bNeedAck,
1203 BOOL bDisCRC,
1204 WORD wCurrentRate,
1205 BYTE byFBOption
1206 )
1207{
1208 unsigned int uCTSFrameLen = 14;
1209 WORD wLen = 0x0000;
1210
1211 if (pvCTS == NULL) {
1212 return;
1213 }
1214
1215 if (bDisCRC) {
1216
1217
1218 uCTSFrameLen -= 4;
1219 }
1220
1221 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1222 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1223
1224 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1225
1226 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1227 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1228 );
1229 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1230 pBuf->wDuration_ba = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption);
1231 pBuf->wDuration_ba += pDevice->wCTSDuration;
1232 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1233
1234 pBuf->wCTSDuration_ba_f0 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption);
1235 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1236 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1237
1238 pBuf->wCTSDuration_ba_f1 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption);
1239 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1240 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1241
1242 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1243 pBuf->Data.wFrameControl = TYPE_CTL_CTS;
1244 pBuf->Data.wReserved = 0x0000;
1245 memcpy(&(pBuf->Data.abyRA[0]),
1246 &(pDevice->abyCurrentNetAddr[0]),
1247 ETH_ALEN);
1248 } else {
1249 PSCTS pBuf = (PSCTS)pvCTS;
1250
1251 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1252 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1253 );
1254 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1255
1256 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption));
1257 pBuf->wDuration_ba += pDevice->wCTSDuration;
1258 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1259
1260
1261 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1262 pBuf->Data.wFrameControl = TYPE_CTL_CTS;
1263 pBuf->Data.wReserved = 0x0000;
1264 memcpy(&(pBuf->Data.abyRA[0]),
1265 &(pDevice->abyCurrentNetAddr[0]),
1266 ETH_ALEN);
1267 }
1268 }
1269}
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294static
1295void
1296s_vGenerateTxParameter (
1297 PSDevice pDevice,
1298 BYTE byPktType,
1299 WORD wCurrentRate,
1300 void *pTxBufHead,
1301 void *pvRrvTime,
1302 void *pvRTS,
1303 void *pvCTS,
1304 unsigned int cbFrameSize,
1305 BOOL bNeedACK,
1306 unsigned int uDMAIdx,
1307 PSEthernetHeader psEthHeader
1308 )
1309{
1310 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1311 WORD wFifoCtl;
1312 BOOL bDisCRC = FALSE;
1313 BYTE byFBOption = AUTO_FB_NONE;
1314
1315
1316
1317 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1318 pFifoHead->wReserved = wCurrentRate;
1319 wFifoCtl = pFifoHead->wFIFOCtl;
1320
1321 if (wFifoCtl & FIFOCTL_CRCDIS) {
1322 bDisCRC = TRUE;
1323 }
1324
1325 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1326 byFBOption = AUTO_FB_0;
1327 }
1328 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1329 byFBOption = AUTO_FB_1;
1330 }
1331
1332 if (pDevice->bLongHeader)
1333 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1334
1335 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1336
1337 if (pvRTS != NULL) {
1338
1339 if (pvRrvTime) {
1340 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1341 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));
1342 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));
1343 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));
1344 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));
1345 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));
1346 }
1347
1348 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1349 }
1350 else {
1351
1352
1353 if (pvRrvTime) {
1354 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1355 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));
1356 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));
1357 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));
1358 }
1359
1360 s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1361 }
1362 }
1363 else if (byPktType == PK_TYPE_11A) {
1364
1365 if (pvRTS != NULL) {
1366
1367 if (pvRrvTime) {
1368 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1369 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));
1370 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));
1371 }
1372
1373 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1374 }
1375 else if (pvRTS == NULL) {
1376
1377 if (pvRrvTime) {
1378 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1379 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK));
1380 }
1381 }
1382 }
1383 else if (byPktType == PK_TYPE_11B) {
1384
1385 if ((pvRTS != NULL)) {
1386
1387 if (pvRrvTime) {
1388 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1389 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));
1390 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));
1391 }
1392
1393 s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1394 }
1395 else {
1396
1397 if (pvRrvTime) {
1398 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1399 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));
1400 }
1401 }
1402 }
1403
1404}
1405
1406
1407
1408
1409
1410
1411
1412BOOL
1413s_bPacketToWirelessUsb(
1414 PSDevice pDevice,
1415 BYTE byPktType,
1416 PBYTE usbPacketBuf,
1417 BOOL bNeedEncryption,
1418 unsigned int uSkbPacketLen,
1419 unsigned int uDMAIdx,
1420 PSEthernetHeader psEthHeader,
1421 PBYTE pPacket,
1422 PSKeyItem pTransmitKey,
1423 unsigned int uNodeIndex,
1424 WORD wCurrentRate,
1425 unsigned int *pcbHeaderLen,
1426 unsigned int *pcbTotalLen
1427 )
1428{
1429 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1430 unsigned int cbFrameSize, cbFrameBodySize;
1431 PTX_BUFFER pTxBufHead;
1432 unsigned int cb802_1_H_len;
1433 unsigned int cbIVlen = 0, cbICVlen = 0, cbMIClen = 0,
1434 cbMACHdLen = 0, cbFCSlen = 4;
1435 unsigned int cbMICHDR = 0;
1436 BOOL bNeedACK,bRTS;
1437 PBYTE pbyType,pbyMacHdr,pbyIVHead,pbyPayloadHead,pbyTxBufferAddr;
1438 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1439 BYTE abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1440 unsigned int uDuration;
1441 unsigned int cbHeaderLength = 0, uPadding = 0;
1442 void *pvRrvTime;
1443 PSMICHDRHead pMICHDR;
1444 void *pvRTS;
1445 void *pvCTS;
1446 void *pvTxDataHd;
1447 BYTE byFBOption = AUTO_FB_NONE,byFragType;
1448 WORD wTxBufSize;
1449 DWORD dwMICKey0,dwMICKey1,dwMIC_Priority,dwCRC;
1450 PDWORD pdwMIC_L,pdwMIC_R;
1451 BOOL bSoftWEP = FALSE;
1452
1453
1454
1455
1456 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1457 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1458 if (((PSKeyTable) (pTransmitKey->pvKeyTable))->bSoftWEP == TRUE) {
1459
1460 bSoftWEP = TRUE;
1461 }
1462 }
1463
1464 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
1465 memset(pTxBufHead, 0, sizeof(TX_BUFFER));
1466
1467
1468 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1469 if (pDevice->dwDiagRefCount == 0) {
1470 cb802_1_H_len = 8;
1471 } else {
1472 cb802_1_H_len = 2;
1473 }
1474 } else {
1475 cb802_1_H_len = 0;
1476 }
1477
1478 cbFrameBodySize = uSkbPacketLen - ETH_HLEN + cb802_1_H_len;
1479
1480
1481 pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8);
1482
1483 if (pDevice->dwDiagRefCount != 0) {
1484 bNeedACK = FALSE;
1485 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1486 } else {
1487 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1488 (pDevice->eOPMode == OP_MODE_AP)) {
1489 if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) {
1490 bNeedACK = FALSE;
1491 pTxBufHead->wFIFOCtl =
1492 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1493 } else {
1494 bNeedACK = TRUE;
1495 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1496 }
1497 }
1498 else {
1499
1500 bNeedACK = TRUE;
1501 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1502 }
1503 }
1504
1505 pTxBufHead->wTimeStamp = DEFAULT_MSDU_LIFETIME_RES_64us;
1506
1507
1508 if (pDevice->bLongHeader)
1509 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
1510
1511 if (pDevice->bSoftwareGenCrcErr) {
1512 pTxBufHead->wFIFOCtl |= FIFOCTL_CRCDIS;
1513 }
1514
1515
1516 if (pDevice->bLongHeader) {
1517 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1518 } else {
1519 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1520 }
1521 pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10);
1522
1523
1524 if (pDevice->bGrpAckPolicy == TRUE) {
1525 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1526 }
1527
1528
1529 if (wCurrentRate >= RATE_18M) {
1530 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
1531 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
1532 byFBOption = AUTO_FB_0;
1533 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
1534 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
1535 byFBOption = AUTO_FB_1;
1536 }
1537 }
1538
1539 if (bSoftWEP != TRUE) {
1540 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1541 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1542 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
1543 }
1544 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Tx Set wFragCtl == FRAGCTL_TKIP\n");
1546 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
1547 }
1548 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1549 pTxBufHead->wFragCtl |= FRAGCTL_AES;
1550 }
1551 }
1552 }
1553
1554
1555 if ((bNeedEncryption) && (pTransmitKey != NULL)) {
1556 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1557 cbIVlen = 4;
1558 cbICVlen = 4;
1559 }
1560 else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1561 cbIVlen = 8;
1562 cbMIClen = 8;
1563 cbICVlen = 4;
1564 }
1565 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1566 cbIVlen = 8;
1567 cbICVlen = 8;
1568 cbMICHDR = sizeof(SMICHDRHead);
1569 }
1570 if (bSoftWEP == FALSE) {
1571
1572 uPadding = 4 - (cbMACHdLen%4);
1573 uPadding %= 4;
1574 }
1575 }
1576
1577 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1578
1579 if ( (bNeedACK == FALSE) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1580 bRTS = FALSE;
1581 } else {
1582 bRTS = TRUE;
1583 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1584 }
1585
1586 pbyTxBufferAddr = (PBYTE) &(pTxBufHead->adwTxKey[0]);
1587 wTxBufSize = sizeof(STxBufHead);
1588 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
1589 if (byFBOption == AUTO_FB_NONE) {
1590 if (bRTS == TRUE) {
1591 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1592 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1593 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1594 pvCTS = NULL;
1595 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1596 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1597 }
1598 else {
1599 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1600 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1601 pvRTS = NULL;
1602 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1603 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1604 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1605 }
1606 } else {
1607
1608 if (bRTS == TRUE) {
1609 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1610 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1611 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1612 pvCTS = NULL;
1613 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1614 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1615 }
1616 else if (bRTS == FALSE) {
1617 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1618 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1619 pvRTS = NULL;
1620 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1621 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1622 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1623 }
1624 }
1625 }
1626 else {
1627 if (byFBOption == AUTO_FB_NONE) {
1628 if (bRTS == TRUE) {
1629 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1630 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1631 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1632 pvCTS = NULL;
1633 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1634 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1635 }
1636 else if (bRTS == FALSE) {
1637 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1638 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1639 pvRTS = NULL;
1640 pvCTS = NULL;
1641 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1642 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1643 }
1644 } else {
1645
1646 if (bRTS == TRUE) {
1647 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1648 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1649 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1650 pvCTS = NULL;
1651 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1652 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1653 }
1654 else if (bRTS == FALSE) {
1655 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1656 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1657 pvRTS = NULL;
1658 pvCTS = NULL;
1659 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1660 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1661 }
1662 }
1663 }
1664
1665 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1666 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1667 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1668
1669
1670
1671
1672
1673 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1674 byFragType = FRAGCTL_NONFRAG;
1675
1676
1677
1678
1679
1680 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate,
1681 (void *)pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
1682 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader);
1683
1684 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1685 0, 0, 1, byFBOption);
1686
1687 s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption,
1688 byFragType, uDMAIdx, 0);
1689
1690 if (bNeedEncryption == TRUE) {
1691
1692 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1693 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
1694
1695 if (pDevice->bEnableHostWEP) {
1696 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1697 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1698 }
1699 }
1700
1701
1702 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1703 if (pDevice->dwDiagRefCount == 0) {
1704 if ((psEthHeader->wType == cpu_to_le16(ETH_P_IPX)) ||
1705 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1706 memcpy((PBYTE) (pbyPayloadHead),
1707 abySNAP_Bridgetunnel, 6);
1708 } else {
1709 memcpy((PBYTE) (pbyPayloadHead), &abySNAP_RFC1042[0], 6);
1710 }
1711 pbyType = (PBYTE) (pbyPayloadHead + 6);
1712 memcpy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1713 } else {
1714 memcpy((PBYTE) (pbyPayloadHead), &(psEthHeader->wType), sizeof(WORD));
1715
1716 }
1717
1718 }
1719
1720
1721 if (pPacket != NULL) {
1722
1723 memcpy((pbyPayloadHead + cb802_1_H_len),
1724 (pPacket + ETH_HLEN),
1725 uSkbPacketLen - ETH_HLEN
1726 );
1727
1728 } else {
1729
1730 memcpy((pbyPayloadHead + cb802_1_H_len), ((PBYTE)psEthHeader) + ETH_HLEN, uSkbPacketLen - ETH_HLEN);
1731 }
1732
1733 ASSERT(uLength == cbNdisBodySize);
1734
1735 if ((bNeedEncryption == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1736
1737
1738
1739 if (pDevice->sMgmtObj.eAuthenMode == WMAC_AUTH_WPANONE) {
1740 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1741 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1742 }
1743 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1744 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1745 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1746 }
1747 else {
1748 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1749 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1750 }
1751
1752 MIC_vInit(dwMICKey0, dwMICKey1);
1753 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1754 dwMIC_Priority = 0;
1755 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766 MIC_vAppend(pbyPayloadHead, cbFrameBodySize);
1767
1768 pdwMIC_L = (PDWORD)(pbyPayloadHead + cbFrameBodySize);
1769 pdwMIC_R = (PDWORD)(pbyPayloadHead + cbFrameBodySize + 4);
1770
1771 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1772 MIC_vUnInit();
1773
1774 if (pDevice->bTxMICFail == TRUE) {
1775 *pdwMIC_L = 0;
1776 *pdwMIC_R = 0;
1777 pDevice->bTxMICFail = FALSE;
1778 }
1779
1780
1781
1782 }
1783
1784
1785 if (bSoftWEP == TRUE) {
1786
1787 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen));
1788
1789 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == TRUE)) ||
1790 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == TRUE)) ||
1791 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == TRUE)) ) {
1792 cbFrameSize -= cbICVlen;
1793 }
1794
1795 if (pDevice->bSoftwareGenCrcErr == TRUE) {
1796 unsigned int cbLen;
1797 PDWORD pdwCRC;
1798
1799 dwCRC = 0xFFFFFFFFL;
1800 cbLen = cbFrameSize - cbFCSlen;
1801
1802 dwCRC = CRCdwGetCrc32Ex(pbyMacHdr, cbLen, dwCRC);
1803 pdwCRC = (PDWORD)(pbyMacHdr + cbLen);
1804
1805 *pdwCRC = ~dwCRC;
1806
1807 *pdwCRC -= 1;
1808 } else {
1809 cbFrameSize -= cbFCSlen;
1810 }
1811
1812 *pcbHeaderLen = cbHeaderLength;
1813 *pcbTotalLen = cbHeaderLength + cbFrameSize ;
1814
1815
1816
1817 pTxBufHead->wFragCtl |= (WORD)byFragType;
1818
1819
1820 return TRUE;
1821
1822}
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844void
1845s_vGenerateMACHeader (
1846 PSDevice pDevice,
1847 PBYTE pbyBufferAddr,
1848 WORD wDuration,
1849 PSEthernetHeader psEthHeader,
1850 BOOL bNeedEncrypt,
1851 WORD wFragType,
1852 unsigned int uDMAIdx,
1853 unsigned int uFragIdx
1854 )
1855{
1856 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
1857
1858 memset(pMACHeader, 0, (sizeof(S802_11Header)));
1859
1860 if (uDMAIdx == TYPE_ATIMDMA) {
1861 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
1862 } else {
1863 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
1864 }
1865
1866 if (pDevice->eOPMode == OP_MODE_AP) {
1867 memcpy(&(pMACHeader->abyAddr1[0]),
1868 &(psEthHeader->abyDstAddr[0]),
1869 ETH_ALEN);
1870 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
1871 memcpy(&(pMACHeader->abyAddr3[0]),
1872 &(psEthHeader->abySrcAddr[0]),
1873 ETH_ALEN);
1874 pMACHeader->wFrameCtl |= FC_FROMDS;
1875 } else {
1876 if (pDevice->eOPMode == OP_MODE_ADHOC) {
1877 memcpy(&(pMACHeader->abyAddr1[0]),
1878 &(psEthHeader->abyDstAddr[0]),
1879 ETH_ALEN);
1880 memcpy(&(pMACHeader->abyAddr2[0]),
1881 &(psEthHeader->abySrcAddr[0]),
1882 ETH_ALEN);
1883 memcpy(&(pMACHeader->abyAddr3[0]),
1884 &(pDevice->abyBSSID[0]),
1885 ETH_ALEN);
1886 } else {
1887 memcpy(&(pMACHeader->abyAddr3[0]),
1888 &(psEthHeader->abyDstAddr[0]),
1889 ETH_ALEN);
1890 memcpy(&(pMACHeader->abyAddr2[0]),
1891 &(psEthHeader->abySrcAddr[0]),
1892 ETH_ALEN);
1893 memcpy(&(pMACHeader->abyAddr1[0]),
1894 &(pDevice->abyBSSID[0]),
1895 ETH_ALEN);
1896 pMACHeader->wFrameCtl |= FC_TODS;
1897 }
1898 }
1899
1900 if (bNeedEncrypt)
1901 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
1902
1903 pMACHeader->wDurationID = cpu_to_le16(wDuration);
1904
1905 if (pDevice->bLongHeader) {
1906 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
1907 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
1908 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
1909 }
1910 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
1911
1912
1913 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
1914
1915 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
1916 pDevice->wSeqCounter++;
1917 if (pDevice->wSeqCounter > 0x0fff)
1918 pDevice->wSeqCounter = 0;
1919 }
1920
1921 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) {
1922 pMACHeader->wFrameCtl |= FC_MOREFRAG;
1923 }
1924}
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945CMD_STATUS csMgmt_xmit(
1946 PSDevice pDevice,
1947 PSTxMgmtPacket pPacket
1948 )
1949{
1950 BYTE byPktType;
1951 PBYTE pbyTxBufferAddr;
1952 void *pvRTS;
1953 PSCTS pCTS;
1954 void *pvTxDataHd;
1955 unsigned int uDuration;
1956 unsigned int cbReqCount;
1957 PS802_11Header pMACHeader;
1958 unsigned int cbHeaderSize;
1959 unsigned int cbFrameBodySize;
1960 BOOL bNeedACK;
1961 BOOL bIsPSPOLL = FALSE;
1962 PSTxBufHead pTxBufHead;
1963 unsigned int cbFrameSize;
1964 unsigned int cbIVlen = 0;
1965 unsigned int cbICVlen = 0;
1966 unsigned int cbMIClen = 0;
1967 unsigned int cbFCSlen = 4;
1968 unsigned int uPadding = 0;
1969 WORD wTxBufSize;
1970 unsigned int cbMacHdLen;
1971 SEthernetHeader sEthHeader;
1972 void *pvRrvTime;
1973 void *pMICHDR;
1974 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1975 WORD wCurrentRate = RATE_1M;
1976 PTX_BUFFER pTX_Buffer;
1977 PUSB_SEND_CONTEXT pContext;
1978
1979
1980
1981 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
1982
1983 if (NULL == pContext) {
1984 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
1985 return CMD_STATUS_RESOURCES;
1986 }
1987
1988 pTX_Buffer = (PTX_BUFFER) (&pContext->Data[0]);
1989 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->adwTxKey[0]);
1990 cbFrameBodySize = pPacket->cbPayloadLen;
1991 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
1992 wTxBufSize = sizeof(STxBufHead);
1993 memset(pTxBufHead, 0, wTxBufSize);
1994
1995 if (pDevice->byBBType == BB_TYPE_11A) {
1996 wCurrentRate = RATE_6M;
1997 byPktType = PK_TYPE_11A;
1998 } else {
1999 wCurrentRate = RATE_1M;
2000 byPktType = PK_TYPE_11B;
2001 }
2002
2003
2004
2005
2006
2007 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2008 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2009 } else {
2010 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2011 }
2012 pDevice->wCurrentRate = wCurrentRate;
2013
2014
2015
2016 if (byPktType == PK_TYPE_11A) {
2017 pTxBufHead->wFIFOCtl = 0;
2018 }
2019 else if (byPktType == PK_TYPE_11B) {
2020 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2021 }
2022 else if (byPktType == PK_TYPE_11GB) {
2023 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2024 }
2025 else if (byPktType == PK_TYPE_11GA) {
2026 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2027 }
2028
2029 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2030 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2031
2032 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
2033 bNeedACK = FALSE;
2034 }
2035 else {
2036 bNeedACK = TRUE;
2037 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2038 };
2039
2040 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2041 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2042
2043 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2044
2045
2046
2047
2048
2049
2050
2051 }
2052
2053 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2054
2055 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2056 bIsPSPOLL = TRUE;
2057 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2058 } else {
2059 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2060 }
2061
2062
2063 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2064
2065
2066
2067
2068 pDevice->bAES = FALSE;
2069
2070 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2071 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2072 cbIVlen = 4;
2073 cbICVlen = 4;
2074 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2075 }
2076 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2077 cbIVlen = 8;
2078 cbMIClen = 8;
2079 cbICVlen = 4;
2080 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2081
2082
2083
2084 }
2085 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2086 cbIVlen = 8;
2087 cbICVlen = 8;
2088 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2089 pDevice->bAES = TRUE;
2090 }
2091
2092 uPadding = 4 - (cbMacHdLen%4);
2093 uPadding %= 4;
2094 }
2095
2096 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2097
2098
2099 if (pDevice->bGrpAckPolicy == TRUE) {
2100 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2101 }
2102
2103
2104
2105 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2106
2107 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2108 pMICHDR = NULL;
2109 pvRTS = NULL;
2110 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2111 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2112 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2113 }
2114 else {
2115 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2116 pMICHDR = NULL;
2117 pvRTS = NULL;
2118 pCTS = NULL;
2119 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2120 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2121 }
2122
2123 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
2124 (cbHeaderSize - wTxBufSize));
2125
2126 memcpy(&(sEthHeader.abyDstAddr[0]),
2127 &(pPacket->p80211Header->sA3.abyAddr1[0]),
2128 ETH_ALEN);
2129 memcpy(&(sEthHeader.abySrcAddr[0]),
2130 &(pPacket->p80211Header->sA3.abyAddr2[0]),
2131 ETH_ALEN);
2132
2133
2134
2135 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2136
2137
2138
2139 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2140 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2141
2142
2143 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2144 0, 0, 1, AUTO_FB_NONE);
2145
2146 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2147
2148 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2149
2150 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2151 PBYTE pbyIVHead;
2152 PBYTE pbyPayloadHead;
2153 PBYTE pbyBSSID;
2154 PSKeyItem pTransmitKey = NULL;
2155
2156 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2157 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2158 do {
2159 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2160 (pDevice->bLinkPass == TRUE)) {
2161 pbyBSSID = pDevice->abyBSSID;
2162
2163 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2164
2165 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2166 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2167 break;
2168 }
2169 } else {
2170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2171 break;
2172 }
2173 }
2174
2175 pbyBSSID = pDevice->abyBroadcastAddr;
2176 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2177 pTransmitKey = NULL;
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2179 } else {
2180 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2181 }
2182 } while(FALSE);
2183
2184 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2185 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2186
2187 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2188 memcpy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2189 cbFrameBodySize);
2190 }
2191 else {
2192
2193 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2194 }
2195
2196 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2197 pDevice->wSeqCounter++ ;
2198 if (pDevice->wSeqCounter > 0x0fff)
2199 pDevice->wSeqCounter = 0;
2200
2201 if (bIsPSPOLL) {
2202
2203
2204
2205
2206
2207 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2208 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2209 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2210 } else {
2211 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2212 }
2213 }
2214
2215
2216 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2217 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2218 pTX_Buffer->byType = 0x00;
2219
2220 pContext->pPacket = NULL;
2221 pContext->Type = CONTEXT_MGMT_PACKET;
2222 pContext->uBufLen = (WORD)cbReqCount + 4;
2223
2224 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2225 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2226 }
2227 else {
2228 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2229 }
2230
2231 PIPEnsSendBulkOut(pDevice,pContext);
2232 return CMD_STATUS_PENDING;
2233}
2234
2235
2236CMD_STATUS
2237csBeacon_xmit(
2238 PSDevice pDevice,
2239 PSTxMgmtPacket pPacket
2240 )
2241{
2242
2243 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2244 unsigned int cbHeaderSize = 0;
2245 WORD wTxBufSize = sizeof(STxShortBufHead);
2246 PSTxShortBufHead pTxBufHead;
2247 PS802_11Header pMACHeader;
2248 PSTxDataHead_ab pTxDataHead;
2249 WORD wCurrentRate;
2250 unsigned int cbFrameBodySize;
2251 unsigned int cbReqCount;
2252 PBEACON_BUFFER pTX_Buffer;
2253 PBYTE pbyTxBufferAddr;
2254 PUSB_SEND_CONTEXT pContext;
2255 CMD_STATUS status;
2256
2257
2258 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2259 if (NULL == pContext) {
2260 status = CMD_STATUS_RESOURCES;
2261 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ManagementSend TX...NO CONTEXT!\n");
2262 return status ;
2263 }
2264 pTX_Buffer = (PBEACON_BUFFER) (&pContext->Data[0]);
2265 pbyTxBufferAddr = (PBYTE)&(pTX_Buffer->wFIFOCtl);
2266
2267 cbFrameBodySize = pPacket->cbPayloadLen;
2268
2269 pTxBufHead = (PSTxShortBufHead) pbyTxBufferAddr;
2270 wTxBufSize = sizeof(STxShortBufHead);
2271 memset(pTxBufHead, 0, wTxBufSize);
2272
2273 if (pDevice->byBBType == BB_TYPE_11A) {
2274 wCurrentRate = RATE_6M;
2275 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2276
2277 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11A,
2278 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2279 );
2280
2281 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
2282 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2283 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2284 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2285 } else {
2286 wCurrentRate = RATE_1M;
2287 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2288 pTxDataHead = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize);
2289
2290 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, PK_TYPE_11B,
2291 (PWORD)&(pTxDataHead->wTransmitLength), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2292 );
2293
2294 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
2295 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2296 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2297 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2298 }
2299
2300
2301 pMACHeader = (PS802_11Header)(pbyTxBufferAddr + cbHeaderSize);
2302 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2303
2304 pMACHeader->wDurationID = 0;
2305 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2306 pDevice->wSeqCounter++ ;
2307 if (pDevice->wSeqCounter > 0x0fff)
2308 pDevice->wSeqCounter = 0;
2309
2310 cbReqCount = cbHeaderSize + WLAN_HDR_ADDR3_LEN + cbFrameBodySize;
2311
2312 pTX_Buffer->wTxByteCount = (WORD)cbReqCount;
2313 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2314 pTX_Buffer->byType = 0x01;
2315
2316 pContext->pPacket = NULL;
2317 pContext->Type = CONTEXT_MGMT_PACKET;
2318 pContext->uBufLen = (WORD)cbReqCount + 4;
2319
2320 PIPEnsSendBulkOut(pDevice,pContext);
2321 return CMD_STATUS_PENDING;
2322
2323}
2324
2325
2326
2327
2328
2329void
2330vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2331
2332 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2333 BYTE byPktType;
2334 PBYTE pbyTxBufferAddr;
2335 void *pvRTS;
2336 void *pvCTS;
2337 void *pvTxDataHd;
2338 unsigned int uDuration;
2339 unsigned int cbReqCount;
2340 PS802_11Header pMACHeader;
2341 unsigned int cbHeaderSize;
2342 unsigned int cbFrameBodySize;
2343 BOOL bNeedACK;
2344 BOOL bIsPSPOLL = FALSE;
2345 PSTxBufHead pTxBufHead;
2346 unsigned int cbFrameSize;
2347 unsigned int cbIVlen = 0;
2348 unsigned int cbICVlen = 0;
2349 unsigned int cbMIClen = 0;
2350 unsigned int cbFCSlen = 4;
2351 unsigned int uPadding = 0;
2352 unsigned int cbMICHDR = 0;
2353 unsigned int uLength = 0;
2354 DWORD dwMICKey0, dwMICKey1;
2355 DWORD dwMIC_Priority;
2356 PDWORD pdwMIC_L;
2357 PDWORD pdwMIC_R;
2358 WORD wTxBufSize;
2359 unsigned int cbMacHdLen;
2360 SEthernetHeader sEthHeader;
2361 void *pvRrvTime;
2362 void *pMICHDR;
2363 WORD wCurrentRate = RATE_1M;
2364 PUWLAN_80211HDR p80211Header;
2365 unsigned int uNodeIndex = 0;
2366 BOOL bNodeExist = FALSE;
2367 SKeyItem STempKey;
2368 PSKeyItem pTransmitKey = NULL;
2369 PBYTE pbyIVHead;
2370 PBYTE pbyPayloadHead;
2371 PBYTE pbyMacHdr;
2372 unsigned int cbExtSuppRate = 0;
2373 PTX_BUFFER pTX_Buffer;
2374 PUSB_SEND_CONTEXT pContext;
2375
2376
2377
2378 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2379
2380 if(skb->len <= WLAN_HDR_ADDR3_LEN) {
2381 cbFrameBodySize = 0;
2382 }
2383 else {
2384 cbFrameBodySize = skb->len - WLAN_HDR_ADDR3_LEN;
2385 }
2386 p80211Header = (PUWLAN_80211HDR)skb->data;
2387
2388 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2389
2390 if (NULL == pContext) {
2391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0 TX...NO CONTEXT!\n");
2392 dev_kfree_skb_irq(skb);
2393 return ;
2394 }
2395
2396 pTX_Buffer = (PTX_BUFFER)(&pContext->Data[0]);
2397 pbyTxBufferAddr = (PBYTE)(&pTX_Buffer->adwTxKey[0]);
2398 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2399 wTxBufSize = sizeof(STxBufHead);
2400 memset(pTxBufHead, 0, wTxBufSize);
2401
2402 if (pDevice->byBBType == BB_TYPE_11A) {
2403 wCurrentRate = RATE_6M;
2404 byPktType = PK_TYPE_11A;
2405 } else {
2406 wCurrentRate = RATE_1M;
2407 byPktType = PK_TYPE_11B;
2408 }
2409
2410
2411
2412
2413
2414 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
2415 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2416 } else {
2417 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2418 }
2419
2420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2421
2422
2423 if (byPktType == PK_TYPE_11A) {
2424 pTxBufHead->wFIFOCtl = 0;
2425 }
2426 else if (byPktType == PK_TYPE_11B) {
2427 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2428 }
2429 else if (byPktType == PK_TYPE_11GB) {
2430 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2431 }
2432 else if (byPktType == PK_TYPE_11GA) {
2433 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2434 }
2435
2436 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2437 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2438
2439 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
2440 bNeedACK = FALSE;
2441 if (pDevice->bEnableHostWEP) {
2442 uNodeIndex = 0;
2443 bNodeExist = TRUE;
2444 }
2445 }
2446 else {
2447 if (pDevice->bEnableHostWEP) {
2448 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2449 bNodeExist = TRUE;
2450 }
2451 bNeedACK = TRUE;
2452 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2453 };
2454
2455 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2456 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2457
2458 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2459
2460
2461
2462
2463
2464
2465
2466
2467 }
2468
2469 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2470
2471 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2472 bIsPSPOLL = TRUE;
2473 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2474 } else {
2475 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2476 }
2477
2478
2479 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2480
2481 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
2482 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2483 }
2484
2485 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
2486 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
2487 }
2488
2489 if (cbExtSuppRate >0) {
2490 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
2491 }
2492 }
2493
2494
2495
2496 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
2497
2498
2499
2500
2501 pDevice->bAES = FALSE;
2502
2503
2504 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2505 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2506 cbIVlen = 4;
2507 cbICVlen = 4;
2508 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2509 }
2510 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2511 cbIVlen = 8;
2512 cbMIClen = 8;
2513 cbICVlen = 4;
2514 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2515
2516
2517
2518 }
2519 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2520 cbIVlen = 8;
2521 cbICVlen = 8;
2522 cbMICHDR = sizeof(SMICHDRHead);
2523 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2524 pDevice->bAES = TRUE;
2525 }
2526
2527 uPadding = 4 - (cbMacHdLen%4);
2528 uPadding %= 4;
2529 }
2530
2531 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2532
2533
2534 if (pDevice->bGrpAckPolicy == TRUE) {
2535 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2536 }
2537
2538
2539
2540 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2541
2542 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2543 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2544 pvRTS = NULL;
2545 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
2546 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
2547 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
2548
2549 }
2550 else {
2551
2552 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2553 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2554 pvRTS = NULL;
2555 pvCTS = NULL;
2556 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
2557 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
2558 }
2559 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0,
2560 (cbHeaderSize - wTxBufSize));
2561 memcpy(&(sEthHeader.abyDstAddr[0]),
2562 &(p80211Header->sA3.abyAddr1[0]),
2563 ETH_ALEN);
2564 memcpy(&(sEthHeader.abySrcAddr[0]),
2565 &(p80211Header->sA3.abyAddr2[0]),
2566 ETH_ALEN);
2567
2568
2569
2570 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2571
2572
2573
2574 s_vGenerateTxParameter(pDevice, byPktType, wCurrentRate, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2575 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader);
2576
2577
2578 uDuration = s_uFillDataHead(pDevice, byPktType, wCurrentRate, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2579 0, 0, 1, AUTO_FB_NONE);
2580
2581 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2582
2583 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
2584
2585 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
2586 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
2587 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
2588
2589
2590 memcpy(pbyMacHdr, skb->data, cbMacHdLen);
2591
2592
2593 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
2594 memcpy(pbyPayloadHead, (skb->data + cbMacHdLen), cbFrameBodySize);
2595
2596
2597 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2598 if (cbExtSuppRate != 0) {
2599 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2600 memcpy((pbyPayloadHead + cbFrameBodySize),
2601 pMgmt->abyCurrSuppRates,
2602 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2603 );
2604 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2605 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2606 pMgmt->abyCurrExtSuppRates,
2607 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2608 );
2609 }
2610 }
2611
2612
2613 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2614
2615 if (pDevice->bEnableHostWEP) {
2616 pTransmitKey = &STempKey;
2617 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2618 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2619 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2620 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2621 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2622 memcpy(pTransmitKey->abyKey,
2623 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2624 pTransmitKey->uKeyLength
2625 );
2626 }
2627
2628 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2629
2630 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
2631 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
2632
2633
2634 MIC_vInit(dwMICKey0, dwMICKey1);
2635 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
2636 dwMIC_Priority = 0;
2637 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
2638 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
2639
2640 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2641
2642 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2643
2644 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2645 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2646
2647 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2648 MIC_vUnInit();
2649
2650 if (pDevice->bTxMICFail == TRUE) {
2651 *pdwMIC_L = 0;
2652 *pdwMIC_R = 0;
2653 pDevice->bTxMICFail = FALSE;
2654 }
2655
2656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2658 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2659
2660 }
2661
2662 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2663 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
2664
2665 if (pDevice->bEnableHostWEP) {
2666 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2667 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2668 }
2669
2670 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
2671 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
2672 }
2673 }
2674
2675 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2676 pDevice->wSeqCounter++ ;
2677 if (pDevice->wSeqCounter > 0x0fff)
2678 pDevice->wSeqCounter = 0;
2679
2680
2681 if (bIsPSPOLL) {
2682
2683
2684
2685
2686
2687 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2688 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2689 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2690 } else {
2691 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
2692 }
2693 }
2694
2695 pTX_Buffer->wTxByteCount = cpu_to_le16((WORD)(cbReqCount));
2696 pTX_Buffer->byPKTNO = (BYTE) (((wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
2697 pTX_Buffer->byType = 0x00;
2698
2699 pContext->pPacket = skb;
2700 pContext->Type = CONTEXT_MGMT_PACKET;
2701 pContext->uBufLen = (WORD)cbReqCount + 4;
2702
2703 if (WLAN_GET_FC_TODS(pMACHeader->wFrameCtl) == 0) {
2704 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr1[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2705 }
2706 else {
2707 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pMACHeader->abyAddr3[0]),(WORD)cbFrameSize,pTX_Buffer->wFIFOCtl);
2708 }
2709 PIPEnsSendBulkOut(pDevice,pContext);
2710 return ;
2711
2712}
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2733{
2734 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2735 unsigned int BytesToWrite = 0, uHeaderLen = 0;
2736 unsigned int uNodeIndex = 0;
2737 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2738 WORD wAID;
2739 BYTE byPktType;
2740 BOOL bNeedEncryption = FALSE;
2741 PSKeyItem pTransmitKey = NULL;
2742 SKeyItem STempKey;
2743 unsigned int ii;
2744 BOOL bTKIP_UseGTK = FALSE;
2745 BOOL bNeedDeAuth = FALSE;
2746 PBYTE pbyBSSID;
2747 BOOL bNodeExist = FALSE;
2748 PUSB_SEND_CONTEXT pContext;
2749 BOOL fConvertedPacket;
2750 PTX_BUFFER pTX_Buffer;
2751 unsigned int status;
2752 WORD wKeepRate = pDevice->wCurrentRate;
2753 struct net_device_stats* pStats = &pDevice->stats;
2754 BOOL bTxeapol_key = FALSE;
2755
2756
2757 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2758
2759 if (pDevice->uAssocCount == 0) {
2760 dev_kfree_skb_irq(skb);
2761 return 0;
2762 }
2763
2764 if (is_multicast_ether_addr((PBYTE)(skb->data))) {
2765 uNodeIndex = 0;
2766 bNodeExist = TRUE;
2767 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2768
2769 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2770 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2771
2772 pMgmt->abyPSTxMap[0] |= byMask[0];
2773 return 0;
2774 }
2775
2776
2777 if (pDevice->byBBType != BB_TYPE_11A)
2778 pDevice->wCurrentRate = RATE_2M;
2779 else
2780 pDevice->wCurrentRate = RATE_24M;
2781
2782 pDevice->byPreambleType = PREAMBLE_SHORT;
2783
2784 }else {
2785
2786 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data), &uNodeIndex)) {
2787
2788 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2789
2790 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2791
2792 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2793
2794 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2795 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2796 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2797 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2798
2799 return 0;
2800 }
2801
2802 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2803
2804
2805 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2806 pDevice->byPreambleType = pDevice->byShortPreamble;
2807
2808 }else {
2809 pDevice->byPreambleType = PREAMBLE_LONG;
2810 }
2811 bNodeExist = TRUE;
2812 }
2813 }
2814
2815 if (bNodeExist == FALSE) {
2816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2817 dev_kfree_skb_irq(skb);
2818 return 0;
2819 }
2820 }
2821
2822 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
2823
2824 if (pContext == NULL) {
2825 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG" pContext == NULL\n");
2826 dev_kfree_skb_irq(skb);
2827 return STATUS_RESOURCES;
2828 }
2829
2830 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), ETH_HLEN);
2831
2832
2833{
2834 BYTE Protocol_Version;
2835 BYTE Packet_Type;
2836 BYTE Descriptor_type;
2837 WORD Key_info;
2838
2839 Protocol_Version = skb->data[ETH_HLEN];
2840 Packet_Type = skb->data[ETH_HLEN+1];
2841 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2842 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2843 if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) {
2844
2845 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2846 (Packet_Type == 3)) {
2847 bTxeapol_key = TRUE;
2848 if(!(Key_info & BIT3) &&
2849 (Key_info & BIT8) && (Key_info & BIT9)) {
2850 if(Descriptor_type==254) {
2851 pDevice->fWPA_Authened = TRUE;
2852 PRINT_K("WPA ");
2853 }
2854 else {
2855 pDevice->fWPA_Authened = TRUE;
2856 PRINT_K("WPA2(re-keying) ");
2857 }
2858 PRINT_K("Authentication completed!!\n");
2859 }
2860 else if((Key_info & BIT3) && (Descriptor_type==2) &&
2861 (Key_info & BIT8) && (Key_info & BIT9)) {
2862 pDevice->fWPA_Authened = TRUE;
2863 PRINT_K("WPA2 Authentication completed!!\n");
2864 }
2865 }
2866 }
2867}
2868
2869
2870 if (pDevice->bEncryptionEnable == TRUE) {
2871 bNeedEncryption = TRUE;
2872
2873 do {
2874 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2875 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2876 pbyBSSID = pDevice->abyBSSID;
2877
2878 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2879
2880 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2881 bTKIP_UseGTK = TRUE;
2882 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2883 break;
2884 }
2885 } else {
2886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2887 break;
2888 }
2889 }else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2890
2891 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr;
2892 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2893 for (ii = 0; ii< 6; ii++)
2894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2896
2897
2898 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2899 break;
2900 }
2901
2902 pbyBSSID = pDevice->abyBroadcastAddr;
2903 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2904 pTransmitKey = NULL;
2905 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2906 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2907 }
2908 else
2909 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2910 } else {
2911 bTKIP_UseGTK = TRUE;
2912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2913 }
2914 } while(FALSE);
2915 }
2916
2917 if (pDevice->bEnableHostWEP) {
2918 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2919 if (pDevice->bEncryptionEnable == TRUE) {
2920 pTransmitKey = &STempKey;
2921 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2922 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2923 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2924 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2925 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2926 memcpy(pTransmitKey->abyKey,
2927 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2928 pTransmitKey->uKeyLength
2929 );
2930 }
2931 }
2932
2933 byPktType = (BYTE)pDevice->byPacketType;
2934
2935 if (pDevice->bFixRate) {
2936 if (pDevice->byBBType == BB_TYPE_11B) {
2937 if (pDevice->uConnectionRate >= RATE_11M) {
2938 pDevice->wCurrentRate = RATE_11M;
2939 } else {
2940 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2941 }
2942 } else {
2943 if ((pDevice->byBBType == BB_TYPE_11A) &&
2944 (pDevice->uConnectionRate <= RATE_6M)) {
2945 pDevice->wCurrentRate = RATE_6M;
2946 } else {
2947 if (pDevice->uConnectionRate >= RATE_54M)
2948 pDevice->wCurrentRate = RATE_54M;
2949 else
2950 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2951 }
2952 }
2953 }
2954 else {
2955 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2956
2957 if (is_multicast_ether_addr(pDevice->sTxEthHeader.abyDstAddr)) {
2958
2959 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2960
2961 pDevice->byPreambleType = pDevice->byShortPreamble;
2962 }
2963 else {
2964 if(BSSbIsSTAInNodeDB(pDevice, &(pDevice->sTxEthHeader.abyDstAddr[0]), &uNodeIndex)) {
2965 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2966 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2967 pDevice->byPreambleType = pDevice->byShortPreamble;
2968
2969 }
2970 else {
2971 pDevice->byPreambleType = PREAMBLE_LONG;
2972 }
2973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Found Node Index is [%d] Tx Data Rate:[%d]\n",uNodeIndex, pDevice->wCurrentRate);
2974 }
2975 else {
2976 if (pDevice->byBBType != BB_TYPE_11A)
2977 pDevice->wCurrentRate = RATE_2M;
2978 else
2979 pDevice->wCurrentRate = RATE_24M;
2980
2981 pDevice->byPreambleType = PREAMBLE_SHORT;
2982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Not Found Node use highest basic Rate.....\n");
2983 }
2984 }
2985 }
2986 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
2987
2988 pDevice->wCurrentRate = pMgmt->sNodeDBTable[0].wTxDataRate;
2989 }
2990 }
2991
2992 if (pDevice->sTxEthHeader.wType == cpu_to_le16(ETH_P_PAE)) {
2993 if (pDevice->byBBType != BB_TYPE_11A) {
2994 pDevice->wCurrentRate = RATE_1M;
2995 pDevice->byACKRate = RATE_1M;
2996 pDevice->byTopCCKBasicRate = RATE_1M;
2997 pDevice->byTopOFDMBasicRate = RATE_6M;
2998 } else {
2999 pDevice->wCurrentRate = RATE_6M;
3000 pDevice->byACKRate = RATE_6M;
3001 pDevice->byTopCCKBasicRate = RATE_1M;
3002 pDevice->byTopOFDMBasicRate = RATE_6M;
3003 }
3004 }
3005
3006 DBG_PRT(MSG_LEVEL_DEBUG,
3007 KERN_INFO "dma_tx: pDevice->wCurrentRate = %d\n",
3008 pDevice->wCurrentRate);
3009
3010 if (wKeepRate != pDevice->wCurrentRate) {
3011 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
3012 }
3013
3014 if (pDevice->wCurrentRate <= RATE_11M) {
3015 byPktType = PK_TYPE_11B;
3016 }
3017
3018 if (bNeedEncryption == TRUE) {
3019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
3020 if ((pDevice->sTxEthHeader.wType) == cpu_to_le16(ETH_P_PAE)) {
3021 bNeedEncryption = FALSE;
3022 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
3023 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
3024 if (pTransmitKey == NULL) {
3025 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
3026 }
3027 else {
3028 if (bTKIP_UseGTK == TRUE) {
3029 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
3030 }
3031 else {
3032 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3033 bNeedEncryption = TRUE;
3034 }
3035 }
3036 }
3037
3038 if (pDevice->byCntMeasure == 2) {
3039 bNeedDeAuth = TRUE;
3040 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
3041 }
3042
3043 if (pDevice->bEnableHostWEP) {
3044 if ((uNodeIndex != 0) &&
3045 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
3046 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
3047 bNeedEncryption = TRUE;
3048 }
3049 }
3050 }
3051 else {
3052
3053 if (pTransmitKey == NULL) {
3054 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
3055 dev_kfree_skb_irq(skb);
3056 pStats->tx_dropped++;
3057 return STATUS_FAILURE;
3058 }
3059 }
3060 }
3061
3062 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3063 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3064 skb->len, uDMAIdx, &pDevice->sTxEthHeader,
3065 (PBYTE)skb->data, pTransmitKey, uNodeIndex,
3066 pDevice->wCurrentRate,
3067 &uHeaderLen, &BytesToWrite
3068 );
3069
3070 if (fConvertedPacket == FALSE) {
3071 pContext->bBoolInUse = FALSE;
3072 dev_kfree_skb_irq(skb);
3073 return STATUS_FAILURE;
3074 }
3075
3076 if ( pDevice->bEnablePSMode == TRUE ) {
3077 if ( !pDevice->bPSModeTxBurst ) {
3078 bScheduleCommand((void *) pDevice,
3079 WLAN_CMD_MAC_DISPOWERSAVING,
3080 NULL);
3081 pDevice->bPSModeTxBurst = TRUE;
3082 }
3083 }
3084
3085 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3086 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3087 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3088
3089 pContext->pPacket = skb;
3090 pContext->Type = CONTEXT_DATA_PACKET;
3091 pContext->uBufLen = (WORD)BytesToWrite + 4 ;
3092
3093 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3094
3095 status = PIPEnsSendBulkOut(pDevice,pContext);
3096
3097 if (bNeedDeAuth == TRUE) {
3098 WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE;
3099
3100 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason);
3101 }
3102
3103 if(status!=STATUS_PENDING) {
3104 pContext->bBoolInUse = FALSE;
3105 dev_kfree_skb_irq(skb);
3106 return STATUS_FAILURE;
3107 }
3108 else
3109 return 0;
3110
3111}
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131BOOL
3132bRelayPacketSend (
3133 PSDevice pDevice,
3134 PBYTE pbySkbData,
3135 unsigned int uDataLen,
3136 unsigned int uNodeIndex
3137 )
3138{
3139 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
3140 unsigned int BytesToWrite = 0, uHeaderLen = 0;
3141 BYTE byPktType = PK_TYPE_11B;
3142 BOOL bNeedEncryption = FALSE;
3143 SKeyItem STempKey;
3144 PSKeyItem pTransmitKey = NULL;
3145 PBYTE pbyBSSID;
3146 PUSB_SEND_CONTEXT pContext;
3147 BYTE byPktTyp;
3148 BOOL fConvertedPacket;
3149 PTX_BUFFER pTX_Buffer;
3150 unsigned int status;
3151 WORD wKeepRate = pDevice->wCurrentRate;
3152
3153
3154
3155 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
3156
3157 if (NULL == pContext) {
3158 return FALSE;
3159 }
3160
3161 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN);
3162
3163 if (pDevice->bEncryptionEnable == TRUE) {
3164 bNeedEncryption = TRUE;
3165
3166 pbyBSSID = pDevice->abyBroadcastAddr;
3167 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
3168 pTransmitKey = NULL;
3169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
3170 } else {
3171 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
3172 }
3173 }
3174
3175 if (pDevice->bEnableHostWEP) {
3176 if (uNodeIndex < MAX_NODE_NUM + 1) {
3177 pTransmitKey = &STempKey;
3178 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3179 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3180 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3181 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3182 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3183 memcpy(pTransmitKey->abyKey,
3184 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3185 pTransmitKey->uKeyLength
3186 );
3187 }
3188 }
3189
3190 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
3191 pContext->bBoolInUse = FALSE;
3192 return FALSE;
3193 }
3194
3195 byPktTyp = (BYTE)pDevice->byPacketType;
3196
3197 if (pDevice->bFixRate) {
3198 if (pDevice->byBBType == BB_TYPE_11B) {
3199 if (pDevice->uConnectionRate >= RATE_11M) {
3200 pDevice->wCurrentRate = RATE_11M;
3201 } else {
3202 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3203 }
3204 } else {
3205 if ((pDevice->byBBType == BB_TYPE_11A) &&
3206 (pDevice->uConnectionRate <= RATE_6M)) {
3207 pDevice->wCurrentRate = RATE_6M;
3208 } else {
3209 if (pDevice->uConnectionRate >= RATE_54M)
3210 pDevice->wCurrentRate = RATE_54M;
3211 else
3212 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
3213 }
3214 }
3215 }
3216 else {
3217 pDevice->wCurrentRate = pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
3218 }
3219
3220 if (wKeepRate != pDevice->wCurrentRate) {
3221 bScheduleCommand((void *) pDevice, WLAN_CMD_SETPOWER, NULL);
3222 }
3223
3224 if (pDevice->wCurrentRate <= RATE_11M)
3225 byPktType = PK_TYPE_11B;
3226
3227 BytesToWrite = uDataLen + ETH_FCS_LEN;
3228
3229
3230
3231
3232 fConvertedPacket = s_bPacketToWirelessUsb(pDevice, byPktType,
3233 (PBYTE)(&pContext->Data[0]), bNeedEncryption,
3234 uDataLen, TYPE_AC0DMA, &pDevice->sTxEthHeader,
3235 pbySkbData, pTransmitKey, uNodeIndex,
3236 pDevice->wCurrentRate,
3237 &uHeaderLen, &BytesToWrite
3238 );
3239
3240 if (fConvertedPacket == FALSE) {
3241 pContext->bBoolInUse = FALSE;
3242 return FALSE;
3243 }
3244
3245 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
3246 pTX_Buffer->byPKTNO = (BYTE) (((pDevice->wCurrentRate<<4) &0x00F0) | ((pDevice->wSeqCounter - 1) & 0x000F));
3247 pTX_Buffer->wTxByteCount = (WORD)BytesToWrite;
3248
3249 pContext->pPacket = NULL;
3250 pContext->Type = CONTEXT_DATA_PACKET;
3251 pContext->uBufLen = (WORD)BytesToWrite + 4 ;
3252
3253 s_vSaveTxPktInfo(pDevice, (BYTE) (pTX_Buffer->byPKTNO & 0x0F), &(pContext->sEthHeader.abyDstAddr[0]),(WORD) (BytesToWrite-uHeaderLen),pTX_Buffer->wFIFOCtl);
3254
3255 status = PIPEnsSendBulkOut(pDevice,pContext);
3256
3257 return TRUE;
3258}
3259
3260