2 #include <linux/etherdevice.h>
3 #include <linux/slab.h>
4 #include "rtl819x_TS.h"
6 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
7 #define list_for_each_entry_safe(pos, n, head, member) \
8 for (pos = list_entry((head)->next, typeof(*pos), member), \
9 n = list_entry(pos->member.next, typeof(*pos), member); \
10 &pos->member != (head); \
11 pos = n, n = list_entry(n->member.next, typeof(*n), member))
13 void TsSetupTimeOut(unsigned long data)
16 // This is used for WMMSA and ACM , that would send ADDTSReq frame.
19 void TsInactTimeout(unsigned long data)
22 // This is used for WMMSA and ACM.
23 // This function would be call when TS is no Tx/Rx for some period of time.
26 /********************************************************************************************************************
27 *function: I still not understand this function, so wait for further implementation
28 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
31 ********************************************************************************************************************/
33 void RxPktPendingTimeout(unsigned long data)
35 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
36 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
38 PRX_REORDER_ENTRY pReorderEntry = NULL;
41 unsigned long flags = 0;
42 struct ieee80211_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
44 bool bPktInBuf = false;
47 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
48 //PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
49 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"==================>%s()\n",__FUNCTION__);
50 if(pRxTs->RxTimeoutIndicateSeq != 0xffff)
52 // Indicate the pending packets sequentially according to SeqNum until meet the gap.
53 while(!list_empty(&pRxTs->RxPendingPktList))
55 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
57 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
59 if( SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
60 SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) )
62 list_del_init(&pReorderEntry->List);
64 if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq))
65 pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096;
67 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum);
68 stats_IndicateArray[index] = pReorderEntry->prxb;
71 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
83 // Set RxTimeoutIndicateSeq to 0xffff to indicate no pending packets in buffer now.
84 pRxTs->RxTimeoutIndicateSeq = 0xffff;
87 if(index > REORDER_WIN_SIZE){
88 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
89 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
92 ieee80211_indicate_packets(ieee, stats_IndicateArray, index);
96 if(bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff))
98 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
100 if(timer_pending(&pRxTs->RxPktPendingTimer))
101 del_timer_sync(&pRxTs->RxPktPendingTimer);
102 pRxTs->RxPktPendingTimer.expires = jiffies + ieee->pHTInfo->RxReorderPendingTime;
103 add_timer(&pRxTs->RxPktPendingTimer);
105 mod_timer(&pRxTs->RxPktPendingTimer, jiffies + MSECS(ieee->pHTInfo->RxReorderPendingTime));
108 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
109 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
113 /********************************************************************************************************************
114 *function: Add BA timer function
115 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
118 ********************************************************************************************************************/
119 void TsAddBaProcess(unsigned long data)
121 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
123 struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[num]);
125 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
126 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsAddBaProcess(): ADDBA Req is started!! \n");
130 void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo)
132 memset(pTsCommonInfo->Addr, 0, 6);
133 memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY));
134 memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM);
135 pTsCommonInfo->TClasProc = 0;
136 pTsCommonInfo->TClasNum = 0;
139 void ResetTxTsEntry(PTX_TS_RECORD pTS)
141 ResetTsCommonInfo(&pTS->TsCommonInfo);
143 pTS->bAddBaReqInProgress = false;
144 pTS->bAddBaReqDelayed = false;
145 pTS->bUsingBa = false;
146 ResetBaEntry(&pTS->TxAdmittedBARecord); //For BA Originator
147 ResetBaEntry(&pTS->TxPendingBARecord);
150 void ResetRxTsEntry(PRX_TS_RECORD pTS)
152 ResetTsCommonInfo(&pTS->TsCommonInfo);
153 pTS->RxIndicateSeq = 0xffff; // This indicate the RxIndicateSeq is not used now!!
154 pTS->RxTimeoutIndicateSeq = 0xffff; // This indicate the RxTimeoutIndicateSeq is not used now!!
155 ResetBaEntry(&pTS->RxAdmittedBARecord); // For BA Recepient
158 void TSInitialize(struct ieee80211_device *ieee)
160 PTX_TS_RECORD pTxTS = ieee->TxTsRecord;
161 PRX_TS_RECORD pRxTS = ieee->RxTsRecord;
162 PRX_REORDER_ENTRY pRxReorderEntry = ieee->RxReorderEntry;
164 IEEE80211_DEBUG(IEEE80211_DL_TS, "==========>%s()\n", __FUNCTION__);
165 // Initialize Tx TS related info.
166 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
167 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
168 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
170 for(count = 0; count < TOTAL_TS_NUM; count++)
174 // The timers for the operation of Traffic Stream and Block Ack.
175 // DLS related timer will be add here in the future!!
176 init_timer(&pTxTS->TsCommonInfo.SetupTimer);
177 pTxTS->TsCommonInfo.SetupTimer.data = (unsigned long)pTxTS;
178 pTxTS->TsCommonInfo.SetupTimer.function = TsSetupTimeOut;
180 init_timer(&pTxTS->TsCommonInfo.InactTimer);
181 pTxTS->TsCommonInfo.InactTimer.data = (unsigned long)pTxTS;
182 pTxTS->TsCommonInfo.InactTimer.function = TsInactTimeout;
184 init_timer(&pTxTS->TsAddBaTimer);
185 pTxTS->TsAddBaTimer.data = (unsigned long)pTxTS;
186 pTxTS->TsAddBaTimer.function = TsAddBaProcess;
188 init_timer(&pTxTS->TxPendingBARecord.Timer);
189 pTxTS->TxPendingBARecord.Timer.data = (unsigned long)pTxTS;
190 pTxTS->TxPendingBARecord.Timer.function = BaSetupTimeOut;
192 init_timer(&pTxTS->TxAdmittedBARecord.Timer);
193 pTxTS->TxAdmittedBARecord.Timer.data = (unsigned long)pTxTS;
194 pTxTS->TxAdmittedBARecord.Timer.function = TxBaInactTimeout;
196 ResetTxTsEntry(pTxTS);
197 list_add_tail(&pTxTS->TsCommonInfo.List, &ieee->Tx_TS_Unused_List);
201 // Initialize Rx TS related info.
202 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
203 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
204 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
205 for(count = 0; count < TOTAL_TS_NUM; count++)
208 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
210 init_timer(&pRxTS->TsCommonInfo.SetupTimer);
211 pRxTS->TsCommonInfo.SetupTimer.data = (unsigned long)pRxTS;
212 pRxTS->TsCommonInfo.SetupTimer.function = TsSetupTimeOut;
214 init_timer(&pRxTS->TsCommonInfo.InactTimer);
215 pRxTS->TsCommonInfo.InactTimer.data = (unsigned long)pRxTS;
216 pRxTS->TsCommonInfo.InactTimer.function = TsInactTimeout;
218 init_timer(&pRxTS->RxAdmittedBARecord.Timer);
219 pRxTS->RxAdmittedBARecord.Timer.data = (unsigned long)pRxTS;
220 pRxTS->RxAdmittedBARecord.Timer.function = RxBaInactTimeout;
222 init_timer(&pRxTS->RxPktPendingTimer);
223 pRxTS->RxPktPendingTimer.data = (unsigned long)pRxTS;
224 pRxTS->RxPktPendingTimer.function = RxPktPendingTimeout;
226 ResetRxTsEntry(pRxTS);
227 list_add_tail(&pRxTS->TsCommonInfo.List, &ieee->Rx_TS_Unused_List);
230 // Initialize unused Rx Reorder List.
231 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
233 for(count = 0; count < REORDER_ENTRY_NUM; count++)
235 list_add_tail( &pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
236 if(count == (REORDER_ENTRY_NUM-1))
238 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
244 void AdmitTS(struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 InactTime)
246 del_timer_sync(&pTsCommonInfo->SetupTimer);
247 del_timer_sync(&pTsCommonInfo->InactTimer);
250 mod_timer(&pTsCommonInfo->InactTimer, jiffies + MSECS(InactTime));
254 PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect)
256 //DIRECTION_VALUE dir;
258 bool search_dir[4] = {0, 0, 0, 0};
259 struct list_head* psearch_list; //FIXME
260 PTS_COMMON_INFO pRet = NULL;
261 if(ieee->iw_mode == IW_MODE_MASTER) //ap mode
263 if(TxRxSelect == TX_DIR)
265 search_dir[DIR_DOWN] = true;
266 search_dir[DIR_BI_DIR]= true;
270 search_dir[DIR_UP] = true;
271 search_dir[DIR_BI_DIR]= true;
274 else if(ieee->iw_mode == IW_MODE_ADHOC)
276 if(TxRxSelect == TX_DIR)
277 search_dir[DIR_UP] = true;
279 search_dir[DIR_DOWN] = true;
283 if(TxRxSelect == TX_DIR)
285 search_dir[DIR_UP] = true;
286 search_dir[DIR_BI_DIR]= true;
287 search_dir[DIR_DIRECT]= true;
291 search_dir[DIR_DOWN] = true;
292 search_dir[DIR_BI_DIR]= true;
293 search_dir[DIR_DIRECT]= true;
297 if(TxRxSelect == TX_DIR)
298 psearch_list = &ieee->Tx_TS_Admit_List;
300 psearch_list = &ieee->Rx_TS_Admit_List;
302 //for(dir = DIR_UP; dir <= DIR_BI_DIR; dir++)
303 for(dir = 0; dir <= DIR_BI_DIR; dir++)
305 if(search_dir[dir] ==false )
307 list_for_each_entry(pRet, psearch_list, List){
308 // 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);
309 if (memcmp(pRet->Addr, Addr, 6) == 0)
310 if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
311 if(pRet->TSpec.f.TSInfo.field.ucDirection == dir)
313 // printk("Bingo! got it\n");
318 if(&pRet->List != psearch_list)
322 if(&pRet->List != psearch_list){
330 PTS_COMMON_INFO pTsCommonInfo,
340 if(pTsCommonInfo == NULL)
343 memcpy(pTsCommonInfo->Addr, Addr, 6);
346 memcpy((u8*)(&(pTsCommonInfo->TSpec)), (u8*)pTSPEC, sizeof(TSPEC_BODY));
348 for(count = 0; count < TCLAS_Num; count++)
349 memcpy((u8*)(&(pTsCommonInfo->TClass[count])), (u8*)pTCLAS, sizeof(QOS_TCLAS));
351 pTsCommonInfo->TClasProc = TCLAS_Proc;
352 pTsCommonInfo->TClasNum = TCLAS_Num;
357 struct ieee80211_device* ieee,
358 PTS_COMMON_INFO *ppTS,
361 TR_SELECT TxRxSelect, //Rx:1, Tx:0
367 // We do not build any TS for Broadcast or Multicast stream.
368 // So reject these kinds of search here.
370 if(is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr))
372 IEEE80211_DEBUG(IEEE80211_DL_ERR, "get TS for Broadcast or Multicast\n");
376 if(ieee->pStaQos->CurrentQosMode == QOS_DISABLE)
377 { UP = 0; } //only use one TS
378 else if(ieee->pStaQos->CurrentQosMode & QOS_WMM)
381 if (ieee->current_network.qos_data.supported == 0)
386 // In WMM case: we use 4 TID only
389 IEEE80211_DEBUG(IEEE80211_DL_ERR, " in %s(), TID(%d) is not valid\n", __FUNCTION__, TID);
417 *ppTS = SearchAdmitTRStream(
428 if(bAddNewTs == false)
430 IEEE80211_DEBUG(IEEE80211_DL_TS, "add new TS failed(tid:%d)\n", UP);
436 // Create a new Traffic stream for current Tx/Rx
437 // This is for EDCA and WMM to add a new TS.
438 // For HCCA or WMMSA, TS cannot be addmit without negotiation.
441 PQOS_TSINFO pTSInfo = &TSpec.f.TSInfo;
442 struct list_head* pUnusedList =
443 (TxRxSelect == TX_DIR)?
444 (&ieee->Tx_TS_Unused_List):
445 (&ieee->Rx_TS_Unused_List);
447 struct list_head* pAddmitList =
448 (TxRxSelect == TX_DIR)?
449 (&ieee->Tx_TS_Admit_List):
450 (&ieee->Rx_TS_Admit_List);
452 DIRECTION_VALUE Dir = (ieee->iw_mode == IW_MODE_MASTER)?
453 ((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):
454 ((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
455 IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
456 if(!list_empty(pUnusedList))
458 (*ppTS) = list_entry(pUnusedList->next, TS_COMMON_INFO, List);
459 list_del_init(&(*ppTS)->List);
460 if(TxRxSelect==TX_DIR)
462 PTX_TS_RECORD tmp = container_of(*ppTS, TX_TS_RECORD, TsCommonInfo);
466 PRX_TS_RECORD tmp = container_of(*ppTS, RX_TS_RECORD, TsCommonInfo);
470 IEEE80211_DEBUG(IEEE80211_DL_TS, "to init current TS, UP:%d, Dir:%d, addr:%pM\n", UP, Dir, Addr);
471 // Prepare TS Info releated field
472 pTSInfo->field.ucTrafficType = 0; // Traffic type: WMM is reserved in this field
473 pTSInfo->field.ucTSID = UP; // TSID
474 pTSInfo->field.ucDirection = Dir; // Direction: if there is DirectLink, this need additional consideration.
475 pTSInfo->field.ucAccessPolicy = 1; // Access policy
476 pTSInfo->field.ucAggregation = 0; // Aggregation
477 pTSInfo->field.ucPSB = 0; // Aggregation
478 pTSInfo->field.ucUP = UP; // User priority
479 pTSInfo->field.ucTSInfoAckPolicy = 0; // Ack policy
480 pTSInfo->field.ucSchedule = 0; // Schedule
482 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
483 AdmitTS(ieee, *ppTS, 0);
484 list_add_tail(&((*ppTS)->List), pAddmitList);
485 // if there is DirectLink, we need to do additional operation here!!
491 IEEE80211_DEBUG(IEEE80211_DL_ERR, "in function %s() There is not enough TS record to be used!!", __FUNCTION__);
499 struct ieee80211_device* ieee,
505 unsigned long flags = 0;
506 del_timer_sync(&pTs->SetupTimer);
507 del_timer_sync(&pTs->InactTimer);
508 TsInitDelBA(ieee, pTs, TxRxSelect);
510 if(TxRxSelect == RX_DIR)
513 PRX_REORDER_ENTRY pRxReorderEntry;
514 PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs;
515 if(timer_pending(&pRxTS->RxPktPendingTimer))
516 del_timer_sync(&pRxTS->RxPktPendingTimer);
518 while(!list_empty(&pRxTS->RxPendingPktList))
520 // PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
521 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
522 //pRxReorderEntry = list_entry(&pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
523 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
524 list_del_init(&pRxReorderEntry->List);
527 struct ieee80211_rxb * prxb = pRxReorderEntry->prxb;
530 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
533 for(i =0; i < prxb->nr_subframes; i++) {
534 dev_kfree_skb(prxb->subframes[i]);
539 list_add_tail(&pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
540 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
541 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
548 PTX_TS_RECORD pTxTS = (PTX_TS_RECORD)pTs;
549 del_timer_sync(&pTxTS->TsAddBaTimer);
553 void RemovePeerTS(struct ieee80211_device* ieee, u8* Addr)
555 PTS_COMMON_INFO pTS, pTmpTS;
556 printk("===========>RemovePeerTS,%pM\n", Addr);
558 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
560 if (memcmp(pTS->Addr, Addr, 6) == 0)
562 RemoveTsEntry(ieee, pTS, TX_DIR);
563 list_del_init(&pTS->List);
564 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
568 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
570 if (memcmp(pTS->Addr, Addr, 6) == 0)
572 printk("====>remove Tx_TS_admin_list\n");
573 RemoveTsEntry(ieee, pTS, TX_DIR);
574 list_del_init(&pTS->List);
575 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
579 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
581 if (memcmp(pTS->Addr, Addr, 6) == 0)
583 RemoveTsEntry(ieee, pTS, RX_DIR);
584 list_del_init(&pTS->List);
585 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
589 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
591 if (memcmp(pTS->Addr, Addr, 6) == 0)
593 RemoveTsEntry(ieee, pTS, RX_DIR);
594 list_del_init(&pTS->List);
595 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
601 void RemoveAllTS(struct ieee80211_device* ieee)
603 PTS_COMMON_INFO pTS, pTmpTS;
605 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
607 RemoveTsEntry(ieee, pTS, TX_DIR);
608 list_del_init(&pTS->List);
609 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
612 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
614 RemoveTsEntry(ieee, pTS, TX_DIR);
615 list_del_init(&pTS->List);
616 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
619 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
621 RemoveTsEntry(ieee, pTS, RX_DIR);
622 list_del_init(&pTS->List);
623 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
626 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
628 RemoveTsEntry(ieee, pTS, RX_DIR);
629 list_del_init(&pTS->List);
630 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
635 void TsStartAddBaProcess(struct ieee80211_device* ieee, PTX_TS_RECORD pTxTS)
637 if(pTxTS->bAddBaReqInProgress == false)
639 pTxTS->bAddBaReqInProgress = true;
641 if(pTxTS->bAddBaReqDelayed)
643 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n");
644 mod_timer(&pTxTS->TsAddBaTimer, jiffies + MSECS(TS_ADDBA_DELAY));
648 IEEE80211_DEBUG(IEEE80211_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
649 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10); //set 10 ticks
654 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s()==>BA timer is already added\n", __FUNCTION__);
656 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
657 EXPORT_SYMBOL_NOVERS(RemovePeerTS);
659 //EXPORT_SYMBOL(RemovePeerTS);