summaryrefslogtreecommitdiff
path: root/network/wlan/WDI/COMMON/TSGen.c
blob: 36543f4b4bb4057dc307d26dab8913c64c9b0deb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#include "Mp_Precomp.h"

#if WPP_SOFTWARE_TRACE
#include "TSGen.tmh"
#endif

VOID
TsAddBaProcess(
	PRT_TIMER	pTimer
	)
{
	PADAPTER		Adapter = (PADAPTER)pTimer->Adapter;
	PTX_TS_RECORD	pTxTs = (PTX_TS_RECORD)pTimer->Context;

	TsInitAddBA(Adapter, pTxTs, BA_POLICY_IMMEDIATE, FALSE);
	RT_TRACE(COMP_QOS, DBG_LOUD, ("TsAddBaProcess(): ADDBA Req is started!! \n"));
}


VOID
ResetTsCommonInfo(
	PTS_COMMON_INFO	pTsCommonInfo
	)
{
	PlatformZeroMemory(pTsCommonInfo->Addr, 6);
	PlatformZeroMemory(&pTsCommonInfo->TSpec, WMM_TSPEC_BODY_LENGTH);
	PlatformZeroMemory(&pTsCommonInfo->TClass, sizeof(QOS_TCLAS)*TCLAS_NUM);
	pTsCommonInfo->TClasProc = 0;
	pTsCommonInfo->TClasNum = 0;
}

VOID
ResetTxTsEntry(
	PTX_TS_RECORD	pTS
	)
{
	ResetTsCommonInfo(&pTS->TsCommonInfo);
	pTS->TxCurSeq = 0;
	pTS->bAddBaReqInProgress = FALSE;
	pTS->bAddBaReqDelayed = FALSE;
	pTS->bUsingBa = FALSE;
	ResetBaEntry(&pTS->TxAdmittedBARecord); //For BA Originator
	ResetBaEntry(&pTS->TxPendingBARecord);
}

VOID
ResetRxTsEntry(
	PRX_TS_RECORD	pTS
	)
{
	ResetTsCommonInfo(&pTS->TsCommonInfo);
	pTS->RxIndicateSeq = 0xffff; // This indicate the RxIndicateSeq is not used now!!
	pTS->RxIndicateState = 0; // Reset indicate state!!
	ResetBaEntry(&pTS->RxAdmittedBARecord);	  // For BA Recepient

	//Init it for avoid drop first packet. 
	pTS->RxLastFragNum = 0xff;
	pTS->RxLastSeqNum = 0xffff;	
}

