drivers: staging: rtl8192u: Fix "space prohibited after that open parenthesis '(...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / rtl8192u / 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 structure 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 static 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 static 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 static 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 static 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:%pM, ieee->dev:%p\n", __func__, type, 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 /********************************************************************************************************************
179  *function:  construct DELBA frame
180  *   input:  u8*                dst     //DELBA frame's destination
181  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
182  *           TR_SELECT          TxRxSelect  //TX RX direction
183  *           u16                ReasonCode  //status code.
184  *  output:  none
185  *  return:  sk_buff*           skb     //return constructed skb to xmit
186 ********************************************************************************************************************/
187 static struct sk_buff *ieee80211_DELBA(
188         struct ieee80211_device  *ieee,
189         u8                       *dst,
190         PBA_RECORD               pBA,
191         TR_SELECT                TxRxSelect,
192         u16                      ReasonCode
193         )
194 {
195         DELBA_PARAM_SET DelbaParamSet;
196         struct sk_buff *skb = NULL;
197          struct ieee80211_hdr_3addr *Delba = NULL;
198         u8 *tag = NULL;
199         u16 tmp = 0;
200         //len = head len + DELBA Parameter Set(2) + Reason Code(2)
201         u16 len = 6 + ieee->tx_headroom;
202
203         if (net_ratelimit())
204         IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), ReasonCode(%d) sentd to:%pM\n", __func__, ReasonCode, dst);
205
206         memset(&DelbaParamSet, 0, 2);
207
208         DelbaParamSet.field.Initiator   = (TxRxSelect==TX_DIR)?1:0;
209         DelbaParamSet.field.TID = pBA->BaParamSet.field.TID;
210
211         skb = dev_alloc_skb(len + sizeof( struct ieee80211_hdr_3addr)); //need to add something others? FIXME
212         if (skb == NULL)
213         {
214                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n");
215                 return NULL;
216         }
217 //      memset(skb->data, 0, len+sizeof( struct ieee80211_hdr_3addr));
218         skb_reserve(skb, ieee->tx_headroom);
219
220         Delba = ( struct ieee80211_hdr_3addr *) skb_put(skb,sizeof( struct ieee80211_hdr_3addr));
221
222         memcpy(Delba->addr1, dst, ETH_ALEN);
223         memcpy(Delba->addr2, ieee->dev->dev_addr, ETH_ALEN);
224         memcpy(Delba->addr3, ieee->current_network.bssid, ETH_ALEN);
225         Delba->frame_ctl = cpu_to_le16(IEEE80211_STYPE_MANAGE_ACT); //action frame
226
227         tag = (u8 *)skb_put(skb, 6);
228
229         *tag ++= ACT_CAT_BA;
230         *tag ++= ACT_DELBA;
231
232         // DELBA Parameter Set
233         tmp = cpu_to_le16(DelbaParamSet.shortData);
234         memcpy(tag, (u8 *)&tmp, 2);
235         tag += 2;
236         // Reason Code
237         tmp = cpu_to_le16(ReasonCode);
238         memcpy(tag, (u8 *)&tmp, 2);
239         tag += 2;
240
241         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
242         if (net_ratelimit())
243         IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "<=====%s()\n", __func__);
244         return skb;
245 }
246
247 /********************************************************************************************************************
248  *function: send ADDBAReq frame out
249  *   input:  u8*                dst     //ADDBAReq frame's destination
250  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
251  *  output:  none
252  *  notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
253 ********************************************************************************************************************/
254 static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee,
255                                     u8 *dst, PBA_RECORD pBA)
256 {
257         struct sk_buff *skb = NULL;
258         skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero.
259
260         if (skb)
261         {
262                 softmac_mgmt_xmit(skb, ieee);
263                 //add statistic needed here.
264                 //and skb will be freed in softmac_mgmt_xmit(), so omit all dev_kfree_skb_any() outside softmac_mgmt_xmit()
265                 //WB
266         }
267         else
268         {
269                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__);
270         }
271         return;
272 }
273
274 /********************************************************************************************************************
275  *function: send ADDBARSP frame out
276  *   input:  u8*                dst     //DELBA frame's destination
277  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
278  *           u16                StatusCode //RSP StatusCode
279  *  output:  none
280  *  notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
281 ********************************************************************************************************************/
282 static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst,
283                                     PBA_RECORD pBA, u16 StatusCode)
284 {
285         struct sk_buff *skb = NULL;
286         skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames
287         if (skb)
288         {
289                 softmac_mgmt_xmit(skb, ieee);
290                 //same above
291         }
292         else
293         {
294                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__);
295         }
296
297         return;
298
299 }
300 /********************************************************************************************************************
301  *function: send ADDBARSP frame out
302  *   input:  u8*                dst     //DELBA frame's destination
303  *           PBA_RECORD         pBA     //BA_RECORD entry which stores the necessary information for BA
304  *           TR_SELECT          TxRxSelect //TX or RX
305  *           u16                ReasonCode //DEL ReasonCode
306  *  output:  none
307  *  notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
308 ********************************************************************************************************************/
309
310 static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst,
311                                  PBA_RECORD pBA, TR_SELECT TxRxSelect,
312                                  u16 ReasonCode)
313 {
314         struct sk_buff *skb = NULL;
315         skb = ieee80211_DELBA(ieee, dst, pBA, TxRxSelect, ReasonCode); //construct ACT_ADDBARSP frames
316         if (skb)
317         {
318                 softmac_mgmt_xmit(skb, ieee);
319                 //same above
320         }
321         else
322         {
323                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__);
324         }
325         return ;
326 }
327
328 /********************************************************************************************************************
329  *function: RX ADDBAReq
330  *   input:  struct sk_buff *   skb     //incoming ADDBAReq skb.
331  *  return:  0(pass), other(fail)
332  *  notice:  As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
333 ********************************************************************************************************************/
334 int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
335 {
336          struct ieee80211_hdr_3addr *req = NULL;
337         u16 rc = 0;
338         u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL;
339         PBA_RECORD pBA = NULL;
340         PBA_PARAM_SET   pBaParamSet = NULL;
341         u16 *pBaTimeoutVal = NULL;
342         PSEQUENCE_CONTROL pBaStartSeqCtrl = NULL;
343         PRX_TS_RECORD   pTS = NULL;
344
345         if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9)
346         {
347                 IEEE80211_DEBUG(IEEE80211_DL_ERR,
348                                 " Invalid skb len in BAREQ(%d / %zu)\n",
349                                 skb->len,
350                                 (sizeof(struct ieee80211_hdr_3addr) + 9));
351                 return -1;
352         }
353
354         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
355
356         req = (struct ieee80211_hdr_3addr *) skb->data;
357         tag = (u8 *)req;
358         dst = (u8 *)(&req->addr2[0]);
359         tag += sizeof(struct ieee80211_hdr_3addr);
360         pDialogToken = tag + 2;  //category+action
361         pBaParamSet = (PBA_PARAM_SET)(tag + 3);   //+DialogToken
362         pBaTimeoutVal = (u16 *)(tag + 5);
363         pBaStartSeqCtrl = (PSEQUENCE_CONTROL)(req + 7);
364
365         printk("====================>rx ADDBAREQ from :%pM\n", dst);
366 //some other capability is not ready now.
367         if(     (ieee->current_network.qos_data.active == 0) ||
368                 (ieee->pHTInfo->bCurrentHTSupport == false)) //||
369         //      (ieee->pStaQos->bEnableRxImmBA == false)        )
370         {
371                 rc = ADDBA_STATUS_REFUSED;
372                 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);
373                 goto OnADDBAReq_Fail;
374         }
375         // Search for related traffic stream.
376         // If there is no matched TS, reject the ADDBA request.
377         if(     !GetTs(
378                         ieee,
379                         (PTS_COMMON_INFO *)(&pTS),
380                         dst,
381                         (u8)(pBaParamSet->field.TID),
382                         RX_DIR,
383                         true)   )
384         {
385                 rc = ADDBA_STATUS_REFUSED;
386                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__);
387                 goto OnADDBAReq_Fail;
388         }
389         pBA = &pTS->RxAdmittedBARecord;
390         // To Determine the ADDBA Req content
391         // We can do much more check here, including BufferSize, AMSDU_Support, Policy, StartSeqCtrl...
392         // I want to check StartSeqCtrl to make sure when we start aggregation!!!
393         //
394         if(pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED)
395         {
396                 rc = ADDBA_STATUS_INVALID_PARAM;
397                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __func__);
398                 goto OnADDBAReq_Fail;
399         }
400                 // Admit the ADDBA Request
401         //
402         DeActivateBAEntry(ieee, pBA);
403         pBA->DialogToken = *pDialogToken;
404         pBA->BaParamSet = *pBaParamSet;
405         pBA->BaTimeoutValue = *pBaTimeoutVal;
406         pBA->BaStartSeqCtrl = *pBaStartSeqCtrl;
407         //for half N mode we only aggregate 1 frame
408         if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
409         pBA->BaParamSet.field.BufferSize = 1;
410         else
411         pBA->BaParamSet.field.BufferSize = 32;
412         ActivateBAEntry(ieee, pBA, pBA->BaTimeoutValue);
413         ieee80211_send_ADDBARsp(ieee, dst, pBA, ADDBA_STATUS_SUCCESS);
414
415         // End of procedure.
416         return 0;
417
418 OnADDBAReq_Fail:
419         {
420                 BA_RECORD       BA;
421                 BA.BaParamSet = *pBaParamSet;
422                 BA.BaTimeoutValue = *pBaTimeoutVal;
423                 BA.DialogToken = *pDialogToken;
424                 BA.BaParamSet.field.BAPolicy = BA_POLICY_IMMEDIATE;
425                 ieee80211_send_ADDBARsp(ieee, dst, &BA, rc);
426                 return 0; //we send RSP out.
427         }
428
429 }
430
431 /********************************************************************************************************************
432  *function: RX ADDBARSP
433  *   input:  struct sk_buff *   skb     //incoming ADDBAReq skb.
434  *  return:  0(pass), other(fail)
435  *  notice:  As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
436 ********************************************************************************************************************/
437 int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
438 {
439          struct ieee80211_hdr_3addr *rsp = NULL;
440         PBA_RECORD              pPendingBA, pAdmittedBA;
441         PTX_TS_RECORD           pTS = NULL;
442         u8 *dst = NULL, *pDialogToken = NULL, *tag = NULL;
443         u16 *pStatusCode = NULL, *pBaTimeoutVal = NULL;
444         PBA_PARAM_SET           pBaParamSet = NULL;
445         u16                     ReasonCode;
446
447         if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9)
448         {
449                 IEEE80211_DEBUG(IEEE80211_DL_ERR,
450                                 " Invalid skb len in BARSP(%d / %zu)\n",
451                                 skb->len,
452                                 (sizeof(struct ieee80211_hdr_3addr) + 9));
453                 return -1;
454         }
455         rsp = (struct ieee80211_hdr_3addr *)skb->data;
456         tag = (u8 *)rsp;
457         dst = (u8 *)(&rsp->addr2[0]);
458         tag += sizeof(struct ieee80211_hdr_3addr);
459         pDialogToken = tag + 2;
460         pStatusCode = (u16 *)(tag + 3);
461         pBaParamSet = (PBA_PARAM_SET)(tag + 5);
462         pBaTimeoutVal = (u16 *)(tag + 7);
463
464         // Check the capability
465         // Since we can always receive A-MPDU, we just check if it is under HT mode.
466         if(     ieee->current_network.qos_data.active == 0  ||
467                 ieee->pHTInfo->bCurrentHTSupport == false ||
468                 ieee->pHTInfo->bCurrentAMPDUEnable == false )
469         {
470                 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);
471                 ReasonCode = DELBA_REASON_UNKNOWN_BA;
472                 goto OnADDBARsp_Reject;
473         }
474
475
476         //
477         // Search for related TS.
478         // If there is no TS found, we wil reject ADDBA Rsp by sending DELBA frame.
479         //
480         if (!GetTs(
481                         ieee,
482                         (PTS_COMMON_INFO *)(&pTS),
483                         dst,
484                         (u8)(pBaParamSet->field.TID),
485                         TX_DIR,
486                         false)  )
487         {
488                 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__);
489                 ReasonCode = DELBA_REASON_UNKNOWN_BA;
490                 goto OnADDBARsp_Reject;
491         }
492
493         pTS->bAddBaReqInProgress = false;
494         pPendingBA = &pTS->TxPendingBARecord;
495         pAdmittedBA = &pTS->TxAdmittedBARecord;
496
497
498         //
499         // Check if related BA is waiting for setup.
500         // If not, reject by sending DELBA frame.
501         //
502         if((pAdmittedBA->bValid==true))
503         {
504                 // Since BA is already setup, we ignore all other ADDBA Response.
505                 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n");
506                 return -1;
507         }
508         else if((pPendingBA->bValid == false) ||(*pDialogToken != pPendingBA->DialogToken))
509         {
510                 IEEE80211_DEBUG(IEEE80211_DL_ERR,  "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n");
511                 ReasonCode = DELBA_REASON_UNKNOWN_BA;
512                 goto OnADDBARsp_Reject;
513         }
514         else
515         {
516                 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. BA is admitted! Status code:%X\n", *pStatusCode);
517                 DeActivateBAEntry(ieee, pPendingBA);
518         }
519
520
521         if(*pStatusCode == ADDBA_STATUS_SUCCESS)
522         {
523                 //
524                 // Determine ADDBA Rsp content here.
525                 // We can compare the value of BA parameter set that Peer returned and Self sent.
526                 // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism.
527                 //
528                 if(pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED)
529                 {
530                         // Since this is a kind of ADDBA failed, we delay next ADDBA process.
531                         pTS->bAddBaReqDelayed = true;
532                         DeActivateBAEntry(ieee, pAdmittedBA);
533                         ReasonCode = DELBA_REASON_END_BA;
534                         goto OnADDBARsp_Reject;
535                 }
536
537
538                 //
539                 // Admitted condition
540                 //
541                 pAdmittedBA->DialogToken = *pDialogToken;
542                 pAdmittedBA->BaTimeoutValue = *pBaTimeoutVal;
543                 pAdmittedBA->BaStartSeqCtrl = pPendingBA->BaStartSeqCtrl;
544                 pAdmittedBA->BaParamSet = *pBaParamSet;
545                 DeActivateBAEntry(ieee, pAdmittedBA);
546                 ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal);
547         }
548         else
549         {
550                 // Delay next ADDBA process.
551                 pTS->bAddBaReqDelayed = true;
552         }
553
554         // End of procedure
555         return 0;
556
557 OnADDBARsp_Reject:
558         {
559                 BA_RECORD       BA;
560                 BA.BaParamSet = *pBaParamSet;
561                 ieee80211_send_DELBA(ieee, dst, &BA, TX_DIR, ReasonCode);
562                 return 0;
563         }
564
565 }
566
567 /********************************************************************************************************************
568  *function: RX DELBA
569  *   input:  struct sk_buff *   skb     //incoming ADDBAReq skb.
570  *  return:  0(pass), other(fail)
571  *  notice:  As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
572 ********************************************************************************************************************/
573 int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
574 {
575          struct ieee80211_hdr_3addr *delba = NULL;
576         PDELBA_PARAM_SET        pDelBaParamSet = NULL;
577         u16                     *pReasonCode = NULL;
578         u8                      *dst = NULL;
579
580         if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 6)
581         {
582                 IEEE80211_DEBUG(IEEE80211_DL_ERR,
583                                 " Invalid skb len in DELBA(%d / %zu)\n",
584                                 skb->len,
585                                 (sizeof(struct ieee80211_hdr_3addr) + 6));
586                 return -1;
587         }
588
589         if(ieee->current_network.qos_data.active == 0 ||
590                 ieee->pHTInfo->bCurrentHTSupport == false )
591         {
592                 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);
593                 return -1;
594         }
595
596         IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_BA, skb->data, skb->len);
597         delba = (struct ieee80211_hdr_3addr *)skb->data;
598         dst = (u8 *)(&delba->addr2[0]);
599         delba += sizeof(struct ieee80211_hdr_3addr);
600         pDelBaParamSet = (PDELBA_PARAM_SET)(delba+2);
601         pReasonCode = (u16 *)(delba+4);
602
603         if(pDelBaParamSet->field.Initiator == 1)
604         {
605                 PRX_TS_RECORD   pRxTs;
606
607                 if( !GetTs(
608                                 ieee,
609                                 (PTS_COMMON_INFO *)&pRxTs,
610                                 dst,
611                                 (u8)pDelBaParamSet->field.TID,
612                                 RX_DIR,
613                                 false)  )
614                 {
615                         IEEE80211_DEBUG(IEEE80211_DL_ERR,  "can't get TS for RXTS in %s()\n", __func__);
616                         return -1;
617                 }
618
619                 RxTsDeleteBA(ieee, pRxTs);
620         }
621         else
622         {
623                 PTX_TS_RECORD   pTxTs;
624
625                 if(!GetTs(
626                         ieee,
627                         (PTS_COMMON_INFO *)&pTxTs,
628                         dst,
629                         (u8)pDelBaParamSet->field.TID,
630                         TX_DIR,
631                         false)  )
632                 {
633                         IEEE80211_DEBUG(IEEE80211_DL_ERR,  "can't get TS for TXTS in %s()\n", __func__);
634                         return -1;
635                 }
636
637                 pTxTs->bUsingBa = false;
638                 pTxTs->bAddBaReqInProgress = false;
639                 pTxTs->bAddBaReqDelayed = false;
640                 del_timer_sync(&pTxTs->TsAddBaTimer);
641                 //PlatformCancelTimer(Adapter, &pTxTs->TsAddBaTimer);
642                 TxTsDeleteBA(ieee, pTxTs);
643         }
644         return 0;
645 }
646
647 //
648 // ADDBA initiate. This can only be called by TX side.
649 //
650 void
651 TsInitAddBA(
652         struct ieee80211_device *ieee,
653         PTX_TS_RECORD   pTS,
654         u8              Policy,
655         u8              bOverwritePending
656         )
657 {
658         PBA_RECORD                      pBA = &pTS->TxPendingBARecord;
659
660         if(pBA->bValid==true && bOverwritePending==false)
661                 return;
662
663         // Set parameters to "Pending" variable set
664         DeActivateBAEntry(ieee, pBA);
665
666         pBA->DialogToken++;                                             // DialogToken: Only keep the latest dialog token
667         pBA->BaParamSet.field.AMSDU_Support = 0;        // Do not support A-MSDU with A-MPDU now!!
668         pBA->BaParamSet.field.BAPolicy = Policy;        // Policy: Delayed or Immediate
669         pBA->BaParamSet.field.TID = pTS->TsCommonInfo.TSpec.f.TSInfo.field.ucTSID;      // TID
670         // BufferSize: This need to be set according to A-MPDU vector
671         pBA->BaParamSet.field.BufferSize = 32;          // BufferSize: This need to be set according to A-MPDU vector
672         pBA->BaTimeoutValue = 0;                                        // Timeout value: Set 0 to disable Timer
673         pBA->BaStartSeqCtrl.field.SeqNum = (pTS->TxCurSeq + 3) % 4096;  // Block Ack will start after 3 packets later.
674
675         ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT);
676
677         ieee80211_send_ADDBAReq(ieee, pTS->TsCommonInfo.Addr, pBA);
678 }
679
680 void
681 TsInitDelBA( struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect)
682 {
683
684         if(TxRxSelect == TX_DIR)
685         {
686                 PTX_TS_RECORD   pTxTs = (PTX_TS_RECORD)pTsCommonInfo;
687
688                 if(TxTsDeleteBA(ieee, pTxTs))
689                         ieee80211_send_DELBA(
690                                 ieee,
691                                 pTsCommonInfo->Addr,
692                                 (pTxTs->TxAdmittedBARecord.bValid)?(&pTxTs->TxAdmittedBARecord):(&pTxTs->TxPendingBARecord),
693                                 TxRxSelect,
694                                 DELBA_REASON_END_BA);
695         }
696         else if(TxRxSelect == RX_DIR)
697         {
698                 PRX_TS_RECORD   pRxTs = (PRX_TS_RECORD)pTsCommonInfo;
699                 if(RxTsDeleteBA(ieee, pRxTs))
700                         ieee80211_send_DELBA(
701                                 ieee,
702                                 pTsCommonInfo->Addr,
703                                 &pRxTs->RxAdmittedBARecord,
704                                 TxRxSelect,
705                                 DELBA_REASON_END_BA     );
706         }
707 }
708 /********************************************************************************************************************
709  *function:  BA setup timer
710  *   input:  unsigned long       data           //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
711  *  return:  NULL
712  *  notice:
713 ********************************************************************************************************************/
714 void BaSetupTimeOut(unsigned long data)
715 {
716         PTX_TS_RECORD   pTxTs = (PTX_TS_RECORD)data;
717
718         pTxTs->bAddBaReqInProgress = false;
719         pTxTs->bAddBaReqDelayed = true;
720         pTxTs->TxPendingBARecord.bValid = false;
721 }
722
723 void TxBaInactTimeout(unsigned long data)
724 {
725         PTX_TS_RECORD   pTxTs = (PTX_TS_RECORD)data;
726         struct ieee80211_device *ieee = container_of(pTxTs, struct ieee80211_device, TxTsRecord[pTxTs->num]);
727         TxTsDeleteBA(ieee, pTxTs);
728         ieee80211_send_DELBA(
729                 ieee,
730                 pTxTs->TsCommonInfo.Addr,
731                 &pTxTs->TxAdmittedBARecord,
732                 TX_DIR,
733                 DELBA_REASON_TIMEOUT);
734 }
735
736 void RxBaInactTimeout(unsigned long data)
737 {
738         PRX_TS_RECORD   pRxTs = (PRX_TS_RECORD)data;
739         struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
740
741         RxTsDeleteBA(ieee, pRxTs);
742         ieee80211_send_DELBA(
743                 ieee,
744                 pRxTs->TsCommonInfo.Addr,
745                 &pRxTs->RxAdmittedBARecord,
746                 RX_DIR,
747                 DELBA_REASON_TIMEOUT);
748         return ;
749 }