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