VOID
TSInitialize(
	PADAPTER	Adapter
	)
{
	PMGNT_INFO			pMgntInfo = &Adapter->MgntInfo;
	PTX_TS_RECORD		pTxTS = pMgntInfo->TxTsRecord;
	PRX_TS_RECORD		pRxTS = pMgntInfo->RxTsRecord;
	PRX_REORDER_ENTRY	pRxReorderEntry = pMgntInfo->RxReorderEntry;
	u2Byte				count = 0;

	RT_TRACE(COMP_QOS, DBG_LOUD, ("===>TSInitialize()\r\n"));

	// Initialize Tx TS related info.
	RTInitializeListHead(&pMgntInfo->Tx_TS_Admit_List);
	RTInitializeListHead(&pMgntInfo->Tx_TS_Pending_List);
	RTInitializeListHead(&pMgntInfo->Tx_TS_Unused_List);
	for(count = 0; count < TOTAL_TS_NUM; count++)
	{
		//
		// The timers for the operation of Traffic Stream and Block Ack.
		// DLS related timer will be add here in the future!!
		//
		PlatformInitializeTimer(
			Adapter, 
			&pTxTS->TsAddBaTimer, 
			(RT_TIMER_CALL_BACK)TsAddBaProcess, 
			(PVOID)pTxTS, 
			"TxTsAddBaTimer" );

		PlatformInitializeTimer(
			Adapter,
			&pTxTS->TxPendingBARecord.Timer,
			(RT_TIMER_CALL_BACK)BaSetupTimeOut, 
			(PVOID)pTxTS, 
			"TxPendingBARecordTimer");

		PlatformInitializeTimer(
			Adapter,
			&pTxTS->TxAdmittedBARecord.Timer,
			(RT_TIMER_CALL_BACK)TxBaInactTimeout, 
			(PVOID) pTxTS, 
			"TxAdmittedBARecordTimer" );
		
		ResetTxTsEntry(pTxTS);
		RTInsertTailList(&pMgntInfo->Tx_TS_Unused_List, &pTxTS->TsCommonInfo.List);
		pTxTS++;
	}

	// Initialize Rx TS related info.
	RTInitializeListHead(&pMgntInfo->Rx_TS_Admit_List);
	RTInitializeListHead(&pMgntInfo->Rx_TS_Pending_List);
	RTInitializeListHead(&pMgntInfo->Rx_TS_Unused_List);
	for(count = 0; count < TOTAL_TS_NUM; count++)
	{
		RTInitializeListHead(&pRxTS->RxPendingPktList);

		PlatformInitializeTimer(
			Adapter,
			&pRxTS->RxAdmittedBARecord.Timer,
			(RT_TIMER_CALL_BACK)RxBaInactTimeout, 
			(PVOID)pRxTS, 
			"RxAdmittedBARecordTimer");
	
		PlatformInitializeTimer(
			Adapter,
			&pRxTS->RxPktPendingTimer,
			(RT_TIMER_CALL_BACK)RxPktPendingTimeout, 
			(PVOID)pRxTS, 
			"RxPktPendingTimer");

		ResetRxTsEntry(pRxTS);
		RTInsertTailList(&pMgntInfo->Rx_TS_Unused_List, &pRxTS->TsCommonInfo.List);
		pRxTS++;
	}

	// Initialize unused Rx Reorder List.
	RTInitializeListHead(&pMgntInfo->RxReorder_Unused_List);
	for(count = 0; count < REORDER_ENTRY_NUM; count++)
	{
		RTInsertTailList(&pMgntInfo->RxReorder_Unused_List, &pRxReorderEntry->List);
		pRxReorderEntry++;
	}
}

VOID
AdmitTS(
	PADAPTER			Adapter,
	PTS_COMMON_INFO	pTsCommonInfo,
	u4Byte				InactTime
	)
{
}

VOID
ExtendRxTS(
	PADAPTER			Adapter,
	PRX_TS_RECORD		pRxTS
	)
{
	// TS part needs to be implemented in the future.
}

PRT_LIST_ENTRY
SearchTSList(
	PRT_LIST_ENTRY		pTSList,
	pu1Byte				Addr,
	u1Byte				TID,
	DIRECTION_VALUE		Dir
	)
{
	BOOLEAN				bIsFound = FALSE;
	PTS_COMMON_INFO	pTS_Record = (PTS_COMMON_INFO) RTGetHeadList(pTSList);

	while(&pTS_Record->List != pTSList)
	{
		if( PlatformCompareMemory(pTS_Record->Addr, Addr, 6) == 0 )
		{
			if(GET_TSPEC_BODY_TSINFO_TSID(pTS_Record->TSpec) == TID)
			{
				if(GET_TSPEC_BODY_TSINFO_DIRECTION(pTS_Record->TSpec) == Dir)
				{
					bIsFound = TRUE;
					break;
				}
			}
		}
		pTS_Record = (PTS_COMMON_INFO)RTNextEntryList(&pTS_Record->List);
	}

	if(bIsFound)
		return &pTS_Record->List;
	else
		return NULL;
}


