Merge branches 'topic/fix/asoc', 'topic/fix/hda', 'topic/fix/misc' and 'topic/pci...
[linux-2.6] / drivers / staging / winbond / mds.c
1 #include "os_common.h"
2
3 void
4 Mds_reset_descriptor(PADAPTER Adapter)
5 {
6         PMDS pMds = &Adapter->Mds;
7
8         pMds->TxPause = 0;
9         pMds->TxThreadCount = 0;
10         pMds->TxFillIndex = 0;
11         pMds->TxDesIndex = 0;
12         pMds->ScanTxPause = 0;
13         memset(pMds->TxOwner, 0, ((MAX_USB_TX_BUFFER_NUMBER + 3) & ~0x03));
14 }
15
16 unsigned char
17 Mds_initial(PADAPTER Adapter)
18 {
19         PMDS pMds = &Adapter->Mds;
20
21         pMds->TxPause = FALSE;
22         pMds->TxRTSThreshold = DEFAULT_RTSThreshold;
23         pMds->TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
24
25         vRxTimerInit(Adapter);//for WPA countermeasure
26
27         return hal_get_tx_buffer( &Adapter->sHwData, &pMds->pTxBuffer );
28 }
29
30 void
31 Mds_Destroy(PADAPTER Adapter)
32 {
33         vRxTimerStop(Adapter);
34 }
35
36 void
37 Mds_Tx(PADAPTER Adapter)
38 {
39         phw_data_t      pHwData = &Adapter->sHwData;
40         PMDS            pMds = &Adapter->Mds;
41         DESCRIPTOR      TxDes;
42         PDESCRIPTOR     pTxDes = &TxDes;
43         PUCHAR          XmitBufAddress;
44         u16             XmitBufSize, PacketSize, stmp, CurrentSize, FragmentThreshold;
45         u8              FillIndex, TxDesIndex, FragmentCount, FillCount;
46         unsigned char   BufferFilled = FALSE, MICAdd = 0;
47
48
49         if (pMds->TxPause)
50                 return;
51         if (!hal_driver_init_OK(pHwData))
52                 return;
53
54         //Only one thread can be run here
55         if (!OS_ATOMIC_INC( Adapter, &pMds->TxThreadCount) == 1)
56                 goto cleanup;
57
58         // Start to fill the data
59         do {
60                 FillIndex = pMds->TxFillIndex;
61                 if (pMds->TxOwner[FillIndex]) { // Is owned by software 0:Yes 1:No
62 #ifdef _PE_TX_DUMP_
63                         WBDEBUG(("[Mds_Tx] Tx Owner is H/W.\n"));
64 #endif
65                         break;
66                 }
67
68                 XmitBufAddress = pMds->pTxBuffer + (MAX_USB_TX_BUFFER * FillIndex); //Get buffer
69                 XmitBufSize = 0;
70                 FillCount = 0;
71                 do {
72                         PacketSize = Adapter->sMlmeFrame.len;
73                         if (!PacketSize)
74                                 break;
75
76                         //For Check the buffer resource
77                         FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
78                         //931130.5.b
79                         FragmentCount = PacketSize/FragmentThreshold + 1;
80                         stmp = PacketSize + FragmentCount*32 + 8;//931130.5.c 8:MIC
81                         if ((XmitBufSize + stmp) >= MAX_USB_TX_BUFFER) {
82                                 printk("[Mds_Tx] Excess max tx buffer.\n");
83                                 break; // buffer is not enough
84                         }
85
86
87                         //
88                         // Start transmitting
89                         //
90                         BufferFilled = TRUE;
91
92                         /* Leaves first u8 intact */
93                         memset((PUCHAR)pTxDes + 1, 0, sizeof(DESCRIPTOR) - 1);
94
95                         TxDesIndex = pMds->TxDesIndex;//Get the current ID
96                         pTxDes->Descriptor_ID = TxDesIndex;
97                         pMds->TxDesFrom[ TxDesIndex ] = 2;//Storing the information of source comming from
98                         pMds->TxDesIndex++;
99                         pMds->TxDesIndex %= MAX_USB_TX_DESCRIPTOR;
100
101                         MLME_GetNextPacket( Adapter, pTxDes );
102
103                         // Copy header. 8byte USB + 24byte 802.11Hdr. Set TxRate, Preamble type
104                         Mds_HeaderCopy( Adapter, pTxDes, XmitBufAddress );
105
106                         // For speed up Key setting
107                         if (pTxDes->EapFix) {
108 #ifdef _PE_TX_DUMP_
109                                 WBDEBUG(("35: EPA 4th frame detected. Size = %d\n", PacketSize));
110 #endif
111                                 pHwData->IsKeyPreSet = 1;
112                         }
113
114                         // Copy (fragment) frame body, and set USB, 802.11 hdr flag
115                         CurrentSize = Mds_BodyCopy(Adapter, pTxDes, XmitBufAddress);
116
117                         // Set RTS/CTS and Normal duration field into buffer
118                         Mds_DurationSet(Adapter, pTxDes, XmitBufAddress);
119
120                         //
121                         // Calculation MIC from buffer which maybe fragment, then fill into temporary address 8 byte
122                         // 931130.5.e
123                         if (MICAdd)
124                                 Mds_MicFill( Adapter, pTxDes, XmitBufAddress );
125
126                         //Shift to the next address
127                         XmitBufSize += CurrentSize;
128                         XmitBufAddress += CurrentSize;
129
130 #ifdef _IBSS_BEACON_SEQ_STICK_
131                         if ((XmitBufAddress[ DOT_11_DA_OFFSET+8 ] & 0xfc) != MAC_SUBTYPE_MNGMNT_PROBE_REQUEST) // +8 for USB hdr
132 #endif
133                                 pMds->TxToggle = TRUE;
134
135                         // Get packet to transmit completed, 1:TESTSTA 2:MLME 3: Ndis data
136                         MLME_SendComplete(Adapter, 0, TRUE);
137
138                         // Software TSC count 20060214
139                         pMds->TxTsc++;
140                         if (pMds->TxTsc == 0)
141                                 pMds->TxTsc_2++;
142
143                         FillCount++; // 20060928
144                 } while (HAL_USB_MODE_BURST(pHwData)); // End of multiple MSDU copy loop. FALSE = single TRUE = multiple sending
145
146                 // Move to the next one, if necessary
147                 if (BufferFilled) {
148                         // size setting
149                         pMds->TxBufferSize[ FillIndex ] = XmitBufSize;
150
151                         // 20060928 set Tx count
152                         pMds->TxCountInBuffer[FillIndex] = FillCount;
153
154                         // Set owner flag
155                         pMds->TxOwner[FillIndex] = 1;
156
157                         pMds->TxFillIndex++;
158                         pMds->TxFillIndex %= MAX_USB_TX_BUFFER_NUMBER;
159                         BufferFilled = FALSE;
160                 } else
161                         break;
162
163                 if (!PacketSize) // No more pk for transmitting
164                         break;
165
166         } while(TRUE);
167
168         //
169         // Start to send by lower module
170         //
171         if (!pHwData->IsKeyPreSet)
172                 Wb35Tx_start(pHwData);
173
174  cleanup:
175         OS_ATOMIC_DEC( Adapter, &pMds->TxThreadCount );
176 }
177
178 void
179 Mds_SendComplete(PADAPTER Adapter, PT02_DESCRIPTOR pT02)
180 {
181         PMDS    pMds = &Adapter->Mds;
182         phw_data_t      pHwData = &Adapter->sHwData;
183         u8      PacketId = (u8)pT02->T02_Tx_PktID;
184         unsigned char   SendOK = TRUE;
185         u8      RetryCount, TxRate;
186
187         if (pT02->T02_IgnoreResult) // Don't care the result
188                 return;
189         if (pT02->T02_IsLastMpdu) {
190                 //TODO: DTO -- get the retry count and fragment count
191                 // Tx rate
192                 TxRate = pMds->TxRate[ PacketId ][ 0 ];
193                 RetryCount = (u8)pT02->T02_MPDU_Cnt;
194                 if (pT02->value & FLAG_ERROR_TX_MASK) {
195                         SendOK = FALSE;
196
197                         if (pT02->T02_transmit_abort || pT02->T02_out_of_MaxTxMSDULiftTime) {
198                                 //retry error
199                                 pHwData->dto_tx_retry_count += (RetryCount+1);
200                                 //[for tx debug]
201                                 if (RetryCount<7)
202                                         pHwData->tx_retry_count[RetryCount] += RetryCount;
203                                 else
204                                         pHwData->tx_retry_count[7] += RetryCount;
205                                 #ifdef _PE_STATE_DUMP_
206                                 WBDEBUG(("dto_tx_retry_count =%d\n", pHwData->dto_tx_retry_count));
207                                 #endif
208                                 MTO_SetTxCount(Adapter, TxRate, RetryCount);
209                         }
210                         pHwData->dto_tx_frag_count += (RetryCount+1);
211
212                         //[for tx debug]
213                         if (pT02->T02_transmit_abort_due_to_TBTT)
214                                 pHwData->tx_TBTT_start_count++;
215                         if (pT02->T02_transmit_without_encryption_due_to_wep_on_false)
216                                 pHwData->tx_WepOn_false_count++;
217                         if (pT02->T02_discard_due_to_null_wep_key)
218                                 pHwData->tx_Null_key_count++;
219                 } else {
220                         if (pT02->T02_effective_transmission_rate)
221                                 pHwData->tx_ETR_count++;
222                         MTO_SetTxCount(Adapter, TxRate, RetryCount);
223                 }
224
225                 // Clear send result buffer
226                 pMds->TxResult[ PacketId ] = 0;
227         } else
228                 pMds->TxResult[ PacketId ] |= ((u16)(pT02->value & 0x0ffff));
229 }
230
231 void
232 Mds_HeaderCopy(PADAPTER Adapter, PDESCRIPTOR pDes, PUCHAR TargetBuffer)
233 {
234         PMDS    pMds = &Adapter->Mds;
235         PUCHAR  src_buffer = pDes->buffer_address[0];//931130.5.g
236         PT00_DESCRIPTOR pT00;
237         PT01_DESCRIPTOR pT01;
238         u16     stmp;
239         u8      i, ctmp1, ctmp2, ctmpf;
240         u16     FragmentThreshold = CURRENT_FRAGMENT_THRESHOLD;
241
242
243         stmp = pDes->buffer_total_size;
244         //
245         // Set USB header 8 byte
246         //
247         pT00 = (PT00_DESCRIPTOR)TargetBuffer;
248         TargetBuffer += 4;
249         pT01 = (PT01_DESCRIPTOR)TargetBuffer;
250         TargetBuffer += 4;
251
252         pT00->value = 0;// Clear
253         pT01->value = 0;// Clear
254
255         pT00->T00_tx_packet_id = pDes->Descriptor_ID;// Set packet ID
256         pT00->T00_header_length = 24;// Set header length
257         pT01->T01_retry_abort_ebable = 1;//921013 931130.5.h
258
259         // Key ID setup
260         pT01->T01_wep_id = 0;
261
262         FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; //Do not fragment
263         // Copy full data, the 1'st buffer contain all the data 931130.5.j
264         memcpy( TargetBuffer, src_buffer, DOT_11_MAC_HEADER_SIZE );// Copy header
265         pDes->buffer_address[0] = src_buffer + DOT_11_MAC_HEADER_SIZE;
266         pDes->buffer_total_size -= DOT_11_MAC_HEADER_SIZE;
267         pDes->buffer_size[0] = pDes->buffer_total_size;
268
269         // Set fragment threshold
270         FragmentThreshold -= (DOT_11_MAC_HEADER_SIZE + 4);
271         pDes->FragmentThreshold = FragmentThreshold;
272
273         // Set more frag bit
274         TargetBuffer[1] |= 0x04;// Set more frag bit
275
276         //
277         // Set tx rate
278         //
279         stmp = *(PUSHORT)(TargetBuffer+30); // 2n alignment address
280
281         //Use basic rate
282         ctmp1 = ctmpf = CURRENT_TX_RATE_FOR_MNG;
283
284         pDes->TxRate = ctmp1;
285         #ifdef _PE_TX_DUMP_
286         WBDEBUG(("Tx rate =%x\n", ctmp1));
287         #endif
288
289         pT01->T01_modulation_type = (ctmp1%3) ? 0 : 1;
290
291         for( i=0; i<2; i++ ) {
292                 if( i == 1 )
293                         ctmp1 = ctmpf;
294
295                 pMds->TxRate[pDes->Descriptor_ID][i] = ctmp1; // backup the ta rate and fall back rate
296
297                 if( ctmp1 == 108) ctmp2 = 7;
298                 else if( ctmp1 == 96 ) ctmp2 = 6; // Rate convert for USB
299                 else if( ctmp1 == 72 ) ctmp2 = 5;
300                 else if( ctmp1 == 48 ) ctmp2 = 4;
301                 else if( ctmp1 == 36 ) ctmp2 = 3;
302                 else if( ctmp1 == 24 ) ctmp2 = 2;
303                 else if( ctmp1 == 18 ) ctmp2 = 1;
304                 else if( ctmp1 == 12 ) ctmp2 = 0;
305                 else if( ctmp1 == 22 ) ctmp2 = 3;
306                 else if( ctmp1 == 11 ) ctmp2 = 2;
307                 else if( ctmp1 == 4  ) ctmp2 = 1;
308                 else ctmp2 = 0; // if( ctmp1 == 2  ) or default
309
310                 if( i == 0 )
311                         pT01->T01_transmit_rate = ctmp2;
312                 else
313                         pT01->T01_fall_back_rate = ctmp2;
314         }
315
316         //
317         // Set preamble type
318         //
319         if ((pT01->T01_modulation_type == 0) && (pT01->T01_transmit_rate == 0)) // RATE_1M
320                 pDes->PreambleMode =  WLAN_PREAMBLE_TYPE_LONG;
321         else
322                 pDes->PreambleMode =  CURRENT_PREAMBLE_MODE;
323         pT01->T01_plcp_header_length = pDes->PreambleMode;      // Set preamble
324
325 }
326
327 // The function return the 4n size of usb pk
328 u16
329 Mds_BodyCopy(PADAPTER Adapter, PDESCRIPTOR pDes, PUCHAR TargetBuffer)
330 {
331         PT00_DESCRIPTOR pT00;
332         PMDS    pMds = &Adapter->Mds;
333         PUCHAR  buffer, src_buffer, pctmp;
334         u16     Size = 0;
335         u16     SizeLeft, CopySize, CopyLeft, stmp;
336         u8      buf_index, FragmentCount = 0;
337
338
339         // Copy fragment body
340         buffer = TargetBuffer; // shift 8B usb + 24B 802.11
341         SizeLeft = pDes->buffer_total_size;
342         buf_index = pDes->buffer_start_index;
343
344         pT00 = (PT00_DESCRIPTOR)buffer;
345         while (SizeLeft) {
346                 pT00 = (PT00_DESCRIPTOR)buffer;
347                 CopySize = SizeLeft;
348                 if (SizeLeft > pDes->FragmentThreshold) {
349                         CopySize = pDes->FragmentThreshold;
350                         pT00->T00_frame_length = 24 + CopySize;//Set USB length
351                 } else
352                         pT00->T00_frame_length = 24 + SizeLeft;//Set USB length
353
354                 SizeLeft -= CopySize;
355
356                 // 1 Byte operation
357                 pctmp = (PUCHAR)( buffer + 8 + DOT_11_SEQUENCE_OFFSET );
358                 *pctmp &= 0xf0;
359                 *pctmp |= FragmentCount;//931130.5.m
360                 if( !FragmentCount )
361                         pT00->T00_first_mpdu = 1;
362
363                 buffer += 32; // 8B usb + 24B 802.11 header
364                 Size += 32;
365
366                 // Copy into buffer
367                 stmp = CopySize + 3;
368                 stmp &= ~0x03;//4n Alignment
369                 Size += stmp;// Current 4n offset of mpdu
370
371                 while (CopySize) {
372                         // Copy body
373                         src_buffer = pDes->buffer_address[buf_index];
374                         CopyLeft = CopySize;
375                         if (CopySize >= pDes->buffer_size[buf_index]) {
376                                 CopyLeft = pDes->buffer_size[buf_index];
377
378                                 // Get the next buffer of descriptor
379                                 buf_index++;
380                                 buf_index %= MAX_DESCRIPTOR_BUFFER_INDEX;
381                         } else {
382                                 PUCHAR  pctmp = pDes->buffer_address[buf_index];
383                                 pctmp += CopySize;
384                                 pDes->buffer_address[buf_index] = pctmp;
385                                 pDes->buffer_size[buf_index] -= CopySize;
386                         }
387
388                         memcpy(buffer, src_buffer, CopyLeft);
389                         buffer += CopyLeft;
390                         CopySize -= CopyLeft;
391                 }
392
393                 // 931130.5.n
394                 if (pMds->MicAdd) {
395                         if (!SizeLeft) {
396                                 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - pMds->MicAdd;
397                                 pMds->MicWriteSize[ pMds->MicWriteIndex ] = pMds->MicAdd;
398                                 pMds->MicAdd = 0;
399                         }
400                         else if( SizeLeft < 8 ) //931130.5.p
401                         {
402                                 pMds->MicAdd = SizeLeft;
403                                 pMds->MicWriteAddress[ pMds->MicWriteIndex ] = buffer - ( 8 - SizeLeft );
404                                 pMds->MicWriteSize[ pMds->MicWriteIndex ] = 8 - SizeLeft;
405                                 pMds->MicWriteIndex++;
406                         }
407                 }
408
409                 // Does it need to generate the new header for next mpdu?
410                 if (SizeLeft) {
411                         buffer = TargetBuffer + Size; // Get the next 4n start address
412                         memcpy( buffer, TargetBuffer, 32 );//Copy 8B USB +24B 802.11
413                         pT00 = (PT00_DESCRIPTOR)buffer;
414                         pT00->T00_first_mpdu = 0;
415                 }
416
417                 FragmentCount++;
418         }
419
420         pT00->T00_last_mpdu = 1;
421         pT00->T00_IsLastMpdu = 1;
422         buffer = (PUCHAR)pT00 + 8; // +8 for USB hdr
423         buffer[1] &= ~0x04; // Clear more frag bit of 802.11 frame control
424         pDes->FragmentCount = FragmentCount; // Update the correct fragment number
425         return Size;
426 }
427
428
429 void
430 Mds_DurationSet(  PADAPTER Adapter,  PDESCRIPTOR pDes,  PUCHAR buffer )
431 {
432         PT00_DESCRIPTOR pT00;
433         PT01_DESCRIPTOR pT01;
434         u16     Duration, NextBodyLen, OffsetSize;
435         u8      Rate, i;
436         unsigned char   CTS_on = FALSE, RTS_on = FALSE;
437         PT00_DESCRIPTOR pNextT00;
438         u16 BodyLen;
439         unsigned char boGroupAddr = FALSE;
440
441
442         OffsetSize = pDes->FragmentThreshold + 32 + 3;
443         OffsetSize &= ~0x03;
444         Rate = pDes->TxRate >> 1;
445         if (!Rate)
446                 Rate = 1;
447
448         pT00 = (PT00_DESCRIPTOR)buffer;
449         pT01 = (PT01_DESCRIPTOR)(buffer+4);
450         pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
451
452         if( buffer[ DOT_11_DA_OFFSET+8 ] & 0x1 ) // +8 for USB hdr
453                 boGroupAddr = TRUE;
454
455         //========================================
456         // Set RTS/CTS mechanism
457         //========================================
458         if (!boGroupAddr)
459         {
460                 //NOTE : If the protection mode is enabled and the MSDU will be fragmented,
461                 //               the tx rates of MPDUs will all be DSSS rates. So it will not use
462                 //               CTS-to-self in this case. CTS-To-self will only be used when without
463                 //               fragmentation. -- 20050112
464                 BodyLen = (u16)pT00->T00_frame_length;  //include 802.11 header
465                 BodyLen += 4;   //CRC
466
467                 if( BodyLen >= CURRENT_RTS_THRESHOLD )
468                         RTS_on = TRUE; // Using RTS
469                 else
470                 {
471                         if( pT01->T01_modulation_type ) // Is using OFDM
472                         {
473                                 if( CURRENT_PROTECT_MECHANISM ) // Is using protect
474                                         CTS_on = TRUE; // Using CTS
475                         }
476                 }
477         }
478
479         if( RTS_on || CTS_on )
480         {
481                 if( pT01->T01_modulation_type) // Is using OFDM
482                 {
483                         //CTS duration
484                         // 2 SIFS + DATA transmit time + 1 ACK
485                         // ACK Rate : 24 Mega bps
486                         // ACK frame length = 14 bytes
487                         Duration = 2*DEFAULT_SIFSTIME +
488                                            2*PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
489                                            ((BodyLen*8 + 22 + Rate*4 - 1)/(Rate*4))*Tsym +
490                                            ((112 + 22 + 95)/96)*Tsym;
491                 }
492                 else    //DSSS
493                 {
494                         //CTS duration
495                         // 2 SIFS + DATA transmit time + 1 ACK
496                         // Rate : ?? Mega bps
497                         // ACK frame length = 14 bytes
498                         if( pT01->T01_plcp_header_length ) //long preamble
499                                 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
500                         else
501                                 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*2;
502
503                         Duration += ( ((BodyLen + 14)*8 + Rate-1) / Rate +
504                                                 DEFAULT_SIFSTIME*2 );
505                 }
506
507                 if( RTS_on )
508                 {
509                         if( pT01->T01_modulation_type ) // Is using OFDM
510                         {
511                                 //CTS + 1 SIFS + CTS duration
512                                 //CTS Rate : 24 Mega bps
513                                 //CTS frame length = 14 bytes
514                                 Duration += (DEFAULT_SIFSTIME +
515                                                                 PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION +
516                                                                 ((112 + 22 + 95)/96)*Tsym);
517                         }
518                         else
519                         {
520                                 //CTS + 1 SIFS + CTS duration
521                                 //CTS Rate : ?? Mega bps
522                                 //CTS frame length = 14 bytes
523                                 if( pT01->T01_plcp_header_length ) //long preamble
524                                         Duration += LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
525                                 else
526                                         Duration += SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
527
528                                 Duration += ( ((112 + Rate-1) / Rate) + DEFAULT_SIFSTIME );
529                         }
530                 }
531
532                 // Set the value into USB descriptor
533                 pT01->T01_add_rts = RTS_on ? 1 : 0;
534                 pT01->T01_add_cts = CTS_on ? 1 : 0;
535                 pT01->T01_rts_cts_duration = Duration;
536         }
537
538         //=====================================
539         // Fill the more fragment descriptor
540         //=====================================
541         if( boGroupAddr )
542                 Duration = 0;
543         else
544         {
545                 for( i=pDes->FragmentCount-1; i>0; i-- )
546                 {
547                         NextBodyLen = (u16)pNextT00->T00_frame_length;
548                         NextBodyLen += 4;       //CRC
549
550                         if( pT01->T01_modulation_type )
551                         {
552                                 //OFDM
553                                 // data transmit time + 3 SIFS + 2 ACK
554                                 // Rate : ??Mega bps
555                                 // ACK frame length = 14 bytes, tx rate = 24M
556                                 Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION * 3;
557                                 Duration += (((NextBodyLen*8 + 22 + Rate*4 - 1)/(Rate*4)) * Tsym +
558                                                         (((2*14)*8 + 22 + 95)/96)*Tsym +
559                                                         DEFAULT_SIFSTIME*3);
560                         }
561                         else
562                         {
563                                 //DSSS
564                                 // data transmit time + 2 ACK + 3 SIFS
565                                 // Rate : ??Mega bps
566                                 // ACK frame length = 14 bytes
567                                 //TODO :
568                                 if( pT01->T01_plcp_header_length ) //long preamble
569                                         Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
570                                 else
571                                         Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME*3;
572
573                                 Duration += ( ((NextBodyLen + (2*14))*8 + Rate-1) / Rate +
574                                                         DEFAULT_SIFSTIME*3 );
575                         }
576
577                         ((PUSHORT)buffer)[5] = cpu_to_le16(Duration);// 4 USHOR for skip 8B USB, 2USHORT=FC + Duration
578
579                         //----20061009 add by anson's endian
580                         pNextT00->value = cpu_to_le32(pNextT00->value);
581                         pT01->value = cpu_to_le32( pT01->value );
582                         //----end 20061009 add by anson's endian
583
584                         buffer += OffsetSize;
585                         pT01 = (PT01_DESCRIPTOR)(buffer+4);
586                         if (i != 1)     //The last fragment will not have the next fragment
587                                 pNextT00 = (PT00_DESCRIPTOR)(buffer+OffsetSize);
588                 }
589
590                 //=====================================
591                 // Fill the last fragment descriptor
592                 //=====================================
593                 if( pT01->T01_modulation_type )
594                 {
595                         //OFDM
596                         // 1 SIFS + 1 ACK
597                         // Rate : 24 Mega bps
598                         // ACK frame length = 14 bytes
599                         Duration = PREAMBLE_PLUS_SIGNAL_PLUS_SIGNALEXTENSION;
600                         //The Tx rate of ACK use 24M
601                         Duration += (((112 + 22 + 95)/96)*Tsym + DEFAULT_SIFSTIME );
602                 }
603                 else
604                 {
605                         // DSSS
606                         // 1 ACK + 1 SIFS
607                         // Rate : ?? Mega bps
608                         // ACK frame length = 14 bytes(112 bits)
609                         if( pT01->T01_plcp_header_length ) //long preamble
610                                 Duration = LONG_PREAMBLE_PLUS_PLCPHEADER_TIME;
611                         else
612                                 Duration = SHORT_PREAMBLE_PLUS_PLCPHEADER_TIME;
613
614                         Duration += ( (112 + Rate-1)/Rate +     DEFAULT_SIFSTIME );
615                 }
616         }
617
618         ((PUSHORT)buffer)[5] = cpu_to_le16(Duration);// 4 USHOR for skip 8B USB, 2USHORT=FC + Duration
619         pT00->value = cpu_to_le32(pT00->value);
620         pT01->value = cpu_to_le32(pT01->value);
621         //--end 20061009 add
622
623 }
624
625 void MDS_EthernetPacketReceive(  PADAPTER Adapter,  PRXLAYER1 pRxLayer1 )
626 {
627                 OS_RECEIVE_PACKET_INDICATE( Adapter, pRxLayer1 );
628 }
629
630