Merge branch 'acpi-pad' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux...
[sfrench/cifs-2.6.git] / drivers / staging / rtl8192su / ieee80211 / rtl819x_BAProc.c
1 /********************************************************************************************************************************
2  * This file is created to process BA Action Frame. According to 802.11 spec, there are 3 BA action types at all. And as BA is
3  * related to TS, this part need some struture defined in QOS side code. Also TX RX is going to be resturctured, so how to send
4  * ADDBAREQ ADDBARSP and DELBA packet is still on consideration. Temporarily use MANAGE QUEUE instead of Normal Queue.
5  * WB 2008-05-27
6  * *****************************************************************************************************************************/
7 #include "ieee80211.h"
8 #include "rtl819x_BA.h"
9
10 /********************************************************************************************************************
11  *function:  Activate BA entry. And if Time is nozero, start timer.
12  *   input:  PBA_RECORD                 pBA  //BA entry to be enabled
13  *           u16                        Time //indicate time delay.
14  *  output:  none
15 ********************************************************************************************************************/
16 void ActivateBAEntry(struct ieee80211_device* ieee, PBA_RECORD pBA, u16 Time)
17 {
18         pBA->bValid = true;
19         if(Time != 0)
20                 mod_timer(&pBA->Timer, jiffies + MSECS(Time));
21 }
22
23 /********************************************************************************************************************
24  *function:  deactivate BA entry, including its timer.
25  *   input:  PBA_RECORD                 pBA  //BA entry to be disabled
26  *  output:  none
27 ********************************************************************************************************************/
28 void DeActivateBAEntry( struct ieee80211_device* ieee, PBA_RECORD pBA)
29 {
30         pBA->bValid = false;
31         del_timer_sync(&pBA->Timer);
32 }
33 /********************************************************************************************************************
34  *function: deactivete BA entry in Tx Ts, and send DELBA.
35  *   input:
36  *           PTX_TS_RECORD              pTxTs //Tx Ts which is to deactivate BA entry.
37  *  output:  none
38  *  notice:  As PTX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME
39 ********************************************************************************************************************/
40 u8 TxTsDeleteBA( struct ieee80211_device* ieee, PTX_TS_RECORD   pTxTs)
41 {
42         PBA_RECORD              pAdmittedBa = &pTxTs->TxAdmittedBARecord;  //These two BA entries must exist in TS structure
43         PBA_RECORD              pPendingBa = &pTxTs->TxPendingBARecord;
44         u8                      bSendDELBA = false;
45
46         // Delete pending BA
47         if(pPendingBa->bValid)
48         {
49                 DeActivateBAEntry(ieee, pPendingBa);
50                 bSendDELBA = true;
51         }
52
53         // Delete admitted BA
54         if(pAdmittedBa->bValid)
55         {
56                 DeActivateBAEntry(ieee, pAdmittedBa);
57                 bSendDELBA = true;
58         }
59
60         return bSendDELBA;
61 }
62
63 /********************************************************************************************************************
64  *function: deactivete BA entry in Tx Ts, and send DELBA.
65  *   input:
66  *           PRX_TS_RECORD              pRxTs //Rx Ts which is to deactivate BA entry.
67  *  output:  none
68  *  notice:  As PRX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME, same with above
69 ********************************************************************************************************************/
70 u8 RxTsDeleteBA( struct ieee80211_device* ieee, PRX_TS_RECORD   pRxTs)
71 {
72         PBA_RECORD              pBa = &pRxTs->RxAdmittedBARecord;
73         u8                      bSendDELBA = false;
74
75         if(pBa->bValid)
76         {
77                 DeActivateBAEntry(ieee, pBa);
78                 bSendDELBA = true;
79         }
80
81         return bSendDELBA;
82 }
83
84 /********************************************************************************************************************
85  *function: reset BA entry
86  *   input:
87  *           PBA_RECORD         pBA //entry to be reset
88  *  output:  none
89 ********************************************************************************************************************/
90 void ResetBaEntry( PBA_RECORD pBA)
91 {
92         pBA->bValid                     = false;
93         pBA->BaParamSet.shortData       = 0;
94         pBA->BaTimeoutValue             = 0;
95         pBA->DialogToken                = 0;
96         pBA->BaStartSeqCtrl.ShortData   = 0;
97 }
98 //These functions need porting here or not?
99 /*******************************************************************************************************************************
100  *function:  construct ADDBAREQ and ADDBARSP frame here together.
101  *   input:  u8*                Dst     //ADDBA frame's destination
102  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA.
103  *           u16                StatusCode  //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?)
104  *           u8                 type    //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ)
105  *  output:  none
106  *  return:  sk_buff*           skb     //return constructed skb to xmit
107 *******************************************************************************************************************************/
108 static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, PBA_RECORD pBA, u16 StatusCode, u8 type)
109 {
110         struct sk_buff *skb = NULL;
111          struct ieee80211_hdr_3addr* BAReq = NULL;
112         u8* tag = NULL;
113         u16 tmp = 0;
114         u16 len = ieee->tx_headroom + 9;
115         //category(1) + action field(1) + Dialog Token(1) + BA Parameter Set(2) +  BA Timeout Value(2) +  BA Start SeqCtrl(2)(or StatusCode(2))
116         IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), frame(%d) sentd to:"MAC_FMT", ieee->dev:%p\n", __FUNCTION__, type, MAC_ARG(Dst), ieee->dev);
117         if (pBA == NULL||ieee == NULL)
118         {
119                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pBA(%p) is NULL or ieee(%p) is NULL\n", pBA, ieee);
120                 return NULL;
121         }
122         skb = dev_alloc_skb(len + sizeof( struct ieee80211_hdr_3addr)); //need to add something others? FIXME
123         if (skb == NULL)
124         {
125                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n");
126                 return NULL;
127         }
128
129         memset(skb->data, 0, sizeof( struct ieee80211_hdr_3addr));      //I wonder whether it's necessary. Apparently kernel will not do it when alloc a skb.
130         skb_reserve(skb, ieee->tx_headroom);
131
132         BAReq = ( struct ieee80211_hdr_3addr *) skb_put(skb,sizeof( struct ieee80211_hdr_3addr));
133
134         memcpy(BAReq->addr1, Dst, ETH_ALEN);
135         memcpy(BAReq->addr2, ieee->dev->dev_addr, ETH_ALEN);
136
137         memcpy(BAReq->addr3, ieee->current_network.bssid, ETH_ALEN);
138
139         BAReq->frame_ctl = cpu_to_le16(IEEE80211_STYPE_MANAGE_ACT); //action frame
140
141         //tag += sizeof( struct ieee80211_hdr_3addr); //move to action field
142         tag = (u8*)skb_put(skb, 9);
143         *tag ++= ACT_CAT_BA;
144         *tag ++= type;
145         // Dialog Token
146         *tag ++= pBA->DialogToken;
147
148         if (ACT_ADDBARSP == type)
149         {
150                 // Status Code
151                 printk("=====>to send ADDBARSP\n");
152                 tmp = cpu_to_le16(StatusCode);
153                 memcpy(tag, (u8*)&tmp, 2);
154                 tag += 2;
155         }
156         // BA Parameter Set
157         tmp = cpu_to_le16(pBA->BaParamSet.shortData);
158         memcpy(tag, (u8*)&tmp, 2);
159         tag += 2;
160         // BA Timeout Value
161         tmp = cpu_to_le16(pBA->BaTimeoutValue);
162         memcpy(tag, (u8*)&tmp, 2);
163         tag += 2;
164
165         if (ACT_ADDBAREQ == type)
166         {
167         // BA Start SeqCtrl
168                 memcpy(tag,(u8*)&(pBA->BaStartSeqCtrl), 2);
169                 tag += 2;
170         }
171
172         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
173         return skb;
174         //return NULL;
175 }
176
177 /********************************************************************************************************************
178  *function:  construct DELBA frame
179  *   input:  u8*                dst     //DELBA frame's destination
180  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
181  *           TR_SELECT          TxRxSelect  //TX RX direction
182  *           u16                ReasonCode  //status code.
183  *  output:  none
184  *  return:  sk_buff*           skb     //return constructed skb to xmit
185 ********************************************************************************************************************/
186 static struct sk_buff* ieee80211_DELBA(
187         struct ieee80211_device* ieee,
188         u8*                      dst,
189         PBA_RECORD               pBA,
190         TR_SELECT                TxRxSelect,
191         u16                      ReasonCode
192         )
193 {
194         DELBA_PARAM_SET DelbaParamSet;
195         struct sk_buff *skb = NULL;
196          struct ieee80211_hdr_3addr* Delba = NULL;
197         u8* tag = NULL;
198         u16 tmp = 0;
199         //len = head len + DELBA Parameter Set(2) + Reason Code(2)
200         u16 len = 6 + ieee->tx_headroom;
201
202         if (net_ratelimit())
203         IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), ReasonCode(%d) sentd to:"MAC_FMT"\n", __FUNCTION__, ReasonCode, MAC_ARG(dst));
204
205         memset(&DelbaParamSet, 0, 2);
206
207         DelbaParamSet.field.Initiator   = (TxRxSelect==TX_DIR)?1:0;
208         DelbaParamSet.field.TID = pBA->BaParamSet.field.TID;
209
210         skb = dev_alloc_skb(len + sizeof( struct ieee80211_hdr_3addr)); //need to add something others? FIXME
211         if (skb == NULL)
212         {
213                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n");
214                 return NULL;
215         }
216 //      memset(skb->data, 0, len+sizeof( struct ieee80211_hdr_3addr));
217         skb_reserve(skb, ieee->tx_headroom);
218
219         Delba = ( struct ieee80211_hdr_3addr *) skb_put(skb,sizeof( struct ieee80211_hdr_3addr));
220
221         memcpy(Delba->addr1, dst, ETH_ALEN);
222         memcpy(Delba->addr2, ieee->dev->dev_addr, ETH_ALEN);
223         memcpy(Delba->addr3, ieee->current_network.bssid, ETH_ALEN);
224         Delba->frame_ctl = cpu_to_le16(IEEE80211_STYPE_MANAGE_ACT); //action frame
225
226         tag = (u8*)skb_put(skb, 6);
227
228         *tag ++= ACT_CAT_BA;
229         *tag ++= ACT_DELBA;
230
231         // DELBA Parameter Set
232         tmp = cpu_to_le16(DelbaParamSet.shortData);
233         memcpy(tag, (u8*)&tmp, 2);
234         tag += 2;
235         // Reason Code
236         tmp = cpu_to_le16(ReasonCode);
237         memcpy(tag, (u8*)&tmp, 2);
238         tag += 2;
239
240         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
241         if (net_ratelimit())
242         IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "<=====%s()\n", __FUNCTION__);
243         return skb;
244 }
245
246 /********************************************************************************************************************
247  *function: send ADDBAReq frame out
248  *   input:  u8*                dst     //ADDBAReq frame's destination
249  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
250  *  output:  none
251  *  notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
252 ********************************************************************************************************************/
253 void ieee80211_send_ADDBAReq(struct ieee80211_device* ieee, u8* dst, PBA_RECORD pBA)
254 {
255         struct sk_buff *skb = NULL;
256         skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero.
257
258         if (skb)
259         {
260                 softmac_mgmt_xmit(skb, ieee);
261                 //add statistic needed here.
262                 //and skb will be freed in softmac_mgmt_xmit(), so omit all dev_kfree_skb_any() outside softmac_mgmt_xmit()
263                 //WB
264         }
265         else
266         {
267                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __FUNCTION__);
268         }
269         return;
270 }
271
272 /********************************************************************************************************************
273  *function: send ADDBARSP frame out
274  *   input:  u8*                dst     //DELBA frame's destination
275  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
276  *           u16                StatusCode //RSP StatusCode
277  *  output:  none
278  *  notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
279 ********************************************************************************************************************/
280 void ieee80211_send_ADDBARsp(struct ieee80211_device* ieee, u8* dst, PBA_RECORD pBA, u16 StatusCode)
281 {
282         struct sk_buff *skb = NULL;
283         skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames
284         if (skb)
285         {
286                 softmac_mgmt_xmit(skb, ieee);
287                 //same above
288         }
289         else
290         {
291                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __FUNCTION__);
292         }
293
294         return;
295
296 }
297 /********************************************************************************************************************
298  *function: send ADDBARSP frame out
299  *   input:  u8*                dst     //DELBA frame's destination
300  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
301  *           TR_SELECT          TxRxSelect //TX or RX
302  *           u16                ReasonCode //DEL ReasonCode
303  *  output:  none
304  *  notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
305 ********************************************************************************************************************/
306
307 void ieee80211_send_DELBA(struct ieee80211_device* ieee, u8* dst, PBA_RECORD pBA, TR_SELECT TxRxSelect, u16 ReasonCode)
308 {
309         struct sk_buff *skb = NULL;
310         skb = ieee80211_DELBA(ieee, dst, pBA, TxRxSelect, ReasonCode); //construct ACT_ADDBARSP frames
311         if (skb)
312         {
313                 softmac_mgmt_xmit(skb, ieee);
314                 //same above
315         }
316         else
317         {
318                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __FUNCTION__);
319         }
320         return ;
321 }
322
323 /********************************************************************************************************************
324  *function: RX ADDBAReq
325  *   input:  struct sk_buff *   skb     //incoming ADDBAReq skb.
326  *  return:  0(pass), other(fail)
327  *  notice:  As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
328 ********************************************************************************************************************/
329 int ieee80211_rx_ADDBAReq( struct ieee80211_device* ieee, struct sk_buff *skb)
330 {
331          struct ieee80211_hdr_3addr* req = NULL;
332         u16 rc = 0;
333         u8 * dst = NULL, *pDialogToken = NULL, *tag = NULL;
334         PBA_RECORD pBA = NULL;
335         PBA_PARAM_SET   pBaParamSet = NULL;
336         u16* pBaTimeoutVal = NULL;
337         PSEQUENCE_CONTROL pBaStartSeqCtrl = NULL;
338         PRX_TS_RECORD   pTS = NULL;
339
340         if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9)
341         {
342                 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BAREQ(%d / %ld)\n", skb->len,    (sizeof( struct ieee80211_hdr_3addr) + 9));
343                 return -1;
344         }
345
346         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
347
348         req = ( struct ieee80211_hdr_3addr*) skb->data;
349         tag = (u8*)req;
350         dst = (u8*)(&req->addr2[0]);
351         tag += sizeof( struct ieee80211_hdr_3addr);
352         pDialogToken = tag + 2;  //category+action
353         pBaParamSet = (PBA_PARAM_SET)(tag + 3);   //+DialogToken
354         pBaTimeoutVal = (u16*)(tag + 5);
355         pBaStartSeqCtrl = (PSEQUENCE_CONTROL)(req + 7);
356
357         printk("====================>rx ADDBAREQ from :"MAC_FMT"\n", MAC_ARG(dst));
358 //some other capability is not ready now.
359         if(     (ieee->current_network.qos_data.active == 0) ||
360                 (ieee->pHTInfo->bCurrentHTSupport == false) ||
361                 (ieee->pHTInfo->IOTAction & HT_IOT_ACT_REJECT_ADDBA_REQ)) //||
362         //      (ieee->pStaQos->bEnableRxImmBA == false)        )
363         {
364                 rc = ADDBA_STATUS_REFUSED;
365                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "Failed to reply on ADDBA_REQ as some capability is not ready(%d, %d)\n", ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport);
366                 goto OnADDBAReq_Fail;
367         }
368         // Search for related traffic stream.
369         // If there is no matched TS, reject the ADDBA request.
370         if(     !GetTs(
371                         ieee,
372                         (PTS_COMMON_INFO*)(&pTS),
373                         dst,
374                         (u8)(pBaParamSet->field.TID),
375                         RX_DIR,
376                         true)   )
377         {
378                 rc = ADDBA_STATUS_REFUSED;
379                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __FUNCTION__);
380                 goto OnADDBAReq_Fail;
381         }
382         pBA = &pTS->RxAdmittedBARecord;
383         // To Determine the ADDBA Req content
384         // We can do much more check here, including BufferSize, AMSDU_Support, Policy, StartSeqCtrl...
385         // I want to check StartSeqCtrl to make sure when we start aggregation!!!
386         //
387         if(pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED)
388         {
389                 rc = ADDBA_STATUS_INVALID_PARAM;
390                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __FUNCTION__);
391                 goto OnADDBAReq_Fail;
392         }
393                 // Admit the ADDBA Request
394         //
395         DeActivateBAEntry(ieee, pBA);
396         pBA->DialogToken = *pDialogToken;
397         pBA->BaParamSet = *pBaParamSet;
398         pBA->BaTimeoutValue = *pBaTimeoutVal;
399         pBA->BaStartSeqCtrl = *pBaStartSeqCtrl;
400         //for half N mode we only aggregate 1 frame
401         if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)||
402         (ieee->pHTInfo->IOTAction & HT_IOT_ACT_ALLOW_PEER_AGG_ONE_PKT))
403         pBA->BaParamSet.field.BufferSize = 1;
404         else
405         pBA->BaParamSet.field.BufferSize = 32;
406         ActivateBAEntry(ieee, pBA, 0);//pBA->BaTimeoutValue);
407         ieee80211_send_ADDBARsp(ieee, dst, pBA, ADDBA_STATUS_SUCCESS);
408
409         // End of procedure.
410         return 0;
411
412 OnADDBAReq_Fail:
413         {
414                 BA_RECORD       BA;
415                 BA.BaParamSet = *pBaParamSet;
416                 BA.BaTimeoutValue = *pBaTimeoutVal;
417                 BA.DialogToken = *pDialogToken;
418                 BA.BaParamSet.field.BAPolicy = BA_POLICY_IMMEDIATE;
419                 ieee80211_send_ADDBARsp(ieee, dst, &BA, rc);
420                 return 0; //we send RSP out.
421         }
422
423 }
424
425 /********************************************************************************************************************
426  *function: RX ADDBARSP
427  *   input:  struct sk_buff *   skb     //incoming ADDBAReq skb.
428  *  return:  0(pass), other(fail)
429  *  notice:  As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
430 ********************************************************************************************************************/
431 int ieee80211_rx_ADDBARsp( struct ieee80211_device* ieee, struct sk_buff *skb)
432 {
433          struct ieee80211_hdr_3addr* rsp = NULL;
434         PBA_RECORD              pPendingBA, pAdmittedBA;
435         PTX_TS_RECORD           pTS = NULL;
436         u8* dst = NULL, *pDialogToken = NULL, *tag = NULL;
437         u16* pStatusCode = NULL, *pBaTimeoutVal = NULL;
438         PBA_PARAM_SET           pBaParamSet = NULL;
439         u16                     ReasonCode;
440
441         if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9)
442         {
443                 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BARSP(%d / %ld)\n", skb->len,    (sizeof( struct ieee80211_hdr_3addr) + 9));
444                 return -1;
445         }
446         rsp = ( struct ieee80211_hdr_3addr*)skb->data;
447         tag = (u8*)rsp;
448         dst = (u8*)(&rsp->addr2[0]);
449         tag += sizeof( struct ieee80211_hdr_3addr);
450         pDialogToken = tag + 2;
451         pStatusCode = (u16*)(tag + 3);
452         pBaParamSet = (PBA_PARAM_SET)(tag + 5);
453         pBaTimeoutVal = (u16*)(tag + 7);
454
455         // Check the capability
456         // Since we can always receive A-MPDU, we just check if it is under HT mode.
457         if(     ieee->current_network.qos_data.active == 0  ||
458                 ieee->pHTInfo->bCurrentHTSupport == false ||
459                 ieee->pHTInfo->bCurrentAMPDUEnable == false )
460         {
461                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "reject to ADDBA_RSP as some capability is not ready(%d, %d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport, ieee->pHTInfo->bCurrentAMPDUEnable);
462                 ReasonCode = DELBA_REASON_UNKNOWN_BA;
463                 goto OnADDBARsp_Reject;
464         }
465
466
467         //
468         // Search for related TS.
469         // If there is no TS found, we wil reject ADDBA Rsp by sending DELBA frame.
470         //
471         if (!GetTs(
472                         ieee,
473                         (PTS_COMMON_INFO*)(&pTS),
474                         dst,
475                         (u8)(pBaParamSet->field.TID),
476                         TX_DIR,
477                         false)  )
478         {
479                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __FUNCTION__);
480                 ReasonCode = DELBA_REASON_UNKNOWN_BA;
481                 goto OnADDBARsp_Reject;
482         }
483
484         pTS->bAddBaReqInProgress = false;
485         pPendingBA = &pTS->TxPendingBARecord;
486         pAdmittedBA = &pTS->TxAdmittedBARecord;
487
488
489         //
490         // Check if related BA is waiting for setup.
491         // If not, reject by sending DELBA frame.
492         //
493         if((pAdmittedBA->bValid==true))
494         {
495                 // Since BA is already setup, we ignore all other ADDBA Response.
496                 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n");
497                 return -1;
498         }
499         else if((pPendingBA->bValid == false) ||(*pDialogToken != pPendingBA->DialogToken))
500         {
501                 IEEE80211_DEBUG(IEEE80211_DL_ERR,  "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n");
502                 ReasonCode = DELBA_REASON_UNKNOWN_BA;
503                 goto OnADDBARsp_Reject;
504         }
505         else
506         {
507                 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. BA is admitted! Status code:%X\n", *pStatusCode);
508                 DeActivateBAEntry(ieee, pPendingBA);
509         }
510
511
512         if(*pStatusCode == ADDBA_STATUS_SUCCESS)
513         {
514                 //
515                 // Determine ADDBA Rsp content here.
516                 // We can compare the value of BA parameter set that Peer returned and Self sent.
517                 // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism.
518                 //
519                 if(pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED)
520                 {
521                         // Since this is a kind of ADDBA failed, we delay next ADDBA process.
522                         pTS->bAddBaReqDelayed = true;
523                         DeActivateBAEntry(ieee, pAdmittedBA);
524                         ReasonCode = DELBA_REASON_END_BA;
525                         goto OnADDBARsp_Reject;
526                 }
527
528
529                 //
530                 // Admitted condition
531                 //
532                 pAdmittedBA->DialogToken = *pDialogToken;
533                 pAdmittedBA->BaTimeoutValue = *pBaTimeoutVal;
534                 pAdmittedBA->BaStartSeqCtrl = pPendingBA->BaStartSeqCtrl;
535                 pAdmittedBA->BaParamSet = *pBaParamSet;
536                 DeActivateBAEntry(ieee, pAdmittedBA);
537                 ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal);
538         }
539         else
540         {
541                 // Delay next ADDBA process.
542                 pTS->bAddBaReqDelayed = true;
543         }
544
545         // End of procedure
546         return 0;
547
548 OnADDBARsp_Reject:
549         {
550                 BA_RECORD       BA;
551                 BA.BaParamSet = *pBaParamSet;
552                 ieee80211_send_DELBA(ieee, dst, &BA, TX_DIR, ReasonCode);
553                 return 0;
554         }
555
556 }
557
558 /********************************************************************************************************************
559  *function: RX DELBA
560  *   input:  struct sk_buff *   skb     //incoming ADDBAReq skb.
561  *  return:  0(pass), other(fail)
562  *  notice:  As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
563 ********************************************************************************************************************/
564 int ieee80211_rx_DELBA(struct ieee80211_device* ieee,struct sk_buff *skb)
565 {
566          struct ieee80211_hdr_3addr* delba = NULL;
567         PDELBA_PARAM_SET        pDelBaParamSet = NULL;
568         u16*                    pReasonCode = NULL;
569         u8*                     dst = NULL;
570
571         if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 6)
572         {
573                 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in DELBA(%d / %ld)\n", skb->len,    (sizeof( struct ieee80211_hdr_3addr) + 6));
574                 return -1;
575         }
576
577         if(ieee->current_network.qos_data.active == 0 ||
578                 ieee->pHTInfo->bCurrentHTSupport == false )
579         {
580                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "received DELBA while QOS or HT is not supported(%d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport);
581                 return -1;
582         }
583
584         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
585         delba = ( struct ieee80211_hdr_3addr*)skb->data;
586         dst = (u8*)(&delba->addr2[0]);
587         delba += sizeof( struct ieee80211_hdr_3addr);
588         pDelBaParamSet = (PDELBA_PARAM_SET)(delba+2);
589         pReasonCode = (u16*)(delba+4);
590
591         if(pDelBaParamSet->field.Initiator == 1)
592         {
593                 PRX_TS_RECORD   pRxTs;
594
595                 if( !GetTs(
596                                 ieee,
597                                 (PTS_COMMON_INFO*)&pRxTs,
598                                 dst,
599                                 (u8)pDelBaParamSet->field.TID,
600                                 RX_DIR,
601                                 false)  )
602                 {
603                         IEEE80211_DEBUG(IEEE80211_DL_ERR,  "can't get TS for RXTS in %s()\n", __FUNCTION__);
604                         return -1;
605                 }
606
607                 RxTsDeleteBA(ieee, pRxTs);
608         }
609         else
610         {
611                 PTX_TS_RECORD   pTxTs;
612
613                 if(!GetTs(
614                         ieee,
615                         (PTS_COMMON_INFO*)&pTxTs,
616                         dst,
617                         (u8)pDelBaParamSet->field.TID,
618                         TX_DIR,
619                         false)  )
620                 {
621                         IEEE80211_DEBUG(IEEE80211_DL_ERR,  "can't get TS for TXTS in %s()\n", __FUNCTION__);
622                         return -1;
623                 }
624
625                 pTxTs->bUsingBa = false;
626                 pTxTs->bAddBaReqInProgress = false;
627                 pTxTs->bAddBaReqDelayed = false;
628                 del_timer_sync(&pTxTs->TsAddBaTimer);
629                 //PlatformCancelTimer(Adapter, &pTxTs->TsAddBaTimer);
630                 TxTsDeleteBA(ieee, pTxTs);
631         }
632         return 0;
633 }
634
635 //
636 // ADDBA initiate. This can only be called by TX side.
637 //
638 void
639 TsInitAddBA(
640         struct ieee80211_device* ieee,
641         PTX_TS_RECORD   pTS,
642         u8              Policy,
643         u8              bOverwritePending
644         )
645 {
646         PBA_RECORD                      pBA = &pTS->TxPendingBARecord;
647
648         if(pBA->bValid==true && bOverwritePending==false)
649                 return;
650
651         // Set parameters to "Pending" variable set
652         DeActivateBAEntry(ieee, pBA);
653
654         pBA->DialogToken++;                                             // DialogToken: Only keep the latest dialog token
655         pBA->BaParamSet.field.AMSDU_Support = 0;        // Do not support A-MSDU with A-MPDU now!!
656         pBA->BaParamSet.field.BAPolicy = Policy;        // Policy: Delayed or Immediate
657         pBA->BaParamSet.field.TID = pTS->TsCommonInfo.TSpec.f.TSInfo.field.ucTSID;      // TID
658         // BufferSize: This need to be set according to A-MPDU vector
659         pBA->BaParamSet.field.BufferSize = 32;          // BufferSize: This need to be set according to A-MPDU vector
660         pBA->BaTimeoutValue = 0;                                        // Timeout value: Set 0 to disable Timer
661         pBA->BaStartSeqCtrl.field.SeqNum = (pTS->TxCurSeq + 3) % 4096;  // Block Ack will start after 3 packets later.
662
663         ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT);
664
665         ieee80211_send_ADDBAReq(ieee, pTS->TsCommonInfo.Addr, pBA);
666 }
667
668 void
669 TsInitDelBA( struct ieee80211_device* ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect)
670 {
671
672         if(TxRxSelect == TX_DIR)
673         {
674                 PTX_TS_RECORD   pTxTs = (PTX_TS_RECORD)pTsCommonInfo;
675
676                 if(TxTsDeleteBA(ieee, pTxTs))
677                         ieee80211_send_DELBA(
678                                 ieee,
679                                 pTsCommonInfo->Addr,
680                                 (pTxTs->TxAdmittedBARecord.bValid)?(&pTxTs->TxAdmittedBARecord):(&pTxTs->TxPendingBARecord),
681                                 TxRxSelect,
682                                 DELBA_REASON_END_BA);
683         }
684         else if(TxRxSelect == RX_DIR)
685         {
686                 PRX_TS_RECORD   pRxTs = (PRX_TS_RECORD)pTsCommonInfo;
687                 if(RxTsDeleteBA(ieee, pRxTs))
688                         ieee80211_send_DELBA(
689                                 ieee,
690                                 pTsCommonInfo->Addr,
691                                 &pRxTs->RxAdmittedBARecord,
692                                 TxRxSelect,
693                                 DELBA_REASON_END_BA     );
694         }
695 }
696 /********************************************************************************************************************
697  *function:  BA setup timer
698  *   input:  unsigned long       data           //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
699  *  return:  NULL
700  *  notice:
701 ********************************************************************************************************************/
702 void BaSetupTimeOut(unsigned long data)
703 {
704         PTX_TS_RECORD   pTxTs = (PTX_TS_RECORD)data;
705
706         pTxTs->bAddBaReqInProgress = false;
707         pTxTs->bAddBaReqDelayed = true;
708         pTxTs->TxPendingBARecord.bValid = false;
709 }
710
711 void TxBaInactTimeout(unsigned long data)
712 {
713         PTX_TS_RECORD   pTxTs = (PTX_TS_RECORD)data;
714         struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[pTxTs->num]);
715         TxTsDeleteBA(ieee, pTxTs);
716         ieee80211_send_DELBA(
717                 ieee,
718                 pTxTs->TsCommonInfo.Addr,
719                 &pTxTs->TxAdmittedBARecord,
720                 TX_DIR,
721                 DELBA_REASON_TIMEOUT);
722 }
723
724 void RxBaInactTimeout(unsigned long data)
725 {
726         PRX_TS_RECORD   pRxTs = (PRX_TS_RECORD)data;
727         struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
728
729         RxTsDeleteBA(ieee, pRxTs);
730         ieee80211_send_DELBA(
731                 ieee,
732                 pRxTs->TsCommonInfo.Addr,
733                 &pRxTs->RxAdmittedBARecord,
734                 RX_DIR,
735                 DELBA_REASON_TIMEOUT);
736         return ;
737 }
738