PTS_COMMON_INFO
SearchAdmitTRStream(
	PMGNT_INFO	pMgntInfo,
	pu1Byte		Addr,
	u1Byte		TID,
	TR_SELECT	TxRxSelect //Tx:0, Rx:1
)
{
	//DIRECTION_VALUE 	dir;
	u1Byte 	dir;
	BOOLEAN				search_dir[4] = {0, 0, 0, 0};
	PRT_LIST_ENTRY		psearch_list = NULL;
	PTS_COMMON_INFO		pRet=NULL;
		
	if(pMgntInfo->ApType > 0)
	{
		if(TxRxSelect == TX_DIR)
		{
			search_dir[DIR_DOWN] = TRUE;
			search_dir[DIR_BI_DIR]= TRUE;
		}
		else
		{
			search_dir[DIR_UP] 	= TRUE;
			search_dir[DIR_BI_DIR]= TRUE;
		}
	}
	else if(pMgntInfo->mIbss)
	{
		if(TxRxSelect == TX_DIR)
			search_dir[DIR_UP] 	= TRUE;
		else
			search_dir[DIR_DOWN] = TRUE;
	}
	else
	{
		if(TxRxSelect == TX_DIR)
		{
			search_dir[DIR_UP] 	= TRUE;
			search_dir[DIR_BI_DIR]= TRUE;
			search_dir[DIR_DIRECT]= TRUE;
		}
		else
		{
			search_dir[DIR_DOWN] = TRUE;
			search_dir[DIR_BI_DIR]= TRUE;
			search_dir[DIR_DIRECT]= TRUE;
		}
	}

	if(TxRxSelect == TX_DIR)
		psearch_list = &pMgntInfo->Tx_TS_Admit_List;
	else
		psearch_list = &pMgntInfo->Rx_TS_Admit_List;
	
	//for(dir = DIR_UP; dir <= DIR_BI_DIR; dir++)
	for(dir = 0; dir <= DIR_BI_DIR; dir++)
	{
		if(search_dir[dir] ==FALSE )
			continue;

		pRet = (PTS_COMMON_INFO)SearchTSList(psearch_list, Addr, TID, (DIRECTION_VALUE)dir);

		if(pRet  != NULL)
			break;
	}

	if(pRet  != NULL)
		return pRet ;
	else 
		return NULL;
}

VOID
MakeTSEntry(
	OUT	PTS_COMMON_INFO	pTsCommonInfo,
	IN	pu1Byte				Addr,
	IN	pu1Byte				pTSPEC,
	IN	PQOS_TCLAS			pTCLAS,
	IN	u1Byte				TCLAS_Num,
	IN	u1Byte				TCLAS_Proc
	)
{
	u1Byte	count;

	if(pTsCommonInfo == NULL)
		return;
	
	PlatformMoveMemory(pTsCommonInfo->Addr, Addr, 6);

	if(pTSPEC != NULL)
		PlatformMoveMemory((pu1Byte)(&(pTsCommonInfo->TSpec)), (pu1Byte)pTSPEC, WMM_TSPEC_BODY_LENGTH);

	for(count = 0; count < TCLAS_Num; count++)
		PlatformMoveMemory((pu1Byte)(&(pTsCommonInfo->TClass[count])), (pu1Byte)pTCLAS, sizeof(QOS_TCLAS));

	pTsCommonInfo->TClasProc = TCLAS_Proc;
	pTsCommonInfo->TClasNum = TCLAS_Num;
}


