2 #include <linux/etherdevice.h>
3 #include "rtl819x_TS.h"
5 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6 #define list_for_each_entry_safe(pos, n, head, member) \
7 for (pos = list_entry((head)->next, typeof(*pos), member), \
8 n = list_entry(pos->member.next, typeof(*pos), member); \
9 &pos->member != (head); \
10 pos = n, n = list_entry(n->member.next, typeof(*n), member))
12 void TsSetupTimeOut(unsigned long data)
15 // This is used for WMMSA and ACM , that would send ADDTSReq frame.
18 void TsInactTimeout(unsigned long data)
21 // This is used for WMMSA and ACM.
22 // This function would be call when TS is no Tx/Rx for some period of time.
25 /********************************************************************************************************************
26 *function: I still not understand this function, so wait for further implementation
27 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
30 ********************************************************************************************************************/
32 void RxPktPendingTimeout(unsigned long data)
34 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
35 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
37 PRX_REORDER_ENTRY pReorderEntry = NULL;
40 unsigned long flags = 0;
41 struct ieee80211_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
43 bool bPktInBuf = false;
46 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
47 //PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
48 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"==================>%s()\n",__FUNCTION__);
49 if(pRxTs->RxTimeoutIndicateSeq != 0xffff)
51 // Indicate the pending packets sequentially according to SeqNum until meet the gap.
52 while(!list_empty(&pRxTs->RxPendingPktList))
54 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTs->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
56 pRxTs->RxIndicateSeq = pReorderEntry->SeqNum;
58 if( SN_LESS(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) ||
59 SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq) )
61 list_del_init(&pReorderEntry->List);
63 if(SN_EQUAL(pReorderEntry->SeqNum, pRxTs->RxIndicateSeq))
64 pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096;
66 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum);
67 stats_IndicateArray[index] = pReorderEntry->prxb;
70 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
82 // Set RxTimeoutIndicateSeq to 0xffff to indicate no pending packets in buffer now.
83 pRxTs->RxTimeoutIndicateSeq = 0xffff;
86 if(index > REORDER_WIN_SIZE){
87 IEEE80211_DEBUG(IEEE80211_DL_ERR, "RxReorderIndicatePacket(): Rx Reorer buffer full!! \n");
88 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
91 ieee80211_indicate_packets(ieee, stats_IndicateArray, index);
95 if(bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff))
97 pRxTs->RxTimeoutIndicateSeq = pRxTs->RxIndicateSeq;
99 if(timer_pending(&pRxTs->RxPktPendingTimer))
100 del_timer_sync(&pRxTs->RxPktPendingTimer);
101 pRxTs->RxPktPendingTimer.expires = jiffies + ieee->pHTInfo->RxReorderPendingTime;
102 add_timer(&pRxTs->RxPktPendingTimer);
104 mod_timer(&pRxTs->RxPktPendingTimer, jiffies + MSECS(ieee->pHTInfo->RxReorderPendingTime));
107 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
108 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
112 /********************************************************************************************************************
113 *function: Add BA timer function
114 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
117 ********************************************************************************************************************/
118 void TsAddBaProcess(unsigned long data)
120 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
122 struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[num]);
124 TsInitAddBA(ieee, pTxTs, BA_POLICY_IMMEDIATE, false);
125 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsAddBaProcess(): ADDBA Req is started!! \n");
129 void ResetTsCommonInfo(PTS_COMMON_INFO pTsCommonInfo)
131 memset(pTsCommonInfo->Addr, 0, 6);
132 memset(&pTsCommonInfo->TSpec, 0, sizeof(TSPEC_BODY));
133 memset(&pTsCommonInfo->TClass, 0, sizeof(QOS_TCLAS)*TCLAS_NUM);
134 pTsCommonInfo->TClasProc = 0;
135 pTsCommonInfo->TClasNum = 0;
138 void ResetTxTsEntry(PTX_TS_RECORD pTS)
140 ResetTsCommonInfo(&pTS->TsCommonInfo);
142 pTS->bAddBaReqInProgress = false;
143 pTS->bAddBaReqDelayed = false;
144 pTS->bUsingBa = false;
145 ResetBaEntry(&pTS->TxAdmittedBARecord); //For BA Originator
146 ResetBaEntry(&pTS->TxPendingBARecord);
149 void ResetRxTsEntry(PRX_TS_RECORD pTS)
151 ResetTsCommonInfo(&pTS->TsCommonInfo);
152 pTS->RxIndicateSeq = 0xffff; // This indicate the RxIndicateSeq is not used now!!
153 pTS->RxTimeoutIndicateSeq = 0xffff; // This indicate the RxTimeoutIndicateSeq is not used now!!
154 ResetBaEntry(&pTS->RxAdmittedBARecord); // For BA Recepient
157 void TSInitialize(struct ieee80211_device *ieee)
159 PTX_TS_RECORD pTxTS = ieee->TxTsRecord;
160 PRX_TS_RECORD pRxTS = ieee->RxTsRecord;
161 PRX_REORDER_ENTRY pRxReorderEntry = ieee->RxReorderEntry;
163 IEEE80211_DEBUG(IEEE80211_DL_TS, "==========>%s()\n", __FUNCTION__);
164 // Initialize Tx TS related info.
165 INIT_LIST_HEAD(&ieee->Tx_TS_Admit_List);
166 INIT_LIST_HEAD(&ieee->Tx_TS_Pending_List);
167 INIT_LIST_HEAD(&ieee->Tx_TS_Unused_List);
169 for(count = 0; count < TOTAL_TS_NUM; count++)
173 // The timers for the operation of Traffic Stream and Block Ack.
174 // DLS related timer will be add here in the future!!
175 init_timer(&pTxTS->TsCommonInfo.SetupTimer);
176 pTxTS->TsCommonInfo.SetupTimer.data = (unsigned long)pTxTS;
177 pTxTS->TsCommonInfo.SetupTimer.function = TsSetupTimeOut;
179 init_timer(&pTxTS->TsCommonInfo.InactTimer);
180 pTxTS->TsCommonInfo.InactTimer.data = (unsigned long)pTxTS;
181 pTxTS->TsCommonInfo.InactTimer.function = TsInactTimeout;
183 init_timer(&pTxTS->TsAddBaTimer);
184 pTxTS->TsAddBaTimer.data = (unsigned long)pTxTS;
185 pTxTS->TsAddBaTimer.function = TsAddBaProcess;
187 init_timer(&pTxTS->TxPendingBARecord.Timer);
188 pTxTS->TxPendingBARecord.Timer.data = (unsigned long)pTxTS;
189 pTxTS->TxPendingBARecord.Timer.function = BaSetupTimeOut;
191 init_timer(&pTxTS->TxAdmittedBARecord.Timer);
192 pTxTS->TxAdmittedBARecord.Timer.data = (unsigned long)pTxTS;
193 pTxTS->TxAdmittedBARecord.Timer.function = TxBaInactTimeout;
195 ResetTxTsEntry(pTxTS);
196 list_add_tail(&pTxTS->TsCommonInfo.List, &ieee->Tx_TS_Unused_List);
200 // Initialize Rx TS related info.
201 INIT_LIST_HEAD(&ieee->Rx_TS_Admit_List);
202 INIT_LIST_HEAD(&ieee->Rx_TS_Pending_List);
203 INIT_LIST_HEAD(&ieee->Rx_TS_Unused_List);
204 for(count = 0; count < TOTAL_TS_NUM; count++)
207 INIT_LIST_HEAD(&pRxTS->RxPendingPktList);
209 init_timer(&pRxTS->TsCommonInfo.SetupTimer);
210 pRxTS->TsCommonInfo.SetupTimer.data = (unsigned long)pRxTS;
211 pRxTS->TsCommonInfo.SetupTimer.function = TsSetupTimeOut;
213 init_timer(&pRxTS->TsCommonInfo.InactTimer);
214 pRxTS->TsCommonInfo.InactTimer.data = (unsigned long)pRxTS;
215 pRxTS->TsCommonInfo.InactTimer.function = TsInactTimeout;
217 init_timer(&pRxTS->RxAdmittedBARecord.Timer);
218 pRxTS->RxAdmittedBARecord.Timer.data = (unsigned long)pRxTS;
219 pRxTS->RxAdmittedBARecord.Timer.function = RxBaInactTimeout;
221 init_timer(&pRxTS->RxPktPendingTimer);
222 pRxTS->RxPktPendingTimer.data = (unsigned long)pRxTS;
223 pRxTS->RxPktPendingTimer.function = RxPktPendingTimeout;
225 ResetRxTsEntry(pRxTS);
226 list_add_tail(&pRxTS->TsCommonInfo.List, &ieee->Rx_TS_Unused_List);
229 // Initialize unused Rx Reorder List.
230 INIT_LIST_HEAD(&ieee->RxReorder_Unused_List);
232 for(count = 0; count < REORDER_ENTRY_NUM; count++)
234 list_add_tail( &pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
235 if(count == (REORDER_ENTRY_NUM-1))
237 pRxReorderEntry = &ieee->RxReorderEntry[count+1];
243 void AdmitTS(struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 InactTime)
245 del_timer_sync(&pTsCommonInfo->SetupTimer);
246 del_timer_sync(&pTsCommonInfo->InactTimer);
249 mod_timer(&pTsCommonInfo->InactTimer, jiffies + MSECS(InactTime));
253 PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect)
255 //DIRECTION_VALUE dir;
257 bool search_dir[4] = {0, 0, 0, 0};
258 struct list_head* psearch_list; //FIXME
259 PTS_COMMON_INFO pRet = NULL;
260 if(ieee->iw_mode == IW_MODE_MASTER) //ap mode
262 if(TxRxSelect == TX_DIR)
264 search_dir[DIR_DOWN] = true;
265 search_dir[DIR_BI_DIR]= true;
269 search_dir[DIR_UP] = true;
270 search_dir[DIR_BI_DIR]= true;
273 else if(ieee->iw_mode == IW_MODE_ADHOC)
275 if(TxRxSelect == TX_DIR)
276 search_dir[DIR_UP] = true;
278 search_dir[DIR_DOWN] = true;
282 if(TxRxSelect == TX_DIR)
284 search_dir[DIR_UP] = true;
285 search_dir[DIR_BI_DIR]= true;
286 search_dir[DIR_DIRECT]= true;
290 search_dir[DIR_DOWN] = true;
291 search_dir[DIR_BI_DIR]= true;
292 search_dir[DIR_DIRECT]= true;
296 if(TxRxSelect == TX_DIR)
297 psearch_list = &ieee->Tx_TS_Admit_List;
299 psearch_list = &ieee->Rx_TS_Admit_List;
301 //for(dir = DIR_UP; dir <= DIR_BI_DIR; dir++)
302 for(dir = 0; dir <= DIR_BI_DIR; dir++)
304 if(search_dir[dir] ==false )
306 list_for_each_entry(pRet, psearch_list, List){
307 // 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);
308 if (memcmp(pRet->Addr, Addr, 6) == 0)
309 if (pRet->TSpec.f.TSInfo.field.ucTSID == TID)
310 if(pRet->TSpec.f.TSInfo.field.ucDirection == dir)
312 // printk("Bingo! got it\n");
317 if(&pRet->List != psearch_list)
321 if(&pRet->List != psearch_list){
329 PTS_COMMON_INFO pTsCommonInfo,
339 if(pTsCommonInfo == NULL)
342 memcpy(pTsCommonInfo->Addr, Addr, 6);
345 memcpy((u8*)(&(pTsCommonInfo->TSpec)), (u8*)pTSPEC, sizeof(TSPEC_BODY));
347 for(count = 0; count < TCLAS_Num; count++)
348 memcpy((u8*)(&(pTsCommonInfo->TClass[count])), (u8*)pTCLAS, sizeof(QOS_TCLAS));
350 pTsCommonInfo->TClasProc = TCLAS_Proc;
351 pTsCommonInfo->TClasNum = TCLAS_Num;
356 struct ieee80211_device* ieee,
357 PTS_COMMON_INFO *ppTS,
360 TR_SELECT TxRxSelect, //Rx:1, Tx:0
366 // We do not build any TS for Broadcast or Multicast stream.
367 // So reject these kinds of search here.
369 if(is_broadcast_ether_addr(Addr) || is_multicast_ether_addr(Addr))
371 IEEE80211_DEBUG(IEEE80211_DL_ERR, "get TS for Broadcast or Multicast\n");
375 if(ieee->pStaQos->CurrentQosMode == QOS_DISABLE)
376 { UP = 0; } //only use one TS
377 else if(ieee->pStaQos->CurrentQosMode & QOS_WMM)
380 if (ieee->current_network.qos_data.supported == 0)
385 // In WMM case: we use 4 TID only
388 IEEE80211_DEBUG(IEEE80211_DL_ERR, " in %s(), TID(%d) is not valid\n", __FUNCTION__, TID);
416 *ppTS = SearchAdmitTRStream(
427 if(bAddNewTs == false)
429 IEEE80211_DEBUG(IEEE80211_DL_TS, "add new TS failed(tid:%d)\n", UP);
435 // Create a new Traffic stream for current Tx/Rx
436 // This is for EDCA and WMM to add a new TS.
437 // For HCCA or WMMSA, TS cannot be addmit without negotiation.
440 PQOS_TSINFO pTSInfo = &TSpec.f.TSInfo;
441 struct list_head* pUnusedList =
442 (TxRxSelect == TX_DIR)?
443 (&ieee->Tx_TS_Unused_List):
444 (&ieee->Rx_TS_Unused_List);
446 struct list_head* pAddmitList =
447 (TxRxSelect == TX_DIR)?
448 (&ieee->Tx_TS_Admit_List):
449 (&ieee->Rx_TS_Admit_List);
451 DIRECTION_VALUE Dir = (ieee->iw_mode == IW_MODE_MASTER)?
452 ((TxRxSelect==TX_DIR)?DIR_DOWN:DIR_UP):
453 ((TxRxSelect==TX_DIR)?DIR_UP:DIR_DOWN);
454 IEEE80211_DEBUG(IEEE80211_DL_TS, "to add Ts\n");
455 if(!list_empty(pUnusedList))
457 (*ppTS) = list_entry(pUnusedList->next, TS_COMMON_INFO, List);
458 list_del_init(&(*ppTS)->List);
459 if(TxRxSelect==TX_DIR)
461 PTX_TS_RECORD tmp = container_of(*ppTS, TX_TS_RECORD, TsCommonInfo);
465 PRX_TS_RECORD tmp = container_of(*ppTS, RX_TS_RECORD, TsCommonInfo);
469 IEEE80211_DEBUG(IEEE80211_DL_TS, "to init current TS, UP:%d, Dir:%d, addr:%pM\n", UP, Dir, Addr);
470 // Prepare TS Info releated field
471 pTSInfo->field.ucTrafficType = 0; // Traffic type: WMM is reserved in this field
472 pTSInfo->field.ucTSID = UP; // TSID
473 pTSInfo->field.ucDirection = Dir; // Direction: if there is DirectLink, this need additional consideration.
474 pTSInfo->field.ucAccessPolicy = 1; // Access policy
475 pTSInfo->field.ucAggregation = 0; // Aggregation
476 pTSInfo->field.ucPSB = 0; // Aggregation
477 pTSInfo->field.ucUP = UP; // User priority
478 pTSInfo->field.ucTSInfoAckPolicy = 0; // Ack policy
479 pTSInfo->field.ucSchedule = 0; // Schedule
481 MakeTSEntry(*ppTS, Addr, &TSpec, NULL, 0, 0);
482 AdmitTS(ieee, *ppTS, 0);
483 list_add_tail(&((*ppTS)->List), pAddmitList);
484 // if there is DirectLink, we need to do additional operation here!!
490 IEEE80211_DEBUG(IEEE80211_DL_ERR, "in function %s() There is not enough TS record to be used!!", __FUNCTION__);
498 struct ieee80211_device* ieee,
504 unsigned long flags = 0;
505 del_timer_sync(&pTs->SetupTimer);
506 del_timer_sync(&pTs->InactTimer);
507 TsInitDelBA(ieee, pTs, TxRxSelect);
509 if(TxRxSelect == RX_DIR)
512 PRX_REORDER_ENTRY pRxReorderEntry;
513 PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs;
514 if(timer_pending(&pRxTS->RxPktPendingTimer))
515 del_timer_sync(&pRxTS->RxPktPendingTimer);
517 while(!list_empty(&pRxTS->RxPendingPktList))
519 // PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
520 spin_lock_irqsave(&(ieee->reorder_spinlock), flags);
521 //pRxReorderEntry = list_entry(&pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
522 pRxReorderEntry = (PRX_REORDER_ENTRY)list_entry(pRxTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
523 list_del_init(&pRxReorderEntry->List);
526 struct ieee80211_rxb * prxb = pRxReorderEntry->prxb;
529 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
532 for(i =0; i < prxb->nr_subframes; i++) {
533 dev_kfree_skb(prxb->subframes[i]);
538 list_add_tail(&pRxReorderEntry->List,&ieee->RxReorder_Unused_List);
539 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
540 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
547 PTX_TS_RECORD pTxTS = (PTX_TS_RECORD)pTs;
548 del_timer_sync(&pTxTS->TsAddBaTimer);
552 void RemovePeerTS(struct ieee80211_device* ieee, u8* Addr)
554 PTS_COMMON_INFO pTS, pTmpTS;
555 printk("===========>RemovePeerTS,%pM\n", Addr);
557 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
559 if (memcmp(pTS->Addr, Addr, 6) == 0)
561 RemoveTsEntry(ieee, pTS, TX_DIR);
562 list_del_init(&pTS->List);
563 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
567 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
569 if (memcmp(pTS->Addr, Addr, 6) == 0)
571 printk("====>remove Tx_TS_admin_list\n");
572 RemoveTsEntry(ieee, pTS, TX_DIR);
573 list_del_init(&pTS->List);
574 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
578 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
580 if (memcmp(pTS->Addr, Addr, 6) == 0)
582 RemoveTsEntry(ieee, pTS, RX_DIR);
583 list_del_init(&pTS->List);
584 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
588 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
590 if (memcmp(pTS->Addr, Addr, 6) == 0)
592 RemoveTsEntry(ieee, pTS, RX_DIR);
593 list_del_init(&pTS->List);
594 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
600 void RemoveAllTS(struct ieee80211_device* ieee)
602 PTS_COMMON_INFO pTS, pTmpTS;
604 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List)
606 RemoveTsEntry(ieee, pTS, TX_DIR);
607 list_del_init(&pTS->List);
608 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
611 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Admit_List, List)
613 RemoveTsEntry(ieee, pTS, TX_DIR);
614 list_del_init(&pTS->List);
615 list_add_tail(&pTS->List, &ieee->Tx_TS_Unused_List);
618 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Pending_List, List)
620 RemoveTsEntry(ieee, pTS, RX_DIR);
621 list_del_init(&pTS->List);
622 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
625 list_for_each_entry_safe(pTS, pTmpTS, &ieee->Rx_TS_Admit_List, List)
627 RemoveTsEntry(ieee, pTS, RX_DIR);
628 list_del_init(&pTS->List);
629 list_add_tail(&pTS->List, &ieee->Rx_TS_Unused_List);
634 void TsStartAddBaProcess(struct ieee80211_device* ieee, PTX_TS_RECORD pTxTS)
636 if(pTxTS->bAddBaReqInProgress == false)
638 pTxTS->bAddBaReqInProgress = true;
640 if(pTxTS->bAddBaReqDelayed)
642 IEEE80211_DEBUG(IEEE80211_DL_BA, "TsStartAddBaProcess(): Delayed Start ADDBA after 60 sec!!\n");
643 mod_timer(&pTxTS->TsAddBaTimer, jiffies + MSECS(TS_ADDBA_DELAY));
647 IEEE80211_DEBUG(IEEE80211_DL_BA,"TsStartAddBaProcess(): Immediately Start ADDBA now!!\n");
648 mod_timer(&pTxTS->TsAddBaTimer, jiffies+10); //set 10 ticks
653 IEEE80211_DEBUG(IEEE80211_DL_ERR, "%s()==>BA timer is already added\n", __FUNCTION__);
655 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
656 EXPORT_SYMBOL_NOVERS(RemovePeerTS);
658 //EXPORT_SYMBOL(RemovePeerTS);