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