BOOLEAN
GetTs(
	PADAPTER			Adapter,
	PTS_COMMON_INFO	*ppTS,
	pu1Byte				Addr,
	u1Byte				TID,
	TR_SELECT			TxRxSelect,  //Rx:1, Tx:0
	BOOLEAN				bAddNewTs
	)
{
	PMGNT_INFO	pMgntInfo = &Adapter->MgntInfo;
	u1Byte			UP=0;

	//
	// We do not build any TS for Broadcast or Multicast stream.
	// So reject these kinds of search here.
	//
	if(MacAddr_isBcst(Addr) || MacAddr_isMulticast(Addr))
	{
		RT_TRACE(COMP_QOS, DBG_LOUD, ("Broad or multicast return\r\n"));
		return FALSE;
	}

	if(pMgntInfo->pStaQos->CurrentQosMode == QOS_DISABLE)
	{//only use one TS	
		UP = 0; 
	} 
	else if(pMgntInfo->pStaQos->CurrentQosMode & QOS_WMM)
	{
		// In WMM case: we use 4 TID only
	
		//
		// <Roger_Notes> We use 7 TIDs to fit differentiated service from IP layer 
		// to meet different implementation of APs.
		// 2008.12.18.
		//
		UP = TID;		
	}

	*ppTS = SearchAdmitTRStream(
			pMgntInfo, 
			Addr,
			UP, 
			TxRxSelect);
	
	if(*ppTS != NULL)
	{
		RT_TRACE(COMP_QOS, DBG_TRACE, ("SearchAdmitTRStream get ppTS\r\n"));
		return TRUE;
	}
	else
	{
		if(bAddNewTs == FALSE)
		{
			RT_TRACE(COMP_QOS, DBG_LOUD, ("bAddNewTs == FALSE\r\n"));
			return FALSE;
		}
		else
		{
			// 
			// Create a new Traffic stream for current Tx/Rx
			// This is for EDCA and WMM to add a new TS.
			// For HCCA or WMMSA, TS cannot be addmit without negotiation.
			//
			u1Byte			TSpec[WMM_TSPEC_BODY_LENGTH]={0};
			
			pu1Byte			pTSInfo= TSpec;
			PRT_LIST_ENTRY	pUnusedList = 
								(TxRxSelect == TX_DIR)?
								(&pMgntInfo->Tx_TS_Unused_List):
								(&pMgntInfo->Rx_TS_Unused_List);
								
			PRT_LIST_ENTRY	pAddmitList = 
								(TxRxSelect == TX_DIR)?
								(&pMgntInfo->Tx_TS_Admit_List):
								(&pMgntInfo->Rx_TS_Admit_List);

			DIRECTION_VALUE		Dir = 
								(ACTING_AS_AP(Adapter))?
								((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):
								((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
			RT_TRACE(COMP_QOS, DBG_TRACE, ("GetTs(): Add New TS %s Entry.\n", TxRxSelect?"Rx":"Tx"));
			RT_PRINT_ADDR(COMP_QOS, DBG_TRACE, "PeerAddress:", Addr);
			RT_TRACE(COMP_QOS, DBG_TRACE, ("UserPriority: %d\n", UP));
			if(!RTIsListEmpty(pUnusedList))
			{
				(*ppTS) = (PTS_COMMON_INFO)RTRemoveHeadList(pUnusedList);

				if(TxRxSelect==TX_DIR)
					ResetTxTsEntry((PTX_TS_RECORD) *ppTS);
				else
					ResetRxTsEntry((PRX_TS_RECORD) *ppTS);

				// Prepare TS Info releated field
				SET_TSPEC_BODY_TSINFO_TRAFFIC_TYPE(pTSInfo, 0); // Traffic type: WMM is reserved in this field
				SET_TSPEC_BODY_TSINFO_TSID(pTSInfo, UP);	// TSID
				SET_TSPEC_BODY_TSINFO_DIRECTION(pTSInfo, Dir);	// Direction: if there is DirectLink, this need additional consideration.
				SET_TSPEC_BODY_TSINFO_ACCESS_POLICY(pTSInfo, 1); // Access policy
				SET_TSPEC_BODY_TSINFO_AGGREGATION(pTSInfo, 0);	 // Aggregation
				SET_TSPEC_BODY_TSINFO_PSB(pTSInfo, 0);		// Aggregation
				SET_TSPEC_BODY_TSINFO_UP(pTSInfo, UP);		// User priority
				SET_TSPEC_BODY_TSINFO_ACK_POLICY(pTSInfo, 0);	 // Ack policy
				SET_TSPEC_BODY_TSINFO_SCHEDULE(pTSInfo, 0);		 // Schedule
					
				MakeTSEntry(*ppTS, Addr, TSpec, NULL, 0, 0);
				AdmitTS(Adapter, *ppTS, 0);
				RTInsertTailList(pAddmitList, &((*ppTS)->List));

				// if there is DirectLink, we need to do additional operation here!!


				return TRUE;
			}
			else
			{
				RT_ASSERT(FALSE, ("ManageTSInformation(): There is not enough TS record to be used!!"));
				return FALSE;
			}		
		}		
	}

}

VOID
RemoveTsEntry(
	PADAPTER			Adapter,
	PTS_COMMON_INFO		pTs,
	TR_SELECT			TxRxSelect
	)
{
	BOOLEAN 	bInRxProgress = FALSE;

	TsInitDelBA(Adapter, pTs, TxRxSelect);

	RT_TRACE(COMP_QOS, DBG_TRACE, ("RemoveTsEntry(): Remove %s Entry.\n", TxRxSelect?"Rx":"Tx"));
	RT_PRINT_ADDR(COMP_QOS, DBG_TRACE, "PeerAddress:", pTs->Addr);

	if(TxRxSelect == RX_DIR)
	{
		PRX_REORDER_ENTRY	pRxReorderEntry;
		PRX_TS_RECORD 		pRxTS = (PRX_TS_RECORD)pTs;
		PMGNT_INFO			pMgntInfo = &Adapter->MgntInfo;

		if( PlatformCancelTimer(Adapter, &pRxTS->RxPktPendingTimer) == FALSE )
		{
			pRxTS->RxIndicateState = RXTS_INDICATE_IDLE;
		}

		if(!GetDefaultAdapter(Adapter)->bRemoveTsInRxPath)
			PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
		else
			bInRxProgress = TRUE;
			
		while(!RTIsListEmpty(&pRxTS->RxPendingPktList))
		{					
			pRxReorderEntry = (PRX_REORDER_ENTRY)RTRemoveHeadList(&pRxTS->RxPendingPktList);
			pRxTS->RxBatchCount--;
			ReturnRFDList(Adapter, pRxReorderEntry->pRfd);
			RTInsertTailList(&pMgntInfo->RxReorder_Unused_List, &pRxReorderEntry->List);
		}

		if(!bInRxProgress)
			PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
	}
	else
	{
		PTX_TS_RECORD pTxTS = (PTX_TS_RECORD)pTs;
		PlatformCancelTimer(Adapter, &pTxTS->TsAddBaTimer);
	}
}

VOID
RemovePeerTS(
	PADAPTER	Adapter,
	pu1Byte		Addr
	)
{
	PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
	PTS_COMMON_INFO	pTS, pTmpTS;

	pTS = (PTS_COMMON_INFO)RTGetHeadList(&pMgntInfo->Tx_TS_Pending_List);
	while(&pTS->List != &pMgntInfo->Tx_TS_Pending_List)
	{
		if(PlatformCompareMemory(pTS->Addr, Addr, 6) == 0)
		{
			pTmpTS = pTS;
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
			RTRemoveEntryList(&pTmpTS->List);
			RemoveTsEntry(Adapter, pTmpTS, TX_DIR);
//			RemoveMAEntry(Adapter, &pTmpTS->Ts_MAInfo);
			RTInsertTailList(&pMgntInfo->Tx_TS_Unused_List, &pTmpTS->List);
		}
		else
		{
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
		}
	}

	pTS = (PTS_COMMON_INFO)RTGetHeadList(&pMgntInfo->Tx_TS_Admit_List);
	while(&pTS->List != &pMgntInfo->Tx_TS_Admit_List)
	{
		if(PlatformCompareMemory(pTS->Addr, Addr, 6) == 0)
		{
			pTmpTS = pTS;
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
			RTRemoveEntryList(&pTmpTS->List);
			RemoveTsEntry(Adapter, pTmpTS, TX_DIR);
//			RemoveMAEntry(Adapter, &pTmpTS->Ts_MAInfo);
			RTInsertTailList(&pMgntInfo->Tx_TS_Unused_List, &pTmpTS->List);
		}
		else
		{
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
		}
	}

	pTS = (PTS_COMMON_INFO)RTGetHeadList(&pMgntInfo->Rx_TS_Pending_List);
	while(&pTS->List != &pMgntInfo->Rx_TS_Pending_List)
	{
		if(PlatformCompareMemory(pTS->Addr, Addr, 6) == 0)
		{
			pTmpTS = pTS;
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
			RTRemoveEntryList(&pTmpTS->List);
			RemoveTsEntry(Adapter, pTmpTS, RX_DIR);
//			RemoveMAEntry(Adapter, &pTmpTS->Ts_MAInfo);
			RTInsertTailList(&pMgntInfo->Rx_TS_Unused_List, &pTmpTS->List);
		}
		else
		{
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
		}
	}

	pTS = (PTS_COMMON_INFO)RTGetHeadList(&pMgntInfo->Rx_TS_Admit_List);
	while(&pTS->List != &pMgntInfo->Rx_TS_Admit_List)
	{
		if(PlatformCompareMemory(pTS->Addr, Addr, 6) == 0)
		{
			pTmpTS = pTS;
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
			RTRemoveEntryList(&pTmpTS->List);
			RemoveTsEntry(Adapter, pTmpTS, RX_DIR);
//			RemoveMAEntry(Adapter, &pTmpTS->Ts_MAInfo);
			RTInsertTailList(&pMgntInfo->Rx_TS_Unused_List, &pTmpTS->List);
		}
		else
		{
			pTS = (PTS_COMMON_INFO)RTNextEntryList(&pTS->List);
		}
	}		
}

VOID
ReleaseAllTSTimer(
	PADAPTER	Adapter)
{
	PMGNT_INFO 			pMgntInfo = &Adapter->MgntInfo;
	PTX_TS_RECORD		pTxTS = pMgntInfo->TxTsRecord;
	PRX_TS_RECORD		pRxTS = pMgntInfo->RxTsRecord;
	u1Byte					count = 0;
	
	for(count = 0; count < TOTAL_TS_NUM; count++)
		{
			//
			// The timers for the operation of Traffic Stream and Block Ack.
			// DLS related timer will be add here in the future!!
			//
			PlatformReleaseTimer(
				Adapter, 
				&pTxTS->TsAddBaTimer);

			PlatformReleaseTimer(
				Adapter,
				&pTxTS->TxPendingBARecord.Timer);

			PlatformReleaseTimer(
				Adapter,
				&pTxTS->TxAdmittedBARecord.Timer);
		
		pTxTS++;
	}

	for(count = 0; count < TOTAL_TS_NUM; count++)
		{
			PlatformReleaseTimer(
				Adapter,
				&pRxTS->RxAdmittedBARecord.Timer);
		
			PlatformReleaseTimer(
				Adapter,
				&pRxTS->RxPktPendingTimer);
			
			pRxTS++;
		}
}



VOID
RemoveAllTS(
	PADAPTER	Adapter
	)
{
	PMGNT_INFO pMgntInfo = &Adapter->MgntInfo;
	PTS_COMMON_INFO 	pTS;
	
	while(!RTIsListEmpty(&pMgntInfo->Tx_TS_Pending_List))
	{
		pTS = (PTS_COMMON_INFO)RTRemoveHeadList(&pMgntInfo->Tx_TS_Pending_List);
		RemoveTsEntry(Adapter, pTS, TX_DIR);
//		RemoveMAEntry(Adapter, &pTS->Ts_MAInfo);
		RTInsertTailList(&pMgntInfo->Tx_TS_Unused_List, &pTS->List);
	}

	while(!RTIsListEmpty(&pMgntInfo->Tx_TS_Admit_List))
	{
		pTS = (PTS_COMMON_INFO)RTRemoveHeadList(&pMgntInfo->Tx_TS_Admit_List);
		RemoveTsEntry(Adapter, pTS, TX_DIR);
//		RemoveMAEntry(Adapter, &pTS->Ts_MAInfo);
		RTInsertTailList(&pMgntInfo->Tx_TS_Unused_List, &pTS->List);
	}

	while(!RTIsListEmpty(&pMgntInfo->Rx_TS_Pending_List))
	{
		pTS = (PTS_COMMON_INFO)RTRemoveHeadList(&pMgntInfo->Rx_TS_Pending_List);
		RemoveTsEntry(Adapter, pTS, RX_DIR);
//		RemoveMAEntry(Adapter, &pTS->Ts_MAInfo);
		RTInsertTailList(&pMgntInfo->Rx_TS_Unused_List, &pTS->List);
	}

	while(!RTIsListEmpty(&pMgntInfo->Rx_TS_Admit_List))
	{
		pTS = (PTS_COMMON_INFO)RTRemoveHeadList(&pMgntInfo->Rx_TS_Admit_List);
		RemoveTsEntry(Adapter, pTS, RX_DIR);
//		RemoveMAEntry(Adapter, &pTS->Ts_MAInfo);
		RTInsertTailList(&pMgntInfo->Rx_TS_Unused_List, &pTS->List);
	}		
}

VOID
TsStartAddBaProcess(
	PADAPTER		Adapter,
	PTX_TS_RECORD	pTxTS
	)
{
	if(Adapter->MgntInfo.SafeModeEnabled)
	{
		RT_TRACE(COMP_MLME, DBG_LOUD, ("TsStartAddBaProcess ABORT becuase SafeModeEnable\n"));
		return;
	}
	
	if(pTxTS->bAddBaReqInProgress == FALSE)
	{
		pTxTS->bAddBaReqInProgress = TRUE;

		if(pTxTS->bAddBaReqDelayed)
		{
			RT_TRACE(COMP_QOS, DBG_TRACE, ("TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n"));
			PlatformSetTimer(Adapter, &pTxTS->TsAddBaTimer, TS_ADDBA_DELAY);
		}
		else
		{
			RT_TRACE(COMP_QOS, DBG_TRACE, ("TsStartAddBaProcess(): Immediately Start ADDBA now!!\n"));
			PlatformSetTimer(Adapter, &pTxTS->TsAddBaTimer, 0);
		}
	}
}

VOID
RxTSIndicate(
	PADAPTER		Adapter,
	PRT_RFD			pRfd
	)
{
	OCTET_STRING	frame;
	u1Byte			tid;
	u2Byte			SeqNum;

	frame.Octet = pRfd->Buffer.VirtualAddress;
	frame.Length = pRfd->PacketLength;
	tid = Frame_QoSTID(frame, sMacHdrLng);
	SeqNum = Frame_SeqNum(frame);

	if(GetTs(
		Adapter, 
		(PTS_COMMON_INFO*) &(pRfd->Status.pRxTS),
		Frame_Addr2(frame),
		tid,
		RX_DIR,
		TRUE))
	{
		ExtendRxTS(Adapter, pRfd->Status.pRxTS);

		if(pRfd->Status.bIsAMPDU)
			ExtendBAEntry(Adapter, &(pRfd->Status.pRxTS->RxAdmittedBARecord));

		// Reserve for later usage by RxReorder.
		pRfd->Status.Seq_Num = SeqNum;

		// For 819X series turbo mode!!
		// 2012/09/13 MH This should move to HAL layer.
		// 2012/09/14 MH IN a special case, TPLINK WR741ND Atheros AR9341 AP.
		// When tested in win7 OS, every 45-50s, AP will send a TID=6 packet to
		// NIC for 3 times(6 sec). Then RTWLANU will disable EDCA turbo mode temporarily
		// So the throughput will downgrade. We need to ignore the special case.
		{			
			if(tid!=0 && tid!=3)
			{				
				HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(Adapter);
				if (Adapter->MgntInfo.bWiFiConfg)
				{
					pHalData->bIsAnyNonBEPkts = TRUE;
				}
				else
				{
					//
					// How to Judge,? In busy trafic and then BE packets > VI/VO more than 90%.
					// Then in busy traffic and VI/VO > 1M??
					//
				}
				Adapter->MgntInfo.NumNonBePkt++;
			}
			else
			{
				Adapter->MgntInfo.NumBePkt++;
			}
		}
	}
	else
	{
		pRfd->Status.pRxTS = NULL;

		RT_TRACE(COMP_RECV, DBG_LOUD, ("RxTSIndicate(): No TS!! Skip the check!!\n"));
		RT_ASSERT(FALSE, ("RxTSIndicate(): No TS allocated!!"));
	}
}