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