Staging: rtl8192e: Fix printk style warning
[firefly-linux-kernel-4.4.55.git] / drivers / staging / rtl8192e / rtl819x_HTProc.c
1 /******************************************************************************
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * This program is distributed in the hope that it will be useful, but WITHOUT
5  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
7  * more details.
8  *
9  * You should have received a copy of the GNU General Public License along with
10  * this program; if not, write to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
12  *
13  * The full GNU General Public License is included in this distribution in the
14  * file called LICENSE.
15  *
16  * Contact Information:
17  * wlanfae <wlanfae@realtek.com>
18 ******************************************************************************/
19 #include "rtllib.h"
20 #include "rtl819x_HT.h"
21 u8 MCS_FILTER_ALL[16] = {
22         0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
23         0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
24 };
25
26 u8 MCS_FILTER_1SS[16] = {
27         0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
28         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
29 ;
30
31 u16 MCS_DATA_RATE[2][2][77] = {
32         {{13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234,
33          260, 39, 78, 117, 234, 312, 351, 390, 52, 104, 156, 208, 312, 416,
34          468, 520, 0, 78, 104, 130, 117, 156, 195, 104, 130, 130, 156, 182,
35          182, 208, 156, 195, 195, 234, 273, 273, 312, 130, 156, 181, 156,
36          181, 208, 234, 208, 234, 260, 260, 286, 195, 234, 273, 234, 273,
37          312, 351, 312, 351, 390, 390, 429} ,
38         {14, 29, 43, 58, 87, 116, 130, 144, 29, 58, 87, 116, 173, 231, 260, 289,
39          43, 87, 130, 173, 260, 347, 390, 433, 58, 116, 173, 231, 347, 462, 520,
40          578, 0, 87, 116, 144, 130, 173, 217, 116, 144, 144, 173, 202, 202, 231,
41          173, 217, 217, 260, 303, 303, 347, 144, 173, 202, 173, 202, 231, 260,
42          231, 260, 289, 289, 318, 217, 260, 303, 260, 303, 347, 390, 347, 390,
43          433, 433, 477} } ,
44         {{27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486,
45          540, 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648,
46          864, 972, 1080, 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324,
47          378, 378, 432, 324, 405, 405, 486, 567, 567, 648, 270, 324, 378, 324,
48          378, 432, 486, 432, 486, 540, 540, 594, 405, 486, 567, 486, 567, 648,
49          729, 648, 729, 810, 810, 891},
50         {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540,
51          600, 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720,
52          960, 1080, 1200, 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360,
53          420, 420, 480, 360, 450, 450, 540, 630, 630, 720, 300, 360, 420, 360,
54          420, 480, 540, 480, 540, 600, 600, 660, 450, 540, 630, 540, 630, 720,
55          810, 720, 810, 900, 900, 990} }
56 };
57
58 static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf};
59
60 static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70};
61
62 static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e};
63
64 static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f};
65
66 static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf};
67
68 static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc};
69
70 static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e};
71
72 static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02};
73
74 static u8 DLINK_ATHEROS_1[3] = {0x00, 0x1c, 0xf0};
75
76 static u8 DLINK_ATHEROS_2[3] = {0x00, 0x21, 0x91};
77
78 static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94};
79
80 static u8 LINKSYS_MARVELL_4400N[3] = {0x00, 0x14, 0xa4};
81
82 void HTUpdateDefaultSetting(struct rtllib_device *ieee)
83 {
84         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
85
86         pHTInfo->bAcceptAddbaReq = 1;
87
88         pHTInfo->bRegShortGI20MHz = 1;
89         pHTInfo->bRegShortGI40MHz = 1;
90
91         pHTInfo->bRegBW40MHz = 1;
92
93         if (pHTInfo->bRegBW40MHz)
94                 pHTInfo->bRegSuppCCK = 1;
95         else
96                 pHTInfo->bRegSuppCCK = true;
97
98         pHTInfo->nAMSDU_MaxSize = 7935UL;
99         pHTInfo->bAMSDU_Support = 0;
100
101         pHTInfo->bAMPDUEnable = 1;
102         pHTInfo->AMPDU_Factor = 2;
103         pHTInfo->MPDU_Density = 0;
104
105         pHTInfo->SelfMimoPs = 3;
106         if (pHTInfo->SelfMimoPs == 2)
107                 pHTInfo->SelfMimoPs = 3;
108         ieee->bTxDisableRateFallBack = 0;
109         ieee->bTxUseDriverAssingedRate = 0;
110
111         ieee->bTxEnableFwCalcDur = 1;
112
113         pHTInfo->bRegRT2RTAggregation = 1;
114
115         pHTInfo->bRegRxReorderEnable = 1;
116         pHTInfo->RxReorderWinSize = 64;
117         pHTInfo->RxReorderPendingTime = 30;
118 }
119
120 void HTDebugHTCapability(u8 *CapIE, u8 *TitleString)
121 {
122
123         static u8       EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};
124         struct ht_capab_ele *pCapELE;
125
126         if (!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) {
127                 RTLLIB_DEBUG(RTLLIB_DL_HT, "EWC IE in %s()\n", __func__);
128                 pCapELE = (struct ht_capab_ele *)(&CapIE[4]);
129         } else
130                 pCapELE = (struct ht_capab_ele *)(&CapIE[0]);
131
132         RTLLIB_DEBUG(RTLLIB_DL_HT, "<Log HT Capability>. Called by %s\n",
133                      TitleString);
134
135         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tSupported Channel Width = %s\n",
136                      (pCapELE->ChlWidth) ? "20MHz" : "20/40MHz");
137         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tSupport Short GI for 20M = %s\n",
138                      (pCapELE->ShortGI20Mhz) ? "YES" : "NO");
139         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tSupport Short GI for 40M = %s\n",
140                      (pCapELE->ShortGI40Mhz) ? "YES" : "NO");
141         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tSupport TX STBC = %s\n",
142                      (pCapELE->TxSTBC) ? "YES" : "NO");
143         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tMax AMSDU Size = %s\n",
144                      (pCapELE->MaxAMSDUSize) ? "3839" : "7935");
145         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tSupport CCK in 20/40 mode = %s\n",
146                      (pCapELE->DssCCk) ? "YES" : "NO");
147         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tMax AMPDU Factor = %d\n",
148                      pCapELE->MaxRxAMPDUFactor);
149         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tMPDU Density = %d\n",
150                      pCapELE->MPDUDensity);
151         RTLLIB_DEBUG(RTLLIB_DL_HT,  "\tMCS Rate Set = [%x][%x][%x][%x][%x]\n",
152                      pCapELE->MCS[0], pCapELE->MCS[1], pCapELE->MCS[2],
153                      pCapELE->MCS[3], pCapELE->MCS[4]);
154         return;
155
156 }
157
158 void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString)
159 {
160
161         static u8       EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};
162         struct ht_info_ele *pHTInfoEle;
163
164         if (!memcmp(InfoIE, EWC11NHTInfo, sizeof(EWC11NHTInfo))) {
165                 RTLLIB_DEBUG(RTLLIB_DL_HT, "EWC IE in %s()\n", __func__);
166                 pHTInfoEle = (struct ht_info_ele *)(&InfoIE[4]);
167         } else
168                 pHTInfoEle = (struct ht_info_ele *)(&InfoIE[0]);
169
170
171         RTLLIB_DEBUG(RTLLIB_DL_HT, "<Log HT Information Element>. "
172                      "Called by %s\n", TitleString);
173
174         RTLLIB_DEBUG(RTLLIB_DL_HT, "\tPrimary channel = %d\n",
175                      pHTInfoEle->ControlChl);
176         RTLLIB_DEBUG(RTLLIB_DL_HT, "\tSenondary channel =");
177         switch (pHTInfoEle->ExtChlOffset) {
178         case 0:
179                 RTLLIB_DEBUG(RTLLIB_DL_HT, "Not Present\n");
180                 break;
181         case 1:
182                 RTLLIB_DEBUG(RTLLIB_DL_HT, "Upper channel\n");
183                 break;
184         case 2:
185                 RTLLIB_DEBUG(RTLLIB_DL_HT, "Reserved. Eooro!!!\n");
186                 break;
187         case 3:
188                 RTLLIB_DEBUG(RTLLIB_DL_HT, "Lower Channel\n");
189                 break;
190         }
191         RTLLIB_DEBUG(RTLLIB_DL_HT, "\tRecommended channel width = %s\n",
192                      (pHTInfoEle->RecommemdedTxWidth) ? "20Mhz" : "40Mhz");
193
194         RTLLIB_DEBUG(RTLLIB_DL_HT, "\tOperation mode for protection = ");
195         switch (pHTInfoEle->OptMode) {
196         case 0:
197                 RTLLIB_DEBUG(RTLLIB_DL_HT, "No Protection\n");
198                 break;
199         case 1:
200                 RTLLIB_DEBUG(RTLLIB_DL_HT, "HT non-member protection mode\n");
201                 break;
202         case 2:
203                 RTLLIB_DEBUG(RTLLIB_DL_HT, "Suggest to open protection\n");
204                 break;
205         case 3:
206                 RTLLIB_DEBUG(RTLLIB_DL_HT, "HT mixed mode\n");
207                 break;
208         }
209
210         RTLLIB_DEBUG(RTLLIB_DL_HT, "\tBasic MCS Rate Set = [%x][%x][%x][%x]"
211                      "[%x]\n", pHTInfoEle->BasicMSC[0], pHTInfoEle->BasicMSC[1],
212                      pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3],
213                      pHTInfoEle->BasicMSC[4]);
214         return;
215 }
216
217 static bool IsHTHalfNmode40Bandwidth(struct rtllib_device *ieee)
218 {
219         bool                    retValue = false;
220         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
221
222         if (pHTInfo->bCurrentHTSupport == false)
223                 retValue = false;
224         else if (pHTInfo->bRegBW40MHz == false)
225                 retValue = false;
226         else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
227                 retValue = false;
228         else if (((struct ht_capab_ele *)(pHTInfo->PeerHTCapBuf))->ChlWidth)
229                 retValue = true;
230         else
231                 retValue = false;
232
233         return retValue;
234 }
235
236 static bool IsHTHalfNmodeSGI(struct rtllib_device *ieee, bool is40MHz)
237 {
238         bool                    retValue = false;
239         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
240
241         if (pHTInfo->bCurrentHTSupport == false)
242                 retValue = false;
243         else if (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
244                 retValue = false;
245         else if (is40MHz) {
246                 if (((struct ht_capab_ele *)
247                     (pHTInfo->PeerHTCapBuf))->ShortGI40Mhz)
248                         retValue = true;
249                 else
250                         retValue = false;
251         } else {
252                 if (((struct ht_capab_ele *)
253                    (pHTInfo->PeerHTCapBuf))->ShortGI20Mhz)
254                         retValue = true;
255                 else
256                         retValue = false;
257         }
258
259         return retValue;
260 }
261
262 u16 HTHalfMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate)
263 {
264
265         u8      is40MHz;
266         u8      isShortGI;
267
268         is40MHz  =  (IsHTHalfNmode40Bandwidth(ieee)) ? 1 : 0;
269         isShortGI = (IsHTHalfNmodeSGI(ieee, is40MHz)) ? 1 : 0;
270
271         return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)];
272 }
273
274
275 u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate)
276 {
277         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
278
279         u8      is40MHz = (pHTInfo->bCurBW40MHz) ? 1 : 0;
280         u8      isShortGI = (pHTInfo->bCurBW40MHz) ?
281                             ((pHTInfo->bCurShortGI40MHz) ? 1 : 0) :
282                             ((pHTInfo->bCurShortGI20MHz) ? 1 : 0);
283         return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate & 0x7f)];
284 }
285
286 u16  TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate)
287 {
288         u16     CCKOFDMRate[12] = {0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18,
289                                    0x24, 0x30, 0x48, 0x60, 0x6c};
290         u8      is40MHz = 0;
291         u8      isShortGI = 0;
292
293         if (nDataRate < 12) {
294                 return CCKOFDMRate[nDataRate];
295         } else {
296                 if (nDataRate >= 0x10 && nDataRate <= 0x1f) {
297                         is40MHz = 0;
298                         isShortGI = 0;
299                 } else if (nDataRate >= 0x20  && nDataRate <= 0x2f) {
300                         is40MHz = 1;
301                         isShortGI = 0;
302
303                 } else if (nDataRate >= 0x30  && nDataRate <= 0x3f) {
304                         is40MHz = 0;
305                         isShortGI = 1;
306                 } else if (nDataRate >= 0x40  && nDataRate <= 0x4f) {
307                         is40MHz = 1;
308                         isShortGI = 1;
309                 }
310                 return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate&0xf];
311         }
312 }
313
314 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee)
315 {
316         bool                    retValue = false;
317         struct rtllib_network *net = &ieee->current_network;
318
319         if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) ||
320             (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) ||
321             (memcmp(net->bssid, PCI_RALINK, 3) == 0) ||
322             (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) ||
323             (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) ||
324             (net->ralink_cap_exist))
325                 retValue = true;
326         else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) ||
327                 !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) ||
328                 !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) ||
329                 (net->broadcom_cap_exist))
330                 retValue = true;
331         else if (net->bssht.bdRT2RTAggregation)
332                 retValue = true;
333         else
334                 retValue = false;
335
336         return retValue;
337 }
338
339 static void HTIOTPeerDetermine(struct rtllib_device *ieee)
340 {
341         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
342         struct rtllib_network *net = &ieee->current_network;
343
344         if (net->bssht.bdRT2RTAggregation) {
345                 pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK;
346                 if (net->bssht.RT2RT_HT_Mode & RT_HT_CAP_USE_92SE)
347                         pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK_92SE;
348                 if (net->bssht.RT2RT_HT_Mode & RT_HT_CAP_USE_SOFTAP)
349                         pHTInfo->IOTPeer = HT_IOT_PEER_92U_SOFTAP;
350         } else if (net->broadcom_cap_exist)
351                 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
352         else if (!memcmp(net->bssid, UNKNOWN_BORADCOM, 3) ||
353                  !memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3) ||
354                  !memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3))
355                 pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
356         else if ((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3) == 0) ||
357                  (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3) == 0) ||
358                  (memcmp(net->bssid, PCI_RALINK, 3) == 0) ||
359                  (memcmp(net->bssid, EDIMAX_RALINK, 3) == 0) ||
360                  (memcmp(net->bssid, AIRLINK_RALINK, 3) == 0) ||
361                   net->ralink_cap_exist)
362                 pHTInfo->IOTPeer = HT_IOT_PEER_RALINK;
363         else if ((net->atheros_cap_exist) ||
364                 (memcmp(net->bssid, DLINK_ATHEROS_1, 3) == 0) ||
365                 (memcmp(net->bssid, DLINK_ATHEROS_2, 3) == 0))
366                 pHTInfo->IOTPeer = HT_IOT_PEER_ATHEROS;
367         else if ((memcmp(net->bssid, CISCO_BROADCOM, 3) == 0) ||
368                   net->cisco_cap_exist)
369                 pHTInfo->IOTPeer = HT_IOT_PEER_CISCO;
370         else if ((memcmp(net->bssid, LINKSYS_MARVELL_4400N, 3) == 0) ||
371                   net->marvell_cap_exist)
372                 pHTInfo->IOTPeer = HT_IOT_PEER_MARVELL;
373         else if (net->airgo_cap_exist)
374                 pHTInfo->IOTPeer = HT_IOT_PEER_AIRGO;
375         else
376                 pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
377
378         RTLLIB_DEBUG(RTLLIB_DL_IOT, "Joseph debug!! IOTPEER: %x\n",
379                      pHTInfo->IOTPeer);
380 }
381
382 static u8 HTIOTActIsDisableMCS14(struct rtllib_device *ieee, u8 *PeerMacAddr)
383 {
384         return 0;
385 }
386
387
388 static bool HTIOTActIsDisableMCS15(struct rtllib_device *ieee)
389 {
390         bool retValue = false;
391
392         return retValue;
393 }
394
395 static bool HTIOTActIsDisableMCSTwoSpatialStream(struct rtllib_device *ieee)
396 {
397         return false;
398 }
399
400 static u8 HTIOTActIsDisableEDCATurbo(struct rtllib_device *ieee, u8 *PeerMacAddr)
401 {
402         return false;
403 }
404
405 static u8 HTIOTActIsMgntUseCCK6M(struct rtllib_device *ieee,
406                                  struct rtllib_network *network)
407 {
408         u8      retValue = 0;
409
410
411         if (ieee->pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM)
412                 retValue = 1;
413
414         return retValue;
415 }
416
417 static u8 HTIOTActIsCCDFsync(struct rtllib_device *ieee)
418 {
419         u8      retValue = 0;
420
421         if (ieee->pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM)
422                 retValue = 1;
423         return retValue;
424 }
425
426 static void HTIOTActDetermineRaFunc(struct rtllib_device *ieee, bool bPeerRx2ss)
427 {
428         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
429
430         pHTInfo->IOTRaFunc &= HT_IOT_RAFUNC_DISABLE_ALL;
431
432         if (pHTInfo->IOTPeer == HT_IOT_PEER_RALINK && !bPeerRx2ss)
433                 pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_PEER_1R;
434
435         if (pHTInfo->IOTAction & HT_IOT_ACT_AMSDU_ENABLE)
436                 pHTInfo->IOTRaFunc |= HT_IOT_RAFUNC_TX_AMSDU;
437
438 }
439
440 void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo)
441 {
442         pHTInfo->IOTAction = 0;
443         pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
444         pHTInfo->IOTRaFunc = 0;
445 }
446
447 void HTConstructCapabilityElement(struct rtllib_device *ieee, u8 *posHTCap,
448                                   u8 *len, u8 IsEncrypt, bool bAssoc)
449 {
450         struct rt_hi_throughput *pHT = ieee->pHTInfo;
451         struct ht_capab_ele *pCapELE = NULL;
452
453         if ((posHTCap == NULL) || (pHT == NULL)) {
454                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "posHTCap or pHTInfo can't be "
455                              "null in HTConstructCapabilityElement()\n");
456                 return;
457         }
458         memset(posHTCap, 0, *len);
459
460         if ((bAssoc) && (pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)) {
461                 u8      EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};
462
463                 memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
464                 pCapELE = (struct ht_capab_ele *)&(posHTCap[4]);
465                 *len = 30 + 2;
466         } else {
467                 pCapELE = (struct ht_capab_ele *)posHTCap;
468                 *len = 26 + 2;
469         }
470
471         pCapELE->AdvCoding              = 0;
472         if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
473                 pCapELE->ChlWidth = 0;
474         else
475                 pCapELE->ChlWidth = (pHT->bRegBW40MHz ? 1 : 0);
476
477         pCapELE->MimoPwrSave            = pHT->SelfMimoPs;
478         pCapELE->GreenField             = 0;
479         pCapELE->ShortGI20Mhz           = 1;
480         pCapELE->ShortGI40Mhz           = 1;
481
482         pCapELE->TxSTBC                 = 1;
483         pCapELE->RxSTBC                 = 0;
484         pCapELE->DelayBA                = 0;
485         pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0;
486         pCapELE->DssCCk = ((pHT->bRegBW40MHz) ? (pHT->bRegSuppCCK ? 1 : 0) : 0);
487         pCapELE->PSMP = 0;
488         pCapELE->LSigTxopProtect = 0;
489
490
491         RTLLIB_DEBUG(RTLLIB_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d "
492                      "DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize,
493                      pCapELE->DssCCk);
494
495         if (IsEncrypt) {
496                 pCapELE->MPDUDensity    = 7;
497                 pCapELE->MaxRxAMPDUFactor       = 2;
498         } else {
499                 pCapELE->MaxRxAMPDUFactor       = 3;
500                 pCapELE->MPDUDensity    = 0;
501         }
502
503         memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16);
504         memset(&pCapELE->ExtHTCapInfo, 0, 2);
505         memset(pCapELE->TxBFCap, 0, 4);
506
507         pCapELE->ASCap = 0;
508
509         if (bAssoc) {
510                 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15)
511                         pCapELE->MCS[1] &= 0x7f;
512
513                 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14)
514                         pCapELE->MCS[1] &= 0xbf;
515
516                 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS)
517                         pCapELE->MCS[1] &= 0x00;
518
519                 if (pHT->IOTAction & HT_IOT_ACT_DISABLE_RX_40MHZ_SHORT_GI)
520                         pCapELE->ShortGI40Mhz           = 0;
521
522                 if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) {
523                         pCapELE->ChlWidth = 0;
524                         pCapELE->MCS[1] = 0;
525                 }
526         }
527         return;
528 }
529
530 void HTConstructInfoElement(struct rtllib_device *ieee, u8 *posHTInfo,
531                             u8 *len, u8 IsEncrypt)
532 {
533         struct rt_hi_throughput *pHT = ieee->pHTInfo;
534         struct ht_info_ele *pHTInfoEle = (struct ht_info_ele *)posHTInfo;
535
536         if ((posHTInfo == NULL) || (pHTInfoEle == NULL)) {
537                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "posHTInfo or pHTInfoEle can't be "
538                              "null in HTConstructInfoElement()\n");
539                 return;
540         }
541
542         memset(posHTInfo, 0, *len);
543         if ((ieee->iw_mode == IW_MODE_ADHOC) ||
544             (ieee->iw_mode == IW_MODE_MASTER)) {
545                 pHTInfoEle->ControlChl  = ieee->current_network.channel;
546                 pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false) ?
547                                             HT_EXTCHNL_OFFSET_NO_EXT :
548                                             (ieee->current_network.channel <= 6)
549                                             ? HT_EXTCHNL_OFFSET_UPPER :
550                                             HT_EXTCHNL_OFFSET_LOWER);
551                 pHTInfoEle->RecommemdedTxWidth  = pHT->bRegBW40MHz;
552                 pHTInfoEle->RIFS                        = 0;
553                 pHTInfoEle->PSMPAccessOnly              = 0;
554                 pHTInfoEle->SrvIntGranularity           = 0;
555                 pHTInfoEle->OptMode                     = pHT->CurrentOpMode;
556                 pHTInfoEle->NonGFDevPresent             = 0;
557                 pHTInfoEle->DualBeacon                  = 0;
558                 pHTInfoEle->SecondaryBeacon             = 0;
559                 pHTInfoEle->LSigTxopProtectFull         = 0;
560                 pHTInfoEle->PcoActive                   = 0;
561                 pHTInfoEle->PcoPhase                    = 0;
562
563                 memset(pHTInfoEle->BasicMSC, 0, 16);
564
565
566                 *len = 22 + 2;
567
568         } else {
569                 *len = 0;
570         }
571         return;
572 }
573
574 void HTConstructRT2RTAggElement(struct rtllib_device *ieee, u8 *posRT2RTAgg,
575                                 u8 *len)
576 {
577         if (posRT2RTAgg == NULL) {
578                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "posRT2RTAgg can't be null in "
579                              "HTConstructRT2RTAggElement()\n");
580                 return;
581         }
582         memset(posRT2RTAgg, 0, *len);
583         *posRT2RTAgg++ = 0x00;
584         *posRT2RTAgg++ = 0xe0;
585         *posRT2RTAgg++ = 0x4c;
586         *posRT2RTAgg++ = 0x02;
587         *posRT2RTAgg++ = 0x01;
588
589         *posRT2RTAgg = 0x30;
590
591         if (ieee->bSupportRemoteWakeUp)
592                 *posRT2RTAgg |= RT_HT_CAP_USE_WOW;
593
594         *len = 6 + 2;
595
596         return;
597 }
598
599 static u8 HT_PickMCSRate(struct rtllib_device *ieee, u8 *pOperateMCS)
600 {
601         u8 i;
602
603         if (pOperateMCS == NULL) {
604                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "pOperateMCS can't be null"
605                              " in HT_PickMCSRate()\n");
606                 return false;
607         }
608
609         switch (ieee->mode) {
610         case IEEE_A:
611         case IEEE_B:
612         case IEEE_G:
613                 for (i = 0; i <= 15; i++)
614                         pOperateMCS[i] = 0;
615                 break;
616         case IEEE_N_24G:
617         case IEEE_N_5G:
618                 pOperateMCS[0] &= RATE_ADPT_1SS_MASK;
619                 pOperateMCS[1] &= RATE_ADPT_2SS_MASK;
620                 pOperateMCS[3] &= RATE_ADPT_MCS32_MASK;
621                 break;
622         default:
623                 break;
624
625         }
626
627         return true;
628 }
629
630 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
631                        u8 *pMCSFilter)
632 {
633         u8              i, j;
634         u8              bitMap;
635         u8              mcsRate = 0;
636         u8              availableMcsRate[16];
637
638         if (pMCSRateSet == NULL || pMCSFilter == NULL) {
639                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "pMCSRateSet or pMCSFilter can't "
640                              "be null in HTGetHighestMCSRate()\n");
641                 return false;
642         }
643         for (i = 0; i < 16; i++)
644                 availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i];
645
646         for (i = 0; i < 16; i++) {
647                 if (availableMcsRate[i] != 0)
648                         break;
649         }
650         if (i == 16)
651                 return false;
652
653         for (i = 0; i < 16; i++) {
654                 if (availableMcsRate[i] != 0) {
655                         bitMap = availableMcsRate[i];
656                         for (j = 0; j < 8; j++) {
657                                 if ((bitMap%2) != 0) {
658                                         if (HTMcsToDataRate(ieee, (8*i+j)) >
659                                             HTMcsToDataRate(ieee, mcsRate))
660                                                 mcsRate = (8*i+j);
661                                 }
662                                 bitMap = bitMap>>1;
663                         }
664                 }
665         }
666         return mcsRate | 0x80;
667 }
668
669 u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS, u8 *pOperateMCS)
670 {
671
672         u8 i;
673
674         for (i = 0; i <= 15; i++)
675                 pOperateMCS[i] = ieee->Regdot11TxHTOperationalRateSet[i] &
676                                  pSupportMCS[i];
677
678         HT_PickMCSRate(ieee, pOperateMCS);
679
680         if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
681                 pOperateMCS[1] = 0;
682
683         for (i = 2; i <= 15; i++)
684                 pOperateMCS[i] = 0;
685
686         return true;
687 }
688
689 void HTSetConnectBwMode(struct rtllib_device *ieee,
690                         enum ht_channel_width Bandwidth,
691                         enum ht_extchnl_offset Offset);
692
693 void HTOnAssocRsp(struct rtllib_device *ieee)
694 {
695         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
696         struct ht_capab_ele *pPeerHTCap = NULL;
697         struct ht_info_ele *pPeerHTInfo = NULL;
698         u16 nMaxAMSDUSize = 0;
699         u8 *pMcsFilter = NULL;
700
701         static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};
702         static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};
703
704         if (pHTInfo->bCurrentHTSupport == false) {
705                 RTLLIB_DEBUG(RTLLIB_DL_ERR, "<=== HTOnAssocRsp(): "
706                              "HT_DISABLE\n");
707                 return;
708         }
709         RTLLIB_DEBUG(RTLLIB_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n");
710
711         if (!memcmp(pHTInfo->PeerHTCapBuf, EWC11NHTCap, sizeof(EWC11NHTCap)))
712                 pPeerHTCap = (struct ht_capab_ele *)(&pHTInfo->PeerHTCapBuf[4]);
713         else
714                 pPeerHTCap = (struct ht_capab_ele *)(pHTInfo->PeerHTCapBuf);
715
716         if (!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
717                 pPeerHTInfo = (struct ht_info_ele *)
718                              (&pHTInfo->PeerHTInfoBuf[4]);
719         else
720                 pPeerHTInfo = (struct ht_info_ele *)(pHTInfo->PeerHTInfoBuf);
721
722         RTLLIB_DEBUG_DATA(RTLLIB_DL_DATA | RTLLIB_DL_HT, pPeerHTCap,
723                           sizeof(struct ht_capab_ele));
724         HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth),
725                           (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset));
726         pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ?
727                                  true : false);
728
729         pHTInfo->bCurShortGI20MHz = ((pHTInfo->bRegShortGI20MHz) ?
730                                     ((pPeerHTCap->ShortGI20Mhz == 1) ?
731                                     true : false) : false);
732         pHTInfo->bCurShortGI40MHz = ((pHTInfo->bRegShortGI40MHz) ?
733                                      ((pPeerHTCap->ShortGI40Mhz == 1) ?
734                                      true : false) : false);
735
736         pHTInfo->bCurSuppCCK = ((pHTInfo->bRegSuppCCK) ?
737                                ((pPeerHTCap->DssCCk == 1) ? true :
738                                false) : false);
739
740
741         pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
742
743         nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize == 0) ? 3839 : 7935;
744
745         if (pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize)
746                 pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize;
747         else
748                 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
749
750         pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
751         if (ieee->rtllib_ap_sec_type &&
752            (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP))) {
753                 if ((pHTInfo->IOTPeer == HT_IOT_PEER_ATHEROS) ||
754                                 (pHTInfo->IOTPeer == HT_IOT_PEER_UNKNOWN))
755                         pHTInfo->bCurrentAMPDUEnable = false;
756         }
757
758         if (!pHTInfo->bRegRT2RTAggregation) {
759                 if (pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor)
760                         pHTInfo->CurrentAMPDUFactor =
761                                                  pPeerHTCap->MaxRxAMPDUFactor;
762                 else
763                         pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
764
765         } else {
766                 if (ieee->current_network.bssht.bdRT2RTAggregation) {
767                         if (ieee->pairwise_key_type != KEY_TYPE_NA)
768                                 pHTInfo->CurrentAMPDUFactor =
769                                                  pPeerHTCap->MaxRxAMPDUFactor;
770                         else
771                                 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
772                 } else {
773                         if (pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
774                                 pHTInfo->CurrentAMPDUFactor =
775                                                  pPeerHTCap->MaxRxAMPDUFactor;
776                         else
777                                 pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
778                 }
779         }
780         if (pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
781                 pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
782         else
783                 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
784         if (pHTInfo->IOTAction & HT_IOT_ACT_TX_USE_AMSDU_8K) {
785                 pHTInfo->bCurrentAMPDUEnable = false;
786                 pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE;
787                 pHTInfo->ForcedAMSDUMaxSize = 7935;
788         }
789         pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable;
790
791         if (pPeerHTCap->MCS[0] == 0)
792                 pPeerHTCap->MCS[0] = 0xff;
793
794         HTIOTActDetermineRaFunc(ieee, ((pPeerHTCap->MCS[1]) != 0));
795
796         HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet);
797
798         pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave;
799         if (pHTInfo->PeerMimoPs == MIMO_PS_STATIC)
800                 pMcsFilter = MCS_FILTER_1SS;
801         else
802                 pMcsFilter = MCS_FILTER_ALL;
803         ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee,
804                                    ieee->dot11HTOperationalRateSet, pMcsFilter);
805         ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
806
807         pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
808 }
809
810 void HTInitializeHTInfo(struct rtllib_device *ieee)
811 {
812         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
813
814         RTLLIB_DEBUG(RTLLIB_DL_HT, "===========>%s()\n", __func__);
815         pHTInfo->bCurrentHTSupport = false;
816
817         pHTInfo->bCurBW40MHz = false;
818         pHTInfo->bCurTxBW40MHz = false;
819
820         pHTInfo->bCurShortGI20MHz = false;
821         pHTInfo->bCurShortGI40MHz = false;
822         pHTInfo->bForcedShortGI = false;
823
824         pHTInfo->bCurSuppCCK = true;
825
826         pHTInfo->bCurrent_AMSDU_Support = false;
827         pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
828         pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
829         pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
830
831         memset((void *)(&(pHTInfo->SelfHTCap)), 0,
832                 sizeof(pHTInfo->SelfHTCap));
833         memset((void *)(&(pHTInfo->SelfHTInfo)), 0,
834                 sizeof(pHTInfo->SelfHTInfo));
835         memset((void *)(&(pHTInfo->PeerHTCapBuf)), 0,
836                 sizeof(pHTInfo->PeerHTCapBuf));
837         memset((void *)(&(pHTInfo->PeerHTInfoBuf)), 0,
838                 sizeof(pHTInfo->PeerHTInfoBuf));
839
840         pHTInfo->bSwBwInProgress = false;
841         pHTInfo->ChnlOp = CHNLOP_NONE;
842
843         pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
844
845         pHTInfo->bCurrentRT2RTAggregation = false;
846         pHTInfo->bCurrentRT2RTLongSlotTime = false;
847         pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0;
848
849         pHTInfo->IOTPeer = 0;
850         pHTInfo->IOTAction = 0;
851         pHTInfo->IOTRaFunc = 0;
852
853         {
854                 u8 *RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]);
855
856                 RegHTSuppRateSets[0] = 0xFF;
857                 RegHTSuppRateSets[1] = 0xFF;
858                 RegHTSuppRateSets[4] = 0x01;
859         }
860 }
861
862 void HTInitializeBssDesc(struct bss_ht *pBssHT)
863 {
864
865         pBssHT->bdSupportHT = false;
866         memset(pBssHT->bdHTCapBuf, 0, sizeof(pBssHT->bdHTCapBuf));
867         pBssHT->bdHTCapLen = 0;
868         memset(pBssHT->bdHTInfoBuf, 0, sizeof(pBssHT->bdHTInfoBuf));
869         pBssHT->bdHTInfoLen = 0;
870
871         pBssHT->bdHTSpecVer = HT_SPEC_VER_IEEE;
872
873         pBssHT->bdRT2RTAggregation = false;
874         pBssHT->bdRT2RTLongSlotTime = false;
875         pBssHT->RT2RT_HT_Mode = (enum rt_ht_capability)0;
876 }
877
878 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
879                                    struct rtllib_network *pNetwork)
880 {
881         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
882         u8      bIOTAction = 0;
883
884         RTLLIB_DEBUG(RTLLIB_DL_HT, "==============>%s()\n", __func__);
885         /* unmark bEnableHT flag here is the same reason why unmarked in
886          * function rtllib_softmac_new_net. WB 2008.09.10*/
887         if (pNetwork->bssht.bdSupportHT) {
888                 pHTInfo->bCurrentHTSupport = true;
889                 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer;
890
891                 if (pNetwork->bssht.bdHTCapLen > 0 &&
892                     pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf))
893                         memcpy(pHTInfo->PeerHTCapBuf,
894                                pNetwork->bssht.bdHTCapBuf,
895                                pNetwork->bssht.bdHTCapLen);
896
897                 if (pNetwork->bssht.bdHTInfoLen > 0 &&
898                     pNetwork->bssht.bdHTInfoLen <=
899                     sizeof(pHTInfo->PeerHTInfoBuf))
900                         memcpy(pHTInfo->PeerHTInfoBuf,
901                                pNetwork->bssht.bdHTInfoBuf,
902                                pNetwork->bssht.bdHTInfoLen);
903
904                 if (pHTInfo->bRegRT2RTAggregation) {
905                         pHTInfo->bCurrentRT2RTAggregation =
906                                  pNetwork->bssht.bdRT2RTAggregation;
907                         pHTInfo->bCurrentRT2RTLongSlotTime =
908                                  pNetwork->bssht.bdRT2RTLongSlotTime;
909                         pHTInfo->RT2RT_HT_Mode = pNetwork->bssht.RT2RT_HT_Mode;
910                 } else {
911                         pHTInfo->bCurrentRT2RTAggregation = false;
912                         pHTInfo->bCurrentRT2RTLongSlotTime = false;
913                         pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0;
914                 }
915
916                 HTIOTPeerDetermine(ieee);
917
918                 pHTInfo->IOTAction = 0;
919                 bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid);
920                 if (bIOTAction)
921                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14;
922
923                 bIOTAction = HTIOTActIsDisableMCS15(ieee);
924                 if (bIOTAction)
925                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15;
926
927                 bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee);
928                 if (bIOTAction)
929                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS;
930
931
932                 bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid);
933                 if (bIOTAction)
934                         pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO;
935
936                 bIOTAction = HTIOTActIsMgntUseCCK6M(ieee, pNetwork);
937                 if (bIOTAction)
938                         pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M;
939                 bIOTAction = HTIOTActIsCCDFsync(ieee);
940                 if (bIOTAction)
941                         pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC;
942         } else {
943                 pHTInfo->bCurrentHTSupport = false;
944                 pHTInfo->bCurrentRT2RTAggregation = false;
945                 pHTInfo->bCurrentRT2RTLongSlotTime = false;
946                 pHTInfo->RT2RT_HT_Mode = (enum rt_ht_capability)0;
947
948                 pHTInfo->IOTAction = 0;
949                 pHTInfo->IOTRaFunc = 0;
950         }
951 }
952
953 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
954                                      struct rtllib_network *pNetwork)
955 {
956         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
957         struct ht_info_ele *pPeerHTInfo =
958                  (struct ht_info_ele *)pNetwork->bssht.bdHTInfoBuf;
959
960         if (pHTInfo->bCurrentHTSupport) {
961                 if (pNetwork->bssht.bdHTInfoLen != 0)
962                         pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
963         }
964 }
965 EXPORT_SYMBOL(HT_update_self_and_peer_setting);
966
967 void HTUseDefaultSetting(struct rtllib_device *ieee)
968 {
969         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
970
971         if (pHTInfo->bEnableHT) {
972                 pHTInfo->bCurrentHTSupport = true;
973                 pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK;
974
975                 pHTInfo->bCurBW40MHz = pHTInfo->bRegBW40MHz;
976                 pHTInfo->bCurShortGI20MHz = pHTInfo->bRegShortGI20MHz;
977
978                 pHTInfo->bCurShortGI40MHz = pHTInfo->bRegShortGI40MHz;
979
980                 if (ieee->iw_mode == IW_MODE_ADHOC)
981                         ieee->current_network.qos_data.active =
982                                  ieee->current_network.qos_data.supported;
983                 pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
984                 pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
985
986                 pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
987                 pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
988
989                 pHTInfo->CurrentMPDUDensity = pHTInfo->CurrentMPDUDensity;
990
991                 HTFilterMCSRate(ieee, ieee->Regdot11TxHTOperationalRateSet,
992                                 ieee->dot11HTOperationalRateSet);
993                 ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee,
994                                            ieee->dot11HTOperationalRateSet,
995                                            MCS_FILTER_ALL);
996                 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
997
998         } else {
999                 pHTInfo->bCurrentHTSupport = false;
1000         }
1001         return;
1002 }
1003
1004 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame)
1005 {
1006         if (ieee->pHTInfo->bCurrentHTSupport) {
1007                 if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) {
1008                         RTLLIB_DEBUG(RTLLIB_DL_HT, "HT CONTROL FILED "
1009                                      "EXIST!!\n");
1010                         return true;
1011                 }
1012         }
1013         return false;
1014 }
1015
1016 static void HTSetConnectBwModeCallback(struct rtllib_device *ieee)
1017 {
1018         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
1019
1020         RTLLIB_DEBUG(RTLLIB_DL_HT, "======>%s()\n", __func__);
1021         if (pHTInfo->bCurBW40MHz) {
1022                 if (pHTInfo->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER)
1023                         ieee->set_chan(ieee->dev,
1024                                        ieee->current_network.channel + 2);
1025                 else if (pHTInfo->CurSTAExtChnlOffset ==
1026                          HT_EXTCHNL_OFFSET_LOWER)
1027                         ieee->set_chan(ieee->dev,
1028                                        ieee->current_network.channel - 2);
1029                 else
1030                         ieee->set_chan(ieee->dev,
1031                                        ieee->current_network.channel);
1032
1033                 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40,
1034                                        pHTInfo->CurSTAExtChnlOffset);
1035         } else {
1036                 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1037                 ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20,
1038                                        HT_EXTCHNL_OFFSET_NO_EXT);
1039         }
1040
1041         pHTInfo->bSwBwInProgress = false;
1042 }
1043
1044 void HTSetConnectBwMode(struct rtllib_device *ieee,
1045                         enum ht_channel_width Bandwidth,
1046                         enum ht_extchnl_offset Offset)
1047 {
1048         struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
1049
1050         if (pHTInfo->bRegBW40MHz == false)
1051                 return;
1052
1053         if (ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
1054                 Bandwidth = HT_CHANNEL_WIDTH_20;
1055
1056         if (pHTInfo->bSwBwInProgress) {
1057                 pr_info("%s: bSwBwInProgress!!\n", __func__);
1058                 return;
1059         }
1060         if (Bandwidth == HT_CHANNEL_WIDTH_20_40) {
1061                 if (ieee->current_network.channel < 2 &&
1062                     Offset == HT_EXTCHNL_OFFSET_LOWER)
1063                         Offset = HT_EXTCHNL_OFFSET_NO_EXT;
1064                 if (Offset == HT_EXTCHNL_OFFSET_UPPER ||
1065                     Offset == HT_EXTCHNL_OFFSET_LOWER) {
1066                         pHTInfo->bCurBW40MHz = true;
1067                         pHTInfo->CurSTAExtChnlOffset = Offset;
1068                 } else {
1069                         pHTInfo->bCurBW40MHz = false;
1070                         pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1071                 }
1072         } else {
1073                 pHTInfo->bCurBW40MHz = false;
1074                 pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1075         }
1076
1077         pr_info("%s():pHTInfo->bCurBW40MHz:%x\n", __func__,
1078                pHTInfo->bCurBW40MHz);
1079
1080         pHTInfo->bSwBwInProgress = true;
1081
1082         HTSetConnectBwModeCallback(ieee);
1083 }