2 #include <linux/etherdevice.h>
3 #include <linux/slab.h>
4 #include "rtl819x_TS.h"
6 void TsSetupTimeOut(unsigned long data)
9 // This is used for WMMSA and ACM , that would send ADDTSReq frame.
12 void TsInactTimeout(unsigned long data)
15 // This is used for WMMSA and ACM.
16 // This function would be call when TS is no Tx/Rx for some period of time.
19 /********************************************************************************************************************
20 *function: I still not understand this function, so wait for further implementation
21 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
24 ********************************************************************************************************************/
26 void RxPktPendingTimeout(unsigned long data)
28 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
29 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
31 PRX_REORDER_ENTRY pReorderEntry = NULL;
34 unsigned long flags = 0;
35 struct ieee80211_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
37 bool bPktInBuf = false;
40 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
41 //PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
42 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"==================>%s()\n",__FUNCTION__);
43 if(pRxTs->RxTimeoutIndicateSeq != 0xffff)
45 // Indicate the pending packets sequentially according to SeqNum until meet the gap.
46 while(!list_empty(&pRxTs->RxPendingPktList))
48 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
50 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
52 if( SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
53 SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) )
55 list_del_init(&pReorderEntry->List);
57 if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq))
58 pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096;
60 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum);
61 stats_IndicateArray[index] = pReorderEntry->prxb;
64 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
76 // Set RxTimeoutIndicateSeq to 0xffff to indicate no pending packets in buffer now.
77 pRxTs->RxTimeoutIndicateSeq = 0xffff;
80 if(index > REORDER_WIN_SIZE){
81 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
82 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
85 ieee80211_indicate_packets(ieee, stats_IndicateArray, index);
90 if(bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff))
92 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
93 mod_timer(&pRxTs->RxPktPendingTimer, jiffies + MSECS(ieee->pHTInfo->RxReorderPendingTime));
95 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
96 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
100 /********************************************************************************************************************
101 *function: Add BA timer function
102 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
105 ********************************************************************************************************************/
106 void TsAddBaProcess(unsigned long data)
108 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
110 struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[num]);
112 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
113 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsAddBaProcess(): ADDBA Req is started!! \n");
117 void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo)
119 memset(pTsCommonInfo->Addr, 0, 6);
120 memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY));
121 memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM);
122 pTsCommonInfo->TClasProc = 0;
123 pTsCommonInfo->TClasNum = 0;
126 void ResetTxTsEntry(PTX_TS_RECORD pTS)
128 ResetTsCommonInfo(&pTS->TsCommonInfo);
130 pTS->bAddBaReqInProgress = false;
131 pTS->bAddBaReqDelayed = false;
132 pTS->bUsingBa = false;
133 ResetBaEntry(&pTS->TxAdmittedBARecord); //For BA Originator
134 ResetBaEntry(&pTS->TxPendingBARecord);
137 void ResetRxTsEntry(PRX_TS_RECORD pTS)
139 ResetTsCommonInfo(&pTS->TsCommonInfo);
140 pTS->RxIndicateSeq = 0xffff; // This indicate the RxIndicateSeq is not used now!!
141 pTS->RxTimeoutIndicateSeq = 0xffff; // This indicate the RxTimeoutIndicateSeq is not used now!!
142 ResetBaEntry(&pTS->RxAdmittedBARecord); // For BA Recepient
145 void TSInitialize(struct ieee80211_device *ieee)
147 PTX_TS_RECORD pTxTS = ieee->TxTsRecord;
148 PRX_TS_RECORD pRxTS = ieee->RxTsRecord;
149 PRX_REORDER_ENTRY pRxReorderEntry = ieee->RxReorderEntry;
151 IEEE80211_DEBUG(IEEE80211_DL_TS, "==========>%s()\n", __FUNCTION__);
152 // Initialize Tx TS related info.
153 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
154 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
155 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
157 for(count = 0; count < TOTAL_TS_NUM; count++)
161 // The timers for the operation of Traffic Stream and Block Ack.
162 // DLS related timer will be add here in the future!!
163 init_timer(&pTxTS->TsCommonInfo.SetupTimer);
164 pTxTS->TsCommonInfo.SetupTimer.data = (unsigned long)pTxTS;
165 pTxTS->TsCommonInfo.SetupTimer.function = TsSetupTimeOut;
167 init_timer(&pTxTS->TsCommonInfo.InactTimer);
168 pTxTS->TsCommonInfo.InactTimer.data = (unsigned long)pTxTS;
169 pTxTS->TsCommonInfo.InactTimer.function = TsInactTimeout;
171 init_timer(&pTxTS->TsAddBaTimer);
172 pTxTS->TsAddBaTimer.data = (unsigned long)pTxTS;
173 pTxTS->TsAddBaTimer.function = TsAddBaProcess;
175 init_timer(&pTxTS->TxPendingBARecord.Timer);
176 pTxTS->TxPendingBARecord.Timer.data = (unsigned long)pTxTS;
177 pTxTS->TxPendingBARecord.Timer.function = BaSetupTimeOut;
179 init_timer(&pTxTS->TxAdmittedBARecord.Timer);
180 pTxTS->TxAdmittedBARecord.Timer.data = (unsigned long)pTxTS;
181 pTxTS->TxAdmittedBARecord.Timer.function = TxBaInactTimeout;
183 ResetTxTsEntry(pTxTS);
184 list_add_tail(&pTxTS->TsCommonInfo.List, &ieee->Tx_TS_Unused_List);
188 // Initialize Rx TS related info.
189 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
190 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
191 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
192 for(count = 0; count < TOTAL_TS_NUM; count++)
195 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
197 init_timer(&pRxTS->TsCommonInfo.SetupTimer);
198 pRxTS->TsCommonInfo.SetupTimer.data = (unsigned long)pRxTS;
199 pRxTS->TsCommonInfo.SetupTimer.function = TsSetupTimeOut;
201 init_timer(&pRxTS->TsCommonInfo.InactTimer);
202 pRxTS->TsCommonInfo.InactTimer.data = (unsigned long)pRxTS;
203 pRxTS->TsCommonInfo.InactTimer.function = TsInactTimeout;
205 init_timer(&pRxTS->RxAdmittedBARecord.Timer);
206 pRxTS->RxAdmittedBARecord.Timer.data = (unsigned long)pRxTS;
207 pRxTS->RxAdmittedBARecord.Timer.function = RxBaInactTimeout;
209 init_timer(&pRxTS->RxPktPendingTimer);
210 pRxTS->RxPktPendingTimer.data = (unsigned long)pRxTS;
211 pRxTS->RxPktPendingTimer.function = RxPktPendingTimeout;
213 ResetRxTsEntry(pRxTS);
214 list_add_tail(&pRxTS->TsCommonInfo.List, &ieee->Rx_TS_Unused_List);
217 // Initialize unused Rx Reorder List.
218 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
220 for(count = 0; count < REORDER_ENTRY_NUM; count++)
222 list_add_tail( &pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
223 if(count == (REORDER_ENTRY_NUM-1))
225 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
231 void AdmitTS(struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 InactTime)
233 del_timer_sync(&pTsCommonInfo->SetupTimer);
234 del_timer_sync(&pTsCommonInfo->InactTimer);
237 mod_timer(&pTsCommonInfo->InactTimer, jiffies + MSECS(InactTime));
241 PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect)
243 //DIRECTION_VALUE dir;
245 bool search_dir[4] = {0, 0, 0, 0};
246 struct list_head* psearch_list; //FIXME
247 PTS_COMMON_INFO pRet = NULL;
248 if(ieee->iw_mode == IW_MODE_MASTER) //ap mode
250 if(TxRxSelect == TX_DIR)
252 search_dir[DIR_DOWN] = true;
253 search_dir[DIR_BI_DIR]= true;
257 search_dir[DIR_UP] = true;
258 search_dir[DIR_BI_DIR]= true;
261 else if(ieee->iw_mode == IW_MODE_ADHOC)
263 if(TxRxSelect == TX_DIR)
264 search_dir[DIR_UP] = true;
266 search_dir[DIR_DOWN] = true;
270 if(TxRxSelect == TX_DIR)
272 search_dir[DIR_UP] = true;
273 search_dir[DIR_BI_DIR]= true;
274 search_dir[DIR_DIRECT]= true;
278 search_dir[DIR_DOWN] = true;
279 search_dir[DIR_BI_DIR]= true;
280 search_dir[DIR_DIRECT]= true;
284 if(TxRxSelect == TX_DIR)
285 psearch_list = &ieee->Tx_TS_Admit_List;
287 psearch_list = &ieee->Rx_TS_Admit_List;
289 //for(dir = DIR_UP; dir <= DIR_BI_DIR; dir++)
290 for(dir = 0; dir <= DIR_BI_DIR; dir++)
292 if(search_dir[dir] ==false )
294 list_for_each_entry(pRet, psearch_list, List){
295 // IEEE80211_DEBUG(IEEE80211_DL_TS, "ADD:%pM, TID:%d, dir:%d\n", pRet->Addr, pRet->TSpec.f.TSInfo.field.ucTSID, pRet->TSpec.f.TSInfo.field.ucDirection);
296 if (memcmp(pRet->Addr, Addr, 6) == 0)
297 if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
298 if(pRet->TSpec.f.TSInfo.field.ucDirection == dir)
300 // printk("Bingo! got it\n");
305 if(&pRet->List != psearch_list)
309 if(&pRet->List != psearch_list){
317 PTS_COMMON_INFO pTsCommonInfo,
327 if(pTsCommonInfo == NULL)
330 memcpy(pTsCommonInfo->Addr, Addr, 6);
333 memcpy((u8*)(&(pTsCommonInfo->TSpec)), (u8*)pTSPEC, sizeof(TSPEC_BODY));
335 for(count = 0; count < TCLAS_Num; count++)
336 memcpy((u8*)(&(pTsCommonInfo->TClass[count])), (u8*)pTCLAS, sizeof(QOS_TCLAS));
338 pTsCommonInfo->TClasProc = TCLAS_Proc;
339 pTsCommonInfo->TClasNum = TCLAS_Num;
344 struct ieee80211_device* ieee,
345 PTS_COMMON_INFO *ppTS,
348 TR_SELECT TxRxSelect, //Rx:1, Tx:0
354 // We do not build any TS for Broadcast or Multicast stream.
355 // So reject these kinds of search here.
357 if(is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr))
359 IEEE80211_DEBUG(IEEE80211_DL_ERR, "get TS for Broadcast or Multicast\n");
363 if (ieee->current_network.qos_data.supported == 0)
367 // In WMM case: we use 4 TID only
370 IEEE80211_DEBUG(IEEE80211_DL_ERR, " in %s(), TID(%d) is not valid\n", __FUNCTION__, TID);
398 *ppTS = SearchAdmitTRStream(
409 if(bAddNewTs == false)
411 IEEE80211_DEBUG(IEEE80211_DL_TS, "add new TS failed(tid:%d)\n", UP);
417 // Create a new Traffic stream for current Tx/Rx
418 // This is for EDCA and WMM to add a new TS.
419 // For HCCA or WMMSA, TS cannot be addmit without negotiation.
422 PQOS_TSINFO pTSInfo = &TSpec.f.TSInfo;
423 struct list_head* pUnusedList =
424 (TxRxSelect == TX_DIR)?
425 (&ieee->Tx_TS_Unused_List):
426 (&ieee->Rx_TS_Unused_List);
428 struct list_head* pAddmitList =
429 (TxRxSelect == TX_DIR)?
430 (&ieee->Tx_TS_Admit_List):
431 (&ieee->Rx_TS_Admit_List);
433 DIRECTION_VALUE Dir = (ieee->iw_mode == IW_MODE_MASTER)?
434 ((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):
435 ((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
436 IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
437 if(!list_empty(pUnusedList))
439 (*ppTS) = list_entry(pUnusedList->next, TS_COMMON_INFO, List);
440 list_del_init(&(*ppTS)->List);
441 if(TxRxSelect==TX_DIR)
443 PTX_TS_RECORD tmp = container_of(*ppTS, TX_TS_RECORD, TsCommonInfo);
447 PRX_TS_RECORD tmp = container_of(*ppTS, RX_TS_RECORD, TsCommonInfo);
451 IEEE80211_DEBUG(IEEE80211_DL_TS, "to init current TS, UP:%d, Dir:%d, addr:%pM\n", UP, Dir, Addr);
452 // Prepare TS Info releated field
453 pTSInfo->field.ucTrafficType = 0; // Traffic type: WMM is reserved in this field
454 pTSInfo->field.ucTSID = UP; // TSID
455 pTSInfo->field.ucDirection = Dir; // Direction: if there is DirectLink, this need additional consideration.
456 pTSInfo->field.ucAccessPolicy = 1; // Access policy
457 pTSInfo->field.ucAggregation = 0; // Aggregation
458 pTSInfo->field.ucPSB = 0; // Aggregation
459 pTSInfo->field.ucUP = UP; // User priority
460 pTSInfo->field.ucTSInfoAckPolicy = 0; // Ack policy
461 pTSInfo->field.ucSchedule = 0; // Schedule
463 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
464 AdmitTS(ieee, *ppTS, 0);
465 list_add_tail(&((*ppTS)->List), pAddmitList);
466 // if there is DirectLink, we need to do additional operation here!!
472 IEEE80211_DEBUG(IEEE80211_DL_ERR, "in function %s() There is not enough TS record to be used!!", __FUNCTION__);
480 struct ieee80211_device* ieee,
486 unsigned long flags = 0;
487 del_timer_sync(&pTs->SetupTimer);
488 del_timer_sync(&pTs->InactTimer);
489 TsInitDelBA(ieee, pTs, TxRxSelect);
491 if(TxRxSelect == RX_DIR)
494 PRX_REORDER_ENTRY pRxReorderEntry;
495 PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs;
496 if(timer_pending(&pRxTS->RxPktPendingTimer))
497 del_timer_sync(&pRxTS->RxPktPendingTimer);
499 while(!list_empty(&pRxTS->RxPendingPktList))
501 // PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
502 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
503 //pRxReorderEntry = list_entry(&pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
504 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
505 list_del_init(&pRxReorderEntry->List);
508 struct ieee80211_rxb * prxb = pRxReorderEntry->prxb;
511 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
514 for(i =0; i < prxb->nr_subframes; i++) {
515 dev_kfree_skb(prxb->subframes[i]);
520 list_add_tail(&pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
521 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
522 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
529 PTX_TS_RECORD pTxTS = (PTX_TS_RECORD)pTs;
530 del_timer_sync(&pTxTS->TsAddBaTimer);
534 void RemovePeerTS(struct ieee80211_device* ieee, u8* Addr)
536 PTS_COMMON_INFO pTS, pTmpTS;
537 printk("===========>RemovePeerTS,%pM\n", Addr);
539 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
541 if (memcmp(pTS->Addr, Addr, 6) == 0)
543 RemoveTsEntry(ieee, pTS, TX_DIR);
544 list_del_init(&pTS->List);
545 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
549 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
551 if (memcmp(pTS->Addr, Addr, 6) == 0)
553 printk("====>remove Tx_TS_admin_list\n");
554 RemoveTsEntry(ieee, pTS, TX_DIR);
555 list_del_init(&pTS->List);
556 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
560 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
562 if (memcmp(pTS->Addr, Addr, 6) == 0)
564 RemoveTsEntry(ieee, pTS, RX_DIR);
565 list_del_init(&pTS->List);
566 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
570 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
572 if (memcmp(pTS->Addr, Addr, 6) == 0)
574 RemoveTsEntry(ieee, pTS, RX_DIR);
575 list_del_init(&pTS->List);
576 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
582 void RemoveAllTS(struct ieee80211_device* ieee)
584 PTS_COMMON_INFO pTS, pTmpTS;
586 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
588 RemoveTsEntry(ieee, pTS, TX_DIR);
589 list_del_init(&pTS->List);
590 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
593 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
595 RemoveTsEntry(ieee, pTS, TX_DIR);
596 list_del_init(&pTS->List);
597 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
600 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
602 RemoveTsEntry(ieee, pTS, RX_DIR);
603 list_del_init(&pTS->List);
604 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
607 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
609 RemoveTsEntry(ieee, pTS, RX_DIR);
610 list_del_init(&pTS->List);
611 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
616 void TsStartAddBaProcess(struct ieee80211_device* ieee, PTX_TS_RECORD pTxTS)
618 if(pTxTS->bAddBaReqInProgress == false)
620 pTxTS->bAddBaReqInProgress = true;
622 if(pTxTS->bAddBaReqDelayed)
624 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n");
625 mod_timer(&pTxTS->TsAddBaTimer, jiffies + MSECS(TS_ADDBA_DELAY));
629 IEEE80211_DEBUG(IEEE80211_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
630 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10); //set 10 ticks
635 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s()==>BA timer is already added\n", __FUNCTION__);