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